V1_0.java [src/java/m/rhem/rhem05_slopeShapes] Revision: default Date:
/*
* $Id$
*
* This file is part of the Cloud Services Integration Platform (CSIP),
* a Model-as-a-Service framework, API, and application suite.
*
* 2012-2017, OMSLab, Colorado State University.
*
* OMSLab licenses this file to you under the MIT license.
* See the LICENSE file in the project root for more information.
*/
package m.rhem.rhem05_slopeShapes;
import csip.ModelDataService;
import csip.api.server.ServiceException;
import csip.annotations.Polling;
import csip.annotations.Resource;
import csip.utils.JSONUtils;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import javax.ws.rs.Path;
import csip.annotations.Description;
import csip.annotations.Name;
import java.util.List;
import org.codehaus.jettison.json.JSONArray;
import org.codehaus.jettison.json.JSONException;
import m.rhem.DBResources;
import static m.rhem.DBResources.CRDB;
/**
* RHEM-05: Get RHEM Slope Shape Choice List
*
* @version 1.0
* @author rumpal
*/
@Name("RHEM-05: Get RHEM Slope Shape Choice List.")
@Description("Get and return a list of RHEM slope shapes.")
@Path("m/rhem/getslopeshapes/1.0")
@Polling(first = 10000, next = 2000)
@Resource(from = DBResources.class)
public class V1_0 extends ModelDataService {
private List<ChoiceList> choiceList = new ArrayList<>();
@Override
public void doProcess() throws Exception {
try (Connection conn = resources().getJDBC(CRDB);
Statement statement = conn.createStatement()) {
try (ResultSet resultSet = statement.executeQuery(DBResources.RHEM05Query01())) {
while (resultSet.next()) {
int id = resultSet.getInt("choice_id");
String label = resultSet.getString("choice_label");
choiceList.add(new ChoiceList(id, "slope shape", id, label));
}
}
}
}
@Override
public void postProcess() throws Exception {
JSONArray resultArr = new JSONArray();
for (ChoiceList list : choiceList) {
JSONArray choiceListArr = new JSONArray()
.put(JSONUtils.dataDesc("choice_id", list.getChoiceId(), "Choice Identifier"))
.put(JSONUtils.dataDesc("choice_kind", list.getChoiceKind(), "Choice Kind"))
.put(JSONUtils.dataDesc("choice_sequence", list.getChoiceSequence(), "Choice Sequence"))
.put(JSONUtils.dataDesc("choice_label", list.getChoiceLabel(), "Choice Label"));
resultArr.put(JSONUtils.dataDesc("slope_shape", choiceListArr, "Slope Shape"));
}
results().put("choice_lists", resultArr, "Slope Shape Choice List");
}
static class ChoiceList {
int id;
String kind;
int sequence;
String label;
public ChoiceList(int id, String kind, int sequence, String label) {
this.id = id;
this.kind = kind;
this.sequence = sequence;
this.label = label;
}
public int getChoiceId() {
return id;
}
public String getChoiceKind() {
return kind;
}
public int getChoiceSequence() {
return sequence;
}
public String getChoiceLabel() {
return label;
}
}
}