diff --git a/src/helper/reconciliation-service.helper.ts b/src/helper/reconciliation-service.helper.ts index 44646eb..1bafd66 100644 --- a/src/helper/reconciliation-service.helper.ts +++ b/src/helper/reconciliation-service.helper.ts @@ -98,7 +98,7 @@ export class ReconciliationServiceHelper { static isQueryByURI(query: string) { const artsdataIdPattern = "^K[0-9]+-[0-9]+$"; - return !!(query.match(artsdataIdPattern) || + return !!(query?.match(artsdataIdPattern) || (this.isValidURI(query) && query.startsWith("http://kg.artsdata.ca/resource/K"))); } diff --git a/src/service/recon/recon.service.spec.ts b/src/service/recon/recon.service.spec.ts index 281459d..98ff806 100644 --- a/src/service/recon/recon.service.spec.ts +++ b/src/service/recon/recon.service.spec.ts @@ -238,6 +238,7 @@ describe("Recon Service tests", () => { ] } ], + expectedId: "K11-19", expectedName: "Roy Thomson Hall", expectedCount: 1 }, { @@ -254,6 +255,7 @@ describe("Recon Service tests", () => { ] }] , + expectedId: "K11-19", expectedName: "Roy Thomson Hall", expectedCount: 1 }, { @@ -270,6 +272,7 @@ describe("Recon Service tests", () => { ] } ], + expectedId: "K11-19", expectedName: "Roy Thomson Hall", expectedCount: 1 }, @@ -287,6 +290,7 @@ describe("Recon Service tests", () => { ] } ], + expectedId: "K11-19", expectedName: "Roy Thomson Hall", expectedCount: 1 }, { @@ -308,6 +312,7 @@ describe("Recon Service tests", () => { ] } ], + expectedId: "K11-19", expectedName: "Roy Thomson Hall", expectedCount: 1 }, @@ -331,10 +336,53 @@ describe("Recon Service tests", () => { ] } ], + expectedId: "K11-19", expectedName: "Roy Thomson Hall", expectedCount: 1 - } + }, { + description: "Reconcile Event with Name", + "queries": [ + { + "type": "schema:Event", + "limit": 1, + "conditions": [ + { + "matchType": "name", + "v": "Matilda - Citadel Theatre" + } + ] + } + ], + expectedId: "citadeltheatre-com_2018-2019_matilda", + expectedName: "Matilda - Citadel Theatre", + expectedCount: 1 + }, { + description: "Reconcile Event with Name and startDate", + "queries": [ + { + "type": "schema:Event", + "limit": 1, + "conditions": [ + { + "matchType": "name", + "v": "Matilda - Citadel Theatre", + "pid": "string", + "required": true + }, + { + "matchType": "property", + "v": "2019-03-17T13:30:00-04:00", + "pid": "schema:startDate", + "required": true + } + ] + } + ], + expectedId: "citadeltheatre-com_2018-2019_matilda#2019-03-17T133000-0400", + expectedName: "Matilda - Citadel Theatre", + expectedCount: 1 + } ]; for (const test of testCases) { @@ -342,6 +390,7 @@ describe("Recon Service tests", () => { const result = await reconService .reconcileByQueries({ queries: test.queries }); let title = result.results?.[0]?.candidates?.[0]?.name; + const id = result.results?.[0]?.candidates?.[0]?.id; title = title instanceof String ? title : (title as any)?.values.find((value: { lang: string; str: string @@ -352,7 +401,9 @@ describe("Recon Service tests", () => { expect(result.results?.[0].candidates.length).toBe(test.expectedCount); if (test.duplicateCheck) { expect(result.results[0]?.candidates?.[0].name === result.results[0]?.candidates?.[1].name).toBeFalsy(); - + } + if (test.expectedId) { + expect(id).toBe(test.expectedId); } }); } diff --git a/src/service/recon/recon.service.ts b/src/service/recon/recon.service.ts index 1acb6d5..303f538 100644 --- a/src/service/recon/recon.service.ts +++ b/src/service/recon/recon.service.ts @@ -38,7 +38,7 @@ export class ReconciliationService { for (const reconciliationQuery of queries) { const { type, limit, conditions } = reconciliationQuery; const { name, propertyConditions } = this._resolveConditions(conditions); - const isQueryByURI = ReconciliationServiceHelper.isQueryByURI(name as string); + const isQueryByURI = !!name && ReconciliationServiceHelper.isQueryByURI(name as string); const rawSparqlQuery: string = this._getSparqlQuery(name as string, isQueryByURI, type, limit); const rawSparqlQueryWithPropertyFilters = this._resolvePropertyConditions(rawSparqlQuery, propertyConditions); const sparqlQuery: string = "query=" + encodeURIComponent(rawSparqlQueryWithPropertyFilters);