V1_0.java [src/java/m/wqm/wqm22_nutmitigationtech] Revision: default Date:
package m.wqm.wqm22_nutmitigationtech;
import csip.ModelDataService;
import csip.api.server.ServiceException;
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 org.codehaus.jettison.json.JSONArray;
import org.codehaus.jettison.json.JSONException;
import wqm.utils.DBQueries;
import wqm.utils.DBResources;
/**
*
* @author Sandeep
*/
@Name("WQM-22: Get Nutrient Mitigation Techniques")
@Description("This service returns all rows and columns from the wqm_nutrient_technique_scores table.")
@Path("m/nutmitigationtech/1.0")
@Resource(from = DBResources.class)
public class V1_0 extends ModelDataService {
private ArrayList<Result1> result1 = new ArrayList<>();
@Override
public void doProcess() throws ServiceException, SQLException {
try (Connection connection = resources().getJDBC(DBResources.WQM_READONLY_ID);
Statement statement = connection.createStatement();
ResultSet resultSet = statement.executeQuery(DBQueries.WQM22Query())) {
while (resultSet.next()) {
int nutrient_technique_score_id = resultSet.getInt("nutrient_technique_score_id");
int nutrient_technique_id = resultSet.getInt("nutrient_technique_id");
int nut_tech_score = resultSet.getInt("nut_tech_score");
String nut_tech_kind = resultSet.getString("nut_tech_kind");
String nut_tech_description = resultSet.getString("nut_tech_description");
String wqm_concern = resultSet.getString("wqm_concern");
String mode_of_action = resultSet.getString("mode_of_action");
String tech_discrim_type = resultSet.getString("tech_discrim_type");
String tech_discrim = resultSet.getString("tech_discrim");
result1.add(new Result1(nutrient_technique_score_id, nutrient_technique_id,
nut_tech_score, nut_tech_kind, nut_tech_description,
wqm_concern, mode_of_action, tech_discrim_type, tech_discrim));
}
}
}
@Override
public void postProcess() throws JSONException {
JSONArray result1Arr = new JSONArray();
for (Result1 rs1 : result1) {
JSONArray tmpArr = new JSONArray();
tmpArr.put(JSONUtils.dataDesc("nutrient_technique_score_id", rs1.nutrient_technique_score_id, "Nutrient Technique Score Identifier"));
tmpArr.put(JSONUtils.dataDesc("nutrient_technique_id", rs1.nutrient_technique_id, "Nutrient Technique Identifier"));
tmpArr.put(JSONUtils.dataDesc("nut_tech_score", rs1.nut_tech_score, "nut_tech_score"));
tmpArr.put(JSONUtils.dataDesc("nut_tech_kind", rs1.nut_tech_kind, "nut_tech_kind"));
tmpArr.put(JSONUtils.dataDesc("nut_tech_description", rs1.nut_tech_description, "nut_tech_description"));
tmpArr.put(JSONUtils.dataDesc("wqm_concern", rs1.wqm_concern, "WQM Resource Concern"));
tmpArr.put(JSONUtils.dataDesc("mode_of_action", rs1.mode_of_action, "Mode of action of the nutrient technique"));
tmpArr.put(JSONUtils.dataDesc("tech_discrim_type", rs1.tech_discrim_type, "tech_discrim_type"));
tmpArr.put(JSONUtils.dataDesc("tech_discrim", rs1.tech_discrim, "tech_discrim"));
result1Arr.put(tmpArr);
}
results().put("operation", result1Arr);
}
static class Result1 {
int nutrient_technique_score_id, nutrient_technique_id, nut_tech_score;
String nut_tech_kind, nut_tech_description, wqm_concern, mode_of_action, tech_discrim_type, tech_discrim;
public Result1(int nutrient_technique_score_id, int nutrient_technique_id,
int nut_tech_score, String nut_tech_kind, String nut_tech_description,
String wqm_concern, String mode_of_action, String tech_discrim_type, String tech_discrim) {
this.nutrient_technique_score_id = nutrient_technique_score_id;
this.nutrient_technique_id = nutrient_technique_id;
this.nut_tech_score = nut_tech_score;
this.nut_tech_kind = nut_tech_kind;
this.nut_tech_description = nut_tech_description;
this.wqm_concern = wqm_concern;
this.mode_of_action = mode_of_action;
this.tech_discrim_type = tech_discrim_type;
this.tech_discrim = tech_discrim;
}
}
}