-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DSP-428 Create res properties #235
Changes from 12 commits
823a044
c93db05
5cb0fe1
cc70297
7375f2d
4cdf1f4
59de3c3
de21383
14d9515
f98e1e6
01a9950
0ef4b7d
f762399
ca6ddb9
65ef34a
a419211
b7f0bca
6da6b77
2cdeb52
f0dc4ad
34dba9e
b5e95da
1f9087c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,14 +3,24 @@ 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"; | ||
|
||
|
@@ -66,11 +76,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 | ||
*/ | ||
* 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<OntologiesMetadata | ApiResponseError> { | ||
|
||
return this.httpGet("/metadata/" + encodeURIComponent(projectIri)).pipe( | ||
|
@@ -90,7 +100,7 @@ export class OntologiesEndpointV2 extends Endpoint { | |
|
||
/** | ||
* Creates a new ontology. | ||
* | ||
* | ||
* @param ontology The ontology to be created | ||
*/ | ||
createOntology(ontology: CreateOntology): Observable<OntologyMetadata | ApiResponseError> { | ||
|
@@ -136,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<ResourceClassDefinitionWithAllLanguages | ApiResponseError> { | ||
|
@@ -151,7 +161,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; | ||
|
||
|
@@ -176,7 +186,7 @@ export class OntologiesEndpointV2 extends Endpoint { | |
/** | ||
* Delete resource class | ||
* | ||
* @param updateOntology | ||
* @param updateOntology with class IRI | ||
*/ | ||
deleteResourceClass(updateOntology: UpdateOntology): Observable<OntologyMetadata | ApiResponseError> { | ||
|
||
|
@@ -196,4 +206,94 @@ export class OntologiesEndpointV2 extends Endpoint { | |
|
||
} | ||
|
||
/** | ||
* Create a resource property | ||
* | ||
* @param resProp The resource property to be created | ||
*/ | ||
createResourceProperty(resProp: CreateResourceProperty): Observable<ResourcePropertyDefinitionWithAllLanguages | ApiResponseError> { | ||
|
||
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 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; | ||
newResProperty.type = Constants.ObjectProperty; | ||
|
||
newResProperty.subjectType = resProp.subjectType; | ||
newResProperty.objectType = resProp.objectType; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we simplify the // If the new property is a subproperty of knora-api:hasValue, its knora-api:objectType must be one of the built-in subclasses of knora-api:Value.
// If the new property is a subproperty of knora-base:hasLinkTo, its knora-api:objectType must be a subclass of knora-api:Resource
newResProperty.objectType = (resProp.subPropertyOf === Constants.HasValue ? Constants.Value : Constants.Resource) Not sure if all Constants are defined. And maybe this is not a good solution as the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we could do some consistency checks for value and link props. Or we could make specific classes for value and link props. Would that help? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A user of the method needs a deep knowledge of the ontology stuff. I thought that the object you hand over to the method could be simplified. At this point it is similar to the payload. And you have to take care that you pass the correct I'll be able to use it in DSP-App. But if somebody else uses it, it gets complicated very fast. For the moment it's ok for me. It was just an idea / suggestion. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's definitely worth thinking about. I will keep that in kind when doing the refactoring in https://dasch.myjetbrains.com/youtrack/issue/DSP-685 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I made a note in https://dasch.myjetbrains.com/youtrack/issue/DSP-685 |
||
|
||
if (resProp.guiElement) { | ||
newResProperty.guiElement = resProp.guiElement; | ||
} | ||
if (resProp.guiAttributes) { | ||
newResProperty.guiAttributes = resProp.guiAttributes; | ||
} | ||
|
||
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.convertResourcePropertyResponse(jsonldobj, this.jsonConvert); | ||
}), | ||
catchError(error => { | ||
return this.handleError(error); | ||
}) | ||
); | ||
} | ||
|
||
/** | ||
* Delete resource property | ||
* | ||
* @param updateOntology with property IRI | ||
*/ | ||
deleteResourceProperty(updateOntology: UpdateOntology): Observable<OntologyMetadata | ApiResponseError> { | ||
|
||
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)) | ||
); | ||
} | ||
|
||
addCardinalityToResourceClass(addCardinalityToResourceClass: AddCardinalityToResourceClass): Observable<ResourceClassDefinitionWithAllLanguages | ApiResponseError> { | ||
|
||
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); | ||
}) | ||
); | ||
|
||
} | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kilchenmann Is this supposed to be a fallback if no comments are provided? But then how would we know that the labels array is not empty?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this is a kind of fallback. The labels are a mandatory value, they shouldn't be empty. But I think we do not check that, do we?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The problem is that with
json2typescript
, all properties have an initial value, so technically speaking, all props are set. But the initial value does not make any sense, e..g, an empty string.So yes, there could be some checks in the endpoint's method for empty strings and empty arrays.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we implement additional checks in this PR? I suggest to do it in a separate one..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will do it in https://dasch.myjetbrains.com/youtrack/issue/DSP-685, I added a note