From: Richard Millet Date: Thu, 30 Aug 2012 18:09:31 +0000 (-0700) Subject: CSPACE-5492: More dependency shuffling to get things compiling again after authority... X-Git-Url: https://git.aero2k.de/?a=commitdiff_plain;h=0704addba5f7e1c2eca0bde401a827880b61d94c;p=tmp%2Fjakarta-migration.git CSPACE-5492: More dependency shuffling to get things compiling again after authority item hierarchy transplant. --- diff --git a/services/IntegrationTests/src/test/java/org/collectionspace/services/IntegrationTests/test/CollectionSpaceIntegrationTest.java b/services/IntegrationTests/src/test/java/org/collectionspace/services/IntegrationTests/test/CollectionSpaceIntegrationTest.java index ce402cdf9..03e9ef279 100644 --- a/services/IntegrationTests/src/test/java/org/collectionspace/services/IntegrationTests/test/CollectionSpaceIntegrationTest.java +++ b/services/IntegrationTests/src/test/java/org/collectionspace/services/IntegrationTests/test/CollectionSpaceIntegrationTest.java @@ -39,7 +39,7 @@ import org.collectionspace.services.client.PoxPayloadIn; import org.collectionspace.services.collectionobject.CollectionobjectsCommon; import org.collectionspace.services.collectionobject.TitleGroup; import org.collectionspace.services.collectionobject.TitleGroupList; -import org.collectionspace.services.common.datetime.GregorianCalendarDateTimeUtils; +import org.collectionspace.services.common.api.GregorianCalendarDateTimeUtils; import org.collectionspace.services.intake.IntakesCommon; import org.collectionspace.services.relation.RelationsCommon; import org.jboss.resteasy.client.ClientResponse; diff --git a/services/JaxRsServiceProvider/src/main/java/org/collectionspace/services/jaxrs/CollectionSpaceJaxRsApplication.java b/services/JaxRsServiceProvider/src/main/java/org/collectionspace/services/jaxrs/CollectionSpaceJaxRsApplication.java index 7ed9eef6a..7276c2d3c 100644 --- a/services/JaxRsServiceProvider/src/main/java/org/collectionspace/services/jaxrs/CollectionSpaceJaxRsApplication.java +++ b/services/JaxRsServiceProvider/src/main/java/org/collectionspace/services/jaxrs/CollectionSpaceJaxRsApplication.java @@ -40,7 +40,6 @@ import org.collectionspace.services.place.PlaceAuthorityResource; import org.collectionspace.services.concept.ConceptAuthorityResource; import org.collectionspace.services.taxonomy.TaxonomyAuthorityResource; import org.collectionspace.services.movement.MovementResource; -import org.collectionspace.services.relation.RelationResource; import org.collectionspace.services.report.ReportResource; import org.collectionspace.services.acquisition.AcquisitionResource; import org.collectionspace.services.dimension.DimensionResource; @@ -68,6 +67,7 @@ import org.collectionspace.services.common.ResourceBase; import org.collectionspace.services.common.ResourceMap; import org.collectionspace.services.common.ResourceMapHolder; import org.collectionspace.services.common.ResourceMapImpl; +import org.collectionspace.services.common.relation.RelationResource; import org.collectionspace.services.common.security.SecurityInterceptor; import org.jboss.resteasy.core.Dispatcher; import org.jboss.resteasy.spi.ResteasyProviderFactory; diff --git a/services/acquisition/client/src/test/java/org/collectionspace/services/client/test/AcquisitionServiceTest.java b/services/acquisition/client/src/test/java/org/collectionspace/services/client/test/AcquisitionServiceTest.java index d00090568..18ed56d7e 100644 --- a/services/acquisition/client/src/test/java/org/collectionspace/services/client/test/AcquisitionServiceTest.java +++ b/services/acquisition/client/src/test/java/org/collectionspace/services/client/test/AcquisitionServiceTest.java @@ -32,7 +32,7 @@ import org.collectionspace.services.client.CollectionSpaceClient; import org.collectionspace.services.client.PayloadOutputPart; import org.collectionspace.services.client.PoxPayloadIn; import org.collectionspace.services.client.PoxPayloadOut; -import org.collectionspace.services.common.datetime.GregorianCalendarDateTimeUtils; +import org.collectionspace.services.common.api.GregorianCalendarDateTimeUtils; import org.collectionspace.services.jaxb.AbstractCommonList; import org.collectionspace.services.acquisition.AcquisitionsCommon; diff --git a/services/batch/service/src/main/java/org/collectionspace/services/batch/nuxeo/CreateAndLinkLoanOutBatchJob.java b/services/batch/service/src/main/java/org/collectionspace/services/batch/nuxeo/CreateAndLinkLoanOutBatchJob.java index 808976073..c13420c08 100644 --- a/services/batch/service/src/main/java/org/collectionspace/services/batch/nuxeo/CreateAndLinkLoanOutBatchJob.java +++ b/services/batch/service/src/main/java/org/collectionspace/services/batch/nuxeo/CreateAndLinkLoanOutBatchJob.java @@ -10,7 +10,7 @@ import org.collectionspace.services.batch.BatchInvocable; import org.collectionspace.services.client.CollectionSpaceClientUtils; import org.collectionspace.services.common.ResourceBase; import org.collectionspace.services.common.ResourceMap; -import org.collectionspace.services.common.datetime.GregorianCalendarDateTimeUtils; +import org.collectionspace.services.common.api.GregorianCalendarDateTimeUtils; import org.collectionspace.services.common.invocable.InvocationContext; import org.collectionspace.services.common.invocable.InvocationResults; import org.collectionspace.services.client.LoanoutClient; diff --git a/services/collectionobject/service/src/main/java/org/collectionspace/services/collectionobject/CollectionObjectResource.java b/services/collectionobject/service/src/main/java/org/collectionspace/services/collectionobject/CollectionObjectResource.java index 228f34e79..7b3228ccd 100644 --- a/services/collectionobject/service/src/main/java/org/collectionspace/services/collectionobject/CollectionObjectResource.java +++ b/services/collectionobject/service/src/main/java/org/collectionspace/services/collectionobject/CollectionObjectResource.java @@ -27,10 +27,9 @@ package org.collectionspace.services.collectionobject; import org.collectionspace.services.client.CollectionObjectClient; import org.collectionspace.services.client.IQueryManager; +import org.collectionspace.services.client.Profiler; import org.collectionspace.services.common.ResourceBase; -import org.collectionspace.services.common.profile.Profiler; import org.collectionspace.services.jaxb.AbstractCommonList; -import org.collectionspace.services.relation.RelationResource; import org.collectionspace.services.relation.RelationsCommonList; import org.collectionspace.services.relation.RelationshipType; import org.jboss.resteasy.util.HttpResponseCodes; diff --git a/services/common-api/src/main/java/org/collectionspace/services/common/api/DateUtils.java b/services/common-api/src/main/java/org/collectionspace/services/common/api/DateUtils.java new file mode 100644 index 000000000..d76899ae3 --- /dev/null +++ b/services/common-api/src/main/java/org/collectionspace/services/common/api/DateUtils.java @@ -0,0 +1,180 @@ +package org.collectionspace.services.common.api; + +import java.text.DateFormat; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Date; +import java.util.List; +import java.util.Locale; +import java.util.TimeZone; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class DateUtils { + + private static final Logger logger = LoggerFactory.getLogger(DateUtils.class); + + final static String ISO_8601_DATE_PATTERN = "yyyy-MM-dd"; + final static String UTC_TIMEZONE_IDENTIFIER = "UTC"; + final static String ISO_8601_UTC_TIMESTAMP_PATTERN = "yyyy-MM-dd'T'HH:mm:ss'Z'"; + final static Locale NULL_LOCALE = null; + public final static List isoLanguageCodes = new ArrayList(Arrays.asList(Locale.getISOLanguages())); + + /** + * Returns the UTC time zone. + * + * @return The UTC time zone. Defaults to the closely-related GMT time zone, + * if for some reason the UTC time zone identifier cannot be understood. + */ + public static TimeZone UTCTimeZone() { + return TimeZone.getTimeZone(UTC_TIMEZONE_IDENTIFIER); + } + + /** + * Parses a presumptive date or date/time, using a supplied format pattern. + * + * @param str a String, possibly a date or date/time String. + * @param pattern A date or date/time pattern. + * + * @return A date value, resulting from parsing the String using the + * supplied pattern. Returns null if the parsing attempt fails. + */ + public static Date parseDate(String str, String pattern) { + if (pattern == null || pattern.trim().isEmpty()) { + return null; + } + if (str == null || str.trim().isEmpty()) { + return null; + } + DateFormat df = null; + Date date = null; + try { + df = new SimpleDateFormat(pattern); + date = parseDate(str, df); + } catch (IllegalArgumentException iae) { + return null; + } + return date; + } + + /** + * Parses a presumptive date or date/time, using a supplied format pattern. + * + * @param str a String, possibly a date or date/time String. + * @param df A date formatter. + * + * @return A date value, resulting from parsing the String using the + * supplied formatter. Returns null if the parsing attempt fails. + */ + public static Date parseDate(String str, DateFormat df) { + if (df == null) { + return null; + } + if (str == null || str.trim().isEmpty()) { + return null; + } + Date date = null; + try { + df.setLenient(false); + date = df.parse(str); + } catch (ParseException pe) { + return null; + } + return date; + } + + /** + * Returns the locale associated with a supplied ISO 639-1 language code. + * + * @param lang A language code. + * + * @return A locale based on that language code; or null + * if the code was null, empty, or invalid. + */ + public static Locale getLocale(String lang) { + if (lang == null || lang.trim().isEmpty()) { + logger.warn("Null or empty date language code was provided when getting locale."); + return NULL_LOCALE; + } + if (!isoLanguageCodes.contains(lang.trim())) { + logger.warn("Invalid language code '" + lang + "'"); + return NULL_LOCALE; + } + return new Locale(lang); + } + + /** + * Returns a date formatter for a provided date or date/time pattern. + * + * @param pattern A date or date/time pattern. + * + * @return A date formatter using that pattern, or null + * if the pattern was null, empty, or invalid. + */ + public static DateFormat getDateFormatter(String pattern) { + return getDateFormatter(pattern, NULL_LOCALE); + } + + /** + * Returns a date formatter for a supplied date or date/time pattern, + * in the supplied locale (if any). + * + * @param pattern A date or date/time pattern. + * @param locale A locale. + * + * @return A date formatter using that pattern and locale (if any), or null + * if the pattern was null, empty, or invalid. + */ + public static DateFormat getDateFormatter(String pattern, Locale locale) { + DateFormat df = null; + if (pattern == null || pattern.trim().isEmpty()) { + logger.warn("Null or empty date pattern string was provided when getting date formatter."); + return df; + } + try { + if (locale == null) { + df = new SimpleDateFormat(pattern); + } else { + df = new SimpleDateFormat(pattern, locale); + } + df.setLenient(false); + } catch (IllegalArgumentException iae) { + logger.warn("Invalid date pattern string '" + pattern + "': " + iae.getMessage()); + } + return df; + } + + /** + * Identifies whether a presumptive date or date/time can be parsed + * by a date parser, using a supplied format pattern. + * + * @param str a String, possibly a date or date/time String. + * @param pattern A date or date/time pattern. + * + * @return true, if the String can be parsed, using the pattern; + * false if the String cannot be parsed by the pattern, + * or if the String or pattern are null. + */ + public static boolean isParseableByDatePattern(String str, String pattern) { + if (pattern == null || pattern.trim().isEmpty()) { + return false; + } + if (str == null || str.trim().isEmpty()) { + return false; + } + DateFormat df = null; + try { + df = new SimpleDateFormat(pattern); + df.parse(str); + } catch (ParseException pe) { + return false; + } catch (IllegalArgumentException iae) { + return false; + } + return true; + } + +} diff --git a/services/common-api/src/main/java/org/collectionspace/services/common/api/GregorianCalendarDateTimeUtils.java b/services/common-api/src/main/java/org/collectionspace/services/common/api/GregorianCalendarDateTimeUtils.java new file mode 100644 index 000000000..1f0af8970 --- /dev/null +++ b/services/common-api/src/main/java/org/collectionspace/services/common/api/GregorianCalendarDateTimeUtils.java @@ -0,0 +1,165 @@ +/** + * This document is a part of the source code and related artifacts + * for CollectionSpace, an open source collections management system + * for museums and related institutions: + + * http://www.collectionspace.org + * http://wiki.collectionspace.org + + * Copyright © 2009 University of California at Berkeley + + * Licensed under the Educational Community License (ECL), Version 2.0. + * You may not use this file except in compliance with this License. + + * You may obtain a copy of the ECL 2.0 License at + + * https://source.collectionspace.org/collection-space/LICENSE.txt + */ +package org.collectionspace.services.common.api; + +import java.text.DateFormat; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.GregorianCalendar; +import java.util.Locale; +import java.util.TimeZone; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * + * GregorianCalendarDateTimeUtils.java + * + * $LastChangedRevision: $ + * $LastChangedDate: $ + * + */ +public class GregorianCalendarDateTimeUtils { + + private static final Logger logger = LoggerFactory.getLogger(GregorianCalendarDateTimeUtils.class); + + /** + * Returns a String representing the current date and time instance. + * in the UTC time zone, formatted as an ISO 8601 timestamp. + * + * @return A String representing the current date and time instance. + */ + public static String timestampUTC() { + return formatAsISO8601Timestamp(currentDateAndTime(DateUtils.UTCTimeZone())); + } + + /** + * Returns a String representing the current date and time instance. + * in the UTC time zone, formatted as an ISO 8601 date. + * + * @return A String representing the current date and time instance. + */ + public static String currentDateUTC() { + return formatAsISO8601Date(currentDateAndTime(DateUtils.UTCTimeZone())); + } + + /** + * Returns a calendar date, representing the current date and time instance + * in the UTC time zone. + * + * @return The current date and time instance in the UTC time zone. + */ + public static GregorianCalendar currentDateAndTimeUTC() { + return currentDateAndTime(DateUtils.UTCTimeZone()); + } + + /** + * Returns a calendar date, representing the current date and time instance + * in the specified time zone. + * + * @return The current date and time instance in the specified time zone. + * If the time zone is null, will return the current time and + * date in the time zone intrinsic to a new Calendar instance. + */ + public static GregorianCalendar currentDateAndTime(TimeZone tz) { + GregorianCalendar gcal = new GregorianCalendar(); + if (tz != null) { + gcal.setTimeZone(tz); + } + Date now = new Date(); + gcal.setTime(now); + return gcal; + } + + + /** + * Returns a representation of a calendar date and time instance, + * as an ISO 8601-formatted timestamp in the UTC time zone. + * + * @param cal a calendar date and time instance. + * + * @return a representation of that calendar date and time instance, + * as an ISO 8601-formatted timestamp in the UTC time zone. + */ + public static String formatAsISO8601Timestamp(GregorianCalendar cal) { + return formatGregorianCalendarDate(cal, DateUtils.UTCTimeZone(), + DateUtils.getDateFormatter(DateUtils.ISO_8601_UTC_TIMESTAMP_PATTERN)); + } + + /** + * Returns a representation of a calendar date and time instance, + * as an ISO 8601-formatted date. + * + * @param cal a calendar date and time instance. + * + * @return a representation of that calendar date and time instance, + * as an ISO 8601-formatted date. + */ + public static String formatAsISO8601Date(GregorianCalendar cal) { + return formatGregorianCalendarDate(cal, DateUtils.UTCTimeZone(), + DateUtils.getDateFormatter(DateUtils.ISO_8601_DATE_PATTERN)); + } + + /** + * Formats a provided calendar date using a supplied date formatter, + * in the default system time zone. + * + * @param date A calendar date to format. + * @param df A date formatter to apply. + * + * @return A formatted date string, or the empty string + * if one or more of the parameter values were invalid. + */ + public static String formatGregorianCalendarDate(GregorianCalendar gcal, DateFormat df) { + return formatGregorianCalendarDate(gcal, TimeZone.getDefault(), df); + } + + /** + * Formats a provided calendar date using a provided date formatter, + * in a provided time zone. + * + * @param date A calendar date to format. + * @param tz The time zone qualifier for the calendar date to format. + * @param df A date formatter to apply. + * + * @return A formatted date string, or the empty string + * if one or more of the parameter values were invalid. + */ + public static String formatGregorianCalendarDate(GregorianCalendar gcal, TimeZone tz, DateFormat df) { + String formattedDate = ""; + if (gcal == null) { + logger.warn("Null calendar date was provided when a non-null calendar date was required."); + return formattedDate; + } + if (tz == null) { + logger.warn("Null time zone was provided when a non-null time zone was required."); + return formattedDate; + } + if (df == null) { + logger.warn("Null date formatter was provided when a non-null date formatter was required."); + return formattedDate; + } + gcal.setTimeZone(tz); + Date date = gcal.getTime(); + df.setTimeZone(tz); + formattedDate = df.format(date); + return formattedDate; + } +} diff --git a/services/common/src/main/java/org/collectionspace/services/common/datetime/DateTimeFormatUtils.java b/services/common/src/main/java/org/collectionspace/services/common/datetime/DateTimeFormatUtils.java index eab1a2efa..cb8f98df0 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/datetime/DateTimeFormatUtils.java +++ b/services/common/src/main/java/org/collectionspace/services/common/datetime/DateTimeFormatUtils.java @@ -31,6 +31,8 @@ import java.util.Map; import java.util.TimeZone; import org.collectionspace.services.common.ServiceMain; +import org.collectionspace.services.common.api.DateUtils; +import org.collectionspace.services.common.api.GregorianCalendarDateTimeUtils; import org.collectionspace.services.common.config.TenantBindingConfigReaderImpl; import org.collectionspace.services.common.config.TenantBindingUtils; import org.collectionspace.services.common.context.ServiceContext; @@ -52,10 +54,6 @@ public class DateTimeFormatUtils { private static final Logger logger = LoggerFactory.getLogger(DateTimeFormatUtils.class); final static String DATE_FORMAT_PATTERN_PROPERTY_NAME = "datePattern"; final static String LOCALE_LANGUAGE_CODE_PROPERTY_NAME = "localeLanguage"; - final static Locale NULL_LOCALE = null; - final static List isoLanguageCodes = new ArrayList(Arrays.asList(Locale.getISOLanguages())); - final static String ISO_8601_DATE_PATTERN = "yyyy-MM-dd"; - final static String ISO_8601_UTC_TIMESTAMP_PATTERN = "yyyy-MM-dd'T'HH:mm:ss'Z'"; static Map> dateFormatters = new HashMap>(); static Map> datePatterns = new HashMap>(); static Map> localeLanguageCodes = new HashMap>(); @@ -118,9 +116,9 @@ public class DateTimeFormatUtils { if (hasLanguageCodes) { for (String languageCode : languageCodes) { if (languageCode != null && ! languageCode.trim().isEmpty()) { - locale = getLocale(languageCode); + locale = DateUtils.getLocale(languageCode); for (String pattern : patterns) { - df = getDateFormatter(pattern, locale); + df = DateUtils.getDateFormatter(pattern, locale); if (df != null) { formatters.add(df); } @@ -129,7 +127,7 @@ public class DateTimeFormatUtils { } } else { for (String pattern : patterns) { - df = getDateFormatter(pattern, locale); + df = DateUtils.getDateFormatter(pattern, locale); if (df != null) { formatters.add(df); } @@ -215,7 +213,7 @@ public class DateTimeFormatUtils { List validPatterns = new ArrayList(); for (String pattern : patterns) { try { - df = getDateFormatter(pattern); + df = DateUtils.getDateFormatter(pattern); validPatterns.add(pattern); } catch (IllegalArgumentException iae) { logger.warn("Invalid " + DATE_FORMAT_PATTERN_PROPERTY_NAME + " property: " + pattern); @@ -294,7 +292,7 @@ public class DateTimeFormatUtils { } List validLanguageCodes = new ArrayList(); for (String code : languageCodes) { - if (code != null && isoLanguageCodes.contains(code.trim())) { + if (code != null && DateUtils.isoLanguageCodes.contains(code.trim())) { validLanguageCodes.add(code); } } @@ -318,7 +316,7 @@ public class DateTimeFormatUtils { Date date = null; List formatters = getDateFormattersForTenant(tenantId); for (DateFormat formatter : formatters) { - date = parseDate(dateStr, formatter); + date = DateUtils.parseDate(dateStr, formatter); if (date != null) { break; } @@ -328,227 +326,8 @@ public class DateTimeFormatUtils { } else { GregorianCalendar gcal = new GregorianCalendar(); gcal.setTime(date); - String isoStr = formatAsISO8601Timestamp(gcal); + String isoStr = GregorianCalendarDateTimeUtils.formatAsISO8601Timestamp(gcal); return isoStr; } } - - /** - * Returns a representation of a calendar date and time instance, - * as an ISO 8601-formatted timestamp in the UTC time zone. - * - * @param cal a calendar date and time instance. - * - * @return a representation of that calendar date and time instance, - * as an ISO 8601-formatted timestamp in the UTC time zone. - */ - public static String formatAsISO8601Timestamp(GregorianCalendar cal) { - return formatGregorianCalendarDate(cal, GregorianCalendarDateTimeUtils.UTCTimeZone(), - getDateFormatter(ISO_8601_UTC_TIMESTAMP_PATTERN)); - } - - /** - * Returns a representation of a calendar date and time instance, - * as an ISO 8601-formatted date. - * - * @param cal a calendar date and time instance. - * - * @return a representation of that calendar date and time instance, - * as an ISO 8601-formatted date. - */ - public static String formatAsISO8601Date(GregorianCalendar cal) { - return formatGregorianCalendarDate(cal, GregorianCalendarDateTimeUtils.UTCTimeZone(), - getDateFormatter(ISO_8601_DATE_PATTERN)); - } - - /** - * Formats a provided calendar date using a supplied date formatter, - * in the default system time zone. - * - * @param date A calendar date to format. - * @param df A date formatter to apply. - * - * @return A formatted date string, or the empty string - * if one or more of the parameter values were invalid. - */ - public static String formatGregorianCalendarDate(GregorianCalendar gcal, DateFormat df) { - return formatGregorianCalendarDate(gcal, TimeZone.getDefault(), df); - } - - /** - * Formats a provided calendar date using a provided date formatter, - * in a provided time zone. - * - * @param date A calendar date to format. - * @param tz The time zone qualifier for the calendar date to format. - * @param df A date formatter to apply. - * - * @return A formatted date string, or the empty string - * if one or more of the parameter values were invalid. - */ - public static String formatGregorianCalendarDate(GregorianCalendar gcal, TimeZone tz, DateFormat df) { - String formattedDate = ""; - if (gcal == null) { - logger.warn("Null calendar date was provided when a non-null calendar date was required."); - return formattedDate; - } - if (tz == null) { - logger.warn("Null time zone was provided when a non-null time zone was required."); - return formattedDate; - } - if (df == null) { - logger.warn("Null date formatter was provided when a non-null date formatter was required."); - return formattedDate; - } - gcal.setTimeZone(tz); - Date date = gcal.getTime(); - df.setTimeZone(tz); - formattedDate = df.format(date); - return formattedDate; - } - - /** - * Identifies whether a presumptive date or date/time can be parsed - * by a date parser, using a supplied format pattern. - * - * @param str a String, possibly a date or date/time String. - * @param pattern A date or date/time pattern. - * - * @return true, if the String can be parsed, using the pattern; - * false if the String cannot be parsed by the pattern, - * or if the String or pattern are null. - */ - public static boolean isParseableByDatePattern(String str, String pattern) { - if (pattern == null || pattern.trim().isEmpty()) { - return false; - } - if (str == null || str.trim().isEmpty()) { - return false; - } - DateFormat df = null; - try { - df = new SimpleDateFormat(pattern); - df.parse(str); - } catch (ParseException pe) { - return false; - } catch (IllegalArgumentException iae) { - return false; - } - return true; - } - - /** - * Parses a presumptive date or date/time, using a supplied format pattern. - * - * @param str a String, possibly a date or date/time String. - * @param pattern A date or date/time pattern. - * - * @return A date value, resulting from parsing the String using the - * supplied pattern. Returns null if the parsing attempt fails. - */ - public static Date parseDate(String str, String pattern) { - if (pattern == null || pattern.trim().isEmpty()) { - return null; - } - if (str == null || str.trim().isEmpty()) { - return null; - } - DateFormat df = null; - Date date = null; - try { - df = new SimpleDateFormat(pattern); - date = parseDate(str, df); - } catch (IllegalArgumentException iae) { - return null; - } - return date; - } - - /** - * Parses a presumptive date or date/time, using a supplied format pattern. - * - * @param str a String, possibly a date or date/time String. - * @param df A date formatter. - * - * @return A date value, resulting from parsing the String using the - * supplied formatter. Returns null if the parsing attempt fails. - */ - public static Date parseDate(String str, DateFormat df) { - if (df == null) { - return null; - } - if (str == null || str.trim().isEmpty()) { - return null; - } - Date date = null; - try { - df.setLenient(false); - date = df.parse(str); - } catch (ParseException pe) { - return null; - } - return date; - } - - /** - * Returns the locale associated with a supplied ISO 639-1 language code. - * - * @param lang A language code. - * - * @return A locale based on that language code; or null - * if the code was null, empty, or invalid. - */ - public static Locale getLocale(String lang) { - if (lang == null || lang.trim().isEmpty()) { - logger.warn("Null or empty date language code was provided when getting locale."); - return NULL_LOCALE; - } - if (! isoLanguageCodes.contains(lang.trim())) { - logger.warn("Invalid language code '" + lang + "'"); - return NULL_LOCALE; - } - return new Locale(lang); - } - - /** - * Returns a date formatter for a provided date or date/time pattern. - * - * @param pattern A date or date/time pattern. - * - * @return A date formatter using that pattern, or null - * if the pattern was null, empty, or invalid. - */ - public static DateFormat getDateFormatter(String pattern) { - return getDateFormatter(pattern, NULL_LOCALE); - } - - /** - * Returns a date formatter for a supplied date or date/time pattern, - * in the supplied locale (if any). - * - * @param pattern A date or date/time pattern. - * @param locale A locale. - * - * @return A date formatter using that pattern and locale (if any), or null - * if the pattern was null, empty, or invalid. - */ - public static DateFormat getDateFormatter(String pattern, Locale locale) { - DateFormat df = null; - if (pattern == null || pattern.trim().isEmpty()) { - logger.warn("Null or empty date pattern string was provided when getting date formatter."); - return df; - } - try { - if (locale == null) { - df = new SimpleDateFormat(pattern); - } else { - df = new SimpleDateFormat(pattern, locale); - } - df.setLenient(false); - } catch (IllegalArgumentException iae) { - logger.warn("Invalid date pattern string '" + pattern + "': " + iae.getMessage()); - } - return df; - } - } diff --git a/services/common/src/main/java/org/collectionspace/services/common/datetime/GregorianCalendarDateTimeUtils.java b/services/common/src/main/java/org/collectionspace/services/common/datetime/GregorianCalendarDateTimeUtils.java deleted file mode 100644 index ec2217a0e..000000000 --- a/services/common/src/main/java/org/collectionspace/services/common/datetime/GregorianCalendarDateTimeUtils.java +++ /dev/null @@ -1,100 +0,0 @@ -/** - * This document is a part of the source code and related artifacts - * for CollectionSpace, an open source collections management system - * for museums and related institutions: - - * http://www.collectionspace.org - * http://wiki.collectionspace.org - - * Copyright © 2009 University of California at Berkeley - - * Licensed under the Educational Community License (ECL), Version 2.0. - * You may not use this file except in compliance with this License. - - * You may obtain a copy of the ECL 2.0 License at - - * https://source.collectionspace.org/collection-space/LICENSE.txt - */ -package org.collectionspace.services.common.datetime; - -import java.util.Date; -import java.util.GregorianCalendar; -import java.util.TimeZone; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * - * GregorianCalendarDateTimeUtils.java - * - * $LastChangedRevision: $ - * $LastChangedDate: $ - * - */ -public class GregorianCalendarDateTimeUtils { - - private static final Logger logger = LoggerFactory.getLogger(GregorianCalendarDateTimeUtils.class); - - final static String UTC_TIMEZONE_IDENTIFIER = "UTC"; - final static String ISO_8601_UTC_TIMESTAMP_PATTERN = "yyyy-MM-dd'T'HH:mm:ss'Z'"; - - /** - * Returns the UTC time zone. - * - * @return The UTC time zone. Defaults to the closely-related GMT time zone, - * if for some reason the UTC time zone identifier cannot be understood. - */ - public static TimeZone UTCTimeZone() { - return TimeZone.getTimeZone(UTC_TIMEZONE_IDENTIFIER); - } - - /** - * Returns a calendar date, representing the current date and time instance - * in the UTC time zone. - * - * @return The current date and time instance in the UTC time zone. - */ - public static GregorianCalendar currentDateAndTimeUTC() { - return currentDateAndTime(UTCTimeZone()); - } - - /** - * Returns a calendar date, representing the current date and time instance - * in the specified time zone. - * - * @return The current date and time instance in the specified time zone. - * If the time zone is null, will return the current time and - * date in the time zone intrinsic to a new Calendar instance. - */ - public static GregorianCalendar currentDateAndTime(TimeZone tz) { - GregorianCalendar gcal = new GregorianCalendar(); - if (tz != null) { - gcal.setTimeZone(tz); - } - Date now = new Date(); - gcal.setTime(now); - return gcal; - } - - /** - * Returns a String representing the current date and time instance. - * in the UTC time zone, formatted as an ISO 8601 timestamp. - * - * @return A String representing the current date and time instance. - */ - public static String timestampUTC() { - return DateTimeFormatUtils.formatAsISO8601Timestamp(currentDateAndTime(UTCTimeZone())); - } - - /** - * Returns a String representing the current date and time instance. - * in the UTC time zone, formatted as an ISO 8601 date. - * - * @return A String representing the current date and time instance. - */ - public static String currentDateUTC() { - return DateTimeFormatUtils.formatAsISO8601Date(currentDateAndTime(UTCTimeZone())); - } - -} diff --git a/services/common/src/main/java/org/collectionspace/services/common/imaging/nuxeo/NuxeoImageUtils.java b/services/common/src/main/java/org/collectionspace/services/common/imaging/nuxeo/NuxeoImageUtils.java index a02b1f86a..113729df2 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/imaging/nuxeo/NuxeoImageUtils.java +++ b/services/common/src/main/java/org/collectionspace/services/common/imaging/nuxeo/NuxeoImageUtils.java @@ -26,15 +26,8 @@ */ package org.collectionspace.services.common.imaging.nuxeo; -import java.awt.Color; -import java.awt.Font; -import java.awt.Graphics; -import java.awt.image.BufferedImage; -import java.io.ByteArrayInputStream; import java.io.File; import java.io.ByteArrayOutputStream; -import java.io.FileDescriptor; -import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.InputStream; import java.io.BufferedInputStream; @@ -45,11 +38,6 @@ import java.math.BigInteger; import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.Random; -import java.util.Set; -import java.lang.reflect.Field; - -import javax.imageio.ImageIO; import org.nuxeo.runtime.api.Framework; //import org.nuxeo.runtime.api.ServiceManager; @@ -112,7 +100,7 @@ import org.slf4j.LoggerFactory; import org.collectionspace.services.common.ServiceMain; import org.collectionspace.services.common.blob.BlobInput; import org.collectionspace.services.common.context.ServiceContext; -import org.collectionspace.services.common.datetime.GregorianCalendarDateTimeUtils; +import org.collectionspace.services.common.api.GregorianCalendarDateTimeUtils; import org.collectionspace.services.blob.BlobsCommon; import org.collectionspace.services.blob.DimensionSubGroup; import org.collectionspace.services.blob.DimensionSubGroupList; diff --git a/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/DocHandlerBase.java b/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/DocHandlerBase.java index 22c7f1355..cee119ce0 100644 --- a/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/DocHandlerBase.java +++ b/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/DocHandlerBase.java @@ -36,17 +36,15 @@ import org.collectionspace.services.client.CollectionSpaceClient; import org.collectionspace.services.client.IQueryManager; import org.collectionspace.services.client.IRelationsManager; import org.collectionspace.services.common.ReflectionMapper; +import org.collectionspace.services.common.api.GregorianCalendarDateTimeUtils; import org.collectionspace.services.common.api.Tools; import org.collectionspace.services.common.context.AbstractServiceContextImpl; -import org.collectionspace.services.common.context.MultipartServiceContext; -import org.collectionspace.services.common.datetime.DateTimeFormatUtils; import org.collectionspace.services.common.document.DocumentException; import org.collectionspace.services.common.document.DocumentWrapper; import org.collectionspace.services.common.query.QueryContext; import org.collectionspace.services.common.relation.nuxeo.RelationsUtils; import org.collectionspace.services.config.service.DocHandlerParams; import org.collectionspace.services.config.service.ListResultField; -import org.collectionspace.services.config.service.ServiceBindingType; import org.collectionspace.services.jaxb.AbstractCommonList; import org.collectionspace.services.nuxeo.client.java.CommonList; import org.collectionspace.services.nuxeo.client.java.RemoteDocumentModelHandlerImpl; @@ -156,7 +154,7 @@ public abstract class DocHandlerBase extends RemoteDocumentModelHandlerImpl