use of net.minidev.json.JSONArray in project scheduler by btrplace.
the class ModelConverter method toJSON.
@Override
public JSONObject toJSON(Model i) throws JSONConverterException {
JSONArray rcs = new JSONArray();
for (ModelView v : i.getViews()) {
rcs.add(viewsConverter.toJSON(v));
}
JSONObject o = new JSONObject();
o.put(MAPPING_LABEL, toJSON(i.getMapping()));
o.put(ATTRS_LABEL, AttributesConverter.toJSON(i.getAttributes()));
o.put(VIEWS_LABEL, rcs);
return o;
}
use of net.minidev.json.JSONArray in project scheduler by btrplace.
the class ModelConverter method newVMs.
/**
* Build VMs from a key.
*
* @param mo the model to build
* @param o the object that contains the vm
* @param key the key associated to the VMs
* @return the resulting set of VMs
* @throws JSONConverterException if at least one of the parsed VM already exists
*/
private static Set<VM> newVMs(Model mo, JSONObject o, String key) throws JSONConverterException {
checkKeys(o, key);
Object x = o.get(key);
if (!(x instanceof JSONArray)) {
throw new JSONConverterException("array expected at key '" + key + "'");
}
Set<VM> s = new HashSet<>(((JSONArray) x).size());
for (Object i : (JSONArray) x) {
int id = (Integer) i;
VM vm = mo.newVM(id);
if (vm == null) {
throw JSONConverterException.vmAlreadyDeclared(id);
}
s.add(vm);
}
return s;
}
use of net.minidev.json.JSONArray in project scheduler by btrplace.
the class ModelConverter method fromJSON.
@Override
public Model fromJSON(JSONObject o) throws JSONConverterException {
checkKeys(o, MAPPING_LABEL, ATTRS_LABEL, VIEWS_LABEL);
Model i = new DefaultModel();
fillMapping(i, (JSONObject) o.get(MAPPING_LABEL));
i.setAttributes(AttributesConverter.fromJSON(i, (JSONObject) o.get(ATTRS_LABEL)));
for (Object view : (JSONArray) o.get(VIEWS_LABEL)) {
i.attach(viewsConverter.fromJSON(i, (JSONObject) view));
}
return i;
}
use of net.minidev.json.JSONArray in project scheduler by btrplace.
the class AmongConverter method toJSON.
@Override
public JSONObject toJSON(Among o) {
JSONObject c = new JSONObject();
c.put("id", getJSONId());
c.put("vms", vmsToJSON(o.getInvolvedVMs()));
JSONArray a = new JSONArray();
for (Collection<Node> grp : o.getGroupsOfNodes()) {
a.add(nodesToJSON(grp));
}
c.put("parts", a);
c.put("continuous", o.isContinuous());
return c;
}
use of net.minidev.json.JSONArray in project jmeter-plugins by undera.
the class JSONPathExtractor method process.
@Override
public void process() {
JMeterContext context = getThreadContext();
JMeterVariables vars = context.getVariables();
SampleResult previousResult = context.getPreviousResult();
String responseData;
if (getSubject().equals(SUBJECT_VARIABLE)) {
responseData = vars.get(getSrcVariableName());
} else {
responseData = previousResult.getResponseDataAsString();
}
try {
Object jsonPathResult = JsonPath.read(responseData, getJsonPath());
if (jsonPathResult instanceof JSONArray) {
Object[] arr = ((JSONArray) jsonPathResult).toArray();
if (arr.length == 0) {
throw new PathNotFoundException("Extracted array is empty");
}
vars.put(this.getVar(), objectToString(jsonPathResult));
vars.put(this.getVar() + "_matchNr", objectToString(arr.length));
int k = 1;
while (vars.get(this.getVar() + "_" + k) != null) {
vars.remove(this.getVar() + "_" + k);
k++;
}
for (int n = 0; n < arr.length; n++) {
vars.put(this.getVar() + "_" + (n + 1), objectToString(arr[n]));
}
} else {
vars.put(this.getVar(), objectToString(jsonPathResult));
}
} catch (Exception e) {
log.debug("Extract failed", e);
vars.put(this.getVar(), getDefaultValue());
vars.put(this.getVar() + "_matchNr", "0");
int k = 1;
while (vars.get(this.getVar() + "_" + k) != null) {
vars.remove(this.getVar() + "_" + k);
k++;
}
}
}
Aggregations