private void createTagXML(Element element, TreeItemDecorator<TagEntity> tag) { Element tagElement = element.addElement("tag"); tagElement.addElement("name").setText(tag.getEntity().getName()); String title = tag.getEntity().getTitle(); if (StringUtils.isEmpty(title)) { title = tag.getEntity().getName(); } tagElement.addElement("title").setText(title); for (TreeItemDecorator<TagEntity> child : tag.getChildren()) { createTagXML(tagElement, child); } }
@Override public FileEntity findFile(String filename) { try { String path = FolderUtil.getFilePath(filename); String name = FolderUtil.getFileName(filename); TreeItemDecorator<FolderEntity> folder = getFolderBusiness().findFolderByPath(getFolderBusiness().getTree(), path); if (folder == null) { return null; } return getDao().getFileDao().getByName(folder.getEntity().getId(), name); } catch (Exception e) { e.printStackTrace(); return null; } }
/** * /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); }
public void testCreateFolder() throws UnsupportedEncodingException { FolderEntity root = addFolder("/", null); addGuestPerission(root); getBusiness().getFolderBusiness().createFolder("/one/two/free/four"); TreeItemDecorator<FolderEntity> treeRoot = getBusiness().getFolderBusiness().getTree(); TreeItemDecorator<FolderEntity> folder = getBusiness().getFolderBusiness().findFolderByPath(treeRoot, "/one"); assertNotNull(folder); assertEquals("one", folder.getEntity().getName()); folder = getBusiness().getFolderBusiness().findFolderByPath(treeRoot, "/one/two"); assertNotNull(folder); assertEquals("two", folder.getEntity().getName()); folder = getBusiness().getFolderBusiness().findFolderByPath(treeRoot, "/one/two/free"); assertNotNull(folder); assertEquals("free", folder.getEntity().getName()); folder = getBusiness().getFolderBusiness().findFolderByPath(treeRoot, "/one/two/free/four"); assertNotNull(folder); assertEquals("four", folder.getEntity().getName()); }
@Override public void remove(String filename) { String path = FolderUtil.getFilePath(filename); String name = FolderUtil.getFileName(filename); TreeItemDecorator<FolderEntity> folder = getFolderBusiness().findFolderByPath(getFolderBusiness().getTree(), path); if (folder == null) { logger.error("Folder not found. " + path); return; } FileEntity file = getDao().getFileDao().getByName(folder.getEntity().getId(), name); if (file == null) { logger.error("File not found. " + filename); return; } FolderPermissionEntity perm = getFolderPermissionBusiness() .getPermission(folder.getEntity(), VosaoContext.getInstance().getUser()); if (perm.isChangeGranted()) { getDao().getFileDao().remove(file.getId()); getSystemService().getFileCache().remove(filename); } }
private List<TreeItemDecorator<TagEntity>> getTagTreeRoots() { List<TagEntity> tags = getDao().getTagDao().select(); Map<Long, TreeItemDecorator<TagEntity>> buf = new HashMap<Long, TreeItemDecorator<TagEntity>>(); for (TagEntity tag : tags) { buf.put(tag.getId(), new TreeItemDecorator<TagEntity>(tag, null)); } List<TreeItemDecorator<TagEntity>> roots = new ArrayList<TreeItemDecorator<TagEntity>>(); for (Long id : buf.keySet()) { TreeItemDecorator<TagEntity> tag = buf.get(id); if (tag.getEntity().getParent() == null) { roots.add(tag); } else { TreeItemDecorator<TagEntity> parent = buf.get(tag.getEntity().getParent()); if (parent != null) { parent.getChildren().add(tag); tag.setParent(parent); } } } return roots; }