Skip to content

Commit

Permalink
Merge pull request #150 from asascience-open/milestone_1_issues
Browse files Browse the repository at this point in the history
Exception Handling
  • Loading branch information
cheryldmorse committed Aug 28, 2014
2 parents bc15fab + 670af84 commit ef4a3dd
Show file tree
Hide file tree
Showing 12 changed files with 54 additions and 27 deletions.
Binary file modified jar/ncSOS-RC9-SNAPSHOT.zip
Binary file not shown.
Binary file modified jar/ncSOS.zip
Binary file not shown.
4 changes: 2 additions & 2 deletions src/main/java/com/asascience/ncsos/cdmclasses/Grid.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
public class Grid extends baseCDMClass implements iStationData {

private static final String DEPTH = "depth";
private static final String LAT = "latitude";
private static final String LON = "longitude";
public static final String LAT = "latitude";
public static final String LON = "longitude";
private List<String> stationNameList;
private List<String> stationDescripList;
private final String[] variableNames;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/asascience/ncsos/ds/BaseDSHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ private boolean checkDatasetForProcedure(String procedure) {
_log.error("procedure is null");
return false;
}
if (procedure.toLowerCase().contains(NETWORK) && procedure.toLowerCase().contains(ALL))
if (procedure.equals(this.getUrnNetworkAll()))
return true;
// get a list of procedures from dataset and compare it to the passed-in procedure
// get list of station names
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ private void describeNetwork() {
this.network.setVersionMetadata();
this.network.setDescriptionNode((String)this.getGlobalAttribute("description", "No description found"));
this.network.setName(this.procedure);
this.network.removeSmlLocation();
this.formatSmlIdentification();
this.formatSmlClassification();
this.formatSmlValidTime();
Expand Down Expand Up @@ -195,8 +196,8 @@ public String apply(String in) {
dataVars.add(var.getShortName());
}
HashMap<String,String> latLon = new HashMap<String, String>();
latLon.put("lat", this.getGridDataset().getBoundingBox().getLatMin() + "_" + this.getGridDataset().getBoundingBox().getLatMax());
latLon.put("lon", this.getGridDataset().getBoundingBox().getLonMin() + "_" + this.getGridDataset().getBoundingBox().getLonMax());
latLon.put(Grid.LAT, this.getGridDataset().getBoundingBox().getLatMin() + "_" + this.getGridDataset().getBoundingBox().getLatMax());
latLon.put(Grid.LON, this.getGridDataset().getBoundingBox().getLonMin() + "_" + this.getGridDataset().getBoundingBox().getLonMax());
this.stationData = new Grid(stationNames.toArray(new String[stationNames.size()]), null, dataVars.toArray(new String[dataVars.size()]), latLon);
this.stationData.setData(this.getGridDataset());
break;
Expand Down
15 changes: 10 additions & 5 deletions src/main/java/com/asascience/ncsos/ds/IoosPlatform10Handler.java
Original file line number Diff line number Diff line change
Expand Up @@ -239,9 +239,14 @@ private void formatSmlLocationLine() {

private void formatSmlLocationBbox() {
for (Map.Entry<Integer,String> station : this.getStationNames().entrySet()) {
if (station.getValue().equalsIgnoreCase(this.stationName)) {
String lc = this.stationData.getLowerLat(station.getKey()) + " " + this.stationData.getLowerLon(station.getKey());
String uc = this.stationData.getUpperLat(station.getKey()) + " " + this.stationData.getUpperLon(station.getKey());
String stationName = station.getValue();
Integer stationKey = station.getKey();
if (stationName.equalsIgnoreCase(this.stationName) ||
this.getUrnName(stationName).equalsIgnoreCase(this.stationName)) {
String lc = this.stationData.getLowerLat(stationKey) + " " +
this.stationData.getLowerLon(stationKey);
String uc = this.stationData.getUpperLat(stationKey) + " " +
this.stationData.getUpperLon(stationKey);
platform.setSmlPosLocationBbox(this.getCrsName(), lc, uc);
}
}
Expand Down Expand Up @@ -293,8 +298,8 @@ private void setStationData() throws IOException {
break;
case GRID:
HashMap<String,String> latLon = new HashMap<String, String>();
latLon.put("lat", this.getGridDataset().getBoundingBox().getLatMin() + "_" + this.getGridDataset().getBoundingBox().getLatMax());
latLon.put("lon", this.getGridDataset().getBoundingBox().getLonMin() + "_" + this.getGridDataset().getBoundingBox().getLonMax());
latLon.put(Grid.LAT, this.getGridDataset().getBoundingBox().getLatMin() + "_" + this.getGridDataset().getBoundingBox().getLatMax());
latLon.put(Grid.LON, this.getGridDataset().getBoundingBox().getLonMin() + "_" + this.getGridDataset().getBoundingBox().getLonMax());
List<String> dataVars = new ArrayList<String>();
for (VariableSimpleIF var : this.getDataVariables()) {
dataVars.add(var.getShortName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,7 @@ public void parseGetCapabilitiesDocument() throws IOException {
// remove identification from doc
out.removeServiceIdentification();
}
//// check here to see if we need to initialize the data
// if(this.requestedSections.get(Sections.SERVICEIDENTIFICATION.ordinal()) &&
// this.requestedSections.cardinality() == 1)){
//
// }

// service provider; parse if it is the section identified or 'all'
if (this.requestedSections.get(Sections.SERVICEPROVIDER.ordinal())) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,7 @@ public abstract class OutputFormatter {
public static final String FEATURE_COLLECTION = "FeatureCollection";
public static final String USE = "use";
public static final String REQUIRED = "required";
public static final String LAT = "lat";
public static final String LON = "lon";

public static final String HISTORY = "history";
public static final String IDENTIFIER = "identifier";
public static final String SML_VALUE = "value";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,11 @@ public void setComponentLocation(String componentName, String srs, String lowerC
addNewNode(bb, UPPER_CORNER, GML_NS, upperCorner);
}

public void removeSmlLocation(){
Element parent = XMLDomUtils.getNestedChild(this.getRoot(), SYSTEM, SML_NS);
parent.removeChildren(LOCATION, SML_NS);
}

public void addComponentOutput(String componentName, String outName, String outURN, String outDef, String featureType, String units) {
/*
* <sml:output name='outName' xlink:title='outURN'>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,39 +80,47 @@ public String getTemplateLocation() {
* of text/xml;subtype="om/1.0.0/profiles/ioos_sos/1.0"
*/
private void createIoosSosResponse() {
String processingStr = "metaDataProperty";

try {
// Set NcSOS version
this.setVersionMetadata();

// Get the om:Observation element
Element obsElement = this.getRoot().getChild("member", this.OM_NS).getChild("Observation", this.OM_NS);
// Description
processingStr = "description";
obsElement.addContent(new Element("description", this.GML_NS).setText(
(String)this.handler.getGlobalAttribute("description", "No description")));

processingStr = "samplingTime";
Element samplingTime = new Element("samplingTime", this.OM_NS);
samplingTime.addContent(this.createTimePeriodTree());
obsElement.addContent(samplingTime);

processingStr = "procedure";
Element procedure = new Element("procedure", this.OM_NS);
procedure.addContent(this.createProcessTree());
obsElement.addContent(procedure);

processingStr = "observedProperty";
Element observProp = new Element("observedProperty", this.OM_NS);
observProp.addContent(this.createCompositePhenomTree());
obsElement.addContent(observProp);

processingStr = "featureOfInterest";
Element foi = new Element("featureOfInterest", this.OM_NS);
foi.addContent(this.createFeatureCollectionTree());
obsElement.addContent(foi);

processingStr = "result";
Element res = new Element("result", this.OM_NS);
res.addContent(this.createDataRecordTree());
obsElement.addContent(res);

} catch (Exception ex) {
_log.error(ex.toString());
this.setupException("Unable to correctly create response for request: " + ex.toString());
this.setupException("Unable to correctly create response for request: " + ex.toString()+
"\n Error when creating the following response block: " + processingStr);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public static NetcdfDataset openDataset(final HttpServletRequest req,
try {
dataset = NetcdfDataset.openDataset(datasetPath);
} catch (IOException e) {
_log.error("Failed to open dataset <" + datasetPath + ">: "
throw new Exception("Failed to open dataset <" + datasetPath + ">: "
+ e.getMessage());
}

Expand All @@ -51,9 +51,8 @@ public static NetcdfDataset openDataset(final HttpServletRequest req,
dataset = new NetcdfDataset(netcdfFile);

} catch (IOException e) {
_log.error("Failed to open dataset <" + datasetPath + ">: "
throw new Exception("Failed to open dataset <" + datasetPath + ">: "
+ e.getMessage());
e.printStackTrace();
}
}
return dataset;
Expand Down
24 changes: 19 additions & 5 deletions src/main/java/thredds/server/ncsos/controller/SosController.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
package thredds.server.ncsos.controller;

import com.asascience.ncsos.outputformatter.ErrorFormatter;
import com.asascience.ncsos.outputformatter.OutputFormatter;
import com.asascience.ncsos.service.Parser;
import com.asascience.ncsos.util.DatasetHandlerAdapter;

import org.apache.log4j.BasicConfigurator;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import ucar.nc2.dataset.NetcdfDataset;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import java.io.IOException;
import java.io.Writer;
import java.util.HashMap;
Expand Down Expand Up @@ -53,25 +57,34 @@ public void handleSOSRequest(final HttpServletRequest req, final HttpServletResp
NetcdfDataset dataset = null;

respMap = new HashMap<String, Object>();

Writer writer = res.getWriter();
try {
//see http://tomcat.apache.org/tomcat-5.5-doc/config/context.html ----- workdir
String tempdir = System.getProperty("java.io.tmpdir");

dataset = DatasetHandlerAdapter.openDataset(req, res);

Parser md = new Parser();
respMap = md.enhanceGETRequest(dataset, req.getQueryString(), req.getRequestURL()+"?".toString(),tempdir);

Writer writer = res.getWriter();
respMap = md.enhanceGETRequest(dataset, req.getQueryString(), req.getRequestURL()+"?".toString(),tempdir);
OutputFormatter output = (OutputFormatter)respMap.get("outputFormatter");
res.setContentType(output.getContentType().toString());
output.writeOutput(writer);
writer.flush();
writer.close();


} catch (Exception e) {
}

catch (Exception e) {
_log.error("Something went wrong", e);

ErrorFormatter output = new ErrorFormatter();
output.setException(e.getMessage());


output.writeOutput(writer);
writer.flush();
writer.close();
//close the dataset remove memory hang
} finally {
// This is a workaround for a bug in thredds. On the second request
Expand All @@ -94,6 +107,7 @@ public void handleSOSRequest(final HttpServletRequest req, final HttpServletResp


}


}
}

0 comments on commit ef4a3dd

Please sign in to comment.