Parameter.java [src/java/crlmod/element] Revision: Date:
/*
* $Id: 1.0+62 Parameter.java a170e1637ffa 2021-12-20 od $
*
* This file is part of the Cloud Services Integration Platform (CSIP),
* a Model-as-a-Service framework, API, and application suite.
*
* 2012-2024, 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 crlmod.element;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import org.codehaus.jettison.json.JSONArray;
import org.codehaus.jettison.json.JSONException;
import org.codehaus.jettison.json.JSONObject;
/**
*
* @author User
*/
@Deprecated
public class Parameter {
private final String name;
private String type;
private String dim;
private String unit;
private String[] data;
public Parameter(String name) {
this.name = name;
}
public void setData(String[] d) {
data = d;
for (int i = 0; i < data.length; i++) {
if (data[i] != null) {
if (data[i].equals("")) {
data[i] = null;
}
}
}
}
public String populate(HashMap<String, Unit> units) throws SQLException {
Unit param_unit = units.get(name);
if (param_unit == null) {
return null;
}
type = param_unit.type;
dim = param_unit.dim;
unit = param_unit.name;
return null;
}
public String toJSON(JSONObject json, ArrayList<Triple<String, String[], String>> params) throws JSONException, SQLException {
String error = null;
try {
JSONArray jData = new JSONArray();
if (name.contains(":file_key")) {
json.put("name", name.substring(0, name.indexOf(":file_key")));
} else {
json.put("name", name);
}
if (type != null) {
json.put("type", type);
}
if (unit != null) {
if (!unit.equals("")) {
json.put("units", unit);
}
}
if (dim != null) {
JSONObject dimobj = new JSONObject();
dimobj.put("name", dim);
json.put("dim", dimobj);
}
if (type != null) {
if (type.equals("ObR")) {
Triple<String, String[], String> key_dummy = new Triple<>(name, null, null);
Triple<String, String[], String> path_dummy = new Triple<>(name.substring(0, name.length() - 9), null, null);
Triple<String, String[], String> key_param = params.get(params.indexOf(key_dummy));
String[] file_keys = key_param.getY();
String[] paths = params.get(params.indexOf(path_dummy)).getY();
json.put("file_type", key_param.getZ());
for (int i = 0; i < file_keys.length; i++) {
JSONObject file = new JSONObject();
String file_key = file_keys[i];
String path = paths[i];
if (file_key != null) {
if (name.equals("VEG_PTR:file_key")) {
path = "vegetations\\" + path;
}
file.put("file_key", file_key);
file.put("value", path);
} else {
file.put("file_key", JSONObject.NULL);
}
jData.put(file);
}
} else {
for (String datum : data) {
jData.put(datum);
}
}
} else {
for (String datum : data) {
jData.put(datum);
}
}
json.put("data", jData);
} catch (Exception ex) {
error = ex.toString();
}
return error;
}
}