use of net.minidev.json.JSONArray in project mica2 by obiba.
the class SchemaFormContentFileService method getPathFilesMap.
private Map<String, JSONArray> getPathFilesMap(DocumentContext context, Object json) {
DocumentContext reader = new JsonContext(defaultConfiguration().addOptions(Option.REQUIRE_PROPERTIES)).parse(json);
JSONArray paths = null;
try {
paths = context.read("$..obibaFiles");
} catch (PathNotFoundException e) {
return null;
}
return paths.stream().collect(Collectors.toMap(Object::toString, p -> (JSONArray) reader.read(p.toString())));
}
use of net.minidev.json.JSONArray in project mica2 by obiba.
the class SchemaFormContentFileService method save.
public void save(@NotNull SchemaFormContentAware newEntity, SchemaFormContentAware oldEntity, String entityPath) {
Assert.notNull(newEntity, "New content cannot be null");
Object json = defaultConfiguration().jsonProvider().parse(newEntity.getContent());
DocumentContext newContext = JsonPath.using(defaultConfiguration().addOptions(Option.AS_PATH_LIST)).parse(json);
Map<String, JSONArray> newPaths = getPathFilesMap(newContext, json);
// content does not have any file field
if (newPaths == null)
return;
if (oldEntity != null) {
Object oldJson = defaultConfiguration().jsonProvider().parse(oldEntity.getContent());
DocumentContext oldContext = JsonPath.using(defaultConfiguration().addOptions(Option.AS_PATH_LIST)).parse(oldJson);
Map<String, JSONArray> oldPaths = getPathFilesMap(oldContext, oldJson);
if (oldPaths != null) {
saveAndDelete(oldPaths, newPaths, entityPath);
} else {
// schema and definition now have files
newPaths.values().forEach(v -> saveFiles(v, entityPath));
}
} else {
newPaths.values().forEach(v -> saveFiles(v, entityPath));
}
cleanup(newPaths, newContext);
newEntity.setContent(newContext.jsonString());
}
use of net.minidev.json.JSONArray in project knox by apache.
the class AmbariClientCommon method getActiveServiceConfigurations.
Map<String, Map<String, AmbariCluster.ServiceConfiguration>> getActiveServiceConfigurations(String discoveryAddress, String clusterName, String discoveryUser, String discoveryPwdAlias) {
Map<String, Map<String, AmbariCluster.ServiceConfiguration>> serviceConfigurations = new HashMap<>();
String serviceConfigsURL = String.format("%s" + AMBARI_SERVICECONFIGS_URI, discoveryAddress, clusterName);
JSONObject serviceConfigsJSON = restClient.invoke(serviceConfigsURL, discoveryUser, discoveryPwdAlias);
if (serviceConfigsJSON != null) {
// Process the service configurations
JSONArray serviceConfigs = (JSONArray) serviceConfigsJSON.get("items");
for (Object serviceConfig : serviceConfigs) {
String serviceName = (String) ((JSONObject) serviceConfig).get("service_name");
JSONArray configurations = (JSONArray) ((JSONObject) serviceConfig).get("configurations");
for (Object configuration : configurations) {
String configType = (String) ((JSONObject) configuration).get("type");
String configVersion = String.valueOf(((JSONObject) configuration).get("version"));
Map<String, String> configProps = new HashMap<>();
JSONObject configProperties = (JSONObject) ((JSONObject) configuration).get("properties");
for (Entry<String, Object> entry : configProperties.entrySet()) {
configProps.put(entry.getKey(), String.valueOf(entry.getValue()));
}
if (!serviceConfigurations.containsKey(serviceName)) {
serviceConfigurations.put(serviceName, new HashMap<>());
}
serviceConfigurations.get(serviceName).put(configType, new AmbariCluster.ServiceConfiguration(configType, configVersion, configProps));
}
}
}
return serviceConfigurations;
}
use of net.minidev.json.JSONArray in project knox by apache.
the class AmbariServiceDiscovery method discover.
@Override
public Map<String, Cluster> discover(GatewayConfig gatewayConfig, ServiceDiscoveryConfig discoveryConfig) {
Map<String, Cluster> clusters = new HashMap<>();
init(gatewayConfig);
String discoveryAddress = discoveryConfig.getAddress();
// Invoke Ambari REST API to discover the available clusters
String clustersDiscoveryURL = String.format("%s" + AMBARI_CLUSTERS_URI, discoveryAddress);
JSONObject json = restClient.invoke(clustersDiscoveryURL, discoveryConfig.getUser(), discoveryConfig.getPasswordAlias());
// Parse the cluster names from the response, and perform the cluster discovery
JSONArray clusterItems = (JSONArray) json.get("items");
for (Object clusterItem : clusterItems) {
String clusterName = (String) ((JSONObject) ((JSONObject) clusterItem).get("Clusters")).get("cluster_name");
try {
Cluster c = discover(gatewayConfig, discoveryConfig, clusterName);
clusters.put(clusterName, c);
} catch (Exception e) {
log.clusterDiscoveryError(clusterName, e);
}
}
return clusters;
}
use of net.minidev.json.JSONArray in project connectors-workspace-one by vmware.
the class AirWatchController method toGreenBoxApp.
private GreenBoxApp toGreenBoxApp(JsonDocument document, String appName) {
int RIGHT_APP_COUNT = 1;
JSONArray jsonArray = document.read("$._embedded.entitlements");
if (jsonArray.size() != RIGHT_APP_COUNT) {
throw new GbAppMapException("Unable to map " + appName + " to a single GreenBox app");
}
return new GreenBoxApp(document.read("$._embedded.entitlements[0].name"), document.read("$._embedded.entitlements[0]._links.install.href"));
}
Aggregations