diff --git a/src/api/v2/values/values-endpoint.spec.ts b/src/api/v2/values/values-endpoint.spec.ts index ccb4c3296..8a5cba259 100644 --- a/src/api/v2/values/values-endpoint.spec.ts +++ b/src/api/v2/values/values-endpoint.spec.ts @@ -31,7 +31,10 @@ import { ReadBooleanValue } from "../../../models/v2/resources/values/read/read- import { ReadColorValue } from "../../../models/v2/resources/values/read/read-color-value"; import { KnoraDate, ReadDateValue } from "../../../models/v2/resources/values/read/read-date-value"; import { ReadDecimalValue } from "../../../models/v2/resources/values/read/read-decimal-value"; -import { ReadStillImageFileValue } from "../../../models/v2/resources/values/read/read-file-value"; +import { + ReadStillImageExternalFileValue, + ReadStillImageFileValue +} from "../../../models/v2/resources/values/read/read-file-value"; import { ReadGeomValue } from "../../../models/v2/resources/values/read/read-geom-value"; import { ReadGeonameValue } from "../../../models/v2/resources/values/read/read-geoname-value"; import { ReadIntValue } from "../../../models/v2/resources/values/read/read-int-value"; @@ -490,6 +493,35 @@ describe("ValuesEndpoint", () => { }); + it("should read an external image file value", done => { + + knoraApiConnection.v2.values.getValue("http://rdfh.ch/0803/RRjceJu5S86zfc_-ZrIEtg", "1-COzXfuTXiwDJ_2GZxeoQ").subscribe( + (res: ReadResource) => { + const externalImageVal = res.getValuesAs("http://api.knora.org/ontology/knora-api/v2#hasStillImageFileValue", ReadStillImageExternalFileValue); + expect(externalImageVal.length).toEqual(1); + expect(externalImageVal[0].externalUrl).toEqual("https://ids.lib.harvard.edu/ids/iiif/24209711/full/105,/0/default.jpg"); + + expect(getResourceClassDefinitionFromCacheSpy).toHaveBeenCalledTimes(1); + expect(getResourceClassDefinitionFromCacheSpy).toHaveBeenCalledWith("http://0.0.0.0:3333/ontology/0001/anything/v2#ThingPicture"); + + expect(getListNodeFromCacheSpy).toHaveBeenCalledTimes(0); + + done(); + } + ); + + const request = jasmine.Ajax.requests.mostRecent(); + + const resource = require("../../../../test/data/api/v2/manually-generated/get-still-image-external-file-value-response.json"); + + request.respondWith(MockAjaxCall.mockResponse(JSON.stringify(resource))); + + expect(request.url).toBe("http://0.0.0.0:3333/v2/values/http%3A%2F%2Frdfh.ch%2F0803%2FRRjceJu5S86zfc_-ZrIEtg/1-COzXfuTXiwDJ_2GZxeoQ"); + + expect(request.method).toEqual("GET"); + + }); + it("should read a geometry value", done => { knoraApiConnection.v2.values.getValue("http://rdfh.ch/0001/H6gBWUuJSuuO-CilHV8kQw", "we-ybmj-SRen-91n4RaDOQ").subscribe( diff --git a/src/index.ts b/src/index.ts index 8d7d0e6cb..3ee333abc 100644 --- a/src/index.ts +++ b/src/index.ts @@ -167,12 +167,13 @@ export { ReadBooleanValue } from "./models/v2/resources/values/read/read-boolean export { ReadColorValue } from "./models/v2/resources/values/read/read-color-value"; export { ReadDateValue, KnoraDate, KnoraPeriod, Precision } from "./models/v2/resources/values/read/read-date-value"; export { ReadDecimalValue } from "./models/v2/resources/values/read/read-decimal-value"; -export { +export { ReadFileValue, ReadAudioFileValue, ReadDocumentFileValue, ReadMovingImageFileValue, ReadStillImageFileValue, + ReadStillImageExternalFileValue, ReadArchiveFileValue, ReadTextFileValue } from "./models/v2/resources/values/read/read-file-value"; @@ -182,9 +183,9 @@ export { ReadIntervalValue } from "./models/v2/resources/values/read/read-interv export { ReadLinkValue } from "./models/v2/resources/values/read/read-link-value"; export { ReadListValue } from "./models/v2/resources/values/read/read-list-value"; export { - ReadTextValue, - ReadTextValueAsString, - ReadTextValueAsHtml, + ReadTextValue, + ReadTextValueAsString, + ReadTextValueAsHtml, ReadTextValueAsXml } from "./models/v2/resources/values/read/read-text-value"; export { ReadUriValue } from "./models/v2/resources/values/read/read-uri-value"; @@ -197,7 +198,7 @@ export { UpdateBooleanValue } from "./models/v2/resources/values/update/update-b export { UpdateColorValue } from "./models/v2/resources/values/update/update-color-value"; export { UpdateDateValue } from "./models/v2/resources/values/update/update-date-value"; export { UpdateDecimalValue } from "./models/v2/resources/values/update/update-decimal-value"; -export { +export { UpdateFileValue, UpdateAudioFileValue, UpdateDocumentFileValue, @@ -211,7 +212,7 @@ export { UpdateIntValue } from "./models/v2/resources/values/update/update-int-v export { UpdateIntervalValue } from "./models/v2/resources/values/update/update-interval-value"; export { UpdateLinkValue } from "./models/v2/resources/values/update/update-link-value"; export { UpdateListValue } from "./models/v2/resources/values/update/update-list-value"; -export { +export { UpdateTextValueAsString, UpdateTextValueAsXml, UpdateTextValueAsHtml @@ -225,12 +226,13 @@ export { CreateBooleanValue } from "./models/v2/resources/values/create/create-b export { CreateColorValue } from "./models/v2/resources/values/create/create-color-value"; export { CreateDateValue } from "./models/v2/resources/values/create/create-date-value"; export { CreateDecimalValue } from "./models/v2/resources/values/create/create-decimal-value"; -export { +export { CreateFileValue, CreateAudioFileValue, CreateDocumentFileValue, CreateMovingImageFileValue, CreateStillImageFileValue, + CreateStillImageExternalFileValue, CreateTextFileValue, CreateArchiveFileValue } from "./models/v2/resources/values/create/create-file-value"; @@ -239,7 +241,7 @@ export { CreateIntValue } from "./models/v2/resources/values/create/create-int-v export { CreateIntervalValue } from "./models/v2/resources/values/create/create-interval-value"; export { CreateLinkValue } from "./models/v2/resources/values/create/create-link-value"; export { CreateListValue } from "./models/v2/resources/values/create/create-list-value"; -export { +export { CreateTextValueAsString, CreateTextValueAsXml } from "./models/v2/resources/values/create/create-text-value"; diff --git a/src/models/v2/Constants.ts b/src/models/v2/Constants.ts index 769efeda1..f0e661b88 100644 --- a/src/models/v2/Constants.ts +++ b/src/models/v2/Constants.ts @@ -48,6 +48,7 @@ export class Constants { static DDDFileValue = Constants.KnoraApiV2 + Constants.HashDelimiter + "DDDFileValue"; static DocumentFileValue = Constants.KnoraApiV2 + Constants.HashDelimiter + "DocumentFileValue"; static StillImageFileValue = Constants.KnoraApiV2 + Constants.HashDelimiter + "StillImageFileValue"; + static StillImageExternalFileValue = Constants.KnoraApiV2 + Constants.HashDelimiter + "StillImageExternalFileValue"; static MovingImageFileValue = Constants.KnoraApiV2 + Constants.HashDelimiter + "MovingImageFileValue"; static TextFileValue = Constants.KnoraApiV2 + Constants.HashDelimiter + "TextFileValue"; static ArchiveFileValue = Constants.KnoraApiV2 + Constants.HashDelimiter + "ArchiveFileValue"; @@ -128,6 +129,8 @@ export class Constants { static StillImageFileValueHasDimX = Constants.KnoraApiV2 + Constants.HashDelimiter + "stillImageFileValueHasDimX"; static StillImageFileValueHasDimY = Constants.KnoraApiV2 + Constants.HashDelimiter + "stillImageFileValueHasDimY"; static StillImageFileValueHasIIIFBaseUrl = Constants.KnoraApiV2 + Constants.HashDelimiter + "stillImageFileValueHasIIIFBaseUrl"; + static FileValueHasExternalUrl = Constants.KnoraApiV2 + Constants.HashDelimiter + "fileValueHasExternalUrl"; + static StillImageFileValueHasExternalUrl = Constants.KnoraApiV2 + Constants.HashDelimiter + "stillImageFileValueHasExternalUrl"; static AudioFileValueHasDuration = Constants.KnoraApiV2 + Constants.HashDelimiter + "audioFileValueHasDuration"; static MovingImageFileValueHasDimX = Constants.KnoraApiV2 + Constants.HashDelimiter + "movingImageFileValueHasDimX"; static MovingImageFileValueHasDimY = Constants.KnoraApiV2 + Constants.HashDelimiter + "movingImageFileValueHasDimY"; diff --git a/src/models/v2/resources/ResourcesConversionUtil.ts b/src/models/v2/resources/ResourcesConversionUtil.ts index 66096955d..baa1b4665 100644 --- a/src/models/v2/resources/ResourcesConversionUtil.ts +++ b/src/models/v2/resources/ResourcesConversionUtil.ts @@ -17,6 +17,7 @@ import { ReadAudioFileValue, ReadDocumentFileValue, ReadMovingImageFileValue, + ReadStillImageExternalFileValue, ReadStillImageFileValue, ReadTextFileValue } from "./values/read/read-file-value"; @@ -459,6 +460,14 @@ export namespace ResourcesConversionUtil { break; } + case Constants.StillImageExternalFileValue: { + const extStillImageVal = handleSimpleValue(valueJsonld, ReadStillImageExternalFileValue, jsonConvert); + value = extStillImageVal.pipe(map((val: ReadStillImageExternalFileValue) => { + return val; + })); + break; + } + case Constants.ArchiveFileValue: { const archiveVal = handleSimpleValue(valueJsonld, ReadArchiveFileValue, jsonConvert); value = archiveVal.pipe(map((val: ReadArchiveFileValue) => { diff --git a/src/models/v2/resources/values/create/create-file-value.ts b/src/models/v2/resources/values/create/create-file-value.ts index 6d0f50175..6ff7dd181 100644 --- a/src/models/v2/resources/values/create/create-file-value.ts +++ b/src/models/v2/resources/values/create/create-file-value.ts @@ -56,6 +56,20 @@ export class CreateStillImageFileValue extends CreateFileValue { constructor() { super(Constants.StillImageFileValue); + + } + +} + +/** + * @category Model V2 + */ +@JsonObject("CreateStillImageExternalFileValue") +export class CreateStillImageExternalFileValue extends CreateFileValue { + @JsonProperty(Constants.FileValueHasExternalUrl, String, true) + externalUrl?: string = ""; + constructor() { + super(Constants.StillImageExternalFileValue); } } @@ -77,9 +91,9 @@ export class CreateTextFileValue extends CreateFileValue { */ @JsonObject("CreateArchiveFileValue") export class CreateArchiveFileValue extends CreateFileValue { - + constructor() { super(Constants.ArchiveFileValue); } - + } diff --git a/src/models/v2/resources/values/read/read-file-value.ts b/src/models/v2/resources/values/read/read-file-value.ts index 3e985ca6a..0b0b45089 100644 --- a/src/models/v2/resources/values/read/read-file-value.ts +++ b/src/models/v2/resources/values/read/read-file-value.ts @@ -82,6 +82,17 @@ export class ReadStillImageFileValue extends ReadFileValue { } +/** + * @category Model V2 + */ +@JsonObject("ReadStillImageExternalFileValue") +export class ReadStillImageExternalFileValue extends ReadFileValue { + @JsonProperty(Constants.StillImageFileValueHasExternalUrl, UriConverter, true) + externalUrl: string = ""; + +} + + /** * @category Model V2 */ diff --git a/src/models/v2/resources/values/update/update-file-value.ts b/src/models/v2/resources/values/update/update-file-value.ts index d779164db..4229bea16 100644 --- a/src/models/v2/resources/values/update/update-file-value.ts +++ b/src/models/v2/resources/values/update/update-file-value.ts @@ -62,6 +62,19 @@ export class UpdateStillImageFileValue extends UpdateFileValue { } +/** + * @category Model V2 + */ +@JsonObject("UpdateStillImageExternalFileValue") +export class UpdateExternalStillImageFileValue extends UpdateFileValue { + @JsonProperty(Constants.StillImageFileValueHasExternalUrl, String, true) + externalUrl?: string = ""; + constructor() { + super(Constants.StillImageAbstractFileValue); + } +} + + /** * @category Model V2 */ @@ -79,9 +92,9 @@ export class UpdateTextFileValue extends UpdateFileValue { */ @JsonObject("UpdateArchiveFileValue") export class UpdateArchiveFileValue extends UpdateFileValue { - + constructor() { super(Constants.ArchiveFileValue); } - + } diff --git a/test/data/api/v2/manually-generated/get-still-image-external-file-value-response.json b/test/data/api/v2/manually-generated/get-still-image-external-file-value-response.json new file mode 100644 index 000000000..2d00fce7b --- /dev/null +++ b/test/data/api/v2/manually-generated/get-still-image-external-file-value-response.json @@ -0,0 +1,67 @@ +{ + "knora-api:arkUrl": { + "@value": "http://0.0.0.0:3336/ark:/72163/1/0001/a=thing=picture1", + "@type": "xsd:anyURI" + }, + "knora-api:versionArkUrl": { + "@value": "http://0.0.0.0:3336/ark:/72163/1/0001/a=thing=picture1.20110302T150510Z", + "@type": "xsd:anyURI" + }, + "knora-api:attachedToProject": { + "@id": "http://rdfh.ch/projects/0001" + }, + "knora-api:userHasPermission": "CR", + "knora-api:creationDate": { + "@value": "2024-08-05T15:20:29.932538430Z", + "@type": "xsd:dateTimeStamp" + }, + "knora-api:attachedToUser": { + "@id": "http://rdfh.ch/users/9XBCrDV3SRa7kS1WwynB4Q" + }, + "knora-api:hasPermissions": "CR knora-admin:Creator|M knora-admin:ProjectMember|RV knora-admin:UnknownUser", + "@type": "anything:ThingPicture", + "@id": "http://rdfh.ch/0001/a-thing-picture", + "rdfs:label": "A thing with an external iiif picture", + "knora-api:hasStillImageFileValue": { + "knora-api:arkUrl": { + "@value": "http://0.0.0.0:3336/ark:/72163/1/0803/RRjceJu5S86zfc_=ZrIEtgK/1=COzXfuTXiwDJ_2GZxeoQR", + "@type": "xsd:anyURI" + }, + "knora-api:versionArkUrl": { + "@value": "http://0.0.0.0:3336/ark:/72163/1/0803/RRjceJu5S86zfc_=ZrIEtgK/1=COzXfuTXiwDJ_2GZxeoQR.20240805T15202993253843Z", + "@type": "xsd:anyURI" + }, + "knora-api:userHasPermission": "CR", + "knora-api:valueCreationDate": { + "@value": "2024-08-05T15:20:29.932538430Z", + "@type": "xsd:dateTimeStamp" + }, + "knora-api:valueHasUUID": "1-COzXfuTXiwDJ_2GZxeoQ", + "knora-api:stillImageFileValueHasIIIFBaseUrl": { + "@value": "https://ids.lib.harvard.edu", + "@type": "xsd:anyURI" + }, + "@id": "http://rdfh.ch/0803/RRjceJu5S86zfc_-ZrIEtg/values/1-COzXfuTXiwDJ_2GZxeoQ", + "knora-api:stillImageFileValueHasExternalUrl": { + "@value": "https://ids.lib.harvard.edu/ids/iiif/24209711/full/105,/0/default.jpg", + "@type": "xsd:anyURI" + }, + "knora-api:attachedToUser": { + "@id": "http://rdfh.ch/users/9XBCrDV3SRa7kS1WwynB4Q" + }, + "knora-api:fileValueAsUrl": { + "@value": "https://ids.lib.harvard.edu/ids/iiif/24209711/full/105,/0/default.jpg", + "@type": "xsd:anyURI" + }, + "knora-api:hasPermissions": "M knora-admin:Creator,knora-admin:ProjectMember|V knora-admin:KnownUser,knora-admin:UnknownUser", + "@type": "knora-api:StillImageExternalFileValue", + "knora-api:fileValueHasFilename": "internalFilename" + }, + "@context": { + "rdf": "http://www.w3.org/1999/02/22-rdf-syntax-ns#", + "knora-api": "http://api.knora.org/ontology/knora-api/v2#", + "rdfs": "http://www.w3.org/2000/01/rdf-schema#", + "xsd": "http://www.w3.org/2001/XMLSchema#", + "anything": "http://0.0.0.0:3333/ontology/0001/anything/v2#" + } +} diff --git a/tsconfig.json b/tsconfig.json index e0266fc33..76b8e3ef3 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,36 +1 @@ -{ - "compilerOptions": { - "declaration": true, - "emitDecoratorMetadata": true, - "esModuleInterop": true, - "experimentalDecorators": true, - "lib": [ - "es6", - "dom" - ], - "module": "es6", - "removeComments": false, - "target": "es5", - "resolveJsonModule": true, - "moduleResolution": "node", - "sourceMap": true, - "strictNullChecks": true, - "noImplicitAny": true, - "outDir": "build" - }, - "exclude": [ - "build", - "coverage", - "dist", - "node_modules", - "test", - "**/*.spec.ts", - "test-framework" - ], - "files": [ - "index.ts" - ], - "include": [ - "src/**/*.ts" - ] -} \ No newline at end of file +{"compilerOptions":{"declaration":true,"emitDecoratorMetadata":true,"esModuleInterop":true,"experimentalDecorators":true,"lib":["es6","dom"],"module":"es6","removeComments":false,"target":"es5","resolveJsonModule":true,"moduleResolution":"node","sourceMap":true,"strictNullChecks":true,"noImplicitAny":true,"outDir":"build"},"exclude":["build","coverage"],"files":["index.ts"],"include":["src/**/*.ts"]}