summaryrefslogtreecommitdiffstats
path: root/petascope/src/petascope/wcs/server/core/convertGetCoverage.java
diff options
context:
space:
mode:
Diffstat (limited to 'petascope/src/petascope/wcs/server/core/convertGetCoverage.java')
-rw-r--r--petascope/src/petascope/wcs/server/core/convertGetCoverage.java138
1 files changed, 64 insertions, 74 deletions
diff --git a/petascope/src/petascope/wcs/server/core/convertGetCoverage.java b/petascope/src/petascope/wcs/server/core/convertGetCoverage.java
index 92262e6..153728c 100644
--- a/petascope/src/petascope/wcs/server/core/convertGetCoverage.java
+++ b/petascope/src/petascope/wcs/server/core/convertGetCoverage.java
@@ -14,16 +14,15 @@
* You should have received a copy of the GNU General Public License
* along with rasdaman community. If not, see <http://www.gnu.org/licenses/>.
*
- * Copyright 2003, 2004, 2005, 2006, 2007, 2008, 2009 Peter Baumann /
- rasdaman GmbH.
+ * Copyright 2003 - 2010 Peter Baumann / rasdaman GmbH.
*
* For more information please see <http://www.rasdaman.org>
* or contact Peter Baumann via <baumann@rasdaman.com>.
*/
package petascope.wcs.server.core;
-//~--- non-JDK imports --------------------------------------------------------
-import petascope.wcs.server.exceptions.WCSException;
+import petascope.exceptions.WCSException;
+import petascope.exceptions.ExceptionCode;
import net.opengis.gml.v_3_1_1.TimePositionType;
import net.opengis.ows.v_1_0_0.BoundingBoxType;
import net.opengis.wcs.v_1_1_0.DomainSubsetType;
@@ -31,27 +30,18 @@ import net.opengis.wcs.v_1_1_0.GetCoverage;
import net.opengis.wcs.v_1_1_0.GridCrsType;
import net.opengis.wcs.v_1_1_0.RangeSubsetType;
import net.opengis.wcs.v_1_1_0.TimePeriodType;
-
-import petascope.wcps.server.core.DbMetadataSource;
+import petascope.core.DbMetadataSource;
import petascope.wcps.server.core.ProcessCoveragesRequest;
-import petascope.wcps.server.exceptions.WCPSException;
+import petascope.exceptions.WCPSException;
import petascope.wcps.server.core.DomainElement;
-
import petascope.ConfigManager;
-
-//~--- JDK imports ------------------------------------------------------------
-
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.antlr.runtime.RecognitionException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import petascope.wcps.server.core.Metadata;
-import petascope.wcs.server.exceptions.InvalidParameterValueException;
-import petascope.wcs.server.exceptions.InvalidTemporalMetadataException;
-import petascope.wcs.server.exceptions.MissingParameterValueException;
-import petascope.wcs.server.exceptions.NoApplicableCodeException;
+import petascope.core.Metadata;
/**
* This class takes a WCS GetCoverage XML request and converts this request into
@@ -62,7 +52,7 @@ import petascope.wcs.server.exceptions.NoApplicableCodeException;
*/
public class convertGetCoverage {
- private static Logger LOG = LoggerFactory.getLogger(convertGetCoverage.class);
+ private static Logger log = LoggerFactory.getLogger(convertGetCoverage.class);
// Trimming
private boolean xAxisTrim = false;
private boolean yAxisTrim = false;
@@ -125,11 +115,11 @@ public class convertGetCoverage {
}
/* Convert the abstract syntax query to a ProcessCoveragesRequest */
- LOG.debug("Converting WCPS abstract query '{}' to xml", abstractRequest);
+ log.debug("Converting WCPS abstract query '{}' to xml", abstractRequest);
xmlRequest = ProcessCoveragesRequest.abstractQueryToXmlQuery(abstractRequest);
- LOG.debug("Resulting XML query is: \n{}", xmlRequest);
+ log.debug("Resulting XML query is: \n{}", xmlRequest);
} catch (RecognitionException re) {
- throw new NoApplicableCodeException("Internal error: Generated abstract syntax query was not valid.", re);
+ throw new WCSException(ExceptionCode.NoApplicableCode, "Internal error: Generated abstract syntax query was not valid.", re);
}
return xmlRequest;
@@ -149,10 +139,10 @@ public class convertGetCoverage {
*/
private void readField2() throws WCSException {
if (!wcs.isSetDomainSubset()) {
- throw new MissingParameterValueException("DomainSubset");
+ throw new WCSException(ExceptionCode.MissingParameterValue, "DomainSubset");
}
if (!wcs.getDomainSubset().isSetBoundingBox()) {
- throw new MissingParameterValueException("BoundingBox");
+ throw new WCSException(ExceptionCode.MissingParameterValue, "BoundingBox");
}
DomainSubsetType domain = wcs.getDomainSubset();
@@ -166,27 +156,27 @@ public class convertGetCoverage {
crsName = bbox.getCrs();
if (crsName != null) {
if (crsName.equals(DomainElement.IMAGE_CRS)) {
- LOG.trace("CRS: NATIVE_IMAGE_CRS");
+ log.trace("CRS: NATIVE_IMAGE_CRS");
} else if (crsName.equals(DomainElement.WGS84_CRS)) {
- LOG.trace("CRS: WGS84");
+ log.trace("CRS: WGS84");
} else {
- throw new InvalidParameterValueException("BoundingBox.crs. Explanation: "
+ throw new WCSException(ExceptionCode.InvalidParameterValue, "BoundingBox.crs. Explanation: "
+ "CRS '" + crsName + "' not available on this server.");
}
} else {
- LOG.debug("CRS: None specified for bounding box");
- LOG.debug("CRS: Using default IMAGE_CRS");
+ log.debug("CRS: None specified for bounding box");
+ log.debug("CRS: Using default IMAGE_CRS");
crsName = DomainElement.IMAGE_CRS;
}
/* BBox declarations */
if (bbox.getLowerCorner().size() != 2) {
- throw new InvalidParameterValueException("LowerCorner. Explanation: "
+ throw new WCSException(ExceptionCode.InvalidParameterValue, "LowerCorner. Explanation: "
+ "BoundingBox -> LowerCorner should have exactly two "
+ "values, not " + bbox.getLowerCorner().size());
}
if (bbox.getUpperCorner().size() != 2) {
- throw new InvalidParameterValueException("UpperCorner. Explanation: "
+ throw new WCSException(ExceptionCode.InvalidParameterValue, "UpperCorner. Explanation: "
+ "BoundingBox -> UpperCorner should have exactly two "
+ "values, not " + bbox.getUpperCorner().size());
}
@@ -194,13 +184,13 @@ public class convertGetCoverage {
xAxisTrim = true;
int u2 = bbox.getLowerCorner().get(0).intValue();
int u3 = bbox.getUpperCorner().get(0).intValue();
- LOG.trace("Added X-axis trimming ! (DomainSubset->BoundingBox): " + u2 + " ... "
+ log.trace("Added X-axis trimming ! (DomainSubset->BoundingBox): " + u2 + " ... "
+ u3);
yAxisTrim = true;
int v2 = bbox.getLowerCorner().get(1).intValue();
int v3 = bbox.getUpperCorner().get(1).intValue();
- LOG.trace("Added Y-axis trimming ! (DomainSubset->BoundingBox): " + v2 + " ... "
+ log.trace("Added Y-axis trimming ! (DomainSubset->BoundingBox): " + v2 + " ... "
+ v3);
/* Use bounding-box values as they are given */
@@ -211,7 +201,7 @@ public class convertGetCoverage {
if (crsName.equals(DomainElement.IMAGE_CRS) == false
&& crsName.equals(DomainElement.WGS84_CRS) == false) {
- throw new NoApplicableCodeException("Unknown CRS: " + crsName);
+ throw new WCSException(ExceptionCode.NoApplicableCode, "Unknown CRS: " + crsName);
}
}
@@ -220,7 +210,7 @@ public class convertGetCoverage {
// TemporalSubset is of type TimeSequenceType = choice(gml:TimePosition, wcs:TimePeriodType)
Object one = domain.getTemporalSubset().getTimePositionOrTimePeriod().get(0);
- LOG.trace("Inside TemporalSubset there is " + one.getClass());
+ log.trace("Inside TemporalSubset there is " + one.getClass());
if (one instanceof net.opengis.gml.v_3_1_1.TimePositionType) {
// TemporalSubset = gml:TimePosition
// use WCPS:slice
@@ -232,7 +222,7 @@ public class convertGetCoverage {
/* Default syntax is ISO 8601.
However, we also accept direct time-axis coordinates, as a fail-back solution. */
timePos = parseTimePosition(pos);
- LOG.trace("Added time-axis slicing ! ( DomainSubset->TemporalSubset->gml:TimePositionType): position "
+ log.trace("Added time-axis slicing ! ( DomainSubset->TemporalSubset->gml:TimePositionType): position "
+ timePos);
} else if (one instanceof net.opengis.wcs.v_1_1_0.TimePeriodType) {
// TemporalSubset = wcs:TimePeriodType
@@ -248,7 +238,7 @@ public class convertGetCoverage {
time1 = parseTimePosition(pos1);
time2 = parseTimePosition(pos2);
- LOG.trace("Added time-axis trimming ! ( DomainSubset->TemporalSubset->wcs:TimePeriodType): "
+ log.trace("Added time-axis trimming ! ( DomainSubset->TemporalSubset->wcs:TimePeriodType): "
+ time1 + " ... " + time2);
}
}
@@ -270,9 +260,9 @@ public class convertGetCoverage {
RangeSubsetType.FieldSubset field = it.next();
fields.add(field.getIdentifier().getValue());
- LOG.trace("RangeSubsetType->FieldSubset->Identifier is "
+ log.trace("RangeSubsetType->FieldSubset->Identifier is "
+ field.getIdentifier().getValue());
- LOG.trace("RangeSubsetType->FieldSubset->Interpolation is "
+ log.trace("RangeSubsetType->FieldSubset->Interpolation is "
+ field.getInterpolationType());
/* NOTE: We ignore interpolation instructions (optional) */
/* NOTE: We ignore axis subset lists (optional) */
@@ -287,26 +277,26 @@ public class convertGetCoverage {
*/
private void readField4() throws WCSException {
if (!wcs.isSetOutput()) {
- throw new MissingParameterValueException("Output");
+ throw new WCSException(ExceptionCode.MissingParameterValue, "Output");
}
- LOG.trace("Format: " + wcs.getOutput().getFormat());
+ log.trace("Format: " + wcs.getOutput().getFormat());
if (wcs.getOutput().isSetGridCRS()) {
GridCrsType crs = wcs.getOutput().getGridCRS();
- throw new NoApplicableCodeException("Currently, the Output->GridCRS node is not supported !");
+ throw new WCSException(ExceptionCode.NoApplicableCode, "Currently, the Output->GridCRS node is not supported !");
}
String wcsMimeFormat = wcs.getOutput().getFormat();
format = meta.mimetypeToFormat(wcsMimeFormat);
- LOG.trace("New format: " + format);
+ log.trace("New format: " + format);
if ((format == null) || format.equals("")) {
- throw new InvalidParameterValueException("Output format");
+ throw new WCSException(ExceptionCode.InvalidParameterValue, "Output format");
}
- LOG.trace("issetstore = " + wcs.getOutput().isSetStore());
- LOG.trace("isstore = " + wcs.getOutput().isStore());
+ log.trace("issetstore = " + wcs.getOutput().isSetStore());
+ log.trace("isstore = " + wcs.getOutput().isStore());
store = false;
if (wcs.getOutput().isSetStore() && wcs.getOutput().isStore()) {
store = true;
@@ -314,7 +304,7 @@ public class convertGetCoverage {
/* WCPS does not support "store=true" */
if (store) {
- throw new InvalidParameterValueException("Output Store. Explanation: "
+ throw new WCSException(ExceptionCode.InvalidParameterValue, "Output Store. Explanation: "
+ "Cannot store result image on server.");
}
}
@@ -327,50 +317,50 @@ public class convertGetCoverage {
public void process() throws WCSException {
/** * Processing starts here ... with the nodes of the WCS * */
// Service Description
- LOG.debug("WCS service: \"" + wcs.SERVICE + "\"");
- LOG.debug("WCS version: \"" + wcs.VERSION + "\"");
+ log.debug("WCS service: \"" + wcs.SERVICE + "\"");
+ log.debug("WCS version: \"" + wcs.VERSION + "\"");
if (!wcs.SERVICE.equalsIgnoreCase("WCS")) {
- throw new InvalidParameterValueException("Service. Explanation: "
+ throw new WCSException(ExceptionCode.InvalidParameterValue, "Service. Explanation: "
+ "Only the WCS service is supported.");
}
if (!wcs.VERSION.equals("1.1.0")) {
- throw new InvalidParameterValueException("Version. Explanation: "
+ throw new WCSException(ExceptionCode.InvalidParameterValue, "Version. Explanation: "
+ "Only WCS Version 1.1.0 is currently supported.");
}
// First of all, error checking: is the coverage offered by the server?
if (!wcs.isSetIdentifier()) {
- throw new MissingParameterValueException("Identifier");
+ throw new WCSException(ExceptionCode.MissingParameterValue, "Identifier");
}
try {
if (!meta.existsCoverageName(wcs.getIdentifier().getValue())) {
- throw new InvalidParameterValueException("Identifier. Explanation: "
+ throw new WCSException(ExceptionCode.InvalidParameterValue, "Identifier. Explanation: "
+ "Coverage " + wcs.getIdentifier().getValue()
+ " is not served by this server.");
}
covMeta = meta.read(wcs.getIdentifier().getValue());
- } catch (WCPSException e) {
- throw new InvalidParameterValueException("Identifier. Explanation: "
+ } catch (Exception e) {
+ throw new WCSException(ExceptionCode.InvalidParameterValue, "Identifier. Explanation: "
+ "Coverage " + wcs.getIdentifier().getValue()
+ " is not served by this server.");
}
// Convert all the child nodes of WCS GetCoverage XML node
- LOG.trace("*** Reading WCS node 1 ... ");
+ log.trace("*** Reading WCS node 1 ... ");
readField1();
- LOG.trace("*** Reading WCS node 2 ...");
+ log.trace("*** Reading WCS node 2 ...");
readField2();
- LOG.trace("*** Reading WCS node 3 ...");
+ log.trace("*** Reading WCS node 3 ...");
readField3();
- LOG.trace("*** Reading WCS node 4 ...");
+ log.trace("*** Reading WCS node 4 ...");
readField4();
- LOG.trace("*** Assembling WCPS abstract syntax query ...");
+ log.trace("*** Assembling WCPS abstract syntax query ...");
assembleFinalWcpsQuery();
/* Done building WCPS abstract query. */
finished = true;
- LOG.trace("Done Converting WCS GetCoverage into WCPS ProcessCoverage.");
+ log.trace("Done Converting WCS GetCoverage into WCPS ProcessCoverage.");
}
/**
@@ -442,55 +432,55 @@ public class convertGetCoverage {
private String parseTimePosition(TimePositionType pos) throws WCSException {
String result;
- LOG.trace("TimePosition has length " + pos.getValue().size());
+ log.trace("TimePosition has length " + pos.getValue().size());
if (pos.getValue().size() != 1) {
- throw new InvalidParameterValueException("TimePosition. Explanation: "
+ throw new WCSException(ExceptionCode.InvalidParameterValue, "TimePosition. Explanation: "
+ "The TimePosition element should have exactly one item, and not "
+ pos.getValue().size());
}
String timeStr = pos.getValue().get(0);
- LOG.debug("Parsing time position: " + timeStr);
+ log.debug("Parsing time position: " + timeStr);
try {
// ISO 8601 parsing
TimeString ts = new TimeString(timeStr);
- LOG.debug("Found time position (ISO 8601): " + timeStr);
+ log.debug("Found time position (ISO 8601): " + timeStr);
if (ts.subtract(covMeta.getTimePeriodBeginning()) < 0
|| TimeString.difference(covMeta.getTimePeriodEnd(), timeStr) < 0) {
- throw new InvalidParameterValueException("TimePosition: value " + timeStr
+ throw new WCSException(ExceptionCode.InvalidParameterValue, "TimePosition: value " + timeStr
+ " is outside this coverage's time range.");
}
String begin = covMeta.getTimePeriodBeginning();
if (begin == null) {
- throw new InvalidTemporalMetadataException("Coverage '" + covMeta.getCoverageName()
+ throw new WCSException(ExceptionCode.InvalidTemporalMetadata, "Coverage '" + covMeta.getCoverageName()
+ "' has no time axis beginning or end in table PS_Domain.");
}
long diff1 = ts.subtract(begin);
- LOG.trace("Selected time span (ISO 8601, in ms) : " + diff1);
+ log.trace("Selected time span (ISO 8601, in ms) : " + diff1);
long diff2 = covMeta.getTimeSpan();
if (diff2 == -1) {
- throw new InvalidTemporalMetadataException("Coverage '" + covMeta.getCoverageName()
+ throw new WCSException(ExceptionCode.InvalidTemporalMetadata, "Coverage '" + covMeta.getCoverageName()
+ "' has no time axis beginning or end in table PS_Domain.");
}
- LOG.trace("Coverage " + covMeta.getCoverageName() + " has time span (ISO 8601, in ms) : " + diff2);
- LOG.trace("Coverage " + covMeta.getCoverageName() + " has time indexes span : " + covMeta.getTimeIndexesSpan());
+ log.trace("Coverage " + covMeta.getCoverageName() + " has time span (ISO 8601, in ms) : " + diff2);
+ log.trace("Coverage " + covMeta.getCoverageName() + " has time indexes span : " + covMeta.getTimeIndexesSpan());
Double dIndex = covMeta.getTimeIndexesSpan() * diff1 * new Double(1.0) / diff2;
if (dIndex == -1) {
- throw new InvalidTemporalMetadataException("Coverage '" + covMeta.getCoverageName()
+ throw new WCSException(ExceptionCode.InvalidTemporalMetadata, "Coverage '" + covMeta.getCoverageName()
+ "' has no time axis.");
}
- LOG.trace("Computed time axis index: " + dIndex);
+ log.trace("Computed time axis index: " + dIndex);
long timeIndex = dIndex.longValue();
result = String.valueOf(timeIndex);
} catch (IllegalArgumentException e) {
- LOG.warn("Time position '" + timeStr + "' was not in ISO 8601 format. Trying to parse integer...");
+ log.warn("Time position '" + timeStr + "' was not in ISO 8601 format. Trying to parse integer...");
try {
Integer tPos = Integer.parseInt(timeStr);
- LOG.debug("Found time position in integer coordinates: " + tPos);
+ log.debug("Found time position in integer coordinates: " + tPos);
result = tPos.toString();
} catch (NumberFormatException e2) {
- throw new InvalidParameterValueException("TimePosition: " + timeStr, e2);
+ throw new WCSException(ExceptionCode.InvalidParameterValue, "TimePosition: " + timeStr, e2);
}
}