From 823a04456cc0d03b520cc118f7dd126c486d0396 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Kilchenmann?= Date: Mon, 7 Sep 2020 16:29:14 +0200 Subject: [PATCH 01/19] feat(ontology): Init "create property" --- .gitignore | 2 +- src/api/v2/ontology/ontologies-endpoint-v2.ts | 66 ++++++++++++++++++- .../create-resource-property-payload.ts | 59 +++++++++++++++++ .../create/create-resource-property.ts | 36 ++++++++++ 4 files changed, 161 insertions(+), 2 deletions(-) create mode 100644 src/models/v2/ontologies/create/create-resource-property-payload.ts create mode 100644 src/models/v2/ontologies/create/create-resource-property.ts diff --git a/.gitignore b/.gitignore index f716ce75f..a6eab3e38 100644 --- a/.gitignore +++ b/.gitignore @@ -14,7 +14,7 @@ # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 # User-specific stuff -.vscode/** +.vscode .idea/**/workspace.xml .idea/**/tasks.xml .idea/**/usage.statistics.xml diff --git a/src/api/v2/ontology/ontologies-endpoint-v2.ts b/src/api/v2/ontology/ontologies-endpoint-v2.ts index 2374fc735..53fce8368 100644 --- a/src/api/v2/ontology/ontologies-endpoint-v2.ts +++ b/src/api/v2/ontology/ontologies-endpoint-v2.ts @@ -13,6 +13,8 @@ import { ReadOntology } from "../../../models/v2/ontologies/read/read-ontology"; import { ResourceClassDefinitionWithAllLanguages } from "../../../models/v2/ontologies/resource-class-definition"; import { UpdateOntology } from "../../../models/v2/ontologies/update-ontology"; import { Endpoint } from "../../endpoint"; +import { CreateResourceProperty } from "../../../models/v2/ontologies/create/create-resource-property"; +import { CreateResourcePropertyPayload, NewResourceProperty } from "../../../models/v2/ontologies/create/create-resource-property-payload"; declare let require: any; // http://stackoverflow.com/questions/34730010/angular2-5-minute-install-bug-require-is-not-defined const jsonld = require("jsonld/dist/jsonld.js"); @@ -176,7 +178,7 @@ export class OntologiesEndpointV2 extends Endpoint { /** * Delete resource class * - * @param updateOntology + * @param updateOntology with class IRI */ deleteResourceClass(updateOntology: UpdateOntology): Observable { @@ -196,4 +198,66 @@ export class OntologiesEndpointV2 extends Endpoint { } + /** + * Create a resource property + * + * @param resProp The resource property to be created + */ + createResourceProperty(resProp: CreateResourceProperty): Observable { + const resPropPayload = new CreateResourcePropertyPayload(); + + // prepare ontology data for payload + resPropPayload.id = resProp.ontology.id; + resPropPayload.lastModificationDate = resProp.ontology.lastModificationDate; + + // prepare new res class object for payload + const newResProperty = new NewResourceProperty(); + newResProperty.id = resProp.ontology.id + Constants.Delimiter + resProp.name; + newResProperty.label = resProp.labels; + newResProperty.comment = resProp.comments; + newResProperty.subPropertyOf = resProp.subPropertyOf; + newResProperty.type = Constants.ObjectProperty; + + resPropPayload.resProperty = [newResProperty]; + + const payload = this.jsonConvert.serializeObject(resPropPayload); + + return this.httpPost("/properties", payload).pipe( + mergeMap((ajaxResponse: AjaxResponse) => { + // TODO: @rosenth Adapt context object + // TODO: adapt getOntologyIriFromEntityIri + return jsonld.compact(ajaxResponse.response, {}); + }), map((jsonldobj: object) => { + return OntologyConversionUtil.convertResourceClassResponse(jsonldobj, this.jsonConvert); + }), + catchError(error => { + return this.handleError(error); + }) + ); + } + + + /** + * Delete resource property + * + * @param updateOntology with property IRI + */ + deleteResourceProperty(updateOntology: UpdateOntology): Observable { + + const path = "/properties/" + encodeURIComponent(updateOntology.id) + "?lastModificationDate=" + encodeURIComponent(updateOntology.lastModificationDate); + + return this.httpDelete(path).pipe( + mergeMap((ajaxResponse: AjaxResponse) => { + // TODO: @rosenth Adapt context object + // TODO: adapt getOntologyIriFromEntityIri + return jsonld.compact(ajaxResponse.response, {}); + }), + map(jsonldobj => { + return this.jsonConvert.deserializeObject(jsonldobj, OntologyMetadata); + }), + catchError(error => this.handleError(error)) + ); + + } + } diff --git a/src/models/v2/ontologies/create/create-resource-property-payload.ts b/src/models/v2/ontologies/create/create-resource-property-payload.ts new file mode 100644 index 000000000..c399decee --- /dev/null +++ b/src/models/v2/ontologies/create/create-resource-property-payload.ts @@ -0,0 +1,59 @@ +import { JsonObject, JsonProperty } from "json2typescript"; +import { Constants } from "../../Constants"; +import { DateTimeStampConverter } from "../../custom-converters/date-time-stamp-converter"; +import { StringLiteralToStringLiteralArrayConverter } from "../../custom-converters/string-literal-to-string-literal-array-converter"; +import { SubClassOfConverter } from "../../custom-converters/subclass-of-converter"; +import { StringLiteralV2 } from "../../string-literal-v2"; +import { IdConverter } from "../../custom-converters/id-converter"; + + +// Resource property data as part of CreateResourcePropertyPayload +@JsonObject("NewResourceProperty") +export class NewResourceProperty { + @JsonProperty("@id", String) + id: string = ""; + + @JsonProperty("@type", String, true) + type: string = Constants.ObjectProperty; + + @JsonProperty("subjectType", IdConverter, true) + subjectType: string = ""; + + @JsonProperty("objectType", IdConverter) + objectType: string = ""; + + @JsonProperty(Constants.Label, StringLiteralToStringLiteralArrayConverter) + label: StringLiteralV2[] = []; + + @JsonProperty(Constants.Comment, StringLiteralToStringLiteralArrayConverter) + comment: StringLiteralV2[] = []; + + @JsonProperty(Constants.SubPropertyOf, SubClassOfConverter) + subPropertyOf: string[] = []; + + @JsonProperty(Constants.SalsahGui, IdConverter, true) + guiElement: string = ""; + + @JsonProperty("guiAttributes", [String], true) + guiAttributes: string[] = []; + +} + +// Resource property data payload: This will be sent to the api +@JsonObject("CreateResourcePropertyPayload") +export class CreateResourcePropertyPayload { + + // ontology's iri + @JsonProperty("@id", String) + id: string = ""; + + // ontology's last modification data + @JsonProperty(Constants.LastModificationDate, DateTimeStampConverter) + lastModificationDate: string; + + @JsonProperty("@type", String) + type: string = Constants.Ontology; + + @JsonProperty("@graph", [NewResourceProperty]) + resProperty: NewResourceProperty[] = []; +} \ No newline at end of file diff --git a/src/models/v2/ontologies/create/create-resource-property.ts b/src/models/v2/ontologies/create/create-resource-property.ts new file mode 100644 index 000000000..1f93ebf13 --- /dev/null +++ b/src/models/v2/ontologies/create/create-resource-property.ts @@ -0,0 +1,36 @@ +import { JsonObject, JsonProperty } from "json2typescript"; +import { StringLiteral } from "../../../admin/string-literal"; +import { IdConverter } from "../../custom-converters/id-converter"; +import { UpdateOntology } from "../update-ontology"; + +@JsonObject("CreateResourceProperty") +export class CreateResourceProperty { + + @JsonProperty("ontology", UpdateOntology) + ontology: UpdateOntology = new UpdateOntology(); + + @JsonProperty("subjectType", IdConverter, true) + subjectType: string = ""; + + @JsonProperty("objectType", IdConverter) + objectType: string = ""; + + @JsonProperty("name", String) + name: string = ""; + + @JsonProperty("labels", [StringLiteral]) + labels: StringLiteral[] = []; + + @JsonProperty("comments", [StringLiteral], true) + comments: StringLiteral[] = []; + + @JsonProperty("subPropertyOf", [String]) + subPropertyOf: string[] = []; + + @JsonProperty("guiElement", IdConverter, true) + guiElement: string = ""; + + @JsonProperty("guiAttributes", [String], true) + guiAttributes: string[] = []; + +} From c93db053b9280683caa0a574bf7280b4f4872dbc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Kilchenmann?= Date: Wed, 9 Sep 2020 12:03:43 +0200 Subject: [PATCH 02/19] feat(ontology): Create property --- src/api/v2/ontology/ontologies-endpoint-v2.ts | 27 +++++-- src/models/v2/Constants.ts | 1 + .../v2/ontologies/OntologyConversionUtil.ts | 18 ++++- .../create-resource-property-payload.ts | 14 ++-- .../create/create-resource-property.ts | 6 +- .../resource-property-definition.ts | 19 +++++ test-framework/src/app/app.component.html | 15 +++- test-framework/src/app/app.component.ts | 71 +++++++++++++++++-- 8 files changed, 143 insertions(+), 28 deletions(-) diff --git a/src/api/v2/ontology/ontologies-endpoint-v2.ts b/src/api/v2/ontology/ontologies-endpoint-v2.ts index 53fce8368..0da71e311 100644 --- a/src/api/v2/ontology/ontologies-endpoint-v2.ts +++ b/src/api/v2/ontology/ontologies-endpoint-v2.ts @@ -15,6 +15,7 @@ import { UpdateOntology } from "../../../models/v2/ontologies/update-ontology"; import { Endpoint } from "../../endpoint"; import { CreateResourceProperty } from "../../../models/v2/ontologies/create/create-resource-property"; import { CreateResourcePropertyPayload, NewResourceProperty } from "../../../models/v2/ontologies/create/create-resource-property-payload"; +import { ResourcePropertyDefinitionWithAllLanguages } from "../../../models/v2/ontologies/resource-property-definition"; declare let require: any; // http://stackoverflow.com/questions/34730010/angular2-5-minute-install-bug-require-is-not-defined const jsonld = require("jsonld/dist/jsonld.js"); @@ -67,12 +68,13 @@ export class OntologiesEndpointV2 extends Endpoint { ); } + /** - * Requests metadata about all ontologies from a specific project - * - * @param projectIri the IRI of the project - * @return OntologiesMetadata or an error - */ + * Requests metadata about all ontologies from a specific project + * + * @param projectIri the IRI of the project + * @return OntologiesMetadata or an error + */ getOntologiesByProjectIri(projectIri: string): Observable { return this.httpGet("/metadata/" + encodeURIComponent(projectIri)).pipe( @@ -203,7 +205,7 @@ export class OntologiesEndpointV2 extends Endpoint { * * @param resProp The resource property to be created */ - createResourceProperty(resProp: CreateResourceProperty): Observable { + createResourceProperty(resProp: CreateResourceProperty): Observable { const resPropPayload = new CreateResourcePropertyPayload(); // prepare ontology data for payload @@ -218,17 +220,28 @@ export class OntologiesEndpointV2 extends Endpoint { newResProperty.subPropertyOf = resProp.subPropertyOf; newResProperty.type = Constants.ObjectProperty; + newResProperty.subjectType = resProp.subjectType; + newResProperty.objectType = resProp.objectType; + + if (resProp.guiElement) { + newResProperty.guiElement = resProp.guiElement; + } + if (resProp.guiAttributes) { + newResProperty.guiAttributes = resProp.guiAttributes; + } resPropPayload.resProperty = [newResProperty]; const payload = this.jsonConvert.serializeObject(resPropPayload); + console.log('create res prop payload: ', payload); + return this.httpPost("/properties", payload).pipe( mergeMap((ajaxResponse: AjaxResponse) => { // TODO: @rosenth Adapt context object // TODO: adapt getOntologyIriFromEntityIri return jsonld.compact(ajaxResponse.response, {}); }), map((jsonldobj: object) => { - return OntologyConversionUtil.convertResourceClassResponse(jsonldobj, this.jsonConvert); + return OntologyConversionUtil.convertResourcePropertyResponse(jsonldobj, this.jsonConvert); }), catchError(error => { return this.handleError(error); diff --git a/src/models/v2/Constants.ts b/src/models/v2/Constants.ts index e9260e008..25639aa1d 100644 --- a/src/models/v2/Constants.ts +++ b/src/models/v2/Constants.ts @@ -22,6 +22,7 @@ export class Constants { static ResourceIcon = Constants.KnoraApiV2 + Constants.Delimiter + "ResourceIcon"; static Region = Constants.KnoraApiV2 + Constants.Delimiter + "Region"; static ForbiddenResource = Constants.KnoraApiV2 + Constants.Delimiter + "ForbiddenResource"; + static HasValue = Constants.KnoraApiV2 + Constants.Delimiter + "hasValue"; static BooleanValue = Constants.KnoraApiV2 + Constants.Delimiter + "BooleanValue"; static ColorValue = Constants.KnoraApiV2 + Constants.Delimiter + "ColorValue"; static GeonameValue = Constants.KnoraApiV2 + Constants.Delimiter + "GeonameValue"; diff --git a/src/models/v2/ontologies/OntologyConversionUtil.ts b/src/models/v2/ontologies/OntologyConversionUtil.ts index a78d2e109..c65bd22b2 100644 --- a/src/models/v2/ontologies/OntologyConversionUtil.ts +++ b/src/models/v2/ontologies/OntologyConversionUtil.ts @@ -6,7 +6,7 @@ import { EntityDefinition } from "./EntityDefinition"; import { OntologiesMetadata, OntologyMetadata } from "./ontology-metadata"; import { ReadOntology } from "./read/read-ontology"; import { ResourceClassDefinition, ResourceClassDefinitionWithAllLanguages } from "./resource-class-definition"; -import { ResourcePropertyDefinition } from "./resource-property-definition"; +import { ResourcePropertyDefinition, ResourcePropertyDefinitionWithAllLanguages } from "./resource-property-definition"; import { StandoffClassDefinition } from "./standoff-class-definition"; import { SystemPropertyDefinition } from "./system-property-definition"; @@ -242,7 +242,7 @@ export namespace OntologyConversionUtil { * * @param resClassJsonld * @param jsonConvert - * @returns ResourceClassDefinition + * @returns ResourceClassDefinitionWithAllLanguages */ export const convertResourceClassResponse = (resClassJsonld: object, jsonConvert: JsonConvert): ResourceClassDefinitionWithAllLanguages => { if (resClassJsonld.hasOwnProperty("@graph")) { @@ -251,5 +251,19 @@ export namespace OntologyConversionUtil { return jsonConvert.deserializeObject(resClassJsonld, ResourceClassDefinitionWithAllLanguages); } } + /** + * Converts the response from createResourceProperty serialized as JSON-LD to an instance of `ResourcePropertyDefinition` + * + * @param resPropJsonld + * @param jsonConvert + * @returns ResourcePropertyDefinitionWithAllLanguages + */ + export const convertResourcePropertyResponse = (resPropJsonld: object, jsonConvert: JsonConvert): ResourcePropertyDefinitionWithAllLanguages => { + if (resPropJsonld.hasOwnProperty("@graph")) { + return jsonConvert.deserializeObject((resPropJsonld as any)['@graph'][0], ResourcePropertyDefinitionWithAllLanguages); + } else { + return jsonConvert.deserializeObject(resPropJsonld, ResourcePropertyDefinitionWithAllLanguages); + } + } } diff --git a/src/models/v2/ontologies/create/create-resource-property-payload.ts b/src/models/v2/ontologies/create/create-resource-property-payload.ts index c399decee..6faa01032 100644 --- a/src/models/v2/ontologies/create/create-resource-property-payload.ts +++ b/src/models/v2/ontologies/create/create-resource-property-payload.ts @@ -16,10 +16,10 @@ export class NewResourceProperty { @JsonProperty("@type", String, true) type: string = Constants.ObjectProperty; - @JsonProperty("subjectType", IdConverter, true) - subjectType: string = ""; + @JsonProperty(Constants.SubjectType, IdConverter, true) + subjectType?: string = undefined; - @JsonProperty("objectType", IdConverter) + @JsonProperty(Constants.ObjectType, IdConverter) objectType: string = ""; @JsonProperty(Constants.Label, StringLiteralToStringLiteralArrayConverter) @@ -31,11 +31,11 @@ export class NewResourceProperty { @JsonProperty(Constants.SubPropertyOf, SubClassOfConverter) subPropertyOf: string[] = []; - @JsonProperty(Constants.SalsahGui, IdConverter, true) - guiElement: string = ""; + @JsonProperty(Constants.GuiElement, IdConverter, true) + guiElement?: string = undefined; - @JsonProperty("guiAttributes", [String], true) - guiAttributes: string[] = []; + @JsonProperty(Constants.GuiAttribute, [String], true) + guiAttributes?: string[] = []; } diff --git a/src/models/v2/ontologies/create/create-resource-property.ts b/src/models/v2/ontologies/create/create-resource-property.ts index 1f93ebf13..21fd82350 100644 --- a/src/models/v2/ontologies/create/create-resource-property.ts +++ b/src/models/v2/ontologies/create/create-resource-property.ts @@ -10,7 +10,7 @@ export class CreateResourceProperty { ontology: UpdateOntology = new UpdateOntology(); @JsonProperty("subjectType", IdConverter, true) - subjectType: string = ""; + subjectType?: string = undefined; @JsonProperty("objectType", IdConverter) objectType: string = ""; @@ -28,9 +28,9 @@ export class CreateResourceProperty { subPropertyOf: string[] = []; @JsonProperty("guiElement", IdConverter, true) - guiElement: string = ""; + guiElement?: string = undefined; @JsonProperty("guiAttributes", [String], true) - guiAttributes: string[] = []; + guiAttributes?: string[] = []; } diff --git a/src/models/v2/ontologies/resource-property-definition.ts b/src/models/v2/ontologies/resource-property-definition.ts index dbd537267..9045c2e47 100644 --- a/src/models/v2/ontologies/resource-property-definition.ts +++ b/src/models/v2/ontologies/resource-property-definition.ts @@ -4,6 +4,9 @@ import { GuiAttributeConverter } from "../custom-converters/gui-attribute-conver import { IdConverter } from "../custom-converters/id-converter"; import { SubPropertyOfConverter } from "../custom-converters/subproperty-of-converter"; import { PropertyDefinition } from "./property-definition"; +import { StringLiteralToStringConverter } from "../custom-converters/string-literal-to-string-converter"; +import { StringLiteralV2 } from "../string-literal-v2"; +import { StringLiteralToStringLiteralArrayConverter } from "../custom-converters/string-literal-to-string-literal-array-converter"; @JsonObject("ResourcePropertyDefinition") export class ResourcePropertyDefinition extends PropertyDefinition { @@ -40,3 +43,19 @@ export class ResourcePropertyDefinition extends PropertyDefinition { @JsonProperty(Constants.GuiAttribute, GuiAttributeConverter, true) guiAttributes: string[] = []; } + +@JsonObject("ResourcePropertyDefinitionWithAllLanguages") +export class ResourcePropertyDefinitionWithAllLanguages extends ResourcePropertyDefinition { + + @JsonProperty(Constants.Comment, StringLiteralToStringConverter, true) + comment?: string = undefined; + + @JsonProperty(Constants.Comment, StringLiteralToStringLiteralArrayConverter, true) + comments: StringLiteralV2[] = []; + + @JsonProperty(Constants.Label, StringLiteralToStringConverter, true) + label?: string = undefined; + + @JsonProperty(Constants.Label, StringLiteralToStringLiteralArrayConverter, true) + labels: StringLiteralV2[] = []; +} \ No newline at end of file diff --git a/test-framework/src/app/app.component.html b/test-framework/src/app/app.component.html index 8fe23544d..b31ef4962 100644 --- a/test-framework/src/app/app.component.html +++ b/test-framework/src/app/app.component.html @@ -47,16 +47,25 @@

Ontology



The ontology's label: {{ontology?.label}}

+

Before clicking on the following resource class or property action buttons, you should click each time on Get testonto button above. Because lastModification time is always needed.

+

Resource Class

-

Before clicking on the following resource class action buttons, you should click each time on Get testonto button above. Because lastModification time is always needed.



Res class created: {{resClass?.label}}



- +

- +

Resource Property

+

+ + + + +

+ +
Delete status: {{message}}

diff --git a/test-framework/src/app/app.component.ts b/test-framework/src/app/app.component.ts index c7e13490b..81efd9d60 100644 --- a/test-framework/src/app/app.component.ts +++ b/test-framework/src/app/app.component.ts @@ -41,6 +41,8 @@ import { } from "@dasch-swiss/dsp-js"; import { map } from "rxjs/operators"; +import { CreateResourceProperty } from '@dasch-swiss/dsp-js/src/models/v2/ontologies/create/create-resource-property'; +import { ResourcePropertyDefinitionWithAllLanguages } from '@dasch-swiss/dsp-js/src/models/v2/ontologies/resource-property-definition'; @Component({ selector: 'app-root', @@ -216,12 +218,12 @@ export class AppComponent implements OnInit { value: "Test Class" } ], - newResClass.comments = [ - { - language: "en", - value: "Just an example of a new resource class" - } - ] + newResClass.comments = [ + { + language: "en", + value: "Just an example of a new resource class" + } + ] newResClass.subClassOf = [Constants.Resource]; this.knoraApiConnection.v2.onto.createResourceClass(newResClass).subscribe( @@ -249,6 +251,63 @@ export class AppComponent implements OnInit { } + + createResourceProperty() { + const newResProp = new CreateResourceProperty(); + newResProp.ontology = { + id: this.ontology.id, + lastModificationDate: this.ontology.lastModificationDate + }; + newResProp.name = "testprop"; + newResProp.labels = [ + { + language: "de", + value: "Test Eigenschaft" + }, { + language: "en", + value: "Test Property" + } + ], + newResProp.comments = [ + { + language: "en", + value: "Just an example of a new resource property" + } + ] + newResProp.subPropertyOf = [Constants.HasValue]; + newResProp.objectType = Constants.TextValue; + newResProp.subjectType = "http://0.0.0.0:3333/ontology/0001/testonto/v2#testclass"; + + newResProp.guiElement = "http://api.knora.org/ontology/salsah-gui/v2#SimpleText"; + newResProp.guiAttributes = [ + "maxlength=100", + "size=80" + ]; + + this.knoraApiConnection.v2.onto.createResourceProperty(newResProp).subscribe( + (response: ResourcePropertyDefinitionWithAllLanguages) => { + console.log('new resource property created', response); + } + ); + } + + deleteResourceProperty() { + const deleteResProp: UpdateOntology = new UpdateOntology(); + deleteResProp.id = "http://0.0.0.0:3333/ontology/0001/testonto/v2#testprop"; + deleteResProp.lastModificationDate = this.ontology.lastModificationDate; + + this.knoraApiConnection.v2.onto.deleteResourceProperty(deleteResProp).subscribe( + (response: OntologyMetadata) => { + this.message = 'res property has been deleted'; + console.log('res property deleted', response); + }, + (error: ApiResponseError) => { + console.error(error); + } + ) + + } + getResourceClass(iri: string) { this.knoraApiConnection.v2.ontologyCache.getResourceClassDefinition(iri).subscribe( From 5cb0fe13e82a8874124f3ff736bb6bb79920e6b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Kilchenmann?= Date: Wed, 9 Sep 2020 18:06:31 +0200 Subject: [PATCH 03/19] test(ontology): Init test for res property --- .../v2/ontology/ontologies-endpoint.spec.ts | 98 ++++++++++++++++++- .../create-resource-property-payload.ts | 2 +- test-framework/src/app/app.component.ts | 12 +-- 3 files changed, 104 insertions(+), 8 deletions(-) diff --git a/src/api/v2/ontology/ontologies-endpoint.spec.ts b/src/api/v2/ontology/ontologies-endpoint.spec.ts index 2e0062897..fbb465f34 100644 --- a/src/api/v2/ontology/ontologies-endpoint.spec.ts +++ b/src/api/v2/ontology/ontologies-endpoint.spec.ts @@ -7,9 +7,11 @@ import { DeleteOntologyResponse } from "../../../models/v2/ontologies/delete/del import { OntologiesMetadata, OntologyMetadata } from "../../../models/v2/ontologies/ontology-metadata"; import { ReadOntology } from "../../../models/v2/ontologies/read/read-ontology"; import { ResourceClassDefinition, ResourceClassDefinitionWithAllLanguages } from "../../../models/v2/ontologies/resource-class-definition"; -import { ResourcePropertyDefinition } from "../../../models/v2/ontologies/resource-property-definition"; +import { ResourcePropertyDefinition, ResourcePropertyDefinitionWithAllLanguages } from "../../../models/v2/ontologies/resource-property-definition"; import { SystemPropertyDefinition } from "../../../models/v2/ontologies/system-property-definition"; import { UpdateOntology } from "../../../models/v2/ontologies/update-ontology"; +import { CreateResourceProperty } from "../../../models/v2/ontologies/create/create-resource-property"; +import { Constants } from "../../../models/v2/Constants"; describe("OntologiesEndpoint", () => { @@ -365,4 +367,98 @@ describe("OntologiesEndpoint", () => { }); }); + + /* TODO: NO TEST DATA available for create-property-response + describe("Method createResourceProperty", () => { + it("should create a new res property and add it to anything ontology", done => { + + const newResProp = new CreateResourceProperty(); + + newResProp.ontology = { + id: "http://0.0.0.0:3333/ontology/00FF/images/v2", + lastModificationDate: "2017-12-19T15:23:42.166Z" + }; + newResProp.name = "titel"; + + newResProp.labels = [ + { + language: "en", + value: "Title" + } + ]; + + // newResProp.comments = [ + // { + // language: "en", + // value: "Comment" + // } + // ]; + + newResProp.subPropertyOf = [Constants.HasValue]; + + newResProp.objectType = Constants.ListValue; + newResProp.subjectType = "http://0.0.0.0:3333/ontology/00FF/images/v2#bild"; + + newResProp.guiElement = "http://api.knora.org/ontology/salsah-gui/v2#List"; + newResProp.guiAttributes = ["hlist="]; + + + knoraApiConnection.v2.onto.createResourceProperty(newResProp).subscribe( + (response: ResourcePropertyDefinitionWithAllLanguages) => { + console.warn('new resource property created', response); + expect(response.id).toBe("http://0.0.0.0:3333/ontology/00FF/images/v2#titel"); + done(); + } + ); + + const request = jasmine.Ajax.requests.mostRecent(); + + const createResPropResponse = require("../../../../test/data/api/v2/ontologies/get-property-textValue-response.json"); + + request.respondWith(MockAjaxCall.mockResponse(JSON.stringify(createResPropResponse))); + + expect(request.url).toBe("http://0.0.0.0:3333/v2/ontologies/properties"); + + expect(request.method).toEqual("POST"); + + // const expectedPayload = require("../../../../test/data/api/v2/ontologies/create-class-without-cardinalities-request-expanded.json"); + // expect(request.data()).toEqual(expectedPayload); + }); + + }); + */ + + /* TODO: NO TEST DATA available for delete-property-response + describe("Method deleteResourceProperty", () => { + it("should delete a resource property", done => { + + const resprop = new UpdateOntology(); + + resprop.id = "http://0.0.0.0:3333/ontology/00FF/images/v2#titel"; + + resprop.lastModificationDate = "2017-12-19T15:23:42.166Z"; + + knoraApiConnection.v2.onto.deleteResourceProperty(resprop).subscribe( + (res: OntologyMetadata) => { + expect(res.id).toEqual("http://0.0.0.0:3333/ontology/0001/anything/v2"); + done(); + } + ); + + const request = jasmine.Ajax.requests.mostRecent(); + + const deleteOntoResponse = require("../../../../test/data/api/v2/ontologies/anything-ontology.json"); + + request.respondWith(MockAjaxCall.mockResponse(JSON.stringify(deleteOntoResponse))); + + const path = "http://0.0.0.0:3333/v2/ontologies/properties/http%3A%2F%2F0.0.0.0%3A3333%2Fontology%2F00FF%2Fimages%2Fv2%23titel?lastModificationDate=2017-12-19T15%3A23%3A42.166Z"; + expect(request.url).toBe(path); + + expect(request.method).toEqual("DELETE"); + + }); + + }); + */ + }); diff --git a/src/models/v2/ontologies/create/create-resource-property-payload.ts b/src/models/v2/ontologies/create/create-resource-property-payload.ts index 6faa01032..0829df4df 100644 --- a/src/models/v2/ontologies/create/create-resource-property-payload.ts +++ b/src/models/v2/ontologies/create/create-resource-property-payload.ts @@ -25,7 +25,7 @@ export class NewResourceProperty { @JsonProperty(Constants.Label, StringLiteralToStringLiteralArrayConverter) label: StringLiteralV2[] = []; - @JsonProperty(Constants.Comment, StringLiteralToStringLiteralArrayConverter) + @JsonProperty(Constants.Comment, StringLiteralToStringLiteralArrayConverter, true) comment: StringLiteralV2[] = []; @JsonProperty(Constants.SubPropertyOf, SubClassOfConverter) diff --git a/test-framework/src/app/app.component.ts b/test-framework/src/app/app.component.ts index 81efd9d60..7fab65fc1 100644 --- a/test-framework/src/app/app.component.ts +++ b/test-framework/src/app/app.component.ts @@ -268,12 +268,12 @@ export class AppComponent implements OnInit { value: "Test Property" } ], - newResProp.comments = [ - { - language: "en", - value: "Just an example of a new resource property" - } - ] + newResProp.comments = [ + { + language: "en", + value: "Just an example of a new resource property" + } + ] newResProp.subPropertyOf = [Constants.HasValue]; newResProp.objectType = Constants.TextValue; newResProp.subjectType = "http://0.0.0.0:3333/ontology/0001/testonto/v2#testclass"; From cc70297c81551aec8fd31c0c9e28367ce89fa21f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Kilchenmann?= Date: Thu, 10 Sep 2020 16:41:49 +0200 Subject: [PATCH 04/19] feat(ontology): Create property --- src/api/v2/ontology/ontologies-endpoint-v2.ts | 8 +++-- .../create-resource-property-payload.ts | 2 +- test-framework/src/app/app.component.ts | 22 +++++------- tsconfig.json | 36 +------------------ 4 files changed, 15 insertions(+), 53 deletions(-) diff --git a/src/api/v2/ontology/ontologies-endpoint-v2.ts b/src/api/v2/ontology/ontologies-endpoint-v2.ts index 0da71e311..65aa654fd 100644 --- a/src/api/v2/ontology/ontologies-endpoint-v2.ts +++ b/src/api/v2/ontology/ontologies-endpoint-v2.ts @@ -155,7 +155,7 @@ export class OntologiesEndpointV2 extends Endpoint { const newResClass = new NewResourceClass(); newResClass.id = resClass.ontology.id + Constants.Delimiter + resClass.name; newResClass.label = resClass.labels; - newResClass.comment = resClass.comments; + newResClass.comment = (resClass.comments.length ? resClass.comments : resClass.labels); newResClass.subClassOf = resClass.subClassOf; newResClass.type = Constants.Class; @@ -206,6 +206,7 @@ export class OntologiesEndpointV2 extends Endpoint { * @param resProp The resource property to be created */ createResourceProperty(resProp: CreateResourceProperty): Observable { + const resPropPayload = new CreateResourcePropertyPayload(); // prepare ontology data for payload @@ -216,19 +217,20 @@ export class OntologiesEndpointV2 extends Endpoint { const newResProperty = new NewResourceProperty(); newResProperty.id = resProp.ontology.id + Constants.Delimiter + resProp.name; newResProperty.label = resProp.labels; - newResProperty.comment = resProp.comments; + newResProperty.comment = (resProp.comments.length ? resProp.comments : resProp.labels); newResProperty.subPropertyOf = resProp.subPropertyOf; newResProperty.type = Constants.ObjectProperty; newResProperty.subjectType = resProp.subjectType; newResProperty.objectType = resProp.objectType; - + if (resProp.guiElement) { newResProperty.guiElement = resProp.guiElement; } if (resProp.guiAttributes) { newResProperty.guiAttributes = resProp.guiAttributes; } + resPropPayload.resProperty = [newResProperty]; const payload = this.jsonConvert.serializeObject(resPropPayload); diff --git a/src/models/v2/ontologies/create/create-resource-property-payload.ts b/src/models/v2/ontologies/create/create-resource-property-payload.ts index 0829df4df..6faa01032 100644 --- a/src/models/v2/ontologies/create/create-resource-property-payload.ts +++ b/src/models/v2/ontologies/create/create-resource-property-payload.ts @@ -25,7 +25,7 @@ export class NewResourceProperty { @JsonProperty(Constants.Label, StringLiteralToStringLiteralArrayConverter) label: StringLiteralV2[] = []; - @JsonProperty(Constants.Comment, StringLiteralToStringLiteralArrayConverter, true) + @JsonProperty(Constants.Comment, StringLiteralToStringLiteralArrayConverter) comment: StringLiteralV2[] = []; @JsonProperty(Constants.SubPropertyOf, SubClassOfConverter) diff --git a/test-framework/src/app/app.component.ts b/test-framework/src/app/app.component.ts index 7fab65fc1..acaeaebee 100644 --- a/test-framework/src/app/app.component.ts +++ b/test-framework/src/app/app.component.ts @@ -217,13 +217,13 @@ export class AppComponent implements OnInit { language: "en", value: "Test Class" } - ], - newResClass.comments = [ - { - language: "en", - value: "Just an example of a new resource class" - } - ] + ]; + newResClass.comments = [ + { + language: "en", + value: "Just an example of a new resource class" + } + ]; newResClass.subClassOf = [Constants.Resource]; this.knoraApiConnection.v2.onto.createResourceClass(newResClass).subscribe( @@ -267,13 +267,7 @@ export class AppComponent implements OnInit { language: "en", value: "Test Property" } - ], - newResProp.comments = [ - { - language: "en", - value: "Just an example of a new resource property" - } - ] + ]; newResProp.subPropertyOf = [Constants.HasValue]; newResProp.objectType = Constants.TextValue; newResProp.subjectType = "http://0.0.0.0:3333/ontology/0001/testonto/v2#testclass"; diff --git a/tsconfig.json b/tsconfig.json index 25e745ad4..2c286e7d4 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,35 +1 @@ -{ - "compilerOptions": { - "declaration": true, - "emitDecoratorMetadata": true, - "esModuleInterop": true, - "experimentalDecorators": true, - "lib": [ - "es6", - "dom" - ], - "module": "commonjs", - "removeComments": false, - "target": "es5", - "resolveJsonModule": true, - "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":"commonjs","removeComments":false,"target":"es5","resolveJsonModule":true,"sourceMap":true,"strictNullChecks":true,"noImplicitAny":true,"outDir":"build"},"exclude":["build","coverage","dist","node_modules","**/*.spec.ts","test-framework"],"files":["index.ts"],"include":["src/**/*.ts"]} From 4cdf1f408b398c8b319b9893f9f481f57f1e2e89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Kilchenmann?= Date: Fri, 11 Sep 2020 13:57:54 +0200 Subject: [PATCH 05/19] test(ontology): More test data --- scripts/v2-test-data-config.json | 24 +++ ...ies-to-class-nothing-request-expanded.json | 1 + ...ardinalities-to-class-nothing-request.json | 29 +++ ...es-to-class-nothing-response-expanded.json | 1 + ...rdinalities-to-class-nothing-response.json | 175 ++++++++++++++++++ ...create-link-property-request-expanded.json | 1 + .../create-link-property-request.json | 39 ++++ ...reate-link-property-response-expanded.json | 1 + .../create-link-property-response.json | 45 +++++ ...reate-value-property-request-expanded.json | 1 + .../create-value-property-request.json | 52 ++++++ ...eate-value-property-response-expanded.json | 1 + .../create-value-property-response.json | 56 ++++++ 13 files changed, 426 insertions(+) create mode 100644 test/data/api/v2/ontologies/add-cardinalities-to-class-nothing-request-expanded.json create mode 100644 test/data/api/v2/ontologies/add-cardinalities-to-class-nothing-request.json create mode 100644 test/data/api/v2/ontologies/add-cardinalities-to-class-nothing-response-expanded.json create mode 100644 test/data/api/v2/ontologies/add-cardinalities-to-class-nothing-response.json create mode 100644 test/data/api/v2/ontologies/create-link-property-request-expanded.json create mode 100644 test/data/api/v2/ontologies/create-link-property-request.json create mode 100644 test/data/api/v2/ontologies/create-link-property-response-expanded.json create mode 100644 test/data/api/v2/ontologies/create-link-property-response.json create mode 100644 test/data/api/v2/ontologies/create-value-property-request-expanded.json create mode 100644 test/data/api/v2/ontologies/create-value-property-request.json create mode 100644 test/data/api/v2/ontologies/create-value-property-response-expanded.json create mode 100644 test/data/api/v2/ontologies/create-value-property-response.json diff --git a/scripts/v2-test-data-config.json b/scripts/v2-test-data-config.json index 396dcb14a..348b35ad2 100644 --- a/scripts/v2-test-data-config.json +++ b/scripts/v2-test-data-config.json @@ -48,6 +48,30 @@ "source": "/v2/ontologies/create-class-without-cardinalities-response.json", "destination": "./test/data/api/v2/ontologies/create-class-without-cardinalities-response.json" }, + { + "source": "/v2/ontologies/create-value-property-request.json", + "destination": "./test/data/api/v2/ontologies/create-value-property-request.json" + }, + { + "source": "/v2/ontologies/create-value-property-response.json", + "destination": "./test/data/api/v2/ontologies/create-value-property-response.json" + }, + { + "source": "/v2/ontologies/create-link-property-request.json", + "destination": "./test/data/api/v2/ontologies/create-link-property-request.json" + }, + { + "source": "/v2/ontologies/create-link-property-response.json", + "destination": "./test/data/api/v2/ontologies/create-link-property-response.json" + }, + { + "source": "/v2/ontologies/add-cardinalities-to-class-nothing-request.json", + "destination": "./test/data/api/v2/ontologies/add-cardinalities-to-class-nothing-request.json" + }, + { + "source": "/v2/ontologies/add-cardinalities-to-class-nothing-response.json", + "destination": "./test/data/api/v2/ontologies/add-cardinalities-to-class-nothing-response.json" + }, { "source": "/v2/resources/testding.json", "destination": "./test/data/api/v2/resources/testding.json" diff --git a/test/data/api/v2/ontologies/add-cardinalities-to-class-nothing-request-expanded.json b/test/data/api/v2/ontologies/add-cardinalities-to-class-nothing-request-expanded.json new file mode 100644 index 000000000..35ef501fd --- /dev/null +++ b/test/data/api/v2/ontologies/add-cardinalities-to-class-nothing-request-expanded.json @@ -0,0 +1 @@ +{"@graph":[{"@id":"http://0.0.0.0:3333/ontology/0001/anything/v2#Nothing","@type":"http://www.w3.org/2002/07/owl#Class","http://www.w3.org/2000/01/rdf-schema#subClassOf":{"@type":"http://www.w3.org/2002/07/owl#Restriction","http://www.w3.org/2002/07/owl#maxCardinality":1,"http://www.w3.org/2002/07/owl#onProperty":{"@id":"http://0.0.0.0:3333/ontology/0001/anything/v2#hasOtherNothing"}}}],"@id":"http://0.0.0.0:3333/ontology/0001/anything/v2","@type":"http://www.w3.org/2002/07/owl#Ontology","http://api.knora.org/ontology/knora-api/v2#lastModificationDate":{"@type":"http://www.w3.org/2001/XMLSchema#dateTimeStamp","@value":"2017-12-19T15:23:42.166Z"}} \ No newline at end of file diff --git a/test/data/api/v2/ontologies/add-cardinalities-to-class-nothing-request.json b/test/data/api/v2/ontologies/add-cardinalities-to-class-nothing-request.json new file mode 100644 index 000000000..633dd0371 --- /dev/null +++ b/test/data/api/v2/ontologies/add-cardinalities-to-class-nothing-request.json @@ -0,0 +1,29 @@ + +{ + "@id" : "http://0.0.0.0:3333/ontology/0001/anything/v2", + "@type" : "owl:Ontology", + "knora-api:lastModificationDate" : { + "@type" : "xsd:dateTimeStamp", + "@value" : "2017-12-19T15:23:42.166Z" + }, + "@graph" : [ { + "@id" : "anything:Nothing", + "@type" : "owl:Class", + "rdfs:subClassOf" : { + "@type": "owl:Restriction", + "owl:maxCardinality" : 1, + "owl:onProperty" : { + "@id" : "anything:hasOtherNothing" + } + } + } ], + "@context" : { + "rdf" : "http://www.w3.org/1999/02/22-rdf-syntax-ns#", + "knora-api" : "http://api.knora.org/ontology/knora-api/v2#", + "owl" : "http://www.w3.org/2002/07/owl#", + "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#" + } +} + \ No newline at end of file diff --git a/test/data/api/v2/ontologies/add-cardinalities-to-class-nothing-response-expanded.json b/test/data/api/v2/ontologies/add-cardinalities-to-class-nothing-response-expanded.json new file mode 100644 index 000000000..b36aa12cc --- /dev/null +++ b/test/data/api/v2/ontologies/add-cardinalities-to-class-nothing-response-expanded.json @@ -0,0 +1 @@ +{"@graph":[{"@id":"http://0.0.0.0:3333/ontology/0001/anything/v2#Nothing","@type":"http://www.w3.org/2002/07/owl#Class","http://api.knora.org/ontology/knora-api/v2#canBeInstantiated":true,"http://api.knora.org/ontology/knora-api/v2#isResourceClass":true,"http://www.w3.org/2000/01/rdf-schema#comment":[{"@language":"en","@value":"Represents nothing"},{"@language":"fr","@value":"ne représente rien"}],"http://www.w3.org/2000/01/rdf-schema#label":[{"@language":"en","@value":"nothing"},{"@language":"fr","@value":"rien"}],"http://www.w3.org/2000/01/rdf-schema#subClassOf":[{"@id":"http://api.knora.org/ontology/knora-api/v2#Resource"},{"@type":"http://www.w3.org/2002/07/owl#Restriction","http://www.w3.org/2002/07/owl#maxCardinality":1,"http://www.w3.org/2002/07/owl#onProperty":{"@id":"http://0.0.0.0:3333/ontology/0001/anything/v2#hasOtherNothing"}},{"@type":"http://www.w3.org/2002/07/owl#Restriction","http://www.w3.org/2002/07/owl#maxCardinality":1,"http://www.w3.org/2002/07/owl#onProperty":{"@id":"http://0.0.0.0:3333/ontology/0001/anything/v2#hasOtherNothingValue"}},{"@type":"http://www.w3.org/2002/07/owl#Restriction","http://api.knora.org/ontology/knora-api/v2#isInherited":true,"http://www.w3.org/2002/07/owl#cardinality":1,"http://www.w3.org/2002/07/owl#onProperty":{"@id":"http://api.knora.org/ontology/knora-api/v2#arkUrl"}},{"@type":"http://www.w3.org/2002/07/owl#Restriction","http://api.knora.org/ontology/knora-api/v2#isInherited":true,"http://www.w3.org/2002/07/owl#cardinality":1,"http://www.w3.org/2002/07/owl#onProperty":{"@id":"http://api.knora.org/ontology/knora-api/v2#attachedToProject"}},{"@type":"http://www.w3.org/2002/07/owl#Restriction","http://api.knora.org/ontology/knora-api/v2#isInherited":true,"http://www.w3.org/2002/07/owl#cardinality":1,"http://www.w3.org/2002/07/owl#onProperty":{"@id":"http://api.knora.org/ontology/knora-api/v2#attachedToUser"}},{"@type":"http://www.w3.org/2002/07/owl#Restriction","http://api.knora.org/ontology/knora-api/v2#isInherited":true,"http://www.w3.org/2002/07/owl#cardinality":1,"http://www.w3.org/2002/07/owl#onProperty":{"@id":"http://api.knora.org/ontology/knora-api/v2#creationDate"}},{"@type":"http://www.w3.org/2002/07/owl#Restriction","http://api.knora.org/ontology/knora-api/v2#isInherited":true,"http://www.w3.org/2002/07/owl#maxCardinality":1,"http://www.w3.org/2002/07/owl#onProperty":{"@id":"http://api.knora.org/ontology/knora-api/v2#deleteComment"}},{"@type":"http://www.w3.org/2002/07/owl#Restriction","http://api.knora.org/ontology/knora-api/v2#isInherited":true,"http://www.w3.org/2002/07/owl#maxCardinality":1,"http://www.w3.org/2002/07/owl#onProperty":{"@id":"http://api.knora.org/ontology/knora-api/v2#deleteDate"}},{"@type":"http://www.w3.org/2002/07/owl#Restriction","http://api.knora.org/ontology/knora-api/v2#isInherited":true,"http://www.w3.org/2002/07/owl#maxCardinality":1,"http://www.w3.org/2002/07/owl#onProperty":{"@id":"http://api.knora.org/ontology/knora-api/v2#deletedBy"}},{"@type":"http://www.w3.org/2002/07/owl#Restriction","http://api.knora.org/ontology/knora-api/v2#isInherited":true,"http://www.w3.org/2002/07/owl#minCardinality":0,"http://www.w3.org/2002/07/owl#onProperty":{"@id":"http://api.knora.org/ontology/knora-api/v2#hasIncomingLinkValue"}},{"@type":"http://www.w3.org/2002/07/owl#Restriction","http://api.knora.org/ontology/knora-api/v2#isInherited":true,"http://www.w3.org/2002/07/owl#cardinality":1,"http://www.w3.org/2002/07/owl#onProperty":{"@id":"http://api.knora.org/ontology/knora-api/v2#hasPermissions"}},{"@type":"http://www.w3.org/2002/07/owl#Restriction","http://api.knora.org/ontology/knora-api/v2#isInherited":true,"http://www.w3.org/2002/07/owl#minCardinality":0,"http://www.w3.org/2002/07/owl#onProperty":{"@id":"http://api.knora.org/ontology/knora-api/v2#hasStandoffLinkTo"}},{"@type":"http://www.w3.org/2002/07/owl#Restriction","http://api.knora.org/ontology/knora-api/v2#isInherited":true,"http://www.w3.org/2002/07/owl#minCardinality":0,"http://www.w3.org/2002/07/owl#onProperty":{"@id":"http://api.knora.org/ontology/knora-api/v2#hasStandoffLinkToValue"}},{"@type":"http://www.w3.org/2002/07/owl#Restriction","http://api.knora.org/ontology/knora-api/v2#isInherited":true,"http://www.w3.org/2002/07/owl#maxCardinality":1,"http://www.w3.org/2002/07/owl#onProperty":{"@id":"http://api.knora.org/ontology/knora-api/v2#isDeleted"}},{"@type":"http://www.w3.org/2002/07/owl#Restriction","http://api.knora.org/ontology/knora-api/v2#isInherited":true,"http://www.w3.org/2002/07/owl#maxCardinality":1,"http://www.w3.org/2002/07/owl#onProperty":{"@id":"http://api.knora.org/ontology/knora-api/v2#lastModificationDate"}},{"@type":"http://www.w3.org/2002/07/owl#Restriction","http://api.knora.org/ontology/knora-api/v2#isInherited":true,"http://www.w3.org/2002/07/owl#cardinality":1,"http://www.w3.org/2002/07/owl#onProperty":{"@id":"http://api.knora.org/ontology/knora-api/v2#userHasPermission"}},{"@type":"http://www.w3.org/2002/07/owl#Restriction","http://api.knora.org/ontology/knora-api/v2#isInherited":true,"http://www.w3.org/2002/07/owl#cardinality":1,"http://www.w3.org/2002/07/owl#onProperty":{"@id":"http://api.knora.org/ontology/knora-api/v2#versionArkUrl"}},{"@type":"http://www.w3.org/2002/07/owl#Restriction","http://api.knora.org/ontology/knora-api/v2#isInherited":true,"http://www.w3.org/2002/07/owl#maxCardinality":1,"http://www.w3.org/2002/07/owl#onProperty":{"@id":"http://api.knora.org/ontology/knora-api/v2#versionDate"}},{"@type":"http://www.w3.org/2002/07/owl#Restriction","http://api.knora.org/ontology/knora-api/v2#isInherited":true,"http://www.w3.org/2002/07/owl#cardinality":1,"http://www.w3.org/2002/07/owl#onProperty":{"@id":"http://www.w3.org/2000/01/rdf-schema#label"}}]}],"@id":"http://0.0.0.0:3333/ontology/0001/anything/v2","@type":"http://www.w3.org/2002/07/owl#Ontology","http://api.knora.org/ontology/knora-api/v2#attachedToProject":{"@id":"http://rdfh.ch/projects/0001"},"http://api.knora.org/ontology/knora-api/v2#lastModificationDate":{"@type":"http://www.w3.org/2001/XMLSchema#dateTimeStamp","@value":"2020-09-10T09:41:17.151318Z"},"http://www.w3.org/2000/01/rdf-schema#label":"The anything ontology"} \ No newline at end of file diff --git a/test/data/api/v2/ontologies/add-cardinalities-to-class-nothing-response.json b/test/data/api/v2/ontologies/add-cardinalities-to-class-nothing-response.json new file mode 100644 index 000000000..ef1e35e4c --- /dev/null +++ b/test/data/api/v2/ontologies/add-cardinalities-to-class-nothing-response.json @@ -0,0 +1,175 @@ +{ + "@graph" : [ { + "@id" : "anything:Nothing", + "@type" : "owl:Class", + "knora-api:canBeInstantiated" : true, + "knora-api:isResourceClass" : true, + "rdfs:comment" : [ { + "@language" : "en", + "@value" : "Represents nothing" + }, { + "@language" : "fr", + "@value" : "ne représente rien" + } ], + "rdfs:label" : [ { + "@language" : "en", + "@value" : "nothing" + }, { + "@language" : "fr", + "@value" : "rien" + } ], + "rdfs:subClassOf" : [ { + "@id" : "knora-api:Resource" + }, { + "@type" : "owl:Restriction", + "owl:maxCardinality" : 1, + "owl:onProperty" : { + "@id" : "anything:hasOtherNothing" + } + }, { + "@type" : "owl:Restriction", + "owl:maxCardinality" : 1, + "owl:onProperty" : { + "@id" : "anything:hasOtherNothingValue" + } + }, { + "@type" : "owl:Restriction", + "knora-api:isInherited" : true, + "owl:cardinality" : 1, + "owl:onProperty" : { + "@id" : "knora-api:arkUrl" + } + }, { + "@type" : "owl:Restriction", + "knora-api:isInherited" : true, + "owl:cardinality" : 1, + "owl:onProperty" : { + "@id" : "knora-api:attachedToProject" + } + }, { + "@type" : "owl:Restriction", + "knora-api:isInherited" : true, + "owl:cardinality" : 1, + "owl:onProperty" : { + "@id" : "knora-api:attachedToUser" + } + }, { + "@type" : "owl:Restriction", + "knora-api:isInherited" : true, + "owl:cardinality" : 1, + "owl:onProperty" : { + "@id" : "knora-api:creationDate" + } + }, { + "@type" : "owl:Restriction", + "knora-api:isInherited" : true, + "owl:maxCardinality" : 1, + "owl:onProperty" : { + "@id" : "knora-api:deleteComment" + } + }, { + "@type" : "owl:Restriction", + "knora-api:isInherited" : true, + "owl:maxCardinality" : 1, + "owl:onProperty" : { + "@id" : "knora-api:deleteDate" + } + }, { + "@type" : "owl:Restriction", + "knora-api:isInherited" : true, + "owl:maxCardinality" : 1, + "owl:onProperty" : { + "@id" : "knora-api:deletedBy" + } + }, { + "@type" : "owl:Restriction", + "knora-api:isInherited" : true, + "owl:minCardinality" : 0, + "owl:onProperty" : { + "@id" : "knora-api:hasIncomingLinkValue" + } + }, { + "@type" : "owl:Restriction", + "knora-api:isInherited" : true, + "owl:cardinality" : 1, + "owl:onProperty" : { + "@id" : "knora-api:hasPermissions" + } + }, { + "@type" : "owl:Restriction", + "knora-api:isInherited" : true, + "owl:minCardinality" : 0, + "owl:onProperty" : { + "@id" : "knora-api:hasStandoffLinkTo" + } + }, { + "@type" : "owl:Restriction", + "knora-api:isInherited" : true, + "owl:minCardinality" : 0, + "owl:onProperty" : { + "@id" : "knora-api:hasStandoffLinkToValue" + } + }, { + "@type" : "owl:Restriction", + "knora-api:isInherited" : true, + "owl:maxCardinality" : 1, + "owl:onProperty" : { + "@id" : "knora-api:isDeleted" + } + }, { + "@type" : "owl:Restriction", + "knora-api:isInherited" : true, + "owl:maxCardinality" : 1, + "owl:onProperty" : { + "@id" : "knora-api:lastModificationDate" + } + }, { + "@type" : "owl:Restriction", + "knora-api:isInherited" : true, + "owl:cardinality" : 1, + "owl:onProperty" : { + "@id" : "knora-api:userHasPermission" + } + }, { + "@type" : "owl:Restriction", + "knora-api:isInherited" : true, + "owl:cardinality" : 1, + "owl:onProperty" : { + "@id" : "knora-api:versionArkUrl" + } + }, { + "@type" : "owl:Restriction", + "knora-api:isInherited" : true, + "owl:maxCardinality" : 1, + "owl:onProperty" : { + "@id" : "knora-api:versionDate" + } + }, { + "@type" : "owl:Restriction", + "knora-api:isInherited" : true, + "owl:cardinality" : 1, + "owl:onProperty" : { + "@id" : "rdfs:label" + } + } ] + } ], + "@id" : "http://0.0.0.0:3333/ontology/0001/anything/v2", + "@type" : "owl:Ontology", + "knora-api:attachedToProject" : { + "@id" : "http://rdfh.ch/projects/0001" + }, + "knora-api:lastModificationDate" : { + "@type" : "xsd:dateTimeStamp", + "@value" : "2020-09-10T09:41:17.151318Z" + }, + "rdfs:label" : "The anything ontology", + "@context" : { + "rdf" : "http://www.w3.org/1999/02/22-rdf-syntax-ns#", + "knora-api" : "http://api.knora.org/ontology/knora-api/v2#", + "owl" : "http://www.w3.org/2002/07/owl#", + "salsah-gui" : "http://api.knora.org/ontology/salsah-gui/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#" + } +} \ No newline at end of file diff --git a/test/data/api/v2/ontologies/create-link-property-request-expanded.json b/test/data/api/v2/ontologies/create-link-property-request-expanded.json new file mode 100644 index 000000000..d919c82a3 --- /dev/null +++ b/test/data/api/v2/ontologies/create-link-property-request-expanded.json @@ -0,0 +1 @@ +{"@graph":[{"@id":"http://0.0.0.0:3333/ontology/0001/anything/v2#hasOtherNothing","@type":"http://www.w3.org/2002/07/owl#ObjectProperty","http://api.knora.org/ontology/knora-api/v2#objectType":{"@id":"http://0.0.0.0:3333/ontology/0001/anything/v2#Nothing"},"http://api.knora.org/ontology/knora-api/v2#subjectType":{"@id":"http://0.0.0.0:3333/ontology/0001/anything/v2#Nothing"},"http://www.w3.org/2000/01/rdf-schema#comment":{"@language":"en","@value":"Refers to the other Nothing of a Nothing"},"http://www.w3.org/2000/01/rdf-schema#label":{"@language":"en","@value":"has nothingness"},"http://www.w3.org/2000/01/rdf-schema#subPropertyOf":{"@id":"http://api.knora.org/ontology/knora-api/v2#hasLinkTo"}}],"@id":"http://0.0.0.0:3333/ontology/0001/anything/v2","@type":"http://www.w3.org/2002/07/owl#Ontology","http://api.knora.org/ontology/knora-api/v2#lastModificationDate":{"@type":"http://www.w3.org/2001/XMLSchema#dateTimeStamp","@value":"2017-12-19T15:23:42.166Z"}} \ No newline at end of file diff --git a/test/data/api/v2/ontologies/create-link-property-request.json b/test/data/api/v2/ontologies/create-link-property-request.json new file mode 100644 index 000000000..e1a89bf1b --- /dev/null +++ b/test/data/api/v2/ontologies/create-link-property-request.json @@ -0,0 +1,39 @@ + +{ + "@id" : "http://0.0.0.0:3333/ontology/0001/anything/v2", + "@type" : "owl:Ontology", + "knora-api:lastModificationDate" : { + "@type" : "xsd:dateTimeStamp", + "@value" : "2017-12-19T15:23:42.166Z" + }, + "@graph" : [ { + "@id" : "anything:hasOtherNothing", + "@type" : "owl:ObjectProperty", + "knora-api:subjectType" : { + "@id" : "anything:Nothing" + }, + "knora-api:objectType" : { + "@id" : "anything:Nothing" + }, + "rdfs:comment" : { + "@language" : "en", + "@value" : "Refers to the other Nothing of a Nothing" + }, + "rdfs:label" : { + "@language" : "en", + "@value" : "has nothingness" + }, + "rdfs:subPropertyOf" : { + "@id" : "knora-api:hasLinkTo" + } + } ], + "@context" : { + "rdf" : "http://www.w3.org/1999/02/22-rdf-syntax-ns#", + "knora-api" : "http://api.knora.org/ontology/knora-api/v2#", + "owl" : "http://www.w3.org/2002/07/owl#", + "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#" + } +} + \ No newline at end of file diff --git a/test/data/api/v2/ontologies/create-link-property-response-expanded.json b/test/data/api/v2/ontologies/create-link-property-response-expanded.json new file mode 100644 index 000000000..448710469 --- /dev/null +++ b/test/data/api/v2/ontologies/create-link-property-response-expanded.json @@ -0,0 +1 @@ +{"@graph":[{"@id":"http://0.0.0.0:3333/ontology/0001/anything/v2#hasOtherNothing","@type":"http://www.w3.org/2002/07/owl#ObjectProperty","http://api.knora.org/ontology/knora-api/v2#isEditable":true,"http://api.knora.org/ontology/knora-api/v2#isLinkProperty":true,"http://api.knora.org/ontology/knora-api/v2#isResourceProperty":true,"http://api.knora.org/ontology/knora-api/v2#objectType":{"@id":"http://0.0.0.0:3333/ontology/0001/anything/v2#Nothing"},"http://api.knora.org/ontology/knora-api/v2#subjectType":{"@id":"http://0.0.0.0:3333/ontology/0001/anything/v2#Nothing"},"http://www.w3.org/2000/01/rdf-schema#comment":{"@language":"en","@value":"Refers to the other Nothing of a Nothing"},"http://www.w3.org/2000/01/rdf-schema#label":{"@language":"en","@value":"has nothingness"},"http://www.w3.org/2000/01/rdf-schema#subPropertyOf":{"@id":"http://api.knora.org/ontology/knora-api/v2#hasLinkTo"}}],"@id":"http://0.0.0.0:3333/ontology/0001/anything/v2","@type":"http://www.w3.org/2002/07/owl#Ontology","http://api.knora.org/ontology/knora-api/v2#attachedToProject":{"@id":"http://rdfh.ch/projects/0001"},"http://api.knora.org/ontology/knora-api/v2#lastModificationDate":{"@type":"http://www.w3.org/2001/XMLSchema#dateTimeStamp","@value":"2020-09-10T09:28:51.537917Z"},"http://www.w3.org/2000/01/rdf-schema#label":"The anything ontology"} \ No newline at end of file diff --git a/test/data/api/v2/ontologies/create-link-property-response.json b/test/data/api/v2/ontologies/create-link-property-response.json new file mode 100644 index 000000000..72d1dfc11 --- /dev/null +++ b/test/data/api/v2/ontologies/create-link-property-response.json @@ -0,0 +1,45 @@ +{ + "@graph" : [ { + "@id" : "anything:hasOtherNothing", + "@type" : "owl:ObjectProperty", + "knora-api:isEditable" : true, + "knora-api:isLinkProperty" : true, + "knora-api:isResourceProperty" : true, + "knora-api:objectType" : { + "@id" : "anything:Nothing" + }, + "knora-api:subjectType" : { + "@id" : "anything:Nothing" + }, + "rdfs:comment" : { + "@language" : "en", + "@value" : "Refers to the other Nothing of a Nothing" + }, + "rdfs:label" : { + "@language" : "en", + "@value" : "has nothingness" + }, + "rdfs:subPropertyOf" : { + "@id" : "knora-api:hasLinkTo" + } + } ], + "@id" : "http://0.0.0.0:3333/ontology/0001/anything/v2", + "@type" : "owl:Ontology", + "knora-api:attachedToProject" : { + "@id" : "http://rdfh.ch/projects/0001" + }, + "knora-api:lastModificationDate" : { + "@type" : "xsd:dateTimeStamp", + "@value" : "2020-09-10T09:28:51.537917Z" + }, + "rdfs:label" : "The anything ontology", + "@context" : { + "rdf" : "http://www.w3.org/1999/02/22-rdf-syntax-ns#", + "knora-api" : "http://api.knora.org/ontology/knora-api/v2#", + "owl" : "http://www.w3.org/2002/07/owl#", + "salsah-gui" : "http://api.knora.org/ontology/salsah-gui/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#" + } +} \ No newline at end of file diff --git a/test/data/api/v2/ontologies/create-value-property-request-expanded.json b/test/data/api/v2/ontologies/create-value-property-request-expanded.json new file mode 100644 index 000000000..78ad00507 --- /dev/null +++ b/test/data/api/v2/ontologies/create-value-property-request-expanded.json @@ -0,0 +1 @@ +{"@graph":[{"@id":"http://0.0.0.0:3333/ontology/0001/anything/v2#hasName","@type":"http://www.w3.org/2002/07/owl#ObjectProperty","http://api.knora.org/ontology/knora-api/v2#objectType":{"@id":"http://api.knora.org/ontology/knora-api/v2#TextValue"},"http://api.knora.org/ontology/knora-api/v2#subjectType":{"@id":"http://0.0.0.0:3333/ontology/0001/anything/v2#Thing"},"http://api.knora.org/ontology/salsah-gui/v2#guiAttribute":["size=80","maxlength=100"],"http://api.knora.org/ontology/salsah-gui/v2#guiElement":{"@id":"http://api.knora.org/ontology/salsah-gui/v2#SimpleText"},"http://www.w3.org/2000/01/rdf-schema#comment":[{"@language":"en","@value":"The name of a Thing"},{"@language":"de","@value":"Der Name eines Dinges"}],"http://www.w3.org/2000/01/rdf-schema#label":[{"@language":"en","@value":"has name"},{"@language":"de","@value":"hat Namen"}],"http://www.w3.org/2000/01/rdf-schema#subPropertyOf":[{"@id":"http://api.knora.org/ontology/knora-api/v2#hasValue"},{"@id":"http://schema.org/name"}]}],"@id":"http://0.0.0.0:3333/ontology/0001/anything/v2","@type":"http://www.w3.org/2002/07/owl#Ontology","http://api.knora.org/ontology/knora-api/v2#lastModificationDate":{"@type":"http://www.w3.org/2001/XMLSchema#dateTimeStamp","@value":"2017-12-19T15:23:42.166Z"}} \ No newline at end of file diff --git a/test/data/api/v2/ontologies/create-value-property-request.json b/test/data/api/v2/ontologies/create-value-property-request.json new file mode 100644 index 000000000..ef435378f --- /dev/null +++ b/test/data/api/v2/ontologies/create-value-property-request.json @@ -0,0 +1,52 @@ + +{ + "@id" : "http://0.0.0.0:3333/ontology/0001/anything/v2", + "@type" : "owl:Ontology", + "knora-api:lastModificationDate" : { + "@type" : "xsd:dateTimeStamp", + "@value" : "2017-12-19T15:23:42.166Z" + }, + "@graph" : [ { + "@id" : "anything:hasName", + "@type" : "owl:ObjectProperty", + "knora-api:subjectType" : { + "@id" : "anything:Thing" + }, + "knora-api:objectType" : { + "@id" : "knora-api:TextValue" + }, + "rdfs:comment" : [ { + "@language" : "en", + "@value" : "The name of a Thing" + }, { + "@language" : "de", + "@value" : "Der Name eines Dinges" + } ], + "rdfs:label" : [ { + "@language" : "en", + "@value" : "has name" + }, { + "@language" : "de", + "@value" : "hat Namen" + } ], + "rdfs:subPropertyOf" : [ { + "@id" : "knora-api:hasValue" + }, { + "@id" : "http://schema.org/name" + } ], + "salsah-gui:guiElement" : { + "@id" : "salsah-gui:SimpleText" + }, + "salsah-gui:guiAttribute" : [ "size=80", "maxlength=100" ] + } ], + "@context" : { + "rdf" : "http://www.w3.org/1999/02/22-rdf-syntax-ns#", + "knora-api" : "http://api.knora.org/ontology/knora-api/v2#", + "salsah-gui" : "http://api.knora.org/ontology/salsah-gui/v2#", + "owl" : "http://www.w3.org/2002/07/owl#", + "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#" + } +} + \ No newline at end of file diff --git a/test/data/api/v2/ontologies/create-value-property-response-expanded.json b/test/data/api/v2/ontologies/create-value-property-response-expanded.json new file mode 100644 index 000000000..db5cc728d --- /dev/null +++ b/test/data/api/v2/ontologies/create-value-property-response-expanded.json @@ -0,0 +1 @@ +{"@graph":[{"@id":"http://0.0.0.0:3333/ontology/0001/anything/v2#hasName","@type":"http://www.w3.org/2002/07/owl#ObjectProperty","http://api.knora.org/ontology/knora-api/v2#isEditable":true,"http://api.knora.org/ontology/knora-api/v2#isResourceProperty":true,"http://api.knora.org/ontology/knora-api/v2#objectType":{"@id":"http://api.knora.org/ontology/knora-api/v2#TextValue"},"http://api.knora.org/ontology/knora-api/v2#subjectType":{"@id":"http://0.0.0.0:3333/ontology/0001/anything/v2#Thing"},"http://api.knora.org/ontology/salsah-gui/v2#guiAttribute":["maxlength=100","size=80"],"http://api.knora.org/ontology/salsah-gui/v2#guiElement":{"@id":"http://api.knora.org/ontology/salsah-gui/v2#SimpleText"},"http://www.w3.org/2000/01/rdf-schema#comment":[{"@language":"en","@value":"The name of a Thing"},{"@language":"de","@value":"Der Name eines Dinges"}],"http://www.w3.org/2000/01/rdf-schema#label":[{"@language":"en","@value":"has name"},{"@language":"de","@value":"hat Namen"}],"http://www.w3.org/2000/01/rdf-schema#subPropertyOf":[{"@id":"http://api.knora.org/ontology/knora-api/v2#hasValue"},{"@id":"http://schema.org/name"}]}],"@id":"http://0.0.0.0:3333/ontology/0001/anything/v2","@type":"http://www.w3.org/2002/07/owl#Ontology","http://api.knora.org/ontology/knora-api/v2#attachedToProject":{"@id":"http://rdfh.ch/projects/0001"},"http://api.knora.org/ontology/knora-api/v2#lastModificationDate":{"@type":"http://www.w3.org/2001/XMLSchema#dateTimeStamp","@value":"2020-09-10T09:28:47.884563Z"},"http://www.w3.org/2000/01/rdf-schema#label":"The anything ontology"} \ No newline at end of file diff --git a/test/data/api/v2/ontologies/create-value-property-response.json b/test/data/api/v2/ontologies/create-value-property-response.json new file mode 100644 index 000000000..828d1c076 --- /dev/null +++ b/test/data/api/v2/ontologies/create-value-property-response.json @@ -0,0 +1,56 @@ +{ + "@graph" : [ { + "@id" : "anything:hasName", + "@type" : "owl:ObjectProperty", + "knora-api:isEditable" : true, + "knora-api:isResourceProperty" : true, + "knora-api:objectType" : { + "@id" : "knora-api:TextValue" + }, + "knora-api:subjectType" : { + "@id" : "anything:Thing" + }, + "salsah-gui:guiAttribute" : [ "maxlength=100", "size=80" ], + "salsah-gui:guiElement" : { + "@id" : "salsah-gui:SimpleText" + }, + "rdfs:comment" : [ { + "@language" : "en", + "@value" : "The name of a Thing" + }, { + "@language" : "de", + "@value" : "Der Name eines Dinges" + } ], + "rdfs:label" : [ { + "@language" : "en", + "@value" : "has name" + }, { + "@language" : "de", + "@value" : "hat Namen" + } ], + "rdfs:subPropertyOf" : [ { + "@id" : "knora-api:hasValue" + }, { + "@id" : "http://schema.org/name" + } ] + } ], + "@id" : "http://0.0.0.0:3333/ontology/0001/anything/v2", + "@type" : "owl:Ontology", + "knora-api:attachedToProject" : { + "@id" : "http://rdfh.ch/projects/0001" + }, + "knora-api:lastModificationDate" : { + "@type" : "xsd:dateTimeStamp", + "@value" : "2020-09-10T09:28:47.884563Z" + }, + "rdfs:label" : "The anything ontology", + "@context" : { + "rdf" : "http://www.w3.org/1999/02/22-rdf-syntax-ns#", + "knora-api" : "http://api.knora.org/ontology/knora-api/v2#", + "owl" : "http://www.w3.org/2002/07/owl#", + "salsah-gui" : "http://api.knora.org/ontology/salsah-gui/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#" + } +} \ No newline at end of file From 59de3c3635f8d1b05b1668a93a93dac5ac964ce4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Kilchenmann?= Date: Tue, 15 Sep 2020 09:21:46 +0200 Subject: [PATCH 06/19] test(ontology): Add create property test --- .../v2/ontology/ontologies-endpoint.spec.ts | 52 +++++++++++-------- test-framework/src/app/app.component.ts | 42 ++++++++++----- 2 files changed, 58 insertions(+), 36 deletions(-) diff --git a/src/api/v2/ontology/ontologies-endpoint.spec.ts b/src/api/v2/ontology/ontologies-endpoint.spec.ts index fbb465f34..549e1f62d 100644 --- a/src/api/v2/ontology/ontologies-endpoint.spec.ts +++ b/src/api/v2/ontology/ontologies-endpoint.spec.ts @@ -367,66 +367,74 @@ describe("OntologiesEndpoint", () => { }); }); - - /* TODO: NO TEST DATA available for create-property-response + describe("Method createResourceProperty", () => { - it("should create a new res property and add it to anything ontology", done => { + it("should create a new res property as supPropertyOf 'hasValue'", done => { const newResProp = new CreateResourceProperty(); newResProp.ontology = { - id: "http://0.0.0.0:3333/ontology/00FF/images/v2", + id: "http://0.0.0.0:3333/ontology/0001/anything/v2", lastModificationDate: "2017-12-19T15:23:42.166Z" }; - newResProp.name = "titel"; + newResProp.name = "hasName"; newResProp.labels = [ { language: "en", - value: "Title" + value: "has name" + }, + { + language: "de", + value: "hat Namen" } ]; - // newResProp.comments = [ - // { - // language: "en", - // value: "Comment" - // } - // ]; + newResProp.comments = [ + { + language: "en", + value: "The name of a Thing" + }, + { + language: "de", + value: "Der Name eines Dinges" + } + ]; - newResProp.subPropertyOf = [Constants.HasValue]; + newResProp.subPropertyOf = [Constants.HasValue, "http://schema.org/name"]; - newResProp.objectType = Constants.ListValue; - newResProp.subjectType = "http://0.0.0.0:3333/ontology/00FF/images/v2#bild"; + newResProp.objectType = Constants.TextValue; + newResProp.subjectType = "http://0.0.0.0:3333/ontology/0001/anything/v2#Thing"; - newResProp.guiElement = "http://api.knora.org/ontology/salsah-gui/v2#List"; - newResProp.guiAttributes = ["hlist="]; + newResProp.guiElement = "http://api.knora.org/ontology/salsah-gui/v2#SimpleText"; + newResProp.guiAttributes = ["size=80", "maxlength=100"]; + console.log("NEW RES PROP ----------------", newResProp); knoraApiConnection.v2.onto.createResourceProperty(newResProp).subscribe( (response: ResourcePropertyDefinitionWithAllLanguages) => { console.warn('new resource property created', response); - expect(response.id).toBe("http://0.0.0.0:3333/ontology/00FF/images/v2#titel"); + expect(response.id).toBe("http://0.0.0.0:3333/ontology/0001/anything/v2#hasName"); done(); } ); const request = jasmine.Ajax.requests.mostRecent(); - const createResPropResponse = require("../../../../test/data/api/v2/ontologies/get-property-textValue-response.json"); + const expectedPayload = require("../../../../test/data/api/v2/ontologies/create-value-property-request.json"); + // expect(request.data()).toEqual(expectedPayload); + const createResPropResponse = require("../../../../test/data/api/v2/ontologies/create-value-property-response.json"); request.respondWith(MockAjaxCall.mockResponse(JSON.stringify(createResPropResponse))); expect(request.url).toBe("http://0.0.0.0:3333/v2/ontologies/properties"); expect(request.method).toEqual("POST"); - // const expectedPayload = require("../../../../test/data/api/v2/ontologies/create-class-without-cardinalities-request-expanded.json"); - // expect(request.data()).toEqual(expectedPayload); }); }); - */ + /* TODO: NO TEST DATA available for delete-property-response describe("Method deleteResourceProperty", () => { diff --git a/test-framework/src/app/app.component.ts b/test-framework/src/app/app.component.ts index acaeaebee..005a0853d 100644 --- a/test-framework/src/app/app.component.ts +++ b/test-framework/src/app/app.component.ts @@ -254,29 +254,42 @@ export class AppComponent implements OnInit { createResourceProperty() { const newResProp = new CreateResourceProperty(); + newResProp.ontology = { - id: this.ontology.id, - lastModificationDate: this.ontology.lastModificationDate + id: "http://0.0.0.0:3333/ontology/0001/anything/v2", + lastModificationDate: "2020-09-14T15:29:03.194356Z" }; - newResProp.name = "testprop"; + newResProp.name = "hasName"; + newResProp.labels = [ + { + language: "en", + value: "has name" + }, { language: "de", - value: "Test Eigenschaft" - }, { + value: "hat Namen" + } + ]; + + newResProp.comments = [ + { language: "en", - value: "Test Property" + value: "The name of a Thing" + }, + { + language: "de", + value: "Der Name eines Dinges" } ]; - newResProp.subPropertyOf = [Constants.HasValue]; + + newResProp.subPropertyOf = [Constants.HasValue, "http://schema.org/name"]; + newResProp.objectType = Constants.TextValue; - newResProp.subjectType = "http://0.0.0.0:3333/ontology/0001/testonto/v2#testclass"; + newResProp.subjectType = "http://0.0.0.0:3333/ontology/0001/anything/v2#Thing"; newResProp.guiElement = "http://api.knora.org/ontology/salsah-gui/v2#SimpleText"; - newResProp.guiAttributes = [ - "maxlength=100", - "size=80" - ]; + newResProp.guiAttributes = ["size=80", "maxlength=100"]; this.knoraApiConnection.v2.onto.createResourceProperty(newResProp).subscribe( (response: ResourcePropertyDefinitionWithAllLanguages) => { @@ -287,8 +300,9 @@ export class AppComponent implements OnInit { deleteResourceProperty() { const deleteResProp: UpdateOntology = new UpdateOntology(); - deleteResProp.id = "http://0.0.0.0:3333/ontology/0001/testonto/v2#testprop"; - deleteResProp.lastModificationDate = this.ontology.lastModificationDate; + deleteResProp.id = "http://0.0.0.0:3333/ontology/0001/anything/v2#hasName"; + deleteResProp.lastModificationDate = "2020-09-14T15:29:48.544437Z"; + // this.ontology.lastModificationDate; this.knoraApiConnection.v2.onto.deleteResourceProperty(deleteResProp).subscribe( (response: OntologyMetadata) => { From 14d951568c6e7ca73919663c27c999406dfe5366 Mon Sep 17 00:00:00 2001 From: Tobias Schweizer Date: Wed, 16 Sep 2020 14:52:26 +0200 Subject: [PATCH 07/19] test (ontologies endpoint): fix res prop creation test --- src/api/v2/ontology/ontologies-endpoint-v2.ts | 2 -- src/api/v2/ontology/ontologies-endpoint.spec.ts | 7 ++----- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/src/api/v2/ontology/ontologies-endpoint-v2.ts b/src/api/v2/ontology/ontologies-endpoint-v2.ts index 65aa654fd..de980c37c 100644 --- a/src/api/v2/ontology/ontologies-endpoint-v2.ts +++ b/src/api/v2/ontology/ontologies-endpoint-v2.ts @@ -235,8 +235,6 @@ export class OntologiesEndpointV2 extends Endpoint { const payload = this.jsonConvert.serializeObject(resPropPayload); - console.log('create res prop payload: ', payload); - return this.httpPost("/properties", payload).pipe( mergeMap((ajaxResponse: AjaxResponse) => { // TODO: @rosenth Adapt context object diff --git a/src/api/v2/ontology/ontologies-endpoint.spec.ts b/src/api/v2/ontology/ontologies-endpoint.spec.ts index 549e1f62d..05f34d415 100644 --- a/src/api/v2/ontology/ontologies-endpoint.spec.ts +++ b/src/api/v2/ontology/ontologies-endpoint.spec.ts @@ -409,11 +409,8 @@ describe("OntologiesEndpoint", () => { newResProp.guiElement = "http://api.knora.org/ontology/salsah-gui/v2#SimpleText"; newResProp.guiAttributes = ["size=80", "maxlength=100"]; - console.log("NEW RES PROP ----------------", newResProp); - knoraApiConnection.v2.onto.createResourceProperty(newResProp).subscribe( (response: ResourcePropertyDefinitionWithAllLanguages) => { - console.warn('new resource property created', response); expect(response.id).toBe("http://0.0.0.0:3333/ontology/0001/anything/v2#hasName"); done(); } @@ -421,8 +418,8 @@ describe("OntologiesEndpoint", () => { const request = jasmine.Ajax.requests.mostRecent(); - const expectedPayload = require("../../../../test/data/api/v2/ontologies/create-value-property-request.json"); - // expect(request.data()).toEqual(expectedPayload); + const expectedPayload = require("../../../../test/data/api/v2/ontologies/create-value-property-request-expanded.json"); + expect(request.data()).toEqual(expectedPayload); const createResPropResponse = require("../../../../test/data/api/v2/ontologies/create-value-property-response.json"); request.respondWith(MockAjaxCall.mockResponse(JSON.stringify(createResPropResponse))); From f98e1e66047276ba66582885a26f3d221a0af057 Mon Sep 17 00:00:00 2001 From: Tobias Schweizer Date: Wed, 16 Sep 2020 16:07:32 +0200 Subject: [PATCH 08/19] test (ontologies endpoint): use classes to create request object --- src/api/v2/ontology/ontologies-endpoint-v2.ts | 7 ++- .../v2/ontology/ontologies-endpoint.spec.ts | 59 ++++++++++++------- .../create-resource-property-payload.ts | 10 ++-- 3 files changed, 47 insertions(+), 29 deletions(-) diff --git a/src/api/v2/ontology/ontologies-endpoint-v2.ts b/src/api/v2/ontology/ontologies-endpoint-v2.ts index de980c37c..8c486f0cb 100644 --- a/src/api/v2/ontology/ontologies-endpoint-v2.ts +++ b/src/api/v2/ontology/ontologies-endpoint-v2.ts @@ -14,7 +14,7 @@ import { ResourceClassDefinitionWithAllLanguages } from "../../../models/v2/onto import { UpdateOntology } from "../../../models/v2/ontologies/update-ontology"; import { Endpoint } from "../../endpoint"; import { CreateResourceProperty } from "../../../models/v2/ontologies/create/create-resource-property"; -import { CreateResourcePropertyPayload, NewResourceProperty } from "../../../models/v2/ontologies/create/create-resource-property-payload"; +import { CreateResourcePropertyPayload, NewResourcePropertyPayload } from "../../../models/v2/ontologies/create/create-resource-property-payload"; import { ResourcePropertyDefinitionWithAllLanguages } from "../../../models/v2/ontologies/resource-property-definition"; declare let require: any; // http://stackoverflow.com/questions/34730010/angular2-5-minute-install-bug-require-is-not-defined @@ -214,8 +214,10 @@ export class OntologiesEndpointV2 extends Endpoint { resPropPayload.lastModificationDate = resProp.ontology.lastModificationDate; // prepare new res class object for payload - const newResProperty = new NewResourceProperty(); + const newResProperty = new NewResourcePropertyPayload(); + newResProperty.id = resProp.ontology.id + Constants.Delimiter + resProp.name; + newResProperty.label = resProp.labels; newResProperty.comment = (resProp.comments.length ? resProp.comments : resProp.labels); newResProperty.subPropertyOf = resProp.subPropertyOf; @@ -249,7 +251,6 @@ export class OntologiesEndpointV2 extends Endpoint { ); } - /** * Delete resource property * diff --git a/src/api/v2/ontology/ontologies-endpoint.spec.ts b/src/api/v2/ontology/ontologies-endpoint.spec.ts index 05f34d415..ec8a4d9a5 100644 --- a/src/api/v2/ontology/ontologies-endpoint.spec.ts +++ b/src/api/v2/ontology/ontologies-endpoint.spec.ts @@ -12,6 +12,7 @@ import { SystemPropertyDefinition } from "../../../models/v2/ontologies/system-p import { UpdateOntology } from "../../../models/v2/ontologies/update-ontology"; import { CreateResourceProperty } from "../../../models/v2/ontologies/create/create-resource-property"; import { Constants } from "../../../models/v2/Constants"; +import { StringLiteral } from "../../../models/admin/string-literal"; describe("OntologiesEndpoint", () => { @@ -373,40 +374,56 @@ describe("OntologiesEndpoint", () => { const newResProp = new CreateResourceProperty(); - newResProp.ontology = { - id: "http://0.0.0.0:3333/ontology/0001/anything/v2", - lastModificationDate: "2017-12-19T15:23:42.166Z" - }; + const onto = new UpdateOntology(); + + onto.id = "http://0.0.0.0:3333/ontology/0001/anything/v2"; + onto.lastModificationDate = "2017-12-19T15:23:42.166Z"; + + newResProp.ontology = onto; + newResProp.name = "hasName"; + const label1 = new StringLiteral(); + + label1.language = "en"; + label1.value = "has name"; + + const label2 = new StringLiteral(); + + label2.language = "de"; + label2.value = "hat Namen"; + newResProp.labels = [ - { - language: "en", - value: "has name" - }, - { - language: "de", - value: "hat Namen" - } + label1, + label2 ]; + const comment1 = new StringLiteral(); + + comment1.language = "en"; + comment1.value = "The name of a Thing"; + + const comment2 = new StringLiteral(); + + comment2.language = "de"; + comment2.value = "Der Name eines Dinges"; + newResProp.comments = [ - { - language: "en", - value: "The name of a Thing" - }, - { - language: "de", - value: "Der Name eines Dinges" - } + comment1, + comment2 ]; - newResProp.subPropertyOf = [Constants.HasValue, "http://schema.org/name"]; + newResProp.subPropertyOf = [ + Constants.HasValue, + "http://schema.org/name" + ]; newResProp.objectType = Constants.TextValue; + newResProp.subjectType = "http://0.0.0.0:3333/ontology/0001/anything/v2#Thing"; newResProp.guiElement = "http://api.knora.org/ontology/salsah-gui/v2#SimpleText"; + newResProp.guiAttributes = ["size=80", "maxlength=100"]; knoraApiConnection.v2.onto.createResourceProperty(newResProp).subscribe( diff --git a/src/models/v2/ontologies/create/create-resource-property-payload.ts b/src/models/v2/ontologies/create/create-resource-property-payload.ts index 6faa01032..af13cc560 100644 --- a/src/models/v2/ontologies/create/create-resource-property-payload.ts +++ b/src/models/v2/ontologies/create/create-resource-property-payload.ts @@ -8,8 +8,8 @@ import { IdConverter } from "../../custom-converters/id-converter"; // Resource property data as part of CreateResourcePropertyPayload -@JsonObject("NewResourceProperty") -export class NewResourceProperty { +@JsonObject("NewResourcePropertyPayload") +export class NewResourcePropertyPayload { @JsonProperty("@id", String) id: string = ""; @@ -54,6 +54,6 @@ export class CreateResourcePropertyPayload { @JsonProperty("@type", String) type: string = Constants.Ontology; - @JsonProperty("@graph", [NewResourceProperty]) - resProperty: NewResourceProperty[] = []; -} \ No newline at end of file + @JsonProperty("@graph", [NewResourcePropertyPayload]) + resProperty: NewResourcePropertyPayload[] = []; +} From 01a995093a1211d99f0755f8a404e85eaf1c2c94 Mon Sep 17 00:00:00 2001 From: Tobias Schweizer Date: Wed, 16 Sep 2020 16:25:52 +0200 Subject: [PATCH 09/19] test (ontologies endpoint): add test for creating a link prop --- .../v2/ontology/ontologies-endpoint.spec.ts | 62 ++++++++++++++++++- src/models/v2/Constants.ts | 1 + .../create-resource-property-payload.ts | 3 +- .../create/create-resource-property.ts | 2 +- 4 files changed, 64 insertions(+), 4 deletions(-) diff --git a/src/api/v2/ontology/ontologies-endpoint.spec.ts b/src/api/v2/ontology/ontologies-endpoint.spec.ts index ec8a4d9a5..58631175c 100644 --- a/src/api/v2/ontology/ontologies-endpoint.spec.ts +++ b/src/api/v2/ontology/ontologies-endpoint.spec.ts @@ -337,7 +337,6 @@ describe("OntologiesEndpoint", () => { }); - describe("Method deleteResourceClass", () => { it("should delete a resource class", done => { @@ -370,6 +369,7 @@ describe("OntologiesEndpoint", () => { }); describe("Method createResourceProperty", () => { + it("should create a new res property as supPropertyOf 'hasValue'", done => { const newResProp = new CreateResourceProperty(); @@ -447,6 +447,66 @@ describe("OntologiesEndpoint", () => { }); + it("should create a new res property as supPropertyOf 'hasLinkTo'", done => { + + const newResProp = new CreateResourceProperty(); + + const onto = new UpdateOntology(); + + onto.id = "http://0.0.0.0:3333/ontology/0001/anything/v2"; + onto.lastModificationDate = "2017-12-19T15:23:42.166Z"; + + newResProp.ontology = onto; + + newResProp.name = "hasOtherNothing"; + + const label1 = new StringLiteral(); + + label1.language = "en"; + label1.value = "has nothingness"; + + newResProp.labels = [ + label1 + ]; + + const comment1 = new StringLiteral(); + + comment1.language = "en"; + comment1.value = "Refers to the other Nothing of a Nothing"; + + newResProp.comments = [ + comment1 + ]; + + newResProp.subPropertyOf = [ + Constants.HasLinkTo + ]; + + newResProp.objectType = "http://0.0.0.0:3333/ontology/0001/anything/v2#Nothing"; + + newResProp.subjectType = "http://0.0.0.0:3333/ontology/0001/anything/v2#Nothing"; + + knoraApiConnection.v2.onto.createResourceProperty(newResProp).subscribe( + (response: ResourcePropertyDefinitionWithAllLanguages) => { + expect(response.id).toBe("http://0.0.0.0:3333/ontology/0001/anything/v2#hasOtherNothing"); + done(); + } + ); + + const request = jasmine.Ajax.requests.mostRecent(); + + const expectedPayload = require("../../../../test/data/api/v2/ontologies/create-link-property-request-expanded.json"); + expect(request.data()).toEqual(expectedPayload); + + const createResPropResponse = require("../../../../test/data/api/v2/ontologies/create-link-property-response.json"); + request.respondWith(MockAjaxCall.mockResponse(JSON.stringify(createResPropResponse))); + + expect(request.url).toBe("http://0.0.0.0:3333/v2/ontologies/properties"); + + expect(request.method).toEqual("POST"); + + }); + }); diff --git a/src/models/v2/Constants.ts b/src/models/v2/Constants.ts index 25639aa1d..6a107a097 100644 --- a/src/models/v2/Constants.ts +++ b/src/models/v2/Constants.ts @@ -23,6 +23,7 @@ export class Constants { static Region = Constants.KnoraApiV2 + Constants.Delimiter + "Region"; static ForbiddenResource = Constants.KnoraApiV2 + Constants.Delimiter + "ForbiddenResource"; static HasValue = Constants.KnoraApiV2 + Constants.Delimiter + "hasValue"; + static HasLinkTo = Constants.KnoraApiV2 + Constants.Delimiter + "hasLinkTo"; static BooleanValue = Constants.KnoraApiV2 + Constants.Delimiter + "BooleanValue"; static ColorValue = Constants.KnoraApiV2 + Constants.Delimiter + "ColorValue"; static GeonameValue = Constants.KnoraApiV2 + Constants.Delimiter + "GeonameValue"; diff --git a/src/models/v2/ontologies/create/create-resource-property-payload.ts b/src/models/v2/ontologies/create/create-resource-property-payload.ts index af13cc560..6d3cbf762 100644 --- a/src/models/v2/ontologies/create/create-resource-property-payload.ts +++ b/src/models/v2/ontologies/create/create-resource-property-payload.ts @@ -6,7 +6,6 @@ import { SubClassOfConverter } from "../../custom-converters/subclass-of-convert import { StringLiteralV2 } from "../../string-literal-v2"; import { IdConverter } from "../../custom-converters/id-converter"; - // Resource property data as part of CreateResourcePropertyPayload @JsonObject("NewResourcePropertyPayload") export class NewResourcePropertyPayload { @@ -35,7 +34,7 @@ export class NewResourcePropertyPayload { guiElement?: string = undefined; @JsonProperty(Constants.GuiAttribute, [String], true) - guiAttributes?: string[] = []; + guiAttributes?: string[] = undefined; } diff --git a/src/models/v2/ontologies/create/create-resource-property.ts b/src/models/v2/ontologies/create/create-resource-property.ts index 21fd82350..ba80dfc04 100644 --- a/src/models/v2/ontologies/create/create-resource-property.ts +++ b/src/models/v2/ontologies/create/create-resource-property.ts @@ -31,6 +31,6 @@ export class CreateResourceProperty { guiElement?: string = undefined; @JsonProperty("guiAttributes", [String], true) - guiAttributes?: string[] = []; + guiAttributes?: string[] = undefined; } From 0ef4b7dcf94e209c559b0cd3b81d3e0102bf2c80 Mon Sep 17 00:00:00 2001 From: Tobias Schweizer Date: Thu, 17 Sep 2020 17:21:52 +0200 Subject: [PATCH 10/19] feature (ontologies endpoint): Add cardinality for a property on a resource class --- src/api/v2/ontology/ontologies-endpoint-v2.ts | 46 ++++++++++---- .../v2/ontology/ontologies-endpoint.spec.ts | 63 ++++++++++++++++--- ...ass-definition-with-property-definition.ts | 1 + .../has-cardinality-for-property-converter.ts | 41 +++++++++++- src/models/v2/ontologies/class-definition.ts | 5 ++ .../add-cardinality-to-resource-class.ts | 21 +++++++ 6 files changed, 156 insertions(+), 21 deletions(-) create mode 100644 src/models/v2/ontologies/create/add-cardinality-to-resource-class.ts diff --git a/src/api/v2/ontology/ontologies-endpoint-v2.ts b/src/api/v2/ontology/ontologies-endpoint-v2.ts index 8c486f0cb..e8cf770db 100644 --- a/src/api/v2/ontology/ontologies-endpoint-v2.ts +++ b/src/api/v2/ontology/ontologies-endpoint-v2.ts @@ -3,19 +3,26 @@ import { AjaxResponse } from "rxjs/ajax"; import { catchError, map, mergeMap } from "rxjs/operators"; import { ApiResponseError } from "../../../models/api-response-error"; import { Constants } from "../../../models/v2/Constants"; +import { AddCardinalityToResourceClass } from "../../../models/v2/ontologies/create/add-cardinality-to-resource-class"; import { CreateOntology } from "../../../models/v2/ontologies/create/create-ontology"; import { CreateResourceClass } from "../../../models/v2/ontologies/create/create-resource-class"; -import { CreateResourceClassPayload, NewResourceClass } from "../../../models/v2/ontologies/create/create-resource-class-payload"; +import { + CreateResourceClassPayload, + NewResourceClass +} from "../../../models/v2/ontologies/create/create-resource-class-payload"; +import { CreateResourceProperty } from "../../../models/v2/ontologies/create/create-resource-property"; +import { + CreateResourcePropertyPayload, + NewResourcePropertyPayload +} from "../../../models/v2/ontologies/create/create-resource-property-payload"; import { DeleteOntologyResponse } from "../../../models/v2/ontologies/delete/delete-ontology-response"; import { OntologiesMetadata, OntologyMetadata } from "../../../models/v2/ontologies/ontology-metadata"; import { OntologyConversionUtil } from "../../../models/v2/ontologies/OntologyConversionUtil"; import { ReadOntology } from "../../../models/v2/ontologies/read/read-ontology"; import { ResourceClassDefinitionWithAllLanguages } from "../../../models/v2/ontologies/resource-class-definition"; +import { ResourcePropertyDefinitionWithAllLanguages } from "../../../models/v2/ontologies/resource-property-definition"; import { UpdateOntology } from "../../../models/v2/ontologies/update-ontology"; import { Endpoint } from "../../endpoint"; -import { CreateResourceProperty } from "../../../models/v2/ontologies/create/create-resource-property"; -import { CreateResourcePropertyPayload, NewResourcePropertyPayload } from "../../../models/v2/ontologies/create/create-resource-property-payload"; -import { ResourcePropertyDefinitionWithAllLanguages } from "../../../models/v2/ontologies/resource-property-definition"; declare let require: any; // http://stackoverflow.com/questions/34730010/angular2-5-minute-install-bug-require-is-not-defined const jsonld = require("jsonld/dist/jsonld.js"); @@ -68,12 +75,11 @@ export class OntologiesEndpointV2 extends Endpoint { ); } - /** * Requests metadata about all ontologies from a specific project * * @param projectIri the IRI of the project - * @return OntologiesMetadata or an error + * @return OntologiesMetadata or an error */ getOntologiesByProjectIri(projectIri: string): Observable { @@ -94,7 +100,7 @@ export class OntologiesEndpointV2 extends Endpoint { /** * Creates a new ontology. - * + * * @param ontology The ontology to be created */ createOntology(ontology: CreateOntology): Observable { @@ -140,7 +146,7 @@ export class OntologiesEndpointV2 extends Endpoint { /** * Create a resource class without cardinalities - * + * * @param resClass The resource class to be created */ createResourceClass(resClass: CreateResourceClass): Observable { @@ -202,11 +208,11 @@ export class OntologiesEndpointV2 extends Endpoint { /** * Create a resource property - * + * * @param resProp The resource property to be created */ createResourceProperty(resProp: CreateResourceProperty): Observable { - + const resPropPayload = new CreateResourcePropertyPayload(); // prepare ontology data for payload @@ -225,14 +231,14 @@ export class OntologiesEndpointV2 extends Endpoint { newResProperty.subjectType = resProp.subjectType; newResProperty.objectType = resProp.objectType; - + if (resProp.guiElement) { newResProperty.guiElement = resProp.guiElement; } if (resProp.guiAttributes) { newResProperty.guiAttributes = resProp.guiAttributes; } - + resPropPayload.resProperty = [newResProperty]; const payload = this.jsonConvert.serializeObject(resPropPayload); @@ -271,6 +277,22 @@ export class OntologiesEndpointV2 extends Endpoint { }), catchError(error => this.handleError(error)) ); + } + + addCardinalityToResourceClass(addCardinalityToResourceClass: AddCardinalityToResourceClass): Observable { + + return this.httpPost("/cardinalities", this.jsonConvert.serializeObject(addCardinalityToResourceClass)).pipe( + mergeMap((ajaxResponse: AjaxResponse) => { + // TODO: @rosenth Adapt context object + // TODO: adapt getOntologyIriFromEntityIri + return jsonld.compact(ajaxResponse.response, {}); + }), map((jsonldobj: object) => { + return OntologyConversionUtil.convertResourceClassResponse(jsonldobj, this.jsonConvert); + }), + catchError(error => { + return this.handleError(error); + }) + ); } diff --git a/src/api/v2/ontology/ontologies-endpoint.spec.ts b/src/api/v2/ontology/ontologies-endpoint.spec.ts index 58631175c..c6f03eb7b 100644 --- a/src/api/v2/ontology/ontologies-endpoint.spec.ts +++ b/src/api/v2/ontology/ontologies-endpoint.spec.ts @@ -1,18 +1,26 @@ import { MockAjaxCall } from "../../../../test/mockajaxcall"; import { KnoraApiConfig } from "../../../knora-api-config"; import { KnoraApiConnection } from "../../../knora-api-connection"; +import { StringLiteral } from "../../../models/admin/string-literal"; +import { Constants } from "../../../models/v2/Constants"; +import { AddCardinalityToResourceClass } from "../../../models/v2/ontologies/create/add-cardinality-to-resource-class"; import { CreateOntology } from "../../../models/v2/ontologies/create/create-ontology"; import { CreateResourceClass } from "../../../models/v2/ontologies/create/create-resource-class"; +import { CreateResourceProperty } from "../../../models/v2/ontologies/create/create-resource-property"; import { DeleteOntologyResponse } from "../../../models/v2/ontologies/delete/delete-ontology-response"; import { OntologiesMetadata, OntologyMetadata } from "../../../models/v2/ontologies/ontology-metadata"; import { ReadOntology } from "../../../models/v2/ontologies/read/read-ontology"; -import { ResourceClassDefinition, ResourceClassDefinitionWithAllLanguages } from "../../../models/v2/ontologies/resource-class-definition"; -import { ResourcePropertyDefinition, ResourcePropertyDefinitionWithAllLanguages } from "../../../models/v2/ontologies/resource-property-definition"; +import { + ResourceClassDefinition, + ResourceClassDefinitionWithAllLanguages +} from "../../../models/v2/ontologies/resource-class-definition"; +import { + ResourcePropertyDefinition, + ResourcePropertyDefinitionWithAllLanguages +} from "../../../models/v2/ontologies/resource-property-definition"; import { SystemPropertyDefinition } from "../../../models/v2/ontologies/system-property-definition"; import { UpdateOntology } from "../../../models/v2/ontologies/update-ontology"; -import { CreateResourceProperty } from "../../../models/v2/ontologies/create/create-resource-property"; -import { Constants } from "../../../models/v2/Constants"; -import { StringLiteral } from "../../../models/admin/string-literal"; +import { Cardinality } from "../../../models/v2/ontologies/class-definition"; describe("OntologiesEndpoint", () => { @@ -367,7 +375,7 @@ describe("OntologiesEndpoint", () => { }); }); - + describe("Method createResourceProperty", () => { it("should create a new res property as supPropertyOf 'hasValue'", done => { @@ -508,7 +516,6 @@ describe("OntologiesEndpoint", () => { }); }); - /* TODO: NO TEST DATA available for delete-property-response describe("Method deleteResourceProperty", () => { @@ -543,4 +550,46 @@ describe("OntologiesEndpoint", () => { }); */ + describe("Method addCardinalityToResourceClass", () => { + + it("should add a max cardinality 1 to a resource class", done => { + + const addCard = new AddCardinalityToResourceClass(); + + addCard.id = "http://0.0.0.0:3333/ontology/0001/anything/v2"; + + addCard.lastModificationDate = "2017-12-19T15:23:42.166Z"; + + addCard.cardinalities = [ + { + propertyIndex: "http://0.0.0.0:3333/ontology/0001/anything/v2#hasOtherNothing", + cardinality: Cardinality._0_1, + isInherited: false, + resourceClass: "http://0.0.0.0:3333/ontology/0001/anything/v2#Nothing" + } + ]; + + knoraApiConnection.v2.onto.addCardinalityToResourceClass(addCard).subscribe( + (res: ResourceClassDefinitionWithAllLanguages) => { + expect(res.id).toEqual("http://0.0.0.0:3333/ontology/0001/anything/v2#Nothing"); + done(); + } + ); + + const request = jasmine.Ajax.requests.mostRecent(); + + const expectedPayload = require("../../../../test/data/api/v2/ontologies/add-cardinalities-to-class-nothing-request-expanded.json"); + expect(request.data()).toEqual(expectedPayload); + + const createCardResponse = require("../../../../test/data/api/v2/ontologies/add-cardinalities-to-class-nothing-response.json"); + request.respondWith(MockAjaxCall.mockResponse(JSON.stringify(createCardResponse))); + + expect(request.url).toBe("http://0.0.0.0:3333/v2/ontologies/cardinalities"); + + expect(request.method).toEqual("POST"); + + }); + + }); + }); diff --git a/src/cache/ontology-cache/resource-class-definition-with-property-definition.ts b/src/cache/ontology-cache/resource-class-definition-with-property-definition.ts index 73bda4366..7fe3487bf 100644 --- a/src/cache/ontology-cache/resource-class-definition-with-property-definition.ts +++ b/src/cache/ontology-cache/resource-class-definition-with-property-definition.ts @@ -38,6 +38,7 @@ export class ResourceClassDefinitionWithPropertyDefinition extends ResourceClass cardinality: prop.cardinality, guiOrder: prop.guiOrder, isInherited: prop.isInherited, + resourceClass: prop.resourceClass, propertyDefinition: propertyDefinitions[prop.propertyIndex] }; return propInfo; diff --git a/src/models/v2/custom-converters/has-cardinality-for-property-converter.ts b/src/models/v2/custom-converters/has-cardinality-for-property-converter.ts index 30b02e5f0..71b43ca18 100644 --- a/src/models/v2/custom-converters/has-cardinality-for-property-converter.ts +++ b/src/models/v2/custom-converters/has-cardinality-for-property-converter.ts @@ -1,11 +1,48 @@ import { JsonConverter, JsonCustomConvert } from "json2typescript"; +import { CustomConverterUtils } from "../../../util/utils"; import { Constants } from "../Constants"; import { Cardinality, IHasProperty } from "../ontologies/class-definition"; -import { CustomConverterUtils } from "../../../util/utils"; @JsonConverter export class HasCardinalityForPropertyConverter implements JsonCustomConvert { - serialize(hasProperties: IHasProperty[]): any { + serialize(cardinalities: IHasProperty[]): any { + + if (cardinalities.length === 0) { + throw new Error("At least one cardinality must be defined"); + } + + return cardinalities.map( + card => { + const cardEle: { [index: string]: number | string | object } = {}; + + cardEle["@type"] = Constants.Restriction; + cardEle[Constants.OnProperty] = { + "@id": card.propertyIndex + }; + + if (card.cardinality === Cardinality._0_1) { + cardEle[Constants.MaxCardinality] = 1; + } else if (card.cardinality === Cardinality._0_n) { + cardEle[Constants.MinCardinality] = 0; + } else if (card.cardinality === Cardinality._1_n) { + cardEle[Constants.MinCardinality] = 1; + } else if (card.cardinality === Cardinality._1) { + cardEle[Constants.Cardinality] = 1; + } else { + throw new Error("Invalid cardinalirty: " + card.cardinality); + } + + const cardObj: { [index: string]: string | object } = { + "@id": card.resourceClass as string, + "@type": Constants.Class + }; + + cardObj[Constants.SubClassOf] = cardEle; + + return cardObj; + } + ); + } deserialize(items: any): IHasProperty[] { diff --git a/src/models/v2/ontologies/class-definition.ts b/src/models/v2/ontologies/class-definition.ts index c87df1efd..38e687b11 100644 --- a/src/models/v2/ontologies/class-definition.ts +++ b/src/models/v2/ontologies/class-definition.ts @@ -46,6 +46,11 @@ export interface IHasProperty { * Indicates if the property has been inherited from a super class. */ isInherited: boolean; + + /** + * Iri of the resource class the property is defined on. + */ + resourceClass?: string; } /** diff --git a/src/models/v2/ontologies/create/add-cardinality-to-resource-class.ts b/src/models/v2/ontologies/create/add-cardinality-to-resource-class.ts new file mode 100644 index 000000000..4e85e3619 --- /dev/null +++ b/src/models/v2/ontologies/create/add-cardinality-to-resource-class.ts @@ -0,0 +1,21 @@ +import { JsonObject, JsonProperty } from "json2typescript"; +import { Constants } from "../../Constants"; +import { DateTimeStampConverter } from "../../custom-converters/date-time-stamp-converter"; +import { HasCardinalityForPropertyConverter } from "../../custom-converters/has-cardinality-for-property-converter"; +import { IHasProperty } from "../class-definition"; + +@JsonObject("AddCardinalityToResourceClass") +export class AddCardinalityToResourceClass { + + @JsonProperty("@id", String) + id: string; + + @JsonProperty("@type", String) + readonly type = Constants.Ontology; + + @JsonProperty(Constants.LastModificationDate, DateTimeStampConverter) + lastModificationDate: string; + + @JsonProperty("@graph", HasCardinalityForPropertyConverter) + cardinalities: IHasProperty[] = []; +} From f76239986521d7cf1f1708d583f63382c17798a2 Mon Sep 17 00:00:00 2001 From: Tobias Schweizer Date: Fri, 18 Sep 2020 10:25:08 +0200 Subject: [PATCH 11/19] fix (ontologies): fix typo --- .../custom-converters/has-cardinality-for-property-converter.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/models/v2/custom-converters/has-cardinality-for-property-converter.ts b/src/models/v2/custom-converters/has-cardinality-for-property-converter.ts index 71b43ca18..f643dc267 100644 --- a/src/models/v2/custom-converters/has-cardinality-for-property-converter.ts +++ b/src/models/v2/custom-converters/has-cardinality-for-property-converter.ts @@ -29,7 +29,7 @@ export class HasCardinalityForPropertyConverter implements JsonCustomConvert Date: Fri, 18 Sep 2020 10:45:50 +0200 Subject: [PATCH 12/19] refactor (ontologies): make isInherited prop optional --- src/api/v2/ontology/ontologies-endpoint.spec.ts | 1 - src/models/v2/custom-converters/subclass-of-converter.ts | 2 +- src/models/v2/ontologies/class-definition.ts | 4 +++- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/api/v2/ontology/ontologies-endpoint.spec.ts b/src/api/v2/ontology/ontologies-endpoint.spec.ts index c6f03eb7b..9d996d4a9 100644 --- a/src/api/v2/ontology/ontologies-endpoint.spec.ts +++ b/src/api/v2/ontology/ontologies-endpoint.spec.ts @@ -564,7 +564,6 @@ describe("OntologiesEndpoint", () => { { propertyIndex: "http://0.0.0.0:3333/ontology/0001/anything/v2#hasOtherNothing", cardinality: Cardinality._0_1, - isInherited: false, resourceClass: "http://0.0.0.0:3333/ontology/0001/anything/v2#Nothing" } ]; diff --git a/src/models/v2/custom-converters/subclass-of-converter.ts b/src/models/v2/custom-converters/subclass-of-converter.ts index b22378236..ef913aad8 100644 --- a/src/models/v2/custom-converters/subclass-of-converter.ts +++ b/src/models/v2/custom-converters/subclass-of-converter.ts @@ -8,7 +8,7 @@ export class SubClassOfConverter implements JsonCustomConvert { if (subclasses.length > 1) { const subClassOf: any = []; subclasses.forEach(item => { - subClassOf.push({ "@id": item }) + subClassOf.push({ "@id": item }); }); return subClassOf; diff --git a/src/models/v2/ontologies/class-definition.ts b/src/models/v2/ontologies/class-definition.ts index 38e687b11..9b4cf39d8 100644 --- a/src/models/v2/ontologies/class-definition.ts +++ b/src/models/v2/ontologies/class-definition.ts @@ -44,11 +44,13 @@ export interface IHasProperty { /** * Indicates if the property has been inherited from a super class. + * Only present when reading from Knora. */ - isInherited: boolean; + isInherited?: boolean; /** * Iri of the resource class the property is defined on. + * Only present when writing to Knora. */ resourceClass?: string; } From 65ef34a6b24c508859b1568ce5266c6049fe0b58 Mon Sep 17 00:00:00 2001 From: Tobias Schweizer Date: Fri, 18 Sep 2020 11:46:47 +0200 Subject: [PATCH 13/19] feature (test app): add method to add cardinality --- src/api/v2/ontology/ontologies-endpoint-v2.ts | 29 +++++----- test-framework/src/app/app.component.html | 3 + test-framework/src/app/app.component.ts | 57 +++++++++++++------ 3 files changed, 59 insertions(+), 30 deletions(-) diff --git a/src/api/v2/ontology/ontologies-endpoint-v2.ts b/src/api/v2/ontology/ontologies-endpoint-v2.ts index e8cf770db..39e8c3767 100644 --- a/src/api/v2/ontology/ontologies-endpoint-v2.ts +++ b/src/api/v2/ontology/ontologies-endpoint-v2.ts @@ -53,10 +53,9 @@ export class OntologiesEndpointV2 extends Endpoint { } /** - * Requests an ontology from Knora and converts it to a `ReadOntology`. + * Requests an ontology from Knora. * * @param ontologyIri the IRI of the ontology to be requested. - * @return the ontology or an error. */ getOntology(ontologyIri: string): Observable { @@ -76,10 +75,9 @@ export class OntologiesEndpointV2 extends Endpoint { } /** - * Requests metadata about all ontologies from a specific project + * Requests metadata about all ontologies from a specific project. * - * @param projectIri the IRI of the project - * @return OntologiesMetadata or an error + * @param projectIri the IRI of the project. */ getOntologiesByProjectIri(projectIri: string): Observable { @@ -145,9 +143,9 @@ export class OntologiesEndpointV2 extends Endpoint { } /** - * Create a resource class without cardinalities + * Creates a resource class without cardinalities. * - * @param resClass The resource class to be created + * @param resClass The resource class to be created. */ createResourceClass(resClass: CreateResourceClass): Observable { @@ -184,9 +182,9 @@ export class OntologiesEndpointV2 extends Endpoint { } /** - * Delete resource class + * Deletes a resource class * - * @param updateOntology with class IRI + * @param updateOntology with class IRI. */ deleteResourceClass(updateOntology: UpdateOntology): Observable { @@ -207,9 +205,9 @@ export class OntologiesEndpointV2 extends Endpoint { } /** - * Create a resource property + * Creates a resource property * - * @param resProp The resource property to be created + * @param resProp the resource property to be created. */ createResourceProperty(resProp: CreateResourceProperty): Observable { @@ -258,9 +256,9 @@ export class OntologiesEndpointV2 extends Endpoint { } /** - * Delete resource property + * Deletes a resource property. * - * @param updateOntology with property IRI + * @param updateOntology with property IRI. */ deleteResourceProperty(updateOntology: UpdateOntology): Observable { @@ -279,6 +277,11 @@ export class OntologiesEndpointV2 extends Endpoint { ); } + /** + * Adds cardinalities for properties to a resource class. + * + * @param addCardinalityToResourceClass the cardinailities to be added. + */ addCardinalityToResourceClass(addCardinalityToResourceClass: AddCardinalityToResourceClass): Observable { return this.httpPost("/cardinalities", this.jsonConvert.serializeObject(addCardinalityToResourceClass)).pipe( diff --git a/test-framework/src/app/app.component.html b/test-framework/src/app/app.component.html index b31ef4962..8346dd768 100644 --- a/test-framework/src/app/app.component.html +++ b/test-framework/src/app/app.component.html @@ -45,6 +45,7 @@

Ontology



Ontology created: {{ontologyMeta?.label}}



+

The ontology's label: {{ontology?.label}}

Before clicking on the following resource class or property action buttons, you should click each time on Get testonto button above. Because lastModification time is always needed.

@@ -64,6 +65,8 @@

Resource Property



+ +

Delete status: {{message}}

diff --git a/test-framework/src/app/app.component.ts b/test-framework/src/app/app.component.ts index 005a0853d..6c801d630 100644 --- a/test-framework/src/app/app.component.ts +++ b/test-framework/src/app/app.component.ts @@ -6,9 +6,13 @@ import { CountQueryResponse, CreateBooleanValue, CreateIntValue, + CreateOntology, CreateResource, + CreateResourceClass, CreateValue, + DeleteOntologyResponse, DeleteResource, + DeleteResourceResponse, DeleteValue, DeleteValueResponse, KnoraApiConfig, @@ -16,10 +20,13 @@ import { ListNodeV2, LoginResponse, OntologiesMetadata, + OntologyMetadata, ReadOntology, ReadResource, ReadResourceSequence, + ResourceClassDefinitionWithAllLanguages, UpdateIntValue, + UpdateOntology, UpdateResource, UpdateResourceMetadata, UpdateResourceMetadataResponse, @@ -27,22 +34,14 @@ import { UserCache, UserResponse, UsersResponse, - WriteValueResponse, - DeleteResourceResponse, - OntologyMetadata, - MockOntology, - MockProjects, - MockUsers, - CreateOntology, - DeleteOntologyResponse, - UpdateOntology, - ResourceClassDefinitionWithAllLanguages, - CreateResourceClass + WriteValueResponse } from "@dasch-swiss/dsp-js"; +import { CreateResourceProperty } from "@dasch-swiss/dsp-js/src/models/v2/ontologies/create/create-resource-property"; +import { ResourcePropertyDefinitionWithAllLanguages } from "@dasch-swiss/dsp-js/src/models/v2/ontologies/resource-property-definition"; import { map } from "rxjs/operators"; -import { CreateResourceProperty } from '@dasch-swiss/dsp-js/src/models/v2/ontologies/create/create-resource-property'; -import { ResourcePropertyDefinitionWithAllLanguages } from '@dasch-swiss/dsp-js/src/models/v2/ontologies/resource-property-definition'; +import { AddCardinalityToResourceClass } from "../../../src/models/v2/ontologies/create/add-cardinality-to-resource-class"; +import { Cardinality } from '../../../src/models/v2/ontologies/class-definition'; @Component({ selector: 'app-root', @@ -257,8 +256,9 @@ export class AppComponent implements OnInit { newResProp.ontology = { id: "http://0.0.0.0:3333/ontology/0001/anything/v2", - lastModificationDate: "2020-09-14T15:29:03.194356Z" + lastModificationDate: this.ontology.lastModificationDate }; + newResProp.name = "hasName"; newResProp.labels = [ @@ -286,7 +286,7 @@ export class AppComponent implements OnInit { newResProp.subPropertyOf = [Constants.HasValue, "http://schema.org/name"]; newResProp.objectType = Constants.TextValue; - newResProp.subjectType = "http://0.0.0.0:3333/ontology/0001/anything/v2#Thing"; + // newResProp.subjectType = "http://0.0.0.0:3333/ontology/0001/anything/v2#Thing"; newResProp.guiElement = "http://api.knora.org/ontology/salsah-gui/v2#SimpleText"; newResProp.guiAttributes = ["size=80", "maxlength=100"]; @@ -301,8 +301,7 @@ export class AppComponent implements OnInit { deleteResourceProperty() { const deleteResProp: UpdateOntology = new UpdateOntology(); deleteResProp.id = "http://0.0.0.0:3333/ontology/0001/anything/v2#hasName"; - deleteResProp.lastModificationDate = "2020-09-14T15:29:48.544437Z"; - // this.ontology.lastModificationDate; + deleteResProp.lastModificationDate = this.ontology.lastModificationDate; this.knoraApiConnection.v2.onto.deleteResourceProperty(deleteResProp).subscribe( (response: OntologyMetadata) => { @@ -316,6 +315,30 @@ export class AppComponent implements OnInit { } + addCardinality() { + + const addCard = new AddCardinalityToResourceClass(); + + addCard.lastModificationDate = this.ontology.lastModificationDate; + + addCard.id = "http://0.0.0.0:3333/ontology/0001/anything/v2"; + + addCard.cardinalities = [ + { + propertyIndex: "http://0.0.0.0:3333/ontology/0001/anything/v2#hasName", + cardinality: Cardinality._0_1, + resourceClass: "http://0.0.0.0:3333/ontology/0001/anything/v2#testclass" + } + ]; + + this.knoraApiConnection.v2.onto.addCardinalityToResourceClass(addCard).subscribe( + res => console.log(res) + ); + + + } + + getResourceClass(iri: string) { this.knoraApiConnection.v2.ontologyCache.getResourceClassDefinition(iri).subscribe( From a419211a67503f1d0bf28d07f56c2f5ab13eeb53 Mon Sep 17 00:00:00 2001 From: Tobias Schweizer Date: Fri, 18 Sep 2020 12:01:20 +0200 Subject: [PATCH 14/19] feature (test app): use unique name --- test-framework/src/app/app.component.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test-framework/src/app/app.component.html b/test-framework/src/app/app.component.html index 8346dd768..218ff105e 100644 --- a/test-framework/src/app/app.component.html +++ b/test-framework/src/app/app.component.html @@ -45,7 +45,7 @@

Ontology



Ontology created: {{ontologyMeta?.label}}



-

+

The ontology's label: {{ontology?.label}}

Before clicking on the following resource class or property action buttons, you should click each time on Get testonto button above. Because lastModification time is always needed.

From b7f0bcaadcc8a797a4509c996b100681a160615c Mon Sep 17 00:00:00 2001 From: Tobias Schweizer Date: Fri, 18 Sep 2020 12:28:50 +0200 Subject: [PATCH 15/19] fix (index.ts): add missing export --- src/index.ts | 1 + test-framework/src/app/app.component.ts | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/index.ts b/src/index.ts index e88706e03..957914a87 100644 --- a/src/index.ts +++ b/src/index.ts @@ -82,6 +82,7 @@ export { UpdateOntology } from "./models/v2/ontologies/update-ontology"; export { DeleteOntologyResponse } from "./models/v2/ontologies/delete/delete-ontology-response"; export { CreateResourceClass } from "./models/v2/ontologies/create/create-resource-class"; export { ReadOntology } from "./models/v2/ontologies/read/read-ontology"; +export { AddCardinalityToResourceClass } from "./models/v2/ontologies/create/add-cardinality-to-resource-class"; export { OntologyMetadata, OntologiesMetadata } from "./models/v2/ontologies/ontology-metadata"; export { ResourceClassDefinitionWithPropertyDefinition, diff --git a/test-framework/src/app/app.component.ts b/test-framework/src/app/app.component.ts index 6c801d630..787fc967b 100644 --- a/test-framework/src/app/app.component.ts +++ b/test-framework/src/app/app.component.ts @@ -34,14 +34,14 @@ import { UserCache, UserResponse, UsersResponse, - WriteValueResponse + WriteValueResponse, + Cardinality, + AddCardinalityToResourceClass } from "@dasch-swiss/dsp-js"; import { CreateResourceProperty } from "@dasch-swiss/dsp-js/src/models/v2/ontologies/create/create-resource-property"; import { ResourcePropertyDefinitionWithAllLanguages } from "@dasch-swiss/dsp-js/src/models/v2/ontologies/resource-property-definition"; import { map } from "rxjs/operators"; -import { AddCardinalityToResourceClass } from "../../../src/models/v2/ontologies/create/add-cardinality-to-resource-class"; -import { Cardinality } from '../../../src/models/v2/ontologies/class-definition'; @Component({ selector: 'app-root', From 2cdeb527474756e21e41987652217bd97f658465 Mon Sep 17 00:00:00 2001 From: Tobias Schweizer Date: Tue, 22 Sep 2020 09:33:44 +0200 Subject: [PATCH 16/19] feature (test app): use testonto consistently --- src/api/v2/ontology/ontologies-endpoint.spec.ts | 2 -- test-framework/src/app/app.component.html | 1 - test-framework/src/app/app.component.ts | 10 +++++----- 3 files changed, 5 insertions(+), 8 deletions(-) diff --git a/src/api/v2/ontology/ontologies-endpoint.spec.ts b/src/api/v2/ontology/ontologies-endpoint.spec.ts index 9d996d4a9..ce40bb24e 100644 --- a/src/api/v2/ontology/ontologies-endpoint.spec.ts +++ b/src/api/v2/ontology/ontologies-endpoint.spec.ts @@ -517,7 +517,6 @@ describe("OntologiesEndpoint", () => { }); - /* TODO: NO TEST DATA available for delete-property-response describe("Method deleteResourceProperty", () => { it("should delete a resource property", done => { @@ -548,7 +547,6 @@ describe("OntologiesEndpoint", () => { }); }); - */ describe("Method addCardinalityToResourceClass", () => { diff --git a/test-framework/src/app/app.component.html b/test-framework/src/app/app.component.html index 218ff105e..e1f394fae 100644 --- a/test-framework/src/app/app.component.html +++ b/test-framework/src/app/app.component.html @@ -45,7 +45,6 @@

Ontology



Ontology created: {{ontologyMeta?.label}}



-

The ontology's label: {{ontology?.label}}

Before clicking on the following resource class or property action buttons, you should click each time on Get testonto button above. Because lastModification time is always needed.

diff --git a/test-framework/src/app/app.component.ts b/test-framework/src/app/app.component.ts index 787fc967b..7d2acaae6 100644 --- a/test-framework/src/app/app.component.ts +++ b/test-framework/src/app/app.component.ts @@ -255,7 +255,7 @@ export class AppComponent implements OnInit { const newResProp = new CreateResourceProperty(); newResProp.ontology = { - id: "http://0.0.0.0:3333/ontology/0001/anything/v2", + id: this.ontology.id, lastModificationDate: this.ontology.lastModificationDate }; @@ -300,7 +300,7 @@ export class AppComponent implements OnInit { deleteResourceProperty() { const deleteResProp: UpdateOntology = new UpdateOntology(); - deleteResProp.id = "http://0.0.0.0:3333/ontology/0001/anything/v2#hasName"; + deleteResProp.id = "http://0.0.0.0:3333/ontology/0001/testonto/v2#hasName"; deleteResProp.lastModificationDate = this.ontology.lastModificationDate; this.knoraApiConnection.v2.onto.deleteResourceProperty(deleteResProp).subscribe( @@ -321,13 +321,13 @@ export class AppComponent implements OnInit { addCard.lastModificationDate = this.ontology.lastModificationDate; - addCard.id = "http://0.0.0.0:3333/ontology/0001/anything/v2"; + addCard.id = this.ontology.id; addCard.cardinalities = [ { - propertyIndex: "http://0.0.0.0:3333/ontology/0001/anything/v2#hasName", + propertyIndex: "http://0.0.0.0:3333/ontology/0001/testonto/v2#hasName", cardinality: Cardinality._0_1, - resourceClass: "http://0.0.0.0:3333/ontology/0001/anything/v2#testclass" + resourceClass: "http://0.0.0.0:3333/ontology/0001/testonto/v2#testclass" } ]; From 34dba9e87eb52c508afff1b4a77c16a4c8aaee10 Mon Sep 17 00:00:00 2001 From: Tobias Schweizer Date: Tue, 22 Sep 2020 11:21:28 +0200 Subject: [PATCH 17/19] test (e2e): test property creation --- test-framework/e2e/src/app.e2e-spec.ts | 22 ++++++++++++++++++++++ test-framework/src/app/app.component.html | 2 +- test-framework/src/app/app.component.ts | 2 ++ 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/test-framework/e2e/src/app.e2e-spec.ts b/test-framework/e2e/src/app.e2e-spec.ts index ec134e27d..a7548885c 100644 --- a/test-framework/e2e/src/app.e2e-spec.ts +++ b/test-framework/e2e/src/app.e2e-spec.ts @@ -159,6 +159,28 @@ describe('workspace-project App', () => { }); + it('create a new property in testonto of the anything project', () => { + + page.navigateTo(); + + // login + const loginButton = page.getEle('div section#login button.login'); + loginButton.click(); + const loginStatus = page.getEle('div section#login span.status'); + expect(loginStatus.getText()).toEqual('logged in'); + + // get testonto to have lastModificationDate + const getButton = page.getEle('div section#ontologyeditor button.read-onto'); + getButton.click(); + + // create property + const button = page.getEle('div section#ontologyeditor button.create-res-prop'); + button.click(); + const label = page.getEle('div section#ontologyeditor span.res-prop-label'); + + expect(label.getText()).toEqual('has name'); + }); + it('delete "testclass" resource class', () => { page.navigateTo(); diff --git a/test-framework/src/app/app.component.html b/test-framework/src/app/app.component.html index e1f394fae..ca3b32713 100644 --- a/test-framework/src/app/app.component.html +++ b/test-framework/src/app/app.component.html @@ -59,7 +59,7 @@

Resource Class

Resource Property



- +
Res property created: {{property?.label}}

diff --git a/test-framework/src/app/app.component.ts b/test-framework/src/app/app.component.ts index 7d2acaae6..6f2e25362 100644 --- a/test-framework/src/app/app.component.ts +++ b/test-framework/src/app/app.component.ts @@ -60,6 +60,7 @@ export class AppComponent implements OnInit { ontologyMeta: OntologyMetadata; ontology: ReadOntology; resClass: ResourceClassDefinitionWithAllLanguages; + property: ResourcePropertyDefinitionWithAllLanguages; // reusable response message message: string; @@ -293,6 +294,7 @@ export class AppComponent implements OnInit { this.knoraApiConnection.v2.onto.createResourceProperty(newResProp).subscribe( (response: ResourcePropertyDefinitionWithAllLanguages) => { + this.property = response; console.log('new resource property created', response); } ); From b5e95daeadf88db0a2f5aaadd4a9423aa3937866 Mon Sep 17 00:00:00 2001 From: Tobias Schweizer Date: Tue, 22 Sep 2020 11:30:56 +0200 Subject: [PATCH 18/19] test (e2e): test adding a cardinality --- test-framework/e2e/src/app.e2e-spec.ts | 23 +++++++++++++++++++++++ test-framework/src/app/app.component.html | 3 ++- test-framework/src/app/app.component.ts | 6 +++++- 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/test-framework/e2e/src/app.e2e-spec.ts b/test-framework/e2e/src/app.e2e-spec.ts index a7548885c..c9265a8c8 100644 --- a/test-framework/e2e/src/app.e2e-spec.ts +++ b/test-framework/e2e/src/app.e2e-spec.ts @@ -181,6 +181,29 @@ describe('workspace-project App', () => { expect(label.getText()).toEqual('has name'); }); + it('add a cardinality to a resource class in testonto', () => { + + page.navigateTo(); + + // login + const loginButton = page.getEle('div section#login button.login'); + loginButton.click(); + const loginStatus = page.getEle('div section#login span.status'); + expect(loginStatus.getText()).toEqual('logged in'); + + // get testonto to have lastModificationDate + const getButton = page.getEle('div section#ontologyeditor button.read-onto'); + getButton.click(); + + // add cardinality + const button = page.getEle('div section#ontologyeditor button.add-card-to-res-prop'); + button.click(); + const label = page.getEle('div section#ontologyeditor span.res-card-added'); + + expect(label.getText()).toEqual('Test Klasse'); + + }); + it('delete "testclass" resource class', () => { page.navigateTo(); diff --git a/test-framework/src/app/app.component.html b/test-framework/src/app/app.component.html index ca3b32713..d5255fbbc 100644 --- a/test-framework/src/app/app.component.html +++ b/test-framework/src/app/app.component.html @@ -66,7 +66,8 @@

Resource Property





- +
Cardinality added: {{addCard?.label}}

+
Delete status: {{message}}

diff --git a/test-framework/src/app/app.component.ts b/test-framework/src/app/app.component.ts index 6f2e25362..15af7ebc5 100644 --- a/test-framework/src/app/app.component.ts +++ b/test-framework/src/app/app.component.ts @@ -61,6 +61,7 @@ export class AppComponent implements OnInit { ontology: ReadOntology; resClass: ResourceClassDefinitionWithAllLanguages; property: ResourcePropertyDefinitionWithAllLanguages; + addCard: ResourceClassDefinitionWithAllLanguages; // reusable response message message: string; @@ -334,7 +335,10 @@ export class AppComponent implements OnInit { ]; this.knoraApiConnection.v2.onto.addCardinalityToResourceClass(addCard).subscribe( - res => console.log(res) + (res: ResourceClassDefinitionWithAllLanguages) => { + this.addCard = res; + console.log('added card: ', res) + } ); From 1f9087cda96b2268b5323673eb5c6b85b7ead301 Mon Sep 17 00:00:00 2001 From: Tobias Schweizer Date: Tue, 22 Sep 2020 11:40:38 +0200 Subject: [PATCH 19/19] test (e2e): test property deletion --- test-framework/e2e/src/app.e2e-spec.ts | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/test-framework/e2e/src/app.e2e-spec.ts b/test-framework/e2e/src/app.e2e-spec.ts index c9265a8c8..03a525037 100644 --- a/test-framework/e2e/src/app.e2e-spec.ts +++ b/test-framework/e2e/src/app.e2e-spec.ts @@ -226,6 +226,29 @@ describe('workspace-project App', () => { }); + it('delete "has name" property', () => { + + page.navigateTo(); + + // login + const loginButton = page.getEle('div section#login button.login'); + loginButton.click(); + const loginStatus = page.getEle('div section#login span.status'); + expect(loginStatus.getText()).toEqual('logged in'); + + // get testonto to have lastModificationDate + const getButton = page.getEle('div section#ontologyeditor button.read-onto'); + getButton.click(); + + // delete property + const button = page.getEle('div section#ontologyeditor button.delete-res-prop'); + button.click(); + const msg = page.getEle('div section#ontologyeditor span.status'); + expect(msg.getText()).toEqual('res property has been deleted'); + + + }); + it('delete "testonto" ontology', () => { page.navigateTo();