Skip to content
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

feat(api-v2): Add route for changing GUI order of cardinalities #1850

Merged
merged 10 commits into from May 3, 2021
66 changes: 57 additions & 9 deletions docs/03-apis/api-v2/ontology-information.md
Expand Up @@ -1066,7 +1066,7 @@ HTTP POST to http://host/v2/ontologies/classes
"@value" : "ONTOLOGY_LAST_MODIFICATION_DATE"
},
"@graph" : [ {
"CLASS_IRI" : {
{
"@id" : "CLASS_IRI",
"@type" : "owl:Class",
"rdfs:label" : {
Expand Down Expand Up @@ -1119,7 +1119,7 @@ HTTP POST to http://host/v2/ontologies/classes
"@value" : "ONTOLOGY_LAST_MODIFICATION_DATE"
},
"@graph" : [ {
"CLASS_IRI" : {
{
"@id" : "CLASS_IRI",
"@type" : "owl:Class",
"rdfs:label" : {
Expand Down Expand Up @@ -1185,7 +1185,7 @@ HTTP PUT to http://host/v2/ontologies/classes
"@value" : "ONTOLOGY_LAST_MODIFICATION_DATE"
},
"@graph" : [ {
"CLASS_IRI" : {
{
"@id" : "CLASS_IRI",
"@type" : "owl:Class",
"rdfs:label" : {
Expand Down Expand Up @@ -1224,7 +1224,7 @@ HTTP PUT to http://host/v2/ontologies/classes
"@value" : "ONTOLOGY_LAST_MODIFICATION_DATE"
},
"@graph" : [ {
"CLASS_IRI" : {
{
"@id" : "CLASS_IRI",
"@type" : "owl:Class",
"rdfs:comment" : {
Expand Down Expand Up @@ -1262,7 +1262,7 @@ HTTP POST to http://host/v2/ontologies/properties
"@value" : "ONTOLOGY_LAST_MODIFICATION_DATE"
},
"@graph" : [ {
"PROPERTY_IRI" : {
{
"@id" : "PROPERTY_IRI",
"@type" : "owl:ObjectProperty",
"knora-api:subjectType" : {
Expand Down Expand Up @@ -1351,7 +1351,7 @@ HTTP PUT to http://host/v2/ontologies/properties
"@value" : "ONTOLOGY_LAST_MODIFICATION_DATE"
},
"@graph" : [ {
"PROPERTY_IRI" : {
{
"@id" : "PROPERTY_IRI",
"@type" : "owl:ObjectProperty",
"rdfs:label" : {
Expand Down Expand Up @@ -1389,7 +1389,7 @@ HTTP PUT to http://host/v2/ontologies/properties
"@value" : "ONTOLOGY_LAST_MODIFICATION_DATE"
},
"@graph" : [ {
"PROPERTY_IRI" : {
{
"@id" : "PROPERTY_IRI",
"@type" : "owl:ObjectProperty",
"rdfs:comment" : {
Expand Down Expand Up @@ -1428,7 +1428,7 @@ HTTP POST to http://host/v2/ontologies/cardinalities
"@value" : "ONTOLOGY_LAST_MODIFICATION_DATE"
},
"@graph" : [ {
"CLASS_IRI" : {
{
"@id" : "CLASS_IRI",
"@type" : "owl:Class",
"rdfs:subClassOf" : {
Expand Down Expand Up @@ -1487,7 +1487,7 @@ HTTP PUT to http://host/v2/ontologies/cardinalities
"@value" : "ONTOLOGY_LAST_MODIFICATION_DATE"
},
"@graph" : [ {
"CLASS_IRI" : {
{
"@id" : "CLASS_IRI",
"@type" : "owl:Class",
"rdfs:subClassOf" : {
Expand Down Expand Up @@ -1521,6 +1521,54 @@ on the corresponding link value property is automatically added (see
A successful response will be a JSON-LD document providing the new class
definition (but not any of the other entities in the ontology).

### Changing the GUI Order of Cardinalities

To change the GUI order of one or more cardinalities in a class:

```
HTTP PUT to http://host/v2/ontologies/guiorder
```

This can be done even if the class is used in data.

The request body includes the cardinalities whose GUI order should be changed,
using the predicate `salsah-gui:guiOrder`, whose object is an integer:

```jsonld
{
"@id" : "ONTOLOGY_IRI",
"@type" : "owl:Ontology",
"knora-api:lastModificationDate" : {
"@type" : "xsd:dateTimeStamp",
"@value" : "ONTOLOGY_LAST_MODIFICATION_DATE"
},
"@graph" : [ {
"@id" : "CLASS_IRI",
"@type" : "owl:Class",
"rdfs:subClassOf" : {
"@type": "owl:Restriction",
"OWL_CARDINALITY_PREDICATE": "OWL_CARDINALITY_VALUE",
"owl:onProperty": {
"@id" : "PROPERTY_IRI"
},
"salsah-gui:guiOrder": "GUI_ORDER_VALUE"
}
} ],
"@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#",
}
}
```

Only the cardinalities whose GUI order is to be changed need to be included
in the request. The `OWL_CARDINALITY_PREDICATE` and `OWL_CARDINALITY_VALUE`
are ignored; only the `GUI_ORDER_VALUE` is changed.

### Deleting a Property

A property can be deleted only if no other ontology entity refers to it,
Expand Down
1 change: 1 addition & 0 deletions webapi/scripts/expected-client-test-data.txt
Expand Up @@ -182,6 +182,7 @@ test-data/v2/ontologies/all-ontology-metadata-response.json
test-data/v2/ontologies/anything-ontology.json
test-data/v2/ontologies/change-class-comment-request.json
test-data/v2/ontologies/change-class-label-request.json
test-data/v2/ontologies/change-gui-order-request.json
test-data/v2/ontologies/change-property-comment-request.json
test-data/v2/ontologies/change-property-label-request.json
test-data/v2/ontologies/create-class-with-cardinalities-request.json
Expand Down
Expand Up @@ -3259,6 +3259,5 @@ class StringFormatter private (val maybeSettings: Option[KnoraSettingsImpl] = No
stringLiterals = stringLiteralSeq.stringLiterals.map(stringLiteral =>
StringLiteralV2(value = fromSparqlEncodedString(stringLiteral.value), language = stringLiteral.language))
)

}
}
Expand Up @@ -668,10 +668,12 @@ case class ListRootNodeInfoADM(id: IRI,
val unescapedLabels = stringFormatter.unescapeStringLiteralSeq(labels)

val unescapedComments = stringFormatter.unescapeStringLiteralSeq(comments)

val unescapedName: Option[String] = name match {
case None => None
case Some(value) => Some(stringFormatter.fromSparqlEncodedString(value))
}

copy(name = unescapedName, labels = unescapedLabels, comments = unescapedComments)
}

Expand Down Expand Up @@ -733,10 +735,12 @@ case class ListChildNodeInfoADM(id: IRI,
val unescapedLabels = stringFormatter.unescapeStringLiteralSeq(labels)

val unescapedComments = stringFormatter.unescapeStringLiteralSeq(comments)

val unescapedName: Option[String] = name match {
case None => None
case Some(value) => Some(stringFormatter.fromSparqlEncodedString(value))
}

copy(name = unescapedName, labels = unescapedLabels, comments = unescapedComments)
}

Expand Down Expand Up @@ -857,10 +861,12 @@ case class ListRootNodeADM(id: IRI,

val unescapedLabels = stringFormatter.unescapeStringLiteralSeq(labels)
val unescapedComments = stringFormatter.unescapeStringLiteralSeq(comments)

val unescapedName: Option[String] = name match {
case None => None
case Some(value) => Some(stringFormatter.fromSparqlEncodedString(value))
}

copy(name = unescapedName, labels = unescapedLabels, comments = unescapedComments)
}

Expand Down Expand Up @@ -938,6 +944,7 @@ case class ListChildNodeADM(id: IRI,
case None => None
case Some(value) => Some(stringFormatter.fromSparqlEncodedString(value))
}

copy(name = unescapedName, labels = unescapedLabels, comments = unescapedComments)
}

Expand Down
Expand Up @@ -913,6 +913,60 @@ object ChangeClassLabelsOrCommentsRequestV2 extends KnoraJsonLDRequestReaderV2[C
}
}

case class ChangeGuiOrderRequestV2(classInfoContent: ClassInfoContentV2,
lastModificationDate: Instant,
apiRequestID: UUID,
featureFactoryConfig: FeatureFactoryConfig,
requestingUser: UserADM)
extends OntologiesResponderRequestV2

object ChangeGuiOrderRequestV2 extends KnoraJsonLDRequestReaderV2[ChangeGuiOrderRequestV2] {
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[ChangeGuiOrderRequestV2] = {
Future {
fromJsonLDSync(
jsonLDDocument = jsonLDDocument,
apiRequestID = apiRequestID,
featureFactoryConfig = featureFactoryConfig,
requestingUser = requestingUser
)
}
}

private def fromJsonLDSync(jsonLDDocument: JsonLDDocument,
apiRequestID: UUID,
featureFactoryConfig: FeatureFactoryConfig,
requestingUser: UserADM): ChangeGuiOrderRequestV2 = {
// Get the class definition and the ontology's last modification date from the JSON-LD.

val inputOntologiesV2 = InputOntologyV2.fromJsonLD(jsonLDDocument)
val classUpdateInfo = OntologyUpdateHelper.getClassDef(inputOntologiesV2)
val classInfoContent = classUpdateInfo.classInfoContent
val lastModificationDate = classUpdateInfo.lastModificationDate

// The request must provide cardinalities.

if (classInfoContent.directCardinalities.isEmpty) {
throw BadRequestException("No cardinalities specified")
}

ChangeGuiOrderRequestV2(
classInfoContent = classInfoContent,
lastModificationDate = lastModificationDate,
apiRequestID = apiRequestID,
featureFactoryConfig = featureFactoryConfig,
requestingUser = requestingUser
)
}
}

/**
* Requests a change in the metadata of an ontology. A successful response will be a [[ReadOntologyMetadataV2]].
*
Expand Down