Skip to content

Commit

Permalink
DIGG-386: Adding specifications to concept page
Browse files Browse the repository at this point in the history
  • Loading branch information
MikaMunterud committed Jan 8, 2025
1 parent 5982b20 commit 2f0fecf
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 21 deletions.
42 changes: 29 additions & 13 deletions providers/entrystore-provider/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,20 @@ import { SettingsUtil } from "@/env/settings-util";
import { ESEntry, PageType } from "@/types/entrystore-core";
import { OrganisationData } from "@/types/organisation";
import { ESFacetField, ESFacetFieldValue } from "@/types/search";
import { Choice, fetchDCATMeta, handleLocale } from "@/utilities";
import {
Choice,
fetchDCATMeta,
handleLocale,
includeLangInPath,
} from "@/utilities";
import {
formatTerminologyAddress,
getContactEmail,
getFirstMatchingValue,
getLocalizedChoiceLabel,
getLocalizedValue,
getTemplateChoices,
termsPathResolver,
} from "@/utilities/entrystore/entrystore-helpers";
import { EntrystoreService } from "@/utilities/entrystore/entrystore.service";

Expand Down Expand Up @@ -46,7 +52,6 @@ export interface EntrystoreProviderProps {
entryUri?: string;
entrystoreUrl?: string;
includeContact?: boolean;
hasResourceUri?: string;
pageType: PageType;
}

Expand All @@ -66,7 +71,6 @@ export const EntrystoreProvider: FC<EntrystoreProviderProps> = ({
entrystoreUrl,
includeContact,
pageType,
hasResourceUri,
}) => {
const [state, setState] = useState(defaultESEntry);
const router = useRouter();
Expand Down Expand Up @@ -126,7 +130,7 @@ export const EntrystoreProvider: FC<EntrystoreProviderProps> = ({

// Parallel fetch for publisher info
// TODO: Remove this when concepts and terminologies are moved to admin.dataportal.se
const publisherEntrystoreService =
const adminEntrystoreService =
pageType === "concept" || pageType === "terminology"
? EntrystoreService.getInstance({
baseUrl: `https://${
Expand All @@ -140,10 +144,7 @@ export const EntrystoreProvider: FC<EntrystoreProviderProps> = ({
: entrystoreService;
const publisherPromise =
pageType !== "mqa"
? await publisherEntrystoreService.getPublisherInfo(
resourceUri,
metadata,
)
? await adminEntrystoreService.getPublisherInfo(resourceUri, metadata)
: Promise.resolve({ name: "", entry: null });

const entryData: Partial<ESEntry> = {
Expand Down Expand Up @@ -178,6 +179,7 @@ export const EntrystoreProvider: FC<EntrystoreProviderProps> = ({
metadata,
resourceUri,
entrystoreService,
adminEntrystoreService,
publisherEntry,
defaultESEntry.env,
);
Expand All @@ -199,6 +201,7 @@ export const EntrystoreProvider: FC<EntrystoreProviderProps> = ({
metadata: Metadata,
resourceUri: string,
entrystoreService: EntrystoreService,
adminEntrystoreService: EntrystoreService,
publisherEntry: Entry | null,
env: EnvSettings,
): Promise<Partial<ESEntry>> {
Expand Down Expand Up @@ -268,12 +271,12 @@ export const EntrystoreProvider: FC<EntrystoreProviderProps> = ({

case "terminology": {
// Fetch specifications and formats in parallel
// TODO: replace adminEntrystoreService with entrystoreService when concepts and terminologies are moved to admin.dataportal.se
const [specs, formats, organisationLink] = await Promise.all([
entrystoreService.getRelatedSpecifications(
adminEntrystoreService.getRelatedSpecifications(
entry,
metadata,
pageType,
hasResourceUri,
),
entrystoreService.getDownloadFormats(
entry.getEntryInfo().getMetadataURI(),
Expand Down Expand Up @@ -314,16 +317,29 @@ export const EntrystoreProvider: FC<EntrystoreProviderProps> = ({

case "concept": {
// Fetch term and formats in parallel
const [term, formats] = await Promise.all([
entrystoreService.getRelatedTerm(metadata),
const [termEntry, formats] = await Promise.all([
entrystoreService.getRelatedTerm(metadata, true) as Promise<Entry>,
entrystoreService.getDownloadFormats(
entry.getEntryInfo().getMetadataURI(),
),
]);
// TODO: replace adminEntrystoreService with entrystoreService when concepts and terminologies are moved to admin.dataportal.se
const spec = await adminEntrystoreService.getRelatedSpecifications(
termEntry,
termEntry.getAllMetadata(),
pageType,
);

return {
relatedTerm: term,
relatedTerm: {
title: getLocalizedValue(
termEntry.getAllMetadata(),
"dcterms:title",
),
url: `${includeLangInPath(lang)}${termsPathResolver(termEntry)}`,
},
downloadFormats: formats,
relatedSpecifications: spec,
};
}

Expand Down
23 changes: 15 additions & 8 deletions utilities/entrystore/entrystore.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -868,7 +868,6 @@ export class EntrystoreService {
entry: Entry,
metadata: Metadata,
pageType: PageType,
hasResourceUri?: string,
) {
try {
if (pageType === "dataset") {
Expand All @@ -889,15 +888,16 @@ export class EntrystoreService {
title: getLocalizedValue(e.getAllMetadata(), "dcterms:title"),
url: `${includeLangInPath(this.lang)}${specsPathResolver(e)}`,
}));
} else if (pageType === "terminology") {
} else if (pageType === "terminology" || pageType === "concept") {
const resourceUri = entry
.getResourceURI()
.replace("dataportal.se/concepts/", "dataportal.se/terminology/");

const specifications = await this.entryStore
.newSolrQuery()
.uriProperty(
"http://www.w3.org/ns/dx/prof/hasResource",
hasResourceUri || entry.getResourceURI(),
)
.rdfType(["dcterms:Standard", "prof:Profile"])
.publicRead(true)
.uriProperty("http://www.w3.org/ns/dx/prof/hasResource", resourceUri)
.rdfType([ESRdfType.spec_standard, ESRdfType.spec_profile])
.getEntries();

return specifications
Expand Down Expand Up @@ -945,10 +945,17 @@ export class EntrystoreService {
}
}

async getRelatedTerm(metadata: Metadata): Promise<RelatedTerm> {
async getRelatedTerm(
metadata: Metadata,
returnEntry = false,
): Promise<RelatedTerm | Entry> {
const termUri = metadata.findFirstValue(null, "skos:inScheme");
const termEntry = await this.getEntryByResourceURI(termUri);

if (returnEntry) {
return termEntry;
}

return {
title: getLocalizedValue(termEntry.getAllMetadata(), "dcterms:title"),
url: `${includeLangInPath(this.lang)}${termsPathResolver(termEntry)}`,
Expand Down

0 comments on commit 2f0fecf

Please sign in to comment.