V1_0.java [src/java/d/states/geometry] Revision: default Date:
package d.states.geometry;
import csip.ModelDataService;
import csip.api.server.PayloadParameter;
import csip.api.server.PayloadResults;
import csip.api.server.ServiceException;
import csip.annotations.Description;
import csip.annotations.Name;
import csip.annotations.Resource;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.logging.Level;
import javax.ws.rs.Path;
import cities.utils.DBResources;
import cities.utils.PostgresqlLocationsDatabase;
import m.utils.Layer;
import org.codehaus.jettison.json.JSONObject;
/**
* Last Updated: 21-June-2019
* @author Tyler Wible
* @since 30-August-2016
*/
@Name("States geometry")
@Description("Retrieve 2010 U.S. Census polygon geometries for states that match a given OID")
@Path("d/states/geometry/1.0")
@Resource(from = DBResources.class)
public class V1_0 extends ModelDataService {
protected PostgresqlLocationsDatabase db;
protected int oid;
protected JSONObject result;
@Override
protected void preProcess() throws Exception {
PayloadParameter inputPayload = parameter();
oid = inputPayload.getInt("oid");
}
@Override
protected void doProcess() throws Exception {
try (Connection c = resources().getJDBC(DBResources.cities_ID)) {
db = new PostgresqlLocationsDatabase(c);
Layer lyr = db.getLocation("census", "tl_2010_us_state10", "gid", oid);
result = db.toJSON(lyr);
} catch (SQLException | ServiceException ex) {
LOG.log(Level.SEVERE, null, ex);
throw new ServiceException(ex);
}
}
@Override
protected void postProcess() throws Exception {
PayloadResults resultPayload = results();
resultPayload.put("result", result);
}
}