diff --git a/edexOsgi/com.raytheon.uf.common.dataaccess/build.properties b/edexOsgi/com.raytheon.uf.common.dataaccess/build.properties index 34d2e4d2da..5791d48d5f 100644 --- a/edexOsgi/com.raytheon.uf.common.dataaccess/build.properties +++ b/edexOsgi/com.raytheon.uf.common.dataaccess/build.properties @@ -1,4 +1,5 @@ source.. = src/ output.. = bin/ bin.includes = META-INF/,\ - . + .,\ + res/ diff --git a/edexOsgi/com.raytheon.uf.common.dataaccess/src/com/raytheon/uf/common/dataaccess/DataFactoryRegistry.java b/edexOsgi/com.raytheon.uf.common.dataaccess/src/com/raytheon/uf/common/dataaccess/DataFactoryRegistry.java index 98448f8e1c..cc23dd2f2e 100644 --- a/edexOsgi/com.raytheon.uf.common.dataaccess/src/com/raytheon/uf/common/dataaccess/DataFactoryRegistry.java +++ b/edexOsgi/com.raytheon.uf.common.dataaccess/src/com/raytheon/uf/common/dataaccess/DataFactoryRegistry.java @@ -83,8 +83,8 @@ public class DataFactoryRegistry { * the factory that will support requests of this datatype and * type */ - public void register(String datatype, Class> requestType, - IDataFactory factory) { + public IDataFactory register(String datatype, + Class> requestType, IDataFactory factory) { Map>, IDataFactory> requestTypeMap = datatypeMap .get(datatype); if (requestTypeMap == null) { @@ -92,6 +92,7 @@ public class DataFactoryRegistry { datatypeMap.put(datatype, requestTypeMap); } requestTypeMap.put(requestType, factory); + return factory; } /** diff --git a/edexOsgi/com.raytheon.uf.common.dataaccess/src/com/raytheon/uf/common/dataaccess/exception/DataAccessException.java b/edexOsgi/com.raytheon.uf.common.dataaccess/src/com/raytheon/uf/common/dataaccess/exception/DataAccessException.java index 6cc3a1ae6e..231cc03273 100644 --- a/edexOsgi/com.raytheon.uf.common.dataaccess/src/com/raytheon/uf/common/dataaccess/exception/DataAccessException.java +++ b/edexOsgi/com.raytheon.uf.common.dataaccess/src/com/raytheon/uf/common/dataaccess/exception/DataAccessException.java @@ -44,7 +44,7 @@ public abstract class DataAccessException extends RuntimeException { * Constructor */ public DataAccessException() { - + super(); } /** diff --git a/edexOsgi/com.raytheon.uf.common.dataaccess/src/com/raytheon/uf/common/dataaccess/exception/DataFactoryNotFoundException.java b/edexOsgi/com.raytheon.uf.common.dataaccess/src/com/raytheon/uf/common/dataaccess/exception/DataFactoryNotFoundException.java index a2d1a70f8e..2d243eaf46 100644 --- a/edexOsgi/com.raytheon.uf.common.dataaccess/src/com/raytheon/uf/common/dataaccess/exception/DataFactoryNotFoundException.java +++ b/edexOsgi/com.raytheon.uf.common.dataaccess/src/com/raytheon/uf/common/dataaccess/exception/DataFactoryNotFoundException.java @@ -44,7 +44,7 @@ public class DataFactoryNotFoundException extends DataAccessException { * Constructor */ public DataFactoryNotFoundException() { - + super(); } /** diff --git a/edexOsgi/com.raytheon.uf.common.dataaccess/src/com/raytheon/uf/common/dataaccess/exception/EnvelopeUnsupportedException.java b/edexOsgi/com.raytheon.uf.common.dataaccess/src/com/raytheon/uf/common/dataaccess/exception/DataRetrievalException.java similarity index 77% rename from edexOsgi/com.raytheon.uf.common.dataaccess/src/com/raytheon/uf/common/dataaccess/exception/EnvelopeUnsupportedException.java rename to edexOsgi/com.raytheon.uf.common.dataaccess/src/com/raytheon/uf/common/dataaccess/exception/DataRetrievalException.java index 5f36f67de0..3f21f3ed15 100644 --- a/edexOsgi/com.raytheon.uf.common.dataaccess/src/com/raytheon/uf/common/dataaccess/exception/EnvelopeUnsupportedException.java +++ b/edexOsgi/com.raytheon.uf.common.dataaccess/src/com/raytheon/uf/common/dataaccess/exception/DataRetrievalException.java @@ -20,7 +20,8 @@ package com.raytheon.uf.common.dataaccess.exception; /** - * An exception for when the data does not support bounding envelopes. + * An exception for when there is an error performing the underlying factory + * specific retrieval for data. * *
  * 
@@ -28,7 +29,7 @@ package com.raytheon.uf.common.dataaccess.exception;
  * 
  * Date         Ticket#    Engineer    Description
  * ------------ ---------- ----------- --------------------------
- * Nov 12, 2012            njensen     Initial creation
+ * Nov 14, 2012            njensen     Initial creation
  * 
  * 
* @@ -36,15 +37,15 @@ package com.raytheon.uf.common.dataaccess.exception; * @version 1.0 */ -public class EnvelopeUnsupportedException extends DataAccessException { +public class DataRetrievalException extends DataAccessException { private static final long serialVersionUID = 1L; /** * Constructor */ - public EnvelopeUnsupportedException() { - + public DataRetrievalException() { + super(); } /** @@ -53,7 +54,7 @@ public class EnvelopeUnsupportedException extends DataAccessException { * @param message * the error message */ - public EnvelopeUnsupportedException(String message) { + public DataRetrievalException(String message) { super(message); } @@ -65,7 +66,7 @@ public class EnvelopeUnsupportedException extends DataAccessException { * @param cause * the cause of the error */ - public EnvelopeUnsupportedException(String message, Throwable cause) { + public DataRetrievalException(String message, Throwable cause) { super(message, cause); } @@ -75,7 +76,7 @@ public class EnvelopeUnsupportedException extends DataAccessException { * @param cause * the cause of the error */ - public EnvelopeUnsupportedException(Throwable cause) { + public DataRetrievalException(Throwable cause) { super(cause); } diff --git a/edexOsgi/com.raytheon.uf.common.dataaccess/src/com/raytheon/uf/common/dataaccess/exception/LocationNameUnsupportedException.java b/edexOsgi/com.raytheon.uf.common.dataaccess/src/com/raytheon/uf/common/dataaccess/exception/IncompatibleRequestException.java similarity index 76% rename from edexOsgi/com.raytheon.uf.common.dataaccess/src/com/raytheon/uf/common/dataaccess/exception/LocationNameUnsupportedException.java rename to edexOsgi/com.raytheon.uf.common.dataaccess/src/com/raytheon/uf/common/dataaccess/exception/IncompatibleRequestException.java index aa01959653..ea8a6d601e 100644 --- a/edexOsgi/com.raytheon.uf.common.dataaccess/src/com/raytheon/uf/common/dataaccess/exception/LocationNameUnsupportedException.java +++ b/edexOsgi/com.raytheon.uf.common.dataaccess/src/com/raytheon/uf/common/dataaccess/exception/IncompatibleRequestException.java @@ -20,7 +20,8 @@ package com.raytheon.uf.common.dataaccess.exception; /** - * An exception for when the data does not support location names. + * An exception for when an IDataFactory cannot handle a request due to specific + * values on the request. * *
  * 
@@ -28,7 +29,7 @@ package com.raytheon.uf.common.dataaccess.exception;
  * 
  * Date         Ticket#    Engineer    Description
  * ------------ ---------- ----------- --------------------------
- * Nov 12, 2012            njensen     Initial creation
+ * Nov 13, 2012            njensen     Initial creation
  * 
  * 
* @@ -36,15 +37,15 @@ package com.raytheon.uf.common.dataaccess.exception; * @version 1.0 */ -public class LocationNameUnsupportedException extends DataAccessException { +public class IncompatibleRequestException extends DataAccessException { private static final long serialVersionUID = 1L; /** * Constructor */ - public LocationNameUnsupportedException() { - + public IncompatibleRequestException() { + super(); } /** @@ -53,7 +54,7 @@ public class LocationNameUnsupportedException extends DataAccessException { * @param message * the error message */ - public LocationNameUnsupportedException(String message) { + public IncompatibleRequestException(String message) { super(message); } @@ -65,7 +66,7 @@ public class LocationNameUnsupportedException extends DataAccessException { * @param cause * the cause of the error */ - public LocationNameUnsupportedException(String message, Throwable cause) { + public IncompatibleRequestException(String message, Throwable cause) { super(message, cause); } @@ -75,7 +76,7 @@ public class LocationNameUnsupportedException extends DataAccessException { * @param cause * the cause of the error */ - public LocationNameUnsupportedException(Throwable cause) { + public IncompatibleRequestException(Throwable cause) { super(cause); } diff --git a/edexOsgi/com.raytheon.uf.common.dataaccess/src/com/raytheon/uf/common/dataaccess/exception/MissingRequiredIdentifierException.java b/edexOsgi/com.raytheon.uf.common.dataaccess/src/com/raytheon/uf/common/dataaccess/exception/MissingRequiredIdentifierException.java new file mode 100644 index 0000000000..fef908fb59 --- /dev/null +++ b/edexOsgi/com.raytheon.uf.common.dataaccess/src/com/raytheon/uf/common/dataaccess/exception/MissingRequiredIdentifierException.java @@ -0,0 +1,83 @@ +/** + * This software was developed and / or modified by Raytheon Company, + * pursuant to Contract DG133W-05-CQ-1067 with the US Government. + * + * U.S. EXPORT CONTROLLED TECHNICAL DATA + * This software product contains export-restricted data whose + * export/transfer/disclosure is restricted by U.S. law. Dissemination + * to non-U.S. persons whether in the United States or abroad requires + * an export license or other authorization. + * + * Contractor Name: Raytheon Company + * Contractor Address: 6825 Pine Street, Suite 340 + * Mail Stop B8 + * Omaha, NE 68106 + * 402.291.0100 + * + * See the AWIPS II Master Rights File ("Master Rights File.pdf") for + * further licensing information. + **/ +package com.raytheon.uf.common.dataaccess.exception; + +/** + * An exception for when a request is sent that a factory cannot process without + * one or more specific identifiers. + * + *
+ * 
+ * SOFTWARE HISTORY
+ * 
+ * Date         Ticket#    Engineer    Description
+ * ------------ ---------- ----------- --------------------------
+ * Nov 13, 2012            njensen     Initial creation
+ * 
+ * 
+ * + * @author njensen + * @version 1.0 + */ + +public class MissingRequiredIdentifierException extends DataAccessException { + + private static final long serialVersionUID = 1L; + + /** + * Constructor + */ + public MissingRequiredIdentifierException() { + super(); + } + + /** + * Constructor + * + * @param message + * the error message + */ + public MissingRequiredIdentifierException(String message) { + super(message); + } + + /** + * Constructor + * + * @param message + * the error message + * @param cause + * the cause of the error + */ + public MissingRequiredIdentifierException(String message, Throwable cause) { + super(message, cause); + } + + /** + * Constructor + * + * @param cause + * the cause of the error + */ + public MissingRequiredIdentifierException(Throwable cause) { + super(cause); + } + +} diff --git a/edexOsgi/com.raytheon.uf.common.dataaccess/src/com/raytheon/uf/common/dataaccess/exception/TimeAgnosticDataException.java b/edexOsgi/com.raytheon.uf.common.dataaccess/src/com/raytheon/uf/common/dataaccess/exception/TimeAgnosticDataException.java index da658a2443..0fc6155dc6 100644 --- a/edexOsgi/com.raytheon.uf.common.dataaccess/src/com/raytheon/uf/common/dataaccess/exception/TimeAgnosticDataException.java +++ b/edexOsgi/com.raytheon.uf.common.dataaccess/src/com/raytheon/uf/common/dataaccess/exception/TimeAgnosticDataException.java @@ -45,7 +45,7 @@ public class TimeAgnosticDataException extends DataAccessException { * Constructor */ public TimeAgnosticDataException() { - + super(); } /** diff --git a/edexOsgi/com.raytheon.uf.common.dataaccess/src/com/raytheon/uf/common/dataaccess/geom/IGeometryDataFactory.java b/edexOsgi/com.raytheon.uf.common.dataaccess/src/com/raytheon/uf/common/dataaccess/geom/IGeometryDataFactory.java index ed50d996a8..27258e5885 100644 --- a/edexOsgi/com.raytheon.uf.common.dataaccess/src/com/raytheon/uf/common/dataaccess/geom/IGeometryDataFactory.java +++ b/edexOsgi/com.raytheon.uf.common.dataaccess/src/com/raytheon/uf/common/dataaccess/geom/IGeometryDataFactory.java @@ -20,7 +20,6 @@ package com.raytheon.uf.common.dataaccess.geom; import com.raytheon.uf.common.dataaccess.IDataFactory; -import com.raytheon.uf.common.dataaccess.exception.LocationNameUnsupportedException; /** * IDataFactory for any data that is non-gridded, for example points or @@ -52,7 +51,6 @@ public interface IGeometryDataFactory extends * the request to find matching location names for * @return the available location names that match the request */ - public String[] getAvailableLocationNames(IGeometryRequest request) - throws LocationNameUnsupportedException; + public String[] getAvailableLocationNames(IGeometryRequest request); } diff --git a/edexOsgi/com.raytheon.uf.common.dataaccess/src/com/raytheon/uf/common/dataaccess/impl/AbstractDataFactory.java b/edexOsgi/com.raytheon.uf.common.dataaccess/src/com/raytheon/uf/common/dataaccess/impl/AbstractDataFactory.java new file mode 100644 index 0000000000..308f5ff2c7 --- /dev/null +++ b/edexOsgi/com.raytheon.uf.common.dataaccess/src/com/raytheon/uf/common/dataaccess/impl/AbstractDataFactory.java @@ -0,0 +1,100 @@ +/** + * This software was developed and / or modified by Raytheon Company, + * pursuant to Contract DG133W-05-CQ-1067 with the US Government. + * + * U.S. EXPORT CONTROLLED TECHNICAL DATA + * This software product contains export-restricted data whose + * export/transfer/disclosure is restricted by U.S. law. Dissemination + * to non-U.S. persons whether in the United States or abroad requires + * an export license or other authorization. + * + * Contractor Name: Raytheon Company + * Contractor Address: 6825 Pine Street, Suite 340 + * Mail Stop B8 + * Omaha, NE 68106 + * 402.291.0100 + * + * See the AWIPS II Master Rights File ("Master Rights File.pdf") for + * further licensing information. + **/ +package com.raytheon.uf.common.dataaccess.impl; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +import com.raytheon.uf.common.dataaccess.IDataRequest; +import com.raytheon.uf.common.dataaccess.exception.MissingRequiredIdentifierException; + +/** + * + * An abstract data factory that can be used by implementing IGridDataFactories + * or IGeometryDataFactories. + * + *
+ * 
+ * SOFTWARE HISTORY
+ * 
+ * Date         Ticket#    Engineer    Description
+ * ------------ ---------- ----------- --------------------------
+ * Nov 13, 2012            njensen     Initial creation
+ * 
+ * 
+ * + * @author njensen + * @version 1.0 + */ + +public abstract class AbstractDataFactory { + + /** + * Returns the identifiers that must be set on a request for the request to + * be processed + * + * @return the required identifiers + */ + public abstract String[] getRequiredIdentifiers(); + + /** + * Validates that a request is compatible with the factory + * + * @param request + * the request to validate + */ + public void validateRequest(IDataRequest request) { + String[] required = getRequiredIdentifiers(); + List missing = null; + if (required != null && required.length > 0) { + Map identifiers = request.getIdentifiers(); + if (identifiers != null) { + for (String s : required) { + if (!identifiers.containsKey(s)) { + if (missing == null) { + missing = new ArrayList(required.length); + } + missing.add(s); + } + } + } else { + missing = Arrays.asList(required); + } + } + + if (missing != null) { + StringBuilder sb = new StringBuilder(); + sb.append("Request of "); + sb.append(request.getDatatype()); + sb.append(" data is missing identifiers: "); + Iterator itr = missing.iterator(); + while (itr.hasNext()) { + sb.append(itr.next()); + if (itr.hasNext()) { + sb.append(", "); + } + } + throw new MissingRequiredIdentifierException(sb.toString()); + } + } +} diff --git a/edexOsgi/com.raytheon.uf.common.dataaccess/src/com/raytheon/uf/common/dataaccess/impl/DefaultGeometryData.java b/edexOsgi/com.raytheon.uf.common.dataaccess/src/com/raytheon/uf/common/dataaccess/impl/DefaultGeometryData.java index a2c83afd68..603c4b7d07 100644 --- a/edexOsgi/com.raytheon.uf.common.dataaccess/src/com/raytheon/uf/common/dataaccess/impl/DefaultGeometryData.java +++ b/edexOsgi/com.raytheon.uf.common.dataaccess/src/com/raytheon/uf/common/dataaccess/impl/DefaultGeometryData.java @@ -54,7 +54,7 @@ public class DefaultGeometryData implements IGeometryData { /** * A simple object to hold a value, type, and unit of a parameter */ - public class GeomData { + private class GeomData { private Object value; private Type type; @@ -196,7 +196,78 @@ public class DefaultGeometryData implements IGeometryData { return locationName; } - public void addData(String parameter, GeomData data) { + /** + * Adds data for this IGeometryData + * + * @param parameter + * the parameter name + * @param value + * the value of the parameter + */ + public void addData(String parameter, Object value) { + addData(parameter, value, null, null); + } + + /** + * Adds data for this IGeometryData + * + * @param parameter + * the parameter name + * @param value + * the value of the parameter + * @param type + * the type of the value + */ + public void addData(String parameter, Object value, Type type) { + addData(parameter, value, type, null); + } + + /** + * Adds data for this IGeometryData + * + * @param parameter + * the parameter name + * @param value + * the value of the parameter + * @param unit + * the unit of the value + */ + public void addData(String parameter, Object value, Unit unit) { + addData(parameter, value, null, unit); + } + + /** + * Adds data for this IGeometryData + * + * @param parameter + * the parameter name + * @param value + * the value of the parameter + * @param type + * the type of the value + * @param unit + * the unit of the value + */ + public void addData(String parameter, Object value, Type type, Unit unit) { + GeomData data = new GeomData(); + data.value = value; + data.unit = unit; + data.type = type; + if (data.type == null) { + if (data.value instanceof String) { + data.type = Type.STRING; + } else if (data.value instanceof Double) { + // TODO do these ifs work or will any number fall into + // the first one? + data.type = Type.DOUBLE; + } else if (data.value instanceof Integer) { + data.type = Type.INT; + } else if (data.value instanceof Long) { + data.type = Type.LONG; + } else if (data.value instanceof Float) { + data.type = Type.FLOAT; + } + } this.dataMap.put(parameter, data); } diff --git a/edexOsgi/com.raytheon.uf.common.dataaccess/src/com/raytheon/uf/common/dataaccess/impl/FactoryUtil.java b/edexOsgi/com.raytheon.uf.common.dataaccess/src/com/raytheon/uf/common/dataaccess/impl/FactoryUtil.java new file mode 100644 index 0000000000..cf5b96f83e --- /dev/null +++ b/edexOsgi/com.raytheon.uf.common.dataaccess/src/com/raytheon/uf/common/dataaccess/impl/FactoryUtil.java @@ -0,0 +1,74 @@ +/** + * This software was developed and / or modified by Raytheon Company, + * pursuant to Contract DG133W-05-CQ-1067 with the US Government. + * + * U.S. EXPORT CONTROLLED TECHNICAL DATA + * This software product contains export-restricted data whose + * export/transfer/disclosure is restricted by U.S. law. Dissemination + * to non-U.S. persons whether in the United States or abroad requires + * an export license or other authorization. + * + * Contractor Name: Raytheon Company + * Contractor Address: 6825 Pine Street, Suite 340 + * Mail Stop B8 + * Omaha, NE 68106 + * 402.291.0100 + * + * See the AWIPS II Master Rights File ("Master Rights File.pdf") for + * further licensing information. + **/ +package com.raytheon.uf.common.dataaccess.impl; + +import java.util.Set; + +import com.raytheon.uf.common.dataaccess.IData; +import com.raytheon.uf.common.dataaccess.IDataFactory; +import com.raytheon.uf.common.dataaccess.IDataRequest; +import com.raytheon.uf.common.time.BinOffset; +import com.raytheon.uf.common.time.DataTime; + +/** + * Utilities for working with data factories + * + *
+ * 
+ * SOFTWARE HISTORY
+ * 
+ * Date         Ticket#    Engineer    Description
+ * ------------ ---------- ----------- --------------------------
+ * Nov 14, 2012            njensen     Initial creation
+ * 
+ * 
+ * + * @author njensen + * @version 1.0 + */ + +public class FactoryUtil { + + /** + * Convenience method that provides the getAvailableTimes(R, BinOffset) + * functionality by calling getAvailableTimes(R) and then applying the + * BinOffset to normalize the available times. + * + * @param factory + * the factory to retrieve times through + * @param request + * the request to find available times for + * @param binOffset + * the bin offset to apply + * @return the binned times + */ + public static , D extends IData> DataTime[] getAvailableTimes( + IDataFactory factory, R request, BinOffset binOffset) { + DataTime[] actualTimes = factory.getAvailableTimes(request); + if (binOffset != null) { + Set normalized = binOffset + .getNormalizedTimes(actualTimes); + return normalized.toArray(new DataTime[0]); + } else { + return actualTimes; + } + } + +} diff --git a/edexOsgi/com.raytheon.uf.common.time/src/com/raytheon/uf/common/time/BinOffset.java b/edexOsgi/com.raytheon.uf.common.time/src/com/raytheon/uf/common/time/BinOffset.java index d8ac36da97..8c132aecbd 100644 --- a/edexOsgi/com.raytheon.uf.common.time/src/com/raytheon/uf/common/time/BinOffset.java +++ b/edexOsgi/com.raytheon.uf.common.time/src/com/raytheon/uf/common/time/BinOffset.java @@ -20,6 +20,8 @@ package com.raytheon.uf.common.time; import java.util.Date; +import java.util.HashSet; +import java.util.Set; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; @@ -140,6 +142,22 @@ public class BinOffset implements ISerializableObject { return normalizedTime; } + /** + * Takes range and offsets into account to determine what the times should + * be normalized to in the range + * + * @param times + * the times to normalize + * @return the normalized times + */ + public Set getNormalizedTimes(DataTime[] times) { + Set set = new HashSet(); + for (DataTime dt : times) { + set.add(getNormalizedTime(dt)); + } + return set; + } + public TimeRange getTimeRange(DataTime baseTime) { long negSkew = -negOffset * 1000l; long posSkew = posOffset * 1000l;