Commit c1a17f27 authored by R.W.Majeed's avatar R.W.Majeed

JAXB implementation of query

parent d35accb8
Common API for the AKTIN data warehouse
\ No newline at end of file
Common API for the AKTIN data warehouse
---------------------------------------
Generate XSD files:
```
"$JAVA_HOME"/bin/schemagen -d target -cp target/classes org.aktin.exchange.Query
```
Query exchange
--------------
```
<request>
<id>unique request id</id>
<date-reference>2016-04-11</date-reference>
<published>
<query>
<id>unique query id</id>
<description>
</description>
<principal>
<name></name>
<organisation></organisation>
<location></location>
<email></email>
<phone></phone>
<url></url>
</principal>
<schedule type="single|repeating|benchmark">
<duration>-P1Y</duration>
<interval>P1Y</interval>
</schedule>
<concepts>
<concept id="CEDIS30:XXX" type="raw"/>
<concept id="XXX1" type="aggregate">
<count group-by="fact.value">
</concept>
<concept id="XXX1" type="aggregate">
<!-- by arrival time -->
<count group-by="substr(8,10,fact.start)">
<max/>
<min/>
</concept>
</concepts>
<definition xsi:type="sql">
</definition>
</query>
<signature from="broker" algorithm="SHA256withRSA">...</signature>
<signature from="me" algorithm="SHA256withRSA">...</signature>
<broker>
<last-modified>max timestamp der nachfolgenden</last-modified>
<!-- timestamp the query was published by the broker -->
<published>2015-12-01T18:30:14</published>
<!-- later, the query can be either canceled or closed -->
<closed>2015-12-02T18:30:00</closed>
<canceled>2015-12-02T18:30:14</canceled>
</broker>
</query>
<request-status ref="123">
<last-modified>max timestampt der nachfolgenden</last-modified>
<received>XXXtimestamp</received>
<confirmation method="single|double|automatic">xxx</confirmation>
<!-- confirmation or rejection -->
<rejected></rejected>
<comment></comment>
<last-execution>
<completed>XXXtimestamp</completed>
<failed></failed>
</last-execution>
<last-contact>
<result-submitted>XXX timestamp</result-submitted>
</request-status>
<query-result id-ref="">
</query-result>
```
Error in maven schemagen:
Post error in maven schemagen:
Should not convert spaces to %20:
schemagen -encoding UTF-8 -d D:\Users\marap1\Projects\2014-09 AKTIN\repo-v2\aktin\dwh-api\target\schemagen-work\compile_scope -classpath /D:/Users/marap1/Projects/2014-09%20AKTIN/repo-v2/aktin/dwh-api/src/main/java/ -episode D:\Users\marap1\Projects\2014-09 AKTIN\repo-v2\aktin\dwh-api\target\generated-resources\schemagen\META-INF\sun-jaxb.episode src\main\java\org\aktin\exchange\AbstractConcept.java src\main\java\org\aktin\exchange\Principal.java src\main\java\org\aktin\exchange\Query.java src\main\java\org\aktin\exchange\RawConcept.java src\main\java\org\aktin\exchange\XMLConstants.java src\main\java\org\aktin\exchange\package-info.java
https://github.com/mojohaus/jaxb2-maven-plugin/issues/
......@@ -12,16 +12,37 @@
<version>0.1-SNAPSHOT</version>
</parent>
<build>
<!--
<resources>
<resource>
<directory>src/main/resources</directory>
</resource>
<resource>
<directory>target/generated-resources</directory>
</resource>
</resources>
-->
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxb2-maven-plugin</artifactId>
<version>2.2</version>
<executions>
<execution>
<id>schemagen</id>
<goals>
<goal>schemagen</goal>
</goals>
</execution>
</executions>
<configuration>
<locale>en</locale>
<sources>
<source>src/main/java/org/aktin/exchange</source>
</sources>
</configuration>
</plugin>
</plugins>
</build>
</build>
<dependencies>
<!-- unit tests -->
<dependency>
......
package org.aktin.exchange;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlSeeAlso;
@XmlSeeAlso({RawConcept.class})
public abstract class AbstractConcept {
/**
* Unique identifier of the concept.
*/
@XmlAttribute
public String id;
}
package org.aktin.exchange;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
/**
* Principal of a query.
* @author R.W.Majeed
*
*/
@XmlAccessorType(XmlAccessType.FIELD)
public class Principal {
/**
* Principal's full name
*/
@XmlElement(required=true)
public String name;
/**
* Principal's organisation
*/
@XmlElement(required=true)
public String organisation;
@XmlElement(required=true)
public String email;
@XmlElement(required=true)
public String phone;
/**
* Postal address
*/
public String address;
/**
* Web page URL
*/
public String url;
}
package org.aktin.exchange;
import java.util.List;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementWrapper;
import javax.xml.bind.annotation.XmlRootElement;
/**
* Query which can be executed in an i2b2
* data warehouse by the AKTIN remote query
* plugin.
*
* @author R.W.Majeed
*
*/
@XmlRootElement
@XmlAccessorType(XmlAccessType.NONE)
public class Query {
/**
* Unique identifier for this query. This identifier
* will not change, even if a query scheduled for repeated
* executions.
*/
@XmlElement(required=true)
public String id;
/**
* Human readable description of the query.
*/
@XmlElement(required=true)
public String description;
/**
* Contact for inquiries and further
* information about the query and research
* project.
*/
@XmlElement(required=true)
public Principal principal;
/**
* Execution schedule for the query. For now,
* only {@link SingleExecution} and {@link RepeatedExecution}
* are supported.
*/
@XmlElement(required=true)
public QuerySchedule schedule;
@XmlElementWrapper(name="concepts",required=true)
@XmlElement(name="concept",required=true)
public List<AbstractConcept> concepts;
}
package org.aktin.exchange;
import java.time.Instant;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
public class QueryRequest {
/**
* Unique id for the query request.
* This id will always be unique and different
* for multiple (e.g. recurring) requests for
* the same query.
* The id is given by the broker.
*/
@XmlElement(required=true)
String id;
/**
* Date reference for recurring queries. A recurring
* query may be requested once per month. The reference
* date will then be used to determine the time frame
* for the query. In other words, the reference date is used
* to fill a placeholder in the recurring query.
*/
@XmlElement(required=false)
Instant referenceDate;
/**
* Time stamp when the request was published at the query broker.
*/
Instant published;
/**
* Due date until which the query results have to be submitted.
*/
Instant deadline;
/**
* Date when the request was closed by the query broker. While
* this date is unset/null, results can be sumitted at any time.
*/
Instant closed;
/**
* Date when the request was canceled. This indicates abnormal
* or unsuccessful termination of the request.
* A request can not be closed and canceled at the same time.
*/
Instant canceled;
/**
* Query to execute
*/
@XmlElement(required=true)
Query query;
@XmlElement(name="signature", required=false)
Signature[] signatures;
}
package org.aktin.exchange;
import java.time.Period;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlSeeAlso;
/**
* Abstract query schedule
* @author R.W.Majeed
*
*/
@XmlSeeAlso({SingleExecution.class, RepeatedExecution.class})
public abstract class QuerySchedule {
/**
* Duration for the query. The duration is relative
* to the {@link #reference} timestamp and might also be negative.
*/
@XmlElement(required=true)
public Period duration;
}
package org.aktin.exchange;
import javax.xml.bind.annotation.XmlType;
@XmlType(name="raw")
public class RawConcept extends AbstractConcept{
}
package org.aktin.exchange;
import java.time.Duration;
/**
* Repeated execution schedule for a query.
*
* The repeated execution does not contain a reference timestamp. Instead, the reference
* timestamp is provided by the query request from the broker.
*
* @author R.W.Majeed
*
*/
public class RepeatedExecution extends QuerySchedule{
/**
* Estimated repeating interval. Only positive periods allowed.
* This property will not cause any execution on the data warehouse side.
* It is solely for information purposes.
*/
public Duration repeats;
}
package org.aktin.exchange;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlValue;
/**
* Signature during query exchange
*
* @author R.W.Majeed
*
*/
public class Signature {
/** Signature author */
@XmlAttribute
String from;
/** Signature algorithm */
@XmlAttribute
String algorithm;
@XmlValue
byte[] value;
// TODO add code to verify content
}
package org.aktin.exchange;
import java.time.Instant;
import javax.xml.bind.annotation.XmlElement;
/**
* Single execution schedule for a query.
*
* A reference time stamp is provided.
*
* @author R.W.Majeed
*
*/
public class SingleExecution extends QuerySchedule{
/**
* Reference time stamp for queries. If
*/
@XmlElement(required=false)
public Instant reference;
}
package org.aktin.exchange;
import javax.xml.bind.annotation.XmlTransient;
@XmlTransient
public class XMLConstants {
public static final String XML_NAMESPACE="http://aktin.org/ns/exchange";
}
/**
* Interfaces for the AKTIN data exchange.
* Requests for query executions, query definitions,
* query responses.
*
* @author R.W.Majeed
*
*/
@XmlSchema(namespace=XMLConstants.XML_NAMESPACE,
elementFormDefault=XmlNsForm.QUALIFIED,
xmlns = {
@XmlNs(prefix = "xsi", namespaceURI = javax.xml.XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI)
//"http://www.w3.org/2001/XMLSchema-instance"
}
)
@javax.xml.bind.annotation.adapters.XmlJavaTypeAdapters({
@javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter(type=java.time.Duration.class,value=org.aktin.xml.DurationAdapter.class),
@javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter(type=java.time.Period.class,value=org.aktin.xml.PeriodAdapter.class),
@javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter(type=java.time.Instant.class,value=org.aktin.xml.InstantAdapter.class)
})
package org.aktin.exchange;
import javax.xml.bind.annotation.*;
\ No newline at end of file
package org.aktin.xml;
import java.time.Duration;
import javax.xml.bind.annotation.adapters.XmlAdapter;
/**
* JAXB adapter for processing java.time.Duration.
* This can be removed later on when native support is added to the JAXB implementation
*
*/
public class DurationAdapter extends XmlAdapter<String, Duration>{
@Override
public String marshal(Duration v) throws Exception {
if( v == null )return null;
else return v.toString();
}
@Override
public Duration unmarshal(String v) throws Exception {
if( v == null )return null;
else return Duration.parse(v);
}
}
\ No newline at end of file
package org.aktin.xml;
import java.time.Instant;
import javax.xml.bind.annotation.adapters.XmlAdapter;
/**
* JAXB adapter for processing java.time.Instant.
* This can be removed later on when native support is added to the JAXB implementation
*
*/
public class InstantAdapter extends XmlAdapter<String, Instant>{
@Override
public Instant unmarshal(String v) throws Exception {
if( v == null )return null;
else return Instant.parse(v);
}
@Override
public String marshal(Instant v) throws Exception {
if( v == null )return null;
else return v.toString();
}
}
\ No newline at end of file
package org.aktin.xml;
import java.time.Period;
import javax.xml.bind.annotation.adapters.XmlAdapter;
/**
* JAXB adapter for processing java.time.Duration.
* This can be removed later on when native support is added to the JAXB implementation
*
*/
public class PeriodAdapter extends XmlAdapter<String, Period>{
@Override
public String marshal(Period v) throws Exception {
if( v == null )return null;
else return v.toString();
}
@Override
public Period unmarshal(String v) throws Exception {
if( v == null )return null;
else return Period.parse(v);
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment