diff --git a/Makefile b/Makefile index d2ae2d995..efbe4da08 100644 --- a/Makefile +++ b/Makefile @@ -81,7 +81,7 @@ e2e-tests: ## runs the e2e tests sudo npm install yalc -g npm run prepare-dev-publication npm run yalc-publish - cd test-framework && yalc remove --all && yalc add @dasch-swiss/dsp-js && npm install && npm run webdriver-update && npm run e2e && npm run build-app && docker build . + cd test-framework && yalc add @dasch-swiss/dsp-js && npm install && npm run webdriver-update && npm run e2e && npm run build-app && docker build . .PHONY: build build: ## builds the lib diff --git a/src/api/v2/ontology/ontologies-endpoint-v2.ts b/src/api/v2/ontology/ontologies-endpoint-v2.ts index 39e8c3767..3bd7d1200 100644 --- a/src/api/v2/ontology/ontologies-endpoint-v2.ts +++ b/src/api/v2/ontology/ontologies-endpoint-v2.ts @@ -3,25 +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 { CreateResourceProperty } from "../../../models/v2/ontologies/create/create-resource-property"; + CreateResourceClass, + CreateResourceClassPayload +} from "../../../models/v2/ontologies/create/create-resource-class"; import { - CreateResourcePropertyPayload, - NewResourcePropertyPayload -} from "../../../models/v2/ontologies/create/create-resource-property-payload"; + CreateResourceProperty, + CreateResourcePropertyPayload +} from "../../../models/v2/ontologies/create/create-resource-property"; +import { DeleteOntology } from "../../../models/v2/ontologies/delete/delete-ontology"; import { DeleteOntologyResponse } from "../../../models/v2/ontologies/delete/delete-ontology-response"; +import { DeleteResourceClass } from "../../../models/v2/ontologies/delete/delete-resource-class"; +import { DeleteResourceProperty } from "../../../models/v2/ontologies/delete/delete-resource-property"; 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 { UpdateOntology } from "../../../models/v2/ontologies/update/update-ontology"; +import { UpdateOntologyResourceClassCardinality } from "../../../models/v2/ontologies/update/update-ontology-resource-class-cardinality"; import { Endpoint } from "../../endpoint"; declare let require: any; // http://stackoverflow.com/questions/34730010/angular2-5-minute-install-bug-require-is-not-defined @@ -37,7 +38,6 @@ export class OntologiesEndpointV2 extends Endpoint { */ getOntologiesMetadata(): Observable { - // TODO: Do not hard-code the URL and http call params, generate this from Knora return this.httpGet("/metadata").pipe( mergeMap((ajaxResponse: AjaxResponse) => { // TODO: @rosenth Adapt context object @@ -124,7 +124,7 @@ export class OntologiesEndpointV2 extends Endpoint { * * @param ontology the ontology to be deleted. */ - deleteOntology(ontology: UpdateOntology): Observable { + deleteOntology(ontology: DeleteOntology): Observable { const path = "/" + encodeURIComponent(ontology.id) + "?lastModificationDate=" + encodeURIComponent(ontology.lastModificationDate); @@ -145,29 +145,23 @@ export class OntologiesEndpointV2 extends Endpoint { /** * Creates a resource class without cardinalities. * - * @param resClass The resource class to be created. + * @param resourceClasses The resource class to be created. */ - createResourceClass(resClass: CreateResourceClass): Observable { - - const resClassPayload = new CreateResourceClassPayload(); + createResourceClass(resourceClasses: UpdateOntology): Observable { - // prepare ontology data for payload - resClassPayload.id = resClass.ontology.id; - resClassPayload.lastModificationDate = resClass.ontology.lastModificationDate; + const resClassPay = new CreateResourceClassPayload(); - // prepare new res class object for payload - const newResClass = new NewResourceClass(); - newResClass.id = resClass.ontology.id + Constants.Delimiter + resClass.name; - newResClass.label = resClass.labels; - newResClass.comment = (resClass.comments.length ? resClass.comments : resClass.labels); - newResClass.subClassOf = resClass.subClassOf; - newResClass.type = Constants.Class; + resClassPay.id = resourceClasses.id + Constants.Delimiter + resourceClasses.entity.name; + resClassPay.label = resourceClasses.entity.label; + resClassPay.comment = (resourceClasses.entity.comment.length ? resourceClasses.entity.comment : resourceClasses.entity.label); + resClassPay.subClassOf = resourceClasses.entity.subClassOf; + resClassPay.type = Constants.Class; - resClassPayload.resClass = [newResClass]; + const ontoPayload = this.jsonConvert.serializeObject(resourceClasses); - const payload = this.jsonConvert.serializeObject(resClassPayload); + ontoPayload["@graph"] = [this.jsonConvert.serializeObject(resClassPay)]; - return this.httpPost("/classes", payload).pipe( + return this.httpPost("/classes", ontoPayload).pipe( mergeMap((ajaxResponse: AjaxResponse) => { // TODO: @rosenth Adapt context object // TODO: adapt getOntologyIriFromEntityIri @@ -182,13 +176,13 @@ export class OntologiesEndpointV2 extends Endpoint { } /** - * Deletes a resource class + * Deletes a resource class. * - * @param updateOntology with class IRI. + * @param deleteResourceClass with class IRI. */ - deleteResourceClass(updateOntology: UpdateOntology): Observable { + deleteResourceClass(deleteResourceClass: DeleteResourceClass): Observable { - const path = "/classes/" + encodeURIComponent(updateOntology.id) + "?lastModificationDate=" + encodeURIComponent(updateOntology.lastModificationDate); + const path = "/classes/" + encodeURIComponent(deleteResourceClass.id) + "?lastModificationDate=" + encodeURIComponent(deleteResourceClass.lastModificationDate); return this.httpDelete(path).pipe( mergeMap((ajaxResponse: AjaxResponse) => { @@ -205,43 +199,35 @@ export class OntologiesEndpointV2 extends Endpoint { } /** - * Creates a resource property + * Creates a resource property. * - * @param resProp the resource property to be created. + * @param resourceProperties 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; + createResourceProperty(resourceProperties: UpdateOntology): Observable { - // prepare new res class object for payload - const newResProperty = new NewResourcePropertyPayload(); + const resPropPay = new CreateResourcePropertyPayload(); - newResProperty.id = resProp.ontology.id + Constants.Delimiter + resProp.name; + resPropPay.id = resourceProperties.id + Constants.Delimiter + resourceProperties.entity.name; - newResProperty.label = resProp.labels; - newResProperty.comment = (resProp.comments.length ? resProp.comments : resProp.labels); - newResProperty.subPropertyOf = resProp.subPropertyOf; - newResProperty.type = Constants.ObjectProperty; + resPropPay.label = resourceProperties.entity.label; + resPropPay.comment = (resourceProperties.entity.comment.length ? resourceProperties.entity.comment : resourceProperties.entity.label); + resPropPay.subPropertyOf = resourceProperties.entity.subPropertyOf; - newResProperty.subjectType = resProp.subjectType; - newResProperty.objectType = resProp.objectType; + resPropPay.subjectType = resourceProperties.entity.subjectType; + resPropPay.objectType = resourceProperties.entity.objectType; - if (resProp.guiElement) { - newResProperty.guiElement = resProp.guiElement; + if (resourceProperties.entity.guiElement) { + resPropPay.guiElement = resourceProperties.entity.guiElement; } - if (resProp.guiAttributes) { - newResProperty.guiAttributes = resProp.guiAttributes; + if (resourceProperties.entity.guiAttributes) { + resPropPay.guiAttributes = resourceProperties.entity.guiAttributes; } - resPropPayload.resProperty = [newResProperty]; + const ontoPayload = this.jsonConvert.serializeObject(resourceProperties); - const payload = this.jsonConvert.serializeObject(resPropPayload); + ontoPayload["@graph"] = [this.jsonConvert.serializeObject(resPropPay)]; - return this.httpPost("/properties", payload).pipe( + return this.httpPost("/properties", ontoPayload).pipe( mergeMap((ajaxResponse: AjaxResponse) => { // TODO: @rosenth Adapt context object // TODO: adapt getOntologyIriFromEntityIri @@ -258,11 +244,11 @@ export class OntologiesEndpointV2 extends Endpoint { /** * Deletes a resource property. * - * @param updateOntology with property IRI. + * @param deleteResourceProperty with property IRI. */ - deleteResourceProperty(updateOntology: UpdateOntology): Observable { + deleteResourceProperty(deleteResourceProperty: DeleteResourceProperty): Observable { - const path = "/properties/" + encodeURIComponent(updateOntology.id) + "?lastModificationDate=" + encodeURIComponent(updateOntology.lastModificationDate); + const path = "/properties/" + encodeURIComponent(deleteResourceProperty.id) + "?lastModificationDate=" + encodeURIComponent(deleteResourceProperty.lastModificationDate); return this.httpDelete(path).pipe( mergeMap((ajaxResponse: AjaxResponse) => { @@ -282,7 +268,7 @@ export class OntologiesEndpointV2 extends Endpoint { * * @param addCardinalityToResourceClass the cardinailities to be added. */ - addCardinalityToResourceClass(addCardinalityToResourceClass: AddCardinalityToResourceClass): Observable { + addCardinalityToResourceClass(addCardinalityToResourceClass: UpdateOntologyResourceClassCardinality): Observable { return this.httpPost("/cardinalities", this.jsonConvert.serializeObject(addCardinalityToResourceClass)).pipe( mergeMap((ajaxResponse: AjaxResponse) => { diff --git a/src/api/v2/ontology/ontologies-endpoint.spec.ts b/src/api/v2/ontology/ontologies-endpoint.spec.ts index ce40bb24e..ac0a3993e 100644 --- a/src/api/v2/ontology/ontologies-endpoint.spec.ts +++ b/src/api/v2/ontology/ontologies-endpoint.spec.ts @@ -1,13 +1,13 @@ 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 { UpdateOntologyResourceClassCardinality } from "../../../models/v2/ontologies/update/update-ontology-resource-class-cardinality"; 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 { DeleteResourceClass } from "../../../models/v2/ontologies/delete/delete-resource-class"; import { OntologiesMetadata, OntologyMetadata } from "../../../models/v2/ontologies/ontology-metadata"; import { ReadOntology } from "../../../models/v2/ontologies/read/read-ontology"; import { @@ -19,8 +19,11 @@ import { 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 { UpdateOntology } from "../../../models/v2/ontologies/update/update-ontology"; import { Cardinality } from "../../../models/v2/ontologies/class-definition"; +import { DeleteOntology } from "../../../models/v2/ontologies/delete/delete-ontology"; +import { DeleteResourceProperty } from "../../../models/v2/ontologies/delete/delete-resource-property"; +import { StringLiteralV2 } from "../../../models/v2/string-literal-v2"; describe("OntologiesEndpoint", () => { @@ -268,7 +271,7 @@ describe("OntologiesEndpoint", () => { describe("Method deleteOntology", () => { it("should delete an ontology", done => { - const ontoInfo = new UpdateOntology(); + const ontoInfo = new DeleteOntology(); ontoInfo.id = "http://0.0.0.0:3333/ontology/00FF/foo/v2"; @@ -297,31 +300,37 @@ describe("OntologiesEndpoint", () => { }); describe("Method createResourceClass", () => { + it("should create a new res class and add it to anything ontology", done => { + const onto = new UpdateOntology(); + + onto.id = "http://0.0.0.0:3333/ontology/0001/anything/v2"; + onto.lastModificationDate = "2017-12-19T15:23:42.166Z"; + const newResClass = new CreateResourceClass(); - newResClass.ontology = { - id: "http://0.0.0.0:3333/ontology/0001/anything/v2", - lastModificationDate: "2017-12-19T15:23:42.166Z" - }; newResClass.name = "Nothing"; - newResClass.comments = [ - { - language: "en", - value: "Represents nothing" - } - ]; - newResClass.labels = [ - { - language: "en", - value: "nothing" - } - ]; + const comment = new StringLiteralV2(); + + comment.language = "en"; + comment.value = "Represents nothing"; + + newResClass.comment = [comment]; + + const label = new StringLiteralV2(); + + label.language = "en"; + label.value = "nothing"; + + newResClass.label = [label]; + newResClass.subClassOf = ["http://api.knora.org/ontology/knora-api/v2#Resource"]; - knoraApiConnection.v2.onto.createResourceClass(newResClass).subscribe( + onto.entity = newResClass; + + knoraApiConnection.v2.onto.createResourceClass(onto).subscribe( (response: ResourceClassDefinitionWithAllLanguages) => { // console.log('new resource class created', response); expect(response.id).toBe("http://0.0.0.0:3333/ontology/0001/anything/v2#Nothing"); @@ -346,9 +355,10 @@ describe("OntologiesEndpoint", () => { }); describe("Method deleteResourceClass", () => { + it("should delete a resource class", done => { - const resclass = new UpdateOntology(); + const resclass = new DeleteResourceClass(); resclass.id = "http://0.0.0.0:3333/ontology/0001/anything/v2#Nothing"; @@ -380,43 +390,41 @@ describe("OntologiesEndpoint", () => { it("should create a new res property as supPropertyOf 'hasValue'", done => { - const newResProp = new CreateResourceProperty(); - - const onto = new UpdateOntology(); + 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; + const newResProp = new CreateResourceProperty(); newResProp.name = "hasName"; - const label1 = new StringLiteral(); + const label1 = new StringLiteralV2(); label1.language = "en"; label1.value = "has name"; - const label2 = new StringLiteral(); + const label2 = new StringLiteralV2(); label2.language = "de"; label2.value = "hat Namen"; - newResProp.labels = [ + newResProp.label = [ label1, label2 ]; - const comment1 = new StringLiteral(); + const comment1 = new StringLiteralV2(); comment1.language = "en"; comment1.value = "The name of a Thing"; - const comment2 = new StringLiteral(); + const comment2 = new StringLiteralV2(); comment2.language = "de"; comment2.value = "Der Name eines Dinges"; - newResProp.comments = [ + newResProp.comment = [ comment1, comment2 ]; @@ -434,7 +442,9 @@ describe("OntologiesEndpoint", () => { newResProp.guiAttributes = ["size=80", "maxlength=100"]; - knoraApiConnection.v2.onto.createResourceProperty(newResProp).subscribe( + onto.entity = newResProp; + + knoraApiConnection.v2.onto.createResourceProperty(onto).subscribe( (response: ResourcePropertyDefinitionWithAllLanguages) => { expect(response.id).toBe("http://0.0.0.0:3333/ontology/0001/anything/v2#hasName"); done(); @@ -457,32 +467,30 @@ describe("OntologiesEndpoint", () => { it("should create a new res property as supPropertyOf 'hasLinkTo'", done => { - const newResProp = new CreateResourceProperty(); - - const onto = new UpdateOntology(); + 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; + const newResProp = new CreateResourceProperty(); newResProp.name = "hasOtherNothing"; - const label1 = new StringLiteral(); + const label1 = new StringLiteralV2(); label1.language = "en"; label1.value = "has nothingness"; - newResProp.labels = [ + newResProp.label = [ label1 ]; - const comment1 = new StringLiteral(); + const comment1 = new StringLiteralV2(); comment1.language = "en"; comment1.value = "Refers to the other Nothing of a Nothing"; - newResProp.comments = [ + newResProp.comment = [ comment1 ]; @@ -494,7 +502,9 @@ describe("OntologiesEndpoint", () => { newResProp.subjectType = "http://0.0.0.0:3333/ontology/0001/anything/v2#Nothing"; - knoraApiConnection.v2.onto.createResourceProperty(newResProp).subscribe( + onto.entity = newResProp; + + knoraApiConnection.v2.onto.createResourceProperty(onto).subscribe( (response: ResourcePropertyDefinitionWithAllLanguages) => { expect(response.id).toBe("http://0.0.0.0:3333/ontology/0001/anything/v2#hasOtherNothing"); done(); @@ -518,9 +528,10 @@ describe("OntologiesEndpoint", () => { }); describe("Method deleteResourceProperty", () => { + it("should delete a resource property", done => { - const resprop = new UpdateOntology(); + const resprop = new DeleteResourceProperty(); resprop.id = "http://0.0.0.0:3333/ontology/00FF/images/v2#titel"; @@ -552,7 +563,7 @@ describe("OntologiesEndpoint", () => { it("should add a max cardinality 1 to a resource class", done => { - const addCard = new AddCardinalityToResourceClass(); + const addCard = new UpdateOntologyResourceClassCardinality(); addCard.id = "http://0.0.0.0:3333/ontology/0001/anything/v2"; diff --git a/src/index.ts b/src/index.ts index 957914a87..8112c32d1 100644 --- a/src/index.ts +++ b/src/index.ts @@ -78,11 +78,14 @@ export { ApiResponseData } from "./models/api-response-data"; export { ApiResponseError } from "./models/api-response-error"; export { CreateOntology } from "./models/v2/ontologies/create/create-ontology"; -export { UpdateOntology } from "./models/v2/ontologies/update-ontology"; +export { UpdateOntology } from "./models/v2/ontologies/update/update-ontology"; +export { DeleteOntology } from "./models/v2/ontologies/delete/delete-ontology"; +export { DeleteResourceClass } from "./models/v2/ontologies/delete/delete-resource-class"; +export { DeleteResourceProperty } from "./models/v2/ontologies/delete/delete-resource-property"; 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 { UpdateOntologyResourceClassCardinality } from "./models/v2/ontologies/update/update-ontology-resource-class-cardinality"; export { OntologyMetadata, OntologiesMetadata } from "./models/v2/ontologies/ontology-metadata"; export { ResourceClassDefinitionWithPropertyDefinition, diff --git a/src/models/v2/ontologies/create/create-resource-class-payload.ts b/src/models/v2/ontologies/create/create-resource-class-payload.ts deleted file mode 100644 index 3782a5bca..000000000 --- a/src/models/v2/ontologies/create/create-resource-class-payload.ts +++ /dev/null @@ -1,45 +0,0 @@ -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"; - - -// Resource class data as part of CreateResourceClassPayload -@JsonObject("NewResourceClass") -export class NewResourceClass { - @JsonProperty("@id", String) - id: string = ""; - - @JsonProperty("@type", String, true) - type: string = Constants.Class; - - @JsonProperty(Constants.Label, StringLiteralToStringLiteralArrayConverter) - label: StringLiteralV2[] = []; - - @JsonProperty(Constants.Comment, StringLiteralToStringLiteralArrayConverter) - comment: StringLiteralV2[] = []; - - @JsonProperty(Constants.SubClassOf, SubClassOfConverter) - subClassOf: string[] = []; -} - -// Resource class data payload: This will be sent to the api -@JsonObject("CreateResourceClassPayload") -export class CreateResourceClassPayload { - - // 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", [NewResourceClass]) - resClass: NewResourceClass[] = []; -} \ No newline at end of file diff --git a/src/models/v2/ontologies/create/create-resource-class.ts b/src/models/v2/ontologies/create/create-resource-class.ts index 07f567a55..e17416401 100644 --- a/src/models/v2/ontologies/create/create-resource-class.ts +++ b/src/models/v2/ontologies/create/create-resource-class.ts @@ -1,23 +1,31 @@ import { JsonObject, JsonProperty } from "json2typescript"; -import { StringLiteral } from "../../../admin/string-literal"; -import { UpdateOntology } from "../update-ontology"; +import { Constants } from "../../Constants"; +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"; -// Resource class data to be used in createResourceClass method @JsonObject("CreateResourceClass") export class CreateResourceClass { - @JsonProperty("ontology", UpdateOntology) - ontology: UpdateOntology = new UpdateOntology(); - - @JsonProperty("name", String) name: string = ""; - @JsonProperty("labels", [StringLiteral]) - labels: StringLiteral[] = []; + @JsonProperty("@type", String, true) + type: string = Constants.Class; + + @JsonProperty(Constants.Label, StringLiteralToStringLiteralArrayConverter) + label: StringLiteralV2[] = []; - @JsonProperty("comments", [StringLiteral], true) - comments: StringLiteral[] = []; + @JsonProperty(Constants.Comment, StringLiteralToStringLiteralArrayConverter) + comment: StringLiteralV2[] = []; - @JsonProperty("subClassOf", [String]) + @JsonProperty(Constants.SubClassOf, SubClassOfConverter) subClassOf: string[] = []; } + +@JsonObject("CreateResourceClassPayload") +export class CreateResourceClassPayload extends CreateResourceClass { + + @JsonProperty("@id", String) + id: string = ""; + +} diff --git a/src/models/v2/ontologies/create/create-resource-property-payload.ts b/src/models/v2/ontologies/create/create-resource-property-payload.ts deleted file mode 100644 index 6d3cbf762..000000000 --- a/src/models/v2/ontologies/create/create-resource-property-payload.ts +++ /dev/null @@ -1,58 +0,0 @@ -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("NewResourcePropertyPayload") -export class NewResourcePropertyPayload { - @JsonProperty("@id", String) - id: string = ""; - - @JsonProperty("@type", String, true) - type: string = Constants.ObjectProperty; - - @JsonProperty(Constants.SubjectType, IdConverter, true) - subjectType?: string = undefined; - - @JsonProperty(Constants.ObjectType, IdConverter) - objectType: string = ""; - - @JsonProperty(Constants.Label, StringLiteralToStringLiteralArrayConverter) - label: StringLiteralV2[] = []; - - @JsonProperty(Constants.Comment, StringLiteralToStringLiteralArrayConverter) - comment: StringLiteralV2[] = []; - - @JsonProperty(Constants.SubPropertyOf, SubClassOfConverter) - subPropertyOf: string[] = []; - - @JsonProperty(Constants.GuiElement, IdConverter, true) - guiElement?: string = undefined; - - @JsonProperty(Constants.GuiAttribute, [String], true) - guiAttributes?: string[] = undefined; - -} - -// 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", [NewResourcePropertyPayload]) - resProperty: NewResourcePropertyPayload[] = []; -} diff --git a/src/models/v2/ontologies/create/create-resource-property.ts b/src/models/v2/ontologies/create/create-resource-property.ts index ba80dfc04..c516ffa2c 100644 --- a/src/models/v2/ontologies/create/create-resource-property.ts +++ b/src/models/v2/ontologies/create/create-resource-property.ts @@ -1,36 +1,47 @@ import { JsonObject, JsonProperty } from "json2typescript"; import { StringLiteral } from "../../../admin/string-literal"; +import { Constants } from "../../Constants"; import { IdConverter } from "../../custom-converters/id-converter"; -import { UpdateOntology } from "../update-ontology"; +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 { UpdateOntology } from "../update/update-ontology"; @JsonObject("CreateResourceProperty") export class CreateResourceProperty { - @JsonProperty("ontology", UpdateOntology) - ontology: UpdateOntology = new UpdateOntology(); + name: string = ""; - @JsonProperty("subjectType", IdConverter, true) + @JsonProperty(Constants.SubjectType, IdConverter, true) subjectType?: string = undefined; - @JsonProperty("objectType", IdConverter) + @JsonProperty(Constants.ObjectType, IdConverter) objectType: string = ""; - @JsonProperty("name", String) - name: string = ""; - - @JsonProperty("labels", [StringLiteral]) - labels: StringLiteral[] = []; + @JsonProperty(Constants.Label, StringLiteralToStringLiteralArrayConverter) + label: StringLiteralV2[] = []; - @JsonProperty("comments", [StringLiteral], true) - comments: StringLiteral[] = []; + @JsonProperty(Constants.Comment, StringLiteralToStringLiteralArrayConverter) + comment: StringLiteralV2[] = []; - @JsonProperty("subPropertyOf", [String]) + @JsonProperty(Constants.SubPropertyOf, SubClassOfConverter) subPropertyOf: string[] = []; - @JsonProperty("guiElement", IdConverter, true) + @JsonProperty(Constants.GuiElement, IdConverter, true) guiElement?: string = undefined; - @JsonProperty("guiAttributes", [String], true) + @JsonProperty(Constants.GuiAttribute, [String], true) guiAttributes?: string[] = undefined; } + +@JsonObject("CreateResourcePropertyPayload") +export class CreateResourcePropertyPayload extends CreateResourceProperty { + + @JsonProperty("@id", String) + id: string = ""; + + @JsonProperty("@type", String) + type: string = Constants.ObjectProperty; + +} diff --git a/src/models/v2/ontologies/delete/delete-ontology.ts b/src/models/v2/ontologies/delete/delete-ontology.ts new file mode 100644 index 000000000..677c13254 --- /dev/null +++ b/src/models/v2/ontologies/delete/delete-ontology.ts @@ -0,0 +1,7 @@ +import { JsonObject } from "json2typescript"; +import { UpdateDeleteEntity } from "../update-delete-entity"; + +@JsonObject("DeleteOntology") +export class DeleteOntology extends UpdateDeleteEntity { + +} diff --git a/src/models/v2/ontologies/delete/delete-resource-class.ts b/src/models/v2/ontologies/delete/delete-resource-class.ts new file mode 100644 index 000000000..9059eedda --- /dev/null +++ b/src/models/v2/ontologies/delete/delete-resource-class.ts @@ -0,0 +1,5 @@ +import { UpdateDeleteEntity } from "../update-delete-entity"; + +export class DeleteResourceClass extends UpdateDeleteEntity { + +} diff --git a/src/models/v2/ontologies/delete/delete-resource-property.ts b/src/models/v2/ontologies/delete/delete-resource-property.ts new file mode 100644 index 000000000..6ccf555e7 --- /dev/null +++ b/src/models/v2/ontologies/delete/delete-resource-property.ts @@ -0,0 +1,5 @@ +import { UpdateDeleteEntity } from "../update-delete-entity"; + +export class DeleteResourceProperty extends UpdateDeleteEntity { + +} diff --git a/src/models/v2/ontologies/update-delete-entity.ts b/src/models/v2/ontologies/update-delete-entity.ts new file mode 100644 index 000000000..6271c8ea8 --- /dev/null +++ b/src/models/v2/ontologies/update-delete-entity.ts @@ -0,0 +1,14 @@ +import { JsonObject, JsonProperty } from "json2typescript"; +import { Constants } from "../Constants"; +import { DateTimeStampConverter } from "../custom-converters/date-time-stamp-converter"; + +@JsonObject("UpdateDeleteEntity") +export abstract class UpdateDeleteEntity { + + @JsonProperty("@id", String) + id: string = ""; + + @JsonProperty(Constants.LastModificationDate, DateTimeStampConverter, true) + lastModificationDate: string; + +} diff --git a/src/models/v2/ontologies/update-ontology.ts b/src/models/v2/ontologies/update-ontology.ts deleted file mode 100644 index 87ff82b2d..000000000 --- a/src/models/v2/ontologies/update-ontology.ts +++ /dev/null @@ -1,22 +0,0 @@ -import { JsonObject, JsonProperty } from "json2typescript"; -import { Constants } from "../Constants"; -import { DateTimeStampConverter } from "../custom-converters/date-time-stamp-converter"; - -/** - * UpdateOntology class can be used whenever the ontology, - * a resource class or a resource property has to be updated (incl. delete). - * It can be used to update - * - ontology: ontology id and lastModificationDate - * - resource classe: res class id and lastModificationDate - * - resource property: res prop id and lastModificationDate - */ -@JsonObject("UpdateOntology") -export class UpdateOntology { - - @JsonProperty("id", String) - id: string = ""; - - @JsonProperty(Constants.LastModificationDate, DateTimeStampConverter, true) - lastModificationDate: string; - -} diff --git a/src/models/v2/ontologies/create/add-cardinality-to-resource-class.ts b/src/models/v2/ontologies/update/update-ontology-resource-class-cardinality.ts similarity index 68% rename from src/models/v2/ontologies/create/add-cardinality-to-resource-class.ts rename to src/models/v2/ontologies/update/update-ontology-resource-class-cardinality.ts index 4e85e3619..e46aff5ee 100644 --- a/src/models/v2/ontologies/create/add-cardinality-to-resource-class.ts +++ b/src/models/v2/ontologies/update/update-ontology-resource-class-cardinality.ts @@ -3,19 +3,15 @@ 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"; +import { UpdateDeleteEntity } from "../update-delete-entity"; -@JsonObject("AddCardinalityToResourceClass") -export class AddCardinalityToResourceClass { - - @JsonProperty("@id", String) - id: string; +@JsonObject("UpdateOntologyResourceClassCardinality") +export class UpdateOntologyResourceClassCardinality extends UpdateDeleteEntity { @JsonProperty("@type", String) readonly type = Constants.Ontology; - @JsonProperty(Constants.LastModificationDate, DateTimeStampConverter) - lastModificationDate: string; - @JsonProperty("@graph", HasCardinalityForPropertyConverter) cardinalities: IHasProperty[] = []; + } diff --git a/src/models/v2/ontologies/update/update-ontology.ts b/src/models/v2/ontologies/update/update-ontology.ts new file mode 100644 index 000000000..cdbbaa6bf --- /dev/null +++ b/src/models/v2/ontologies/update/update-ontology.ts @@ -0,0 +1,15 @@ +import { JsonObject, JsonProperty } from "json2typescript"; +import { CreateResourceProperty } from "../create/create-resource-property"; +import { UpdateDeleteEntity } from "../update-delete-entity"; +import { CreateResourceClass } from "../create/create-resource-class"; +import { Constants } from "../../Constants"; + +@JsonObject("UpdateOntology") +export class UpdateOntology extends UpdateDeleteEntity { + + @JsonProperty("@type", String) + type: string = Constants.Ontology; + + entity: T; + +} diff --git a/test-framework/src/app/app.component.ts b/test-framework/src/app/app.component.ts index 15af7ebc5..80782c9c7 100644 --- a/test-framework/src/app/app.component.ts +++ b/test-framework/src/app/app.component.ts @@ -36,7 +36,10 @@ import { UsersResponse, WriteValueResponse, Cardinality, - AddCardinalityToResourceClass + DeleteOntology, + DeleteResourceClass, + DeleteResourceProperty, + UpdateOntologyResourceClassCardinality } 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"; @@ -191,10 +194,10 @@ export class AppComponent implements OnInit { } deleteOntology() { - // 2020-06-30T08:52:10.532394Z - const deleteOntology = new UpdateOntology(); + const deleteOntology = new DeleteOntology(); deleteOntology.id = this.ontology.id; deleteOntology.lastModificationDate = this.ontology.lastModificationDate; + this.knoraApiConnection.v2.onto.deleteOntology(deleteOntology).subscribe( (response: DeleteOntologyResponse) => { this.message = response.result; @@ -204,13 +207,16 @@ export class AppComponent implements OnInit { } createResourceClass() { + + const onto = new UpdateOntology(); + + onto.id = this.ontology.id; + onto.lastModificationDate = this.ontology.lastModificationDate; + const newResClass = new CreateResourceClass(); - newResClass.ontology = { - id: this.ontology.id, - lastModificationDate: this.ontology.lastModificationDate - }; + newResClass.name = "testclass"; - newResClass.labels = [ + newResClass.label = [ { language: "de", value: "Test Klasse" @@ -219,7 +225,7 @@ export class AppComponent implements OnInit { value: "Test Class" } ]; - newResClass.comments = [ + newResClass.comment = [ { language: "en", value: "Just an example of a new resource class" @@ -227,7 +233,9 @@ export class AppComponent implements OnInit { ]; newResClass.subClassOf = [Constants.Resource]; - this.knoraApiConnection.v2.onto.createResourceClass(newResClass).subscribe( + onto.entity = newResClass; + + this.knoraApiConnection.v2.onto.createResourceClass(onto).subscribe( (response: ResourceClassDefinitionWithAllLanguages) => { console.log('new resource class created', response); this.resClass = response; @@ -236,7 +244,8 @@ export class AppComponent implements OnInit { } deleteResourceClass() { - const deleteResClass: UpdateOntology = new UpdateOntology(); + + const deleteResClass: DeleteResourceClass = new DeleteResourceClass(); deleteResClass.id = "http://0.0.0.0:3333/ontology/0001/testonto/v2#testclass"; deleteResClass.lastModificationDate = this.ontology.lastModificationDate; @@ -254,16 +263,16 @@ export class AppComponent implements OnInit { createResourceProperty() { - const newResProp = new CreateResourceProperty(); + const onto = new UpdateOntology(); - newResProp.ontology = { - id: this.ontology.id, - lastModificationDate: this.ontology.lastModificationDate - }; + onto.id = this.ontology.id; + onto.lastModificationDate = this.ontology.lastModificationDate; + + const newResProp = new CreateResourceProperty(); newResProp.name = "hasName"; - newResProp.labels = [ + newResProp.label = [ { language: "en", value: "has name" @@ -274,7 +283,7 @@ export class AppComponent implements OnInit { } ]; - newResProp.comments = [ + newResProp.comment = [ { language: "en", value: "The name of a Thing" @@ -293,7 +302,9 @@ export class AppComponent implements OnInit { newResProp.guiElement = "http://api.knora.org/ontology/salsah-gui/v2#SimpleText"; newResProp.guiAttributes = ["size=80", "maxlength=100"]; - this.knoraApiConnection.v2.onto.createResourceProperty(newResProp).subscribe( + onto.entity = newResProp; + + this.knoraApiConnection.v2.onto.createResourceProperty(onto).subscribe( (response: ResourcePropertyDefinitionWithAllLanguages) => { this.property = response; console.log('new resource property created', response); @@ -302,7 +313,8 @@ export class AppComponent implements OnInit { } deleteResourceProperty() { - const deleteResProp: UpdateOntology = new UpdateOntology(); + + const deleteResProp: DeleteResourceProperty = new DeleteResourceProperty(); deleteResProp.id = "http://0.0.0.0:3333/ontology/0001/testonto/v2#hasName"; deleteResProp.lastModificationDate = this.ontology.lastModificationDate; @@ -320,7 +332,7 @@ export class AppComponent implements OnInit { addCardinality() { - const addCard = new AddCardinalityToResourceClass(); + const addCard = new UpdateOntologyResourceClassCardinality(); addCard.lastModificationDate = this.ontology.lastModificationDate;