Merge branch 'omaha_16.2.1' into omaha_16.2.2

Conflicts:
	cave/com.raytheon.uf.viz.monitor.ffmp/src/com/raytheon/uf/viz/monitor/ffmp/ui/rsc/FFMPResource.java
	cave/com.raytheon.viz.texteditor/src/com/raytheon/viz/texteditor/dialogs/TextEditorDialog.java
	edexOsgi/com.raytheon.uf.edex.ogc.common/META-INF/MANIFEST.MF
	edexOsgi/com.raytheon.uf.edex.ogc.common/src/com/raytheon/uf/edex/ogc/common/OgcLayer.java
	edexOsgi/com.raytheon.uf.edex.ogc.common/src/com/raytheon/uf/edex/ogc/common/db/LayerCollector.java
	edexOsgi/com.raytheon.uf.edex.ogc.common/src/com/raytheon/uf/edex/ogc/common/db/LayerTransformer.java
	edexOsgi/com.raytheon.uf.edex.ogc.common/src/com/raytheon/uf/edex/ogc/common/filter/ComparisonFilter.java
	edexOsgi/com.raytheon.uf.edex.ogc.common/src/com/raytheon/uf/edex/ogc/common/gml3_1_1/EnvelopeConverter.java
	edexOsgi/com.raytheon.uf.edex.ogc.common/src/com/raytheon/uf/edex/ogc/common/gml3_2_1/EnvelopeConverter.java
	edexOsgi/com.raytheon.uf.edex.ogc.common/src/com/raytheon/uf/edex/ogc/common/gml3_2_1/GeometryConverter.java
	edexOsgi/com.raytheon.uf.edex.ogc.common/src/com/raytheon/uf/edex/ogc/common/http/IOgcHttpPooler.java
	edexOsgi/com.raytheon.uf.edex.ogc.common/src/com/raytheon/uf/edex/ogc/common/http/OgcHttpHandler.java
	edexOsgi/com.raytheon.uf.edex.ogc.common/src/com/raytheon/uf/edex/ogc/common/http/SingleHttpPool.java
	edexOsgi/com.raytheon.uf.edex.ogc.common/src/com/raytheon/uf/edex/ogc/common/spatial/CoordinateUtil.java
	edexOsgi/com.raytheon.uf.edex.wfs/META-INF/MANIFEST.MF
	edexOsgi/com.raytheon.uf.edex.wfs/src/com/raytheon/uf/edex/wfs/filter/v1_1_0/QueryFilterVisitor.java
	edexOsgi/com.raytheon.uf.edex.wfs/src/com/raytheon/uf/edex/wfs/filter/v2_0_0/AbstractQueryFilterVisitor.java
	edexOsgi/com.raytheon.uf.edex.wfs/src/com/raytheon/uf/edex/wfs/filter/v2_0_0/QueryExpressionVisitor.java
	edexOsgi/com.raytheon.uf.edex.wfs/src/com/raytheon/uf/edex/wfs/reg/WfsRegistryImpl.java


Former-commit-id: b9aab5f7931fde1d2aaf9ba0402bf35314cd0c5f
This commit is contained in:
Steve Harris 2015-11-12 13:57:32 -06:00
commit 260d20c920
254 changed files with 1429 additions and 37023 deletions

View file

@ -109,5 +109,11 @@ if [ $? -ne 0 ]; then
exit 1
fi
# Relocate localization files.
/bin/bash /awips2/cave/relocateLocalization.sh
if [ $? -ne 0 ]; then
exit 1
fi
echo "Successfully installed feature: ${feature_id}."
exit 0
exit 0

View file

@ -73,4 +73,11 @@ for feature in `cat ${_output}`; do
fi
done
# Relocate localization files.
/bin/bash /awips2/cave/relocateLocalization.sh
if [ $? -ne 0 ]; then
exit 1
fi
echo "INFO: Upgrades Finished."
exit 0

View file

@ -0,0 +1,23 @@
#!/bin/bash
# Post-installation script that copies the unpacked localization files
# to /awips2/cave/etc.
pushd . > /dev/null 2>&1
cd /awips2/cave/plugins
for localizationDirectory in `find . -maxdepth 2 -name localization -type d`;
do
# copy the contents of the localization directory to the
# etc directory.
cp -rf ${localizationDirectory}/* /awips2/cave/etc
if [ $? -ne 0 ]; then
exit 1
fi
# remove the localization directory.
rm -rf ${localizationDirectory}
if [ $? -ne 0 ]; then
exit 1
fi
done
popd > /dev/null 2>&1

View file

@ -201,6 +201,7 @@ import com.vividsolutions.jts.geom.Point;
* Dec 16, 2014 3026 mpduff Change location of text.
* Feb 13, 2015 4121 mpduff Change label caching.
* Sep 28, 2015 4756 dhladky Multiple guidance sources.
* Oct 26, 2015 5056 dhladky Simplified Guidance Interpolation.
* Nov 05, 2015 5070 randerso Adjust font sizes for dpi scaling
*
* </pre>
@ -3419,10 +3420,6 @@ public class FFMPResource extends
if (guidanceInterpolator.isInterpolate()) {
guidancev = guidBasin.getInterpolatedValue(
guidanceInterpolator.getSource1(),
guidanceInterpolator.getSource2(),
guidanceInterpolator
.getInterpolationOffset(),
guidanceInterpolator,
getGuidSourceExpiration(ffgGraphType));
} else {
@ -3837,10 +3834,7 @@ public class FFMPResource extends
// interpolating
if (interp.isInterpolate()) {
// Interpolating between sources
String source1 = interp.getSource1();
String source2 = interp.getSource2();
dvalue = basin.getInterpolatedValue(source1, source2,
interp.getInterpolationOffset(), interp,
dvalue = basin.getInterpolatedValue(interp,
sourceExpiration);
} else {
dvalue = basin.getValue(interp.getStandardSource(), interp,

View file

@ -43,6 +43,7 @@ import com.raytheon.uf.viz.monitor.ffmp.ui.rsc.FFMPResourceData;
* ------------ ---------- ----------- --------------------------
* Jun 04, 2013 2075 njensen Initial creation
* Jun 07, 2013 2075 njensen Added progress monitoring
* Oct 26, 2015 5056 dhladky Removed println.
*
* </pre>
*
@ -128,8 +129,8 @@ public class BackgroundLoadJob extends AbstractLoadJob {
}
smonitor.done();
System.out.println(this.getName() + " took: "
+ (System.currentTimeMillis() - t0));
statusHandler.debug(this.getName() + " took: "
+ (System.currentTimeMillis() - t0) + " ms");
} catch (Exception e) {
statusHandler.error("Couldn't complete " + this.getName(), e);

View file

@ -57,6 +57,7 @@ import com.raytheon.uf.viz.monitor.ffmp.ui.rsc.FFMPResourceData;
* ------------ ---------- ----------- --------------------------
* Jun 04, 2013 2075 njensen Initial creation
* Jun 07, 2013 2075 njensen Added progress monitoring
* Oct 26, 2015 5056 dhladky Removed println.
*
* </pre>
*
@ -154,8 +155,8 @@ public class InitialLoadJob extends AbstractLoadJob {
smonitor.subTask("Processing Guidance...");
doGuidance(startTime, smonitor.newChild(200));
System.out.println("Initial Load Job took: "
+ (System.currentTimeMillis() - t0));
statusHandler.debug(this.getName() + " took: "
+ (System.currentTimeMillis() - t0) + " ms");
return Status.OK_STATUS;
}

View file

@ -100,6 +100,7 @@ import com.vividsolutions.jts.io.ParseException;
* Sep 15, 2014 3220 skorolev Added refreshZoneTableData method.
* Nov 03, 2014 3741 skorolev Updated zoom procedures.
* Sep 25, 2015 3873 skorolev Added center definition for moving platforms.
* Nov 09, 2015 3841 dhladky Update all tables when zones/stations are updated.
*
* </pre>
*
@ -490,10 +491,7 @@ public abstract class ZoneTableDlg extends CaveSWTDialog implements
public void updateTableDlg(ObHourReports obHrData) {
nominalTime = obHrData.getNominalTime();
updateZoneTable(nominalTime);
if (!selectedZone.equals("")
&& obHrData.getHourReports().containsKey(selectedZone)) {
updateStationTable(nominalTime);
}
updateStationTable(nominalTime);
updateNominalTimeLabel(nominalTime);
}

View file

@ -31,6 +31,7 @@ import java.util.regex.Pattern;
import javax.xml.bind.JAXB;
import org.apache.commons.collections.ListUtils;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
@ -51,8 +52,10 @@ import com.raytheon.uf.common.status.UFStatus;
import com.raytheon.uf.common.status.UFStatus.Priority;
import com.raytheon.uf.common.tafqueue.ServerResponse;
import com.raytheon.uf.common.tafqueue.TafQueueRecord;
import com.raytheon.uf.common.tafqueue.TafQueueRecord.TafQueueState;
import com.raytheon.uf.common.tafqueue.TafQueueRequest;
import com.raytheon.uf.common.tafqueue.TafQueueRequest.Type;
import com.raytheon.uf.common.time.util.TimeUtil;
import com.raytheon.uf.viz.core.auth.UserController;
import com.raytheon.uf.viz.core.exception.VizException;
import com.raytheon.uf.viz.core.requests.ThriftClient;
@ -84,6 +87,8 @@ import com.raytheon.viz.ui.dialogs.CaveSWTDialog;
* 06May2014 3091 rferrel Use OUP authorization to bring up send dialog.
* 20May2015 4510 rferrel Added {@link #getForecasterId()}.
* Sep 25, 2015 4918 rferrel Allow selection of forecaster to send a TAF.
* Nov 06, 2015 5108 rferrel Display warning when forecast xmittime will result in a
* header time the same as any existing pending forecast.
*
* </pre>
*
@ -456,15 +461,66 @@ public class SendDialog extends CaveSWTDialog {
request.setType(Type.CREATE);
request.setUser(UserController.getUserObject());
Calendar xmitTime = Calendar.getInstance();
xmitTime.setTimeZone(TimeZone.getTimeZone("GMT"));
Calendar xmitTime = TimeUtil.newGmtCalendar();
xmitTime.set(Calendar.HOUR_OF_DAY, hourSpnr.getSelection());
xmitTime.set(Calendar.MINUTE, minuteSpnr.getSelection());
xmitTime.set(Calendar.SECOND, secondSpnr.getSelection());
xmitTime.set(Calendar.MILLISECOND, 0);
String xmitTimestamp = String.format(TIMESTAMP_FORMAT,
xmitTime.get(Calendar.DAY_OF_MONTH),
xmitTime.get(Calendar.HOUR_OF_DAY),
xmitTime.get(Calendar.MINUTE));
/*
* Check for pending entries with same xmitTimestamp. The header
* timestamp is always adjusted to the xmitTimestamp.
*/
TafQueueRequest pendingRequest = new TafQueueRequest();
pendingRequest.setType(Type.GET_TAFS);
pendingRequest.setUser(UserController.getUserObject());
pendingRequest.setXmitTime(xmitTime.getTime());
pendingRequest.setState(TafQueueState.PENDING);
ServerResponse<List<String>> pendingResponse = null;
try {
pendingResponse = (ServerResponse<List<String>>) ThriftClient
.sendRequest(pendingRequest);
} catch (VizException e1) {
String msg = "Unable to get pending TAFs. ";
statusHandler.handle(Priority.PROBLEM, msg, e1);
msgStatComp.setMessageText(msg,
shell.getDisplay().getSystemColor(SWT.COLOR_RED).getRGB());
return;
}
List<String> pendingList = pendingResponse.getPayload();
if (!pendingList.isEmpty()) {
StringBuilder message = new StringBuilder("The pending queue ");
if (pendingList.size() == 1) {
message.append("has a product with the same header time");
} else {
message.append("has products with the same header time");
}
msgStatComp.setMessageText(message.toString() + ".", shell
.getDisplay().getSystemColor(SWT.COLOR_RED).getRGB());
message.append(":\n");
for (String filename : pendingList) {
message.append(filename.split(",", 2)[1]).append("\n");
}
message.append("\nSelect OK to transmit this product with the same header time.");
MessageDialog dlg = new MessageDialog(shell,
"Duplicate Transmission Time", null, message.toString(),
MessageDialog.WARNING, new String[] { "OK", "Cancel" }, 1);
if (0 != dlg.open()) {
return;
} else {
statusHandler
.info("WARNING multiple products with same header time in the pending queue.");
}
}
// BBB
String in = tabComp.getTextEditorControl().getText();
String bbb = tabComp.getBBB();

View file

@ -22,8 +22,10 @@ package com.raytheon.viz.lightning;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.xml.bind.annotation.XmlAccessType;
@ -34,12 +36,18 @@ import javax.xml.bind.annotation.XmlElement;
import com.raytheon.uf.common.dataplugin.PluginDataObject;
import com.raytheon.uf.common.dataplugin.binlightning.BinLightningRecord;
import com.raytheon.uf.common.dataplugin.binlightning.LightningConstants;
import com.raytheon.uf.common.dataquery.requests.DbQueryRequest;
import com.raytheon.uf.common.dataquery.requests.RequestConstraint;
import com.raytheon.uf.common.dataquery.responses.DbQueryResponse;
import com.raytheon.uf.common.status.IUFStatusHandler;
import com.raytheon.uf.common.status.UFStatus;
import com.raytheon.uf.common.status.UFStatus.Priority;
import com.raytheon.uf.common.time.BinOffset;
import com.raytheon.uf.common.time.DataTime;
import com.raytheon.uf.common.time.SimulatedTime;
import com.raytheon.uf.common.time.util.TimeUtil;
import com.raytheon.uf.viz.core.exception.VizException;
import com.raytheon.uf.viz.core.requests.ThriftClient;
import com.raytheon.uf.viz.core.rsc.AbstractRequestableResourceData;
import com.raytheon.uf.viz.core.rsc.AbstractVizResource;
import com.raytheon.uf.viz.core.rsc.LoadProperties;
@ -50,16 +58,19 @@ import com.raytheon.uf.viz.core.rsc.LoadProperties;
* <pre>
*
* SOFTWARE HISTORY
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Feb 18, 2009 chammack Initial creation
* Feb 27, 2013 DCS 152 jgerth Support for WWLLN and multiple sources
* Jun 19, 2014 3214 bclement added pulse and cloud flash support
* Jul 07, 2014 3333 bclement removed plotLightSource field
* Mar 05, 2015 4233 bsteffen include source in cache key.
* Jul 01, 2015 4597 bclement added DisplayType
* Jul 02, 2015 4605 bclement don't show current bin as available
* Sep 25, 2015 4605 bsteffen repeat binning
*
* Date Ticket# Engineer Description
* ------------- -------- --------- --------------------------------------------
* Feb 18, 2009 1959 chammack Initial creation
* Feb 27, 2013 DCS 152 jgerth Support for WWLLN and multiple sources
* Jun 19, 2014 3214 bclement added pulse and cloud flash support
* Jul 07, 2014 3333 bclement removed plotLightSource field
* Mar 05, 2015 4233 bsteffen include source in cache key.
* Jul 01, 2015 4597 bclement added DisplayType
* Jul 02, 2015 4605 bclement don't show current bin as available
* Sep 25, 2015 4605 bsteffen repeat binning
* Nov 04, 2015 5090 bsteffen Add ability to get available times from a
* range.
*
* </pre>
*
@ -158,6 +169,55 @@ public class LightningResourceData extends AbstractRequestableResourceData {
return rval;
}
@Override
protected DataTime[] getAvailableTimes(
Map<String, RequestConstraint> constraintMap, BinOffset binOffset)
throws VizException {
if (binOffset != null
&& binOffset.getInterval() <= TimeUtil.SECONDS_PER_MINUTE) {
return getAvailableTimesFromRange(constraintMap, binOffset);
} else {
return super.getAvailableTimes(constraintMap, binOffset);
}
}
/**
* Replacement for {@link #getAvailableTimes(Map, BinOffset)} that includes
* the binned end times in the result. Normally binning is only applied to
* the start time of the range, so it is possible to miss frames where data
* is available at the end of the range. For very small bins it is necessary
* to use both start and end time to ensure all frames are displayed.
*/
protected DataTime[] getAvailableTimesFromRange(
Map<String, RequestConstraint> constraintMap, BinOffset binOffset)
throws VizException {
DbQueryRequest request = new DbQueryRequest(constraintMap);
request.addRequestField(PluginDataObject.STARTTIME_ID);
request.addRequestField(PluginDataObject.ENDTIME_ID);
request.setDistinct(true);
DbQueryResponse response = (DbQueryResponse) ThriftClient
.sendRequest(request);
Date[] startTimes = response.getFieldObjects(
PluginDataObject.STARTTIME_ID, Date.class);
Date[] endTimes = response.getFieldObjects(PluginDataObject.ENDTIME_ID,
Date.class);
Set<DataTime> binnedTimes = new HashSet<>(startTimes.length);
for (Date time : startTimes) {
DataTime dataTime = new DataTime(time);
dataTime = binOffset.getNormalizedTime(dataTime);
binnedTimes.add(dataTime);
}
for (Date time : endTimes) {
DataTime dataTime = new DataTime(time);
dataTime = binOffset.getNormalizedTime(dataTime);
binnedTimes.add(dataTime);
}
DataTime[] allTimes = binnedTimes.toArray(new DataTime[0]);
Arrays.sort(allTimes);
return allTimes;
}
@Override
protected PluginDataObject[] requestPluginDataObjects(
Collection<DataTime> loadSet) throws VizException {

View file

@ -30,6 +30,7 @@ import java.util.Map;
import java.util.Map.Entry;
import com.raytheon.uf.common.dataplugin.HDF5Util;
import com.raytheon.uf.common.dataplugin.PluginDataObject;
import com.raytheon.uf.common.dataplugin.annotations.DataURI;
import com.raytheon.uf.common.dataplugin.binlightning.BinLightningRecord;
import com.raytheon.uf.common.dataplugin.binlightning.LightningConstants;
@ -65,12 +66,15 @@ import com.raytheon.uf.viz.core.cache.CacheObject.IObjectRetrieverAndDisposer;
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Jul 09, 2014 3333 bclement moved from LightningResource
* Jul 22, 2014 3214 bclement fixed typos in populatePulseData() and updateAndGet()
* Sep 11, 2014 3608 bclement index records by group and dataset name for better error handling
* Sep 25, 2015 4605 bsteffen repeat binning
* Date Ticket# Engineer Description
* ------------- -------- --------- --------------------------------------------
* Jul 09, 2014 3333 bclement moved from LightningResource
* Jul 22, 2014 3214 bclement fixed typos in populatePulseData() and
* updateAndGet()
* Sep 11, 2014 3608 bclement index records by group and dataset name for
* better error handling
* Sep 25, 2015 4605 bsteffen repeat binning
* Nov 05, 2015 5090 bsteffen Use constants for datatime start/end
*
* </pre>
*
@ -149,9 +153,9 @@ public class LightningFrameRetriever implements
DbQueryRequest request = new DbQueryRequest();
request.setEntityClass(BinLightningRecord.class);
request.addConstraint(LightningConstants.SOURCE, sourceRC);
request.addConstraint("dataTime.validPeriod.start",
request.addConstraint(PluginDataObject.STARTTIME_ID,
startRC);
request.addConstraint("dataTime.validPeriod.end", endRC);
request.addConstraint(PluginDataObject.ENDTIME_ID, endRC);
try {
DbQueryResponse response = (DbQueryResponse) RequestRouter
.route(request);

View file

@ -105,7 +105,6 @@
<feature id="com.raytheon.viz.hydro.feature" version="1.0.0.qualifier"/>
<feature id="com.raytheon.uf.viz.dat.feature" version="1.0.0.qualifier"/>
<feature id="com.raytheon.uf.viz.d2d.gfe.feature" version="1.0.0.qualifier"/>
<feature id="com.raytheon.uf.viz.collaboration.feature" version="1.0.0.qualifier"/>
<feature id="com.raytheon.uf.viz.d2d.damagepath.feature" version="1.0.0.qualifier"/>
<feature id="com.raytheon.uf.viz.gisdatastore.feature" version="1.0.0.qualifier"/>
<feature id="com.raytheon.uf.viz.d2d.ui.awips.feature" version="1.0.0.qualifier"/>

View file

@ -359,6 +359,7 @@ import com.raytheon.viz.ui.simulatedtime.SimulatedTimeOperations;
* 07Oct2015 RM 18132 D. Friedman Exlucde certain phensigs from automatic ETN incrementing.
* Oct 28, 2015 5054 randerso Make Text Editor windows appear on same monitor as the parent.
* Removed hard coded offset for window placement.
* Nov 05, 2015 5039 rferrel Prevent wrapping text to a component name line and clean up of streams.
*
* </pre>
*
@ -528,6 +529,12 @@ public class TextEditorDialog extends CaveSWTDialog implements VerifyListener,
private static final Pattern UGC_FIRST_LINE_PATTERN = Pattern
.compile("^[A-Z][A-Z0-9][CZ]\\d{3}[->].*-\\s*$");
/**
* Pattern used to determine if a line is a component name line.
*/
private static final Pattern COMPONENT_NAME_PATTERN = Pattern
.compile("^\\.[A-Za-z0-9][^.]*\\.{3}");
/**
* The directory to place saved sessions.
*/
@ -4759,20 +4766,20 @@ public class TextEditorDialog extends CaveSWTDialog implements VerifyListener,
File file = new File(fn);
if (file.exists() && (file.length() <= 50000)
&& isTextFile(file)) {
FileInputStream in = new FileInputStream(file);
byte[] bytes = new byte[(int) file.length()];
int offset = 0;
int numRead = 0;
while ((offset < bytes.length)
&& ((numRead = in.read(bytes, offset, bytes.length
- offset)) >= 0)) {
offset += numRead;
try (FileInputStream in = new FileInputStream(file)) {
byte[] bytes = new byte[(int) file.length()];
int offset = 0;
int numRead = 0;
while ((offset < bytes.length)
&& ((numRead = in.read(bytes, offset,
bytes.length - offset)) >= 0)) {
offset += numRead;
}
attachedFile = bytes;
attachedFilename = fn.substring(fn
.lastIndexOf(File.separator) + 1);
statusBarLabel.setText("Attachment: " + fn);
}
in.close();
attachedFile = bytes;
attachedFilename = fn.substring(fn
.lastIndexOf(File.separator) + 1);
statusBarLabel.setText("Attachment: " + fn);
} else {
StringBuilder sb = new StringBuilder();
if (!file.exists()) {
@ -4807,8 +4814,7 @@ public class TextEditorDialog extends CaveSWTDialog implements VerifyListener,
dlg.setFilterExtensions(FILTER_EXTS);
String fn = dlg.open();
if (fn != null) {
try {
BufferedWriter out = new BufferedWriter(new FileWriter(fn));
try (BufferedWriter out = new BufferedWriter(new FileWriter(fn))) {
StringBuilder s = new StringBuilder();
if (inEditMode) {
s.append(removeSoftReturns(headerTF.getText()));
@ -4821,7 +4827,6 @@ public class TextEditorDialog extends CaveSWTDialog implements VerifyListener,
s.replace(ddhhmmIndex, ddhhmmIndex + 6, "000000");
}
out.append(s);
out.close();
} catch (IOException e1) {
statusHandler.handle(Priority.PROBLEM,
"Error retrieving metatdata", e1);
@ -5198,7 +5203,9 @@ public class TextEditorDialog extends CaveSWTDialog implements VerifyListener,
throw new Exception("ETN rules file (" + ETN_RULES_FILE
+ ") not found.");
}
return JAXB.unmarshal(lf.getFile(), EtnRules.class);
try (InputStream stream = lf.openInputStream()) {
return JAXB.unmarshal(stream, EtnRules.class);
}
}
private boolean shouldSetETNtoNextValue(StdTextProduct prod) {
@ -5752,8 +5759,8 @@ public class TextEditorDialog extends CaveSWTDialog implements VerifyListener,
}
}
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
// e.printStackTrace();
statusHandler.handle(Priority.PROBLEM, "Problem verifying text. ",
e);
}
}
@ -7397,8 +7404,6 @@ public class TextEditorDialog extends CaveSWTDialog implements VerifyListener,
+ "_"
+ AUTOSAVE_DATE_FORMAT.format(TimeUtil.newGmtCalendar()
.getTime()) + ".txt";
BufferedOutputStream bufStream = null;
try {
// delete and write new file, rename didn't always work
// rename would end up writing a new file every time and
@ -7414,10 +7419,11 @@ public class TextEditorDialog extends CaveSWTDialog implements VerifyListener,
.warn("Auto save failed. See server for details...");
} else {
synchronized (this) {
bufStream = new BufferedOutputStream(
new FileOutputStream(file));
getJaxbManager().marshalToStream(stdTextProduct,
bufStream);
try (BufferedOutputStream bufStream = new BufferedOutputStream(
new FileOutputStream(file))) {
getJaxbManager().marshalToStream(stdTextProduct,
bufStream);
}
}
}
@ -7426,15 +7432,6 @@ public class TextEditorDialog extends CaveSWTDialog implements VerifyListener,
} catch (Exception e) {
statusHandler.handle(Priority.PROBLEM, "Auto save failed to "
+ filename, e);
} finally {
if (bufStream != null) {
try {
bufStream.close();
} catch (IOException e) {
statusHandler.handle(Priority.VERBOSE,
"Failed to close file stream", e);
}
}
}
}
@ -7442,30 +7439,19 @@ public class TextEditorDialog extends CaveSWTDialog implements VerifyListener,
StdTextProduct rval = null;
if (file != null) {
BufferedInputStream bufStream = null;
synchronized (this) {
try (BufferedInputStream bufStream = new BufferedInputStream(
new FileInputStream(file))) {
try {
synchronized (this) {
bufStream = new BufferedInputStream(
new FileInputStream(file));
}
rval = (StdTextProduct) getJaxbManager()
.unmarshalFromInputStream(bufStream);
} catch (Exception e) {
statusHandler.handle(Priority.PROBLEM,
"Retrieval of product failed:" + file.getName(), e);
} finally {
if (bufStream != null) {
try {
bufStream.close();
} catch (IOException e) {
statusHandler.handle(Priority.VERBOSE,
"Failed to close file stream", e);
}
rval = (StdTextProduct) getJaxbManager()
.unmarshalFromInputStream(bufStream);
} catch (Exception e) {
statusHandler
.handle(Priority.PROBLEM,
"Retrieval of product failed:"
+ file.getName(), e);
}
}
}
return rval;
@ -8444,10 +8430,26 @@ public class TextEditorDialog extends CaveSWTDialog implements VerifyListener,
rval = true;
} else if (isSaoMetarFlag && (lineText.startsWith(" ") == false)) {
rval = true;
} else if (isComponentNameLine(line - 1)) {
rval = true;
}
return rval;
}
/**
* @param lineNumber
* @return true when line number is a component name line
*/
private boolean isComponentNameLine(int lineNumber) {
boolean result = false;
if ((lineNumber > 0)
&& textEditor.getLine(lineNumber - 1).trim().isEmpty()) {
result = COMPONENT_NAME_PATTERN.matcher(
textEditor.getLine(lineNumber)).find();
}
return result;
}
/**
* call recompileRegex when charWrapCol changes
*/
@ -8599,11 +8601,9 @@ public class TextEditorDialog extends CaveSWTDialog implements VerifyListener,
* @throws IOException
*/
private byte[] getBytesFromFile(File file) throws IOException {
InputStream is = null;
byte[] bytes = null;
try {
is = new FileInputStream(file);
try (InputStream is = new FileInputStream(file)) {
// Get the size of the file
long length = file.length();
@ -8632,11 +8632,6 @@ public class TextEditorDialog extends CaveSWTDialog implements VerifyListener,
} catch (Exception ex) {
statusHandler.handle(Priority.PROBLEM,
"Error opening input stream.", ex);
} finally {
// Close the input stream and return bytes
if (is != null) {
is.close();
}
}
return bytes;

View file

@ -6,6 +6,7 @@ Bundle-Version: 1.14.0.qualifier
Bundle-Vendor: RAYTHEON
Bundle-RequiredExecutionEnvironment: JavaSE-1.7
Export-Package: com.raytheon.uf.common.dataplugin.ffmp,
com.raytheon.uf.common.dataplugin.ffmp.collections,
com.raytheon.uf.common.dataplugin.ffmp.dataaccess
Require-Bundle: javax.persistence;bundle-version="1.0.0",
com.raytheon.uf.common.serialization,

View file

@ -52,6 +52,7 @@ import com.raytheon.uf.common.serialization.annotations.DynamicSerializeElement;
* Jul 31, 2013 2242 bsteffen Optimize FFMP NavigableMap memory.
* Aug 08, 2015 4722 dhladky Dynamic serialize imp not needed.
* Oct 10, 2015 4756 dhladky Prevent null values from being inserted.
* Oct 26, 2015 5056 dhladky Better debugging info.
*
* </pre>
*
@ -445,6 +446,7 @@ public class FFMPBasin implements Cloneable {
buff.append("PFAF ID: " + pfaf + "\n");
buff.append("Aggregated : " + aggregated + "\n");
for (Date date : values.keySet()) {
buff.append("Date : " + date + "\n");
buff.append("Value : " + values.get(date) + "\n");
}
return buff.toString();

View file

@ -59,6 +59,7 @@ import com.raytheon.uf.common.serialization.annotations.DynamicSerializeElement;
* Jul 31, 2013 2242 bsteffen Optimize FFMP NavigableMap memory.
* Aug 08, 2015 4722 dhladky Dynamic serialize imp not needed.
* Aug 31, 2015 4780 dhladky Corrected guidance basin mosaic averaging logic.
* Oct 26, 2015 5056 dhladky Simplified guidance interpolator.
*
*
* </pre>
@ -430,11 +431,8 @@ public class FFMPBasinData {
FFMPGuidanceBasin fgb = (FFMPGuidanceBasin) basin;
if (forcedPfafs.contains(pfaf)) {
if (interpolation.isInterpolate()) {
value = fgb.getInterpolatedValue(
interpolation.getSource1(),
interpolation.getSource2(),
interpolation.getInterpolationOffset(),
interpolation, expiration);
value = fgb.getInterpolatedValue(interpolation,
expiration);
} else {
value = fgb.getValue(interpolation.getStandardSource(),
interpolation, expiration);
@ -449,11 +447,8 @@ public class FFMPBasinData {
if (interpolation.isInterpolate()) {
float nvalue;
if (new Float(guidance).isNaN()) {
nvalue = fgb.getInterpolatedValue(
interpolation.getSource1(),
interpolation.getSource2(),
interpolation.getInterpolationOffset(),
interpolation, expiration);
nvalue = fgb.getInterpolatedValue(interpolation,
expiration);
} else {
nvalue = guidance;
}
@ -506,11 +501,8 @@ public class FFMPBasinData {
FFMPGuidanceBasin fgb = (FFMPGuidanceBasin) basin;
fgb.setCountyFips(parentPfaf);
if (interpolation.isInterpolate()) {
float nvalue = fgb.getInterpolatedValue(
interpolation.getSource1(),
interpolation.getSource2(),
interpolation.getInterpolationOffset(),
interpolation, expiration);
float nvalue = fgb.getInterpolatedValue(interpolation,
expiration);
// ignore missing values
if (nvalue < -999) {
continue;
@ -586,11 +578,8 @@ public class FFMPBasinData {
if (basin != null) {
FFMPGuidanceBasin fgb = (FFMPGuidanceBasin) basin;
if (interpolation.isInterpolate()) {
values.add(fgb.getInterpolatedValue(
interpolation.getSource1(),
interpolation.getSource2(),
interpolation.getInterpolationOffset(),
interpolation, expiration));
values.add(fgb.getInterpolatedValue(interpolation,
expiration));
} else {
values.add(fgb.getValue(interpolation.getStandardSource(),
interpolation, expiration));

View file

@ -25,6 +25,7 @@ import com.raytheon.uf.common.serialization.annotations.DynamicSerializeElement;
* 08/22/10 3437 D. Hladky Initial release
* 01/17/13 1478 D. Hladky Removed un-needed XML attributes
* Aug 08, 2015 4722 dhladky Dynamic serialize imp not needed.
* Oct 26, 2015 5056 dhladky Simplified Guidance interpolator.
*
* </pre>
*
@ -326,18 +327,19 @@ public class FFMPGuidanceBasin extends FFMPBasin {
/**
* Interpolate between guidance sources
*
* @param source1
* @param source2
* @param ratioOffset
* @param interpolation
* @param expiration
* @return
*/
public Float getInterpolatedValue(String source1, String source2,
double ratioOffset, FFMPGuidanceInterpolation interpolation,
public Float getInterpolatedValue(FFMPGuidanceInterpolation interpolation,
long expiration) {
float value1 = 0.0f;
float value2 = 0.0f;
String source1 = interpolation.getSource1();
String source2 = interpolation.getSource2();
double ratioOffset = interpolation.getInterpolationOffset();
// interpolate from zero to first guidance
if (source1.equals(source2)) {
if ((ratioOffset == Double.NaN) || (ratioOffset == 0.0)) {

View file

@ -2187,7 +2187,7 @@ public class FFMPTemplates {
}
/**
* Get the ares for a list of pfafs
* Get the areas for a list of pfafs
*
* @param pfafs
* @return

View file

@ -0,0 +1,772 @@
/**
* 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.dataplugin.ffmp.collections;
import java.io.File;
import java.lang.ref.SoftReference;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.NavigableMap;
import java.util.Set;
import java.util.SortedMap;
import java.util.concurrent.ConcurrentNavigableMap;
import com.raytheon.uf.common.dataplugin.HDF5Util;
import com.raytheon.uf.common.dataplugin.ffmp.FFMPAggregateRecord;
import com.raytheon.uf.common.dataplugin.ffmp.FFMPBasin;
import com.raytheon.uf.common.dataplugin.ffmp.FFMPBasinData;
import com.raytheon.uf.common.dataplugin.ffmp.FFMPRecord;
import com.raytheon.uf.common.dataplugin.ffmp.FFMPTemplates;
import com.raytheon.uf.common.dataplugin.ffmp.FFMPTemplates.MODE;
import com.raytheon.uf.common.dataquery.requests.DbQueryRequest;
import com.raytheon.uf.common.dataquery.requests.DbQueryRequest.OrderMode;
import com.raytheon.uf.common.dataquery.requests.RequestConstraint;
import com.raytheon.uf.common.dataquery.requests.RequestConstraint.ConstraintType;
import com.raytheon.uf.common.dataquery.responses.DbQueryResponse;
import com.raytheon.uf.common.datastorage.DataStoreFactory;
import com.raytheon.uf.common.datastorage.IDataStore;
import com.raytheon.uf.common.monitor.config.FFMPRunConfigurationManager;
import com.raytheon.uf.common.monitor.config.FFMPSourceConfigurationManager;
import com.raytheon.uf.common.monitor.config.FFMPSourceConfigurationManager.GUIDANCE_TYPE;
import com.raytheon.uf.common.monitor.config.FFMPSourceConfigurationManager.SOURCE_TYPE;
import com.raytheon.uf.common.monitor.xml.DomainXML;
import com.raytheon.uf.common.monitor.xml.FFMPRunXML;
import com.raytheon.uf.common.monitor.xml.ProductRunXML;
import com.raytheon.uf.common.monitor.xml.ProductXML;
import com.raytheon.uf.common.monitor.xml.SourceXML;
import com.raytheon.uf.common.serialization.comm.RequestRouter;
import com.raytheon.uf.common.status.IUFStatusHandler;
import com.raytheon.uf.common.status.UFStatus;
import com.raytheon.uf.common.time.util.TimeUtil;
/**
* FFMP Common Data Cache
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Oct 26, 2015 5056 D. Hladky Initial release
*
* </pre>
*
* @author dhladky
* @version 1
*/
public class FFMPDataCache {
/** Soft reference wrapper for data cache **/
private static SoftReference<FFMPDataCache> softCache = new SoftReference<FFMPDataCache>(null);
/** FFMP Source configuration manager **/
private FFMPSourceConfigurationManager fscm = FFMPSourceConfigurationManager.getInstance();
/** FFMP Running(Comparison) configuration manager **/
private FFMPRunConfigurationManager frcm = FFMPRunConfigurationManager.getInstance();
/** The FFMP templates **/
private volatile FFMPTemplates templates;
/** FFMP Cache Data Container **/
private final FFMPSiteDataContainer siteDataMap = new FFMPSiteDataContainer();
/** Local lock object for URI requests **/
private final Object uriRequestLock = new Object();
/** WFO this cache is active for **/
private final String wfo;
/** Status handler **/
private static final transient IUFStatusHandler statusHandler = UFStatus
.getHandler(FFMPDataCache.class);
/**
* Singleton instance
*
* @param wfo
*
* @return
*/
public static synchronized FFMPDataCache getInstance(String wfo) {
FFMPDataCache cache = softCache.get();
if (cache == null ||!cache.wfo.equals(wfo)) {
cache = new FFMPDataCache(wfo);
softCache = new SoftReference<FFMPDataCache>(cache);
}
return cache;
}
/**
* private instance constructor
*
* @param wfo
*/
private FFMPDataCache(String wfo) {
this.wfo = wfo;
}
/**
* Gets the HUC templates
*
* @param siteKey
* @return
*/
public FFMPTemplates getTemplates(String siteKey) {
if (templates == null) {
long t0 = System.currentTimeMillis();
synchronized (this) {
if (templates == null) {
FFMPRunXML runner = frcm.getRunner(wfo);
templates = FFMPTemplates.getInstance(
runner.getPrimaryDomain(), siteKey, MODE.CAVE);
// backup domains
if (runner.getBackupDomains() != null) {
for (DomainXML backup : runner.getBackupDomains()) {
templates.addDomain(siteKey, backup);
}
} else {
templates.done = true;
}
}
}
statusHandler.info("Time spent initializing templates: "
+ (System.currentTimeMillis() - t0));
}
if (!templates.isSiteLoaded(siteKey)) {
FFMPRunXML runner = frcm.getRunner(wfo);
for (DomainXML domain : runner.getDomains()) {
templates.addDomain(siteKey, domain);
}
}
return templates;
}
/**
* populate a new FFMPRecord
*
* @param uri
* @param siteKey
* @param source
* @return
* @throws Exception
*/
public FFMPRecord populateFFMPRecord(String uri, String siteKey,
String source) throws Exception {
populateFFMPRecord(siteKey, new FFMPRecord(uri), source);
SourceXML sourceXml = fscm.getSource(source);
if (sourceXml.getSourceType().equals(
SOURCE_TYPE.GUIDANCE.getSourceType())) {
source = sourceXml.getDisplayName();
}
return siteDataMap.get(siteKey).getSourceData(source).getRecord(uri);
}
/**
* populate a new FFMPRecord
*
* @param siteKey
* @param dataKey
* @param source
* @param ptime
* @param retrieveNew
* @throws Exception
*/
public void populateFFMPRecord(String siteKey, String dataKey,
String source, Date ptime, boolean retrieveNew) throws Exception {
if (source != null) {
boolean dupOverride = false;
if (fscm.getSource(source).getSourceType()
.equals(SOURCE_TYPE.GUIDANCE.getSourceType())) {
dupOverride = true;
}
SortedMap<Date, List<String>> urisByDate = getAvailableUris(
siteKey, dataKey, source, ptime, retrieveNew);
if (urisByDate != null) {
for (List<String> uris : urisByDate.values()) {
for (String uri : uris) {
if (uri != null) {
if (dupOverride
|| !getLoadedUris(siteKey, source)
.contains(uri)) {
populateFFMPRecord(siteKey,
new FFMPRecord(uri), source);
}
}
}
}
}
}
}
/**
* Inserts the loader records directly into the cache
*
*
* @param data
* @param uris
* @param siteKey
* @param source
*/
public void insertFFMPData(FFMPAggregateRecord data,
NavigableMap<Date, List<String>> uris, String siteKey, String source) {
// get record from cache
FFMPSourceData sourceData = siteDataMap.get(siteKey).getSourceData(
source);
// add all of the uris
for (Entry<Date, List<String>> duris : uris.entrySet()) {
if (data.getTimes().contains(duris.getKey().getTime())) {
for (String uri : duris.getValue()) {
sourceData.getRecord(uri);
if (!sourceData.getLoadedUris().contains(uri)) {
sourceData.addLoadedUri(uri);
}
}
}
}
if (sourceData.getRecord() != null) {
FFMPBasinData basinData = data.getBasins();
basinData.populate(data.getTimes());
sourceData.getRecord().populate(basinData);
}
}
/**
* Try and get the loading off of the GUI thread
*
* @param siteKey
* @param ffmpRec
* @param source
*
* @throws Exception
*/
public void populateFFMPRecord(String siteKey, FFMPRecord ffmpRec,
String source) throws Exception {
if (ffmpRec != null) {
List<String> uris = getLoadedUris(siteKey, source);
String dataUri = ffmpRec.getDataURI();
if (!uris.contains(dataUri)) {
Date refTime = ffmpRec.getDataTime().getRefTime();
File loc = HDF5Util.findHDF5Location(ffmpRec);
FFMPSiteData siteData = siteDataMap.get(siteKey);
String mySource = source;
boolean isGageSource = false;
SourceXML sourceXML = fscm.getSource(source);
if (sourceXML.getSourceType().equals(
SOURCE_TYPE.GUIDANCE.getSourceType())) {
mySource = sourceXML.getDisplayName();
} else if (sourceXML.getSourceType().equals(
SOURCE_TYPE.GAGE.getSourceType())) {
isGageSource = true;
}
FFMPSourceData sourceData = siteData
.getSourceData(mySource);
FFMPRecord curRecord = sourceData.getRecord(dataUri);
if (isGageSource) {
curRecord.retrieveVirtualMapFromDataStore(loc, dataUri,
getTemplates(siteKey), refTime,
ffmpRec.getSourceName());
} else {
curRecord.retrieveMapFromDataStore(loc, dataUri,
getTemplates(ffmpRec.getSiteKey()), refTime,
ffmpRec.getSourceName());
}
sourceData.addLoadedUri(dataUri);
}
}
}
/**
* Load data for a particular basin
*
* @param dataUri
* @param siteKey
* @param source
* @param phuc
* @param basin
* @throws Exception
*/
public void populateFFMPBasin(String dataUri, String siteKey,
String source, String phuc, FFMPBasin basin) throws Exception {
if (dataUri != null) {
List<String> uris = getLoadedUris(siteKey, source);
if (!uris.contains(dataUri)) {
SourceXML sourceXML = fscm.getSource(source);
FFMPRecord ffmpRec = populateFFMPRecord(dataUri, siteKey,
source);
File loc = HDF5Util.findHDF5Location(ffmpRec);
IDataStore dataStore = DataStoreFactory.getDataStore(loc);
if (sourceXML.getSourceType().equals(
SOURCE_TYPE.GAGE.getSourceType())
&& phuc.equals(FFMPRecord.ALL)) {
ffmpRec.retrieveVirtualBasinFromDataStore(loc, dataUri,
getTemplates(siteKey), ffmpRec.getDataTime()
.getRefTime(), basin);
} else {
ffmpRec.retrieveBasinFromDataStore(dataStore, dataUri,
getTemplates(siteKey), phuc, ffmpRec
.getDataTime().getRefTime(), ffmpRec
.getSourceName(), basin);
}
}
}
}
/**
* gets the URI's by field type and site
*
* @param siteKey
* @param pfield
* @return
*/
public List<String> getLoadedUris(String siteKey, String source) {
FFMPSiteData siteData = siteDataMap.get(siteKey);
FFMPSourceData sourceData = siteData.getSourceData(source);
return sourceData.getLoadedUris();
}
/**
* Gets the available uris back to a given time
*
* @param siteKey
* @param dataKey
* @param sourceName
* @param time
* @param retrieveNew
* @return
* @throws Exception
*/
public ConcurrentNavigableMap<Date, List<String>> getAvailableUris(
String siteKey, String dataKey, String sourceName, Date time,
boolean retrieveNew) throws Exception {
synchronized (uriRequestLock) {
ConcurrentNavigableMap<Date, List<String>> sortedUris = siteDataMap
.get(siteKey).getSourceData(sourceName).getAvailableUris();
Date previousQueryTime = siteDataMap.get(siteKey)
.getSourceData(sourceName).getPreviousUriQueryDate();
Date earliestTime = time;
SourceXML source = fscm.getSource(sourceName);
boolean isTimeConstraint = true;
if (source.getSourceType().equals(
SOURCE_TYPE.GUIDANCE.getSourceType())) {
/**
* Always look back for guidance types because of long
* expiration times, prevents mosaic brittleness from occurring.
*/
retrieveNew = true;
if (source.getGuidanceType() != null
&& source.getGuidanceType().equals(
GUIDANCE_TYPE.ARCHIVE.getGuidanceType())) {
isTimeConstraint = false;
} else {
long timeOffset = source.getExpirationMinutes(siteKey)
* TimeUtil.MILLIS_PER_MINUTE;
earliestTime = new Date(time.getTime() - timeOffset);
}
}
if (retrieveNew
|| (time != null && (previousQueryTime == null || time
.before(previousQueryTime)))) {
DbQueryRequest request = new DbQueryRequest();
request.setEntityClass(FFMPRecord.class);
request.addRequestField("dataURI");
request.setOrderByField("dataTime.refTime", OrderMode.DESC);
request.addConstraint("wfo", new RequestConstraint(wfo));
request.addConstraint("sourceName", new RequestConstraint(
sourceName));
request.addConstraint("siteKey", new RequestConstraint(siteKey));
if (!source.isMosaic()) {
request.addConstraint("dataKey", new RequestConstraint(
dataKey));
}
// ARCHIVE sources don't have a time constraint
if (isTimeConstraint) {
String earliestTimeString = TimeUtil
.formatToSqlTimestamp(earliestTime);
if (!retrieveNew && (previousQueryTime != null)) {
String latestTimeString = TimeUtil
.formatToSqlTimestamp(previousQueryTime);
RequestConstraint timeRC = new RequestConstraint(null,
ConstraintType.BETWEEN);
timeRC.setBetweenValueList(new String[] {
earliestTimeString, latestTimeString });
request.addConstraint("dataTime.refTime", timeRC);
} else {
request.addConstraint("dataTime.refTime",
new RequestConstraint(earliestTimeString,
ConstraintType.GREATER_THAN_EQUALS));
}
}
handleURIRequest(request, siteKey, dataKey, time);
}
if (time != null) {
if (source.getSourceType().equals(
SOURCE_TYPE.GUIDANCE.getSourceType())) {
return sortedUris;
} else {
return sortedUris.tailMap(time, true);
}
}
}
return null;
}
/**
* Perform a single database request to populate the availableUris for
* multiple sources. After preloading the uris the uris for each source can
* be retrieved with getAvailableUris
*
* @param siteKey
* @param dataKey
* @param sourceNames
* @param time
* @throws Exception
*/
public void preloadAvailableUris(String siteKey, String dataKey,
Set<String> sourceNames, Date time) throws Exception {
synchronized (uriRequestLock) {
DbQueryRequest request = new DbQueryRequest();
request.setEntityClass(FFMPRecord.class);
request.addRequestField("dataURI");
request.setOrderByField("dataTime.refTime", OrderMode.DESC);
request.addConstraint("wfo", new RequestConstraint(wfo));
request.addConstraint("siteKey", new RequestConstraint(siteKey));
request.addConstraint("dataTime.refTime", new RequestConstraint(
TimeUtil.formatToSqlTimestamp(time),
ConstraintType.GREATER_THAN_EQUALS));
RequestConstraint sourceRC = new RequestConstraint(null,
ConstraintType.IN);
sourceRC.setConstraintValueList(sourceNames);
request.addConstraint("sourceName", sourceRC);
handleURIRequest(request, siteKey, dataKey, time);
FFMPSiteData siteData = siteDataMap.get(siteKey);
for (String sourceName : sourceNames) {
// This is done to ensure that the previous query time is
// updated, even for sources with no data.
FFMPSourceData sourceData = siteData.getSourceData(sourceName);
Date oldPrevTime = sourceData.getPreviousUriQueryDate();
if (oldPrevTime == null || time.before(oldPrevTime)) {
sourceData.setPreviousUriQueryDate(time);
}
}
}
}
/**
* Handle a pre assembled database query for uris. The request is sent to
* edex and the response is parsed to populate the uris in the siteDataMap.
*
* @param request
* @param siteKey
* @param dataKey
* @param time
* @throws Exception
*/
private void handleURIRequest(DbQueryRequest request, String siteKey,
String dataKey, Date time) throws Exception {
FFMPSiteData siteData = siteDataMap.get(siteKey);
DbQueryResponse dbResponse = (DbQueryResponse) RequestRouter
.route(request);
Map<String, List<FFMPRecord>> recordsBySource = new HashMap<String, List<FFMPRecord>>();
for (String datauri : dbResponse.getFieldObjects("dataURI",
String.class)) {
FFMPRecord record = new FFMPRecord(datauri);
List<FFMPRecord> records = recordsBySource.get(record
.getSourceName());
if (records == null) {
records = new ArrayList<FFMPRecord>();
recordsBySource.put(record.getSourceName(), records);
}
records.add(record);
}
for (Entry<String, List<FFMPRecord>> entry : recordsBySource.entrySet()) {
String sourceName = entry.getKey();
SourceXML sourceXml = fscm.getSource(sourceName);
boolean isMosiac = sourceXml.isMosaic();
FFMPSourceData sourceData = siteData.getSourceData(sourceName);
Map<Date, List<String>> sortedUris = sourceData.getAvailableUris();
List<String> list = new LinkedList<String>();
Date prevRefTime = null;
for (FFMPRecord rec : entry.getValue()) {
if (!isMosiac && !rec.getDataKey().equals(dataKey)) {
continue;
}
Date curRefTime = rec.getDataTime().getRefTime();
if ((prevRefTime != null) && !prevRefTime.equals(curRefTime)) {
sortedUris.put(prevRefTime, list);
list = new LinkedList<String>();
}
prevRefTime = curRefTime;
list.add(rec.getDataURI());
}
if (prevRefTime != null) {
sortedUris.put(prevRefTime, list);
}
Date prevTime = time;
if (sourceXml.getSourceType().equals(
SOURCE_TYPE.GUIDANCE.getSourceType())) {
long timeOffset = sourceXml.getExpirationMinutes(siteKey)
* TimeUtil.MILLIS_PER_MINUTE;
prevTime = new Date(time.getTime() - timeOffset);
}
Date oldPrevTime = sourceData.getPreviousUriQueryDate();
if (oldPrevTime == null || prevTime.before(oldPrevTime)) {
sourceData.setPreviousUriQueryDate(prevTime);
}
}
}
/**
* Process an individual URI
*
* @param isProductLoad
* @param uri
* @param siteKey
* @param sourceName
* @param barrierTime
* @throws Exception
*/
public void processUri(String uri, String siteKey, String sourceName,
Date barrierTime) throws Exception {
if (uri != null) {
FFMPRecord record = populateFFMPRecord(uri, siteKey, sourceName);
if (record != null) {
record.getBasinData().loadNow();
SourceXML source = fscm.getSource(sourceName);
if (source != null) {
record.setExpiration(source.getExpirationMinutes(siteKey));
record.setRate(source.isRate());
}
}
}
}
/**
* fire off a cleaner
*
* @param product
* @param source
* @param siteKey
* @param date
*/
public void purgeFFMPData(ProductXML product, String source,
String siteKey, Date date) {
ArrayList<String> purgeSources = new ArrayList<String>();
if (product != null) {
ProductRunXML productRun = frcm.getProduct(siteKey);
// guidance
for (String type : productRun.getGuidanceTypes(product)) {
for (SourceXML guidSource : productRun.getGuidanceSources(
product, type)) {
// Don't purge archive guidance!
if (guidSource != null
&& guidSource.getGuidanceType() != null
&& !guidSource.getGuidanceType()
.equals(GUIDANCE_TYPE.ARCHIVE
.getGuidanceType())) {
purgeSources.add(guidSource.getSourceName());
}
}
}
// qpf
for (String type : productRun.getQpfTypes(product)) {
for (SourceXML qpfSource : productRun.getQpfSources(
product, type)) {
if (qpfSource != null) {
purgeSources.add(qpfSource.getSourceName());
}
}
}
// qpe, etc
for (String sourceName : product.getSources()) {
if (!purgeSources.contains(sourceName)) {
purgeSources.add(sourceName);
}
}
for (String sourceName : purgeSources) {
SourceXML sourceXML = fscm.getSource(sourceName);
if (sourceXML != null) {
if (sourceXML.getSourceType().equals(
SOURCE_TYPE.GUIDANCE.getSourceType())) {
sourceName = SOURCE_TYPE.GUIDANCE.getSourceType();
}
if (siteDataMap != null) {
if (siteDataMap.containsSite(siteKey)) {
FFMPRecord record = siteDataMap.get(siteKey)
.getSourceData(sourceName).getRecord();
if (record != null) {
record.purgeData(date);
}
}
}
}
}
} else {
if (siteDataMap != null) {
if (siteDataMap.containsSite(siteKey)) {
FFMPRecord record = siteDataMap.get(siteKey)
.getSourceData(source).getRecord();
if (record != null) {
record.purgeData(date);
}
}
}
}
FFMPSiteData siteData = siteDataMap.get(siteKey);
for (String sourceEntry : siteData.getSources()) {
ConcurrentNavigableMap<Date, List<String>> oldUris = siteData
.getSourceData(sourceEntry).getAvailableUris()
.headMap(date);
for (List<String> uris : oldUris.headMap(date).values()) {
for (String uri : uris) {
if (product != null) {
for (String sourceName : purgeSources) {
if (siteData.getSourceData(sourceName)
.hasLoadedAnyUris()) {
FFMPSourceData sourceData = siteData
.getSourceData(sourceName);
sourceData.removeLoadedUri(uri);
}
}
} else {
FFMPSourceData sourceData = siteData
.getSourceData(source);
sourceData.removeLoadedUri(uri);
}
}
}
oldUris.clear();
}
}
/**
* Clear site Data
*/
public void clear() {
siteDataMap.clear();
}
/**
* Remove a site.
* @param siteKey
*/
public void removeSite(String siteKey) {
siteDataMap.removeSite(siteKey);
}
/**
* Get the FFMP Data for this site.
*
* @param siteKey
* @return
*/
public FFMPSiteData getFFMPSiteData(String siteKey) {
return siteDataMap.get(siteKey);
}
/**
* Gets the source data for this source.
*
* @param siteKey
* @param sourceName
* @return
*/
public FFMPSourceData getSourceData(String siteKey, String sourceName) {
return siteDataMap.get(siteKey).getSourceData(sourceName);
}
}

View file

@ -17,7 +17,7 @@
* See the AWIPS II Master Rights File ("Master Rights File.pdf") for
* further licensing information.
**/
package com.raytheon.uf.viz.monitor.ffmp;
package com.raytheon.uf.common.dataplugin.ffmp.collections;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
@ -34,6 +34,7 @@ import java.util.concurrent.ConcurrentMap;
* ------------ ---------- ----------- --------------------------
* Feb 18, 2013 njensen Initial creation
* Feb 28, 2013 1729 dhladky Sped up, synch blocks were hanging it.
* Oct 26, 2015 5056 dhladky Moved to common area for data cache.
*
* </pre>
*

View file

@ -17,7 +17,7 @@
* See the AWIPS II Master Rights File ("Master Rights File.pdf") for
* further licensing information.
**/
package com.raytheon.uf.viz.monitor.ffmp;
package com.raytheon.uf.common.dataplugin.ffmp.collections;
import java.util.Collection;
import java.util.concurrent.ConcurrentHashMap;
@ -34,6 +34,7 @@ import java.util.concurrent.ConcurrentMap;
* ------------ ---------- ----------- --------------------------
* Feb 19, 2013 njensen Initial creation
* Feb 28, 2013 1729 dhladky Sped up, synch blocks were hanging it.
* Oct 26, 2015 5056 dhladky Moved to common area for data cache.
*
* </pre>
*
@ -70,7 +71,7 @@ public class FFMPSiteDataContainer {
}
public FFMPSiteData removeSite(String siteKey) {
return siteDataMap.remove(siteKey);
}

View file

@ -17,7 +17,7 @@
* See the AWIPS II Master Rights File ("Master Rights File.pdf") for
* further licensing information.
**/
package com.raytheon.uf.viz.monitor.ffmp;
package com.raytheon.uf.common.dataplugin.ffmp.collections;
import java.util.ArrayList;
import java.util.Collections;
@ -25,6 +25,7 @@ import java.util.Date;
import java.util.List;
import java.util.concurrent.ConcurrentNavigableMap;
import java.util.concurrent.ConcurrentSkipListMap;
import java.util.concurrent.atomic.AtomicReference;
import com.raytheon.uf.common.dataplugin.ffmp.FFMPRecord;
@ -41,6 +42,7 @@ import com.raytheon.uf.common.dataplugin.ffmp.FFMPRecord;
* Feb 18, 2013 njensen Initial creation
* Feb 28, 2013 1729 dhladky Sped up, synch blocks were hanging it.
* Jul 15, 2013 2184 dhladky Removed all HUC's but ALL
* Oct 26, 2015 5056 dhladky Moved to common area for data cache.
*
* </pre>
*
@ -50,7 +52,7 @@ import com.raytheon.uf.common.dataplugin.ffmp.FFMPRecord;
public class FFMPSourceData {
private FFMPRecord ffmpData;
private AtomicReference<FFMPRecord> ffmpData = new AtomicReference<FFMPRecord>();
/** earliest available date queried **/
private Date previousUriQueryDate;
@ -73,21 +75,32 @@ public class FFMPSourceData {
}
/**
* Gets the FFMPRecord. Possibly null.
* Gets the FFMPRecord from the AtomicReference
*
* @return
*/
public FFMPRecord getRecord() {
return ffmpData;
}
return ffmpData.get();
}
/**
* Sets the FFMPRecord.
* Gets the FFMPRecord and sets it if null.
*
* @param record
* @return
*/
public void setRecord(FFMPRecord record) {
ffmpData = record;
public FFMPRecord getRecord(String uri) {
FFMPRecord record = ffmpData.get();
if (record == null) {
record = new FFMPRecord(uri);
if (!ffmpData.compareAndSet(null, record)) {
record = ffmpData.get();
}
}
return record;
}
/**

View file

@ -38,17 +38,21 @@ import com.raytheon.uf.common.dataaccess.util.DatabaseQueryUtil.QUERY_MODE;
import com.raytheon.uf.common.dataplugin.ffmp.FFMPBasin;
import com.raytheon.uf.common.dataplugin.ffmp.FFMPBasinData;
import com.raytheon.uf.common.dataplugin.ffmp.FFMPGuidanceBasin;
import com.raytheon.uf.common.dataplugin.ffmp.FFMPGuidanceInterpolation;
import com.raytheon.uf.common.dataplugin.ffmp.FFMPRecord;
import com.raytheon.uf.common.dataplugin.ffmp.FFMPTemplates;
import com.raytheon.uf.common.dataplugin.ffmp.FFMPTemplates.MODE;
import com.raytheon.uf.common.dataplugin.ffmp.HucLevelGeometriesFactory;
import com.raytheon.uf.common.dataplugin.ffmp.collections.FFMPDataCache;
import com.raytheon.uf.common.dataplugin.level.Level;
import com.raytheon.uf.common.dataquery.requests.RequestConstraint;
import com.raytheon.uf.common.dataquery.requests.RequestConstraint.ConstraintType;
import com.raytheon.uf.common.dataquery.responses.DbQueryResponse;
import com.raytheon.uf.common.monitor.config.FFFGDataMgr;
import com.raytheon.uf.common.monitor.config.FFMPRunConfigurationManager;
import com.raytheon.uf.common.monitor.config.FFMPSourceConfigurationManager;
import com.raytheon.uf.common.monitor.config.FFMPSourceConfigurationManager.SOURCE_TYPE;
import com.raytheon.uf.common.monitor.xml.DomainXML;
import com.raytheon.uf.common.monitor.xml.ProductRunXML;
import com.raytheon.uf.common.monitor.xml.ProductXML;
import com.raytheon.uf.common.monitor.xml.SourceXML;
import com.raytheon.uf.common.status.IUFStatusHandler;
import com.raytheon.uf.common.status.UFStatus;
@ -80,6 +84,7 @@ import com.vividsolutions.jts.geom.Geometry;
* Feb 27, 2015 4180 mapeters Overrode getAvailableParameters().
* Jun 15, 2015 4560 ccody Added support for configurable rate/accumulation calculation for getGeometryData
* Jul 16, 2015 4658 dhladky Expiration times fixed.
* Oct 26, 2015 5056 dhladky Re-wrote to take advantage of FFMP common data cache, fix general bugs.
*
* </pre>
*
@ -108,10 +113,11 @@ public class FFMPGeometryFactory extends AbstractDataPluginFactory {
/** source name constant */
public static final String SOURCE_NAME = "sourceName";
/** FFMP Templates object */
private FFMPTemplates templates;
/** accumulation hours, needed for FFG interpolator */
public static final String ACCUM_HRS = "accumHrs";
/**
* Constructor.
*/
@ -125,21 +131,26 @@ public class FFMPGeometryFactory extends AbstractDataPluginFactory {
protected IGeometryData[] getGeometryData(IDataRequest request,
DbQueryResponse dbQueryResponse) {
List<Map<String, Object>> results = dbQueryResponse.getResults();
Map<Long, DefaultGeometryData> cache = new HashMap<Long, DefaultGeometryData>();
FFMPRecord record = null;
String siteKey = (String) request.getIdentifiers().get(SITE_KEY);
String cwa = (String) request.getIdentifiers().get(WFO);
String sourceName = null;
Date start = new Date(Long.MAX_VALUE);
Date end = new Date(0);
FFMPDataCache cache = getCache(cwa);
// Ensures that all records have been added to the cache before calculations
for (Map<String, Object> map : results) {
for (Map.Entry<String, Object> es : map.entrySet()) {
FFMPRecord rec = (FFMPRecord) es.getValue();
/*
* Adding all of the basin data to a single record so that we
* can get the accumulated values from that record
*/
if (record == null) {
record = rec;
if (sourceName == null) {
sourceName = rec.getSourceName();
}
try {
cache.populateFFMPRecord(siteKey, rec, rec.getSourceName());
} catch (Exception e) {
statusHandler.handle(Priority.PROBLEM, "Unable to populate FFMPRecord: "+rec.getDataURI(), e);
}
// building a time range of the earliest FFMP time (based on
// each record) to the latest FFMP time (based on each record)
if (start.after(rec.getDataTime().getRefTime())) {
@ -148,43 +159,30 @@ public class FFMPGeometryFactory extends AbstractDataPluginFactory {
if (end.before(rec.getDataTime().getRefTime())) {
end = rec.getDataTime().getRefTime();
}
try {
rec.retrieveMapFromDataStore(templates);
} catch (Exception e) {
throw new DataRetrievalException(
"Failed to retrieve the IDataRecord for PluginDataObject: "
+ rec.toString(), e);
}
/*
* loop over each pfaf id in the current record (rec) we are
* iterating. Add that basin data to the record that we are
* keeping around (record) to use to get the accumulated value.
*/
for (Long pfaf : rec.getBasinData().getPfafIds()) {
// setValue is a misnomer here, it is actually an add
record.getBasinData()
.get(pfaf)
.setValue(rec.getDataTime().getRefTime(),
rec.getBasinData().get(pfaf).getValue());
}
}
}
// Time window for FFMP slides +- the 1/2 QPE expiration time.
int expirationTime = FFMPSourceConfigurationManager.getInstance()
.getSource(sourceName).getExpirationMinutes(siteKey);
start = new Date(start.getTime()
- (TimeUtil.MILLIS_PER_MINUTE * (expirationTime/2)));
/*
* now that we have all the basin data in a single record (record), we
* can use the methods on the FFMPRecord class to get the accumulated
* value in the case of a non-guidance basin
*/
Map<Long, DefaultGeometryData> result = null;
try {
cache = makeGeometryData(record, request, cache, start, end);
result = makeGeometryData(sourceName, request, start, end);
} catch (Exception e) {
statusHandler.handle(Priority.PROBLEM,
"Unable to create the geoemtry data from the records.", e);
throw new DataRetrievalException("Unable to create Geometry Data: sourceName: "+sourceName, e);
}
return cache.values().toArray(
new DefaultGeometryData[cache.values().size()]);
return result.values().toArray(
new DefaultGeometryData[result.values().size()]);
}
/**
@ -194,15 +192,16 @@ public class FFMPGeometryFactory extends AbstractDataPluginFactory {
protected Map<String, RequestConstraint> buildConstraintsFromRequest(
IDataRequest request) {
Map<String, RequestConstraint> map = new HashMap<String, RequestConstraint>();
Map<String, Object> identifiers = request.getIdentifiers();
String siteKey = (String) identifiers.get(SITE_KEY);
for (Map.Entry<String, Object> entry : request.getIdentifiers()
.entrySet()) {
String key = entry.getKey();
String value = (String) entry.getValue();
if (!key.equals(HUC)) {
RequestConstraint rc = new RequestConstraint(value);
map.put(key, rc);
// exclude this parameter
if (!key.equals(ACCUM_HRS)) {
String value = (String) entry.getValue();
if (!key.equals(HUC)) {
RequestConstraint rc = new RequestConstraint(value);
map.put(key, rc);
}
}
}
@ -211,74 +210,81 @@ public class FFMPGeometryFactory extends AbstractDataPluginFactory {
parameterConstraint.setConstraintType(ConstraintType.IN);
map.put(SOURCE_NAME, parameterConstraint);
String domain = (String) request.getIdentifiers().get(WFO);
DomainXML domainXml = FFMPRunConfigurationManager.getInstance()
.getDomain(domain);
templates = FFMPTemplates.getInstance(domainXml, siteKey, MODE.EDEX);
return map;
}
/**
* Create the IGeometryData objects.
*
* @param rec
* The FFMPRecord
* @param cache
* @param huc
* The HUC level
* @param siteKey
* The siteKey
* @param cwa
* The CWA
* @param dataKey
* The dataKey
* @param sourceName
* @param request
* @param start
* @param end
* @return
* @throws Exception
*/
private Map<Long, DefaultGeometryData> makeGeometryData(FFMPRecord rec,
IDataRequest request, Map<Long, DefaultGeometryData> cache,
Date start, Date end) throws Exception {
private Map<Long, DefaultGeometryData> makeGeometryData(String sourceName,
IDataRequest request, Date start, Date end) throws Exception {
Map<Long, DefaultGeometryData> result = new HashMap<Long, DefaultGeometryData>();
String huc = (String) request.getIdentifiers().get(HUC);
String dataKey = (String) request.getIdentifiers().get(DATA_KEY);
String siteKey = (String) request.getIdentifiers().get(SITE_KEY);
String cwa = (String) request.getIdentifiers().get(WFO);
Number accumulationTime = (Number) request.getIdentifiers().get(ACCUM_HRS);
FFMPDataCache cache = getCache(cwa);
if (dataKey == null) {
dataKey = siteKey;
}
FFMPBasinData basinData = rec.getBasinData();
FFMPGuidanceInterpolation interpolation = null;
FFMPBasinData basinData = null;
SourceXML source = FFMPSourceConfigurationManager.getInstance()
.getSource(sourceName);
if (source.getSourceType().equals(SOURCE_TYPE.GUIDANCE.getSourceType())) {
basinData = cache.getSourceData(siteKey, source.getDisplayName())
.getRecord().getBasinData();
interpolation = getGuidanceInterpolation(
accumulationTime.doubleValue(), sourceName, cwa, siteKey);
} else {
basinData = cache.getSourceData(siteKey, sourceName).getRecord()
.getBasinData();
}
Map<Long, FFMPBasin> basinDataMap = basinData.getBasins();
HucLevelGeometriesFactory geomFactory = HucLevelGeometriesFactory
.getInstance();
Map<Long, Geometry> geomMap = geomFactory.getGeometries(templates,
siteKey, cwa, huc);
FFMPSourceConfigurationManager srcConfigMan = FFMPSourceConfigurationManager
.getInstance();
SourceXML sourceXml = srcConfigMan.getSource(rec.getSourceName());
String rateOrAccum = sourceXml.getRateOrAccum(siteKey);
boolean isRate = false;
String rateOrAccum = null;
if (source.getSourceType().equals(SOURCE_TYPE.QPE.getSourceType())) {
rateOrAccum = source.getRateOrAccum(siteKey);
}
boolean isRate = true;
/**
* This is a misnomer that has caused loads of confusion.
* In actuality when the FFMPBasin accumulates it checks that the
* Type is NOT a rate and in fact should be accumulating. RATE == false.
* So in effect, values that FFMP stores as RATE==true are actually
* NOT rates when accumulated. So if, it is stored as RATE, it
* must use FALSE when processing the accumulation.
*/
if ((rateOrAccum != null) && (rateOrAccum.isEmpty() == false)
&& (rateOrAccum.compareToIgnoreCase("RATE") == 0)) {
isRate = true;
&& (rateOrAccum.compareToIgnoreCase("RATE") == 0)) {
isRate = false;
}
DefaultGeometryData data = null;
String[] locationNames = request.getLocationNames();
HucLevelGeometriesFactory geomFactory = HucLevelGeometriesFactory
.getInstance();
Map<Long, Geometry> geomMap = geomFactory.getGeometries(getCache(cwa).getTemplates(siteKey),
siteKey, cwa, huc);
List<Long> pfafList = null;
if (locationNames != null && locationNames.length > 0) {
pfafList = convertLocations(locationNames);
}
List<Long> pfafList = getAvailableLocationPfafs(request);
for (Long pfaf : geomMap.keySet()) {
if (pfafList == null || pfafList.contains(pfaf)) {
if (cache.containsKey(pfaf)) {
data = cache.get(pfaf);
if (result.containsKey(pfaf)) {
data = result.get(pfaf);
} else {
data = new DefaultGeometryData();
Map<String, Object> attrs = new HashMap<String, Object>();
@ -291,7 +297,7 @@ public class FFMPGeometryFactory extends AbstractDataPluginFactory {
data.setGeometry(geomMap.get(pfaf));
data.setDataTime(new DataTime(start.getTime(),
new TimeRange(start, end)));
cache.put(pfaf, data);
result.put(pfaf, data);
}
FFMPBasin basin = basinDataMap.get(pfaf);
@ -301,18 +307,41 @@ public class FFMPGeometryFactory extends AbstractDataPluginFactory {
continue;
}
/**
* Guidance Basins will use interpolation, need this to
* perfectly match FFMP table.
*/
if (basin instanceof FFMPGuidanceBasin) {
value = ((FFMPGuidanceBasin) basin).getValue(
rec.getSourceName(),
sourceXml.getExpirationMinutes(rec.getSiteKey())
* TimeUtil.MILLIS_PER_MINUTE);
if (interpolation.isInterpolate()) {
// Interpolating between sources
value = ((FFMPGuidanceBasin) basin)
.getInterpolatedValue(interpolation,
source.getExpirationMinutes(siteKey)
* TimeUtil.MILLIS_PER_MINUTE);
} else {
value = ((FFMPGuidanceBasin) basin).getValue(
interpolation.getStandardSource(),
interpolation,
source.getExpirationMinutes(siteKey)
* TimeUtil.MILLIS_PER_MINUTE);
}
// Will allow for any forcing to take precedence
FFFGDataMgr dman = FFFGDataMgr.getInstance();
if (dman.isExpired() == false) {
value = dman.adjustValue(value, sourceName,
basin.getPfaf(),
((FFMPGuidanceBasin) basin).getCountyFips());
}
} else {
value = basin.getAccumValue(start, end,
sourceXml.getExpirationMinutes(rec.getSiteKey())
source.getExpirationMinutes(siteKey)
* TimeUtil.MILLIS_PER_MINUTE, isRate);
}
String parameter = rec.getSourceName();
String unitStr = sourceXml.getUnit();
String parameter = sourceName;
String unitStr = source.getUnit();
Unit<?> unit = null;
if (unitStr.equals(SourceXML.UNIT_TXT)) {
@ -327,48 +356,38 @@ public class FFMPGeometryFactory extends AbstractDataPluginFactory {
}
}
return cache;
}
/**
* Convert list of PFAF strings to list of PFAF longs
*
* @param locationNames
* @return
*/
private List<Long> convertLocations(String[] locationNames) {
List<Long> pfafList = new ArrayList<Long>();
for (String s : locationNames) {
try {
pfafList.add(Long.parseLong(s));
} catch (NumberFormatException e) {
statusHandler.handle(Priority.PROBLEM,
"Error parsing pfaf id: " + s, e);
}
}
return pfafList;
return result;
}
/**
* {@inheritDoc}
*/
@Override
public String[] getAvailableLocationNames(IDataRequest request) {
List<String> pfafList = new ArrayList<String>();
String domain = (String) request.getIdentifiers().get("wfo");
String sql = "select pfaf_id from mapdata.ffmp_basins where cwa = '"
+ domain + "';";
List<Object[]> results = DatabaseQueryUtil.executeDatabaseQuery(
QUERY_MODE.MODE_SQLQUERY, sql, "metadata", PLUGIN_NAME);
for (Object[] oa : results) {
pfafList.add((String) oa[0]);
// Changed this to query the active Templates, not the DB.
List<Long> pfafs = getAvailableLocationPfafs(request);
List<String> pfafList = new ArrayList<String>(pfafs.size());
for (Long pfaf : pfafs) {
pfafList.add(String.valueOf(pfaf));
}
return pfafList.toArray(new String[0]);
}
/**
* Gets the available location Pfafs.
* @param request
* @return
*/
private List<Long> getAvailableLocationPfafs(IDataRequest request) {
String siteKey = (String) request.getIdentifiers().get(SITE_KEY);
String wfo = (String) request.getIdentifiers().get(WFO);
FFMPDataCache cache = getCache(wfo);
List<DomainXML> domains = cache.getTemplates(siteKey).getDomains();
return cache.getTemplates(siteKey).getHucKeyList(siteKey, FFMPRecord.ALL, domains);
}
@Override
public String[] getAvailableParameters(IDataRequest request) {
@ -410,6 +429,47 @@ public class FFMPGeometryFactory extends AbstractDataPluginFactory {
@Override
public String[] getOptionalIdentifiers() {
return new String[] { DATA_KEY };
return new String[] { DATA_KEY, ACCUM_HRS };
}
/**
* Get the FFG Object need to interpolate between sources
*
* @param accumulationTime
* @param sourceName
* @param wfo
* @param siteKey
* @return
*/
private FFMPGuidanceInterpolation getGuidanceInterpolation(
Double accumulationTime, String sourceName, String wfo,
String siteKey) {
FFMPSourceConfigurationManager sourceConfig = FFMPSourceConfigurationManager
.getInstance();
SourceXML source = sourceConfig.getSource(sourceName);
String primarySourceName = sourceConfig.getPrimarySource(source);
ProductXML product = sourceConfig.getProduct(primarySourceName);
ProductRunXML productRun = FFMPRunConfigurationManager.getInstance()
.getRunner(wfo).getProduct(siteKey);
FFMPGuidanceInterpolation interpolator = new FFMPGuidanceInterpolation(
sourceConfig, product, productRun, primarySourceName,
source.getDisplayName(), siteKey);
interpolator.setInterpolationSources(accumulationTime);
return interpolator;
}
/**
* The soft reference wrapped cache, if no longer needed,
* It will just fade away.
*/
private FFMPDataCache getCache(String wfo) {
return FFMPDataCache.getInstance(wfo);
}
}

View file

@ -1,7 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="output" path="bin"/>
</classpath>

View file

@ -1,28 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>com.raytheon.uf.edex.ogc.common</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.ManifestBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.SchemaBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.pde.PluginNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>

View file

@ -1,47 +0,0 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Common
Bundle-SymbolicName: com.raytheon.uf.edex.ogc.common
Bundle-Version: 1.15.0.qualifier
Bundle-Vendor: RAYTHEON
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Require-Bundle: net.opengis;bundle-version="1.0.2",
org.geotools;bundle-version="2.6.4",
org.apache.commons.lang3;bundle-version="3.4.0",
org.apache.camel;bundle-version="1.0.0",
javax.measure;bundle-version="1.0.0",
javax.persistence;bundle-version="1.0.0",
com.raytheon.edex.common;bundle-version="1.12.1174",
org.apache.commons.collections;bundle-version="3.2.0",
com.raytheon.uf.common.json;bundle-version="1.0.0",
com.sun.xml.bind;bundle-version="1.0.0",
com.raytheon.uf.common.status;bundle-version="1.12.1174",
com.raytheon.uf.common.pointdata;bundle-version="1.12.1174",
ogc.tools.gml;bundle-version="1.0.2",
org.apache.commons.cxf,
org.eclipse.jetty;bundle-version="7.6.9",
com.raytheon.uf.common.dataplugin.level;bundle-version="1.12.1174",
com.raytheon.uf.edex.log;bundle-version="1.12.1174",
com.raytheon.uf.common.http,
com.raytheon.uf.edex.soap;bundle-version="1.14.0"
Export-Package: com.raytheon.uf.edex.ogc.common,
com.raytheon.uf.edex.ogc.common.db,
com.raytheon.uf.edex.ogc.common.feature,
com.raytheon.uf.edex.ogc.common.filter,
com.raytheon.uf.edex.ogc.common.gml3_1_1,
com.raytheon.uf.edex.ogc.common.gml3_2_1,
com.raytheon.uf.edex.ogc.common.http,
com.raytheon.uf.edex.ogc.common.interfaces,
com.raytheon.uf.edex.ogc.common.jaxb,
com.raytheon.uf.edex.ogc.common.level,
com.raytheon.uf.edex.ogc.common.output,
com.raytheon.uf.edex.ogc.common.soap,
com.raytheon.uf.edex.ogc.common.spatial,
com.raytheon.uf.edex.ogc.common.stats,
com.raytheon.uf.edex.ogc.common.time,
com.raytheon.uf.edex.ogc.common.util
Import-Package: com.raytheon.uf.common.convert,
com.raytheon.uf.common.localization,
javax.servlet,
javax.servlet.http,
org.apache.cxf.helpers

View file

@ -1,32 +0,0 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:wfs-soap="http://www.opengis.net/wfs/soap/2.0" xmlns:wsntw="http://docs.oasis-open.org/wsn/bw-2"
xmlns:wsntw-soap="http://docs.oasis-open.org/wsn/bw-2/soap"
xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
targetNamespace="http://wsn.edex.uf.raytheon.com" xmlns:tns="http://wsn.edex.uf.raytheon.com">
<!-- ============================ Bindings Section ================================ -->
<wsdl:import namespace="http://docs.oasis-open.org/wsn/bw-2"
location="http://docs.oasis-open.org/wsn/bw-2.wsdl" />
<wsdl:binding name="NotificationConsumerSOAPBinding"
type="wsntw:NotificationConsumer">
<soap:binding style="document"
transport="http://schemas.xmlsoap.org/soap/http" />
<wsdl:operation name="Notify">
<soap:operation soapAction="" style="document" />
<wsdl:input>
<soap:body use="literal" />
</wsdl:input>
<wsdl:output>
<soap:body use="literal" />
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<!-- ============================ Service Section ================================ -->
<wsdl:service name="wsn-consumer">
<wsdl:port name="wsn-SOAP-Port" binding="tns:NotificationConsumerSOAPBinding">
<soap:address location="http://0.0.0.0:8080/notify">http://0.0.0.0:8080/notify
</soap:address>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>

View file

@ -1,8 +0,0 @@
source.. = src/
output.. = bin/
bin.includes = .project,\
.classpath,\
META-INF/,\
build.properties,\
.,\
res/

View file

@ -1,34 +0,0 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<!--
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.
-->
<!--
Refer to edex/modes/README.txt for documentation
-->
<edexModes>
<mode name="request">
<!-- exclude OGC services -->
<exclude>.*ogc.*</exclude>
</mode>
<mode name="ingest">
<!-- exclude OGC services -->
<exclude>.*ogc.*</exclude>
</mode>
</edexModes>

View file

@ -1,22 +0,0 @@
@startuml
package "EDEX Common OGC" {
[Simple Dimension] as dim
[Simple Layer] as layer
[Abstract Layer Collector] as abscol
}
node "EDEX Data Plug-in Adapter" {
[Plug-in Dimension] as pdim
[Plug-in Layer] as player
[Plug-in Layer Collector] as collector
}
abscol <|-- collector
layer <|-- player
dim <|-- pdim
collector o-left- "*"player
player o-left- "*" pdim
@enduml

View file

@ -1,8 +0,0 @@
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd">
<bean id="ogcPatchConverter" class="com.raytheon.uf.edex.ogc.common.util.PatchConverter" >
</bean>
</beans>

View file

@ -1,15 +0,0 @@
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd">
<bean id="jsonFeatureFormatter" class="com.raytheon.uf.edex.ogc.common.feature.JsonFeatureFormatter" >
</bean>
<bean id="shapeFeatureFormatter" class="com.raytheon.uf.edex.ogc.common.feature.ShpFeatureFormatter" >
</bean>
<bean id="layerStore" class="com.raytheon.uf.edex.ogc.common.db.FsLayerStore">
<constructor-arg value="layerStore"/>
</bean>
</beans>

View file

@ -1,261 +0,0 @@
/**
* Copyright 09/24/12 Raytheon Company.
*
* Unlimited Rights
* This software was developed pursuant to Contract Number
* DTFAWA-10-D-00028 with the US Government. The US Governments rights
* in and to this copyrighted software are as specified in DFARS
* 252.227-7014 which was made part of the above contract.
*/
package com.raytheon.uf.edex.ogc.common;
import java.io.File;
import java.io.FileFilter;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStreamWriter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import org.apache.commons.collections.map.LRUMap;
import com.raytheon.uf.common.util.concurrent.KeyLock;
import com.raytheon.uf.common.util.concurrent.KeyLocker;
import com.raytheon.uf.edex.ogc.common.OgcException.Code;
/**
* Abstract base for file system backed query stores. Provides threadsafe
* list/store/delete operations.
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Feb 15, 2013 bclement Initial creation
* Nov 8, 2013 1314 bclement updated lock to use read/write
*
* </pre>
*
* @author bclement
* @version 1.0
*/
public abstract class AbstractFSQueryStore<T> extends AbstractFsStore {
/**
* @param storeLocation
*/
public AbstractFSQueryStore(File storeLocation) {
super(storeLocation);
}
@SuppressWarnings("unchecked")
private final Map<String, T> objCache = Collections
.synchronizedMap(new LRUMap(2));
@SuppressWarnings("unchecked")
private final Map<String, String> strCache = Collections
.synchronizedMap(new LRUMap(2));
private final KeyLocker<String> locker = new KeyLocker<String>();
/**
* @param id
* @param query
* @throws Exception
*/
public void store(String id, T query) throws OgcException {
KeyLock<String> lock = locker.getLock(id);
lock.lock();
try {
storeObject(id, query);
} finally {
lock.unlock();
}
}
/**
* This must be externally synchronized
*
* @param id
* @param query
* @throws Exception
*/
private void storeObject(String id, T query) throws OgcException {
objCache.put(id, query);
String xml = marshal(query);
storeString(id, xml);
}
protected abstract String marshal(T query) throws OgcException;
/**
* This must be externally synchronized
*
* @param id
* @param query
* @throws Exception
*/
private void storeString(String id, String query) throws OgcException {
OutputStreamWriter out = null;
strCache.put(id, query);
try {
File storage = getStorageFile(id);
out = new OutputStreamWriter(new FileOutputStream(storage));
out.write(query);
} catch (Exception e) {
throw new OgcException(Code.InternalServerError, e);
} finally {
if (out != null) {
try {
out.close();
} catch (IOException e) {
throw new OgcException(Code.InternalServerError, e);
}
}
}
}
/*
* (non-Javadoc)
*
* @see
* com.raytheon.uf.edex.wfs.querystore.QueryStore#retrieve(java.lang.String)
*/
public T retrieve(String id) throws OgcException {
T rval;
KeyLock<String> lock = locker.getLock(id);
lock.readLock();
try {
rval = retrieveObject(id);
} finally {
lock.readUnlock();
}
return rval;
}
/**
* This must be externally synchronized
*
* @param id
* @return
* @throws Exception
*/
private T retrieveObject(String id) throws OgcException {
T rval = objCache.get(id);
if (rval == null) {
String xml = retrieveStringInternal(id);
if (xml != null) {
rval = unmarshal(xml);
objCache.put(id, rval);
}
}
return rval;
}
/**
* This must be externally synchronized
*
* @param id
* @return
* @throws Exception
*/
private String retrieveStringInternal(String id) throws OgcException {
String rval = strCache.get(id);
if (rval == null) {
File storage = getStorageFile(id);
if (storage.exists()) {
InputStream in;
try {
in = new FileInputStream(storage);
} catch (FileNotFoundException e) {
throw new OgcException(Code.InternalServerError, e);
}
try {
rval = new java.util.Scanner(in).useDelimiter("\\A").next();
strCache.put(id, rval);
} finally {
try {
in.close();
} catch (IOException e) {
throw new OgcException(Code.InternalServerError, e);
}
}
}
}
return rval;
}
/**
* @param id
* @return
* @throws Exception
*/
protected String retrieveString(String id) throws OgcException {
KeyLock<String> lock = locker.getLock(id);
lock.readLock();
try {
return retrieveStringInternal(id);
} finally {
lock.readUnlock();
}
}
/*
* (non-Javadoc)
*
* @see
* com.raytheon.uf.edex.wfs.querystore.QueryStore#remove(java.lang.String)
*/
public void remove(String id) {
KeyLock<String> lock = locker.getLock(id);
lock.lock();
try {
objCache.remove(id);
strCache.remove(id);
File storage = getStorageFile(id);
if (storage.exists()) {
storage.delete();
}
} finally {
lock.unlock();
}
}
/**
* @return
* @throws Exception
*/
public List<String> list() throws OgcException {
// NOTE: this is only synched by the file system
File[] files = storeLocation.listFiles(new FileFilter() {
@Override
public boolean accept(File f) {
return f.isFile();
}
});
List<String> rval = new ArrayList<String>(files.length);
for (File f : files) {
String encoded = f.getName();
rval.add(decode(encoded));
}
return rval;
}
/**
* @param id
* @return file for storage
*/
protected File getStorageFile(String id) {
return new File(storeLocation, encode(id));
}
protected abstract T unmarshal(String xml) throws OgcException;
}

View file

@ -1,135 +0,0 @@
/**
* Copyright 09/24/12 Raytheon Company.
*
* Unlimited Rights
* This software was developed pursuant to Contract Number
* DTFAWA-10-D-00028 with the US Government. The US Governments rights
* in and to this copyrighted software are as specified in DFARS
* 252.227-7014 which was made part of the above contract.
*/
package com.raytheon.uf.edex.ogc.common;
import java.io.File;
import java.text.CharacterIterator;
import java.text.StringCharacterIterator;
import com.raytheon.uf.common.localization.IPathManager;
import com.raytheon.uf.common.localization.LocalizationContext;
import com.raytheon.uf.common.localization.PathManagerFactory;
/**
* Abstract File system storage. Provides basic storage location and id <-> file
* name encoding methods.
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Jun 4, 2013 bclement Initial creation
* Aug 18, 2013 #2097 dhladky Changed to configured
* October, 2012 #2472 dhladky/bclement Changed back to base
*
* </pre>
*
* @author bclement
* @version 1.0
*/
public class AbstractFsStore {
protected static final char ESCAPE = '%';
protected static final String SPECIAL_CHARS = ESCAPE + "./\\?*:|\"<>~";
protected final File storeLocation;
/**
* @param storeLocation
*/
public AbstractFsStore(File storeLocation) {
this.storeLocation = storeLocation;
ensureStorage();
}
protected static File findStore(String directoryName) {
IPathManager pathMgr = PathManagerFactory.getPathManager();
LocalizationContext context = pathMgr.getContext(
LocalizationContext.LocalizationType.EDEX_STATIC,
LocalizationContext.LocalizationLevel.BASE);
return pathMgr.getFile(context, directoryName);
}
/**
* Create storage location if necessary
*
* @throws IllegalArgumentException
* if unable to create storage directory or if provided location
* is not a directory
*/
private void ensureStorage() throws IllegalArgumentException {
if (!storeLocation.exists()) {
if (!storeLocation.mkdirs()) {
throw new IllegalArgumentException(
"Unable to create store directory: " + storeLocation);
}
}
if (!storeLocation.isDirectory()) {
throw new IllegalArgumentException(
"Provided storage location is not a directory: "
+ storeLocation);
}
if (!storeLocation.canWrite()) {
throw new IllegalArgumentException(
"Unable to write to storage directory: " + storeLocation);
}
}
/**
* Sanitize id for file system
*
* @param id
* @return
*/
protected static String encode(String id) {
StringBuilder sb = new StringBuilder();
CharacterIterator iter = new StringCharacterIterator(id);
for (char ch = iter.first(); ch != CharacterIterator.DONE; ch = iter
.next()) {
if (SPECIAL_CHARS.indexOf(ch) != -1) {
sb.append(ESCAPE);
sb.append(String.format("%2h", ch));
} else {
sb.append(ch);
}
}
return sb.toString();
}
/**
* de-sanitize file system name
*
* @param encoded
* @return
*/
protected static String decode(String encoded) {
StringBuilder sb = new StringBuilder();
int index = 0;
int prev;
while (index < encoded.length()) {
prev = index;
index = encoded.indexOf(ESCAPE, prev);
if (index < 0) {
sb.append(encoded.substring(prev));
break;
}
sb.append(encoded.substring(prev, index));
String hex = encoded.substring(index + 1, index + 3);
char charNum = (char) Integer.parseInt(hex, 16);
sb.append(charNum);
index = index + 3;
}
return sb.toString();
}
}

View file

@ -1,69 +0,0 @@
/**
* Copyright 09/24/12 Raytheon Company.
*
* Unlimited Rights
* This software was developed pursuant to Contract Number
* DTFAWA-10-D-00028 with the US Government. The US Governments rights
* in and to this copyrighted software are as specified in DFARS
* 252.227-7014 which was made part of the above contract.
*/
package com.raytheon.uf.edex.ogc.common;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
/**
* base source for OGC
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Jul 18, 2013 bclement Initial creation
*
* </pre>
*
* @author bclement
* @version 1.0
*/
public abstract class AbstractOgcSource {
private final Map<Class<?>, Object> extensionMap = new ConcurrentHashMap<Class<?>, Object>();
/*
* (non-Javadoc)
*
* @see com.raytheon.uf.edex.wfs.reg.WfsSource#getExtension(java.lang.Class)
*/
@SuppressWarnings("unchecked")
public <E> E getExtension(Class<E> c) {
E rval = (E) extensionMap.get(c);
if (rval == null) {
for (Class<?> key : extensionMap.keySet()) {
if (c.isAssignableFrom(key)) {
return (E) extensionMap.get(key);
}
}
}
return rval;
}
/**
* @param extension
*/
public void setExtension(Object extension) {
extensionMap.put(extension.getClass(), extension);
}
/**
* @param extensions
*/
public void setExtensions(Object[] extensions) {
for (Object obj : extensions) {
setExtension(obj);
}
}
}

View file

@ -1,192 +0,0 @@
/**
* Copyright 09/24/12 Raytheon Company.
*
* Unlimited Rights
* This software was developed pursuant to Contract Number
* DTFAWA-10-D-00028 with the US Government. The US Governments rights
* in and to this copyrighted software are as specified in DFARS
* 252.227-7014 which was made part of the above contract.
*/
package com.raytheon.uf.edex.ogc.common;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.LinkedList;
import java.util.List;
import javax.xml.bind.JAXBElement;
import net.opengis.ows.v_1_1_0.AllowedValues;
import net.opengis.ows.v_1_1_0.DCP;
import net.opengis.ows.v_1_1_0.DomainType;
import net.opengis.ows.v_1_1_0.HTTP;
import net.opengis.ows.v_1_1_0.ObjectFactory;
import net.opengis.ows.v_1_1_0.Operation;
import net.opengis.ows.v_1_1_0.OperationsMetadata;
import net.opengis.ows.v_1_1_0.RequestMethodType;
import net.opengis.ows.v_1_1_0.ValueType;
/**
* Abstract base for OGC operation descriptions. Provides common utility methods
* for populating OGC capabilities documents.
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* May 21, 2013 bclement Initial creation
*
* </pre>
*
* @author bclement
* @version 1.0
*/
public abstract class AbstractOpDescriber<T> {
protected ObjectFactory owsFactory = new ObjectFactory();
/**
* Get OWS operations metadata from service info
*
* @param serviceinfo
* @return
*/
public OperationsMetadata getOpData(OgcServiceInfo<T> serviceinfo) {
OperationsMetadata rval = new OperationsMetadata();
List<Operation> operations = new LinkedList<Operation>();
for (OgcOperationInfo<T> op : serviceinfo.getOperations()) {
Operation to = new Operation();
to.setName(op.getType().toString());
to.setDCP(getDcpList(op));
to.setParameter(getOpParams(op));
operations.add(to);
}
rval.setOperation(operations);
List<DomainType> params = getParams(serviceinfo);
if (params != null && !params.isEmpty()) {
rval.setParameter(params);
}
List<DomainType> constraints = getConstraints(serviceinfo);
if (constraints != null && !constraints.isEmpty()) {
rval.setConstraint(constraints);
}
Object extendedCapabilities = getExtendedCapabilities(serviceinfo);
if (extendedCapabilities != null) {
rval.setExtendedCapabilities(extendedCapabilities);
}
return rval;
}
/**
* @param serviceinfo
* @return
*/
protected Object getExtendedCapabilities(OgcServiceInfo<T> serviceinfo) {
return null;
}
/**
* @param serviceinfo
* @return
*/
protected List<DomainType> getConstraints(OgcServiceInfo<T> serviceinfo) {
return new ArrayList<DomainType>(0);
}
/**
* Get global parameters
*
* @param serviceinfo
* @return
*/
protected abstract List<DomainType> getParams(OgcServiceInfo<T> serviceinfo);
/**
* Get HTTP endpoint information for operation
*
* @param op
* @return
*/
protected List<DCP> getDcpList(OgcOperationInfo<T> op) {
List<DCP> rval = new LinkedList<DCP>();
DCP dcp = new DCP();
HTTP http = new HTTP();
List<JAXBElement<RequestMethodType>> value = new LinkedList<JAXBElement<RequestMethodType>>();
if (op.hasHttpGet()) {
RequestMethodType req = getRequestType(op.getHttpGetRes(), "KVP");
value.add(owsFactory.createHTTPGet(req));
}
if (op.hasHttpPost()) {
RequestMethodType req = getRequestType(op.getHttpPostRes(),
op.getPostEncoding());
value.add(owsFactory.createHTTPPost(req));
}
http.setGetOrPost(value);
dcp.setHTTP(http);
rval.add(dcp);
return rval;
}
/**
* Create request method object
*
* @param value
* @param postEncoding
* @return
*/
protected RequestMethodType getRequestType(String value, String postEncoding) {
RequestMethodType rval = owsFactory.createRequestMethodType();
rval.setHref(value);
rval.setConstraint(Arrays.asList(getAsDomainType("PostEncoding",
Arrays.asList(postEncoding))));
return rval;
}
/**
* Get parameters for operation
*
* @param op
* @return
*/
protected abstract List<DomainType> getOpParams(OgcOperationInfo<T> op);
/**
* Get keyed values as domain object
*
* @param name
* @param values
* @return
*/
protected DomainType getAsDomainType(String name, String... values) {
return getAsDomainType(name, Arrays.asList(values));
}
/**
* Get keyed values as domain object
*
* @param name
* @param values
* @return
*/
protected DomainType getAsDomainType(String name, Collection<String> values) {
DomainType rval = new DomainType();
rval.setName(name);
AllowedValues avs = new AllowedValues();
List<Object> toVals = new LinkedList<Object>();
for (String val : values) {
ValueType vt = new ValueType();
vt.setValue(val);
toVals.add(vt);
}
avs.setValueOrRange(toVals);
rval.setAllowedValues(avs);
return rval;
}
}

View file

@ -1,225 +0,0 @@
/**
* Copyright 09/24/12 Raytheon Company.
*
* Unlimited Rights
* This software was developed pursuant to Contract Number
* DTFAWA-10-D-00028 with the US Government. The US Governments rights
* in and to this copyrighted software are as specified in DFARS
* 252.227-7014 which was made part of the above contract.
*/
package com.raytheon.uf.edex.ogc.common;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.text.CharacterIterator;
import java.text.StringCharacterIterator;
import org.apache.cxf.helpers.IOUtils;
import com.raytheon.uf.common.localization.IPathManager;
import com.raytheon.uf.common.localization.LocalizationContext;
import com.raytheon.uf.common.localization.PathManagerFactory;
/**
* Basic file system storage. Overlaps functionality with AbstractFsStore.
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Mar 11, 2013 bclement Initial creation
* Aug 18, 2013 #2097 dhladky Moved to configured
*
* </pre>
*
* @author bclement
* @version 1.0
*/
public class BasicFileStore {
protected static final char ESCAPE = '%';
protected static final String SPECIAL_CHARS = ESCAPE + "./\\?*:|\"<>~";
private final Object fileMutex = new Object();
private final File storeLocation;
/**
* @param storeName
*/
public BasicFileStore(String storeName) {
this(findStore(storeName));
}
/**
* @param storeLocation
*/
public BasicFileStore(File storeLocation) {
this.storeLocation = storeLocation;
ensureStorage();
}
/**
* Create storage location if necessary
*
* @throws IllegalArgumentException
* if unable to create storage directory or if provided location
* is not a directory
*/
private void ensureStorage() throws IllegalArgumentException {
if (!storeLocation.exists()) {
if (!storeLocation.mkdirs()) {
throw new IllegalArgumentException(
"Unable to create store directory: " + storeLocation);
}
}
if (!storeLocation.isDirectory()) {
throw new IllegalArgumentException(
"Provided storage location is not a directory: "
+ storeLocation);
}
if (!storeLocation.canWrite()) {
throw new IllegalArgumentException(
"Unable to write to storage directory: " + storeLocation);
}
}
/**
* @param directoryName
* @return
*/
protected static File findStore(String directoryName) {
IPathManager pathMgr = PathManagerFactory.getPathManager();
LocalizationContext edexStaticCONFIGURED = pathMgr.getContext(
LocalizationContext.LocalizationType.EDEX_STATIC,
LocalizationContext.LocalizationLevel.CONFIGURED);
return pathMgr.getFile(edexStaticCONFIGURED, directoryName);
}
/**
* @param id
* @return
*/
private File createPath(String id) {
return new File(storeLocation, encode(id));
}
/**
* Get file from store
*
* @param id
* @return null if file isn't in store
*/
public File getFile(String id) {
File rval = createPath(id);
if (!rval.exists()) {
return null;
}
return rval;
}
/**
* Creates an empty file in store. This is used when data is written to the
* file outside of the store. This cannot be used with
* {@link #store(String, InputStream)}
*
* @param id
* @return
* @throws IOException
* if file already exists in store
*/
public File reserveFile(String id) throws IOException {
File f = createPath(id);
synchronized (fileMutex) {
if (!f.createNewFile()){
throw new IOException("File already exists in store with id: "
+ id);
}
}
return f;
}
/**
* Delete file from store
*
* @param id
*/
public void remove(String id) {
File f = createPath(id);
synchronized (fileMutex) {
if (f.exists()) {
f.delete();
}
}
}
/**
* Put data in store. This should not be used with
* {@link #reserveFile(String)}
*
* @param id
* @param in
* @throws IOException
*/
public void store(String id, InputStream in) throws IOException {
File f = reserveFile(id);
FileOutputStream out = new FileOutputStream(f);
try {
IOUtils.copy(in, out);
} finally {
out.close();
}
}
/**
* Sanitize id for file system
*
* @param id
* @return
*/
protected static String encode(String id) {
StringBuilder sb = new StringBuilder();
CharacterIterator iter = new StringCharacterIterator(id);
for (char ch = iter.first(); ch != CharacterIterator.DONE; ch = iter
.next()) {
if (SPECIAL_CHARS.indexOf(ch) != -1) {
sb.append(ESCAPE);
sb.append(String.format("%2h", ch));
} else {
sb.append(ch);
}
}
return sb.toString();
}
/**
* de-sanitize file system name
*
* @param encoded
* @return
*/
protected static String decode(String encoded) {
StringBuilder sb = new StringBuilder();
int index = 0;
int prev;
while (index < encoded.length()) {
prev = index;
index = encoded.indexOf(ESCAPE, prev);
if (index < 0) {
sb.append(encoded.substring(prev));
break;
}
sb.append(encoded.substring(prev, index));
String hex = encoded.substring(index + 1, index + 3);
char charNum = (char) Integer.parseInt(hex, 16);
sb.append(charNum);
index = index + 3;
}
return sb.toString();
}
}

View file

@ -1,50 +0,0 @@
/**
* Copyright 09/24/12 Raytheon Company.
*
* Unlimited Rights
* This software was developed pursuant to Contract Number
* DTFAWA-10-D-00028 with the US Government. The US Governments rights
* in and to this copyrighted software are as specified in DFARS
* 252.227-7014 which was made part of the above contract.
*/
package com.raytheon.uf.edex.ogc.common;
import java.util.List;
import com.raytheon.uf.common.dataplugin.PluginDataObject;
/**
* Callback interface used by stylers to have access to plugin metadata.
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Sep 30, 2013 bclement Initial creation
*
* </pre>
*
* @author bclement
* @version 1.0
*/
public interface IStyleLookupCallback<R extends PluginDataObject> {
/**
* @param layerName
* @return a sample data record that supports layer
* @throws OgcException
*/
public R lookupSample(String layerName) throws OgcException;
/**
* Return a list of samples for plugin. One sample per layer advertised by
* source.
*
* @return
* @throws OgcException
*/
public List<R> getAllSamples() throws OgcException;
}

View file

@ -1,61 +0,0 @@
/**
* Copyright 09/24/12 Raytheon Company.
*
* Unlimited Rights
* This software was developed pursuant to Contract Number
* DTFAWA-10-D-00028 with the US Government. The US Governments rights
* in and to this copyrighted software are as specified in DFARS
* 252.227-7014 which was made part of the above contract.
*/
package com.raytheon.uf.edex.ogc.common;
/**
* Exception thrown when parsing version numbers
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Oct 26, 2012 bclement Initial creation
*
* </pre>
*
* @author bclement
* @version 1.0
*/
public class InvalidVersionException extends Exception {
private static final long serialVersionUID = -7212986504698593811L;
/**
*
*/
public InvalidVersionException() {
}
/**
* @param message
*/
public InvalidVersionException(String message) {
super(message);
}
/**
* @param cause
*/
public InvalidVersionException(Throwable cause) {
super(cause);
}
/**
* @param message
* @param cause
*/
public InvalidVersionException(String message, Throwable cause) {
super(message, cause);
}
}

View file

@ -1,98 +0,0 @@
/**
* 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.edex.ogc.common;
import com.vividsolutions.jts.geom.Envelope;
/**
* Bounding box with arbitrary CRS that also stored resolution information.
* Should be replaced with GridGeometry2D.
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* 2011 bclement Initial creation
*
* </pre>
*
* @author bclement
* @version 1.0
*/
public class OgcBoundingBox extends OgcGeoBoundingBox {
protected String crs;
protected double resx = Double.NaN;
protected double resy = Double.NaN;
public OgcBoundingBox() {
}
public OgcBoundingBox(String crs, double minx, double maxx, double miny,
double maxy, double resx, double resy) {
this(crs, minx, maxx, miny, maxy);
this.resx = resx;
this.resy = resy;
}
public OgcBoundingBox(String crs, double minx, double maxx, double miny,
double maxy) {
super(maxx, minx, maxy, miny);
this.crs = crs;
}
/**
* @param targetCrs
* @param env
*/
public OgcBoundingBox(String crs, Envelope env) {
super(env);
this.crs = crs;
}
public String getCrs() {
return crs;
}
public void setCrs(String crs) {
this.crs = crs;
}
public double getResx() {
return resx;
}
public void setResx(double resx) {
this.resx = resx;
}
public double getResy() {
return resy;
}
public void setResy(double resy) {
this.resy = resy;
}
}

View file

@ -1,155 +0,0 @@
/**
* 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.edex.ogc.common;
import java.util.List;
/**
* Contains dimension metadata used to populate capability and description OGC
* documents. Separate from OGC JAXB objects to support different versions of
* OGC services.
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* 2011 bclement Initial creation
*
* </pre>
*
* @author bclement
* @version 1.0
*/
public class OgcDimension {
protected String name;
protected String units;
protected String unitSymbol;
protected List<String> values;
protected String defaultVal;
/**
*
*/
public OgcDimension() {
}
public OgcDimension(String name, List<String> values) {
this(name, "", values);
}
public OgcDimension(String name, String units, List<String> values) {
this(name, units, null, values);
}
public OgcDimension(String name, String units, String unitSymbol,
List<String> values) {
this.name = name;
this.units = units;
this.unitSymbol = unitSymbol;
this.values = values;
}
/**
* @return the name
*/
public String getName() {
return name;
}
/**
* @param name
* the name to set
*/
public void setName(String name) {
this.name = name;
}
/**
* @return the units
*/
public String getUnits() {
return units;
}
/**
* @param units
* the units to set
*/
public void setUnits(String units) {
this.units = units;
}
/**
* @return the unitSymbol
*/
public String getUnitSymbol() {
return unitSymbol;
}
/**
* @param unitSymbol
* the unitSymbol to set
*/
public void setUnitSymbol(String unitSymbol) {
this.unitSymbol = unitSymbol;
}
/**
* @return the values
*/
public List<String> getValues() {
return values;
}
/**
* @param values
* the values to set
*/
public void setValues(List<String> values) {
this.values = values;
}
/**
* @return the defaultVal
*/
public String getDefaultVal() {
return defaultVal;
}
/**
* @param defaultVal
* the defaultVal to set
*/
public void setDefaultVal(String defaultVal) {
this.defaultVal = defaultVal;
}
}

View file

@ -1,77 +0,0 @@
/**
* 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.edex.ogc.common;
/**
* Exception class containing OGC specific error codes.
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* 2011 bclement Initial creation
*
* </pre>
*
* @author bclement
* @version 1.0
*/
public class OgcException extends Exception {
private static final long serialVersionUID = -5832661027013919871L;
public enum Code {
InvalidFormat, InvalidCRS, LayerNotDefined, MissingDimensionValue, InvalidDimensionValue, OperationNotSupported, MissingParameterValue, InvalidParameterValue, InternalServerError, InvalidRequest, VersionNegotiationFailed
}
protected Code code;
public OgcException(Code code) {
super();
this.code = code;
}
public OgcException(Code code, String message) {
super(message);
this.code = code;
}
public OgcException(Code code, Throwable cause) {
super(cause);
this.code = code;
}
public OgcException(Code code, String message, Throwable cause) {
super(message, cause);
this.code = code;
}
public Code getCode() {
return code;
}
public void setCode(Code code) {
this.code = code;
}
}

View file

@ -1,165 +0,0 @@
/**
* 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.edex.ogc.common;
import org.opengis.referencing.crs.CoordinateReferenceSystem;
import com.vividsolutions.jts.geom.Coordinate;
import com.vividsolutions.jts.geom.Envelope;
import com.vividsolutions.jts.geom.Geometry;
import com.vividsolutions.jts.geom.Polygon;
/**
* Contains CRS:84 longitudes and latitudes for OGC metadata. Should be replaced
* with ReferencedEnvelope.
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* 2011 bclement Initial creation
*
* </pre>
*
* @author bclement
* @version 1.0
*/
public class OgcGeoBoundingBox {
protected double maxx;
protected double minx;
protected double maxy;
protected double miny;
/**
*
*/
public OgcGeoBoundingBox() {
}
public OgcGeoBoundingBox(double eastLongitude, double westLongitude,
double northLatitude, double southLatitude) {
super();
this.maxx = eastLongitude;
this.minx = westLongitude;
this.maxy = northLatitude;
this.miny = southLatitude;
}
public OgcGeoBoundingBox(Polygon polygon, CoordinateReferenceSystem crs) {
Geometry env = polygon.getEnvelope();
Coordinate[] coords = env.getCoordinates();
Coordinate ur = coords[2];
Coordinate ll = coords[0];
this.maxx = ur.x;
this.minx = ll.x;
this.maxy = ur.y;
this.miny = ll.y;
}
public OgcGeoBoundingBox(Envelope env) {
this.maxx = env.getMaxX();
this.maxy = env.getMaxY();
this.minx = env.getMinX();
this.miny = env.getMinY();
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
long temp;
temp = Double.doubleToLongBits(maxx);
result = prime * result + (int) (temp ^ (temp >>> 32));
temp = Double.doubleToLongBits(maxy);
result = prime * result + (int) (temp ^ (temp >>> 32));
temp = Double.doubleToLongBits(miny);
result = prime * result + (int) (temp ^ (temp >>> 32));
temp = Double.doubleToLongBits(minx);
result = prime * result + (int) (temp ^ (temp >>> 32));
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
OgcGeoBoundingBox other = (OgcGeoBoundingBox) obj;
if (Double.doubleToLongBits(maxx) != Double
.doubleToLongBits(other.maxx))
return false;
if (Double.doubleToLongBits(maxy) != Double
.doubleToLongBits(other.maxy))
return false;
if (Double.doubleToLongBits(miny) != Double
.doubleToLongBits(other.miny))
return false;
if (Double.doubleToLongBits(minx) != Double
.doubleToLongBits(other.minx))
return false;
return true;
}
public double getMaxx() {
return maxx;
}
public void setMaxx(double maxx) {
this.maxx = maxx;
}
public double getMinx() {
return minx;
}
public void setMinx(double minx) {
this.minx = minx;
}
public double getMaxy() {
return maxy;
}
public void setMaxy(double maxy) {
this.maxy = maxy;
}
public double getMiny() {
return miny;
}
public void setMiny(double miny) {
this.miny = miny;
}
}

View file

@ -1,310 +0,0 @@
/**
* 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.edex.ogc.common;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.lang3.StringUtils;
/**
* Contains layer metadata used to populate capability and description OGC
* documents. Separate from OGC JAXB objects to support different versions of
* OGC services.
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* 2011 bclement Initial creation
*
* </pre>
*
* @author bclement
* @version 1.0
*/
public class OgcLayer {
protected OgcLayer parent;
protected List<OgcLayer> children;
protected String name;
protected String title;
protected List<String> keywords;
protected String abs;
protected List<OgcStyle> styles;
protected OgcGeoBoundingBox geoBoundingBox;
protected List<OgcBoundingBox> boundingBox;
protected List<String> crs;
protected double minScaleDenom = Double.NaN;
protected double maxScaleDenom = Double.NaN;
protected boolean opaque;
protected int sizeRecord = 0;
protected List<OgcDimension> dimensions;
public static String keySeparator = "/";
public void addCRS(String crs) {
this.crs = addToList(this.crs, crs);
}
protected <T> List<T> addToList(List<T> l, T item) {
if (l == null) {
l = new ArrayList<T>();
}
l.add(item);
return l;
}
public void addBoundingBox(OgcBoundingBox bbox) {
this.boundingBox = addToList(boundingBox, bbox);
}
public void addStyle(OgcStyle style) {
this.styles = addToList(styles, style);
}
public void addChildLayer(OgcLayer child) {
this.children = addToList(children, child);
}
public void addDimension(OgcDimension dimention) {
this.dimensions = addToList(dimensions, dimention);
}
public void addKeyword(String keyword) {
this.keywords = addToList(keywords, keyword);
}
public String getKey() {
return getKey(name);
}
public String[] separateKey() {
return separateKey(name);
}
/**
* @return the unique key for the source of the layer
*/
public static String getKey(String layerName) {
if (layerName == null) {
return null;
}
return separateKey(layerName)[0];
}
public static String decodeLayerName(String layerName) {
if (layerName == null) {
return null;
}
try {
return URLDecoder.decode(layerName, "UTF-8");
} catch (UnsupportedEncodingException e) {
throw new RuntimeException(e);
}
}
public static String[] separateKey(String layerName) {
String lname = decodeLayerName(layerName);
if (lname == null) {
return null;
}
lname = StringUtils.strip(lname, OgcLayer.keySeparator);
return lname.split(OgcLayer.keySeparator, 2);
}
public String getFullTitle() {
return getKey() + keySeparator + title;
}
public static String createName(String key, String name) {
try {
return URLEncoder.encode(key + keySeparator + name, "UTF-8");
} catch (UnsupportedEncodingException e) {
throw new RuntimeException(e);
}
}
/**
* @return the dimentions
*/
public List<OgcDimension> getDimensions() {
return dimensions;
}
/**
* @param dimensions
* the dimentions to set
*/
public void setDimensions(List<OgcDimension> dimensions) {
this.dimensions = dimensions;
}
public OgcLayer getParent() {
return parent;
}
public void setParent(OgcLayer parent) {
this.parent = parent;
}
public List<OgcLayer> getChildren() {
return children;
}
public void setChildren(List<OgcLayer> children) {
this.children = children;
}
public List<OgcStyle> getStyles() {
return styles;
}
public void setStyles(List<OgcStyle> styles) {
this.styles = styles;
}
/**
* @return the geoBoundingBox
*/
public OgcGeoBoundingBox getGeoBoundingBox() {
return geoBoundingBox;
}
/**
* @param geoBoundingBox
* the geoBoundingBox to set
*/
public void setGeoBoundingBox(OgcGeoBoundingBox geoBoundingBox) {
this.geoBoundingBox = geoBoundingBox;
}
public List<String> getCrs() {
return crs;
}
public void setCrs(List<String> crs) {
this.crs = crs;
}
/**
* @return the boundingBox
*/
public List<OgcBoundingBox> getBoundingBox() {
return boundingBox;
}
/**
* @param boundingBox
* the boundingBox to set
*/
public void setBoundingBox(List<OgcBoundingBox> boundingBox) {
this.boundingBox = boundingBox;
}
public double getMinScaleDenom() {
return minScaleDenom;
}
public void setMinScaleDenom(double minScaleDenom) {
this.minScaleDenom = minScaleDenom;
}
public double getMaxScaleDenom() {
return maxScaleDenom;
}
public void setMaxScaleDenom(double maxScaleDenom) {
this.maxScaleDenom = maxScaleDenom;
}
public boolean isOpaque() {
return opaque;
}
public void setOpaque(boolean opaque) {
this.opaque = opaque;
}
public String getName() {
return name;
}
/**
* @param key
* a key that is used in all layers from the layer's source
* @param name
*/
public void setName(String key, String name) {
this.name = createName(key, name);
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public List<String> getKeywords() {
return keywords;
}
public void setKeywords(List<String> keywords) {
this.keywords = keywords;
}
public String getAbs() {
return abs;
}
public void setAbs(String abs) {
this.abs = abs;
}
public int getSizeRecord() {
return sizeRecord;
}
public void setSizeRecord(int sizeRecord) {
this.sizeRecord = sizeRecord;
}
}

View file

@ -1,115 +0,0 @@
/**
* 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.edex.ogc.common;
/**
* Static constants for OGC related XML namespaces
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* 2011 bclement Initial creation
*
* </pre>
*
* @author bclement
* @version 1.0
*/
public class OgcNamespace {
public static final String GML = "http://www.opengis.net/gml";
public static final String ISM = "urn:us:gov:ic:ism:v2";
public static final String OGC = "http://www.opengis.net/ogc";
public static final String OM100 = "http://www.opengis.net/om/1.0";
public static final String OWS110 = "http://www.opengis.net/ows/1.1";
public static final String OWS = "http://www.opengis.net/ows";
public static final String Sampling100 = "http://www.opengis.net/sampling/1.0";
public static final String SMIL = "http://www.w3.org/2001/SMIL20/";
public static final String SMIL_LANG = "http://www.w3.org/2001/SMIL20/Language";
public static final String SensorML101 = "http://www.opengis.net/sensorML/1.0.1";
public static final String SOS100 = "http://www.opengis.net/sos/1.0";
public static final String SWE101 = "http://www.opengis.net/swe/1.0.1";
public static final String TML = "http://www.opengis.net/tml";
public static final String XLINK = "http://www.w3.org/1999/xlink";
public static final String XSI = "http://www.w3.org/2001/XMLSchema-instance";
public static final String WCS111 = "http://www.opengis.net/wcs/1.1.1";
public static final String WCS112 = "http://www.opengis.net/wcs/1.1.2";
public static final String WCS11 = "http://www.opengis.net/wcs/1.1";
public static final String WMS = "http://www.opengis.net/wms";
public static final String WFS = "http://www.opengis.net/wfs";
public static final String EDEX = "http://edex.uf.raytheon.com";
public static final String SLD = "http://www.opengis.net/sld";
public static final String SE = "http://www.opengis.net/se";
public static final String WMTS100 = "http://www.opengis.net/wmts/1.0";
public static final String WFS20 = "http://www.opengis.net/wfs/2.0";
public static final String FES20 = "http://www.opengis.net/fes/2.0";
public static final String GML32 = "http://www.opengis.net/gml/3.2";
public static final String SWE_GML32 = "http://www.opengis.net/swe/1.0/gml32";
public static final String AVWX11 = "http://www.eurocontrol.int/avwx/1.1";
public static final String OM_GML32 = "http://www.opengis.net/om/1.0/gml32";
public static final String SML_GML32 = "http://www.opengis.net/sensorML/1.0/gml32";
public static final String WX = "http://www.eurocontrol.int/wx/1.1";
public static final String WSNT = "http://docs.oasis-open.org/wsn/b-2";
public static final String WSA = "http://www.w3.org/2005/08/addressing";
public static final String OWSNT = "http://www.opengis.net/owsnt/1.1";
public static final String NAWX15 = "http://www.faa.gov/nawx/1.5";
}

View file

@ -1,247 +0,0 @@
/**
* 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.edex.ogc.common;
import java.util.LinkedList;
import java.util.List;
/**
* Contains operations metadata used to populated OGC capabilities documents.
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* 2011 bclement Initial creation
*
* </pre>
*
* @author bclement
* @version 1.0
* @param <T>
*/
public class OgcOperationInfo<T> {
protected T type;
protected String httpPostRes;
protected String httpGetRes;
protected String postEncoding;
protected String httpBaseHostname;
protected List<String> formats = new LinkedList<String>();
protected List<String> versions = new LinkedList<String>();
protected List<String> acceptversions = new LinkedList<String>();
protected List<String> services = new LinkedList<String>();
protected List<String> identifiers = new LinkedList<String>();
protected List<String> interpolationtypes = new LinkedList<String>();
/**
*
*/
public OgcOperationInfo(T type) {
this.type = type;
}
public OgcOperationInfo(T type, String httpPostRes, String httpGetRes,
String httpBaseHostname) {
this(type);
this.httpGetRes = httpGetRes;
this.httpPostRes = httpPostRes;
this.httpBaseHostname = httpBaseHostname;
}
public void addFormat(String format) {
formats.add(format);
}
public void addVersion(String version) {
versions.add(version);
}
public void addAcceptVersions(String version) {
acceptversions.add(version);
}
public void addService(String service) {
services.add(service);
}
public void addIdentifier(String identifier) {
identifiers.add(identifier);
}
public void addInterpolationType(String interpolationtype) {
interpolationtypes.add(interpolationtype);
}
public boolean hasHttpPost() {
return httpPostRes != null;
}
public boolean hasHttpGet() {
return httpGetRes != null;
}
/**
* @return the httpPostRes
*/
public String getHttpPostRes() {
return httpPostRes;
}
/**
* @param httpPostRes
* the httpPostRes to set
*/
public void setHttpPostRes(String httpPostRes) {
this.httpPostRes = httpPostRes;
}
/**
* @return the httpGetRes
*/
public String getHttpGetRes() {
return httpGetRes;
}
/**
* @param httpGetRes
* the httpGetRes to set
*/
public void setHttpGetRes(String httpGetRes) {
this.httpGetRes = httpGetRes;
}
/**
* @return the type
*/
public T getType() {
return type;
}
/**
* @param type
* the type to set
*/
public void setType(T type) {
this.type = type;
}
/**
* @return the formats
*/
public List<String> getFormats() {
return formats;
}
/**
* @param formats
* the formats to set
*/
public void setFormats(List<String> formats) {
this.formats = formats;
}
/**
* @return the versions
*/
public List<String> getVersions() {
return versions;
}
/**
* @param versions
* the versions to set
*/
public void setVersions(List<String> versions) {
this.versions = versions;
}
public List<String> getAcceptversions() {
return acceptversions;
}
public void setAcceptversions(List<String> acceptversions) {
this.acceptversions = acceptversions;
}
public List<String> getServices() {
return services;
}
public void setServices(List<String> services) {
this.services = services;
}
public List<String> getIdentifiers() {
return identifiers;
}
public void setIdentifiers(List<String> identifiers) {
this.identifiers = identifiers;
}
public List<String> getInterpolationtypes() {
return interpolationtypes;
}
public void setInterpolationtypes(List<String> interpolationtypes) {
this.interpolationtypes = interpolationtypes;
}
/**
* @return the postEncoding
*/
public String getPostEncoding() {
return postEncoding;
}
/**
* @param postEncoding
* the postEncoding to set
*/
public void setPostEncoding(String postEncoding) {
this.postEncoding = postEncoding;
}
public String getHttpBaseHostname() {
return httpBaseHostname;
}
public void setHttpBaseHostname(String httpBaseHostname) {
this.httpBaseHostname = httpBaseHostname;
}
}

View file

@ -1,135 +0,0 @@
/**
* 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.edex.ogc.common;
/**
* Static constants for OGC related XML namespace prefixes
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* 2011 bclement Initial creation
*
* </pre>
*
* @author bclement
* @version 1.0
*/
public class OgcPrefix {
/**
* Geography Markup Language
*/
public static final String GML = "gml";
public static final String ISM = "icism";
/**
* Open Geospatial Consortium
*/
public static final String OGC = "ogc";
/**
* Observations & Measurements
*/
public static final String OM = "om";
public static final String OWS = "ows";
/**
* Sampling
*/
public static final String Sampling = "sa";
/**
* Synchronized Multimedia Integration Language
*/
public static final String SMIL = "smil";
/**
* Synchronized Multimedia Integration Language
*/
public static final String SMIL_LANG = "smilLang";
/**
* Sensor Markup Language
*/
public static final String SensorML = "sml";
/**
* Sensor Observation Service
*/
public static final String SOS = "sos";
/**
* Sensor Web Enablement
*/
public static final String SWE = "swe";
/**
* Transducer Markup Language
*/
public static final String TML = "tml";
/**
* XML Linking Language
*/
public static final String XLINK = "xlink";
/**
* XML Schema Instance
*/
public static final String XSI = "xsi";
public static final String WCS = "wcs";
public static final String WMS = "wms";
public static final String WFS = "wfs";
public static final String WMTS = "wmts";
public static final String EDEX = "edex";
public static final String SLD = "sld";
public static final String SE = "se";
public static final String WX = "wx";
public static final String AVWX = "avwx";
public static final String FES = "fes";
public static final String WSNT = "wsn-b";
public static final String WSA = "wsa";
public static final String OWSNT = "owsnt";
public static final String NAWX = "nawx";
}

View file

@ -1,143 +0,0 @@
/**
* 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.edex.ogc.common;
import com.raytheon.uf.common.http.MimeType;
/**
* Response wrapper for OGC web services
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* 2011 bclement Initial creation
*
* </pre>
*
* @author bclement
* @version 1.0
*/
public class OgcResponse {
public static final MimeType TEXT_XML_MIME = new MimeType("text/xml");
public static final MimeType TEXT_HTML_MIME = new MimeType("text/html");
public static final MimeType APP_VND_OGC_SE_XML = new MimeType(
"application/vnd.ogc.se_xml");
public enum TYPE {
TEXT, IMAGE, BYTE, MULTIPART
};
public enum ErrorType {
NONE, BAD_REQ, INT_ERR, NOT_IMPLEMENTED
};
protected MimeType mimetype;
protected Object body;
protected boolean multipart = false;
protected TYPE type;
protected ErrorType error = ErrorType.NONE;
private MimeType exceptionFormat = OgcResponse.TEXT_XML_MIME;
public OgcResponse(Object body, MimeType mimetype, TYPE type) {
this.body = body;
this.mimetype = mimetype;
this.type = type;
}
public MimeType getMimetype() {
return mimetype;
}
public void setMimetype(MimeType mimetype) {
this.mimetype = mimetype;
}
public Object getBody() {
return body;
}
public void setBody(Object body) {
this.body = body;
}
public boolean isMultipart() {
return multipart;
}
public void setMultipart(boolean multipart) {
this.multipart = multipart;
}
/**
* @param exceptionFormat
* the exceptionFormat to set
*/
public void setExceptionFormat(MimeType exceptionFormat) {
this.exceptionFormat = exceptionFormat;
}
/**
* @return the exceptionFormat
*/
public MimeType getExceptionFormat() {
return exceptionFormat;
}
/**
* @return the type
*/
public TYPE getType() {
return type;
}
/**
* @param type
* the type to set
*/
public void setType(TYPE type) {
this.type = type;
}
/**
* @return the error
*/
public ErrorType getError() {
return error;
}
/**
* @param error
* the error to set
*/
public void setError(ErrorType error) {
this.error = error;
}
}

View file

@ -1,92 +0,0 @@
/**
* 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.edex.ogc.common;
import java.util.LinkedList;
import java.util.List;
/**
* Contains services metadata used to populated OGC capabilities documents.
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* 2011 bclement Initial creation
*
* </pre>
*
* @author bclement
* @version 1.0
* @param <T>
*/
public class OgcServiceInfo<T> {
protected String onlineResource;
protected List<OgcOperationInfo<T>> operations = new LinkedList<OgcOperationInfo<T>>();
/**
*
*/
public OgcServiceInfo(String onlineResouce) {
this.onlineResource = onlineResouce;
}
public void addOperationInfo(OgcOperationInfo<T> info) {
operations.add(info);
}
/**
* @return the onlineResource
*/
public String getOnlineResource() {
return onlineResource;
}
/**
* @param onlineResource
* the onlineResource to set
*/
public void setOnlineResource(String onlineResource) {
this.onlineResource = onlineResource;
}
/**
* @return the operations
*/
public List<OgcOperationInfo<T>> getOperations() {
return operations;
}
/**
* @param operations
* the operations to set
*/
public void setOperations(List<OgcOperationInfo<T>> operations) {
this.operations = operations;
}
}

View file

@ -1,123 +0,0 @@
/**
* 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.edex.ogc.common;
/**
* Contains style metadata used to populate capability and description OGC
* documents. Separate from OGC JAXB objects to support different versions of
* OGC services.
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* 2011 bclement Initial creation
*
* </pre>
*
* @author bclement
* @version 1.0
*/
public class OgcStyle {
protected String name;
protected String title;
protected String abs;
protected String legendUrl;
protected boolean isDefault = false;
public OgcStyle() {
}
public OgcStyle(String name, String title, String abs) {
this.name = name;
this.title = title;
this.abs = abs;
}
public OgcStyle(String name, String title) {
this(name, title, null);
}
public OgcStyle(String name) {
this(name, null, null);
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getAbs() {
return abs;
}
public void setAbs(String abs) {
this.abs = abs;
}
/**
* @return the legendUrl
*/
public String getLegendUrl() {
return legendUrl;
}
/**
* @param legendUrl
* the legendUrl to set
*/
public void setLegendUrl(String legendUrl) {
this.legendUrl = legendUrl;
}
/**
* @return the isDefault
*/
public boolean isDefault() {
return isDefault;
}
/**
* @param isDefault
* the isDefault to set
*/
public void setDefault(boolean isDefault) {
this.isDefault = isDefault;
}
}

View file

@ -1,68 +0,0 @@
/**
* 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.edex.ogc.common;
import java.util.Date;
/**
* OGC Time Range
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* May 18, 2013 753 dhladky Initial creation
*
* </pre>
*
* @author dhladky
* @version 1.0
*/
public class OgcTimeRange {
protected Date startTime;
protected Date endTime;
public OgcTimeRange(Date startTime, Date endTime) {
this.startTime = startTime;
this.endTime = endTime;
}
public Date getStartTime() {
return startTime;
}
public void setStartTime(Date startTime) {
this.startTime = startTime;
}
public Date getEndTime() {
return endTime;
}
public void setEndTime(Date endTime) {
this.endTime = endTime;
}
}

View file

@ -1,98 +0,0 @@
/**
* Copyright 09/24/12 Raytheon Company.
*
* Unlimited Rights
* This software was developed pursuant to Contract Number
* DTFAWA-10-D-00028 with the US Government. The US Governments rights
* in and to this copyrighted software are as specified in DFARS
* 252.227-7014 which was made part of the above contract.
*/
package com.raytheon.uf.edex.ogc.common;
import java.util.Iterator;
/**
* Iterator that allows peeking at the next item without progressing
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Apr 29, 2013 bclement Initial creation
*
* </pre>
*
* @author bclement
* @version 1.0
*/
public class PeekingIterator<T> implements Iterator<T> {
private final Iterator<T> iter;
private T next;
private boolean dirty = false;
/**
* @param iter
*/
public PeekingIterator(Iterator<T> iter) {
this.iter = iter;
}
/*
* (non-Javadoc)
*
* @see java.util.Iterator#hasNext()
*/
@Override
public boolean hasNext() {
if (dirty) {
return true;
}
return iter.hasNext();
}
/*
* (non-Javadoc)
*
* @see java.util.Iterator#next()
*/
@Override
public T next() {
if (dirty) {
dirty = false;
return next;
}
return iter.next();
}
/**
* Look at next item without progressing. Will return the same item until
* {@link PeekingIterator#next()} is called.
*
* {@link PeekingIterator#hasNext()} should be called beforehand.
*
* @return
*/
public T peek(){
if (dirty){
return next;
}
next = iter.next();
dirty = true;
return next;
}
/**
* Unsupported. Throws {@link UnsupportedOperationException}
*/
@Override
public void remove() {
throw new UnsupportedOperationException(
"remove not supported on peeking iterator");
}
}

View file

@ -1,56 +0,0 @@
/**
* 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.edex.ogc.common;
import java.util.List;
/**
* Styling interface for retrieving style information for layers
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Mar 29, 2012 bclement Initial creation
*
* </pre>
*
* @author bclement
* @version 1.0
*/
public interface StyleLookup {
/**
* @param layername
* @return the name of the default style for layer
*/
public String lookup(String layername);
/**
* @return all styles
*/
public List<OgcStyle> getStyles();
public void setLoader(ClassLoader loader);
}

View file

@ -1,244 +0,0 @@
/**
* 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.edex.ogc.common;
import java.io.Serializable;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import com.raytheon.uf.common.serialization.annotations.DynamicSerialize;
import com.raytheon.uf.common.serialization.annotations.DynamicSerializeElement;
/**
* Version object to track versions of OGC services
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* 2011 bclement Initial creation
*
* </pre>
*
* @author bclement
* @version 1.0
*/
@XmlAccessorType(XmlAccessType.NONE)
@DynamicSerialize
public class Version implements Comparable<Version>, Serializable {
private transient static final long serialVersionUID = -7496995218051649871L;
@DynamicSerializeElement
@XmlAttribute
protected int major = 0;
@DynamicSerializeElement
@XmlAttribute
protected int minor = 0;
@DynamicSerializeElement
@XmlAttribute
protected int micro = 0;
@DynamicSerializeElement
@XmlAttribute
protected String qualifier;
protected transient Pattern pattern = Pattern
.compile("^([0-9]+)(\\.([0-9]+)(\\.([0-9]+)(\\.([^\\.,]+))?)?)?$");
public Version() {
}
public Version(Version pv) {
this(pv.major, pv.minor, pv.micro, pv.qualifier);
}
public Version(int major, int minor, int micro) {
this(major, minor, micro, null);
}
public Version(int major, int minor, int micro, String qualifier) {
this.major = major;
this.micro = micro;
this.minor = minor;
this.qualifier = qualifier;
}
public Version(String version) throws InvalidVersionException {
fromString(version);
}
protected void fromString(String version) throws InvalidVersionException {
Matcher m = pattern.matcher(version.trim());
if (m.matches()) {
major = parseInt(m.group(1));
minor = parseInt(m.group(3));
micro = parseInt(m.group(5));
qualifier = m.group(7);
} else {
throw new InvalidVersionException("Invalid version string: '"
+ version + "'");
}
}
public Version majorMinorOnly() {
return new Version(this.major, this.minor, 0);
}
protected int parseInt(String str) {
int rval = 0;
if (str != null) {
rval = Integer.parseInt(str);
}
return rval;
}
public int getMajor() {
return major;
}
public void setMajor(int major) {
this.major = major;
}
public int getMinor() {
return minor;
}
public void setMinor(int minor) {
this.minor = minor;
}
public int getMicro() {
return micro;
}
public void setMicro(int micro) {
this.micro = micro;
}
public String getQualifier() {
return qualifier;
}
public void setQualifier(String qualifier) {
this.qualifier = qualifier;
}
public String toString() {
String rval = String.format("%d.%d.%d", major, minor, micro);
if (this.qualifier != null && !this.qualifier.isEmpty()) {
rval += "." + qualifier;
}
return rval;
}
@Override
public int compareTo(Version o) {
if (o == null) {
return 1;
}
if (o == this) {
return 0;
}
int res = major - o.major;
if (res != 0) {
return res;
}
res = minor - o.minor;
if (res != 0) {
return res;
}
res = micro - o.micro;
if (res != 0) {
return res;
}
if (qualifier == null) {
if (o.qualifier != null) {
return -1;
}
} else if (o.qualifier == null) {
return 1;
} else {
return qualifier.compareTo(o.qualifier);
}
return 0;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + major;
result = prime * result + micro;
result = prime * result + minor;
result = prime * result
+ ((qualifier == null) ? 0 : qualifier.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Version other = (Version) obj;
if (major != other.major)
return false;
if (micro != other.micro)
return false;
if (minor != other.minor)
return false;
if (qualifier == null) {
if (other.qualifier != null)
return false;
} else if (!qualifier.equals(other.qualifier))
return false;
return true;
}
/**
* @param other
* @return true if this and other have the same major and minor versions
*/
public boolean equalsMajorMinor(Version other) {
if (other == null) {
return false;
}
if (major != other.major)
return false;
if (minor != other.minor)
return false;
return true;
}
}

View file

@ -1,37 +0,0 @@
/**
* Copyright 09/24/12 Raytheon Company.
*
* Unlimited Rights
* This software was developed pursuant to Contract Number
* DTFAWA-10-D-00028 with the US Government. The US Governments rights
* in and to this copyrighted software are as specified in DFARS
* 252.227-7014 which was made part of the above contract.
*/
package com.raytheon.uf.edex.ogc.common.db;
import com.raytheon.uf.common.dataplugin.PluginDataObject;
/**
* Factory for creating collector addons
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Jul 18, 2013 bclement Initial creation
*
* </pre>
*
* @author bclement
* @version 1.0
*/
public interface CollectorAddonFactory<D extends SimpleDimension, L extends SimpleLayer<D>, R extends PluginDataObject> {
/**
* @return new instance of collector addon
*/
public ICollectorAddon<D, L, R> create();
}

View file

@ -1,226 +0,0 @@
/**
* 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.edex.ogc.common.db;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.TreeSet;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;
import com.raytheon.uf.common.dataplugin.PluginDataObject;
import com.raytheon.uf.common.status.IUFStatusHandler;
import com.raytheon.uf.common.status.UFStatus;
import com.raytheon.uf.edex.database.DataAccessLayerException;
import com.raytheon.uf.edex.database.dao.CoreDao;
import com.raytheon.uf.edex.database.dao.DaoConfig;
import com.raytheon.uf.edex.database.query.DatabaseQuery;
import com.raytheon.uf.edex.ogc.common.OgcException;
/**
* Collects layer metadata from data records. Designed for use with records that
* contain all data for a layer at a specific time and level.
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* 2011 bclement Initial creation
*
* </pre>
*
* @author bclement
* @version 1.0
* @param <D>
* @param <L>
* @param <R>
*/
public abstract class DefaultLayerCollector<D extends SimpleDimension, L extends SimpleLayer<D>, R extends PluginDataObject>
extends LayerCollector<D, L, R> {
protected static final IUFStatusHandler log = UFStatus
.getHandler(DefaultLayerCollector.class);
protected Map<String, L> layerMap;
protected ReadWriteLock lock = new ReentrantReadWriteLock();
public DefaultLayerCollector(Class<L> layerClass, Class<R> recordClass,
ILayerStore store) {
super(layerClass, recordClass, store);
}
public void add(R... pdos) {
if (pdos != null && pdos.length > 0) {
addAll(Arrays.asList(pdos));
}
}
@SuppressWarnings("unchecked")
public void addAll(Collection<? extends PluginDataObject> coll) {
if (layerMap == null) {
initMap();
}
Lock write = lock.writeLock();
write.lock();
ICollectorAddon<D, L, R> addon = getAddon();
for (PluginDataObject pdo : coll) {
if (recordClass.equals(pdo.getClass())) {
R rec = (R) pdo;
String name = getLayerName(rec);
L layer = newLayer();
layer.setName(name);
if (!initializeLayer(layer, rec)) {
continue;
}
addToTimes(layer, rec);
addToDims(layer, rec);
L oldLayer = layerMap.get(name);
if (oldLayer == null) {
oldLayer = newLayer();
oldLayer.setName(name);
initializeLayer(oldLayer, rec);
layerMap.put(name, oldLayer);
}
oldLayer.update(layer);
addon.onCollect(layer, (R) pdo);
}
}
addon.onFinish();
write.unlock();
}
protected void addToTimes(L layer, R rec) {
Date refTime = rec.getDataTime().getRefTime();
layer.getTimes().add(refTime);
}
protected void addToDims(L layer, R rec) {
// default is to do nothing
}
protected abstract boolean initializeLayer(L layer, R rec);
public void purgeExpired() {
try {
clearLayersInternal();
addFromDb();
getAddon().onPurgeExpired(new TreeSet<Date>());
} catch (Exception e) {
log.error("Problem purging layers", e);
}
}
protected void clearLayersInternal() throws DataAccessLayerException {
Lock write = lock.writeLock();
write.lock();
if (layerMap != null) {
layerMap.clear();
}
write.unlock();
}
@SuppressWarnings("unchecked")
protected void addFromDb() throws DataAccessLayerException {
DaoConfig conf = DaoConfig.forClass(recordClass);
CoreDao dao = new CoreDao(conf);
DatabaseQuery q = new DatabaseQuery(recordClass);
List<R> recs = (List<R>) dao.queryByCriteria(q);
addAll(recs);
}
public void purgeAll() {
try {
clearLayersInternal();
getAddon().onPurgeAll();
} catch (Exception e) {
log.error("problem purging layers", e);
}
}
/*
* (non-Javadoc)
*
* @see com.raytheon.uf.edex.ogc.common.db.LayerCache#getLayers()
*/
@Override
public List<L> getLayers() throws OgcException {
List<L> rval;
if (layerMap == null) {
initMap();
}
Lock read = lock.readLock();
read.lock();
rval = new ArrayList<L>(layerMap.size());
for (String key : layerMap.keySet()) {
rval.add(copy(layerMap.get(key)));
}
read.unlock();
return rval;
}
protected void initMap() {
Lock write = lock.writeLock();
write.lock();
if (layerMap == null) {
layerMap = new ConcurrentHashMap<String, L>();
try {
addFromDb();
} catch (DataAccessLayerException e) {
log.error("Problem loading layers from db", e);
// if we throw an internal server exception here, it would kill
// the ogc request, better to just not add those layers to
// response
}
}
write.unlock();
}
/*
* (non-Javadoc)
*
* @see
* com.raytheon.uf.edex.ogc.common.db.LayerCache#getLayer(java.lang.String)
*/
@Override
public L getLayer(String name) throws OgcException {
if (layerMap == null) {
initMap();
}
L rval;
Lock read = lock.readLock();
read.lock();
rval = layerMap.get(name);
if (rval != null) {
rval = copy(layerMap.get(name));
}
read.unlock();
return rval;
}
}

View file

@ -1,52 +0,0 @@
/**
* Copyright 09/24/12 Raytheon Company.
*
* Unlimited Rights
* This software was developed pursuant to Contract Number
* DTFAWA-10-D-00028 with the US Government. The US Governments rights
* in and to this copyrighted software are as specified in DFARS
* 252.227-7014 which was made part of the above contract.
*/
package com.raytheon.uf.edex.ogc.common.db;
import java.util.HashSet;
import java.util.Set;
/**
* Default dimension object for point data that has no extra dimension
* information.
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* May 24, 2013 bclement Initial creation
*
* </pre>
*
* @author bclement
* @version 1.0
*/
public class DefaultPointDataDimension extends SimpleDimension {
private static final long serialVersionUID = 2947254963150347405L;
/**
* {@inheritDoc}
*/
@Override
public Set<String> getValues() {
return new HashSet<String>(0);
}
/**
* {@inheritDoc}
*/
@Override
public String getDefaultValue(SimpleLayer<? extends SimpleDimension> layer) {
return null;
}
}

View file

@ -1,370 +0,0 @@
/**
* Copyright 09/24/12 Raytheon Company.
*
* Unlimited Rights
* This software was developed pursuant to Contract Number
* DTFAWA-10-D-00028 with the US Government. The US Governments rights
* in and to this copyrighted software are as specified in DFARS
* 252.227-7014 which was made part of the above contract.
*/
package com.raytheon.uf.edex.ogc.common.db;
import java.io.File;
import java.io.FileFilter;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.concurrent.locks.ReentrantReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock.ReadLock;
import java.util.concurrent.locks.ReentrantReadWriteLock.WriteLock;
import com.raytheon.uf.common.serialization.DynamicSerializationManager;
import com.raytheon.uf.common.serialization.DynamicSerializationManager.SerializationType;
import com.raytheon.uf.edex.ogc.common.AbstractFsStore;
import com.raytheon.uf.edex.ogc.common.OgcException;
import com.raytheon.uf.edex.ogc.common.OgcException.Code;
/**
* Simple Layer store using file system
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Jun 4, 2013 bclement Initial creation
*
* </pre>
*
* @author bclement
* @version 1.0
*/
public class FsLayerStore extends AbstractFsStore implements ILayerStore {
private final DynamicSerializationManager serializer = DynamicSerializationManager
.getManager(SerializationType.Thrift);
private final Map<Class<?>, ReentrantReadWriteLock> _lockMap = new HashMap<Class<?>, ReentrantReadWriteLock>();
/**
* @param storeLocation
*/
public FsLayerStore(File storeLocation) {
super(storeLocation);
}
/**
* @param storeName
* name of store relative to edex static base
*/
public FsLayerStore(String storeName) {
this(findStore(storeName));
}
/**
* Get lock for class
*
* @param c
* @return
*/
private ReentrantReadWriteLock getLock(Class<?> c) {
synchronized (_lockMap) {
ReentrantReadWriteLock rval = _lockMap.get(c);
if (rval == null) {
rval = new ReentrantReadWriteLock();
_lockMap.put(c, rval);
}
return rval;
}
}
/*
* (non-Javadoc)
*
* @see com.raytheon.uf.edex.ogc.common.db.LayerStore#get(java.lang.String,
* java.lang.Class)
*/
@Override
public <D extends SimpleDimension, L extends SimpleLayer<D>> L get(
String id, Class<L> c) throws OgcException {
ReentrantReadWriteLock lock = getLock(c);
ReadLock readLock = lock.readLock();
readLock.lock();
try {
File layerFile = getLayerFileRead(id, c);
if (!layerFile.exists()) {
return null;
}
L rval = deserialize(layerFile, c);
return rval;
} finally {
readLock.unlock();
}
}
@SuppressWarnings("unchecked")
private <D extends SimpleDimension, L extends SimpleLayer<D>> L deserialize(
File f, Class<L> c) throws OgcException {
try {
return (L) serializer.deserialize(new FileInputStream(f));
} catch (Exception e) {
throw new OgcException(Code.InternalServerError, e);
}
}
/**
* Get store directory for class, read only
*
* must be synchronized externally
*
* @param c
* @return file object that isn't guaranteed to exist
* @throws OgcException
*/
private File getClassDirRead(Class<?> c) throws OgcException {
File rval = new File(storeLocation, c.getName());
if (!rval.exists()) {
return rval;
}
if (!rval.isDirectory()) {
throw new OgcException(Code.InternalServerError,
rval.getAbsolutePath() + " is not a directory");
}
if (!rval.canRead()) {
throw new OgcException(Code.InternalServerError,
"Unable to read store directory: " + rval.getAbsolutePath());
}
return rval;
}
/**
* Get store directory for class for modification, creates if it doesn't
* exist
*
* must be synchronized externally
*
* @param c
* @param create
* true if method should create if non existent
* @return file object that is only guaranteed to exist if create is true
* @throws OgcException
*/
private File getClassDirWrite(Class<?> c, boolean create)
throws OgcException {
File rval = new File(storeLocation, c.getName());
if (!rval.exists()) {
if (!create) {
return rval;
}
if (!rval.mkdir()) {
throw new OgcException(Code.InternalServerError,
"Unable to create store directory: "
+ rval.getAbsolutePath());
}
}
if (!rval.isDirectory()) {
throw new OgcException(Code.InternalServerError,
rval.getAbsolutePath() + " is not a directory");
}
if (!rval.canWrite()) {
throw new OgcException(Code.InternalServerError,
"Unable to write to store directory: "
+ rval.getAbsolutePath());
}
return rval;
}
/**
* Create file object for layer file for reading
*
* must be synchronized externally
*
* @param id
* @param c
* @return a file object whose path isn't guaranteed to exist
* @throws OgcException
*/
private File getLayerFileRead(String id, Class<?> c) throws OgcException {
return new File(getClassDirRead(c), encode(id));
}
/**
* Create file object for layer file for writing
*
* must be synchronized externally
*
* @param id
* @param c
* @param createPath
* if true, path to file will be created if nonexistent
* @return
* @throws OgcException
*/
private File getLayerFileWrite(String id, Class<?> c, boolean createPath)
throws OgcException {
return new File(getClassDirWrite(c, createPath), encode(id));
}
/*
* (non-Javadoc)
*
* @see
* com.raytheon.uf.edex.ogc.common.db.LayerStore#getAll(java.lang.Class)
*/
@Override
public <D extends SimpleDimension, L extends SimpleLayer<D>> List<L> getAll(
Class<L> c) throws OgcException {
ReentrantReadWriteLock lock = getLock(c);
ReadLock readLock = lock.readLock();
readLock.lock();
try {
File classDir = getClassDirRead(c);
if (!classDir.exists()) {
return new ArrayList<L>(0);
}
File[] listFiles = classDir.listFiles(new FileFilter() {
@Override
public boolean accept(File f) {
return f.isFile();
}
});
List<L> rval = new ArrayList<L>(listFiles.length);
for (File f : listFiles) {
rval.add(deserialize(f, c));
}
return rval;
} finally {
readLock.unlock();
}
}
/*
* (non-Javadoc)
*
* @see
* com.raytheon.uf.edex.ogc.common.db.LayerStore#createOrUpdate(com.raytheon
* .uf.edex.ogc.common.db.SimpleLayer)
*/
@Override
public void createOrUpdate(SimpleLayer<? extends SimpleDimension> l)
throws OgcException {
Class<?> c = l.getClass();
ReentrantReadWriteLock lock = getLock(c);
WriteLock writeLock = lock.writeLock();
writeLock.lock();
try {
serialize(l, getLayerFileWrite(l.getIdentifier(), c, true));
} finally {
writeLock.unlock();
}
}
/*
* (non-Javadoc)
*
* @see
* com.raytheon.uf.edex.ogc.common.db.LayerStore#createOrUpdate(java.util
* .List)
*/
@Override
public void createOrUpdate(
List<SimpleLayer<? extends SimpleDimension>> layers)
throws OgcException {
Map<Class<?>, List<SimpleLayer<?>>> map = new HashMap<Class<?>, List<SimpleLayer<?>>>();
for (SimpleLayer<?> l : layers) {
List<SimpleLayer<?>> list = map.get(l.getClass());
if (list == null) {
list = new ArrayList<SimpleLayer<?>>();
map.put(l.getClass(), list);
}
list.add(l);
}
for (Entry<Class<?>, List<SimpleLayer<?>>> e : map.entrySet()) {
Class<?> c = e.getKey();
ReentrantReadWriteLock lock = getLock(c);
WriteLock writeLock = lock.writeLock();
writeLock.lock();
try {
for (SimpleLayer<?> l : e.getValue()) {
serialize(l, getLayerFileWrite(l.getIdentifier(), c, true));
}
} finally {
writeLock.unlock();
}
}
}
/**
* Store layer
*
* @param l
* @param f
* @throws OgcException
*/
private void serialize(SimpleLayer<?> l, File f) throws OgcException {
try {
serializer.serialize(l, new FileOutputStream(f));
} catch (Exception e) {
throw new OgcException(Code.InternalServerError, e);
}
}
/*
* (non-Javadoc)
*
* @see
* com.raytheon.uf.edex.ogc.common.db.LayerStore#delete(java.lang.String,
* java.lang.Class)
*/
@Override
public void delete(String id, Class<? extends SimpleLayer<?>> c)
throws OgcException {
File layerFile = getLayerFileWrite(id, c, false);
if (!layerFile.exists()) {
return;
}
ReentrantReadWriteLock lock = getLock(c);
WriteLock writeLock = lock.writeLock();
writeLock.lock();
try {
if (layerFile.exists()) {
layerFile.delete();
}
} finally {
writeLock.unlock();
}
}
/*
* (non-Javadoc)
*
* @see
* com.raytheon.uf.edex.ogc.common.db.LayerStore#deleteAll(java.lang.Class)
*/
@Override
public void deleteAll(Class<? extends SimpleLayer<?>> c)
throws OgcException {
ReentrantReadWriteLock lock = getLock(c);
WriteLock writeLock = lock.writeLock();
writeLock.lock();
try {
File classDir = getClassDirWrite(c, false);
if (!classDir.exists()) {
return;
}
for (File f : classDir.listFiles()) {
if (f.isFile()) {
f.delete();
}
}
} finally {
writeLock.unlock();
}
}
}

View file

@ -1,61 +0,0 @@
/**
* Copyright 09/24/12 Raytheon Company.
*
* Unlimited Rights
* This software was developed pursuant to Contract Number
* DTFAWA-10-D-00028 with the US Government. The US Governments rights
* in and to this copyrighted software are as specified in DFARS
* 252.227-7014 which was made part of the above contract.
*/
package com.raytheon.uf.edex.ogc.common.db;
import java.util.Date;
import java.util.Set;
import com.raytheon.uf.common.dataplugin.PluginDataObject;
import com.raytheon.uf.common.dataplugin.persist.PersistableDataObject;
/**
* Interface for extending layer collectors to perform additional tasks
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Jul 17, 2013 bclement Initial creation
*
* </pre>
*
* @author bclement
* @version 1.0
*/
public interface ICollectorAddon<D extends SimpleDimension, L extends SimpleLayer<D>, R extends PersistableDataObject> {
/**
* Called after record is added to layer. Both should be treated as
* read-only.
*
* @param layer
* @param record
*/
public void onCollect(final L layer, final R record);
/**
* Called after group of records have been added to layers
*/
public void onFinish();
/**
* Called after collector has purged all data
*/
public void onPurgeAll();
/**
* Called after collector has purged expired data
*
* @param timesToKeep
*/
public void onPurgeExpired(Set<Date> timesToKeep);
}

View file

@ -1,61 +0,0 @@
/**
* 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.edex.ogc.common.db;
import java.util.List;
import com.raytheon.uf.edex.ogc.common.OgcException;
/**
* Interface for retrieving layer information that may be in storage or cached
* in memory.
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Sept 11, 2012 bclement Initial creation
*
* </pre>
*
* @author bclement
* @version 1.0
* @param <D>
* @param <L>
*/
public interface ILayerCache<D extends SimpleDimension, L extends SimpleLayer<D>> {
/**
* @return all layers
* @throws OgcException
*/
public List<L> getLayers() throws OgcException;
/**
* @param name
* @return layer with matching name or null if none found
* @throws OgcException
*/
public L getLayer(String name) throws OgcException;
}

View file

@ -1,93 +0,0 @@
/**
* Copyright 09/24/12 Raytheon Company.
*
* Unlimited Rights
* This software was developed pursuant to Contract Number
* DTFAWA-10-D-00028 with the US Government. The US Governments rights
* in and to this copyrighted software are as specified in DFARS
* 252.227-7014 which was made part of the above contract.
*/
package com.raytheon.uf.edex.ogc.common.db;
import java.util.List;
import com.raytheon.uf.edex.ogc.common.OgcException;
/**
* Storage interface for layers
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Jun 4, 2013 bclement Initial creation
*
* </pre>
*
* @author bclement
* @version 1.0
*/
public interface ILayerStore {
/**
* Retrieve layer from store
*
* @param id
* @param c
* @return null if layer is not in store
* @throws OgcException
*/
public <D extends SimpleDimension, L extends SimpleLayer<D>> L get(
String id, Class<L> c) throws OgcException;
/**
* Retrieve all layers for class
*
* @param c
* @return
* @throws OgcException
*/
public <D extends SimpleDimension, L extends SimpleLayer<D>> List<L> getAll(
Class<L> c) throws OgcException;
/**
* Persist layer
*
* @param layer
* @throws OgcException
*/
public void createOrUpdate(SimpleLayer<? extends SimpleDimension> layer)
throws OgcException;
/**
* Persist layers
*
* @param layers
* @throws OgcException
*/
public void createOrUpdate(
List<SimpleLayer<? extends SimpleDimension>> layers)
throws OgcException;
/**
* Remove layer with id from store
*
* @param id
* @param c
* @throws OgcException
*/
public void delete(String id, Class<? extends SimpleLayer<?>> c)
throws OgcException;
/**
* Delete all layers with class c from store
*
* @param c
* @throws OgcException
*/
public void deleteAll(Class<? extends SimpleLayer<?>> c)
throws OgcException;
}

View file

@ -1,241 +0,0 @@
/**
* 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.edex.ogc.common.db;
import java.lang.reflect.Constructor;
import java.util.Calendar;
import java.util.Date;
import java.util.Set;
import org.apache.commons.lang3.time.DateUtils;
import com.raytheon.uf.common.dataplugin.PluginDataObject;
import com.raytheon.uf.common.status.IUFStatusHandler;
import com.raytheon.uf.common.status.UFStatus;
import com.raytheon.uf.edex.ogc.common.OgcException;
import com.raytheon.uf.edex.ogc.common.OgcException.Code;
/**
* Abstract base for layer collectors. Provides common utility methods for child
* classes.
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* 2011 bclement Initial creation
*
* </pre>
*
* @author bclement
* @version 1.0
* @param <D>
* @param <L>
* @param <R>
*/
public abstract class LayerCollector<D extends SimpleDimension, L extends SimpleLayer<D>, R extends PluginDataObject>
implements ILayerCache<D, L> {
protected Class<R> recordClass;
protected Class<L> layerClass;
protected IUFStatusHandler log = UFStatus.getHandler(this.getClass());
protected final ILayerStore store;
protected CollectorAddonFactory<D, L, R> addonFactory = new CollectorAddonFactory<D, L, R>() {
@Override
public ICollectorAddon<D, L, R> create() {
return new ICollectorAddon<D, L, R>() {
@Override
public void onCollect(L layer, R record) {
}
@Override
public void onFinish() {
}
@Override
public void onPurgeAll() {
}
@Override
public void onPurgeExpired(Set<Date> timesToKeep) {
}
};
}
};
public LayerCollector(Class<L> layerClass, Class<R> recordClass,
ILayerStore store) {
this.recordClass = recordClass;
this.layerClass = layerClass;
this.store = store;
}
/**
* Returns object for additional tasks at layer collection
*
* @return
*/
public ICollectorAddon<D, L, R> getAddon() {
return addonFactory.create();
}
protected L copy(final L orig) throws OgcException {
L rval;
try {
Constructor<L> constructor = layerClass.getConstructor(layerClass);
rval = constructor.newInstance(orig);
} catch (Exception e) {
log.error("Unable to copy layer: " + layerClass, e);
throw new OgcException(Code.InternalServerError);
}
return rval;
}
protected L newLayer() {
try {
return layerClass.newInstance();
} catch (Exception e) {
log.error("Unable to instantiate class: " + layerClass, e);
throw new RuntimeException(e);
}
}
public void clearLayers(Class<L> c) throws OgcException {
store.deleteAll(c);
}
public void replaceTimes(L layer) throws OgcException {
L old = store.get(layer.getIdentifier(), layerClass);
if (old == null) {
store.createOrUpdate(layer);
} else {
Set<Date> times = old.getTimes();
times.clear();
Set<Date> newTimes = layer.getTimes();
if (newTimes != null) {
times.addAll(newTimes);
}
store.createOrUpdate(layer);
}
}
public void updateLayer(L layer) throws OgcException {
L old = store.get(layer.getIdentifier(), layerClass);
if (old == null) {
store.createOrUpdate(layer);
} else {
old.update(layer);
store.createOrUpdate(layer);
}
}
/**
* Take the Calendar back to the first instant of the current hour. This is
* equivalent to calling roundToHour with cutoff of 59
*
* @param cal
* @return
*/
public static Calendar truncateToHour(Calendar cal) {
return DateUtils.truncate(cal, Calendar.HOUR);
}
/**
* Take the Date back to the first instant of the current hour. This is
* equivalent to calling roundToHour with cutoff of 59
*
* @param d
* @return
*/
public static Date truncateToHour(Date d) {
return DateUtils.truncate(d, Calendar.HOUR);
}
public static Date truncateToMinute(Date d) {
return DateUtils.truncate(d, Calendar.MINUTE);
}
public static Date roundUpToMinute(Date d) {
Date rval = DateUtils.addMinutes(d, 1);
return truncateToMinute(rval);
}
/**
* Round the Calendar to the nearest hour determined by cutoff
*
* @param cal
* @param cutoff
* if cal's minute value is greater than cutoff, the return will
* be rounded up to the next hour, else rounded down
* @return
*/
public static Calendar roundToHour(Calendar cal, int cutoff) {
if (cutoff < 0 || cutoff > 59) {
cutoff %= 60;
}
if (cal.get(Calendar.MINUTE) > cutoff) {
cal = (Calendar) cal.clone();
cal.add(Calendar.HOUR, 1);
}
return truncateToHour(cal);
}
/**
* Round the Date to the nearest hour determined by cutoff
*
* @param d
* @param cutoff
* if d's minute value is greater than cutoff, the return will be
* rounded up to the next hour, else rounded down
* @return
*/
public static Date roundToHour(Date d, int cutoff) {
Calendar tmp = Calendar.getInstance();
tmp.setTime(d);
tmp = roundToHour(tmp, cutoff);
return tmp.getTime();
}
/**
* From a record build and return the layer name. Used to make sure a proper
* layer name can always be retrieved for any record object used by a layer
* collector.
*
* @param rec
* @return
*/
public abstract String getLayerName(R rec);
/**
* @param addonFactory
* the addonFactory to set
*/
public void setAddonFactory(CollectorAddonFactory<D, L, R> addonFactory) {
this.addonFactory = addonFactory;
}
}

View file

@ -1,548 +0,0 @@
/**
* 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.edex.ogc.common.db;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import java.util.TimeZone;
import java.util.TreeSet;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.xml.bind.DatatypeConverter;
import org.apache.commons.lang3.time.DateUtils;
import org.geotools.geometry.jts.JTS;
import org.geotools.geometry.jts.ReferencedEnvelope;
import org.opengis.referencing.ReferenceIdentifier;
import org.opengis.referencing.crs.CoordinateReferenceSystem;
import com.raytheon.uf.common.status.IUFStatusHandler;
import com.raytheon.uf.common.status.UFStatus;
import com.raytheon.uf.common.time.util.TimeUtil;
import com.raytheon.uf.edex.database.DataAccessLayerException;
import com.raytheon.uf.edex.ogc.common.OgcBoundingBox;
import com.raytheon.uf.edex.ogc.common.OgcDimension;
import com.raytheon.uf.edex.ogc.common.OgcException;
import com.raytheon.uf.edex.ogc.common.OgcGeoBoundingBox;
import com.raytheon.uf.edex.ogc.common.OgcLayer;
import com.raytheon.uf.edex.ogc.common.OgcStyle;
import com.raytheon.uf.edex.ogc.common.StyleLookup;
import com.vividsolutions.jts.geom.Polygon;
/**
* Converts layer objects from storage to intermediate OGC metadata layer
* objects.
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Jun 13, 2011 bclement Initial creation
*
* </pre>
*
* @author bclement
* @version 1.0
* @param <DIMENSION>
* @param <L>
*/
public class LayerTransformer<DIMENSION extends SimpleDimension, L extends SimpleLayer<DIMENSION>> {
protected static IUFStatusHandler log = UFStatus
.getHandler(LayerTransformer.class);
public enum TimeFormat {
LIST, HOUR_RANGES
};
protected String key;
protected ILayerCache<DIMENSION, L> lcache;
protected static String timeUnit = "ISO8601";
public static final Pattern frontDot = Pattern
.compile("^(-?[0-9]*\\.?[0-9]+)(.*)$");
public static final Pattern backDot = Pattern
.compile("^(-?[0-9]+\\.?[0-9]*)(.*)$");
/**
* Construct a LayerTransformer that uses a different layerClass and
* layerWrapperClass than the default SimpleLayer and LayerHolder
*
* @param key
* @param layerTable
* @param das
* @param layerClass
* @param layerHolderClass
*/
public LayerTransformer(String key, ILayerCache<DIMENSION, L> lcache) {
this.key = key;
this.lcache = lcache;
}
/**
* @param name
* @return null if layer not found
* @throws DataAccessLayerException
*/
public L find(String name) throws OgcException {
return lcache.getLayer(name);
}
/**
* @param layer
* @param dimension
* @return null if layer/dimension not found
* @throws DataAccessLayerException
*/
public DIMENSION getDimension(String layer, String dimension)
throws OgcException {
L l = find(layer);
if (l == null) {
return null;
}
return l.getDimension(dimension);
}
/**
* Get all dimensions that start with prefix. Case insensitive.
*
* @param layer
* @param prefix
* @return empty list if layer/dimension not found
*/
public static <DIMENSION extends SimpleDimension, L extends SimpleLayer<DIMENSION>> List<DIMENSION> getDimsByPrefix(
L layer, String prefix) {
List<DIMENSION> rval = new ArrayList<DIMENSION>(2);
if (layer == null) {
return rval;
}
for (DIMENSION d : layer.getDimensions()) {
String lower = d.getName().toLowerCase();
if (lower.startsWith(prefix.toLowerCase())) {
rval.add(d);
}
}
return rval;
}
/**
* @param dim
* @return empty set if dim is null or doesn't have any parsable values
*/
public static TreeSet<Double> getDimValuesAsDouble(SimpleDimension dim) {
TreeSet<Double> rval = new TreeSet<Double>();
if (dim == null) {
return rval;
}
for (String val : dim.getValues()) {
try {
Matcher m = frontDot.matcher(val);
if (m.matches()) {
val = m.group(1);
} else {
m = backDot.matcher(val);
if (m.matches()) {
val = m.group(1);
}
}
rval.add(Double.parseDouble(val));
} catch (Throwable e) {
// continue
}
}
return rval;
}
/**
* @param layer
* @return
*/
public List<OgcBoundingBox> getBoundingBoxes(L layer) {
String crs = layer.getTargetCrsCode();
double minx = layer.getTargetMinx();
double maxx = layer.getTargetMaxx();
double miny = layer.getTargetMiny();
double maxy = layer.getTargetMaxy();
OgcBoundingBox rval = new OgcBoundingBox(crs, minx, maxx, miny, maxy);
return Arrays.asList(rval);
}
public static String getCrsName(CoordinateReferenceSystem crs) {
if (crs == null) {
return null;
}
Set<ReferenceIdentifier> ids = crs.getIdentifiers();
if (ids == null || ids.isEmpty()) {
return crs.getName().toString();
} else {
return ids.iterator().next().toString();
}
}
/**
* @param layer
* @return
*/
public static <L extends SimpleLayer<?>> OgcGeoBoundingBox getGeoBoundingBox(
L layer) {
Polygon crs84Bounds = layer.getCrs84Bounds();
if (crs84Bounds == null) {
return null;
}
ReferencedEnvelope env = JTS.toEnvelope(crs84Bounds);
return new OgcGeoBoundingBox(env);
}
/**
* @param layer
* @param tformat
* @return
*/
public static <L extends SimpleLayer<?>> List<String> getTimes(L layer) {
return getTimes(layer, TimeFormat.LIST);
}
/**
* @param layer
* @param tformat
* @return
*/
public static <L extends SimpleLayer<?>> List<String> getTimes(L layer,
TimeFormat tformat) {
List<String> rval;
// TODO this could be adapted to a pattern that allows for formatters to
// be externally added
switch (tformat) {
case LIST:
rval = getTimesAsList(layer);
break;
case HOUR_RANGES:
rval = getTimesAsHourRanges(layer);
break;
default:
throw new IllegalArgumentException("No handler for time format: "
+ tformat);
}
return rval;
}
/**
* @param layer
* @return
*/
protected static <L extends SimpleLayer<?>> List<String> getTimesAsHourRanges(
L layer) {
Set<Date> times = layer.getTimes();
if (times == null || times.isEmpty()) {
return new ArrayList<String>(0);
}
if (times.size() % 2 != 0) {
String msg = "Odd number of times for layer " + layer.getName()
+ ". Should be even to construct time ranges.";
log.warn(msg + " Dropping last time");
}
Iterator<Date> iter = times.iterator();
int ranges = times.size() / 2;
List<String> rval = new ArrayList<String>(ranges);
for (int i = 0; i < ranges; ++i) {
Date start = iter.next();
Date end = iter.next();
rval.add(formatRange(start, end));
}
return rval;
}
protected static String formatRange(Date start, Date end) {
return format(start) + '/' + format(end) + "/0";
}
/**
* End a range started by startRange()
*
* @param d
* start of range
* @param i
* iterator to rest of times that possibly include the rest of
* the range
* @param sb
* where the formatted output goes
* @return the start of the next range, null if there are no more ranges
*/
protected static Date endRange(Date d, Iterator<Date> i, StringBuilder sb) {
long milliStart = d.getTime();
long milliPrev = milliStart;
Date rval = null;
Date prev = null;
Date curr = null;
while (i.hasNext()) {
curr = i.next();
if (curr.getTime() - milliPrev > TimeUtil.MILLIS_PER_HOUR) {
// we've reached the end of the range return rval
rval = curr;
break;
}
prev = curr;
milliPrev = prev.getTime();
}
if (prev == null) {
// iterator didn't have anything
prev = new Date(milliStart + TimeUtil.MILLIS_PER_HOUR);
} else {
// we want the range to end at the next hour
prev = new Date(prev.getTime() + TimeUtil.MILLIS_PER_HOUR);
}
sb.append(format(prev));
// FIXME 0 indicates a continuum range, we should support discrete
// periods in the range
sb.append("/0");
return rval;
}
public static String format(Date d) {
Calendar c = GregorianCalendar.getInstance(TimeZone.getTimeZone("GMT"));
c.setTime(d);
return DatatypeConverter.printDateTime(c);
}
protected static void startRange(StringBuilder sb, Date d) {
sb.append(format(d));
sb.append('/');
}
protected static <L extends SimpleLayer<?>> List<String> getTimesAsList(
L layer) {
Set<Date> times = layer.getTimes();
if (times == null || times.isEmpty()) {
return new ArrayList<String>(0);
}
TreeSet<Date> sorted = new TreeSet<Date>(times);
Iterator<Date> i = sorted.iterator();
List<String> rval = new ArrayList<String>(sorted.size());
while (i.hasNext()) {
rval.add(format(i.next()));
}
return rval;
}
public TreeSet<Date> getAllTimes() throws OgcException {
TreeSet<Date> rval = new TreeSet<Date>();
List<L> layers = getLayers();
for (L l : layers) {
rval.addAll(l.getTimes());
}
return rval;
}
public List<L> getLayers() throws OgcException {
return lcache.getLayers();
}
public List<OgcLayer> getLayersAsOgc(TimeFormat tformat, StyleLookup lookup)
throws OgcException {
return transform(getLayers(), tformat, lookup);
}
public List<OgcLayer> getLayersAsOgc(StyleLookup lookup)
throws OgcException {
return getLayersAsOgc(TimeFormat.LIST, lookup);
}
/**
* @param layers
* @return
*/
protected List<OgcLayer> transform(List<L> layers, TimeFormat tformat,
StyleLookup lookup) {
List<OgcLayer> rval = new ArrayList<OgcLayer>(layers.size());
for (L simple : layers) {
rval.add(transform(simple, tformat, lookup));
}
return rval;
}
/**
* Transform a simple layer as represented in the data storage area to an
* OgcLayer that can be viewed through getCapabilities
* <p>
* Override this method to add additional Dimensions.
*
* @param layer
* @return
*/
public OgcLayer transform(L layer, TimeFormat tformat, StyleLookup lookup) {
OgcLayer rval = new OgcLayer();
String name = layer.getName();
rval.setName(key, name);
rval.setTitle(name);
setStylesForLayer(rval.getName(), layer, rval, lookup);
OgcDimension timeDim = new OgcDimension("time", timeUnit,
layer.getTimeEntries());
String defaultTime = layer.getDefaultTimeEntry();
timeDim.setDefaultVal(defaultTime);
rval.addDimension(timeDim);
for (OgcDimension dim : getDims(layer, layer.getDimensions())) {
rval.addDimension(dim);
}
rval.setGeoBoundingBox(getGeoBoundingBox(layer));
rval.setBoundingBox(getBoundingBoxes(layer));
// rval.setCrs(Arrays.asList(layer.getTargetCrs()));
return rval;
}
public static String getTimeRange(Date d) {
Date start = DateUtils.truncate(d, Calendar.HOUR);
Date end = DateUtils.addHours(start, 1);
return format(start) + '/' + format(end);
}
protected void setStylesForLayer(String layerName, L layer, OgcLayer rval,
StyleLookup lookup) {
if (lookup != null) {
String style = lookup.lookup(layer.getName());
if (style != null) {
OgcStyle ogcstyle = new OgcStyle(style);
ogcstyle.setLegendUrl(createLegendUrl(layerName, style));
ogcstyle.setDefault(true);
rval.setStyles(Arrays.asList(ogcstyle));
}
}
}
public static String createLegendUrl(String layerName, String styleName) {
String url = "&layer=" + layerName + "&style=" + styleName
+ "&format=image/png";
return url.replaceAll(" ", "%20");
}
/**
* @param layer
* @return
*/
protected OgcDimension[] getDims(L layer, Set<DIMENSION> dims) {
if (dims == null) {
return new OgcDimension[0];
}
List<OgcDimension> rval = new ArrayList<OgcDimension>(dims.size());
for (DIMENSION dim : dims) {
OgcDimension ogcdim = transform(layer, dim);
if (ogcdim != null) {
rval.add(ogcdim);
}
}
return rval.toArray(new OgcDimension[rval.size()]);
}
/**
* @param simpleDimension
* @return
*/
protected OgcDimension transform(L layer, DIMENSION dim) {
if (dim == null || dim.getName() == null || dim.getValues() == null) {
return null;
}
OgcDimension rval;
List<String> values = new ArrayList<String>(dim.getValues());
if (dim.getUnits() == null) {
rval = new OgcDimension(dim.getName(), values);
} else {
rval = new OgcDimension(dim.getName(), dim.getUnits(), values);
}
rval.setDefaultVal(dim.getDefaultValue(layer));
return rval;
}
protected OgcLayer transform(L layer, StyleLookup lookup) {
return transform(layer, TimeFormat.LIST, lookup);
}
/**
* @param layerName
* @return null if layer name isn't found
* @throws DataAccessLayerException
*/
public Date getLatestTime(String layerName) throws OgcException {
L simpleLayer = find(layerName);
return getLatestTime(simpleLayer);
}
/**
* @param layer
* @return null if layer name isn't found
*/
public static <L extends SimpleLayer<?>> Date getLatestTime(L layer) {
if (layer == null) {
return null;
}
Set<Date> times = layer.getTimes();
TreeSet<Date> sorted = new TreeSet<Date>(times);
return sorted.last();
}
/**
* @return the key
*/
public String getKey() {
return key;
}
/**
* @param key
* the key to set
*/
public void setKey(String key) {
this.key = key;
}
/**
* @return
* @throws OgcException
*/
public TreeSet<Date> getLatestTimes() throws OgcException {
List<L> layers = getLayers();
TreeSet<Date> rval = new TreeSet<Date>();
for (L l : layers) {
TreeSet<Date> times = new TreeSet<Date>(l.getTimes());
rval.add(times.last());
}
return rval;
}
/**
* @return the lcache
*/
public ILayerCache<DIMENSION, L> getLcache() {
return lcache;
}
}

View file

@ -1,139 +0,0 @@
/**
* 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.edex.ogc.common.db;
import java.util.Date;
import java.util.List;
import java.util.Set;
import java.util.SortedSet;
import java.util.TreeSet;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.MappedSuperclass;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import com.raytheon.uf.common.dataplugin.PluginDataObject;
import com.raytheon.uf.common.serialization.annotations.DynamicSerialize;
import com.raytheon.uf.edex.ogc.common.db.LayerTransformer.TimeFormat;
/**
* Layer metadata storage for point data types
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Mar 29, 2011 bclement Initial creation
* 10/22/2013 2742 dhladky @Entity made for Db dependency in AWIPS code, changed to @MappedSuperclass
*
* </pre>
*
* @author bclement
* @version 1.0
*/
@MappedSuperclass
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
@XmlAccessorType(XmlAccessType.NONE)
@DynamicSerialize
public abstract class PointDataLayer extends
SimpleLayer<DefaultPointDataDimension> {
private static final long serialVersionUID = 4301480632118555546L;
public PointDataLayer() {
}
public PointDataLayer(SimpleLayer<DefaultPointDataDimension> other) {
super(other);
}
/*
* (non-Javadoc)
*
* @see com.raytheon.uf.edex.ogc.common.db.SimpleLayer#getTimeEntries()
*/
@Override
public List<String> getTimeEntries() {
return LayerTransformer.getTimes(this, TimeFormat.HOUR_RANGES);
}
/*
* (non-Javadoc)
*
* @see com.raytheon.uf.edex.ogc.common.db.SimpleLayer#getDimensions()
*/
@Override
public Set<DefaultPointDataDimension> getDimensions() {
return new TreeSet<DefaultPointDataDimension>();
}
/*
* (non-Javadoc)
*
* @see com.raytheon.uf.edex.ogc.common.db.SimpleLayer#getDefaultTimeEntry()
*/
@Override
public String getDefaultTimeEntry() {
return LayerTransformer.getTimeRange(getDefaultTime());
}
/**
* Create formatted time range string with range start at the latest time
* minus milliOffset and the range end at the latest time.
*
* @param milliOffset
* @return
*/
protected <T extends PluginDataObject> String getRangeSinceLatest(
long milliOffset) {
Date end = getTimes().last();
long startTime = end.getTime() - milliOffset;
Date start = new Date(startTime);
String startStr = LayerTransformer.format(start);
String endStr = LayerTransformer.format(end);
return startStr + "/" + endStr;
}
/*
* (non-Javadoc)
*
* @see
* com.raytheon.uf.edex.ogc.common.db.SimpleLayer#updateDates(com.raytheon
* .uf.edex.ogc.common.db.SimpleLayer)
*/
@Override
public void updateDates(SimpleLayer<DefaultPointDataDimension> other) {
SortedSet<Date> memTimes = other.getTimes();
if (memTimes == null || memTimes.isEmpty()) {
return;
}
SortedSet<Date> dbtimes = this.getTimes();
SortedSet<Date> all = new TreeSet<Date>(memTimes);
all.addAll(dbtimes);
dbtimes.clear();
dbtimes.add(all.first());
dbtimes.add(all.last());
}
}

View file

@ -1,89 +0,0 @@
/**
* Copyright 09/24/12 Raytheon Company.
*
* Unlimited Rights
* This software was developed pursuant to Contract Number
* DTFAWA-10-D-00028 with the US Government. The US Governments rights
* in and to this copyrighted software are as specified in DFARS
* 252.227-7014 which was made part of the above contract.
*/
package com.raytheon.uf.edex.ogc.common.db;
import java.util.Date;
import java.util.Map;
import java.util.Set;
import java.util.TreeSet;
import com.raytheon.uf.common.dataplugin.PluginException;
import com.raytheon.uf.common.status.IUFStatusHandler;
import com.raytheon.uf.common.status.UFStatus;
import com.raytheon.uf.edex.core.EDEXUtil;
import com.raytheon.uf.edex.core.EdexException;
import com.raytheon.uf.edex.database.dao.CoreDao;
import com.raytheon.uf.edex.database.plugin.PurgeResults;
/**
* Basic purge notification that sends all kept times to notification topic
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Jun 6, 2013 bclement Initial creation
*
* </pre>
*
* @author bclement
* @version 1.0
*/
public class PurgeNotification {
private final String pluginName;
protected static final IUFStatusHandler statusHandler = UFStatus
.getHandler(CoreDao.class);
/**
* @param pluginName
*/
public PurgeNotification(String pluginName) {
this.pluginName = pluginName;
}
public void purgeAllData() throws PluginException {
try {
EDEXUtil.getMessageProducer().sendAsyncUri(getTopicName("all"),
null);
} catch (EdexException e) {
statusHandler.error("Problem sending purge all message for "
+ pluginName, e);
}
}
public void purgeExpiredData(PurgeResults res) throws PluginException {
try {
if (res.didPurge()) {
Map<String, Set<Date>> timesKept = res.getTimesKept();
Set<Date> keepers = new TreeSet<Date>();
if (timesKept != null) {
for (String pk : timesKept.keySet()) {
keepers.addAll(timesKept.get(pk));
}
}
EDEXUtil.getMessageProducer().sendAsyncUri(
getTopicName("expired"), keepers);
}
} catch (EdexException e) {
statusHandler.error("Problem sending purge expired message for "
+ pluginName, e);
}
}
private String getTopicName(String purgeType) {
return String.format("jms-generic:topic:Purge.%s.%s", purgeType,
this.pluginName);
}
}

View file

@ -1,78 +0,0 @@
/**
* Copyright 09/24/12 Raytheon Company.
*
* Unlimited Rights
* This software was developed pursuant to Contract Number
* DTFAWA-10-D-00028 with the US Government. The US Governments rights
* in and to this copyrighted software are as specified in DFARS
* 252.227-7014 which was made part of the above contract.
*/
package com.raytheon.uf.edex.ogc.common.db;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.hibernate.Criteria;
import org.hibernate.HibernateException;
import org.hibernate.criterion.CriteriaQuery;
import org.hibernate.criterion.Criterion;
import org.hibernate.engine.spi.TypedValue;
/**
* Hibernate criterion that allows for direct SQL restrictions
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Feb 20, 2013 bclement Initial creation
* 10/16/2014 3454 bphillip Upgrading to Hibernate 4
*
* </pre>
*
* @author bclement
* @version 1.0
*/
public class SQLParamRestriction implements Criterion {
private static final long serialVersionUID = -7987314731153087246L;
private final String sql;
private static Pattern paramPattern = Pattern
.compile("\\{([a-zA-Z0-9_\\.]+)\\}");
public String toSqlString(Criteria criteria, CriteriaQuery criteriaQuery) throws HibernateException {
StringBuffer result = new StringBuffer();
Matcher matcher = paramPattern.matcher(sql);
while (matcher.find()) {
String token = matcher.group(1);
String[] columns = criteriaQuery.getColumnsUsingProjection(criteria, token);
if (columns.length > 0) {
matcher.appendReplacement(result, columns[0]);
}
}
matcher.appendTail(result);
return result.toString();
}
public TypedValue[] getTypedValues(Criteria criteria, CriteriaQuery criteriaQuery) throws HibernateException {
return new TypedValue[0];
}
public String toString() {
return sql;
}
protected SQLParamRestriction(String sql) {
this.sql = sql;
}
public static Criterion restriction(String sql) {
return new SQLParamRestriction(sql);
}
}

View file

@ -1,205 +0,0 @@
/**
* 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.edex.ogc.common.db;
import java.io.Serializable;
import java.util.Set;
import java.util.TreeSet;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import com.raytheon.uf.common.serialization.annotations.DynamicSerialize;
import com.raytheon.uf.common.serialization.annotations.DynamicSerializeElement;
/**
* Layer dimension metadata storage object
*
* <pre>
* SOFTWARE HISTORY
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* 08/09/2012 754 dhladky initial creation, based on B Clements original
* 04/22/2013 1746 dhladky Removed DB dependency from WFS code
* </pre>
*
* @author dhladky
* @version 1.0
*/
@XmlRootElement
@XmlAccessorType(XmlAccessType.NONE)
@DynamicSerialize
public abstract class SimpleDimension implements Comparable<SimpleDimension>,
Serializable {
private static final long serialVersionUID = 4654482181227204619L;
@XmlElement
@DynamicSerializeElement
protected String name;
@XmlElement
@DynamicSerializeElement
protected String units;
public SimpleDimension() {
}
public SimpleDimension(SimpleDimension other) {
this.name = other.name;
this.units = other.units;
}
/**
* @return live reference to values set, should not return null
*/
public abstract Set<String> getValues();
/**
* @param layer
* the layer that this dimension belongs to. Used by method to
* determine the best default for dimension.
* @return
*/
public abstract String getDefaultValue(
SimpleLayer<? extends SimpleDimension> layer);
/**
* @param lowest
* set true to return lowest value, otherwise highest is returned
* @return null if there are no values for this dimension
*/
protected String getDouble(boolean lowest) {
Double rval = getValue(lowest);
return rval != null ? rval.toString() : null;
}
/**
* @param lowest
* set true to return lowest value, otherwise highest is returned
* @return null if there are no values for this dimension
*/
protected Double getValue(boolean lowest) {
Double rval;
TreeSet<Double> vals = LayerTransformer.getDimValuesAsDouble(this);
if (vals.isEmpty()) {
rval = null;
} else {
rval = lowest ? vals.first() : vals.last();
}
return rval;
}
/**
* @param lowest
* set true to return lowest value, otherwise highest is returned
* @return null if there are no values for this dimension
*/
protected String getInt(boolean lowest) {
Double val = getValue(lowest);
return val != null ? String.valueOf(val.intValue()) : null;
}
/**
* @param lowest
* set true to return lowest value, otherwise highest is returned
* @return
*/
protected String getString(boolean lowest) {
Set<String> values = this.getValues();
if (values.isEmpty()) {
return null;
}
TreeSet<String> sorted = new TreeSet<String>(values);
return lowest ? sorted.first() : sorted.last();
}
/**
* @return the name
*/
public String getName() {
return name;
}
/**
* @param name
* the name to set
*/
public void setName(String name) {
this.name = name;
}
/**
* @return the units
*/
public String getUnits() {
return units;
}
/**
* @param units
* the units to set
*/
public void setUnits(String units) {
this.units = units;
}
@Override
public int compareTo(SimpleDimension o) {
return this.name.compareTo(o.name);
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((name == null) ? 0 : name.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
SimpleDimension other = (SimpleDimension) obj;
if (name == null) {
if (other.name != null)
return false;
} else if (!name.equals(other.name))
return false;
return true;
}
/*
* (non-Javadoc)
*
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
return "[name=" + name + ", values=" + getValues() + "]";
}
}

View file

@ -1,387 +0,0 @@
/**
* 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.edex.ogc.common.db;
import java.io.Serializable;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Set;
import java.util.TreeSet;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
import com.raytheon.uf.common.dataplugin.persist.IPersistableDataObject;
import com.raytheon.uf.common.geospatial.adapter.GeometryAdapter;
import com.raytheon.uf.common.serialization.annotations.DynamicSerialize;
import com.raytheon.uf.common.serialization.annotations.DynamicSerializeElement;
import com.vividsolutions.jts.geom.Polygon;
/**
* Layer metadata storage object
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Mar 29, 2011 bclement Initial creation
* 04/22/2013 1746 dhladky Removed DB dependency from WFS code
*
* </pre>
*
* @author bclement
* @version 1.0
* @param <DIMENSION>
*/
@XmlRootElement
@XmlAccessorType(XmlAccessType.NONE)
@DynamicSerialize
public abstract class SimpleLayer<DIMENSION extends SimpleDimension> implements
IPersistableDataObject<String>, Serializable {
private static final long serialVersionUID = -9102070476178937194L;
@XmlElement
@DynamicSerializeElement
protected int nx;
@XmlElement
@DynamicSerializeElement
protected int ny;
@XmlElement
@DynamicSerializeElement
protected String name;
@XmlElement
@DynamicSerializeElement
protected String targetCrsCode;
@XmlElement
@DynamicSerializeElement
protected double targetMinx;
@XmlElement
@DynamicSerializeElement
protected double targetMiny;
@XmlElement
@DynamicSerializeElement
protected double targetMaxx;
@XmlElement
@DynamicSerializeElement
protected double targetMaxy;
@XmlJavaTypeAdapter(value = GeometryAdapter.class)
@DynamicSerializeElement
protected Polygon crs84Bounds;
@XmlElement
@DynamicSerializeElement
protected TreeSet<Date> times;
@XmlElement
@DynamicSerializeElement
protected boolean timesAsRanges = false;
/**
*
*/
public SimpleLayer(TreeSet<Date> times) {
this.times = times;
}
public SimpleLayer() {
this.times = new TreeSet<Date>();
}
public SimpleLayer(SimpleLayer<DIMENSION> other) {
this.crs84Bounds = (Polygon) other.crs84Bounds.clone();
this.name = other.name;
this.nx = other.nx;
this.ny = other.ny;
this.targetCrsCode = other.targetCrsCode;
this.targetMaxx = other.targetMaxx;
this.targetMaxy = other.targetMaxy;
this.targetMinx = other.targetMinx;
this.targetMiny = other.targetMiny;
if (other.times != null) {
this.times = new TreeSet<Date>(other.times);
} else {
this.times = new TreeSet<Date>();
}
}
/**
* Merge layer values from other into this layer
*
* @param other
*/
public void update(SimpleLayer<DIMENSION> other) {
if (other == null) {
return;
}
updateDates(other);
updateDims(other);
}
/**
* Merge time values from other into this layer
*
* @param other
*/
public void updateDates(SimpleLayer<DIMENSION> other) {
Set<Date> otherTimes = other.getTimes();
if (otherTimes == null) {
return;
}
Set<Date> thisTimes = this.getTimes();
if (thisTimes == null) {
setTimes(new TreeSet<Date>(otherTimes));
} else {
for (Date time : otherTimes) {
thisTimes.add(time);
}
}
}
/**
* Merge dimension values from other into this layer
*
* @param other
*/
public void updateDims(SimpleLayer<DIMENSION> other) {
Set<DIMENSION> otherDims = other.getDimensions();
if (otherDims == null) {
return;
}
Set<DIMENSION> thisDims = this.getDimensions();
if (thisDims != null) {
if (thisDims != null) {
updateDimLists(thisDims, otherDims);
}
}
}
/**
* Merge dimension values from shinyDims into oldDims
*
* @param oldDims
* @param shinyDims
*/
protected void updateDimLists(Set<DIMENSION> oldDims,
Set<DIMENSION> shinyDims) {
HashMap<String, DIMENSION> oldMap = getDimMap(oldDims);
HashMap<String, DIMENSION> shinyMap = getDimMap(shinyDims);
for (String name : shinyMap.keySet()) {
DIMENSION shinyDim = shinyMap.get(name);
DIMENSION oldDim = oldMap.get(name);
if (oldDim == null) {
oldDims.add(shinyDim);
} else {
updateDimValues(oldDim, shinyDim);
}
}
}
/**
* Create dimension lookup map keyed by dimension name
*
* @param dims
* @return
*/
protected HashMap<String, DIMENSION> getDimMap(Set<DIMENSION> dims) {
HashMap<String, DIMENSION> rval = new HashMap<String, DIMENSION>(
dims.size());
for (DIMENSION sd : dims) {
rval.put(sd.getName(), sd);
}
return rval;
}
/**
* Merge values from shinyDim into oldDim
*
* @param oldDim
* @param shinyDim
*/
protected void updateDimValues(DIMENSION oldDim, DIMENSION shinyDim) {
Set<String> oldValues = oldDim.getValues();
Set<String> shinyValues = shinyDim.getValues();
if (oldValues != null && shinyValues != null) {
for (String val : shinyValues) {
oldValues.add(val);
}
}
}
/**
* @return live reference to dimensions list, should not return null
*/
public abstract Set<DIMENSION> getDimensions();
/**
* @return live reference to times set, should not return null
*/
public TreeSet<Date> getTimes() {
return times;
}
public void setTimes(TreeSet<Date> times) {
this.times = times;
}
/**
* @return list of formatted times for layer (could be ranges)
*/
public List<String> getTimeEntries() {
return LayerTransformer.getTimes(this);
}
public Date getDefaultTime() {
return this.getTimes().last();
}
/**
* @param dimension
* @return null if dimension not found
*/
public DIMENSION getDimension(String dimension) {
DIMENSION rval = null;
for (DIMENSION d : this.getDimensions()) {
if (d.getName().equalsIgnoreCase(dimension)) {
rval = d;
break;
}
}
return rval;
}
/**
* @return formatted time string (could be a range)
*/
public String getDefaultTimeEntry() {
return LayerTransformer.format(getDefaultTime());
}
public String toString() {
return name == null ? super.toString() : name;
}
public int getNx() {
return nx;
}
public void setNx(int nx) {
this.nx = nx;
}
public int getNy() {
return ny;
}
public void setNy(int ny) {
this.ny = ny;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getTargetCrsCode() {
return targetCrsCode;
}
public void setTargetCrsCode(String targetCrsCode) {
this.targetCrsCode = targetCrsCode;
}
public double getTargetMinx() {
return targetMinx;
}
public void setTargetMinx(double targetMinx) {
this.targetMinx = targetMinx;
}
public double getTargetMiny() {
return targetMiny;
}
public void setTargetMiny(double targetMiny) {
this.targetMiny = targetMiny;
}
public double getTargetMaxx() {
return targetMaxx;
}
public void setTargetMaxx(double targetMaxx) {
this.targetMaxx = targetMaxx;
}
public double getTargetMaxy() {
return targetMaxy;
}
public void setTargetMaxy(double targetMaxy) {
this.targetMaxy = targetMaxy;
}
@Override
public String getIdentifier() {
return name;
}
public Polygon getCrs84Bounds() {
return crs84Bounds;
}
public void setCrs84Bounds(Polygon crs84Bounds) {
this.crs84Bounds = crs84Bounds;
}
/**
* @return the timesAsRanges
*/
public boolean isTimesAsRanges() {
return timesAsRanges;
}
/**
* @param timesAsRanges
* the timesAsRanges to set
*/
public void setTimesAsRanges(boolean timesAsRanges) {
this.timesAsRanges = timesAsRanges;
}
}

View file

@ -1,295 +0,0 @@
/**
* 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.
*
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Sep 11, 2012 bclement Initial creation
* Aug 18, 2013 #2097 dhladky Updates for interfaces etc.
*
*/
package com.raytheon.uf.edex.ogc.common.db;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Set;
import java.util.SortedSet;
import java.util.TreeSet;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;
import org.geotools.geometry.jts.JTS;
import org.geotools.geometry.jts.ReferencedEnvelope;
import com.raytheon.uf.common.dataplugin.PluginDataObject;
import com.raytheon.uf.common.geospatial.MapUtil;
import com.raytheon.uf.edex.ogc.common.OgcException;
import com.vividsolutions.jts.geom.Envelope;
/**
* Collects layer metadata from data records. Designed for use with plugins that
* have a single layer which all records contribute to (like pointdata)
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* 2011 bclement Initial creation
*
* </pre>
*
* @author bclement
* @version 1.0
* @param <D>
* @param <L>
* @param <R>
*/
public abstract class SingleLayerCollector<D extends SimpleDimension, L extends SimpleLayer<D>, R extends PluginDataObject>
extends LayerCollector<D, L, R> {
private L _layer;
protected ReadWriteLock lock = new ReentrantReadWriteLock();
protected String layerName;
/**
* @param transformer
*/
public SingleLayerCollector(Class<L> layerClass, Class<R> recordClass,
String layerName, ILayerStore store) {
super(layerClass, recordClass, store);
this.layerName = layerName;
}
@SuppressWarnings("unchecked")
public void add(PluginDataObject... pdos) {
Lock write = lock.writeLock();
write.lock();
try {
ICollectorAddon<D, L, R> addon = getAddon();
L layer = getLayer();
for (PluginDataObject pdo : pdos) {
if (recordClass.equals(pdo.getClass())) {
R record = (R) pdo;
Calendar time = getTime(record);
replaceRange(layer, time);
addon.onCollect(layer, (R) pdo);
}
}
addon.onFinish();
} finally {
write.unlock();
}
}
private void replaceRange(L layer, Calendar time) {
Date floor = truncateToMinute(time.getTime());
Date ceil = roundUpToMinute(time.getTime());
SortedSet<Date> times = layer.getTimes();
Date earliest;
Date latest;
if (times.isEmpty()) {
earliest = floor;
latest = ceil;
} else {
Date lfirst = times.first();
Date llast = times.last();
earliest = lfirst.before(floor) ? lfirst : floor;
latest = llast.after(ceil) ? llast : ceil;
}
times.clear();
times.add(earliest);
times.add(latest);
}
private L getLayer() {
if (_layer == null) {
try {
List<L> res = store.getAll(layerClass);
if (!res.isEmpty()) {
_layer = res.get(0);
}
} catch (OgcException e) {
log.error("Problem reading layer from database", e);
}
if (_layer == null) {
_layer = newLayer();
}
}
return _layer;
}
/*
* (non-Javadoc)
*
* @see com.raytheon.uf.edex.ogc.common.db.LayerCollector#newLayer()
*/
@Override
protected L newLayer() {
L rval = super.newLayer();
initLayer(rval);
return rval;
}
protected void initLayer(L layer) {
layer.setName(layerName);
ReferencedEnvelope env = new ReferencedEnvelope(-180, 180, -90, 90,
MapUtil.LATLON_PROJECTION);
layer.setCrs84Bounds(JTS.toGeometry((Envelope) env));
layer.setTargetCrsCode("CRS:84");
layer.setTargetMaxx(env.getMaxX());
layer.setTargetMaxy(env.getMaxY());
layer.setTargetMinx(env.getMinX());
layer.setTargetMiny(env.getMinY());
}
public void updateDB() {
Lock read = lock.readLock();
read.lock();
try {
L layer = getLayer();
if (!layer.getTimes().isEmpty()) {
updateLayer(layer);
}
} catch (OgcException e) {
log.error("problem updating layer", e);
}
read.unlock();
}
protected abstract Calendar getTime(R record);
public void purgeExpired(Set<Date> timesToKeep) {
Lock write = lock.writeLock();
write.lock();
try {
L layer = getLayer();
SortedSet<Date> ltimes = layer.getTimes();
ltimes.clear();
if (!timesToKeep.isEmpty()) {
SortedSet<Date> incoming = new TreeSet<Date>(timesToKeep);
Date earliest = truncateToMinute(incoming.first());
Date latest = roundUpToMinute(incoming.last());
ltimes.add(earliest);
ltimes.add(latest);
}
try {
replaceTimes(layer);
} catch (OgcException e) {
log.error("problem purging expired layer times", e);
}
getAddon().onPurgeExpired(timesToKeep);
} finally {
write.unlock();
}
}
public void purgeAll() {
Lock write = lock.writeLock();
write.lock();
try {
L layer = getLayer();
layer.getTimes().clear();
try {
clearLayers(layerClass);
} catch (Exception e) {
log.error("problem purging layers", e);
}
} finally {
write.unlock();
}
}
/*
* (non-Javadoc)
*
* @see com.raytheon.uf.edex.ogc.common.db.LayerCache#getLayers()
*/
@Override
public List<L> getLayers() {
ArrayList<L> rval = new ArrayList<L>(1);
L copy = getCopy();
if (copy != null) {
rval.add(copy);
}
return rval;
}
private L getCopy() {
L rval = null;
Lock read = lock.readLock();
read.lock();
try {
L layer = getLayer();
if (!layer.getTimes().isEmpty()) {
rval = copy(layer);
}
} finally {
read.unlock();
}
return rval;
}
/*
* (non-Javadoc)
*
* @see
* com.raytheon.uf.edex.ogc.common.db.LayerCollector#copy(com.raytheon.uf
* .edex.ogc.common.db.SimpleLayer)
*/
@Override
protected L copy(L orig) {
L rval = newLayer();
// assume that only times are different
rval.getTimes().addAll(orig.getTimes());
return rval;
}
/*
* (non-Javadoc)
*
* @see
* com.raytheon.uf.edex.ogc.common.db.LayerCache#getLayer(java.lang.String)
*/
@Override
public L getLayer(String name) {
if (layerName.equals(name)) {
return getCopy();
} else {
return null;
}
}
@Override
public String getLayerName(R rec) {
return this.layerName;
}
}

View file

@ -1,55 +0,0 @@
/**
* 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.edex.ogc.common.feature;
import java.util.List;
import org.opengis.feature.simple.SimpleFeature;
import com.raytheon.uf.common.dataplugin.PluginDataObject;
/**
* Interface for creating geotools feature objects from data records
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Aug 16, 2011 bclement Initial creation
*
* </pre>
*
* @author bclement
* @version 1.0
*/
public interface FeatureFactory {
/**
* Create a simple feature from each plugin data object
*
* @param pdos
* @return
*/
public List<SimpleFeature> convert(PluginDataObject[] pdos);
}

View file

@ -1,154 +0,0 @@
/**
* Copyright 09/24/12 Raytheon Company.
*
* Unlimited Rights
* This software was developed pursuant to Contract Number
* DTFAWA-10-D-00028 with the US Government. The US Governments rights
* in and to this copyrighted software are as specified in DFARS
* 252.227-7014 which was made part of the above contract.
*/
package com.raytheon.uf.edex.ogc.common.feature;
import java.util.HashMap;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import com.raytheon.uf.common.http.MimeType;
import com.raytheon.uf.edex.ogc.common.InvalidVersionException;
import com.raytheon.uf.edex.ogc.common.Version;
/**
* Utility methods and constants for GML version parsing and comparison
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Oct 30, 2012 bclement Initial creation
*
* </pre>
*
* @author bclement
* @version 1.0
*/
public class GmlUtils {
public static final MimeType GML31_TYPE = new MimeType(
"application/gml+xml; version=3.1");
public static final MimeType GML32_TYPE = new MimeType(
"application/gml+xml; version=3.2");
public static final MimeType GML311_OLD_TYPE = new MimeType(
"text/xml; subtype=\"gml/3.1.1\"");
public static final MimeType GML321_OLD_TYPE = new MimeType(
"text/xml; subtype=\"gml/3.2.1\"");
public static final MimeType GML31_VND_TYPE = new MimeType(
"application/vnd.ogc.gml; version=3.1");
public static final MimeType GML32_VND_TYPE = new MimeType(
"application/vnd.ogc.gml; version=3.2");
protected static final Pattern subPattern = Pattern
.compile("^\\s*([a-zA-Z]+)/([0-9\\.]+).*$");
protected static final Pattern versionPattern = Pattern
.compile("^\\s*([0-9]+)\\.([0-9]+)\\.?([0-9]+)?.*$");
protected static final Map<Version, MimeType> versionMap;
static {
versionMap = new HashMap<Version, MimeType>();
versionMap.put(new Version(3, 1, 0), GML31_TYPE);
versionMap.put(new Version(3, 2, 0), GML32_TYPE);
}
/**
* @param type
* @return true if type is a form of gml
*/
public static boolean isGml(MimeType type){
if ( "application".equalsIgnoreCase(type.getType())){
if ("gml+xml".equalsIgnoreCase(type.getSubtype())) {
return true;
}
if ( "vnd.ogc.gml".equalsIgnoreCase(type.getSubtype())){
return true;
}
} else if ("text".equalsIgnoreCase(type.getType())
&& "xml".equals(type.getSubtype())) {
String param = type.getParam("subtype");
if (param != null && param.toLowerCase().startsWith("gml")) {
return true;
}
}
return false;
}
/**
* @param type
* @return null if type isn't gml or version is not found
*/
public static String getGmlVersion(MimeType type) {
if (!isGml(type)) {
return null;
}
String param = type.getParam("version");
if (param != null) {
return param;
}
param = type.getParam("subtype");
if (param != null) {
Matcher m = subPattern.matcher(param);
if (m.matches()) {
return m.group(2);
}
}
return null;
}
/**
* @param left
* @param right
* @return true if both are gml types with versions and those versions have
* the same major and minor versions
*/
public static boolean areCompatible(MimeType left, MimeType right){
String leftVStr = getGmlVersion(left);
String rightVStr = getGmlVersion(right);
if ( leftVStr == null || rightVStr == null){
return false;
}
try {
Version leftVersion = new Version(leftVStr);
Version rightVersion = new Version(rightVStr);
return leftVersion.equalsMajorMinor(rightVersion);
} catch (InvalidVersionException e) {
return false;
}
}
/**
* Find the supported GML version that matches the arguments major and minor
* version
*
* @param type
* @return null if no match found
*/
public static MimeType getMatchingGmlVersion(MimeType type) {
String vstr = getGmlVersion(type);
if (vstr == null) {
return null;
}
try{
Version version = new Version(vstr).majorMinorOnly();
return versionMap.get(version);
} catch (InvalidVersionException e){
return null;
}
}
}

View file

@ -1,127 +0,0 @@
/**
* 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.edex.ogc.common.feature;
import java.io.ByteArrayOutputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.List;
import org.geotools.data.memory.MemoryFeatureCollection;
import org.opengis.feature.simple.SimpleFeature;
import org.opengis.feature.simple.SimpleFeatureType;
import com.raytheon.uf.common.http.MimeType;
import com.raytheon.uf.common.json.geo.IGeoJsonService;
import com.raytheon.uf.common.json.geo.SimpleGeoJsonService;
import com.raytheon.uf.common.json.geo.MixedFeatureCollection;
import com.raytheon.uf.edex.ogc.common.OgcResponse;
import com.raytheon.uf.edex.ogc.common.OgcResponse.TYPE;
/**
* Converts simple features to GeoJSON
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Aug 9, 2011 bclement Initial creation
* Mar 11, 2014 #2718 randerso Changes for GeoTools 10.5
*
* </pre>
*
* @author bclement
* @version 1.0
*/
public class JsonFeatureFormatter implements SimpleFeatureFormatter {
public static MimeType mimeType = new MimeType("application/json");
protected IGeoJsonService jsonUtil = new SimpleGeoJsonService();
/*
* (non-Javadoc)
*
* @see
* com.raytheon.uf.edex.ogc.common.feature.SimpleFeatureFormatter#format
* (java.util.List, java.io.OutputStream)
*/
@Override
public void format(List<List<SimpleFeature>> features, OutputStream out)
throws Exception {
MixedFeatureCollection mixed = convert(features);
jsonUtil.serialize(mixed, out);
}
/*
* (non-Javadoc)
*
* @see
* com.raytheon.uf.edex.wms.format.SimpleFeatureFormatter#format(java.util
* .List)
*/
@Override
public OgcResponse format(List<List<SimpleFeature>> features)
throws Exception {
MixedFeatureCollection mixed = convert(features);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
jsonUtil.serialize(mixed, baos);
return new OgcResponse(baos.toString(), mimeType, TYPE.TEXT);
}
protected MixedFeatureCollection convert(List<List<SimpleFeature>> features) {
List<MemoryFeatureCollection> colls = new ArrayList<MemoryFeatureCollection>(
features.size());
for (List<SimpleFeature> l : features) {
if ((l != null) && !l.isEmpty()) {
SimpleFeatureType t = l.get(0).getFeatureType();
MemoryFeatureCollection c = new MemoryFeatureCollection(t);
c.addAll(l);
colls.add(c);
}
}
return new MixedFeatureCollection(colls);
}
/*
* (non-Javadoc)
*
* @see com.raytheon.uf.edex.wms.format.SimpleFeatureFormatter#getMimeType()
*/
@Override
public MimeType getMimeType() {
return mimeType;
}
/*
* (non-Javadoc)
*
* @see
* com.raytheon.uf.edex.ogc.common.feature.SimpleFeatureFormatter#matchesFormat
* (java.lang.String)
*/
@Override
public boolean matchesFormat(MimeType format) {
return mimeType.equalsIgnoreParams(format);
}
}

View file

@ -1,159 +0,0 @@
/**
* 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.edex.ogc.common.feature;
import java.util.Arrays;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlType;
import net.opengis.gml.v_3_1_1.DirectPositionType;
import net.opengis.gml.v_3_1_1.PointType;
import com.raytheon.uf.common.pointdata.spatial.SurfaceObsLocation;
/**
* ObsLocation OGC representation.
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Mar 24, 2013 1746 dhladky Initial creation
* Jul 23, 2014 3410 bclement location changed to floats
*
* </pre>
*
* @author dhladky
* @version 1.0
*/
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "obsLocation", propOrder = {
"location"
})
public class ObsLocation {
@XmlElement(required = true)
protected PointType location;
@XmlAttribute
protected String stationId;
@XmlAttribute
protected Integer elevation;
/**
* public cons
*/
public ObsLocation() {
}
public ObsLocation(SurfaceObsLocation sol) {
this.setStationId(sol.getStationId());
this.setElevation(sol.getElevation());
Double lat = sol.getLatitude().doubleValue();
Double lon = sol.getLongitude().doubleValue();
PointType point = new PointType();
DirectPositionType pos = new DirectPositionType();
pos.setValue(Arrays.asList(lon, lat));
point.setPos(pos);
this.setLocation(point);
}
/**
* Gets the value of the location property.
*
* @return
* possible object is
* {@link PointType }
*
*/
public PointType getLocation() {
return location;
}
/**
* Sets the value of the location property.
*
* @param value
* allowed object is
* {@link PointType }
*
*/
public void setLocation(PointType value) {
this.location = value;
}
/**
* Gets the value of the stationId property.
*
* @return
* possible object is
* {@link String }
*
*/
public String getStationId() {
return stationId;
}
/**
* Sets the value of the stationId property.
*
* @param value
* allowed object is
* {@link String }
*
*/
public void setStationId(String value) {
this.stationId = value;
}
/**
* Gets the value of the elevation property.
*
* @return
* possible object is
* {@link Integer }
*
*/
public Integer getElevation() {
return elevation;
}
/**
* Sets the value of the elevation property.
*
* @param value
* allowed object is
* {@link Integer }
*
*/
public void setElevation(Integer value) {
this.elevation = value;
}
}

View file

@ -1,291 +0,0 @@
/**
* 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.edex.ogc.common.feature;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
import org.geotools.data.DefaultTransaction;
import org.geotools.data.FeatureSource;
import org.geotools.data.FeatureStore;
import org.geotools.data.Transaction;
import org.geotools.data.memory.MemoryFeatureCollection;
import org.geotools.data.shapefile.ShapefileDataStore;
import org.geotools.data.shapefile.ShapefileDataStoreFactory;
import org.geotools.feature.FeatureCollection;
import org.opengis.feature.simple.SimpleFeature;
import org.opengis.feature.simple.SimpleFeatureType;
import sun.misc.IOUtils;
import com.raytheon.uf.common.http.MimeType;
import com.raytheon.uf.common.status.IUFStatusHandler;
import com.raytheon.uf.common.status.UFStatus;
import com.raytheon.uf.edex.ogc.common.OgcResponse;
import com.raytheon.uf.edex.ogc.common.OgcResponse.TYPE;
/**
* Convert simple features to shape files
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Feb 28, 2012 bclement Initial creation
*
* </pre>
*
* @author bclement
* @version 1.0
*/
public class ShpFeatureFormatter implements SimpleFeatureFormatter {
public static final MimeType mimeType = new MimeType("application/zip");
public static final MimeType zipType = new MimeType("shape-zip");
protected IUFStatusHandler log = UFStatus.getHandler(this.getClass());
protected byte[] buffer = new byte[1024 * 4];
/*
* (non-Javadoc)
*
* @see
* com.raytheon.uf.edex.ogc.common.feature.SimpleFeatureFormatter#format
* (java.util.List, java.io.OutputStream)
*/
@Override
public void format(List<List<SimpleFeature>> features, OutputStream out)
throws Exception {
FeatureCollection<SimpleFeatureType, SimpleFeature> coll = convert(features);
if (coll == null) {
return;
}
File tmpDir = createTempDir();
try {
writeShape(tmpDir, coll);
File zip = createZip(tmpDir);
readFile(zip, out);
} finally {
if (tmpDir != null && tmpDir.exists()) {
deleteDir(tmpDir);
}
}
}
/*
* (non-Javadoc)
*
* @see
* com.raytheon.uf.edex.ogc.common.feature.SimpleFeatureFormatter#format
* (java.util.List)
*/
@Override
public OgcResponse format(List<List<SimpleFeature>> features)
throws Exception {
FeatureCollection<SimpleFeatureType, SimpleFeature> coll = convert(features);
if (coll == null) {
return new OgcResponse(new byte[0], mimeType, TYPE.BYTE);
}
File tmpDir = createTempDir();
try {
writeShape(tmpDir, coll);
File zip = createZip(tmpDir);
byte[] bytes = readFile(zip);
return new OgcResponse(bytes, mimeType, TYPE.BYTE);
} finally {
if (tmpDir != null && tmpDir.exists()) {
deleteDir(tmpDir);
}
}
}
protected FeatureCollection<SimpleFeatureType, SimpleFeature> convert(
List<List<SimpleFeature>> features) {
List<FeatureCollection<SimpleFeatureType, SimpleFeature>> colls = new ArrayList<FeatureCollection<SimpleFeatureType, SimpleFeature>>(
features.size());
for (List<SimpleFeature> l : features) {
if (l != null && !l.isEmpty()) {
SimpleFeatureType t = l.get(0).getFeatureType();
MemoryFeatureCollection c = new MemoryFeatureCollection(t);
c.addAll(l);
colls.add(c);
}
}
// TODO handle multiple schemas
if (colls.size() > 1) {
log.error("Too many feature types sent to shapefile formatter");
}
if (colls.isEmpty()) {
return null;
}
return colls.get(0);
}
protected File createZip(File dir) throws IOException {
File rval = new File(dir, "res.zip");
ZipOutputStream out = null;
try {
out = new ZipOutputStream(new FileOutputStream(rval));
writeDirToZip(dir, rval, out);
} finally {
if (out != null) {
out.close();
}
}
return rval;
}
protected void writeDirToZip(File dir, File zip, ZipOutputStream out)
throws IOException {
for (File f : dir.listFiles()) {
if (f.equals(zip)) {
continue;
}
out.putNextEntry(new ZipEntry(f.getName()));
FileInputStream in = null;
try {
in = new FileInputStream(f);
copy(in, out);
} finally {
if (in != null) {
in.close();
}
out.closeEntry();
}
}
}
protected void copy(InputStream in, OutputStream out) throws IOException {
int read;
while ((read = in.read(buffer)) != -1) {
out.write(buffer, 0, read);
}
}
protected void deleteDir(File dir) {
File[] files = dir.listFiles();
for (File f : files) {
f.delete();
}
dir.delete();
}
protected static File createTempDir() throws Exception {
File sysTmp = new File(System.getProperty("java.io.tmpdir"));
String tstamp = "wfs" + System.currentTimeMillis() + "-";
for (int i = 0; i < 100; ++i) {
File rval = new File(sysTmp, tstamp + i);
if (rval.mkdir()) {
return rval;
}
}
throw new Exception("Unable to create temp directory");
}
protected byte[] readFile(File f) throws FileNotFoundException, IOException {
return IOUtils.readFully(new FileInputStream(f), -1, true);
}
protected void readFile(File f, OutputStream out) throws IOException {
FileInputStream fin = new FileInputStream(f);
try {
copy(fin, out);
} finally {
fin.close();
}
}
protected void writeShape(File dir,
FeatureCollection<SimpleFeatureType, SimpleFeature> coll)
throws Exception {
SimpleFeatureType schema = coll.getSchema();
ShapefileDataStoreFactory dataStoreFactory = new ShapefileDataStoreFactory();
File f = new File(dir, schema.getTypeName() + ".shp");
Map<String, Serializable> params = new HashMap<String, Serializable>();
params.put("url", f.toURI().toURL());
params.put("create spatial index", Boolean.TRUE);
ShapefileDataStore newDataStore = (ShapefileDataStore) dataStoreFactory
.createNewDataStore(params);
newDataStore.createSchema(schema);
Transaction transaction = new DefaultTransaction("create");
String typeName = newDataStore.getTypeNames()[0];
FeatureSource<SimpleFeatureType, SimpleFeature> featureSource = newDataStore
.getFeatureSource(typeName);
if (featureSource instanceof FeatureStore) {
FeatureStore<SimpleFeatureType, SimpleFeature> featureStore = (FeatureStore<SimpleFeatureType, SimpleFeature>) featureSource;
featureStore.setTransaction(transaction);
try {
featureStore.addFeatures(coll);
transaction.commit();
} catch (Exception problem) {
transaction.rollback();
throw problem;
} finally {
transaction.close();
}
}
}
/* (non-Javadoc)
* @see com.raytheon.uf.edex.ogc.common.feature.SimpleFeatureFormatter#getMimeType()
*/
@Override
public MimeType getMimeType() {
return mimeType;
}
/*
* (non-Javadoc)
*
* @see
* com.raytheon.uf.edex.ogc.common.feature.SimpleFeatureFormatter#matchesFormat
* (java.lang.String)
*/
@Override
public boolean matchesFormat(MimeType format) {
if (mimeType.equalsIgnoreParams(format)) {
return true;
}
if (format.equalsIgnoreParams(zipType)) {
return true;
}
return false;
}
}

View file

@ -1,78 +0,0 @@
/**
* 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.edex.ogc.common.feature;
import java.io.OutputStream;
import java.util.List;
import org.opengis.feature.simple.SimpleFeature;
import com.raytheon.uf.common.http.MimeType;
import com.raytheon.uf.edex.ogc.common.OgcResponse;
/**
* Interface for converting simple features to different output formats
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Aug 8, 2011 bclement Initial creation
*
* </pre>
*
* @author bclement
* @version 1.0
*/
public interface SimpleFeatureFormatter {
/**
* Format features and return in response wrapper
*
* @param features
* @return
* @throws Exception
*/
public OgcResponse format(List<List<SimpleFeature>> features)
throws Exception;
/**
* Format features and output to stream
*
* @param features
* @param out
* @throws Exception
*/
public void format(List<List<SimpleFeature>> features, OutputStream out)
throws Exception;
/**
* @return mime type supported by this formatter
*/
public MimeType getMimeType();
/**
* @param format
* @return true if this formatter is suitable for format
*/
public boolean matchesFormat(MimeType format);
}

View file

@ -1,43 +0,0 @@
/**
* Copyright 09/24/12 Raytheon Company.
*
* Unlimited Rights
* This software was developed pursuant to Contract Number
* DTFAWA-10-D-00028 with the US Government. The US Governments rights
* in and to this copyrighted software are as specified in DFARS
* 252.227-7014 which was made part of the above contract.
*/
package com.raytheon.uf.edex.ogc.common.filter;
import com.raytheon.uf.common.dataplugin.PluginDataObject;
/**
* Abstract base for in memory filtering of data records
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Feb 14, 2013 bclement Initial creation
*
* </pre>
*
* @author bclement
* @version 1.0
*/
public abstract class AbstractPdoFilter {
public abstract boolean matches(PluginDataObject pdo);
public static AbstractPdoFilter noFilter() {
return new AbstractPdoFilter() {
@Override
public boolean matches(PluginDataObject pdo) {
return true;
}
};
}
}

View file

@ -1,245 +0,0 @@
/**
* Copyright 09/24/12 Raytheon Company.
*
* Unlimited Rights
* This software was developed pursuant to Contract Number
* DTFAWA-10-D-00028 with the US Government. The US Governments rights
* in and to this copyrighted software are as specified in DFARS
* 252.227-7014 which was made part of the above contract.
*/
package com.raytheon.uf.edex.ogc.common.filter;
import java.lang.reflect.Field;
import java.math.BigDecimal;
import org.apache.commons.lang3.StringUtils;
import com.raytheon.uf.common.dataplugin.PluginDataObject;
import com.raytheon.uf.edex.ogc.common.util.ConvertService;
/**
* In memory data record filtering by standard comparison operators
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Feb 14, 2013 bclement Initial creation
*
* </pre>
*
* @author bclement
* @version 1.0
*/
public class ComparisonFilter extends AbstractPdoFilter {
public static enum CompOp {
EQ, LT, LTE, GT, GTE, NEQ, NULL
};
protected String field;
protected CompOp op;
protected Object value;
private volatile Field[] accessChain;
private final Object accessMutex = new Object();
/**
* @param field
* @param op
* @param value
*/
public ComparisonFilter(String field, CompOp op, Object value) {
this.field = field;
this.op = op;
this.value = value;
}
/**
* @param field
* @param op
* @param value
*/
public ComparisonFilter(String field, Object value) {
this(field, CompOp.EQ, value);
}
/**
*
*/
private ComparisonFilter() {
}
public static ComparisonFilter isNull(String field) {
ComparisonFilter rval = new ComparisonFilter();
rval.field = field;
rval.op = CompOp.NULL;
return rval;
}
@Override
public boolean matches(PluginDataObject pdo) {
if (accessChain == null) {
findField(pdo);
}
Object lhs = access(pdo);
if (lhs != null && value instanceof Number && lhs instanceof Number) {
return matchNumeric(lhs);
}
switch (op) {
case EQ:
return value.equals(lhs);
case NEQ:
return !value.equals(lhs);
case NULL:
return lhs == null;
default:
return true;
}
}
private boolean matchNumeric(Object lhs) {
BigDecimal left = new BigDecimal(lhs.toString());
BigDecimal right = new BigDecimal(value.toString());
int diff = left.compareTo(right);
switch (op) {
case GT:
return diff > 0;
case EQ:
return diff == 0;
case GTE:
return diff >= 0;
case LT:
return diff < 0;
case LTE:
return diff <= 0;
case NEQ:
return diff != 0;
default:
// TODO a return value of true disregards filter, a return of false
// may be a better option
return true;
}
}
private Object access(PluginDataObject pdo) throws IllegalArgumentException {
Object target = pdo;
for (Field f : accessChain) {
try {
if (target == null) {
return null;
}
target = f.get(target);
} catch (IllegalAccessException e) {
throw new IllegalArgumentException(e);
}
}
return target;
}
private void findField(PluginDataObject pdo) {
try {
synchronized (accessMutex) {
if (accessChain == null) {
Class<? extends PluginDataObject> c = pdo.getClass();
String[] fieldPath = StringUtils.split(field, '.');
accessChain = ConvertService.get().getFields(c, fieldPath);
}
}
} catch (Exception e) {
throw new IllegalArgumentException(e);
}
}
/**
* @return the field
*/
public String getField() {
return field;
}
/**
* @return the op
*/
public CompOp getOp() {
return op;
}
/**
* @return the value
*/
public Object getValue() {
return value;
}
/*
* (non-Javadoc)
*
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
if (op.equals(CompOp.NULL)) {
return "[" + field + " is NULL]";
}
return "[" + field + " " + op + " " + value + "]";
}
/*
* (non-Javadoc)
*
* @see java.lang.Object#hashCode()
*/
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((field == null) ? 0 : field.hashCode());
result = prime * result + ((op == null) ? 0 : op.hashCode());
result = prime * result + ((value == null) ? 0 : value.hashCode());
return result;
}
/*
* (non-Javadoc)
*
* @see java.lang.Object#equals(java.lang.Object)
*/
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
ComparisonFilter other = (ComparisonFilter) obj;
if (field == null) {
if (other.field != null) {
return false;
}
} else if (!field.equals(other.field)) {
return false;
}
if (op != other.op) {
return false;
}
if (value == null) {
if (other.value != null) {
return false;
}
} else if (!value.equals(other.value)) {
return false;
}
return true;
}
}

View file

@ -1,176 +0,0 @@
/**
* Copyright 09/24/12 Raytheon Company.
*
* Unlimited Rights
* This software was developed pursuant to Contract Number
* DTFAWA-10-D-00028 with the US Government. The US Governments rights
* in and to this copyrighted software are as specified in DFARS
* 252.227-7014 which was made part of the above contract.
*/
package com.raytheon.uf.edex.ogc.common.filter;
import java.util.Arrays;
import com.raytheon.uf.common.dataplugin.PluginDataObject;
/**
* In memory data record filtering that combines other filters using logical
* operators
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Feb 14, 2013 bclement Initial creation
*
* </pre>
*
* @author bclement
* @version 1.0
*/
public class LogicFilter extends AbstractPdoFilter {
public static enum LogicOp {
AND, OR, NOT
};
protected AbstractPdoFilter[] filters;
protected LogicOp op;
/**
* @param filters
* @param op
*/
public LogicFilter(LogicOp op, AbstractPdoFilter... filters) {
this.filters = filters;
this.op = op;
}
public static LogicFilter or(AbstractPdoFilter... filters) {
return new LogicFilter(LogicOp.OR, filters);
}
public static LogicFilter and(AbstractPdoFilter... filters) {
return new LogicFilter(LogicOp.AND, filters);
}
public static LogicFilter not(AbstractPdoFilter filter) {
return new LogicFilter(LogicOp.NOT, filter);
}
/*
* (non-Javadoc)
*
* @see
* com.raytheon.uf.edex.ogc.common.filter.AbstractFilterOp#matches(com.raytheon
* .uf.common.dataplugin.PluginDataObject)
*/
@Override
public boolean matches(PluginDataObject pdo) {
switch (op) {
case AND:
return and(pdo);
case OR:
return or(pdo);
case NOT:
return !filters[0].matches(pdo);
}
return false;
}
private boolean and(PluginDataObject pdo) {
for (AbstractPdoFilter filter : filters) {
if (!filter.matches(pdo)) {
return false;
}
}
return true;
}
private boolean or(PluginDataObject pdo) {
for (AbstractPdoFilter filter : filters) {
if (filter.matches(pdo)) {
return true;
}
}
return false;
}
/**
* @return the filters
*/
public AbstractPdoFilter[] getFilters() {
return filters;
}
/**
* @return the op
*/
public LogicOp getOp() {
return op;
}
/*
* (non-Javadoc)
*
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
if (op.equals(LogicOp.NOT)) {
return "[ NOT " + filters[0].toString() + "]";
}
StringBuilder builder = new StringBuilder();
if (filters.length < 1) {
return "[]";
} else {
builder.append("[").append(filters[0].toString());
}
for (int i = 1; i < filters.length; ++i) {
AbstractPdoFilter filter = filters[i];
builder.append(" " + op + " ");
builder.append(filter.toString());
}
builder.append("]");
return builder.toString();
}
/*
* (non-Javadoc)
*
* @see java.lang.Object#hashCode()
*/
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + Arrays.hashCode(filters);
result = prime * result + ((op == null) ? 0 : op.hashCode());
return result;
}
/*
* (non-Javadoc)
*
* @see java.lang.Object#equals(java.lang.Object)
*/
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
LogicFilter other = (LogicFilter) obj;
if (!Arrays.equals(filters, other.filters))
return false;
if (op != other.op)
return false;
return true;
}
}

View file

@ -1,411 +0,0 @@
/**
* Copyright 09/24/12 Raytheon Company.
*
* Unlimited Rights
* This software was developed pursuant to Contract Number
* DTFAWA-10-D-00028 with the US Government. The US Governments rights
* in and to this copyrighted software are as specified in DFARS
* 252.227-7014 which was made part of the above contract.
*/
package com.raytheon.uf.edex.ogc.common.filter;
import java.util.LinkedList;
import java.util.ListIterator;
import java.util.Map;
import org.apache.commons.collections.map.LRUMap;
import org.opengis.referencing.crs.CoordinateReferenceSystem;
import com.raytheon.uf.common.dataplugin.PluginDataObject;
import com.raytheon.uf.common.geospatial.ISpatialEnabled;
import com.raytheon.uf.common.geospatial.ISpatialObject;
import com.vividsolutions.jts.geom.Coordinate;
import com.vividsolutions.jts.geom.CoordinateFilter;
import com.vividsolutions.jts.geom.Geometry;
import com.vividsolutions.jts.geom.GeometryFactory;
import com.vividsolutions.jts.geom.LinearRing;
import com.vividsolutions.jts.geom.Polygon;
/**
* In memory data record filtering using spatial fields
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Feb 14, 2013 bclement Initial creation
*
* </pre>
*
* @author bclement
* @version 1.0
*/
public class SpatialFilter extends AbstractPdoFilter {
public static enum SpatialOp {
EQUALS, CONTAINS, COVERS, COVEREDBY, CROSSES, DISJOINT, INTERSECTS, OVERLAPS, TOUCHES, WITHIN
};
protected final Geometry geometry;
protected final SpatialOp op;
private static final Polygon CRS84_BOUNDS;
private static final GeometryFactory geomFact = new GeometryFactory();
@SuppressWarnings("unchecked")
private final Map<String, Boolean> cache = new LRUMap(32);
static {
Coordinate[] coords = new Coordinate[5];
coords[0] = new Coordinate(-180, 90);
coords[1] = new Coordinate(180, 90);
coords[2] = new Coordinate(180, -90);
coords[3] = new Coordinate(-180, -90);
coords[4] = coords[0];
LinearRing shell = geomFact.createLinearRing(coords);
CRS84_BOUNDS = geomFact.createPolygon(shell, new LinearRing[0]);
}
/**
* Geometry is assumed to be same CRS as PDO (CRS:84)
*
* @param geometry
* @param op
*/
public SpatialFilter(SpatialOp op, Geometry geometry) {
this.geometry = geometry;
this.op = op;
}
/*
* (non-Javadoc)
*
* @see
* com.raytheon.uf.edex.ogc.common.filter.AbstractFilterOp#matches(com.raytheon
* .uf.common.dataplugin.PluginDataObject)
*/
@Override
public boolean matches(PluginDataObject pdo) {
boolean rval = true;
if (geometry == null) {
return rval;
}
ISpatialObject spat;
if (pdo instanceof ISpatialEnabled) {
spat = ((ISpatialEnabled) pdo).getSpatialObject();
} else if (pdo instanceof ISpatialObject) {
spat = (ISpatialObject) pdo;
} else {
return rval;
}
String cacheKey = getCacheKey(spat);
synchronized (cache) {
Boolean cachedResult = cache.get(cacheKey);
if (cachedResult != null) {
return cachedResult;
}
}
if (!matchSpatial(spat)) {
rval = false;
}
synchronized (cache) {
cache.put(cacheKey, rval);
}
return rval;
}
/**
* Generate unique key for spatial object
*
* @param spat
* @return
*/
private static String getCacheKey(ISpatialObject spat) {
CoordinateReferenceSystem crs = spat.getCrs();
String rval = (crs == null ? "" : crs.toWKT());
Geometry geom = spat.getGeometry();
if (geom != null) {
rval = rval + geom.toText();
}
return rval;
}
/**
* Get geometries from internal bounds. Takes into account any needed
* adjustments to map to OGC bounds
*
* Assumes any geographic geometry is Lon/Lat order
*
* @param spat
* @return
*/
private static Geometry[] getGeometries(ISpatialObject spatial) {
// we don't support wrapping over the poles
Geometry copy = truncateYAxis(spatial.getGeometry());
// create multiple geometries that all fit inside CRS84 bounds
Geometry diff = copy.difference(CRS84_BOUNDS);
Geometry[] rval = new Geometry[diff.getNumGeometries() + 1];
rval[0] = copy.intersection(CRS84_BOUNDS);
for (int i = 0; i < diff.getNumGeometries(); ++i) {
rval[i + 1] = convertXAxis(diff.getGeometryN(i));
}
return merge(rval);
}
/**
* Attempt to merge any intersecting geometries
*
* @param geoms
* @return
*/
private static Geometry[] merge(Geometry[] geoms) {
if (geoms.length < 2) {
return geoms;
}
LinkedList<Geometry> blobs = new LinkedList<Geometry>();
blobs.add(geoms[0]);
for (int i = 1; i < geoms.length; ++i) {
Geometry geom = geoms[i];
ListIterator<Geometry> iter = blobs.listIterator();
while (iter.hasNext()) {
Geometry blob = iter.next();
if (blob.intersects(geom)) {
geom = blob.union(geom);
iter.remove();
}
}
blobs.add(geom);
}
return blobs.toArray(new Geometry[blobs.size()]);
}
/**
* Truncate geometry Y coordinates to fit between -90 and 90
*
* @param geom
*/
private static Geometry truncateYAxis(Geometry geom) {
Geometry rval = (Geometry) geom.clone();
rval.apply(new CoordinateFilter() {
@Override
public void filter(Coordinate coord) {
if (coord.y > 90) {
coord.y = 90;
} else if (coord.y < -90) {
coord.y = -90;
}
}
});
rval.geometryChanged();
return rval;
}
/**
* Convert geometry X coordinates to fit between -180 and 180
*
* @param geom
* @return
*/
private static Geometry convertXAxis(Geometry geom) {
Geometry rval = (Geometry) geom.clone();
rval.apply(new CoordinateFilter() {
@Override
public void filter(Coordinate coord) {
coord.x = ((coord.x + 180) % 360) - 180;
}
});
geom.geometryChanged();
return rval;
}
/**
* Return true if spatial object matches the geographic operator
*
* @param spat
* @return
*/
private boolean matchSpatial(ISpatialObject spat) {
if (spat.getGeometry() == null) {
return false;
}
Geometry[] geometries = getGeometries(spat);
return matchGeom(geometries);
}
protected static interface ForEach {
public boolean eval(Geometry other);
}
/**
* Return true if geometry matches the geographic operator
*
* @param other
* @return
*/
private boolean matchGeom(Geometry[] others) {
switch (op) {
case EQUALS:
return all(new ForEach() {
public boolean eval(Geometry other) {
return other.equals(geometry);
}
}, others);
case CONTAINS:
return any(new ForEach() {
public boolean eval(Geometry other) {
return other.contains(geometry);
}
}, others);
case COVERS:
return any(new ForEach() {
public boolean eval(Geometry other) {
return other.covers(geometry);
}
}, others);
case COVEREDBY:
return all(new ForEach() {
public boolean eval(Geometry other) {
return other.coveredBy(geometry);
}
}, others);
case CROSSES:
return any(new ForEach() {
public boolean eval(Geometry other) {
return other.crosses(geometry);
}
}, others);
case DISJOINT:
return all(new ForEach() {
public boolean eval(Geometry other) {
return other.disjoint(geometry);
}
}, others);
case INTERSECTS:
return any(new ForEach() {
public boolean eval(Geometry other) {
return other.intersects(geometry);
}
}, others);
case OVERLAPS:
return any(new ForEach() {
public boolean eval(Geometry other) {
return other.overlaps(geometry);
}
}, others);
case TOUCHES:
return any(new ForEach() {
public boolean eval(Geometry other) {
return other.touches(geometry);
}
}, others);
case WITHIN:
return all(new ForEach() {
public boolean eval(Geometry other) {
return other.within(geometry);
}
}, others);
default:
return true;
}
}
/**
* Return true if any of others evaluate true
*
* @param fe
* @param others
* @return
*/
private boolean any(ForEach fe, Geometry[] others) {
for (Geometry other : others) {
if (fe.eval(other)) {
return true;
}
}
return false;
}
/**
* Return true if all of other evaluate true
*
* @param fe
* @param others
* @return
*/
private boolean all(ForEach fe, Geometry[] others) {
for (Geometry other : others) {
if (!fe.eval(other)) {
return false;
}
}
return true;
}
/**
* @return the geometry
*/
public Geometry getGeometry() {
return geometry;
}
/**
* @return the op
*/
public SpatialOp getOp() {
return op;
}
/*
* (non-Javadoc)
*
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
return "[geometry " + op + " " + geometry + "]";
}
/*
* (non-Javadoc)
*
* @see java.lang.Object#hashCode()
*/
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result
+ ((geometry == null) ? 0 : geometry.toText().hashCode());
result = prime * result + ((op == null) ? 0 : op.hashCode());
return result;
}
/*
* (non-Javadoc)
*
* @see java.lang.Object#equals(java.lang.Object)
*/
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
SpatialFilter other = (SpatialFilter) obj;
if (geometry == null) {
if (other.geometry != null)
return false;
} else if (!geometry.equals(other.geometry))
return false;
if (op != other.op)
return false;
return true;
}
}

View file

@ -1,256 +0,0 @@
/**
* Copyright 09/24/12 Raytheon Company.
*
* Unlimited Rights
* This software was developed pursuant to Contract Number
* DTFAWA-10-D-00028 with the US Government. The US Governments rights
* in and to this copyrighted software are as specified in DFARS
* 252.227-7014 which was made part of the above contract.
*/
package com.raytheon.uf.edex.ogc.common.filter;
import java.util.Date;
import com.raytheon.uf.common.dataplugin.PluginDataObject;
import com.raytheon.uf.common.time.DataTime;
import com.raytheon.uf.common.time.TimeRange;
/**
* In memory data record filtering using time fields
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Feb 14, 2013 bclement Initial creation
*
* </pre>
*
* @author bclement
* @version 1.0
*/
public class TemporalFilter extends AbstractPdoFilter {
public static enum TimeOp {
AnyInteracts, After, Before, Begins, BegunBy, TContains, During, TEquals, TOverlaps, Meets, OverlappedBy, MetBy, Ends, EndedBy
};
protected DataTime time;
protected TimeOp op;
/**
* @param time
* @param op
*/
public TemporalFilter(TimeOp op, DataTime time) {
this.time = time;
this.op = op;
}
/*
* (non-Javadoc)
*
* @see
* com.raytheon.uf.edex.ogc.common.filter.AbstractFilterOp#matches(com.raytheon
* .uf.common.dataplugin.PluginDataObject)
*/
@Override
public boolean matches(PluginDataObject pdo) {
DataTime other = pdo.getDataTime();
if (other == null) {
return false;
}
TimeRange otherRange = other.getValidPeriod();
Date t1Start = otherRange.getStart();
Date t1End = otherRange.getEnd();
TimeRange range = time.getValidPeriod();
Date t2Start = range.getStart();
Date t2End = range.getEnd();
switch (op) {
case AnyInteracts:
if (isRange(time)) {
return beforeOrEqual(t1Start, t2End)
&& afterOrEqual(t1End, t2Start);
} else {
return beforeOrEqual(t1Start, t2Start)
&& afterOrEqual(t1End, t2End);
}
case After:
return t1Start.after(t2End);
case Before:
return t1End.before(t2Start);
case Begins:
if (isRange(time)) {
if (isRange(other)) {
return t1Start.equals(t2Start) && t1End.before(t2End);
} else {
return t1Start.equals(t2Start);
}
}
break;
case BegunBy:
if (isRange(other)) {
if (isRange(time)) {
return t1Start.equals(t2Start) && t1End.after(t2End);
} else {
return t1Start.equals(t2Start);
}
}
break;
case During:
if (isRange(time)) {
return t1Start.after(t2Start) && t1End.before(t2End);
}
break;
case EndedBy:
if (isRange(other)) {
if (isRange(time)) {
return t1Start.before(t2Start) && t1End.equals(t2End);
} else {
return t1End.equals(t2End);
}
}
break;
case Ends:
if (isRange(time)) {
if (isRange(other)) {
return t1Start.after(t2Start) && t1End.equals(t2End);
} else {
return t1End.equals(t2End);
}
}
break;
case Meets:
if (isRange(other) && isRange(time)) {
return t1End.equals(t2Start);
}
break;
case MetBy:
if (isRange(other) && isRange(time)) {
return t1Start.equals(t2End);
}
break;
case OverlappedBy:
if (isRange(other) && isRange(time)) {
return t1Start.after(t2Start) && t1Start.before(t2End)
&& t1End.after(t2End);
}
break;
case TContains:
if (isRange(other)) {
if (isRange(time)) {
return t1Start.before(t2Start) && t2End.before(t1End);
} else {
return t1Start.before(t2Start) && t1End.after(t2End);
}
}
break;
case TEquals:
if (!(isRange(other) ^ isRange(time))) {
return t1Start.equals(t2Start) && t1End.equals(t2End);
}
case TOverlaps:
if (isRange(other) && isRange(time)) {
return t1Start.before(t2Start) && t1End.after(t2Start)
&& t1End.before(t2End);
}
break;
}
return false;
}
/**
* @param one
* @param two
* @return true if one is before or equal to two
*/
public static boolean beforeOrEqual(Date one, Date two) {
return one.equals(two) || one.before(two);
}
/**
* @param one
* @param two
* @return true if one is after or equal to two
*/
public static boolean afterOrEqual(Date one, Date two) {
return one.equals(two) || one.after(two);
}
public static boolean isRange(DataTime time) {
return time.getUtilityFlags().contains(DataTime.FLAG.PERIOD_USED);
}
/**
* @return the time
*/
public DataTime getTime() {
return time;
}
/**
* @return the op
*/
public TimeOp getOp() {
return op;
}
/*
* (non-Javadoc)
*
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
String tstamp;
if (isRange(this.time)) {
tstamp = time.getValidPeriod().toString();
} else {
tstamp = time.getRefTime().toString();
}
return "[time " + op + " " + tstamp + "]";
}
/*
* (non-Javadoc)
*
* @see java.lang.Object#hashCode()
*/
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((op == null) ? 0 : op.hashCode());
result = prime * result + ((time == null) ? 0 : time.hashCode());
return result;
}
/*
* (non-Javadoc)
*
* @see java.lang.Object#equals(java.lang.Object)
*/
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
TemporalFilter other = (TemporalFilter) obj;
if (op != other.op)
return false;
if (time == null) {
if (other.time != null)
return false;
} else if (!time.equals(other.time))
return false;
return true;
}
}

View file

@ -1,125 +0,0 @@
/**
* Copyright 09/24/12 Raytheon Company.
*
* Unlimited Rights
* This software was developed pursuant to Contract Number
* DTFAWA-10-D-00028 with the US Government. The US Governments rights
* in and to this copyrighted software are as specified in DFARS
* 252.227-7014 which was made part of the above contract.
*/
package com.raytheon.uf.edex.ogc.common.filter;
import java.util.Map;
import javax.measure.unit.Unit;
import org.apache.commons.collections.map.LRUMap;
import com.raytheon.uf.common.dataplugin.PluginDataObject;
import com.raytheon.uf.edex.ogc.common.spatial.AltUtil;
import com.raytheon.uf.edex.ogc.common.spatial.VerticalCoordinate;
import com.raytheon.uf.edex.ogc.common.spatial.VerticalCoordinate.Reference;
import com.raytheon.uf.edex.ogc.common.spatial.VerticalEnabled;
import com.raytheon.uf.edex.ogc.common.spatial.VerticalSpatialFactory;
/**
* In memory data record filtering using vertical fields
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Apr 23, 2013 bclement Initial creation
*
* </pre>
*
* @author bclement
* @version 1.0
*/
public class VerticalFilter extends AbstractPdoFilter {
public static enum VerticalOp {
ABOVE, BELOW, BETWEEN
};
private final VerticalOp op;
private final VerticalCoordinate vert;
@SuppressWarnings("unchecked")
private final Map<Unit<?>, VerticalCoordinate> cache = new LRUMap(2);
/**
* @param op
* @param alt
*/
public VerticalFilter(VerticalOp op, VerticalCoordinate vert) {
this.op = op;
this.vert = vert;
cache.put(vert.getUnits(), vert);
}
/* (non-Javadoc)
* @see com.raytheon.uf.edex.ogc.common.filter.AbstractPdoFilter#matches(com.raytheon.uf.common.dataplugin.PluginDataObject)
*/
@SuppressWarnings("unchecked")
@Override
public boolean matches(PluginDataObject pdo) {
VerticalEnabled<PluginDataObject> enabled;
if (pdo instanceof VerticalEnabled<?>) {
enabled = (VerticalEnabled<PluginDataObject>) pdo;
} else if ( (enabled = (VerticalEnabled<PluginDataObject>) VerticalSpatialFactory
.getEnabled(pdo.getClass()))!= null) {
} else {
return false;
}
VerticalCoordinate left = enabled.getVerticalCoordinate(pdo);
if (left == null) {
return false;
}
VerticalCoordinate right;
try {
right = getConverted(left.getUnits(), left.getRef());
} catch (Exception e) {
// unable to convert
return false;
}
switch (op) {
case ABOVE:
return left.compareTo(right) > 0;
case BELOW:
return left.compareTo(right) < 0;
case BETWEEN:
return left.compareTo(right) == 0;
default:
return false;
}
}
private VerticalCoordinate getConverted(Unit<?> units, Reference ref) {
VerticalCoordinate rval = cache.get(units);
if (rval != null) {
return rval;
}
rval = AltUtil.convert(units, ref, vert);
cache.put(units, rval);
return rval;
}
/**
* @return the op
*/
public VerticalOp getOp() {
return op;
}
/**
* @return the vert
*/
public VerticalCoordinate getVert() {
return vert;
}
}

View file

@ -1,265 +0,0 @@
/**
* 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.edex.ogc.common.gml3_1_1;
import java.text.ParseException;
import java.util.Arrays;
import java.util.List;
import net.opengis.gml.v_3_1_1.CoordType;
import net.opengis.gml.v_3_1_1.CoordinatesType;
import net.opengis.gml.v_3_1_1.DirectPositionType;
import net.opengis.gml.v_3_1_1.EnvelopeType;
import org.apache.commons.lang3.StringUtils;
import com.raytheon.uf.edex.ogc.common.OgcException;
import com.raytheon.uf.edex.ogc.common.OgcException.Code;
import com.raytheon.uf.edex.ogc.common.spatial.CoordinateUtil;
import com.vividsolutions.jts.geom.Coordinate;
import com.vividsolutions.jts.geom.Envelope;
/**
* Convert GML 3.1.1 envelopes to JTS envelopes
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Apr 26, 2011 bclement Initial creation
*
* </pre>
*
* @author bclement
* @version 1.0
*/
public class EnvelopeConverter {
/**
* Returns number of dimensions in envelope
*
* @param env
* @return
* @throws Exception
*/
public static int getDims(EnvelopeType env) throws OgcException {
if (env.isSetSrsDimension() && env.getSrsDimension().intValue() > 1) {
return env.getSrsDimension().intValue();
}
if (env.isSetLowerCorner()) {
DirectPositionType lc = env.getLowerCorner();
return lc.getValue().size();
}
if (env.isSetCoord()) {
CoordType coord = env.getCoord().get(0);
int size = 0;
// this will be incorrect if dimensions aren't populated
// monotonically
size += coord.getX() != null ? 1 : 0;
size += coord.getY() != null ? 1 : 0;
size += coord.getZ() != null ? 1 : 0;
return size;
}
if (env.isSetCoordinates()) {
CoordinatesType coords = env.getCoordinates();
return StringUtils.split(coords.getValue()).length;
}
if (env.isSetPos()) {
DirectPositionType pos = env.getPos().get(0);
return pos.getValue().size();
}
throw new OgcException(Code.InvalidParameterValue,
"Unsupported envelope dimensions");
}
/**
* Convert GML envelope to JTS envelope
*
* @param env
* @return
* @throws Exception
*/
public Envelope convert(EnvelopeType env) throws OgcException {
Coordinate[] coords = getCoordinates(env);
return new Envelope(coords[0], coords[1]);
}
/**
* Convert GML envelope to JTS coordinates.
*
* @param env
* @param dims
* @return
* @throws Exception
*/
public Coordinate[] getCoordinates(EnvelopeType env) throws OgcException {
int dims = getDims(env);
if (env.isSetLowerCorner() && env.isSetUpperCorner()) {
return translate(env.getLowerCorner(), env.getUpperCorner(), dims);
}
if (env.isSetCoord()) {
return handleCoordList(env.getCoord(), dims);
}
if (env.isSetCoordinates()) {
return handleCoordinates(env.getCoordinates(), dims);
}
if (env.isSetPos()) {
return handlePosList(env.getPos(), dims);
}
throw new OgcException(Code.InvalidFormat,
"Unsupported envelope format");
}
/**
* Convert direct positions to JTS bounding box. Output will only include
* the number of dimensions specified in dims
*
* @param lower
* @param upper
* @param dims
* @return
* @throws Exception
*/
protected Coordinate[] translate(DirectPositionType lower,
DirectPositionType upper, int dims) throws OgcException {
List<Double> lowers = lower.getValue();
List<Double> uppers = upper.getValue();
if (lowers == null || uppers == null || lowers.size() < dims
|| uppers.size() < dims) {
throw new OgcException(Code.InvalidFormat,
"Unsupported envelope format");
}
Coordinate l;
Coordinate u;
if (dims == 2) {
l = new Coordinate(lowers.get(0), lowers.get(1));
u = new Coordinate(uppers.get(0), uppers.get(1));
} else if (dims == 3) {
l = new Coordinate(lowers.get(0), lowers.get(1), lowers.get(2));
u = new Coordinate(uppers.get(0), uppers.get(1), uppers.get(2));
} else {
throw new OgcException(Code.InvalidFormat,
"Unsupported envelope format");
}
return new Coordinate[] { l, u };
}
/**
* Convert list of direct positions to JTS coordinates. Output will only
* include the number of dimensions specified in dims
*
* @param pos
* @param dims
* @return
* @throws Exception
*/
private Coordinate[] handlePosList(List<DirectPositionType> pos, int dims)
throws OgcException {
return translate(pos.get(0), pos.get(1), dims);
}
/**
* Convert list of coords to JTS coordinates. Output will only include the
* number of dimensions specified in dims
*
* @param coords
* @param dims
* @return
* @throws Exception
*/
protected Coordinate[] handleCoordList(List<CoordType> coords, int dims)
throws OgcException {
CoordType c0 = coords.get(0);
CoordType c1 = coords.get(1);
return translate(createPos(c0), createPos(c1), dims);
}
/**
* Convert GML coordinates to JTS coordinates. Output will only include the
* number of dimensions specified in dims
*
* @param coordinates
* @param dims
* @return
* @throws Exception
*/
protected Coordinate[] handleCoordinates(CoordinatesType coordinates,
int dims) throws OgcException {
try {
List<Double[]> coords = CoordinateUtil.parseCoordinates(coordinates
.getValue());
return translate(createPos(coords.get(0)),
createPos(coords.get(1)), dims);
} catch (ParseException e) {
throw new OgcException(Code.InvalidFormat,
"Invalid coordinate string");
}
}
/**
* Create direct position type from double values in strings
*
* @param doubles
* @return
*/
protected DirectPositionType createPos(String[] doubles) {
Double[] rval = new Double[doubles.length];
for (int i = 0; i < doubles.length; ++i) {
rval[i] = Double.parseDouble(doubles[i]);
}
return createPos(rval);
}
/**
* Convert coordtype to direct position
*
* @param coord
* @return
* @throws Exception
*/
protected DirectPositionType createPos(CoordType coord) throws OgcException {
Double[] rval;
if (coord.isSetZ()) {
rval = new Double[] { coord.getX().doubleValue(),
coord.getY().doubleValue(), coord.getZ().doubleValue() };
} else if (coord.isSetY()) {
rval = new Double[] { coord.getX().doubleValue(),
coord.getY().doubleValue() };
} else {
rval = new Double[] { coord.getX().doubleValue() };
}
return createPos(rval);
}
/**
* Create direct position type from double values in strings
*
* @param doubles
* @return
*/
protected DirectPositionType createPos(Double... coords) {
DirectPositionType rval = new DirectPositionType();
rval.setValue(Arrays.asList(coords));
return rval;
}
}

View file

@ -1,62 +0,0 @@
/**
* 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.edex.ogc.common.gml3_1_1;
import net.opengis.gml.v_3_1_1.AbstractGeometryType;
import org.geotools.geometry.jts.JTS;
import org.jvnet.jaxb2_commons.locator.DefaultRootObjectLocator;
import org.jvnet.ogc.gml.v_3_1_1.jts.ConversionFailedException;
import org.jvnet.ogc.gml.v_3_1_1.jts.GML311ToJTSGeometryConverter;
import com.vividsolutions.jts.geom.Envelope;
import com.vividsolutions.jts.geom.Geometry;
import com.vividsolutions.jts.io.ParseException;
/**
* Converts GML 3.1.1 objects to JTS
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Apr 25, 2011 bclement Initial creation
*
* </pre>
*
* @author bclement
* @version 1.0
*/
public class GeometryConverter {
public Geometry convert(Envelope env) throws ParseException {
return JTS.toGeometry(env);
}
public Geometry convert(AbstractGeometryType value)
throws ConversionFailedException {
GML311ToJTSGeometryConverter converter = new GML311ToJTSGeometryConverter();
return converter.createGeometry(new DefaultRootObjectLocator(value),
value);
}
}

View file

@ -1,401 +0,0 @@
/**
* 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.edex.ogc.common.gml3_1_1;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import javax.xml.bind.JAXBElement;
import net.opengis.gml.v_3_1_1.AbstractCurveType;
import net.opengis.gml.v_3_1_1.AbstractGeometryType;
import net.opengis.gml.v_3_1_1.AbstractRingPropertyType;
import net.opengis.gml.v_3_1_1.AbstractRingType;
import net.opengis.gml.v_3_1_1.CoordType;
import net.opengis.gml.v_3_1_1.CurvePropertyType;
import net.opengis.gml.v_3_1_1.DirectPositionListType;
import net.opengis.gml.v_3_1_1.DirectPositionType;
import net.opengis.gml.v_3_1_1.LineStringPropertyType;
import net.opengis.gml.v_3_1_1.LineStringType;
import net.opengis.gml.v_3_1_1.LinearRingType;
import net.opengis.gml.v_3_1_1.MultiLineStringType;
import net.opengis.gml.v_3_1_1.MultiPointType;
import net.opengis.gml.v_3_1_1.MultiPolygonType;
import net.opengis.gml.v_3_1_1.PointArrayPropertyType;
import net.opengis.gml.v_3_1_1.PointPropertyType;
import net.opengis.gml.v_3_1_1.PointType;
import net.opengis.gml.v_3_1_1.PolygonPropertyType;
import net.opengis.gml.v_3_1_1.PolygonType;
import net.opengis.gml.v_3_1_1.RingType;
/**
* Converts GML 3.1.1 objects to Well Known Text
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Apr 25, 2011 bclement Initial creation
*
* </pre>
*
* @author bclement
* @version 1.0
*/
public abstract class GmlWktWriter {
protected static final Map<Class<? extends AbstractGeometryType>, GmlWktWriter> geomMap;
static {
geomMap = new HashMap<Class<? extends AbstractGeometryType>, GmlWktWriter>();
geomMap.put(PolygonType.class, new Polygon());
geomMap.put(MultiPolygonType.class, new MultiPolygon());
geomMap.put(PointType.class, new Point());
geomMap.put(MultiPointType.class, new MultiPoint());
geomMap.put(LinearRingType.class, new LinearRing());
geomMap.put(LineStringType.class, new LineString());
geomMap.put(MultiLineStringType.class, new MultiLineString());
}
public abstract String write(AbstractGeometryType geom) throws Exception;
public static String write(JAXBElement<AbstractGeometryType> elem)
throws Exception {
GmlWktWriter writer = geomMap.get(elem.getDeclaredType());
if (writer != null) {
return writer.write(elem.getValue());
} else {
throw new Exception("Unsupported geometry type: "
+ elem.getDeclaredType());
}
}
protected void addPolygon(PolygonType poly, StringBuilder sb)
throws Exception {
sb.append('(');
AbstractRingPropertyType value = poly.getExterior().getValue();
AbstractRingType ring = value.getRing().getValue();
addAbstractRing(ring, sb);
List<JAXBElement<AbstractRingPropertyType>> interior = poly
.getInterior();
if (interior != null && !interior.isEmpty()) {
sb.append(',');
addInterior(interior, sb);
}
sb.append(')');
}
/**
* @param interior
* @param sb
* @throws Exception
*/
protected void addInterior(
List<JAXBElement<AbstractRingPropertyType>> interior,
StringBuilder sb) throws Exception {
Iterator<JAXBElement<AbstractRingPropertyType>> i = interior.iterator();
sb.append('(');
addAbstractRing(i.next().getValue().getRing().getValue(), sb);
while (i.hasNext()) {
sb.append(',');
addAbstractRing(i.next().getValue().getRing().getValue(), sb);
}
}
protected void addAbstractRing(AbstractRingType ring, StringBuilder sb)
throws Exception {
if (ring instanceof LinearRingType) {
addLinearRing((LinearRingType) ring, sb);
} else if (ring instanceof RingType) {
addRing((RingType) ring, sb);
} else {
throw new Exception("Unsupported ring type" + ring.getClass());
}
}
/**
* @param ring
* @param sb
* @throws Exception
*/
private void addRing(RingType ring, StringBuilder sb) throws Exception {
List<CurvePropertyType> curvProps = ring.getCurveMember();
Iterator<CurvePropertyType> i = curvProps.iterator();
AbstractCurveType curve = i.next().getCurve().getValue();
if (curve instanceof LineStringType) {
addLineString((LineStringType) curve, sb);
} else {
throw new Exception("Unsupported curve type: " + curve.getClass());
}
}
/**
* @param ring
* @param sb
* @throws Exception
*/
private void addLinearRing(LinearRingType ring, StringBuilder sb)
throws Exception {
DirectPositionListType posList = ring.getPosList();
List<CoordType> coord = ring.getCoord();
List<JAXBElement<?>> elems = ring.getPosOrPointPropertyOrPointRep();
addLine(posList, elems, coord, sb);
}
protected void addLine(DirectPositionListType posList,
List<JAXBElement<?>> elems, List<CoordType> coord, StringBuilder sb)
throws Exception {
sb.append("(");
if (posList != null) {
addPosList(posList, sb);
} else if (elems != null) {
addMixedPos(elems, sb);
} else if (coord != null) {
addCoords(coord, sb);
} else {
throw new Exception("Unsupported LineString format");
}
sb.append(")");
}
/**
* @param coord
* @param sb
*/
protected void addCoords(List<CoordType> coord, StringBuilder sb) {
Iterator<CoordType> i = coord.iterator();
addPoint(convert(i.next()), sb);
while (i.hasNext()) {
sb.append(", ");
addPoint(convert(i.next()), sb);
}
}
protected void addLineString(LineStringType lst, StringBuilder sb)
throws Exception {
DirectPositionListType posList = lst.getPosList();
List<JAXBElement<?>> elems = lst.getPosOrPointPropertyOrPointRep();
addLine(posList, elems, null, sb);
}
protected void addMixedPos(List<JAXBElement<?>> elems, StringBuilder sb)
throws Exception {
Iterator<JAXBElement<?>> i = elems.iterator();
while (i.hasNext()) {
JAXBElement<?> elem = i.next();
Object value = elem.getValue();
List<Double> point = null;
if (value instanceof DirectPositionType) {
DirectPositionType pos = (DirectPositionType) value;
point = pos.getValue();
} else if (value instanceof PointPropertyType) {
PointPropertyType pointProp = (PointPropertyType) value;
DirectPositionType pos = pointProp.getPoint().getPos();
CoordType coord = pointProp.getPoint().getCoord();
if (pos != null) {
point = pos.getValue();
} else if (coord != null) {
point = convert(coord);
}
}
if (point == null) {
throw new Exception("Unsupported position type: "
+ value.getClass());
}
addPoint(point, sb);
if (i.hasNext()) {
sb.append(", ");
}
}
}
public void addPointPropList(List<PointPropertyType> pointProps,
StringBuilder sb) throws Exception {
Iterator<PointPropertyType> i = pointProps.iterator();
addPoint(i.next().getPoint(), sb);
while (i.hasNext()) {
sb.append(' ');
addPoint(i.next().getPoint(), sb);
}
}
public void addPointList(List<PointType> point, StringBuilder sb)
throws Exception {
Iterator<PointType> i = point.iterator();
addPoint(i.next(), sb);
while (i.hasNext()) {
sb.append(' ');
addPoint(i.next(), sb);
}
}
protected void addPoint(PointType point, StringBuilder sb) throws Exception {
DirectPositionType pos = point.getPos();
CoordType coord = point.getCoord();
if (pos != null) {
addPoint(pos.getValue(), sb);
} else if (coord != null) {
addPoint(convert(coord), sb);
} else {
throw new Exception("Unsupported point format");
}
}
protected void addPoint(List<Double> point, StringBuilder sb) {
Iterator<Double> j = point.iterator();
sb.append(j.next());
while (j.hasNext()) {
sb.append(" ");
sb.append(j.next());
}
}
protected List<Double> convert(CoordType coord) {
ArrayList<Double> rval = new ArrayList<Double>(3);
rval.add(coord.getX().doubleValue());
BigDecimal y = coord.getY();
BigDecimal z = coord.getZ();
if (y != null) {
rval.add(y.doubleValue());
if (z != null) {
rval.add(z.doubleValue());
}
}
return rval;
}
protected void addPosList(DirectPositionListType poslist, StringBuilder sb)
throws Exception {
int dim = poslist.getSrsDimension().intValue();
List<Double> value = poslist.getValue();
if (dim < 2 || value.size() % dim != 0) {
throw new Exception("Invalid dimensions for position list");
}
Iterator<Double> i = value.iterator();
while (i.hasNext()) {
sb.append(i.next());
for (int j = 0; j < dim; ++j) {
sb.append(" ");
sb.append(i.next());
}
if (i.hasNext()) {
sb.append(", ");
}
}
}
public static class LineString extends GmlWktWriter {
@Override
public String write(AbstractGeometryType geom) throws Exception {
LineStringType lst = (LineStringType) geom;
StringBuilder sb = new StringBuilder("LINESTRING ");
addLineString(lst, sb);
return sb.toString();
}
}
public static class MultiLineString extends GmlWktWriter {
@Override
public String write(AbstractGeometryType geom) throws Exception {
MultiLineStringType mlst = (MultiLineStringType) geom;
StringBuilder sb = new StringBuilder("MULTILINESTRING (");
Iterator<LineStringPropertyType> i = mlst.getLineStringMember()
.iterator();
addLineString(i.next().getLineString(), sb);
while (i.hasNext()) {
sb.append(',');
addLineString(i.next().getLineString(), sb);
}
sb.append(')');
return sb.toString();
}
}
public static class Point extends GmlWktWriter {
@Override
public String write(AbstractGeometryType geom) throws Exception {
PointType p = (PointType) geom;
StringBuilder sb = new StringBuilder("POINT (");
addPoint(p, sb);
sb.append(')');
return sb.toString();
}
}
public static class MultiPoint extends GmlWktWriter {
@Override
public String write(AbstractGeometryType geom) throws Exception {
MultiPointType mult = (MultiPointType) geom;
StringBuilder sb = new StringBuilder("MULTIPOINT (");
List<PointPropertyType> pointProps = mult.getPointMember();
PointArrayPropertyType array = mult.getPointMembers();
if (pointProps != null) {
addPointPropList(pointProps, sb);
}
if (array != null) {
addPointList(array.getPoint(), sb);
}
sb.append(')');
return sb.toString();
}
}
public static class Polygon extends GmlWktWriter {
@Override
public String write(AbstractGeometryType geom) throws Exception {
PolygonType poly = (PolygonType) geom;
StringBuilder sb = new StringBuilder("POLYGON ");
addPolygon(poly, sb);
return sb.toString();
}
}
public static class MultiPolygon extends GmlWktWriter {
@Override
public String write(AbstractGeometryType geom) throws Exception {
MultiPolygonType poly = (MultiPolygonType) geom;
StringBuilder sb = new StringBuilder("MULTIPOLYGON (");
List<PolygonPropertyType> value = poly.getPolygonMember();
Iterator<PolygonPropertyType> i = value.iterator();
addPolygon(i.next().getPolygon(), sb);
while (i.hasNext()) {
sb.append(',');
addPolygon(i.next().getPolygon(), sb);
}
sb.append(')');
return sb.toString();
}
}
public static class LinearRing extends GmlWktWriter {
@Override
public String write(AbstractGeometryType geom) throws Exception {
LinearRingType ring = (LinearRingType) geom;
StringBuilder sb = new StringBuilder("LINEARRING ");
addAbstractRing(ring, sb);
return sb.toString();
}
}
}

View file

@ -1,236 +0,0 @@
/**
* 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.edex.ogc.common.gml3_2_1;
import java.text.ParseException;
import java.util.Arrays;
import java.util.List;
import net.opengis.gml.v_3_1_1.CoordType;
import net.opengis.gml.v_3_2_1.CoordinatesType;
import net.opengis.gml.v_3_2_1.DirectPositionType;
import net.opengis.gml.v_3_2_1.EnvelopeType;
import org.apache.commons.lang3.StringUtils;
import com.raytheon.uf.edex.ogc.common.OgcException;
import com.raytheon.uf.edex.ogc.common.OgcException.Code;
import com.raytheon.uf.edex.ogc.common.spatial.CoordinateUtil;
import com.vividsolutions.jts.geom.Coordinate;
import com.vividsolutions.jts.geom.Envelope;
/**
* Converter for GML 3.2.1 envelopes to JTS envelopes
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Apr 26, 2011 bclement Initial creation
*
* </pre>
*
* @author bclement
* @version 1.0
*/
public class EnvelopeConverter {
/**
* Returns number of dimensions in envelope
*
* @param env
* @return
* @throws Exception
*/
public static int getDims(EnvelopeType env) throws OgcException {
if (env.isSetSrsDimension() && env.getSrsDimension().intValue() > 1) {
return env.getSrsDimension().intValue();
}
if (env.isSetLowerCorner()) {
DirectPositionType lc = env.getLowerCorner();
return lc.getValue().size();
}
if (env.isSetCoordinates()) {
CoordinatesType coords = env.getCoordinates();
return StringUtils.split(coords.getValue()).length;
}
if (env.isSetPos()) {
DirectPositionType pos = env.getPos().get(0);
return pos.getValue().size();
}
throw new OgcException(Code.InvalidParameterValue,
"Unsupported envelope dimensions");
}
/**
* Convert GML envelope to JTS envelope
*
* @param env
* @return
* @throws Exception
*/
public Envelope convert(EnvelopeType env) throws OgcException {
Coordinate[] coords = getCoordinates(env);
return new Envelope(coords[0], coords[1]);
}
/**
* Convert GML envelope to JTS coordinates.
*
* @param env
* @param dims
* @return
* @throws Exception
*/
public Coordinate[] getCoordinates(EnvelopeType env) throws OgcException {
int dims = getDims(env);
if (env.isSetLowerCorner() && env.isSetUpperCorner()) {
return translate(env.getLowerCorner(), env.getUpperCorner(), dims);
}
if (env.isSetCoordinates()) {
return handleCoordinates(env.getCoordinates(), dims);
}
if (env.isSetPos()) {
return handlePosList(env.getPos(), dims);
}
throw new OgcException(Code.InvalidFormat,
"Unsupported envelope format");
}
/**
* Convert direct positions to JTS bounding box. Output will only include
* the number of dimensions specified in dims
*
* @param lower
* @param upper
* @param dims
* @return
* @throws Exception
*/
protected Coordinate[] translate(DirectPositionType lower,
DirectPositionType upper, int dims) throws OgcException {
List<Double> lowers = lower.getValue();
List<Double> uppers = upper.getValue();
if (lowers == null || uppers == null || lowers.size() < dims
|| uppers.size() < dims) {
throw new OgcException(Code.InvalidFormat,
"Unsupported envelope format");
}
Coordinate l;
Coordinate u;
if (dims == 2) {
l = new Coordinate(lowers.get(0), lowers.get(1));
u = new Coordinate(uppers.get(0), uppers.get(1));
} else if (dims == 3) {
l = new Coordinate(lowers.get(0), lowers.get(1), lowers.get(2));
u = new Coordinate(uppers.get(0), uppers.get(1), uppers.get(2));
} else {
throw new OgcException(Code.InvalidFormat,
"Unsupported envelope format");
}
return new Coordinate[] { l, u };
}
/**
* Convert list of direct positions to JTS coordinates. Output will only
* include the number of dimensions specified in dims
*
* @param pos
* @param dims
* @return
* @throws Exception
*/
private Coordinate[] handlePosList(List<DirectPositionType> pos, int dims)
throws OgcException {
return translate(pos.get(0), pos.get(1), dims);
}
/**
* Convert GML coordinates to JTS coordinates. Output will only include the
* number of dimensions specified in dims
*
* @param coordinates
* @param dims
* @return
* @throws Exception
*/
protected Coordinate[] handleCoordinates(CoordinatesType coordinates,
int dims) throws OgcException {
try {
List<Double[]> coords = CoordinateUtil.parseCoordinates(coordinates
.getValue());
return translate(createPos(coords.get(0)),
createPos(coords.get(1)), dims);
} catch (ParseException e) {
throw new OgcException(Code.InvalidFormat,
"Invalid coordinate string");
}
}
/**
* Create direct position type from double values in strings
*
* @param doubles
* @return
*/
protected DirectPositionType createPos(String[] doubles) {
Double[] rval = new Double[doubles.length];
for (int i = 0; i < doubles.length; ++i) {
rval[i] = Double.parseDouble(doubles[i]);
}
return createPos(rval);
}
/**
* Convert coordtype to direct position
*
* @param coord
* @return
* @throws Exception
*/
protected DirectPositionType createPos(CoordType coord) throws OgcException {
Double[] rval;
if (coord.isSetZ()) {
rval = new Double[] { coord.getX().doubleValue(),
coord.getY().doubleValue(), coord.getZ().doubleValue() };
} else if (coord.isSetY()) {
rval = new Double[] { coord.getX().doubleValue(),
coord.getY().doubleValue() };
} else {
rval = new Double[] { coord.getX().doubleValue() };
}
return createPos(rval);
}
/**
* Create direct position type from double values in strings
*
* @param doubles
* @return
*/
protected DirectPositionType createPos(Double... coords) {
DirectPositionType rval = new DirectPositionType();
rval.setValue(Arrays.asList(coords));
return rval;
}
}

View file

@ -1,924 +0,0 @@
/**
* 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.edex.ogc.common.gml3_2_1;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import javax.xml.bind.JAXBElement;
import net.opengis.gml.v_3_2_1.AbstractCurveType;
import net.opengis.gml.v_3_2_1.AbstractGeometricAggregateType;
import net.opengis.gml.v_3_2_1.AbstractGeometricPrimitiveType;
import net.opengis.gml.v_3_2_1.AbstractGeometryType;
import net.opengis.gml.v_3_2_1.AbstractRingPropertyType;
import net.opengis.gml.v_3_2_1.AbstractRingType;
import net.opengis.gml.v_3_2_1.CoordinatesType;
import net.opengis.gml.v_3_2_1.CurveArrayPropertyType;
import net.opengis.gml.v_3_2_1.CurvePropertyType;
import net.opengis.gml.v_3_2_1.DirectPositionListType;
import net.opengis.gml.v_3_2_1.DirectPositionType;
import net.opengis.gml.v_3_2_1.GeometryArrayPropertyType;
import net.opengis.gml.v_3_2_1.GeometryPropertyType;
import net.opengis.gml.v_3_2_1.LineStringType;
import net.opengis.gml.v_3_2_1.LinearRingType;
import net.opengis.gml.v_3_2_1.MultiCurveType;
import net.opengis.gml.v_3_2_1.MultiGeometryType;
import net.opengis.gml.v_3_2_1.MultiPointType;
import net.opengis.gml.v_3_2_1.ObjectFactory;
import net.opengis.gml.v_3_2_1.PointArrayPropertyType;
import net.opengis.gml.v_3_2_1.PointPropertyType;
import net.opengis.gml.v_3_2_1.PointType;
import net.opengis.gml.v_3_2_1.PolygonType;
import org.apache.commons.lang3.ArrayUtils;
import org.geotools.geometry.jts.JTS;
import com.vividsolutions.jts.geom.Coordinate;
import com.vividsolutions.jts.geom.Envelope;
import com.vividsolutions.jts.geom.Geometry;
import com.vividsolutions.jts.geom.GeometryCollection;
import com.vividsolutions.jts.geom.GeometryFactory;
import com.vividsolutions.jts.geom.LineString;
import com.vividsolutions.jts.geom.LinearRing;
import com.vividsolutions.jts.geom.MultiLineString;
import com.vividsolutions.jts.geom.MultiPoint;
import com.vividsolutions.jts.geom.MultiPolygon;
import com.vividsolutions.jts.geom.Point;
import com.vividsolutions.jts.geom.Polygon;
import com.vividsolutions.jts.io.ParseException;
/**
* Converts between GML 3.2.1 and JTS geometries
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Apr 25, 2011 bclement Initial creation
*
* </pre>
*
* @author bclement
* @version 1.0
*/
public class GeometryConverter {
protected final GeometryFactory factory = new GeometryFactory();
protected final ObjectFactory gmlFactory = new ObjectFactory();
private static final String DIGIT_STR = "Ee-.0123456789";
private static final Set<Character> DIGIT_SET;
static {
char[] arr = DIGIT_STR.toCharArray();
HashSet<Character> set = new HashSet<Character>(
Arrays.asList(ArrayUtils.toObject(arr)));
DIGIT_SET = Collections.unmodifiableSet(set);
}
/**
* Supports geometry collection, polygon, point and linestring
*
* @param value
* @return
* @throws IllegalArgumentException
*/
public AbstractGeometryType convert(Geometry value)
throws IllegalArgumentException {
AbstractGeometryType rval;
if (value instanceof GeometryCollection) {
rval = convert((GeometryCollection) value);
} else if (value instanceof Polygon) {
rval = convert((Polygon) value);
} else if (value instanceof Point) {
rval = convert((Point) value);
} else if (value instanceof LineString) {
rval = convert((LineString) value);
} else {
throw new IllegalArgumentException("Unsupported geometry type: "
+ value.getClass());
}
return rval;
}
/**
* Only supports multipolygon, multipoint and multilinestring
*
* @param value
* @return
* @throws IllegalArgumentException
*/
public AbstractGeometricAggregateType convert(GeometryCollection value)
throws IllegalArgumentException {
AbstractGeometricAggregateType rval;
if (value instanceof MultiPolygon) {
rval = convert((MultiPolygon) value);
} else if (value instanceof MultiPoint) {
rval = convert((MultiPoint) value);
} else if (value instanceof MultiLineString) {
rval = convert((MultiLineString) value);
} else {
throw new IllegalArgumentException("Unsupported geometry type: "
+ value.getClass());
}
return rval;
}
/**
* @param value
* @return
* @throws IllegalArgumentException
*/
public MultiGeometryType convert(MultiPolygon value)
throws IllegalArgumentException {
MultiGeometryType rval = new MultiGeometryType();
int count = value.getNumGeometries();
List<GeometryPropertyType> members = new ArrayList<GeometryPropertyType>(
count);
for (int i = 0; i < count; ++i) {
GeometryPropertyType prop = new GeometryPropertyType();
Polygon p = (Polygon) value.getGeometryN(i);
PolygonType ptype = convert(p);
prop.setAbstractGeometry(gmlFactory.createAbstractGeometry(ptype));
members.add(prop);
}
rval.setGeometryMember(members);
return rval;
}
/**
* @param value
* @return
* @throws IllegalArgumentException
*/
public MultiPointType convert(MultiPoint value)
throws IllegalArgumentException {
MultiPointType rval = new MultiPointType();
int count = value.getNumGeometries();
List<PointPropertyType> members = new ArrayList<PointPropertyType>(
count);
for (int i = 0; i < count; ++i) {
PointPropertyType prop = new PointPropertyType();
Point p = (Point) value.getGeometryN(i);
PointType ptype = convert(p);
prop.setPoint(ptype);
members.add(prop);
}
rval.setPointMember(members);
return rval;
}
/**
* @param value
* @return
* @throws IllegalArgumentException
*/
public MultiCurveType convert(MultiLineString value)
throws IllegalArgumentException {
MultiCurveType rval = new MultiCurveType();
int count = value.getNumGeometries();
List<CurvePropertyType> members = new ArrayList<CurvePropertyType>(
count);
for (int i = 0; i < count; ++i) {
CurvePropertyType prop = new CurvePropertyType();
LineString ls = (LineString) value.getGeometryN(i);
LineStringType lstype = convert(ls);
prop.setAbstractCurve(gmlFactory.createAbstractCurve(lstype));
}
rval.setCurveMember(members);
return rval;
}
/**
* @param value
* @return
* @throws IllegalArgumentException
*/
public PolygonType convert(Polygon value) throws IllegalArgumentException {
PolygonType rval = new PolygonType();
AbstractRingPropertyType ext = new AbstractRingPropertyType();
LinearRingType ring = convertStringRing(value.getExteriorRing());
ext.setAbstractRing(gmlFactory.createAbstractRing(ring));
rval.setExterior(ext);
int holeCount = value.getNumInteriorRing();
List<AbstractRingPropertyType> holes = new ArrayList<AbstractRingPropertyType>(
holeCount);
for (int i = 0; i < holeCount; ++i) {
AbstractRingPropertyType prop = new AbstractRingPropertyType();
LineString hole = value.getInteriorRingN(i);
ring = convertStringRing(hole);
prop.setAbstractRing(gmlFactory.createAbstractRing(ring));
}
rval.setInterior(holes);
return rval;
}
/**
* @param value
* @return
* @throws IllegalArgumentException
*/
protected LinearRingType convertStringRing(LineString value)
throws IllegalArgumentException {
int dims = value.getDimension();
Coordinate[] coords = value.getCoordinates();
return ringFromCoords(dims, coords);
}
/**
* @param value
* @return
* @throws IllegalArgumentException
*/
protected LinearRingType convert(LinearRing value)
throws IllegalArgumentException {
int dims = value.getDimension();
Coordinate[] coords = value.getCoordinates();
return ringFromCoords(dims, coords);
}
/**
* @param dims
* number of dimensions in each coordinate
* @param coords
* @return
* @throws IllegalArgumentException
*/
protected LinearRingType ringFromCoords(int dims, Coordinate[] coords)
throws IllegalArgumentException {
LinearRingType rval = new LinearRingType();
DirectPositionListType posList = posListFromCoords(dims, coords);
rval.setPosList(posList);
return rval;
}
/**
* @param dims
* number of dimensions in each coordinate
* @param coords
* @return
* @throws IllegalArgumentException
*/
protected DirectPositionListType posListFromCoords(int dims,
Coordinate[] coords) throws IllegalArgumentException {
DirectPositionListType posList = new DirectPositionListType();
if (dims < 2 && coords.length > 0) {
// check for uninitialized dims
Coordinate sample = coords[0];
// 3 if sample.z is not NaN
// 2 if sample.z is NaN and sample.y is not NaN
dims = Double.isNaN(sample.z) ? 2 : 3;
}
posList.setCount(BigInteger.valueOf(coords.length));
posList.setSrsDimension(BigInteger.valueOf(dims));
List<Double> dubs;
if (dims == 2) {
dubs = convert2D(coords);
} else if (dims == 3) {
dubs = convert3D(coords);
} else {
throw new IllegalArgumentException(
"Unsupported number of dimensions: " + dims);
}
posList.setValue(dubs);
return posList;
}
/**
* @param coords
* 2D coordinates
* @return
*/
protected List<Double> convert2D(Coordinate... coords) {
List<Double> rval = new ArrayList<Double>(coords.length * 2);
for (Coordinate c : coords) {
rval.add(c.x);
rval.add(c.y);
}
return rval;
}
/**
* @param coords
* 3D coodinates
* @return
*/
protected List<Double> convert3D(Coordinate... coords) {
List<Double> rval = new ArrayList<Double>(coords.length * 3);
for (Coordinate c : coords) {
rval.add(c.x);
rval.add(c.y);
rval.add(c.z);
}
return rval;
}
/**
* @param value
* @return
* @throws IllegalArgumentException
*/
public PointType convert(Point value) throws IllegalArgumentException {
PointType rval = new PointType();
int dims = value.getDimension();
DirectPositionType pos = posFromCoord(dims, value.getCoordinate());
rval.setPos(pos);
return rval;
}
/**
* @param dims
* number of dimensions in coordinate
* @param c
* @return
* @throws IllegalArgumentException
*/
protected DirectPositionType posFromCoord(int dims, Coordinate c)
throws IllegalArgumentException {
DirectPositionType rval = new DirectPositionType();
if (dims == 0) {
// check for uninitialized dims
dims = Double.isNaN(c.z) ? 2 : 3;
}
if (dims == 2) {
rval.setValue(convert2D(c));
} else if (dims == 3) {
rval.setValue(convert3D(c));
} else {
throw new IllegalArgumentException(
"Unsupported number of dimensions: " + dims);
}
return rval;
}
/**
* @param value
* @return
* @throws IllegalArgumentException
*/
public LineStringType convert(LineString value)
throws IllegalArgumentException {
LineStringType rval = new LineStringType();
int dims = value.getDimension();
Coordinate[] coords = value.getCoordinates();
DirectPositionListType posList = posListFromCoords(dims, coords);
rval.setPosList(posList);
return rval;
}
/**
* @param env
* @return
* @throws ParseException
*/
public Geometry convert(Envelope env) throws ParseException {
return JTS.toGeometry(env);
}
/**
* @param value
* @return
* @throws Exception
*/
public Geometry convert(AbstractGeometryType value) throws Exception {
Geometry rval;
if (value instanceof AbstractGeometricAggregateType) {
rval = convert((AbstractGeometricAggregateType) value);
} else if (value instanceof AbstractGeometricPrimitiveType) {
rval = convert((AbstractGeometricPrimitiveType) value);
} else {
throw new Exception("Unsupported Geometry type: "
+ value.getClass());
}
return rval;
}
/**
* Supports multipoint, multilinestring and multipolygon
*
* @param agg
* @return
* @throws Exception
*/
public GeometryCollection convert(AbstractGeometricAggregateType agg)
throws Exception {
GeometryCollection rval;
if (agg instanceof MultiGeometryType) {
rval = convert((MultiGeometryType) agg);
} else if (agg instanceof MultiPointType) {
rval = convert((MultiPointType) agg);
} else if (agg instanceof MultiCurveType) {
rval = convert((MultiCurveType) agg);
} else {
throw new Exception("Unsupported geometry aggregate type: "
+ agg.getClass());
}
return rval;
}
/**
* Only supports multilinestring
*
* @param multiCurve
* @return
* @throws Exception
*/
public MultiLineString convert(MultiCurveType multiCurve) throws Exception {
List<AbstractCurveType> curves = new ArrayList<AbstractCurveType>();
if (multiCurve.isSetCurveMember()) {
List<CurvePropertyType> members = multiCurve.getCurveMember();
for (CurvePropertyType cpt : members) {
curves.add(cpt.getAbstractCurve().getValue());
}
}
if (multiCurve.isSetCurveMembers()) {
CurveArrayPropertyType members = multiCurve.getCurveMembers();
List<JAXBElement<? extends AbstractCurveType>> elems = members
.getAbstractCurve();
for (JAXBElement<? extends AbstractCurveType> e : elems) {
curves.add(e.getValue());
}
}
LineString[] lineStrings = new LineString[curves.size()];
Iterator<AbstractCurveType> iter = curves.iterator();
for (int i = 0; iter.hasNext(); ++i) {
AbstractCurveType curve = iter.next();
if (!(curve instanceof LineStringType)) {
throw new Exception("Unsupported multicurve member type: "
+ curve.getClass());
}
lineStrings[i] = convert((LineStringType) curve);
}
return factory.createMultiLineString(lineStrings);
}
/**
*
* @param multiPoint
* @return
* @throws Exception
*/
public MultiPoint convert(MultiPointType multiPoint) throws Exception {
List<PointType> points = new ArrayList<PointType>();
if (multiPoint.isSetPointMember()) {
List<PointPropertyType> members = multiPoint.getPointMember();
for (PointPropertyType ppt : members) {
points.add(ppt.getPoint());
}
}
if (multiPoint.isSetPointMembers()) {
PointArrayPropertyType members = multiPoint.getPointMembers();
points.addAll(members.getPoint());
}
Point[] rval = new Point[points.size()];
Iterator<PointType> iter = points.iterator();
for (int i = 0; iter.hasNext(); ++i) {
PointType ptype = iter.next();
rval[i] = convert(ptype);
}
return factory.createMultiPoint(rval);
}
/**
* Only supports multipolygon
*
* @param multiGeom
* @return
* @throws Exception
*/
public MultiPolygon convert(MultiGeometryType multiGeom) throws Exception {
List<AbstractGeometryType> geoms = new ArrayList<AbstractGeometryType>();
if (multiGeom.isSetGeometryMember()) {
List<GeometryPropertyType> members = multiGeom.getGeometryMember();
for (GeometryPropertyType gpt : members) {
geoms.add(gpt.getAbstractGeometry().getValue());
}
}
if (multiGeom.isSetGeometryMembers()) {
GeometryArrayPropertyType members = multiGeom.getGeometryMembers();
List<JAXBElement<? extends AbstractGeometryType>> elems = members
.getAbstractGeometry();
for (JAXBElement<? extends AbstractGeometryType> e : elems) {
geoms.add(e.getValue());
}
}
Polygon[] polys = new Polygon[geoms.size()];
Iterator<AbstractGeometryType> iter = geoms.iterator();
for (int i = 0; iter.hasNext(); ++i) {
AbstractGeometryType geom = iter.next();
if (geom instanceof AbstractGeometricAggregateType) {
throw new Exception("Nested geometry aggregates not supported");
}
if (!(geom instanceof PolygonType)) {
throw new Exception("Unsupported multi geometry type: "
+ geom.getClass());
}
PolygonType ptype = (PolygonType) geom;
polys[i] = convert(ptype);
}
return factory.createMultiPolygon(polys);
}
/**
* Supports point, linestring and polygon
*
* @param primitive
* @return
* @throws Exception
*/
public Geometry convert(AbstractGeometricPrimitiveType primitive)
throws Exception {
Geometry rval;
if (primitive instanceof LineStringType) {
rval = convert((LineStringType) primitive);
} else if (primitive instanceof PolygonType) {
rval = convert((PolygonType) primitive);
} else if (primitive instanceof PointType) {
rval = convert((PointType) primitive);
} else {
throw new Exception("Unsupported Geometry type: "
+ primitive.getClass());
}
return rval;
}
/**
* @param point
* @return
* @throws Exception
*/
public Point convert(PointType point) throws Exception {
Coordinate coord;
if (point.isSetCoordinates()) {
CoordinatesType ct = point.getCoordinates();
coord = convert(ct)[0];
} else if (point.isSetPos()) {
DirectPositionType pos = point.getPos();
coord = convert(pos);
} else {
throw new Exception("Unable to find coordinate for point: " + point);
}
return factory.createPoint(coord);
}
/**
* @param poly
* @return
* @throws Exception
*/
public Polygon convert(PolygonType poly) throws Exception {
AbstractRingPropertyType exterior = poly.getExterior();
LinearRing shell = convert(exterior);
List<AbstractRingPropertyType> interior = poly.getInterior();
LinearRing[] holes = new LinearRing[interior.size()];
Iterator<AbstractRingPropertyType> iter = interior.iterator();
for (int i = 0; iter.hasNext(); ++i) {
holes[i] = convert(iter.next());
}
return factory.createPolygon(shell, holes);
}
/**
* @param ring
* @return
* @throws Exception
*/
public LinearRing convert(AbstractRingPropertyType ring) throws Exception {
JAXBElement<? extends AbstractRingType> abs = ring.getAbstractRing();
AbstractRingType value = abs.getValue();
if (value instanceof LinearRingType) {
return convert((LinearRingType) value);
} else {
throw new Exception("Unsupported ring type: " + ring.getClass());
}
}
/**
* @param ring
* @return
* @throws Exception
*/
public LinearRing convert(LinearRingType ring) throws Exception {
Coordinate[] coords;
if (ring.isSetCoordinates()) {
CoordinatesType ctype = ring.getCoordinates();
coords = convert(ctype);
} else if (ring.isSetPosList()) {
DirectPositionListType posList = ring.getPosList();
coords = convert(posList);
} else if (ring.isSetPosOrPointPropertyOrPointRep()) {
List<JAXBElement<?>> innerChoice = ring
.getPosOrPointPropertyOrPointRep();
coords = convertPosOrPointChoice(innerChoice);
} else {
throw new Exception("Unable to find coordinates for ring: " + ring);
}
return factory.createLinearRing(coords);
}
/**
* @param line
* @return
* @throws Exception
*/
public LineString convert(LineStringType line) throws Exception {
Coordinate[] coords;
if (line.isSetCoordinates()) {
CoordinatesType ctype = line.getCoordinates();
coords = convert(ctype);
} else if (line.isSetPosList()) {
DirectPositionListType posList = line.getPosList();
coords = convert(posList);
} else if (line.isSetPosOrPointPropertyOrPointRep()) {
List<JAXBElement<?>> innerChoice = line
.getPosOrPointPropertyOrPointRep();
coords = convertPosOrPointChoice(innerChoice);
} else {
throw new Exception("Unable to find coordinates for line: " + line);
}
return factory.createLineString(coords);
}
/**
* Converts list of Pos (DirectPositionType), PointPropertyType or PointType
* elements to list of coordinates
*
* @param list
* @return
* @throws Exception
*/
protected Coordinate[] convertPosOrPointChoice(List<JAXBElement<?>> list)
throws Exception {
Coordinate[] rval = new Coordinate[list.size()];
Iterator<JAXBElement<?>> iter = list.iterator();
for (int i = 0; iter.hasNext(); ++i) {
JAXBElement<?> elem = iter.next();
Object obj = elem.getValue();
if (obj instanceof DirectPositionType) {
DirectPositionType dpt = (DirectPositionType) obj;
rval[i] = convert(dpt);
} else if (obj instanceof PointPropertyType) {
PointPropertyType ppt = (PointPropertyType) obj;
rval[i] = convert(ppt);
} else if (obj instanceof PointType) {
rval[i] = convertToCoord((PointType) obj);
}
}
return rval;
}
/**
* @param ppt
* @return
* @throws Exception
*/
protected Coordinate convert(PointPropertyType ppt) throws Exception {
PointType point = ppt.getPoint();
return convertToCoord(point);
}
/**
* @param point
* @return
* @throws Exception
*/
protected Coordinate convertToCoord(PointType point) throws Exception {
Coordinate rval;
if (point.isSetCoordinates()) {
CoordinatesType coordinates = point.getCoordinates();
rval = convert(coordinates)[0];
} else if (point.isSetPos()) {
DirectPositionType pos = point.getPos();
rval = convert(pos);
} else {
throw new Exception("Unable to find coordinates for point: "
+ point);
}
return rval;
}
/**
* @param pos
* @return
*/
protected Coordinate convert(DirectPositionType pos) {
Coordinate rval;
int dims = 2;
if (pos.isSetSrsDimension()) {
dims = pos.getSrsDimension().intValue();
}
List<Double> value = pos.getValue();
double x = value.get(0);
double y = value.get(1);
if (dims == 2) {
rval = new Coordinate(x, y);
} else {
rval = new Coordinate(x, y, value.get(3));
}
return rval;
}
/**
* @param posList
* @return
* @throws Exception
*/
protected Coordinate[] convert(DirectPositionListType posList)
throws Exception {
int len;
int dims;
List<Double> doubles = posList.getValue();
if (posList.isSetCount()) {
len = posList.getCount().intValue();
dims = posList.getSrsDimension().intValue();
} else {
// default 2D TODO should use outer geom SRS dim
dims = 2;
len = doubles.size() / dims;
}
if (dims < 2 || dims > 3) {
throw new Exception("Unsupported number of dimensions: " + dims);
}
if (dims * len != doubles.size()) {
throw new Exception("Invalid pos list");
}
Coordinate[] rval = new Coordinate[len];
Iterator<Double> iter = doubles.iterator();
for (int i = 0; iter.hasNext(); ++i) {
double x = iter.next();
double y = iter.next();
if (dims == 2) {
rval[i] = new Coordinate(x, y);
} else {
rval[i] = new Coordinate(x, y, iter.next());
}
}
return rval;
}
/**
* Ensure that a string only contains one character
*
* @param str
* string containing character
* @param isSet
* if false, returns fallback
* @param fallback
* default character for use if string is not set
* @return
* @throws Exception
* if string isn't 1 character long and is set
*/
protected Character ensureChar(String str, boolean isSet, Character fallback)
throws Exception {
if (!isSet) {
return fallback;
}
if (str.length() != 1) {
throw new Exception("Invalid character string length: " + str);
}
return str.charAt(0);
}
/**
* states for coordinate conversion state machine
*/
protected static enum CoordState {
START, NUM, BETWEEN, OUTER, INNER
}
/**
* @param ctype
* @return
* @throws Exception
*/
protected Coordinate[] convert(CoordinatesType ctype) throws Exception {
String value = ctype.getValue();
Character innerSeparator = ensureChar(ctype.getCs(), ctype.isSetCs(),
',');
Character outerSeparator = ensureChar(ctype.getTs(), ctype.isSetTs(),
' ');
String decimal = ".";
if (ctype.isSetDecimal()) {
decimal = ctype.getDecimal();
if (!decimal.equals(".")) {
value = value.replace(decimal, ".");
}
}
int len = value.length();
StringBuilder sb = new StringBuilder();
CoordState state = CoordState.START;
ArrayList<Double> nums = new ArrayList<Double>(3);
List<Coordinate> coords = new ArrayList<Coordinate>();
for (int i = 0; i < len; ++i) {
char c = value.charAt(i);
switch (state) {
case START:
if (isNumber(c)) {
state = CoordState.NUM;
sb.append(c);
}
break;
case NUM:
if (isNumber(c)) {
sb.append(c);
} else {
if (innerSeparator.equals(c)) {
state = CoordState.INNER;
} else if (outerSeparator.equals(c)) {
state = CoordState.OUTER;
} else {
state = CoordState.BETWEEN;
}
nums.add(Double.parseDouble(sb.toString()));
sb = new StringBuilder();
}
break;
case BETWEEN:
if (isNumber(c)) {
throw new Exception("Invalid coordinates string: " + value);
} else if (innerSeparator.equals(c)) {
state = CoordState.INNER;
} else if (outerSeparator.equals(c)) {
state = CoordState.OUTER;
}
break;
case OUTER:
if (isNumber(c)) {
sb.append(c);
state = CoordState.NUM;
coords.add(convert(nums));
} else if (innerSeparator.equals(c)) {
state = CoordState.INNER;
}
break;
case INNER:
if (isNumber(c)) {
sb.append(c);
state = CoordState.NUM;
}
break;
}
}
if (state.equals(CoordState.NUM)) {
nums.add(Double.parseDouble(sb.toString()));
}
coords.add(convert(nums));
return coords.toArray(new Coordinate[coords.size()]);
}
/**
* @param c
* @return true if c is a valid character used in representing a number
*/
protected boolean isNumber(Character c) {
return DIGIT_SET.contains(c);
}
/**
* @param nums
* @return
* @throws Exception
*/
protected Coordinate convert(List<Double> nums) throws Exception {
Coordinate rval;
if (nums.size() == 2) {
rval = new Coordinate(nums.get(0), nums.get(1));
} else if (nums.size() == 3) {
rval = new Coordinate(nums.get(0), nums.get(1), nums.get(2));
} else {
throw new Exception("Unsupported dimension length: " + nums.size());
}
nums.clear();
return rval;
}
}

View file

@ -1,155 +0,0 @@
/**
* Copyright 09/24/12 Raytheon Company.
*
* Unlimited Rights
* This software was developed pursuant to Contract Number
* DTFAWA-10-D-00028 with the US Government. The US Governments rights
* in and to this copyrighted software are as specified in DFARS
* 252.227-7014 which was made part of the above contract.
*/
package com.raytheon.uf.edex.ogc.common.http;
/**
* Endpoint information client used when connecting to service
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Oct 26, 2012 bclement Initial creation
*
* </pre>
*
* @author bclement
* @version 1.0
*/
public class EndpointInfo {
protected String protocol;
protected String host;
protected int port;
protected String path;
protected String encoding;
protected boolean postOnly = true;
/**
* @param protocol
* @param host
* @param port
* @param path
*/
public EndpointInfo(String protocol, String host, int port, String path) {
this.protocol = protocol;
this.host = host;
this.port = port;
this.path = path;
}
/**
* @param host
* @param port
* @param path
*/
public EndpointInfo(String host, int port, String path) {
this("http", host, port, path);
}
/**
* @return the protocol
*/
public String getProtocol() {
return protocol;
}
/**
* @param protocol
* the protocol to set
*/
public void setProtocol(String protocol) {
this.protocol = protocol;
}
/**
* @return the host
*/
public String getHost() {
return host;
}
/**
* @param host
* the host to set
*/
public void setHost(String host) {
this.host = host;
}
/**
* @return the port
*/
public int getPort() {
return port;
}
/**
* @param port
* the port to set
*/
public void setPort(int port) {
this.port = port;
}
/**
* @return the path
*/
public String getPath() {
return path;
}
/**
* @param path
* the path to set
*/
public void setPath(String path) {
this.path = path;
}
/**
* @return the encoding
*/
public String getEncoding() {
return encoding;
}
/**
* @param encoding
* the encoding to set
*/
public void setEncoding(String encoding) {
this.encoding = encoding;
}
/**
* @return the postOnly
*/
public boolean isPostOnly() {
return postOnly;
}
/**
* @param postOnly
* the postOnly to set
*/
public void setPostOnly(boolean postOnly) {
this.postOnly = postOnly;
}
}

View file

@ -1,38 +0,0 @@
/**
* Copyright 09/24/12 Raytheon Company.
*
* Unlimited Rights
* This software was developed pursuant to Contract Number
* DTFAWA-10-D-00028 with the US Government. The US Governments rights
* in and to this copyrighted software are as specified in DFARS
* 252.227-7014 which was made part of the above contract.
*/
package com.raytheon.uf.edex.ogc.common.http;
/**
* Interface for pooling OGC http handlers.
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Oct 31, 2012 bclement Initial creation
* Oct 23, 2015 #5004 dgilling Add types to interface methods.
*
* </pre>
*
* @author bclement
* @version 1.0
*/
public interface IOgcHttpPooler {
public OgcHttpHandler borrowObject(Long key);
public void returnObject(Long key, OgcHttpHandler borrowed);
public void drain();
}

View file

@ -1,131 +0,0 @@
/*****************************************************************************************
* COPYRIGHT (c), 2006, RAYTHEON COMPANY
* ALL RIGHTS RESERVED, An Unpublished Work
*
* RAYTHEON PROPRIETARY
* If the end user is not the U.S. Government or any agency thereof, use
* or disclosure of data contained in this source code file is subject to
* the proprietary restrictions set forth in the Master Rights File.
*
* U.S. GOVERNMENT PURPOSE RIGHTS NOTICE
* If the end user is the U.S. Government or any agency thereof, this source
* code is provided to the U.S. Government with Government Purpose Rights.
* Use or disclosure of data contained in this source code file is subject to
* the "Government Purpose Rights" restriction in the Master Rights File.
*
* U.S. EXPORT CONTROLLED TECHNICAL DATA
* Use or disclosure of data contained in this source code file is subject to
* the export restrictions set forth in the Master Rights File.
******************************************************************************************/
package com.raytheon.uf.edex.ogc.common.http;
import java.io.InputStream;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.camel.Exchange;
import org.apache.camel.Processor;
import com.raytheon.uf.common.status.IUFStatusHandler;
import com.raytheon.uf.common.status.UFStatus;
import com.raytheon.uf.edex.ogc.common.stats.IStatsRecorder;
import com.raytheon.uf.edex.ogc.common.stats.OperationType;
import com.raytheon.uf.edex.ogc.common.stats.ServiceType;
import com.raytheon.uf.edex.ogc.common.stats.StatsRecorderFinder;
import com.raytheon.uf.edex.soap.RequestLogController;
/**
* HTTP Camel Processor for OGC REST Services
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
*
* </pre>
*
* @author
* @version 1
*/
public class OgcHttpEndpoint implements Processor {
public static final String HEADER_AC_ALLOW_CREDENTIALS = "Access-Control-Allow-Credentials";
public static final String HEADER_AC_ALLOW_ORIGIN = "Access-Control-Allow-Origin";
public static final String HEADER_AC_EXPOSE_HEADERS = "Access-Control-Expose-Headers";
protected IOgcHttpPooler pool;
protected IUFStatusHandler log = UFStatus.getHandler(this.getClass());
/**
*
*/
public OgcHttpEndpoint(IOgcHttpPooler pool) {
this.pool = pool;
}
@Override
public void process(Exchange ex) throws Exception {
long start = System.nanoTime();
Map<String, Object> headers = ex.getIn().getHeaders();
HttpServletResponse response = ex.getIn().getBody(
HttpServletResponse.class);
HttpServletRequest httpRequest = ex.getIn().getBody(
HttpServletRequest.class);
setCorsHeaders(headers, response);
long id = Thread.currentThread().getId();
OgcHttpHandler handler = (OgcHttpHandler) pool.borrowObject(id);
OgcHttpRequest ogcReq = new OgcHttpRequest(httpRequest, response,
headers);
if (httpRequest.getMethod().equalsIgnoreCase("POST")) {
ogcReq.setInputStream(ex.getIn().getBody(InputStream.class));
}
handler.handle(ogcReq);
// TODO get service from request somehow?? remove time and duration
// calculation from critical path
IStatsRecorder statRecorder = StatsRecorderFinder.find();
statRecorder.recordRequest(System.currentTimeMillis(),
System.nanoTime() - start, ServiceType.OGC, OperationType.QUERY, true);
//TODO this is part of the incoming request log, the rest is usually in CXF
//which is not hooked up here. Fill in cxf portion of request logging.
if (RequestLogController.getInstance().shouldLogRequestsInfo() &&
log.isPriorityEnabled(RequestLogController.getInstance().getRequestLogLevel())) {
String requestLog = "";
requestLog += "Successfully processed request from " + ex.getFromRouteId() + ". ";
requestLog += "Duration of " + (System.nanoTime() - start/1000000000.0) + "s.";
log.handle(RequestLogController.getInstance().getRequestLogLevel(),
requestLog);
}
pool.returnObject(id, handler);
}
/**
* Set the CORS headers allowing access from alternate origins.
* @param headers
* @param response
*/
protected void setCorsHeaders(Map<String, Object> headers, HttpServletResponse response) {
String allowedOrigins = "*";
response.setHeader(HEADER_AC_ALLOW_ORIGIN, allowedOrigins);
response.setHeader(HEADER_AC_ALLOW_CREDENTIALS, "false");
response.setHeader(HEADER_AC_EXPOSE_HEADERS,"");
}
}

View file

@ -1,85 +0,0 @@
/**
* 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.edex.ogc.common.http;
/**
* Exception for when an OGC request fails at the HTTP level. Contains HTTP
* error code for response.
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Nov 11, 2013 2539 bclement Initial creation
*
* </pre>
*
* @author bclement
* @version 1.0
*/
public class OgcHttpErrorException extends Exception {
private static final long serialVersionUID = -452797331391106559L;
private final int code;
/**
*
*/
public OgcHttpErrorException(int code) {
super();
this.code = code;
}
/**
* @param message
* @param cause
*/
public OgcHttpErrorException(int code, String message, Throwable cause) {
super(message, cause);
this.code = code;
}
/**
* @param message
*/
public OgcHttpErrorException(int code, String message) {
super(message);
this.code = code;
}
/**
* @param cause
*/
public OgcHttpErrorException(int code, Throwable cause) {
super(cause);
this.code = code;
}
/**
* @return the error status code
*/
public int getCode() {
return code;
}
}

View file

@ -1,362 +0,0 @@
/**
* 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.edex.ogc.common.http;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.util.Collection;
import java.util.Iterator;
import java.util.Map;
import javax.ws.rs.core.Response.Status;
import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;
import org.apache.commons.collections.map.CaseInsensitiveMap;
import org.apache.commons.lang3.StringUtils;
import com.raytheon.uf.common.http.AcceptHeaderParser;
import com.raytheon.uf.common.http.AcceptHeaderValue;
import com.raytheon.uf.common.http.MimeType;
import com.raytheon.uf.common.status.IUFStatusHandler;
import com.raytheon.uf.common.status.UFStatus;
import com.raytheon.uf.edex.ogc.common.OgcException;
import com.raytheon.uf.edex.ogc.common.OgcException.Code;
import com.raytheon.uf.edex.ogc.common.OgcResponse;
import com.raytheon.uf.edex.ogc.common.OgcResponse.TYPE;
import com.raytheon.uf.edex.ogc.common.output.IOgcHttpResponse;
import com.raytheon.uf.edex.ogc.common.output.OgcResponseOutput;
import com.raytheon.uf.edex.ogc.common.output.ServletOgcResponse;
/**
* Abstract base for HTTP handlers. Provides common utility methods.
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* 2011 bclement Initial creation
* Nov 11, 2013 2539 bclement added accept encoding parsing
*
* </pre>
*
* @author bclement
* @version 1.0
*/
public abstract class OgcHttpHandler {
public static final String USER_HEADER = "username";
public static final String ROLES_HEADER = "roles";
public static final String EXCEP_FORMAT_HEADER = "exceptions";
public static final String VERSION_HEADER = "version";
public static final String ACCEPT_VERSIONS_HEADER = "acceptversions";
public static final String ACCEPT_ENC_HEADER = "accept-encoding";
public abstract void handle(OgcHttpRequest request);
private IUFStatusHandler log = UFStatus.getHandler(this.getClass());
public static MimeType getMimeType(Map<String, Object> map, String key)
throws OgcException {
String str = getString(map, key);
if (str == null || str.isEmpty()) {
return null;
}
try {
return new MimeType(str);
} catch (IllegalArgumentException e) {
throw new OgcException(Code.InvalidParameterValue, e);
}
}
public static String getString(Map<String, Object> map, String key)
throws OgcException {
Object obj = map.get(key);
String rval = null;
if (obj != null) {
if (obj instanceof String) {
rval = (String) obj;
} else if (obj instanceof String[]) {
// they may have multiple values for the entry
String[] arr = (String[]) obj;
rval = arr[0];
for (int i = 1; i < arr.length; ++i) {
if (!rval.equalsIgnoreCase(arr[i])) {
throw new OgcException(Code.InvalidParameterValue,
"Multiple values for parameter: " + key);
}
}
} else if (obj instanceof Collection<?>) {
Collection<?> col = (Collection<?>) obj;
Iterator<?> i = col.iterator();
rval = i.next().toString();
while (i.hasNext()) {
if (!rval.equalsIgnoreCase(i.next().toString())) {
throw new OgcException(Code.InvalidParameterValue,
"Multiple values for parameter: " + key);
}
}
}
}
return rval;
}
public static String getVersionInHeader(Map<String, Object> headerMap)
throws OgcException {
return getString(headerMap, VERSION_HEADER);
}
public static String[] getAcceptVersionInHeader(
Map<String, Object> headerMap) throws OgcException {
return getStringArr(headerMap, ACCEPT_VERSIONS_HEADER);
}
/**
* @param in
* @return null if not found
* @throws XMLStreamException
*/
public static String[] getAttributeArrInRoot(InputStream in, String attrib)
throws XMLStreamException {
String vstr = getAttributeInRoot(in, attrib);
if (vstr == null) {
return null;
}
return StringUtils.split(vstr, ',');
}
/**
* @param in
* @param attrib
* @return null if not found
* @throws XMLStreamException
*/
public static String getAttributeInRoot(InputStream in, String attrib)
throws XMLStreamException {
XMLStreamReader reader = XMLInputFactory.newInstance()
.createXMLStreamReader(in);
while (reader.next() != XMLStreamReader.START_ELEMENT) {
}
return getAttributeValue(reader, attrib);
}
/**
* @param reader
* @param attrib
* @return null if attribute not found
*/
protected static String getAttributeValue(XMLStreamReader reader,
String attrib) {
int count = reader.getAttributeCount();
for (int i = 0; i < count; ++i) {
String local = reader.getAttributeLocalName(i);
if (local.equalsIgnoreCase(attrib)) {
String ns = reader.getAttributeNamespace(i);
return reader.getAttributeValue(ns, local);
}
}
return null;
}
public static String[] getStringArr(Map<String, Object> map, String key) {
Object obj = map.get(key);
String[] rval = null;
if (obj != null) {
if (obj instanceof String[]) {
rval = (String[]) obj;
} else if (obj instanceof String) {
rval = ((String) obj).split(",", -1);
} else if (obj instanceof Collection<?>) {
Collection<?> col = (Collection<?>) obj;
rval = new String[col.size()];
Iterator<?> iter = col.iterator();
for (int i = 0; iter.hasNext(); ++i) {
rval[i] = iter.next().toString();
}
}
}
return rval;
}
public static Integer getInt(Map<String, Object> map, String key)
throws OgcException {
Object obj = map.get(key);
Integer rval = null;
if (obj != null) {
if (obj instanceof Integer) {
rval = (Integer) obj;
} else {
// try to decode string
rval = getInt(getString(map, key));
}
}
return rval;
}
public static Integer getInt(String str) {
Integer rval = null;
try {
rval = Integer.parseInt(str);
} catch (Exception e) {
// leave rval as null
}
return rval;
}
public static Boolean getBool(Map<String, Object> map, String key)
throws OgcException {
Object obj = map.get(key);
Boolean rval = null;
if (obj != null) {
if (obj instanceof Boolean) {
rval = (Boolean) obj;
} else {
// decode as string
rval = getBool(getString(map, key));
}
}
return rval;
}
public static Boolean getBool(String str) {
Boolean rval = null;
try {
rval = Boolean.parseBoolean(str);
} catch (Exception e) {
// leave rval as null
}
return rval;
}
protected OgcResponse handleError(OgcException e, MimeType exceptionFormat) {
log.error("Error handler not configured for http handler: "
+ this.getClass());
String rval = "<ows:ExceptionReport version=\"1.0.0\"\n";
rval += "xsi:schemaLocation=\"http://www.opengis.net/ows\"\n";
rval += "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" \n"
+ "xmlns:ows=\"http://www.opengis.net/ows\">\n";
rval += "<ows:Exception exceptionCode=\"" + e.getCode() + "\">\n";
rval += "<ows:ExceptionText>" + e.getMessage()
+ "</ows:ExceptionText>\n";
rval += "</ows:Exception></ows:ExceptionReport>\n";
return new OgcResponse(rval, OgcResponse.TEXT_XML_MIME, TYPE.TEXT);
}
protected void sendResponse(IOgcHttpResponse httpRes, OgcResponse response)
throws Exception {
try {
OgcResponseOutput.output(response, httpRes);
} catch (OgcException e) {
OgcResponse error = handleError(e, null);
OgcResponseOutput.output(error, httpRes);
}
}
@SuppressWarnings("unchecked")
protected static Map<String, String> getDimensions(
Map<String, Object> headers) {
Map<String, String> rval = new CaseInsensitiveMap();
for (String key : headers.keySet()) {
if (key.toLowerCase().startsWith("dim_")) {
String dim = key.substring(4);
rval.put(dim, (String) headers.get(key));
}
}
return rval;
}
/**
* Check if accept encoding header is present and modify response
* accordingly.
*
* @param headers
* @param response
* @throws OgcException
* on internal server error
* @throws OgcHttpErrorException
* on HTTP protocol error condition
*/
protected void acceptEncodingCheck(Map<String, Object> headers,
ServletOgcResponse response) throws OgcException,
OgcHttpErrorException {
Object obj = headers.get(ACCEPT_ENC_HEADER);
if (obj == null) {
// omitted accept encoding signifies that they accept anything
return;
}
if (!(obj instanceof String)) {
log.error("Unsupported header type encountered: " + obj.getClass());
throw new OgcException(Code.InternalServerError);
}
String encoding = (String) obj;
boolean gzipAcceptable = false;
boolean anyAcceptable = false;
for (AcceptHeaderValue value : new AcceptHeaderParser(encoding)) {
if (value.getEncoding().toLowerCase().contains("gzip")
&& value.isAcceptable()) {
gzipAcceptable = true;
} else if (value.getEncoding().trim().equals("*")) {
anyAcceptable = true;
}
}
if (gzipAcceptable) {
response.enableGzip();
} else if (!anyAcceptable) {
throw new OgcHttpErrorException(406);
}
}
/**
* Output HTTP protocol error
*
* @param response
* @param errorCode
* @throws IOException
*/
protected void outputHttpError(ServletOgcResponse response, int errorCode)
throws IOException {
response.setStatus(errorCode);
response.setContentType("text/plain");
Writer writer = null;
try {
writer = new OutputStreamWriter(response.getOutputStream());
writer.write(Status.fromStatusCode(errorCode).toString());
} finally {
if (writer != null) {
writer.flush();
writer.close();
}
}
}
}

View file

@ -1,97 +0,0 @@
/**
* 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.edex.ogc.common.http;
import java.io.InputStream;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* OGC HTTP request wrapper
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* 2011 bclement Initial creation
*
* </pre>
*
* @author bclement
* @version 1.0
*/
public class OgcHttpRequest {
protected HttpServletRequest request;
protected HttpServletResponse response;
protected Map<String, Object> headers;
protected InputStream inputStream;
public OgcHttpRequest(HttpServletRequest request,
HttpServletResponse response, Map<String, Object> headers) {
this.request = request;
this.response = response;
this.headers = headers;
}
public boolean isPost() {
return inputStream != null;
}
public HttpServletRequest getRequest() {
return request;
}
public void setRequest(HttpServletRequest request) {
this.request = request;
}
public HttpServletResponse getResponse() {
return response;
}
public void setResponse(HttpServletResponse response) {
this.response = response;
}
public Map<String, Object> getHeaders() {
return headers;
}
public void setHeaders(Map<String, Object> headers) {
this.headers = headers;
}
public InputStream getInputStream() {
return inputStream;
}
public void setInputStream(InputStream inputStream) {
this.inputStream = inputStream;
}
}

View file

@ -1,58 +0,0 @@
/**
* Copyright 09/24/12 Raytheon Company.
*
* Unlimited Rights
* This software was developed pursuant to Contract Number
* DTFAWA-10-D-00028 with the US Government. The US Governments rights
* in and to this copyrighted software are as specified in DFARS
* 252.227-7014 which was made part of the above contract.
*/
package com.raytheon.uf.edex.ogc.common.http;
/**
* HTTP pooling for handlers that are thread safe and don't require a separate
* instance per request.
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Oct 31, 2012 bclement Initial creation
* Oct 23, 2015 #5004 dgilling Update function signatures to match
* interface.
*
* </pre>
*
* @author bclement
* @version 1.0
*/
public class SingleHttpPool implements IOgcHttpPooler {
private final OgcHttpHandler handler;
/**
* @param handler
*/
public SingleHttpPool(OgcHttpHandler handler) {
this.handler = handler;
}
@Override
public OgcHttpHandler borrowObject(Long key) {
return handler;
}
@Override
public void returnObject(Long key, OgcHttpHandler borrowed) {
// nothing to do
}
@Override
public void drain() {
// nothing to do
}
}

View file

@ -1,47 +0,0 @@
package com.raytheon.uf.edex.ogc.common.interfaces;
/**
* 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.
**/
import java.util.Collection;
import java.util.Map;
import com.raytheon.uf.common.dataplugin.PluginDataObject;
import com.raytheon.uf.edex.ogc.common.db.SimpleLayer;
/**
*
* WCS Interface
*
* <pre>
* SOFTWARE HISTORY
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* 08/09/2012 754 dhladky Initial
* </pre>
*
* @author dhladky
* @version 1.0
*/
public interface IWCSMetaData<L extends SimpleLayer<?>, R extends PluginDataObject> {
void sendMetaData(Map<String, L> layermap, Collection<R> coll);
}

View file

@ -1,43 +0,0 @@
package com.raytheon.uf.edex.ogc.common.interfaces;
/**
* 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.
**/
import com.raytheon.uf.edex.ogc.common.db.SimpleLayer;
/**
*
* WFS Interface
*
* <pre>
* SOFTWARE HISTORY
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* 08/09/2012 754 dhladky Initial
* 04/01/2013 1746 dhladky Updated for the MADIS impl.
* </pre>
*
* @author dhladky
* @version 1.0
*/
public interface IWFSMetaData<L extends SimpleLayer<?>> {
public void sendMetaData(L layer);
}

View file

@ -1,207 +0,0 @@
/**
* 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.edex.ogc.common.jaxb;
import java.io.File;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBElement;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
import javax.xml.parsers.ParserConfigurationException;
import org.w3c.dom.Node;
import com.raytheon.uf.common.serialization.JAXBManager;
import com.raytheon.uf.common.serialization.SerializationException;
import com.sun.xml.bind.api.JAXBRIContext;
import com.sun.xml.bind.marshaller.NamespacePrefixMapper;
/**
* Cache and utility class for OGC JAXB
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Mar 30, 2011 bclement Initial creation
* Aug 18, 2013 #2097 dhladky extended JAXBManager
* Jul 15, 2014 3373 bclement rewritten to use JAXBManager
* Jul 23, 2014 dhladky restored JAXBElement unwrapping lost in re-write.
*
* </pre>
*
* @author bclement
* @version 1.0
*/
public class OgcJaxbManager extends JAXBManager {
protected static final String JAXB_NAMESPACE_MAPPER = "com.sun.xml.bind.namespacePrefixMapper";
private final OgcMarshallerStrategy marshStrategy;
/**
* @param classes
* @throws JAXBException
*/
public OgcJaxbManager(Class<?>[] classes) throws JAXBException {
this(new OgcMarshallerStrategy(), classes);
}
/**
* @param mapper
* mapping of namespaces to namespace prefixes
* @param classes
* @throws JAXBException
*/
public OgcJaxbManager(NamespacePrefixMapper mapper, Class<?>[] classes)
throws JAXBException {
this(createStrategy(mapper), classes);
}
/**
* @see JAXBManager#JAXBManager(boolean,
* com.raytheon.uf.common.serialization.jaxb.JaxbMarshallerStrategy,
* Class...)
* @param strategy
* @param classes
* @throws JAXBException
*/
public OgcJaxbManager(OgcMarshallerStrategy strategy, Class<?>[] classes)
throws JAXBException {
super(strategy, classes);
this.marshStrategy = strategy;
}
/**
* Create a marshaller strategy that uses the provided namespace prefix
* mapping
*
* @param mapper
* @return
*/
private static OgcMarshallerStrategy createStrategy(
final NamespacePrefixMapper mapper) {
return new OgcMarshallerStrategy() {
@Override
protected Marshaller createMarshaller(JAXBContext context)
throws JAXBException {
Marshaller rval = super.createMarshaller(context);
if (mapper != null) {
rval.setProperty(JAXB_NAMESPACE_MAPPER, mapper);
}
return rval;
}
};
}
/*
* (non-Javadoc)
*
* @see com.raytheon.uf.common.serialization.JAXBManager#getJaxbConfig()
*/
@Override
protected Map<String, Object> getJaxbConfig() throws JAXBException {
Map<String, Object> jaxbConfig = new HashMap<String, Object>();
TransientAnnotationReader reader = new TransientAnnotationReader();
try {
reader.addTransientField(Throwable.class
.getDeclaredField("stackTrace"));
reader.addTransientMethod(Throwable.class
.getDeclaredMethod("getStackTrace"));
} catch (Exception e) {
throw new JAXBException("Unable to add transient members", e);
}
jaxbConfig.put(JAXBRIContext.ANNOTATION_READER, reader);
return jaxbConfig;
}
/**
* @see OgcMarshallerStrategy#unmarshal(JAXBContext, Node)
* @param node
* @return
* @throws JAXBException
*/
public Object unmarshal(Node node) throws JAXBException {
JAXBContext ctx = getJaxbContext();
return extractJaxbElement(marshStrategy.unmarshal(ctx, node));
}
/**
* @see OgcMarshallerStrategy#marshalToNode(JAXBContext, Object)
* @param obj
* @return
* @throws JAXBException
* @throws ParserConfigurationException
*/
public Node marshalToNode(Object obj) throws JAXBException,
ParserConfigurationException {
JAXBContext ctx = getJaxbContext();
return marshStrategy.marshalToNode(ctx, obj);
}
/**
* Override of JAXB manager, pulls Objects out of JAXBElement
* @param xml
* @return
* @throws JAXBException
*/
public Object unmarshalFromXml(String xml) throws JAXBException {
return extractJaxbElement(super.unmarshalFromXml(xml));
}
/**
* Override of JAXB manager, pulls Objects out of JAXBElement
* @param InputStream
* @return
* @throws SerializationException
*/
public Object unmarshalFromInputStream(InputStream is) throws SerializationException {
return extractJaxbElement(super.unmarshalFromInputStream(is));
}
/**
* OGC override of internalUnmarshalFromXmlFile
* @param file
* the file to unmarshal and object from.
* @return the object from the file
* @throws SerializationException
*/
protected Object internalUnmarshalFromXmlFile(File file)
throws SerializationException {
return extractJaxbElement(super.internalUnmarshalFromXmlFile(file));
}
/**
* Extracts the Object from the JAXBElement wrapper
*/
private Object extractJaxbElement(Object o) {
if (o instanceof JAXBElement<?>) {
o = ((JAXBElement<?>) o).getValue();
}
return o;
}
}

View file

@ -1,106 +0,0 @@
/**
* 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.edex.ogc.common.jaxb;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBElement;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
import javax.xml.bind.Unmarshaller;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import com.raytheon.uf.common.serialization.jaxb.PooledJaxbMarshallerStrategy;
/**
* Marshaller strategy for OGC XML operations. Includes w3c dom operations.
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Jul 15, 2014 3373 bclement Initial creation
*
* </pre>
*
* @author bclement
* @version 1.0
*/
public class OgcMarshallerStrategy extends PooledJaxbMarshallerStrategy {
/**
*
*/
public OgcMarshallerStrategy() {
super();
}
/**
* @param poolSize
* @param pooledObjectSizeLimit
*/
public OgcMarshallerStrategy(int poolSize, int pooledObjectSizeLimit) {
super(poolSize, pooledObjectSizeLimit);
}
/**
* Unmarshal object from w3c node.
*
* @param ctx
* @param node
* @return
* @throws JAXBException
*/
public Object unmarshal(JAXBContext ctx, Node node) throws JAXBException {
Unmarshaller msh = createUnmarshaller(ctx);
Object obj = msh.unmarshal(node);
if (obj instanceof JAXBElement<?>) {
obj = ((JAXBElement<?>) obj).getValue();
}
return obj;
}
/**
* Marshal object to w3c node
*
* @param ctx
* @param obj
* @return
* @throws JAXBException
* @throws ParserConfigurationException
*/
public Node marshalToNode(JAXBContext ctx, Object obj)
throws JAXBException, ParserConfigurationException {
Marshaller msh = createMarshaller(ctx);
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setNamespaceAware(true);
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.newDocument();
msh.marshal(obj, doc);
return doc.getFirstChild();
}
}

View file

@ -1,310 +0,0 @@
/**
* Copyright 09/24/12 Raytheon Company.
*
* Unlimited Rights
* This software was developed pursuant to Contract Number
* DTFAWA-10-D-00028 with the US Government. The US Governments rights
* in and to this copyrighted software are as specified in DFARS
* 252.227-7014 which was made part of the above contract.
*/
package com.raytheon.uf.edex.ogc.common.jaxb;
import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.lang.reflect.Type;
import java.util.Collections;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import javax.xml.bind.annotation.XmlTransient;
import com.sun.xml.bind.v2.model.annotation.AbstractInlineAnnotationReaderImpl;
import com.sun.xml.bind.v2.model.annotation.Locatable;
import com.sun.xml.bind.v2.model.annotation.RuntimeAnnotationReader;
import com.sun.xml.bind.v2.model.annotation.RuntimeInlineAnnotationReader;
/**
* JAXB utility to allow for Transient annotation to be added to fields and
* methods of classes
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Oct 11, 2012 bclement Initial creation
*
* </pre>
*
* @author bclement
* @version 1.0
*/
@SuppressWarnings("rawtypes")
public class TransientAnnotationReader extends
AbstractInlineAnnotationReaderImpl<Type, Class, Field, Method>
implements
RuntimeAnnotationReader {
private static class XmlTransientProxyHandler implements InvocationHandler {
public Object invoke(Object proxy, Method method, Object[] args)
throws Throwable {
if (args == null || args.length == 0) {
if (method.getName().equals("annotationType")) {
return XmlTransient.class;
}
if (method.getName().equals("toString")) {
return "XmlTransient";
}
}
String msg = "@XmlTransient doesn't support method: "
+ method.getName();
throw new UnsupportedOperationException(msg);
}
private static XmlTransient create() {
ClassLoader loader = XmlTransientProxyHandler.class
.getClassLoader();
Class<?>[] interfaces = new Class[] { XmlTransient.class };
XmlTransientProxyHandler handler = new XmlTransientProxyHandler();
return (XmlTransient) Proxy.newProxyInstance(loader, interfaces,
handler);
}
}
private static final Annotation XML_TRANSIENT_ANNOTATION = XmlTransientProxyHandler
.create();
private static final Annotation[] XML_TRANSIENT_ANNOTATION_ONLY = { XML_TRANSIENT_ANNOTATION };
private final RuntimeAnnotationReader delegate = new RuntimeInlineAnnotationReader();
private final Set<Class<?>> transientClasses = Collections
.newSetFromMap(new ConcurrentHashMap<Class<?>, Boolean>());
private final Set<Field> transientFields = Collections
.newSetFromMap(new ConcurrentHashMap<Field, Boolean>());
private final Set<Method> transientMethods = Collections
.newSetFromMap(new ConcurrentHashMap<Method, Boolean>());
/**
*
*/
public TransientAnnotationReader() {
}
public void addTransientClass(Class<?> c) {
transientClasses.add(c);
}
public void addTransientField(Field f) {
transientFields.add(f);
}
public void addTransientMethod(Method m) {
transientMethods.add(m);
}
/*
* (non-Javadoc)
*
* @see
* com.sun.xml.bind.v2.model.annotation.AnnotationReader#getAllFieldAnnotations
* (java.lang.Object, com.sun.xml.bind.v2.model.annotation.Locatable)
*/
@Override
public Annotation[] getAllFieldAnnotations(Field f, Locatable srcPos) {
if (transientFields.contains(f)) {
return XML_TRANSIENT_ANNOTATION_ONLY;
}
return delegate.getAllFieldAnnotations(f, srcPos);
}
/*
* (non-Javadoc)
*
* @see
* com.sun.xml.bind.v2.model.annotation.AnnotationReader#getAllMethodAnnotations
* (java.lang.Object, com.sun.xml.bind.v2.model.annotation.Locatable)
*/
@Override
public Annotation[] getAllMethodAnnotations(Method m, Locatable srcPos) {
if (transientMethods.contains(m)) {
return XML_TRANSIENT_ANNOTATION_ONLY;
}
return delegate.getAllMethodAnnotations(m, srcPos);
}
/*
* (non-Javadoc)
*
* @see
* com.sun.xml.bind.v2.model.annotation.AnnotationReader#getClassAnnotation
* (java.lang.Class, java.lang.Object,
* com.sun.xml.bind.v2.model.annotation.Locatable)
*/
@SuppressWarnings("unchecked")
@Override
public <A extends Annotation> A getClassAnnotation(Class<A> type, Class c,
Locatable srcPos) {
if (transientClasses.contains(c)) {
return (A) XML_TRANSIENT_ANNOTATION;
}
return delegate.getClassAnnotation(type, c, srcPos);
}
/*
* (non-Javadoc)
*
* @see
* com.sun.xml.bind.v2.model.annotation.AnnotationReader#getClassArrayValue
* (java.lang.annotation.Annotation, java.lang.String)
*/
@Override
public Type[] getClassArrayValue(Annotation a, String name) {
return delegate.getClassArrayValue(a, name);
}
/*
* (non-Javadoc)
*
* @see
* com.sun.xml.bind.v2.model.annotation.AnnotationReader#getClassValue(java
* .lang.annotation.Annotation, java.lang.String)
*/
@Override
public Type getClassValue(Annotation a, String name) {
return delegate.getClassValue(a, name);
}
/*
* (non-Javadoc)
*
* @see
* com.sun.xml.bind.v2.model.annotation.AnnotationReader#getFieldAnnotation
* (java.lang.Class, java.lang.Object,
* com.sun.xml.bind.v2.model.annotation.Locatable)
*/
@SuppressWarnings("unchecked")
@Override
public <A extends Annotation> A getFieldAnnotation(Class<A> type, Field f,
Locatable srcPos) {
if (XmlTransient.class.isAssignableFrom(type)
&& transientFields.contains(f)) {
return (A) XML_TRANSIENT_ANNOTATION;
}
return delegate.getFieldAnnotation(type, f, srcPos);
}
/*
* (non-Javadoc)
*
* @see
* com.sun.xml.bind.v2.model.annotation.AnnotationReader#getMethodAnnotation
* (java.lang.Class, java.lang.Object,
* com.sun.xml.bind.v2.model.annotation.Locatable)
*/
@SuppressWarnings("unchecked")
@Override
public <A extends Annotation> A getMethodAnnotation(Class<A> type,
Method m, Locatable srcPos) {
if (XmlTransient.class.isAssignableFrom(type)
&& transientMethods.contains(m)) {
return (A) XML_TRANSIENT_ANNOTATION;
}
return delegate.getMethodAnnotation(type, m, srcPos);
}
/*
* (non-Javadoc)
*
* @see com.sun.xml.bind.v2.model.annotation.AnnotationReader#
* getMethodParameterAnnotation(java.lang.Class, java.lang.Object, int,
* com.sun.xml.bind.v2.model.annotation.Locatable)
*/
@Override
public <A extends Annotation> A getMethodParameterAnnotation(Class<A> type,
Method m, int index, Locatable srcPos) {
return delegate.getMethodParameterAnnotation(type, m, index, srcPos);
}
/*
* (non-Javadoc)
*
* @see
* com.sun.xml.bind.v2.model.annotation.AnnotationReader#getPackageAnnotation
* (java.lang.Class, java.lang.Object,
* com.sun.xml.bind.v2.model.annotation.Locatable)
*/
@Override
public <A extends Annotation> A getPackageAnnotation(Class<A> type,
Class c, Locatable srcPos) {
return delegate.getPackageAnnotation(type, c, srcPos);
}
/*
* (non-Javadoc)
*
* @see
* com.sun.xml.bind.v2.model.annotation.AnnotationReader#hasClassAnnotation
* (java.lang.Object, java.lang.Class)
*/
@Override
public boolean hasClassAnnotation(Class c, Class<? extends Annotation> type) {
if (transientClasses.contains(c)) {
return true;
}
return delegate.hasClassAnnotation(c, type);
}
/*
* (non-Javadoc)
*
* @see
* com.sun.xml.bind.v2.model.annotation.AnnotationReader#hasFieldAnnotation
* (java.lang.Class, java.lang.Object)
*/
@Override
public boolean hasFieldAnnotation(Class<? extends Annotation> type, Field f) {
if (XmlTransient.class.isAssignableFrom(type)
&& transientFields.contains(f)) {
return true;
}
return delegate.hasFieldAnnotation(type, f);
}
/*
* (non-Javadoc)
*
* @see
* com.sun.xml.bind.v2.model.annotation.AnnotationReader#hasMethodAnnotation
* (java.lang.Class, java.lang.Object)
*/
@Override
public boolean hasMethodAnnotation(Class<? extends Annotation> type,
Method m) {
if (XmlTransient.class.isAssignableFrom(type)
&& transientMethods.contains(m)) {
return true;
}
return delegate.hasMethodAnnotation(type, m);
}
/*
* (non-Javadoc)
*
* @see
* com.sun.xml.bind.v2.model.annotation.AbstractInlineAnnotationReaderImpl
* #fullName(java.lang.Object)
*/
@Override
protected String fullName(Method m) {
return m.getDeclaringClass().getName() + '#' + m.getName();
}
}

View file

@ -1,105 +0,0 @@
/**
* Copyright 09/24/12 Raytheon Company.
*
* Unlimited Rights
* This software was developed pursuant to Contract Number
* DTFAWA-10-D-00028 with the US Government. The US Governments rights
* in and to this copyrighted software are as specified in DFARS
* 252.227-7014 which was made part of the above contract.
*/
package com.raytheon.uf.edex.ogc.common.level;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import com.raytheon.uf.common.dataplugin.level.Level;
import com.raytheon.uf.common.dataplugin.level.MasterLevel;
import com.raytheon.uf.edex.ogc.common.OgcException;
import com.raytheon.uf.edex.ogc.common.OgcException.Code;
/**
* Utility methods for parsing and formatting level names for OGC metadata
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Jun 18, 2013 bclement Initial creation
*
* </pre>
*
* @author bclement
* @version 1.0
*/
public class LevelDimUtil {
public static final String LEVEL_DIM_PREFIX = "LEVEL_";
public static final Pattern levelPattern = Pattern
.compile("^(-?[0-9]*\\.?[0-9]+)(_(-?[0-9]*\\.?[0-9]+))?(.*)?$");
/**
* @param dimName
* @param value
* @param defaultUnits
* @return null if not parsed
* @throws OgcException
*/
public static Level parseLevel(String dimName, String value,
String defaultUnits) throws OgcException {
String name = dimName.substring(LEVEL_DIM_PREFIX.length());
Matcher m = levelPattern.matcher(value);
if (!m.matches()) {
return null;
}
Level rval = new Level();
MasterLevel master = new MasterLevel(name);
rval.setMasterLevel(master);
rval.setLevelonevalue(parseWithDefault(m.group(1), Level.INVALID_VALUE));
rval.setLeveltwovalue(parseWithDefault(m.group(3), Level.INVALID_VALUE));
String units = m.group(4) == null || m.group(4).isEmpty() ? defaultUnits
: m.group(4);
if (units != null) {
master.setUnitString(units);
} else {
master.setUnitString(defaultUnits);
}
return rval;
}
/**
* @param input
* @param defaultVal
* @return default if input is null/empty
* @throws OgcException
*/
private static double parseWithDefault(String input, double defaultVal)
throws OgcException {
if (input == null || input.isEmpty()) {
return defaultVal;
}
try {
return Double.parseDouble(input);
} catch (Exception e) {
throw new OgcException(Code.InvalidParameterValue,
"Invalid level value: " + input, e);
}
}
/**
* Return formatted level value
*
* @param level
* @return
*/
public static String formatLevelValue(Level level) {
String rval = level.getLevelOneValueAsString();
if (level.isLevelTwoValid()) {
rval += "_" + level.getLevelTwoValueAsString();
}
return rval;
}
}

Some files were not shown because too many files have changed in this diff Show more