]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
DRYD-753: Change struct date parser response to resemble struct date fields in records.
authorRay Lee <ray.lee@lyrasis.org>
Tue, 22 Oct 2019 20:07:35 +0000 (13:07 -0700)
committerRay Lee <ray.lee@lyrasis.org>
Wed, 23 Oct 2019 05:00:23 +0000 (22:00 -0700)
services/structureddate/client/src/main/java/org/collectionspace/services/structureddate/StructuredDateClient.java
services/structureddate/jaxb/src/main/resources/structureddate-common.xsd
services/structureddate/service/src/main/java/org/collectionspace/services/structureddate/StructuredDateResource.java

index 127403163cd506d6060abeea26f9e901976a9d9c..43cb08379a5948710e88238d700b0fb7f6e3264f 100644 (file)
@@ -7,8 +7,9 @@ package org.collectionspace.services.structureddate;
  */
 public class StructuredDateClient {
        public static final String SERVICE_NAME = "structureddates";
-       public static final String SERVICE_PATH_COMPONENT = SERVICE_NAME;       
+       public static final String SERVICE_PATH_COMPONENT = SERVICE_NAME;
        public static final String SERVICE_PATH = "/" + SERVICE_PATH_COMPONENT;
        public static final String SERVICE_PAYLOAD_NAME = SERVICE_NAME;
        public static final String DATE_TO_PARSE_QP = "dateToParse";
+       public static final String DISPLAY_DATE_QP = "displayDate";
 }
index ee27baac9a0f55cf71d1f6ed3327a2a8a77ff62a..7d05df2e9cf7589a083122ab29d9f671bc2902e9 100644 (file)
@@ -1,56 +1,82 @@
 <?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>
index 327a3a2f891b78c47ceaa2990fb693067ee95f85..9517356355703700cbd2cffce3262a2d6331a276 100644 (file)
@@ -45,122 +45,195 @@ public class StructuredDateResource extends AbstractCollectionSpaceResourceImpl<
        // 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();
        }
 }