List of usage examples for org.springframework.util Assert hasLength
@Deprecated public static void hasLength(@Nullable String text)
From source file:de.blizzy.documentr.page.Page.java
public void setViewRestrictionRole(String viewRestrictionRole) { if (viewRestrictionRole != null) { Assert.hasLength(viewRestrictionRole); }/*from www.j av a 2 s . com*/ this.viewRestrictionRole = viewRestrictionRole; }
From source file:de.blizzy.documentr.page.PageChangedEvent.java
public PageChangedEvent(String projectName, String branchName, String path) { Assert.hasLength(projectName); Assert.hasLength(branchName);/*from w ww . ja v a 2 s . c om*/ Assert.hasLength(path); this.projectName = projectName; this.branchName = branchName; this.path = path; }
From source file:de.blizzy.documentr.page.PageStore.java
@Override public MergeConflict savePage(String projectName, String branchName, String path, Page page, String baseCommit, User user) throws IOException { Assert.hasLength(projectName); Assert.hasLength(branchName);//w ww. j a va 2s . c o m Assert.hasLength(path); Assert.notNull(user); try { MergeConflict conflict = savePageInternal(projectName, branchName, path, DocumentrConstants.PAGE_SUFFIX, page, baseCommit, DocumentrConstants.PAGES_DIR_NAME, user); if (conflict == null) { eventBus.post(new PageChangedEvent(projectName, branchName, path)); } return conflict; } catch (GitAPIException e) { throw new IOException(e); } }
From source file:de.blizzy.documentr.page.PageStore.java
@Override public void saveAttachment(String projectName, String branchName, String pagePath, String name, Page attachment, User user) throws IOException { Assert.hasLength(projectName); Assert.hasLength(branchName);//from w ww . ja v a 2s. co m Assert.hasLength(pagePath); Assert.hasLength(name); Assert.notNull(attachment); Assert.notNull(user); // check if page exists by trying to load it getPage(projectName, branchName, pagePath, false); try { savePageInternal(projectName, branchName, pagePath + "/" + name, DocumentrConstants.PAGE_SUFFIX, //$NON-NLS-1$ attachment, null, DocumentrConstants.ATTACHMENTS_DIR_NAME, user); } catch (GitAPIException e) { throw new IOException(e); } }
From source file:de.blizzy.documentr.page.PageStore.java
@Override public Page getPage(String projectName, String branchName, String path, String commit, boolean loadData) throws IOException { Assert.hasLength(projectName); Assert.hasLength(branchName);// ww w .ja v a 2 s . c o m Assert.hasLength(path); if (commit != null) { Assert.hasLength(commit); } if (log.isDebugEnabled()) { log.debug("loading page {}/{}/{}, commit: {}, loadData: {}", //$NON-NLS-1$ projectName, branchName, Util.toUrlPagePath(path), commit, Boolean.valueOf(loadData)); } try { Map<String, Object> pageMap = getPageData(projectName, branchName, path, DocumentrConstants.PAGES_DIR_NAME, commit, loadData); String parentPagePath = (String) pageMap.get(PARENT_PAGE_PATH); String title = (String) pageMap.get(TITLE); String contentType = (String) pageMap.get(CONTENT_TYPE); @SuppressWarnings("unchecked") List<String> tagsList = (List<String>) pageMap.get(TAGS); if (tagsList == null) { tagsList = Collections.emptyList(); } Set<String> tags = Sets.newHashSet(tagsList); String viewRestrictionRole = (String) pageMap.get(VIEW_RESTRICTION_ROLE); PageData pageData = (PageData) pageMap.get(PAGE_DATA); Page page = new Page(title, contentType, pageData); page.setParentPagePath(parentPagePath); page.setTags(tags); page.setViewRestrictionRole(viewRestrictionRole); return page; } catch (GitAPIException e) { throw new IOException(e); } }
From source file:de.blizzy.documentr.page.PageStore.java
@Override public Page getAttachment(String projectName, String branchName, String pagePath, String name) throws IOException { Assert.hasLength(projectName); Assert.hasLength(branchName);/*w ww .jav a2 s .co m*/ Assert.hasLength(pagePath); Assert.hasLength(name); try { Map<String, Object> pageMap = getPageData(projectName, branchName, pagePath + "/" + name, //$NON-NLS-1$ DocumentrConstants.ATTACHMENTS_DIR_NAME, null, true); String parentPagePath = (String) pageMap.get(PARENT_PAGE_PATH); String contentType = (String) pageMap.get(CONTENT_TYPE); PageData pageData = (PageData) pageMap.get(PAGE_DATA); Page page = new Page(null, contentType, pageData); page.setParentPagePath(parentPagePath); return page; } catch (GitAPIException e) { throw new IOException(e); } }
From source file:de.blizzy.documentr.page.PageStore.java
@Override public List<String> listPageAttachments(String projectName, String branchName, String pagePath) throws IOException { Assert.hasLength(projectName); Assert.hasLength(branchName);/*from ww w . j a v a2 s . com*/ Assert.hasLength(pagePath); // check if page exists by trying to load it getPage(projectName, branchName, pagePath, false); ILockedRepository repo = null; try { repo = globalRepositoryManager.getProjectBranchRepository(projectName, branchName); File workingDir = RepositoryUtil.getWorkingDir(repo.r()); File attachmentsDir = new File(workingDir, DocumentrConstants.ATTACHMENTS_DIR_NAME); File pageAttachmentsDir = Util.toFile(attachmentsDir, pagePath); List<String> names = Collections.emptyList(); if (pageAttachmentsDir.isDirectory()) { FileFilter filter = new FileFilter() { @Override public boolean accept(File file) { return file.isFile() && file.getName().endsWith(DocumentrConstants.META_SUFFIX); } }; List<File> files = Lists.newArrayList(pageAttachmentsDir.listFiles(filter)); Function<File, String> function = new Function<File, String>() { @Override public String apply(File file) { return StringUtils.substringBeforeLast(file.getName(), DocumentrConstants.META_SUFFIX); } }; names = Lists.newArrayList(Lists.transform(files, function)); Collections.sort(names); } return names; } catch (GitAPIException e) { throw new IOException(e); } finally { Closeables.closeQuietly(repo); } }
From source file:de.blizzy.documentr.page.PageStore.java
@Override public List<String> listAllPagePaths(String projectName, String branchName) throws IOException { Assert.hasLength(projectName); Assert.hasLength(branchName);//ww w .j a v a 2 s. c om ILockedRepository repo = null; try { repo = globalRepositoryManager.getProjectBranchRepository(projectName, branchName); File workingDir = RepositoryUtil.getWorkingDir(repo.r()); File pagesDir = new File(workingDir, DocumentrConstants.PAGES_DIR_NAME); return listPagePaths(pagesDir, true); } catch (GitAPIException e) { throw new IOException(e); } finally { Closeables.closeQuietly(repo); } }
From source file:de.blizzy.documentr.page.PageStore.java
@Override public boolean isPageSharedWithOtherBranches(String projectName, String branchName, String path) throws IOException { Assert.hasLength(projectName); Assert.hasLength(branchName);//from w ww . j av a2 s . co m Assert.hasLength(path); List<String> branches = getBranchesPageIsSharedWith(projectName, branchName, path); return branches.size() >= 2; }
From source file:de.blizzy.documentr.page.PageStore.java
@Override public List<String> getBranchesPageIsSharedWith(String projectName, String branchName, String path) throws IOException { Assert.hasLength(projectName); Assert.hasLength(branchName);//w ww . j av a 2s.co m Assert.hasLength(path); List<String> allBranches = globalRepositoryManager.listProjectBranches(projectName); ILockedRepository centralRepo = null; Set<String> branchesWithCommit = Collections.emptySet(); try { centralRepo = globalRepositoryManager.getProjectCentralRepository(projectName); String repoPath = DocumentrConstants.PAGES_DIR_NAME + "/" + path + DocumentrConstants.PAGE_SUFFIX; //$NON-NLS-1$ RevCommit commit = CommitUtils.getLastCommit(centralRepo.r(), branchName, repoPath); if (commit != null) { // get all branches where this commit is in their history branchesWithCommit = getBranchesWithCommit(commit, allBranches, centralRepo.r()); if (branchesWithCommit.size() >= 2) { // remove all branches where the previous commit is no longer visible // due to newer commits on those branches for (Iterator<String> iter = branchesWithCommit.iterator(); iter.hasNext();) { String branch = iter.next(); RevCommit c = CommitUtils.getLastCommit(centralRepo.r(), branch, repoPath); if (!c.equals(commit)) { iter.remove(); } } } } } finally { Closeables.closeQuietly(centralRepo); } List<String> branches = Lists.newArrayList(branchesWithCommit); if (!branches.contains(branchName)) { branches.add(branchName); } Collections.sort(branches); return branches; }