V1_0.java [src/java/m/wqm/wqm24_ipmscoresfull] Revision: Date:
package m.wqm.wqm24_ipmscoresfull;
/**
* @author anvesh, rumpal
*/
import csip.ModelDataService;
import csip.api.server.ServiceException;
import csip.annotations.Resource;
import java.util.ArrayList;
import javax.ws.rs.Path;
import csip.annotations.Description;
import csip.annotations.Name;
import org.codehaus.jettison.json.JSONArray;
import csip.utils.JSONUtils;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import org.codehaus.jettison.json.JSONException;
import wqm.utils.DBQueries;
import wqm.utils.DBResources;
import static wqm.utils.DBResources.WQM_READONLY_ID;
@Name("WQM-24: IPM Scores")
@Description("This service returns all rows and columns from the wqm_ipm_scores table.")
@Path("m/ipmscoresfull/1.0")
@Resource(from = DBResources.class)
public class V1_0 extends ModelDataService {
private ArrayList<Result1> result1 = new ArrayList();
@Override
protected void doProcess() throws SQLException, ServiceException {
try (Connection connection = resources().getJDBC(WQM_READONLY_ID);
Statement statement = connection.createStatement();
ResultSet resultSet = statement.executeQuery(DBQueries.WQM24Query())) {
while (resultSet.next()) {
int ipm_score_id = resultSet.getInt("ipm_score_id");
int ipm_mitigation_score = resultSet.getInt("ipm_mitigation_score");
String resource_concern = resultSet.getString("resource_concern");
String ipm_level = resultSet.getString("ipm_level");
String wqm_concern = resultSet.getString("wqm_concern");
String ipm_level_name = resultSet.getString("ipm_level_name");
result1.add(new Result1(ipm_score_id, ipm_mitigation_score,
resource_concern, ipm_level, wqm_concern, ipm_level_name));
}
}
}
@Override
protected void postProcess() throws JSONException {
JSONArray result1Arr = new JSONArray();
for (Result1 rs1 : result1) {
JSONArray tmpArr = new JSONArray();
tmpArr.put(JSONUtils.dataDesc("ipm_score_id", rs1.ipm_score_id, "ipm_score_id"));
tmpArr.put(JSONUtils.dataDesc("ipm_mitigation_score", rs1.ipm_mitigation_score, "ipm_mitigation_score"));
tmpArr.put(JSONUtils.dataDesc("resource_concern", rs1.resource_concern, "NRCS resource concern"));
tmpArr.put(JSONUtils.dataDesc("ipm_level", rs1.ipm_level, "Treatment level of integrated pest management: I (Basic), II (Intermediate), or III (Advanced)"));
tmpArr.put(JSONUtils.dataDesc("wqm_concern", rs1.wqm_concern, "WQM resource concern: pesticide leaching, pesticide solution runoff, pesticide adsorbed runoff, pesticide drift"));
tmpArr.put(JSONUtils.dataDesc("ipm_level_name", rs1.ipm_level_name, "Treatment level of integrated pest management: Basic, Intermediate, Advanced"));
result1Arr.put(JSONUtils.dataDesc("IPM Scores", tmpArr, "IPMScores"));
}
results().put("operation", result1Arr);
}
static class Result1 {
int ipm_score_id;
int ipm_mitigation_score;
String resource_concern;
String ipm_level;
String wqm_concern;
String ipm_level_name;
public Result1(
int ipm_score_id,
int ipm_mitigation_score,
String resource_concern,
String ipm_level,
String wqm_concern,
String ipm_level_name) {
this.ipm_score_id = ipm_score_id;
this.ipm_mitigation_score = ipm_mitigation_score;
this.resource_concern = resource_concern;
this.ipm_level = ipm_level;
this.wqm_concern = wqm_concern;
this.ipm_level_name = ipm_level_name;
}
}
}