Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions backend/src/routes/admin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { Hono } from "hono";
import { z } from "zod";
import { adminMiddleware, authMiddleware, ownerMiddleware } from "../middleware/auth";

import { datasetLandingUrl, datasetVersionLandingUrl } from "../../../shared/datacite-constants.js";
import { LIVE_DATASETS, isLiveDataset } from "../constants";
import { tombstoneUserStatement } from "../db/user-tombstone";
import { SYSTEM_USER_ID } from "../lib/constants";
Expand Down Expand Up @@ -2124,15 +2125,15 @@ adminRoutes.post("/datasets/:id/doi/update", zValidator("json", updateDoiSchema)

const metadata = bidsToDataCite(datasetId, doi, bidsDesc, enrichment);
updateOptions.dataciteXml = buildDataCiteXml(metadata);
updateOptions.target = `https://nemar.org/dataexplorer/detail?dataset_id=${datasetId}`;
updateOptions.target = datasetLandingUrl(datasetId);
metadataRefreshed = true;
}

// Change status
if (body.status) {
if (body.status === "public" && dataset.ezid_status === "reserved") {
updateOptions.status = "public";
updateOptions.target = `https://nemar.org/dataexplorer/detail?dataset_id=${datasetId}`;
updateOptions.target = datasetLandingUrl(datasetId);
} else if (body.status === "unavailable") {
updateOptions.status = "unavailable";
}
Expand Down Expand Up @@ -2197,7 +2198,7 @@ adminRoutes.post("/datasets/:id/doi/update", zValidator("json", updateDoiSchema)
const vMetadata = bidsToDataCite(datasetId, vDoi, bidsDesc, vEnrichment);
vMetadata.version = ver.version;
const vXml = buildDataCiteXml(vMetadata);
const vTarget = `https://nemar.org/dataexplorer/detail?dataset_id=${datasetId}&version=${ver.version}`;
const vTarget = datasetVersionLandingUrl(datasetId, ver.version);
await ezidUpdateIdentifier(auth, versionIdentifier, {
dataciteXml: vXml,
target: vTarget,
Expand Down Expand Up @@ -4507,7 +4508,7 @@ adminRoutes.post("/publish/:id/approve", zValidator("json", approveSchema), asyn
if (vtResult instanceof Response) return vtResult;
const { version, tag, datasetDesc } = vtResult;

const nemarUrl = `https://nemar.org/dataexplorer/detail?dataset_id=${datasetId}`;
const nemarUrl = datasetLandingUrl(datasetId);
const archiveLine = `**Download:** [${tag}.zip](https://github.com/nemarDatasets/${repoName}/archive/refs/tags/${tag}.zip)`;
const sections = [
`# ${dataset.name} - Version ${version}`,
Expand Down Expand Up @@ -4572,7 +4573,7 @@ adminRoutes.post("/publish/:id/approve", zValidator("json", approveSchema), asyn
}

const auth = resolveEzidAuth(c.env, sandbox || !!dataset.is_sandbox);
const target = `https://nemar.org/dataexplorer/detail?dataset_id=${datasetId}`;
const target = datasetLandingUrl(datasetId);
await ezidMakePublic(auth, dataset.ezid_identifier, target);

// Update EZID status in D1
Expand Down
5 changes: 3 additions & 2 deletions backend/src/services/doi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* Each dataset has its own doi_provider; existing Zenodo datasets keep working.
*/

import { datasetLandingUrl, datasetVersionLandingUrl } from "../../../shared/datacite-constants.js";
import type { BidsDatasetDescription, DataCiteEnrichment } from "./datacite";
import { bidsToDataCite, buildDataCiteXml } from "./datacite";
import {
Expand Down Expand Up @@ -189,7 +190,7 @@ async function createEzidConceptDoi(
const dataciteXml = buildDataCiteXml(metadata);

// DOI landing page: always the NEMAR website (not GitHub)
const target = `https://nemar.org/dataexplorer/detail?dataset_id=${options.datasetId}`;
const target = datasetLandingUrl(options.datasetId);

let identifier: EzidIdentifier;
try {
Expand Down Expand Up @@ -298,7 +299,7 @@ export async function createEzidVersionDoi(
const dataciteXml = buildDataCiteXml(metadata);

// Version DOI landing page: NEMAR website with version param (not GitHub release)
const target = `https://nemar.org/dataexplorer/detail?dataset_id=${opts.datasetId}&version=${opts.version}`;
const target = datasetVersionLandingUrl(opts.datasetId, opts.version);

let identifier: EzidIdentifier;
try {
Expand Down
4 changes: 2 additions & 2 deletions backend/src/services/enrich-dataset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* structured EnrichmentRunResult without re-implementing the matrix.
*/

import type { NemarMetadataV2 } from "../../../shared/datacite-constants.js";
import { type NemarMetadataV2, datasetLandingUrl } from "../../../shared/datacite-constants.js";
import type { Bindings } from "../types/bindings.js";
import {
bidsToDataCite,
Expand Down Expand Up @@ -398,7 +398,7 @@ export async function enrichDataset(
`[llm-enrich] Failed to update BIDS Name in D1 for ${datasetId}: ${errorMessage(dbErr)}`,
);
}
const nemarUrl = `https://nemar.org/dataexplorer/detail?dataset_id=${datasetId}`;
const nemarUrl = datasetLandingUrl(datasetId);
const repoResult = await setRepoDescription(repoName, bidsName, pat, nemarUrl);
if (!repoResult.ok) {
console.error(
Expand Down
3 changes: 2 additions & 1 deletion backend/src/services/llm-enrich.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
type NemarMetadataV2,
type RelatedIdentifierEntry,
type StructuredKeyword,
datasetLandingUrl,
isValidRelationType,
} from "../../../shared/datacite-constants.js";

Expand Down Expand Up @@ -369,7 +370,7 @@ export function seedFromBids(
relation_type: "IsDescribedBy",
});
}
const nemarUrl = `https://nemar.org/dataexplorer/detail?dataset_id=${datasetId}`;
const nemarUrl = datasetLandingUrl(datasetId);
if (!relatedIds.some((r) => r.identifier === nemarUrl)) {
relatedIds.push({
identifier: nemarUrl,
Expand Down
22 changes: 22 additions & 0 deletions shared/datacite-constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,3 +186,25 @@ export interface NemarMetadataV2 {

/** Union of both versions. */
export type NemarMetadata = NemarMetadataV1 | NemarMetadataV2;

// ---------------------------------------------------------------------------
// Dataset landing URLs (DOI _target + enrichment links)
// ---------------------------------------------------------------------------

/**
* Canonical NEMAR dataset landing URL used as the DOI `_target` and in
* enrichment/README links. Permanent and provider-agnostic; today
* `nemar.org/dataset/<id>` forwards to `ww2.nemar.org/dataset/<id>`.
* Replaces the retired legacy `nemar.org/dataexplorer/detail?dataset_id=<id>`.
*/
export function datasetLandingUrl(datasetId: string): string {
return `https://nemar.org/dataset/${datasetId}`;
}

/**
* Version-specific landing URL. `version` is the plain semver string (e.g.
* `1.1.0`); the `?v=v<version>` form is what the ww2 dataset page honors.
*/
export function datasetVersionLandingUrl(datasetId: string, version: string): string {
return `https://nemar.org/dataset/${datasetId}?v=v${version}`;
}
2 changes: 1 addition & 1 deletion test/datacite.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1468,7 +1468,7 @@ describe("seedFromBids", () => {
expect(githubEntry?.relation_type).toBe("IsDescribedBy");

const nemarEntry = seeded.related_identifiers?.find(
(r) => r.identifier === "https://nemar.org/dataexplorer/detail?dataset_id=nm000108",
(r) => r.identifier === "https://nemar.org/dataset/nm000108",
);
expect(nemarEntry).toBeDefined();
expect(nemarEntry?.identifier_type).toBe("URL");
Expand Down
26 changes: 26 additions & 0 deletions test/dataset-landing-url.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { describe, expect, test } from "bun:test";
import { datasetLandingUrl, datasetVersionLandingUrl } from "../shared/datacite-constants";

describe("dataset landing URLs (DOI _target)", () => {
test("datasetLandingUrl returns the canonical /dataset/<id> URL", () => {
expect(datasetLandingUrl("nm000132")).toBe("https://nemar.org/dataset/nm000132");
expect(datasetLandingUrl("on004350")).toBe("https://nemar.org/dataset/on004350");
});

test("datasetVersionLandingUrl appends ?v=v<version> (ww2-honored form)", () => {
expect(datasetVersionLandingUrl("nm000132", "1.1.0")).toBe(
"https://nemar.org/dataset/nm000132?v=v1.1.0",
);
expect(datasetVersionLandingUrl("on004350", "2.0.0")).toBe(
"https://nemar.org/dataset/on004350?v=v2.0.0",
);
});

test("targets are on the canonical nemar.org domain, not the legacy dataexplorer path", () => {
const concept = datasetLandingUrl("nm000132");
const version = datasetVersionLandingUrl("nm000132", "1.0.0");
expect(concept).not.toContain("dataexplorer");
expect(version).not.toContain("dataexplorer");
expect(concept.startsWith("https://nemar.org/dataset/")).toBe(true);
});
});
12 changes: 6 additions & 6 deletions test/ezid-sandbox.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ describe.skipIf(!SHOULD_RUN)("EZID Sandbox Integration", { timeout: 30000 }, ()
const minted = await mintIdentifier(EZID_TEST_AUTH, {
shoulder: TEST_SHOULDER,
status: "reserved",
target: `https://nemar.org/dataexplorer/detail?dataset_id=${TEST_DATASET_ID}`,
target: `https://nemar.org/dataset/${TEST_DATASET_ID}`,
dataciteFields: {
creator: "Test, User",
title: `Test Dataset - ${new Date().toISOString()}`,
Expand Down Expand Up @@ -238,7 +238,7 @@ describe.skipIf(!SHOULD_RUN)("EZID Sandbox Integration", { timeout: 30000 }, ()
const minted = await mintIdentifier(EZID_TEST_AUTH, {
shoulder: TEST_SHOULDER,
status: "reserved",
target: `https://nemar.org/dataexplorer/detail?dataset_id=${TEST_DATASET_ID}`,
target: `https://nemar.org/dataset/${TEST_DATASET_ID}`,
dataciteXml: xml,
});

Expand Down Expand Up @@ -604,7 +604,7 @@ describe.skipIf(!SHOULD_RUN)("EZID Sandbox Integration", { timeout: 30000 }, ()
const minted = await mintIdentifier(EZID_TEST_AUTH, {
shoulder: TEST_SHOULDER,
status: "reserved",
target: `https://nemar.org/dataexplorer/detail?dataset_id=${TEST_DATASET_ID}`,
target: `https://nemar.org/dataset/${TEST_DATASET_ID}`,
dataciteXml: xml,
});
createdIdentifiers.push(minted.identifier);
Expand All @@ -628,7 +628,7 @@ describe.skipIf(!SHOULD_RUN)("EZID Sandbox Integration", { timeout: 30000 }, ()

const created = await createIdentifier(EZID_TEST_AUTH, deterministicId, {
status: "reserved",
target: `https://nemar.org/dataexplorer/detail?dataset_id=${TEST_DATASET_ID}`,
target: `https://nemar.org/dataset/${TEST_DATASET_ID}`,
dataciteXml: xml,
});

Expand Down Expand Up @@ -740,7 +740,7 @@ describe.skipIf(!SHOULD_RUN)("EZID Sandbox Integration", { timeout: 30000 }, ()
const minted = await mintIdentifier(EZID_TEST_AUTH, {
shoulder: TEST_SHOULDER,
status: "reserved",
target: `https://nemar.org/dataexplorer/detail?dataset_id=${TEST_DATASET_ID}`,
target: `https://nemar.org/dataset/${TEST_DATASET_ID}`,
dataciteFields: {
creator: "Test, User",
title: "Lifecycle Test v1.0.0",
Expand Down Expand Up @@ -780,7 +780,7 @@ describe.skipIf(!SHOULD_RUN)("EZID Sandbox Integration", { timeout: 30000 }, ()
const published = await makePublic(
EZID_TEST_AUTH,
minted.identifier,
`https://nemar.org/dataexplorer/detail?dataset_id=${TEST_DATASET_ID}`,
`https://nemar.org/dataset/${TEST_DATASET_ID}`,
);
expect(published.status).toBe("public");
console.log(" [x] Step 3: Made public");
Expand Down
Loading