use of com.jayway.jsonpath.internal.JsonContext 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 com.jayway.jsonpath.internal.JsonContext in project mica2 by obiba.
the class SchemaFormContentFileService method deleteFiles.
public void deleteFiles(SchemaFormContentAware entity) {
Object json = defaultConfiguration().jsonProvider().parse(entity.getContent());
DocumentContext context = JsonPath.using(defaultConfiguration().addOptions(Option.AS_PATH_LIST)).parse(json);
DocumentContext reader = new JsonContext(defaultConfiguration().addOptions(Option.REQUIRE_PROPERTIES)).parse(json);
try {
((JSONArray) context.read("$..obibaFiles")).stream().map(p -> (JSONArray) reader.read(p.toString())).flatMap(Collection::stream).forEach(file -> fileStoreService.delete(((LinkedHashMap) file).get("id").toString()));
} catch (PathNotFoundException e) {
}
}
Aggregations