universAAL / middleware

The core software that uses semantic matchmaking for brokering messages among participants of an open distributed system.
10 stars 3 forks source link

Duration datatype is not serialized #492

Closed amedranogil closed 6 years ago

amedranogil commented 6 years ago

Eventhough Duration is managed as a datatype (exists in TypeMapper), it is not serialised at all.

Example:

Session s =new Session();
s.setLast_for(Duration.ofSeconds(150));
s.changeProperty(Session.PROP_LAST_FOR, Duration.ofSeconds(150));

GregorianCalendar c = new GregorianCalendar();
c.setTime(new Date());
XMLGregorianCalendar date2 = DatatypeFactory.newInstance().newXMLGregorianCalendar(c);
chats.setStarts_at(date2);
ContextEvent ce = new ContextEvent(new Resource("userURI"), "http://sample.com/User#produces", chats);
String ser = mcs.serialize(ce);
System.out.println(ser);

Results in :

@prefix ns: <http://sample.com/User#> .
@prefix ns1: <http://ontology.universAAL.org/Context.owl#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix : <http://ontology.universAAL.org/Sessions#> .
<urn:org.universAAL.middleware.context.rdf:ContextEvent#_:0a004b01cdcf8e3c:f4d> a ns1:ContextEvent ;
  rdf:subject <userURI> ;
  ns1:hasTimestamp "1528273482588"^^xsd:long ;
  rdf:predicate ns:Produces ;
  rdf:object _:BN000000 .
_:BN000000 a :FixedChatSession ,
    :ChatSession ,
    :FixedWindowedSession ,
    :Session ;
  :starts_at "2018-06-06T10:24:42.586+02:00"^^xsd:dateTime .
<userURI> ns:Produces _:BN000000 .

Property "Session.PROP_LAST_FOR" has only one restriction determining Duration is the expected type.

Alfiva commented 6 years ago

The first thing that comes to my mind is: Serialization type (FULL, OPTIONAL...) for this property does not serialize it. Have you checked that?

amedranogil commented 6 years ago

Using default behaviour out of the UMLTransformation tool. I guess, since the rest has FULL serialization, this property does too.

amedranogil commented 6 years ago

There was a problem with Java, the correct way to create Duration is:

 Duration dur = DatatypeFactory.newInstance().newDuration(90000); //in ms
 s.setLast_for(dur);

This produces:

:last_for "P0Y0M0DT0H1M30.000S"^^xsd:duration ;