Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
feat(ontology): allow deleting comments of properties (DEV-696) (#2042)
* add method and test to delete property comment

* add route to delete property comment

* allow deleting comments for properties

* improve code

* fix failing test

* add more tests

* wip

* add test for link property

* add route

* add e2e test

* remove print statements
  • Loading branch information
irinaschubert committed Apr 26, 2022
1 parent a47096e commit 985c5fd
Show file tree
Hide file tree
Showing 8 changed files with 657 additions and 0 deletions.
16 changes: 16 additions & 0 deletions docs/03-apis/api-v2/ontology-information.md
Expand Up @@ -1516,6 +1516,22 @@ HTTP PUT to http://host/v2/ontologies/properties
Values for `rdfs:comment` must be submitted in at least one language,
either as an object or as an array of objects.

### Deleting the Comments of a Property

This operation is permitted even if the property is used in data.

```
HTTP DELETE to http://host/v2/ontologies/properties/comment/PROPERTY_IRI?lastModificationDate=ONTOLOGY_LAST_MODIFICATION_DATE
```

The property IRI and the ontology's last modification date must be URL-encoded.

All values i.e. all languages for `rdfs:comment` are deleted.

If the property is a link property, the `rdfs:comment` of its corresponding link value property will automatically be deleted.

A successful response will be a JSON-LD document providing the property definition.

### Changing the GUI Element and GUI Attributes of a Property

This operation is permitted even if the property is used in data.
Expand Down
54 changes: 54 additions & 0 deletions test_data/ontologies/freetest-onto.ttl
Expand Up @@ -322,3 +322,57 @@
salsah-gui:guiElement salsah-gui:SimpleText ;
salsah-gui:guiAttribute "size=80",
"maxlength=255" .

:hasPropertyWithComment
rdf:type owl:ObjectProperty ;
rdfs:subPropertyOf knora-base:hasValue ;
rdfs:label "Property mit einem Kommentar"@de,
"Property with a comment"@en ;
rdfs:comment "Dies ist der Kommentar"@de,
"This is the comment"@en ;
knora-base:objectClassConstraint knora-base:TextValue ;
salsah-gui:guiElement salsah-gui:SimpleText ;
salsah-gui:guiAttribute "size=80",
"maxlength=255" .

:hasPropertyWithoutComment
rdf:type owl:ObjectProperty ;
rdfs:subPropertyOf knora-base:hasValue ;
rdfs:label "Property ohne Kommentar"@de,
"Property without a comment"@en ;
knora-base:objectClassConstraint knora-base:TextValue ;
salsah-gui:guiElement salsah-gui:SimpleText ;
salsah-gui:guiAttribute "size=80",
"maxlength=255" .

:hasPropertyWithComment2
rdf:type owl:ObjectProperty ;
rdfs:subPropertyOf knora-base:hasValue ;
rdfs:label "Property mit einem Kommentar"@de,
"Property with a comment"@en ;
rdfs:comment "Dies ist der Kommentar"@de,
"This is the comment"@en ;
knora-base:objectClassConstraint knora-base:TextValue ;
salsah-gui:guiElement salsah-gui:SimpleText .

:hasLinkPropertyWithComment
rdf:type owl:ObjectProperty ;
rdfs:subPropertyOf knora-base:hasLinkTo ;
rdfs:label "Link Property mit Kommentar"@de,
"Link property with comment"@en;
rdfs:comment "Dies ist der Kommentar"@de,
"This is the comment"@en ;
knora-base:subjectClassConstraint :Book ;
knora-base:objectClassConstraint :Author ;
salsah-gui:guiElement salsah-gui:Searchbox .

:hasLinkPropertyWithCommentValue
rdf:type owl:ObjectProperty ;
rdfs:subPropertyOf knora-base:hasLinkToValue ;
rdfs:label "Link Property mit Kommentar"@de,
"Link property with comment"@en;
rdfs:comment "Dies ist der Kommentar"@de,
"This is the comment"@en ;
knora-base:subjectClassConstraint :Book ;
knora-base:objectClassConstraint knora-base:LinkValue ;
salsah-gui:guiElement salsah-gui:Searchbox .
Expand Up @@ -1151,6 +1151,80 @@ object ChangePropertyLabelsOrCommentsRequestV2
}
}

/**
* Deletes the comment from a property. A successful response will be a [[ReadOntologyV2]].
*
* @param propertyIri the IRI of the property.
* @param lastModificationDate the ontology's last modification date
* @param apiRequestID the ID of the API request.
* @param requestingUser the user making the request.
*/
case class DeletePropertyCommentRequestV2(
propertyIri: SmartIri,
lastModificationDate: Instant,
apiRequestID: UUID,
featureFactoryConfig: FeatureFactoryConfig,
requestingUser: UserADM
) extends OntologiesResponderRequestV2

/**
* Constructs instances of [[DeletePropertyCommentRequestV2]] based on JSON-LD input.
*/
object DeletePropertyCommentRequestV2 extends KnoraJsonLDRequestReaderV2[DeletePropertyCommentRequestV2] {

/**
* Converts a JSON-LD request to a [[DeletePropertyCommentRequestV2]].
*
* @param jsonLDDocument the JSON-LD input.
* @param apiRequestID the UUID of the API request.
* @param requestingUser the user making the request.
* @param responderManager a reference to the responder manager.
* @param storeManager a reference to the store manager.
* @param featureFactoryConfig the feature factory configuration.
* @param settings the application settings.
* @param log a logging adapter.
* @return a [[DeletePropertyCommentRequestV2]] representing the input.
*/
override def fromJsonLD(
jsonLDDocument: JsonLDDocument,
apiRequestID: UUID,
requestingUser: UserADM,
responderManager: ActorRef,
storeManager: ActorRef,
featureFactoryConfig: FeatureFactoryConfig,
settings: KnoraSettingsImpl,
log: LoggingAdapter
)(implicit timeout: Timeout, executionContext: ExecutionContext): Future[DeletePropertyCommentRequestV2] =
Future {
fromJsonLDSync(
jsonLDDocument = jsonLDDocument,
apiRequestID = apiRequestID,
featureFactoryConfig = featureFactoryConfig,
requestingUser = requestingUser
)
}

private def fromJsonLDSync(
jsonLDDocument: JsonLDDocument,
apiRequestID: UUID,
featureFactoryConfig: FeatureFactoryConfig,
requestingUser: UserADM
): DeletePropertyCommentRequestV2 = {
val inputOntologyV2 = InputOntologyV2.fromJsonLD(jsonLDDocument)
val propertyUpdateInfo = OntologyUpdateHelper.getPropertyDef(inputOntologyV2)
val propertyInfoContent = propertyUpdateInfo.propertyInfoContent
val lastModificationDate = propertyUpdateInfo.lastModificationDate

DeletePropertyCommentRequestV2(
propertyIri = propertyInfoContent.propertyIri,
lastModificationDate = lastModificationDate,
apiRequestID = apiRequestID,
featureFactoryConfig = featureFactoryConfig,
requestingUser = requestingUser
)
}
}

/**
* Requests that a class's labels or comments are changed. A successful response will be a [[ReadOntologyV2]].
*
Expand Down

0 comments on commit 985c5fd

Please sign in to comment.