Ejemplo n.º 1
0
 private void saveFiles(Iterable files, String entityPath) {
   if (files != null)
     files.forEach(
         file -> {
           LinkedHashMap map = (LinkedHashMap) file;
           map.put("path", entityPath);
           fileStoreService.save(map.get("id").toString());
         });
 }
Ejemplo n.º 2
0
  private Iterable<Object> saveAndDeleteFiles(
      JSONArray oldFiles, JSONArray newFiles, String entityPath) {
    Iterable<Object> toDelete =
        Sets.difference(Sets.newHashSet(oldFiles), Sets.newHashSet(newFiles));
    Iterable<Object> toSave = Sets.difference(Sets.newHashSet(newFiles), Sets.newHashSet(oldFiles));

    toDelete.forEach(file -> fileStoreService.delete(((LinkedHashMap) file).get("id").toString()));
    saveFiles(toSave, entityPath);
    return toDelete;
  }
Ejemplo n.º 3
0
  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 JsonReader(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) {
    }
  }