diff --git a/src/api/v2/search/search-endpoint-v2.ts b/src/api/v2/search/search-endpoint-v2.ts index 9b46ec844..4775dc286 100644 --- a/src/api/v2/search/search-endpoint-v2.ts +++ b/src/api/v2/search/search-endpoint-v2.ts @@ -139,7 +139,6 @@ export class SearchEndpointV2 extends Endpoint { */ doExtendedSearch(gravsearchQuery: string): Observable { // TODO: Do not hard-code the URL and http call params, generate this from Knora - // TODO: check if content-type have to be set to text/plain return this.httpPost("/searchextended", gravsearchQuery, "sparql").pipe( diff --git a/src/models/v2/resources/ResourcesConversionUtil.ts b/src/models/v2/resources/ResourcesConversionUtil.ts index b0e5f8708..66096955d 100644 --- a/src/models/v2/resources/ResourcesConversionUtil.ts +++ b/src/models/v2/resources/ResourcesConversionUtil.ts @@ -43,31 +43,40 @@ import { ResourceClassAndPropertyDefinitions } from "../../../cache/ontology-cac export namespace ResourcesConversionUtil { /** - * Given a JSON-LD representing zero, one more resources, converts it to an array of ReadResource. + * Given a JSON-LD representing zero, one or more resources, converts it to an array of ReadResource. * * JSON-LD is expected to have expanded prefixes (processed by jsonld processor). * - * @param resourcesJsonld a JSON-LD object with expanded prefixes representing zero, one or more resources. + * @param resourcesJsonld a JSON-LD object with expanded prefixes representing zero, one or more resources. * @param ontologyCache instance of OntologyCache to be used. * @param listNodeCache instance of ListNodeCache to be used. * @param jsonConvert instance of JsonConvert to be used. */ export const createReadResourceSequence = (resourcesJsonld: object, ontologyCache: OntologyCache, listNodeCache: ListNodeV2Cache, jsonConvert: JsonConvert): Observable => { - if (resourcesJsonld.hasOwnProperty("@graph")) { - // sequence of resources - return forkJoin((resourcesJsonld as { [index: string]: object[] })["@graph"] - .map((res: { [index: string]: object[] | string }) => createReadResource(res, ontologyCache, listNodeCache, jsonConvert))).pipe( - map((resources: ReadResource[]) => { - // check for mayHaveMoreResults - if (resourcesJsonld.hasOwnProperty(Constants.MayHaveMoreResults)) { - // presence of knora-api:mayHaveMoreResults implicitly means true - return new ReadResourceSequence(resources, true); - } else { - return new ReadResourceSequence(resources); - } - }) - ); + let graphLength: number = (resourcesJsonld as { [index: string]: object[] })["@graph"].length + + if (graphLength > 0) { + // sequence of resources + return forkJoin((resourcesJsonld as { [index: string]: object[] })["@graph"] + .map((res: { [index: string]: object[] | string }) => createReadResource(res, ontologyCache, listNodeCache, jsonConvert))).pipe( + map((resources: ReadResource[]) => { + // check for mayHaveMoreResults + if (resourcesJsonld.hasOwnProperty(Constants.MayHaveMoreResults)) { + // presence of knora-api:mayHaveMoreResults implicitly means true + return new ReadResourceSequence(resources, true); + } else { + return new ReadResourceSequence(resources); + } + }) + ); + } else { + if (resourcesJsonld.hasOwnProperty(Constants.MayHaveMoreResults)) { + return of(new ReadResourceSequence([], true)); + } else { + return of(new ReadResourceSequence([])); + } + } } else { // one or no resource if (Object.keys(resourcesJsonld).length === 0) { diff --git a/src/models/v2/resources/read/read-resource-sequence.ts b/src/models/v2/resources/read/read-resource-sequence.ts index 9f02a6b7d..4a837578d 100644 --- a/src/models/v2/resources/read/read-resource-sequence.ts +++ b/src/models/v2/resources/read/read-resource-sequence.ts @@ -11,7 +11,5 @@ export class ReadResourceSequence { * @param resources sequence of resources. * @param mayHaveMoreResults flag whether there are more results to be fetched, i.e. for search results. */ - constructor(readonly resources: ReadResource[], readonly mayHaveMoreResults = false) { - } - + constructor(readonly resources: ReadResource[], readonly mayHaveMoreResults = false) { } }