From: Ray Lee Date: Tue, 22 Oct 2019 20:07:35 +0000 (-0700) Subject: DRYD-753: Change struct date parser response to resemble struct date fields in records. X-Git-Url: https://git.aero2k.de/?a=commitdiff_plain;h=786ebce8d33a8536b85df093121a55602ee97f7e;p=tmp%2Fjakarta-migration.git DRYD-753: Change struct date parser response to resemble struct date fields in records. --- diff --git a/services/structureddate/client/src/main/java/org/collectionspace/services/structureddate/StructuredDateClient.java b/services/structureddate/client/src/main/java/org/collectionspace/services/structureddate/StructuredDateClient.java index 127403163..43cb08379 100644 --- a/services/structureddate/client/src/main/java/org/collectionspace/services/structureddate/StructuredDateClient.java +++ b/services/structureddate/client/src/main/java/org/collectionspace/services/structureddate/StructuredDateClient.java @@ -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"; } diff --git a/services/structureddate/jaxb/src/main/resources/structureddate-common.xsd b/services/structureddate/jaxb/src/main/resources/structureddate-common.xsd index ee27baac9..7d05df2e9 100644 --- a/services/structureddate/jaxb/src/main/resources/structureddate-common.xsd +++ b/services/structureddate/jaxb/src/main/resources/structureddate-common.xsd @@ -1,56 +1,82 @@ - + - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - + + + + + + + + + + + + + + diff --git a/services/structureddate/service/src/main/java/org/collectionspace/services/structureddate/StructuredDateResource.java b/services/structureddate/service/src/main/java/org/collectionspace/services/structureddate/StructuredDateResource.java index 327a3a2f8..951735635 100644 --- a/services/structureddate/service/src/main/java/org/collectionspace/services/structureddate/StructuredDateResource.java +++ b/services/structureddate/service/src/main/java/org/collectionspace/services/structureddate/StructuredDateResource.java @@ -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 ctx = createServiceContext(getServiceName()); + MultivaluedMap 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 ctx = createServiceContext(getServiceName()); - MultivaluedMap 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 getServiceContextFactory() { - return (ServiceContextFactory) RemoteServiceContextFactory.get(); + return (ServiceContextFactory) RemoteServiceContextFactory.get(); } }