Beispiel #1
0
 public void testSave() {
   folderTool.addFolder("test", null);
   List<FolderEntity> folders = getDao().getFolderDao().select();
   assertEquals(1, folders.size());
   FolderEntity folder1 = folders.get(0);
   assertEquals("test", folder1.getName());
 }
Beispiel #2
0
 @Override
 public FileEntity saveFile(String filename, byte[] data) {
   try {
     String path = FolderUtil.getFilePath(filename);
     String name = FolderUtil.getFileName(filename);
     FolderEntity folder = getFolderBusiness().createFolder(path);
     FileEntity file = getDao().getFileDao().getByName(folder.getId(), name);
     if (file == null) {
       file =
           new FileEntity(
               name,
               name,
               folder.getId(),
               MimeType.getContentTypeByExt(FolderUtil.getFileExt(filename)),
               new Date(),
               data.length);
     }
     getDao().getFileDao().save(file, data);
     getSystemService().getFileCache().remove(filename);
     return file;
   } catch (Exception e) {
     e.printStackTrace();
     return null;
   }
 }
Beispiel #3
0
 public void testGetByParent() {
   FolderEntity root = folderTool.addFolder("root", null);
   folderTool.addFolder("title1", root.getId());
   folderTool.addFolder("title2", null);
   folderTool.addFolder("title3", root.getId());
   List<FolderEntity> list = getDao().getFolderDao().getByParent(root.getId());
   assertEquals(2, list.size());
 }
 private void clearFileCache(FolderEntity folder) {
   if (folder == null) {
     return;
   }
   String folderPath = getDao().getFolderDao().getFolderPath(folder.getId());
   for (FileEntity file : getDao().getFileDao().getByFolder(folder.getId())) {
     getDao().getSystemService().getFileCache().remove(folderPath + "/" + file.getFilename());
   }
   for (FolderEntity child : getDao().getFolderDao().getByParent(folder.getId())) {
     clearFileCache(child);
   }
 }
  private void initFolders() {
    List<FolderEntity> roots = getDao().getFolderDao().getByParent(null);
    if (roots.size() == 0) {
      log.info("Adding default folders.");
      FolderEntity root = new FolderEntity("file", "/", null);
      getDao().getFolderDao().save(root);
      FolderEntity theme = new FolderEntity("Themes resources", "theme", root.getId());
      getDao().getFolderDao().save(theme);
      FolderEntity simple = new FolderEntity("Simple", "simple", theme.getId());
      getDao().getFolderDao().save(simple);
      getBusiness()
          .getFolderPermissionBusiness()
          .setPermission(root, guests, FolderPermissionType.READ);
      FolderEntity tmp = new FolderEntity("tmp", "tmp", root.getId());
      getDao().getFolderDao().save(tmp);
      getBusiness()
          .getFolderPermissionBusiness()
          .setPermission(tmp, guests, FolderPermissionType.WRITE);
      FolderEntity page = new FolderEntity("page", "page", root.getId());
      getDao().getFolderDao().save(page);

      FolderEntity form = new FolderEntity("form", "form", root.getId());
      getDao().getFolderDao().save(form);
      getBusiness()
          .getFolderPermissionBusiness()
          .setPermission(form, guests, FolderPermissionType.WRITE);
    }
  }
Beispiel #6
0
 public void testGetByParentName() {
   FolderEntity root = folderTool.addFolder("root", null);
   folderTool.addFolder("title1", root.getId());
   folderTool.addFolder("title2", null);
   folderTool.addFolder("title3", root.getId());
   FolderEntity result = getDao().getFolderDao().getByParentName(root.getId(), "title1");
   assertNotNull(result);
   assertEquals("title1", result.getName());
   result = getDao().getFolderDao().getByParentName(root.getId(), "title3");
   assertNotNull(result);
   assertEquals("title3", result.getName());
   result = getDao().getFolderDao().getByParentName(root.getId(), "title2");
   assertNull(result);
 }
Beispiel #7
0
 public void testUpdate() {
   FolderEntity folder = folderTool.addFolder("test", null);
   FolderEntity folder2 = getDao().getFolderDao().getById(folder.getId());
   folder2.setName("update");
   getDao().getFolderDao().save(folder2);
   FolderEntity folder3 = getDao().getFolderDao().getById(folder.getId());
   assertEquals("update", folder3.getName());
 }
Beispiel #8
0
 @Override
 public byte[] readFile(String filename) {
   try {
     String path = FolderUtil.getFilePath(filename);
     String name = FolderUtil.getFileName(filename);
     FolderEntity folder =
         getFolderBusiness().findFolderByPath(getFolderBusiness().getTree(), path).getEntity();
     if (folder == null) {
       return null;
     }
     FileEntity file = getDao().getFileDao().getByName(folder.getId(), name);
     if (file != null) {
       return getDao().getFileDao().getFileContent(file);
     }
     return null;
   } catch (Exception e) {
     e.printStackTrace();
     return null;
   }
 }
 /**
  * /images/ /logos/ /vosao
  *
  * <p>/photos /test
  */
 public void testGetFolderPath() {
   FolderEntity root = addFolder("/", null);
   addGuestPerission(root);
   FolderEntity images = addFolder("images", root.getId());
   FolderEntity logos = addFolder("logos", images.getId());
   FolderEntity photos = addFolder("photos", images.getId());
   FolderEntity test = addFolder("test", images.getId());
   FolderEntity vosao = addFolder("vosao", logos.getId());
   assertEquals("/images", getBusiness().getFolderBusiness().getFolderPath(images));
   assertEquals("/images/logos", getBusiness().getFolderBusiness().getFolderPath(logos));
   assertEquals("/images/logos/vosao", getBusiness().getFolderBusiness().getFolderPath(vosao));
   assertEquals("/images/photos", getBusiness().getFolderBusiness().getFolderPath(photos));
 }
  /**
   * /images/ /logos/ /vosao
   *
   * <p>/photos /test
   */
  public void testFindFolderByPath() {
    FolderEntity root = addFolder("/", null);
    addGuestPerission(root);
    FolderEntity images = addFolder("images", root.getId());
    FolderEntity logos = addFolder("logos", images.getId());
    FolderEntity photos = addFolder("photos", images.getId());
    FolderEntity test = addFolder("test", images.getId());
    FolderEntity vosao = addFolder("vosao", logos.getId());
    TreeItemDecorator<FolderEntity> treeRoot = getBusiness().getFolderBusiness().getTree();

    TreeItemDecorator<FolderEntity> result =
        getBusiness().getFolderBusiness().findFolderByPath(treeRoot, "/images");
    assertNotNull(result);
    assertEquals(images.getId(), result.getEntity().getId());

    result = getBusiness().getFolderBusiness().findFolderByPath(treeRoot, "/images/logos");
    assertNotNull(result);
    assertEquals(logos.getId(), result.getEntity().getId());

    result = getBusiness().getFolderBusiness().findFolderByPath(treeRoot, "/images/photos");
    assertNotNull(result);
    assertEquals(photos.getId(), result.getEntity().getId());

    result = getBusiness().getFolderBusiness().findFolderByPath(treeRoot, "/images/test");
    assertNotNull(result);
    assertEquals(test.getId(), result.getEntity().getId());

    result = getBusiness().getFolderBusiness().findFolderByPath(treeRoot, "/images/logos/vosao");
    assertNotNull(result);
    assertEquals(vosao.getId(), result.getEntity().getId());

    result = getBusiness().getFolderBusiness().findFolderByPath(treeRoot, "/images/logos/vosao1");
    assertNull(result);
  }
 private void addPermission(FolderEntity folder, GroupEntity group, FolderPermissionType perm) {
   FolderPermissionEntity p = new FolderPermissionEntity(folder.getId(), perm, group.getId());
   getDao().getFolderPermissionDao().save(p);
 }
Beispiel #12
0
 public void testGetById() {
   FolderEntity folder = folderTool.addFolder("test", null);
   FolderEntity folder2 = getDao().getFolderDao().getById(folder.getId());
   assertEquals(folder.getName(), folder2.getName());
 }
Beispiel #13
0
 public void testGetByPath() {
   FolderEntity root = folderTool.addFolder("/", null);
   FolderEntity t1 = folderTool.addFolder("t1", root.getId());
   folderTool.addFolder("t2", root.getId());
   FolderEntity s1 = folderTool.addFolder("s1", t1.getId());
   folderTool.addFolder("s2", t1.getId());
   FolderEntity m1 = folderTool.addFolder("m1", s1.getId());
   FolderEntity r = getDao().getFolderDao().getByPath("/");
   assertNotNull(r);
   assertEquals("/", r.getName());
   r = getDao().getFolderDao().getByPath("/t1");
   assertNotNull(r);
   assertEquals("t1", r.getName());
   r = getDao().getFolderDao().getByPath("/t2");
   assertNotNull(r);
   assertEquals("t2", r.getName());
   r = getDao().getFolderDao().getByPath("/t1/s1");
   assertNotNull(r);
   assertEquals("s1", r.getName());
   r = getDao().getFolderDao().getByPath("/t1/s2");
   assertNotNull(r);
   assertEquals("s2", r.getName());
   r = getDao().getFolderDao().getByPath("/t1/s1/m1");
   assertNotNull(r);
   assertEquals("m1", r.getName());
   r = getDao().getFolderDao().getByPath("/t1/s1/m1/f");
   assertNull(r);
   r = getDao().getFolderDao().getByPath("/t1s1/m1/f");
   assertNull(r);
   assertEquals("/t1", getDao().getFolderDao().getFolderPath(t1.getId()));
   assertEquals("/t1/s1/m1", getDao().getFolderDao().getFolderPath(m1.getId()));
 }