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; }
public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException { int index; DatastoreService ds; MemcacheService ms; Cookie[] cookies; boolean insideFlag; String delpw; String paramOffset; String paramSize; int offset; int size; Key postObjGroupKey; Query q; List<Entity> postObjList; PostObj postObj; Gson gson; List<String> filelinkList; resp.setCharacterEncoding("UTF-8"); resp.setContentType("text/plain"); ds = DatastoreServiceFactory.getDatastoreService(); ms = MemcacheServiceFactory.getMemcacheService(); insideFlag = false; try { cookies = req.getCookies(); if (cookies.length > 0) { if (ms.contains(cookies[0].getValue()) == true) { insideFlag = true; } } } catch (Exception e) { insideFlag = false; } delpw = req.getParameter("delpw"); if (delpw != null) { if (delpw.equals("") == true) { delpw = null; } } paramOffset = req.getParameter("offset"); if (paramOffset != null) { offset = Integer.valueOf(paramOffset); } else { offset = 0; } paramSize = req.getParameter("size"); if (paramSize != null) { size = Integer.valueOf(paramSize); } else { size = 4096; } postObjGroupKey = KeyFactory.createKey("PostObjGroup", 1L); q = new Query("PostObj", postObjGroupKey); if (delpw != null) { q.addFilter("delpw", FilterOperator.EQUAL, delpw); q.addSort("delpw"); } q.addSort("posttime", SortDirection.DESCENDING); postObjList = ds.prepare(q).asList(FetchOptions.Builder.withOffset(offset).limit(size)); postObj = new PostObj(); filelinkList = new ArrayList<String>(); for (index = 0; index < postObjList.size(); index++) { postObj.getDB(postObjList.get(index)); if ((postObj.flag.equals("showgallery") == false && insideFlag == true) || (postObj.flag.equals("showgallery") == true && insideFlag == false) || delpw != null) { filelinkList.add(postObj.filelink); } } gson = new Gson(); resp.getWriter().print(gson.toJson(filelinkList)); }