<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<!--
- StructuredDate schema (XSD)
-
- Entity : StructuredDate
- Part : Common
- Used for: JAXB binding between XML and Java objects
+ StructuredDate schema (XSD)
+ Entity : StructuredDate
+ Part : Common
+ Used for: JAXB binding between XML and Java objects
-->
<xs:schema
- xmlns:xs="http://www.w3.org/2001/XMLSchema"
- xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
- jaxb:version="1.0" elementFormDefault="unqualified"
- xmlns:ns="http://collectionspace.org/services/structureddate"
- xmlns="http://collectionspace.org/services/structureddate"
- targetNamespace="http://collectionspace.org/services/structureddate"
- version="0.1"
+ xmlns:xs="http://www.w3.org/2001/XMLSchema"
+ xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
+ jaxb:version="1.0" elementFormDefault="unqualified"
+ xmlns:ns="http://collectionspace.org/services/structureddate"
+ xmlns="http://collectionspace.org/services/structureddate"
+ targetNamespace="http://collectionspace.org/services/structureddate"
+ version="1.0"
>
<!--
- Avoid XmlRootElement nightmare:
- See http://weblogs.java.net/blog/kohsuke/archive/2006/03/why_does_jaxb_p.html
+ Avoid XmlRootElement nightmare:
+ See http://weblogs.java.net/blog/kohsuke/archive/2006/03/why_does_jaxb_p.html
-->
- <xs:element name="structureddate_common">
+ <xs:element name="structureddate_common">
<xs:complexType>
<xs:sequence>
- <xs:element name="displayDate" type="xs:string"/>
- <xs:element name="note" type="xs:string"/>
- <xs:element name="association" type="xs:string"/>
- <xs:element name="period" type="xs:string"/>
- <xs:element name="earliestSingleDate" type="date_common"/>
- <xs:element name="latestDate" type="date_common"/>
- <xs:element name="earliestScalarValue" type="xs:string"/>
- <xs:element name="latestScalarValue" type="xs:string"/>
- <xs:element name="scalarValuesComputed" type="xs:boolean"/>
+ <xs:element name="dateDisplayDate" type="xs:string" />
+ <xs:element name="datePeriod" type="xs:string" />
+ <xs:element name="dateAssociation" type="xs:string" />
+ <xs:element name="dateNote" type="xs:string" />
+
+ <xs:element name="dateEarliestSingleYear" type="xs:integer" />
+ <xs:element name="dateEarliestSingleMonth" type="xs:integer" />
+ <xs:element name="dateEarliestSingleDay" type="xs:integer" />
+ <xs:element name="dateEarliestSingleEra" type="xs:string" />
+ <xs:element name="dateEarliestSingleCertainty" type="xs:string" />
+ <xs:element name="dateEarliestSingleQualifier" type="xs:string" />
+ <xs:element name="dateEarliestSingleQualifierValue" type="xs:integer" />
+ <xs:element name="dateEarliestSingleQualifierUnit" type="xs:string" />
+
+ <xs:element name="dateLatestYear" type="xs:integer" />
+ <xs:element name="dateLatestMonth" type="xs:integer" />
+ <xs:element name="dateLatestDay" type="xs:integer" />
+ <xs:element name="dateLatestEra" type="xs:string" />
+ <xs:element name="dateLatestCertainty" type="xs:string" />
+ <xs:element name="dateLatestQualifier" type="xs:string" />
+ <xs:element name="dateLatestQualifierValue" type="xs:integer" />
+ <xs:element name="dateLatestQualifierUnit" type="xs:string" />
+
+ <xs:element name="dateEarliestScalarValue" type="xs:string" />
+ <xs:element name="dateLatestScalarValue" type="xs:string" />
+ <xs:element name="scalarValuesComputed" type="xs:boolean" />
+
+ <!-- Deprecated -->
+ <xs:element name="displayDate" type="xs:string"/>
+ <xs:element name="period" type="xs:string"/>
+ <xs:element name="association" type="xs:string"/>
+ <xs:element name="note" type="xs:string"/>
+ <xs:element name="earliestSingleDate" type="date_common"/>
+ <xs:element name="latestDate" type="date_common"/>
+ <xs:element name="earliestScalarValue" type="xs:string"/>
+ <xs:element name="latestScalarValue" type="xs:string"/>
</xs:sequence>
</xs:complexType>
- </xs:element>
-
- <xs:complexType name="date_common">
- <xs:sequence>
- <xs:element name="year" type="xs:integer"/>
- <xs:element name="month" type="xs:integer"/>
- <xs:element name="day" type="xs:integer"/>
- <xs:element name="era" type="xs:string"/>
- <xs:element name="certainty" type="xs:string"/>
- <xs:element name="qualifierType" type="xs:string"/>
- <xs:element name="qualifierValue" type="xs:string"/>
- <xs:element name="qualifierUnit" type="xs:string"/>
- </xs:sequence>
- </xs:complexType>
+ </xs:element>
+ <!-- Deprecated -->
+ <xs:complexType name="date_common">
+ <xs:sequence>
+ <xs:element name="year" type="xs:integer"/>
+ <xs:element name="month" type="xs:integer"/>
+ <xs:element name="day" type="xs:integer"/>
+ <xs:element name="era" type="xs:string"/>
+ <xs:element name="certainty" type="xs:string"/>
+ <xs:element name="qualifierType" type="xs:string"/>
+ <xs:element name="qualifierValue" type="xs:integer"/>
+ <xs:element name="qualifierUnit" type="xs:string"/>
+ </xs:sequence>
+ </xs:complexType>
</xs:schema>
// API Endpoints
//
- @GET
- public StructureddateCommon get(@Context UriInfo ui) {
- StructureddateCommon result = null;
+ @GET
+ public StructureddateCommon get(@Context UriInfo ui) {
+ StructureddateCommon result = null;
+
+ try {
+ ServiceContext<StructureddateCommon, StructureddateCommon> ctx = createServiceContext(getServiceName());
+ MultivaluedMap<String,String> queryParams = ui.getQueryParameters();
+ String displayDate = queryParams.getFirst(StructuredDateClient.DISPLAY_DATE_QP);
+ String dateToParse = queryParams.getFirst(StructuredDateClient.DATE_TO_PARSE_QP);
+
+ if (Tools.isEmpty(displayDate) != true) {
+ // The normal form of this call: accepts the display date in the displayDate param,
+ // returns a v1.0 Structured Date Common payload, which has the same structure as structured
+ // date fields in records.
+ StructuredDateInternal structuredDate = StructuredDateInternal.parse(displayDate);
+ result = toStructureddateCommon(ctx.getTenantName(), structuredDate);
+ } else if (Tools.isEmpty(dateToParse) != true) {
+ // The deprecated form of this call: accepts the display date in the dateToParse param,
+ // returns a v0.1 Structured Date Common payload, which resembles the StructuredDateInternal
+ // object.
+ StructuredDateInternal structuredDate = StructuredDateInternal.parse(dateToParse);
+ result = toStructureddateCommonV01(ctx.getTenantName(), structuredDate);
+ } else {
+ String msg = String.format("Use the '%s' query parameter to specify a display date to parse.",
+ StructuredDateClient.DISPLAY_DATE_QP);
+ Response response =
+ Response.status(Response.Status.BAD_REQUEST).entity(msg).type("text/plain").build();
+ throw new CSWebApplicationException(response);
+ }
+ } catch(StructuredDateFormatException fe) {
+ Response response = Response.status(Response.Status.BAD_REQUEST).entity(fe.getMessage()).type("text/plain").build();
+ throw new CSWebApplicationException(response);
+ } catch (Exception e) {
+ throw bigReThrow(e, ServiceMessages.GET_FAILED);
+ }
+
+ return result;
+ }
- try {
- ServiceContext<StructureddateCommon, StructureddateCommon> ctx = createServiceContext(getServiceName());
- MultivaluedMap<String,String> queryParams = ui.getQueryParameters();
- String dateToParse = queryParams.getFirst(StructuredDateClient.DATE_TO_PARSE_QP);
- if (Tools.isEmpty(dateToParse) != true) {
- StructuredDateInternal structuredDate = StructuredDateInternal.parse(dateToParse);
- result = toStructureddateCommon(ctx.getTenantName(), structuredDate);
- } else {
- String msg = String.format("Use the '%s' query parameter to specify a date string you want parsed.",
- StructuredDateClient.DATE_TO_PARSE_QP);
- Response response =
- Response.status(Response.Status.BAD_REQUEST).entity(msg).type("text/plain").build();
- throw new CSWebApplicationException(response);
- }
- } catch(StructuredDateFormatException fe) {
- Response response = Response.status(Response.Status.BAD_REQUEST).entity(fe.getMessage()).type("text/plain").build();
- throw new CSWebApplicationException(response);
- } catch (Exception e) {
- throw bigReThrow(e, ServiceMessages.GET_FAILED);
- }
+ private StructureddateCommon toStructureddateCommon(String tenantDomain, StructuredDateInternal structuredDate) {
+ StructureddateCommon result = new StructureddateCommon();
- return result;
- }
+ String displayDate = structuredDate.getDisplayDate();
- private StructureddateCommon toStructureddateCommon(String tenantDomain, StructuredDateInternal structuredDate) {
- StructureddateCommon result = new StructureddateCommon();
+ if (!Tools.isEmpty(displayDate)) {
+ result.setDateDisplayDate(displayDate);
+ }
- String association = structuredDate.getAssociation();
+ String earliestScalarValue = structuredDate.getEarliestScalarValue();
- if (!Tools.isEmpty(association)) {
- result.setAssociation(association);
- }
+ if (!Tools.isEmpty(earliestScalarValue)) {
+ result.setDateEarliestScalarValue(earliestScalarValue);
+ }
- String displayDate = structuredDate.getDisplayDate();
+ String latestScalarValue = structuredDate.getLatestScalarValue();
- if (!Tools.isEmpty(displayDate)) {
- result.setDisplayDate(displayDate);
- }
+ if (!Tools.isEmpty(latestScalarValue)) {
+ result.setDateLatestScalarValue(latestScalarValue);
+ }
- String earliestScalarValue = structuredDate.getEarliestScalarValue();
+ result.setScalarValuesComputed(structuredDate.areScalarValuesComputed());
- if (!Tools.isEmpty(earliestScalarValue)) {
- result.setEarliestScalarValue(earliestScalarValue);
+ Date earliestSingleDate = structuredDate.getEarliestSingleDate();
+
+ if (earliestSingleDate != null) {
+ if (earliestSingleDate.getYear() != null) {
+ result.setDateEarliestSingleYear(BigInteger.valueOf(earliestSingleDate.getYear()));
}
- String latestScalarValue = structuredDate.getLatestScalarValue();
+ if (earliestSingleDate.getMonth() != null) {
+ result.setDateEarliestSingleMonth(BigInteger.valueOf(earliestSingleDate.getMonth()));
+ }
- if (!Tools.isEmpty(latestScalarValue)) {
- result.setLatestScalarValue(latestScalarValue);
+ if (earliestSingleDate.getDay() != null) {
+ result.setDateEarliestSingleDay(BigInteger.valueOf(earliestSingleDate.getDay()));
}
- result.setScalarValuesComputed(structuredDate.areScalarValuesComputed());
+ if (earliestSingleDate.getEra() != null) {
+ result.setDateEarliestSingleEra(earliestSingleDate.getEra().toString(tenantDomain));
+ }
+ }
+
+ Date latestDate = structuredDate.getLatestDate();
- Date earliestSingleDate = structuredDate.getEarliestSingleDate();
+ if (latestDate != null) {
+ if (latestDate.getYear() != null) {
+ result.setDateLatestYear(BigInteger.valueOf(latestDate.getYear()));
+ }
- if (earliestSingleDate != null) {
- result.setEarliestSingleDate(toDateCommon(tenantDomain, earliestSingleDate));
+ if (latestDate.getMonth() != null) {
+ result.setDateLatestMonth(BigInteger.valueOf(latestDate.getMonth()));
}
- Date latestDate = structuredDate.getLatestDate();
+ if (latestDate.getDay() != null) {
+ result.setDateLatestDay(BigInteger.valueOf(latestDate.getDay()));
+ }
- if (latestDate != null) {
- result.setLatestDate(toDateCommon(tenantDomain, latestDate));
+ if (latestDate.getEra() != null) {
+ result.setDateLatestEra(latestDate.getEra().toString(tenantDomain));
}
+ }
+
+ return result;
+ }
+
+ @Deprecated
+ private StructureddateCommon toStructureddateCommonV01(String tenantDomain, StructuredDateInternal structuredDate) {
+ StructureddateCommon result = new StructureddateCommon();
+
+ String displayDate = structuredDate.getDisplayDate();
+
+ if (!Tools.isEmpty(displayDate)) {
+ result.setDisplayDate(displayDate);
+ }
- return result;
+ String earliestScalarValue = structuredDate.getEarliestScalarValue();
+
+ if (!Tools.isEmpty(earliestScalarValue)) {
+ result.setEarliestScalarValue(earliestScalarValue);
+ }
+
+ String latestScalarValue = structuredDate.getLatestScalarValue();
+
+ if (!Tools.isEmpty(latestScalarValue)) {
+ result.setLatestScalarValue(latestScalarValue);
}
- private DateCommon toDateCommon(String tenantDomain, org.collectionspace.services.structureddate.Date date) {
- DateCommon result = null;
+ result.setScalarValuesComputed(structuredDate.areScalarValuesComputed());
+
+ Date earliestSingleDate = structuredDate.getEarliestSingleDate();
- if (date != null) {
- result = new DateCommon();
+ if (earliestSingleDate != null) {
+ result.setEarliestSingleDate(toDateCommon(tenantDomain, earliestSingleDate));
+ }
- if (date.getCertainty() != null) {
- result.setCertainty(date.getCertainty().toString());
- }
+ Date latestDate = structuredDate.getLatestDate();
- if (date.getDay() != null) {
- result.setDay(BigInteger.valueOf(date.getDay()));
- }
+ if (latestDate != null) {
+ result.setLatestDate(toDateCommon(tenantDomain, latestDate));
+ }
- if (date.getEra() != null) {
- result.setEra(date.getEra().toString(tenantDomain));
- }
+ return result;
+ }
- if (date.getMonth() != null) {
- result.setMonth(BigInteger.valueOf(date.getMonth()));
- }
+ @Deprecated
+ private DateCommon toDateCommon(String tenantDomain, org.collectionspace.services.structureddate.Date date) {
+ DateCommon result = null;
- if (date.getQualifierType() != null) {
- result.setQualifierType(date.getQualifierType().toString());
- }
+ if (date != null) {
+ result = new DateCommon();
- if (date.getQualifierUnit() != null) {
- result.setQualifierUnit(date.getQualifierUnit().toString());
- }
+ if (date.getCertainty() != null) {
+ result.setCertainty(date.getCertainty().toString());
+ }
- if (date.getQualifierValue() != null) {
- result.setQualifierValue(date.getQualifierValue().toString());
- }
+ if (date.getDay() != null) {
+ result.setDay(BigInteger.valueOf(date.getDay()));
+ }
- if (date.getYear() != null) {
- result.setYear(BigInteger.valueOf(date.getYear()));
- }
- }
+ if (date.getEra() != null) {
+ result.setEra(date.getEra().toString(tenantDomain));
+ }
- return result;
- }
+ if (date.getMonth() != null) {
+ result.setMonth(BigInteger.valueOf(date.getMonth()));
+ }
+
+ if (date.getQualifierType() != null) {
+ result.setQualifierType(date.getQualifierType().toString());
+ }
+
+ if (date.getQualifierUnit() != null) {
+ result.setQualifierUnit(date.getQualifierUnit().toString());
+ }
+
+ if (date.getQualifierValue() != null) {
+ result.setQualifierValue(BigInteger.valueOf(date.getQualifierValue()));
+ }
+
+ if (date.getYear() != null) {
+ result.setYear(BigInteger.valueOf(date.getYear()));
+ }
+ }
+
+ return result;
+ }
@Override
public ServiceContextFactory<StructureddateCommon, StructureddateCommon> getServiceContextFactory() {
- return (ServiceContextFactory<StructureddateCommon, StructureddateCommon>) RemoteServiceContextFactory.get();
+ return (ServiceContextFactory<StructureddateCommon, StructureddateCommon>) RemoteServiceContextFactory.get();
}
}