Climate1_1.java [src/java/d/rusle2] Revision: default Date:
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package d.rusle2;
import c.GIS_DB.FileQryResult;
import c.SqlGIS;
import csip.Config;
import java.util.Date;
import javax.ws.rs.Path;
import csip.ModelDataService;
import csip.ServiceException;
import csip.annotations.*;
import csip.annotations.Resource;
import static csip.annotations.ResourceType.JDBC;
import static csip.annotations.State.RELEASED;
import static d.rusle2.Climate1_1.DB;
/**
* EPA climate service
*
* @author wlloyd
*/
@Name("Climate")
@Description("EPA climate service")
@VersionInfo("1.1")
@State(RELEASED)
@Path("d/rusle2/climate/1.1")
@Resource(type = JDBC, file = "${conservation_resources.db}", id = DB)
public class Climate1_1 extends ModelDataService {
static final String DB = "csip.erosion.sqlsvr";
String rusle2db = Config.getString("r2.db", "http://csip.engr.colostate.edu/r2");
@Override
protected void doProcess() throws Exception {
double lat =parameter().getDouble("latitude");
double lon =parameter().getDouble("longitude");
SqlGIS db = new SqlGIS(resources().getJDBC(DB));
try {
LOG.info("get lat long from content input");
if (!db.IsValidCliCoord(lat, lon)) {
throw new ServiceException("Invalid lat/lon : " + lat + "/" + lon);
}
FileQryResult climate = db.findClimate(lat, lon);
if (climate == null) {
throw new ServiceException("No climate found");
}
LOG.info("found climate for lat lng");
String sClimate = rusle2db + "/epa/" + climate.file_path + "/" + climate.file_name + ".xml";
sClimate = fixClimateUrl(sClimate);
results().put("tstamp", new Date());
results().put("climate", sClimate);
} finally {
db.close();
}
}
private String fixClimateUrl(String text) {
// remove \/ 's
text = text.replace("\\/", "/");
// convert \\ to /
text = text.replace("\\\\", "/");
// convert / to \
text = text.replace("\\", "/");
return text;
}
}