Coecoclass.java [src/soils] Revision: default Date:
package soils;
import csip.api.server.ServiceException;
import csip.utils.JSONUtils;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.codehaus.jettison.json.JSONArray;
import org.codehaus.jettison.json.JSONException;
import org.codehaus.jettison.json.JSONObject;
import soils.db.tables.TableCoecoclass;
import soils.db.tables.TableCoecoclassCalculations;
/**
*
* @author <a href="mailto:shaun.case@colostate.edu">Shaun Case</a>
*/
public class Coecoclass {
protected static ArrayList<String> coecoclassRequiredInputs = new ArrayList<>();
protected static ArrayList<String> coecoclassUsedColumns = new ArrayList<>();
public synchronized static void setRequiredInputs(List<String> requiredInputs) {
coecoclassRequiredInputs.clear();
if (null != requiredInputs) {
coecoclassRequiredInputs.addAll(requiredInputs);
coecoclassUsedColumns.addAll(requiredInputs);
}
}
public synchronized static void setDefaultUsedColumns(List<String> usedColumns) {
coecoclassUsedColumns.clear();
if (null != usedColumns) {
coecoclassUsedColumns.addAll(usedColumns);
}
}
public static ArrayList<String> getDefaultUsedColumns() {
return ((null != coecoclassUsedColumns) ? (ArrayList<String>) coecoclassUsedColumns.clone() : null);
}
private final TableCoecoclass tableCoecoclass = new TableCoecoclass();
private final TableCoecoclassCalculations tableCoecoclassCalculations = new TableCoecoclassCalculations();
public Coecoclass() {
tableCoecoclass.setUsedColumns(coecoclassUsedColumns);
tableCoecoclass.setRequiredColumns(coecoclassRequiredInputs);
tableCoecoclassCalculations.setUsedColumns(coecoclassUsedColumns);
tableCoecoclassCalculations.setRequiredColumns(coecoclassRequiredInputs);
}
public Coecoclass(JSONArray dataJSON) throws ServiceException, JSONException {
tableCoecoclass.setUsedColumns(coecoclassUsedColumns);
tableCoecoclass.setRequiredColumns(coecoclassRequiredInputs);
tableCoecoclassCalculations.setUsedColumns(coecoclassUsedColumns);
tableCoecoclassCalculations.setRequiredColumns(coecoclassRequiredInputs);
if ((null != dataJSON) && (dataJSON.length() > 0)) {
Map<String, JSONObject> coecoclassDataArray = JSONUtils.preprocess(dataJSON);
tableCoecoclass.readValuesFromJSON(coecoclassDataArray);
tableCoecoclassCalculations.readValuesFromJSON(coecoclassDataArray);
} else {
throw new ServiceException("No mapunit JSON specified. A NULL or empty value was passed to Coecoclass()");
}
}
public Coecoclass(ResultSet results) throws ServiceException {
tableCoecoclass.setUsedColumns(coecoclassUsedColumns);
tableCoecoclass.setRequiredColumns(coecoclassRequiredInputs);
tableCoecoclassCalculations.setUsedColumns(coecoclassUsedColumns);
tableCoecoclassCalculations.setRequiredColumns(coecoclassRequiredInputs);
tableCoecoclass.readValuesFromSQL(results);
}
public void readFromSQL(ResultSet results) throws ServiceException {
tableCoecoclass.readValuesFromSQL(results);
}
public final String getEDITPath() {
return tableCoecoclassCalculations.editurl();
}
public final void setEDITPath(String value) {
tableCoecoclassCalculations.editurl(value);
}
public final void ecoclasstypename(String value) {
tableCoecoclass.ecoclasstypename(value);
}
public final String ecoclasstypename() {
return tableCoecoclass.ecoclasstypename();
}
public final void ecoclassref(String value) {
tableCoecoclass.ecoclassref(value);
}
public final String ecoclassref() {
return tableCoecoclass.ecoclassref();
}
public final void ecoclassid(String value) {
tableCoecoclass.ecoclassid(value);
}
public final String ecoclassid() {
return tableCoecoclass.ecoclassid();
}
public final void ecoclassname(String value) {
tableCoecoclass.ecoclassname(value);
}
public final String ecoclassname() {
return tableCoecoclass.ecoclassname();
}
public final void cokey(int value) {
tableCoecoclass.cokey(value);
}
public final int cokey() {
return tableCoecoclass.cokey();
}
public final void coecoclasskey(int value) {
tableCoecoclass.coecoclasskey(value);
}
public final int coecoclasskey() {
return tableCoecoclass.coecoclasskey();
}
public final void sourcesdwprimarykey(int value) {
tableCoecoclass.sourcesdwprimarykey(value);
}
public final int sourcesdwprimarykey() {
return tableCoecoclass.sourcesdwprimarykey();
}
public final void sourcesdwtablephysicalname(String value) {
tableCoecoclass.sourcesdwtablephysicalname(value);
}
public final String sourcesdwtablephysicalname() {
return tableCoecoclass.sourcesdwtablephysicalname();
}
public JSONArray toJSON() throws JSONException{
JSONArray outArray = new JSONArray();
tableCoecoclass.toJSON(outArray);
tableCoecoclassCalculations.toJSON(outArray);
return outArray;
}
/**
*
* @param usedList
*/
public void setOutputColumns(List<String> usedList) {
tableCoecoclass.setOutputColumns(usedList);
tableCoecoclassCalculations.setOutputColumns(usedList);
}
public boolean isEqual(Coecoclass tecoClass) throws ServiceException{
return (tableCoecoclass.isEqual(tecoClass.tableCoecoclass) && tableCoecoclassCalculations.isEqual(tecoClass.tableCoecoclassCalculations));
}
}