예제 #1
0
  public static List<StorageNode> getStorageNodesInFolder(String path, Owner owner) {

    DatastoreService ds = DatastoreServiceFactory.getDatastoreService();

    ArrayList<StorageNode> nodes = new ArrayList<StorageNode>();

    String folderPath = PathHelper.getFolderpath(path);

    // Read folders
    Query q = new Query("Folder");
    q.addFilter("path", FilterOperator.GREATER_THAN_OR_EQUAL, path);
    q.addFilter("path", FilterOperator.LESS_THAN, path + "\ufffd");
    q.addFilter("ownerId", FilterOperator.EQUAL, owner.getId());

    PreparedQuery pq = ds.prepare(q);
    List<Entity> results = pq.asList(FetchOptions.Builder.withLimit(99999));
    for (Entity e : results) {
      Folder f = new Folder();
      ReflectionHelper.setPropertiesFromEntity(Folder.class, f, e);

      log.debug("Folder compare: {} =?= {}", PathHelper.getFolderpath(f.getPath()), folderPath);
      if (PathHelper.getFolderpath(f.getPath()).equals(folderPath)) {
        nodes.add(f);
      }
    }

    // Read files
    Query q2 = new Query("File");
    q2.addFilter("path", FilterOperator.GREATER_THAN_OR_EQUAL, path);
    q2.addFilter("path", FilterOperator.LESS_THAN, path + "\ufffd");
    q2.addFilter("ownerId", FilterOperator.EQUAL, owner.getId());

    PreparedQuery pq2 = ds.prepare(q);
    List<Entity> results2 = pq2.asList(FetchOptions.Builder.withLimit(99999));
    for (Entity e : results2) {
      File f = new File();
      ReflectionHelper.setPropertiesFromEntity(File.class, f, e);

      log.debug("File compare: {} =?= {}", PathHelper.getFolderpath(f.getPath()), folderPath);
      if (PathHelper.getFolderpath(f.getPath()).equals(folderPath)) {

        nodes.add(f);
      }
    }

    return nodes;
  }
예제 #2
0
  public static File getByPathAndUser(String path, Owner owner) throws EntityNotFoundException {
    DatastoreService ds = DatastoreServiceFactory.getDatastoreService();

    Entity e = ds.get(PathHelper.getStorageKey("File", path, owner));

    if (e == null) return null;

    File f = new File();
    ReflectionHelper.setPropertiesFromEntity(File.class, f, e);

    return f;
  }