Merge "Issue #1323 Improving framework based on first factory implementation" into development
Former-commit-id: 4d8d7ba7dc2acc827171856657ceea3c8bf13d2f
This commit is contained in:
commit
912eec5fab
13 changed files with 375 additions and 27 deletions
|
@ -1,4 +1,5 @@
|
|||
source.. = src/
|
||||
output.. = bin/
|
||||
bin.includes = META-INF/,\
|
||||
.
|
||||
.,\
|
||||
res/
|
||||
|
|
|
@ -83,8 +83,8 @@ public class DataFactoryRegistry {
|
|||
* the factory that will support requests of this datatype and
|
||||
* type
|
||||
*/
|
||||
public void register(String datatype, Class<IDataRequest<?>> requestType,
|
||||
IDataFactory<?, ?> factory) {
|
||||
public IDataFactory<?, ?> register(String datatype,
|
||||
Class<IDataRequest<?>> requestType, IDataFactory<?, ?> factory) {
|
||||
Map<Class<IDataRequest<?>>, 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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -44,7 +44,7 @@ public abstract class DataAccessException extends RuntimeException {
|
|||
* Constructor
|
||||
*/
|
||||
public DataAccessException() {
|
||||
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -44,7 +44,7 @@ public class DataFactoryNotFoundException extends DataAccessException {
|
|||
* Constructor
|
||||
*/
|
||||
public DataFactoryNotFoundException() {
|
||||
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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.
|
||||
*
|
||||
* <pre>
|
||||
*
|
||||
|
@ -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
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
|
@ -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);
|
||||
}
|
||||
|
|
@ -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.
|
||||
*
|
||||
* <pre>
|
||||
*
|
||||
|
@ -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
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
|
@ -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);
|
||||
}
|
||||
|
|
@ -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.
|
||||
*
|
||||
* <pre>
|
||||
*
|
||||
* SOFTWARE HISTORY
|
||||
*
|
||||
* Date Ticket# Engineer Description
|
||||
* ------------ ---------- ----------- --------------------------
|
||||
* Nov 13, 2012 njensen Initial creation
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
* @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);
|
||||
}
|
||||
|
||||
}
|
|
@ -45,7 +45,7 @@ public class TimeAgnosticDataException extends DataAccessException {
|
|||
* Constructor
|
||||
*/
|
||||
public TimeAgnosticDataException() {
|
||||
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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);
|
||||
|
||||
}
|
||||
|
|
|
@ -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.
|
||||
*
|
||||
* <pre>
|
||||
*
|
||||
* SOFTWARE HISTORY
|
||||
*
|
||||
* Date Ticket# Engineer Description
|
||||
* ------------ ---------- ----------- --------------------------
|
||||
* Nov 13, 2012 njensen Initial creation
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
* @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<String> missing = null;
|
||||
if (required != null && required.length > 0) {
|
||||
Map<String, Object> identifiers = request.getIdentifiers();
|
||||
if (identifiers != null) {
|
||||
for (String s : required) {
|
||||
if (!identifiers.containsKey(s)) {
|
||||
if (missing == null) {
|
||||
missing = new ArrayList<String>(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<String> itr = missing.iterator();
|
||||
while (itr.hasNext()) {
|
||||
sb.append(itr.next());
|
||||
if (itr.hasNext()) {
|
||||
sb.append(", ");
|
||||
}
|
||||
}
|
||||
throw new MissingRequiredIdentifierException(sb.toString());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
*
|
||||
* <pre>
|
||||
*
|
||||
* SOFTWARE HISTORY
|
||||
*
|
||||
* Date Ticket# Engineer Description
|
||||
* ------------ ---------- ----------- --------------------------
|
||||
* Nov 14, 2012 njensen Initial creation
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
* @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 <R extends IDataRequest<D>, D extends IData> DataTime[] getAvailableTimes(
|
||||
IDataFactory<R, D> factory, R request, BinOffset binOffset) {
|
||||
DataTime[] actualTimes = factory.getAvailableTimes(request);
|
||||
if (binOffset != null) {
|
||||
Set<DataTime> normalized = binOffset
|
||||
.getNormalizedTimes(actualTimes);
|
||||
return normalized.toArray(new DataTime[0]);
|
||||
} else {
|
||||
return actualTimes;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -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<DataTime> getNormalizedTimes(DataTime[] times) {
|
||||
Set<DataTime> set = new HashSet<DataTime>();
|
||||
for (DataTime dt : times) {
|
||||
set.add(getNormalizedTime(dt));
|
||||
}
|
||||
return set;
|
||||
}
|
||||
|
||||
public TimeRange getTimeRange(DataTime baseTime) {
|
||||
long negSkew = -negOffset * 1000l;
|
||||
long posSkew = posOffset * 1000l;
|
||||
|
|
Loading…
Add table
Reference in a new issue