Skip to content

Commit

Permalink
fix(api-v2): Fix incorrect serialisation of lastModificationDate (#1442)
Browse files Browse the repository at this point in the history
  • Loading branch information
Benjamin Geer committed Jan 21, 2020
1 parent 45074ec commit 22727a2
Show file tree
Hide file tree
Showing 28 changed files with 3,390 additions and 3,227 deletions.
61 changes: 46 additions & 15 deletions docs/src/paradox/03-apis/api-v2/ontology-information.md
Expand Up @@ -973,12 +973,16 @@ HTTP PUT to http://host/v2/ontologies/metadata

```jsonld
{
"@id": "ONTOLOGY_IRI",
"rdfs:label": "NEW_ONTOLOGY_LABEL",
"knora-api:lastModificationDate": "ONTOLOGY_LAST_MODIFICATION_DATE",
"@context": {
"rdfs": "http://www.w3.org/2000/01/rdf-schema#",
"knora-api": "http://api.knora.org/ontology/knora-api/v2#"
"@id" : "ONTOLOGY_IRI",
"rdfs:label" : "NEW_ONTOLOGY_LABEL",
"knora-api:lastModificationDate" : {
"@type" : "xsd:dateTimeStamp",
"@value" : "ONTOLOGY_LAST_MODIFICATION_DATE"
},
"@context" : {
"xsd" : "http://www.w3.org/2001/XMLSchema#",
"rdfs" : "http://www.w3.org/2000/01/rdf-schema#",
"knora-api" : "http://api.knora.org/ontology/knora-api/v2#"
}
}
```
Expand Down Expand Up @@ -1010,7 +1014,10 @@ HTTP POST to http://host/v2/ontologies/classes
{
"@id" : "ONTOLOGY_IRI",
"@type" : "owl:Ontology",
"knora-api:lastModificationDate" : "ONTOLOGY_LAST_MODIFICATION_DATE",
"knora-api:lastModificationDate" : {
"@type" : "xsd:dateTimeStamp",
"@value" : "ONTOLOGY_LAST_MODIFICATION_DATE"
},
"@graph" : [ {
"CLASS_IRI" : {
"@id" : "CLASS_IRI",
Expand Down Expand Up @@ -1060,7 +1067,10 @@ HTTP POST to http://host/v2/ontologies/classes
{
"@id" : "ONTOLOGY_IRI",
"@type" : "owl:Ontology",
"knora-api:lastModificationDate" : "ONTOLOGY_LAST_MODIFICATION_DATE",
"knora-api:lastModificationDate" : {
"@type" : "xsd:dateTimeStamp",
"@value" : "ONTOLOGY_LAST_MODIFICATION_DATE"
},
"@graph" : [ {
"CLASS_IRI" : {
"@id" : "CLASS_IRI",
Expand Down Expand Up @@ -1123,7 +1133,10 @@ HTTP PUT to http://host/v2/ontologies/classes
{
"@id" : "ONTOLOGY_IRI",
"@type" : "owl:Ontology",
"knora-api:lastModificationDate" : "ONTOLOGY_LAST_MODIFICATION_DATE",
"knora-api:lastModificationDate" : {
"@type" : "xsd:dateTimeStamp",
"@value" : "ONTOLOGY_LAST_MODIFICATION_DATE"
},
"@graph" : [ {
"CLASS_IRI" : {
"@id" : "CLASS_IRI",
Expand Down Expand Up @@ -1159,7 +1172,10 @@ HTTP PUT to http://host/v2/ontologies/classes
{
"@id" : "ONTOLOGY_IRI",
"@type" : "owl:Ontology",
"knora-api:lastModificationDate" : "ONTOLOGY_LAST_MODIFICATION_DATE",
"knora-api:lastModificationDate" : {
"@type" : "xsd:dateTimeStamp",
"@value" : "ONTOLOGY_LAST_MODIFICATION_DATE"
},
"@graph" : [ {
"CLASS_IRI" : {
"@id" : "CLASS_IRI",
Expand Down Expand Up @@ -1194,7 +1210,10 @@ HTTP POST to http://host/v2/ontologies/properties
{
"@id" : "ONTOLOGY_IRI",
"@type" : "owl:Ontology",
"knora-api:lastModificationDate" : "ONTOLOGY_LAST_MODIFICATION_DATE",
"knora-api:lastModificationDate" : {
"@type" : "xsd:dateTimeStamp",
"@value" : "ONTOLOGY_LAST_MODIFICATION_DATE"
},
"@graph" : [ {
"PROPERTY_IRI" : {
"@id" : "PROPERTY_IRI",
Expand Down Expand Up @@ -1280,7 +1299,10 @@ HTTP PUT to http://host/v2/ontologies/properties
{
"@id" : "ONTOLOGY_IRI",
"@type" : "owl:Ontology",
"knora-api:lastModificationDate" : "ONTOLOGY_LAST_MODIFICATION_DATE",
"knora-api:lastModificationDate" : {
"@type" : "xsd:dateTimeStamp",
"@value" : "ONTOLOGY_LAST_MODIFICATION_DATE"
},
"@graph" : [ {
"PROPERTY_IRI" : {
"@id" : "PROPERTY_IRI",
Expand Down Expand Up @@ -1315,7 +1337,10 @@ HTTP PUT to http://host/v2/ontologies/properties
{
"@id" : "ONTOLOGY_IRI",
"@type" : "owl:Ontology",
"knora-api:lastModificationDate" : "ONTOLOGY_LAST_MODIFICATION_DATE",
"knora-api:lastModificationDate" : {
"@type" : "xsd:dateTimeStamp",
"@value" : "ONTOLOGY_LAST_MODIFICATION_DATE"
},
"@graph" : [ {
"PROPERTY_IRI" : {
"@id" : "PROPERTY_IRI",
Expand Down Expand Up @@ -1351,7 +1376,10 @@ HTTP POST to http://host/v2/ontologies/cardinalities
{
"@id" : "ONTOLOGY_IRI",
"@type" : "owl:Ontology",
"knora-api:lastModificationDate" : "ONTOLOGY_LAST_MODIFICATION_DATE",
"knora-api:lastModificationDate" : {
"@type" : "xsd:dateTimeStamp",
"@value" : "ONTOLOGY_LAST_MODIFICATION_DATE"
},
"@graph" : [ {
"CLASS_IRI" : {
"@id" : "CLASS_IRI",
Expand Down Expand Up @@ -1407,7 +1435,10 @@ HTTP PUT to http://host/v2/ontologies/cardinalities
{
"@id" : "ONTOLOGY_IRI",
"@type" : "owl:Ontology",
"knora-api:lastModificationDate" : "ONTOLOGY_LAST_MODIFICATION_DATE",
"knora-api:lastModificationDate" : {
"@type" : "xsd:dateTimeStamp",
"@value" : "ONTOLOGY_LAST_MODIFICATION_DATE"
},
"@graph" : [ {
"CLASS_IRI" : {
"@id" : "CLASS_IRI",
Expand Down
Expand Up @@ -1345,7 +1345,7 @@ object InputOntologyV2 {
def fromJsonLD(jsonLDDocument: JsonLDDocument, parsingMode: InputOntologyParsingModeV2 = ClientInputParsingModeV2): InputOntologyV2 = {
implicit val stringFormatter: StringFormatter = StringFormatter.getGeneralInstance

val ontologyObj = jsonLDDocument.body
val ontologyObj: JsonLDObject = jsonLDDocument.body
val externalOntologyIri: SmartIri = ontologyObj.requireStringWithValidation(JsonLDConstants.ID, stringFormatter.toSmartIriWithErr)

if (!(externalOntologyIri.isKnoraApiV2DefinitionIri && externalOntologyIri.isKnoraOntologyIri)) {
Expand All @@ -1356,9 +1356,10 @@ object InputOntologyV2 {

val ontologyLabel: Option[String] = ontologyObj.maybeStringWithValidation(OntologyConstants.Rdfs.Label, stringFormatter.toSparqlEncodedString)

val lastModificationDate: Option[Instant] = ontologyObj.maybeStringWithValidation(
OntologyConstants.KnoraApiV2Complex.LastModificationDate,
stringFormatter.xsdDateTimeStampToInstant
val lastModificationDate: Option[Instant] = ontologyObj.maybeDatatypeValueInObject(
key = OntologyConstants.KnoraApiV2Complex.LastModificationDate,
expectedDatatype = OntologyConstants.Xsd.DateTimeStamp.toSmartIri,
validationFun = stringFormatter.xsdDateTimeStampToInstant
)

val ontologyMetadata = OntologyMetadataV2(
Expand Down Expand Up @@ -1453,6 +1454,7 @@ case class ReadOntologyMetadataV2(ontologies: Set[OntologyMetadataV2]) extends K

val context = JsonLDObject(Map(
OntologyConstants.KnoraApi.KnoraApiOntologyLabel -> JsonLDString(knoraApiOntologyPrefixExpansion),
"xsd" -> JsonLDString(OntologyConstants.Xsd.XsdPrefixExpansion),
"rdfs" -> JsonLDString(OntologyConstants.Rdfs.RdfsPrefixExpansion),
"owl" -> JsonLDString(OntologyConstants.Owl.OwlPrefixExpansion)
))
Expand Down Expand Up @@ -2973,9 +2975,9 @@ case class OntologyMetadataV2(ontologyIri: SmartIri,
label: Option[String] = None,
lastModificationDate: Option[Instant] = None,
ontologyVersion: Option[String] = None) extends KnoraContentV2[OntologyMetadataV2] {
override def toOntologySchema(targetSchema: OntologySchema): OntologyMetadataV2 = {
implicit val stringFormatter: StringFormatter = StringFormatter.getGeneralInstance
implicit private val stringFormatter: StringFormatter = StringFormatter.getGeneralInstance

override def toOntologySchema(targetSchema: OntologySchema): OntologyMetadataV2 = {
if (ontologyIri == OntologyConstants.KnoraBase.KnoraBaseOntologyIri.toSmartIri) {
targetSchema match {
case InternalSchema => this
Expand Down Expand Up @@ -3028,9 +3030,12 @@ case class OntologyMetadataV2(ontologyIri: SmartIri,
labelStr => OntologyConstants.Rdfs.Label -> JsonLDString(labelStr)
}

val lastModDateStatement: Option[(IRI, JsonLDString)] = if (targetSchema == ApiV2Complex) {
val lastModDateStatement: Option[(IRI, JsonLDObject)] = if (targetSchema == ApiV2Complex) {
lastModificationDate.map {
lastModDate => OntologyConstants.KnoraApiV2Complex.LastModificationDate -> JsonLDString(lastModDate.toString)
lastModDate => OntologyConstants.KnoraApiV2Complex.LastModificationDate -> JsonLDUtil.datatypeValueToJsonLDObject(
value = lastModDate.toString,
datatype = OntologyConstants.Xsd.DateTimeStamp.toSmartIri
)
}
} else {
None
Expand Down
Expand Up @@ -5,15 +5,21 @@
"knora-api:attachedToProject" : {
"@id" : "http://rdfh.ch/projects/0001"
},
"knora-api:lastModificationDate" : "2017-12-19T15:23:42.166Z",
"knora-api:lastModificationDate" : {
"@type" : "xsd:dateTimeStamp",
"@value" : "2017-12-19T15:23:42.166Z"
},
"rdfs:label" : "The anything ontology"
}, {
"@id" : "http://0.0.0.0:3333/ontology/0001/minimal/v2",
"@type" : "owl:Ontology",
"knora-api:attachedToProject" : {
"@id" : "http://rdfh.ch/projects/0001"
},
"knora-api:lastModificationDate" : "2019-09-10T08:57:46.633162Z",
"knora-api:lastModificationDate" : {
"@type" : "xsd:dateTimeStamp",
"@value" : "2019-09-10T08:57:46.633162Z"
},
"rdfs:label" : "A minimal ontology"
}, {
"@id" : "http://0.0.0.0:3333/ontology/0001/something/v2",
Expand Down Expand Up @@ -95,7 +101,10 @@
"@id" : "http://www.knora.org/ontology/knora-admin#DefaultSharedOntologiesProject"
},
"knora-api:isShared" : true,
"knora-api:lastModificationDate" : "2018-09-10T14:53:00Z",
"knora-api:lastModificationDate" : {
"@type" : "xsd:dateTimeStamp",
"@value" : "2018-09-10T14:53:00Z"
},
"rdfs:label" : "An example of a shared ontology"
}, {
"@id" : "http://api.knora.org/ontology/standoff/v2",
Expand All @@ -108,6 +117,7 @@
} ],
"@context" : {
"knora-api" : "http://api.knora.org/ontology/knora-api/v2#",
"xsd" : "http://www.w3.org/2001/XMLSchema#",
"rdfs" : "http://www.w3.org/2000/01/rdf-schema#",
"owl" : "http://www.w3.org/2002/07/owl#"
}
Expand Down
@@ -1,17 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<rdf:RDF
xmlns:knora-api="http://api.knora.org/ontology/knora-api/v2#"
xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
xmlns:owl="http://www.w3.org/2002/07/owl#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
<owl:Ontology rdf:about="http://0.0.0.0:3333/ontology/0001/anything/v2">
<knora-api:attachedToProject rdf:resource="http://rdfh.ch/projects/0001"/>
<knora-api:lastModificationDate rdf:datatype="http://www.w3.org/2001/XMLSchema#string">2017-12-19T15:23:42.166Z</knora-api:lastModificationDate>
<knora-api:lastModificationDate rdf:datatype="http://www.w3.org/2001/XMLSchema#dateTimeStamp">2017-12-19T15:23:42.166Z</knora-api:lastModificationDate>
<rdfs:label rdf:datatype="http://www.w3.org/2001/XMLSchema#string">The anything ontology</rdfs:label>
</owl:Ontology>
<owl:Ontology rdf:about="http://0.0.0.0:3333/ontology/0001/minimal/v2">
<knora-api:attachedToProject rdf:resource="http://rdfh.ch/projects/0001"/>
<knora-api:lastModificationDate rdf:datatype="http://www.w3.org/2001/XMLSchema#string">2019-09-10T08:57:46.633162Z</knora-api:lastModificationDate>
<knora-api:lastModificationDate rdf:datatype="http://www.w3.org/2001/XMLSchema#dateTimeStamp">2019-09-10T08:57:46.633162Z</knora-api:lastModificationDate>
<rdfs:label rdf:datatype="http://www.w3.org/2001/XMLSchema#string">A minimal ontology</rdfs:label>
</owl:Ontology>
<owl:Ontology rdf:about="http://0.0.0.0:3333/ontology/0001/something/v2">
Expand Down Expand Up @@ -60,7 +61,7 @@
<owl:Ontology rdf:about="http://api.knora.org/ontology/shared/example-box/v2">
<knora-api:attachedToProject rdf:resource="http://www.knora.org/ontology/knora-admin#DefaultSharedOntologiesProject"/>
<knora-api:isShared rdf:datatype="http://www.w3.org/2001/XMLSchema#boolean">true</knora-api:isShared>
<knora-api:lastModificationDate rdf:datatype="http://www.w3.org/2001/XMLSchema#string">2018-09-10T14:53:00Z</knora-api:lastModificationDate>
<knora-api:lastModificationDate rdf:datatype="http://www.w3.org/2001/XMLSchema#dateTimeStamp">2018-09-10T14:53:00Z</knora-api:lastModificationDate>
<rdfs:label rdf:datatype="http://www.w3.org/2001/XMLSchema#string">An example of a shared ontology</rdfs:label>
</owl:Ontology>
<owl:Ontology rdf:about="http://api.knora.org/ontology/standoff/v2">
Expand Down
@@ -1,15 +1,16 @@
@prefix knora-api: <http://api.knora.org/ontology/knora-api/v2#> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .

<http://0.0.0.0:3333/ontology/0001/anything/v2> a owl:Ontology;
knora-api:attachedToProject <http://rdfh.ch/projects/0001>;
knora-api:lastModificationDate "2017-12-19T15:23:42.166Z";
knora-api:lastModificationDate "2017-12-19T15:23:42.166Z"^^xsd:dateTimeStamp;
rdfs:label "The anything ontology" .

<http://0.0.0.0:3333/ontology/0001/minimal/v2> a owl:Ontology;
knora-api:attachedToProject <http://rdfh.ch/projects/0001>;
knora-api:lastModificationDate "2019-09-10T08:57:46.633162Z";
knora-api:lastModificationDate "2019-09-10T08:57:46.633162Z"^^xsd:dateTimeStamp;
rdfs:label "A minimal ontology" .

<http://0.0.0.0:3333/ontology/0001/something/v2> a owl:Ontology;
Expand Down Expand Up @@ -58,7 +59,7 @@
<http://api.knora.org/ontology/shared/example-box/v2> a owl:Ontology;
knora-api:attachedToProject <http://www.knora.org/ontology/knora-admin#DefaultSharedOntologiesProject>;
knora-api:isShared true;
knora-api:lastModificationDate "2018-09-10T14:53:00Z";
knora-api:lastModificationDate "2018-09-10T14:53:00Z"^^xsd:dateTimeStamp;
rdfs:label "An example of a shared ontology" .

<http://api.knora.org/ontology/standoff/v2> a owl:Ontology;
Expand Down
Expand Up @@ -2236,7 +2236,10 @@
"knora-api:attachedToProject" : {
"@id" : "http://rdfh.ch/projects/0001"
},
"knora-api:lastModificationDate" : "2017-12-19T15:23:42.166Z",
"knora-api:lastModificationDate" : {
"@type" : "xsd:dateTimeStamp",
"@value" : "2017-12-19T15:23:42.166Z"
},
"rdfs:label" : "The anything ontology",
"@context" : {
"rdf" : "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
Expand Down

0 comments on commit 22727a2

Please sign in to comment.