Example usage for org.springframework.util Assert hasLength

List of usage examples for org.springframework.util Assert hasLength

Introduction

In this page you can find the example usage for org.springframework.util Assert hasLength.

Prototype

@Deprecated
public static void hasLength(@Nullable String text) 

Source Link

Document

Assert that the given String is not empty; that is, it must not be null and not the empty String.

Usage

From source file:de.blizzy.documentr.access.UserStore.java

/**
 * Returns a user's authorities./* w ww .j a v  a 2  s .  c  o m*/
 *
 * @param loginName the login name of the user
 *
 * @throws UserNotFoundException when the user does not exist
 */
public List<RoleGrantedAuthority> getUserAuthorities(String loginName) throws IOException {
    Assert.hasLength(loginName);

    ILockedRepository repo = null;
    try {
        repo = globalRepositoryManager.getProjectCentralRepository(REPOSITORY_NAME, false);
        return getUserAuthorities(loginName, repo);
    } finally {
        Closeables.closeQuietly(repo);
    }
}

From source file:de.blizzy.documentr.access.UserStore.java

public void deleteUser(String loginName, User currentUser) throws IOException {
    Assert.hasLength(loginName);
    Assert.notNull(currentUser);/*from w  ww  . jav  a 2s.co m*/

    ILockedRepository repo = null;
    try {
        repo = globalRepositoryManager.getProjectCentralRepository(REPOSITORY_NAME, false);
        Git git = Git.wrap(repo.r());
        git.rm().addFilepattern(loginName + USER_SUFFIX).call();
        git.rm().addFilepattern(loginName + AUTHORITIES_SUFFIX).call();
        PersonIdent ident = new PersonIdent(currentUser.getLoginName(), currentUser.getEmail());
        git.commit().setAuthor(ident).setCommitter(ident).setMessage("delete user " + loginName) //$NON-NLS-1$
                .call();
    } catch (GitAPIException e) {
        throw new IOException(e);
    } finally {
        Closeables.closeQuietly(repo);
    }
}

From source file:de.blizzy.documentr.access.UserStore.java

public void renameUser(String loginName, String newLoginName, User currentUser) throws IOException {
    Assert.hasLength(loginName);
    Assert.hasLength(newLoginName);//w w w. ja v a  2s .c  o  m
    Assert.notNull(currentUser);
    // check that user exists by trying to load it
    getUser(loginName);
    // check that new user does not exist by trying to load it
    try {
        getUser(newLoginName);
        throw new IllegalArgumentException("user already exists: " + newLoginName); //$NON-NLS-1$
    } catch (UserNotFoundException e) {
        // okay
    }

    ILockedRepository repo = null;
    try {
        repo = globalRepositoryManager.getProjectCentralRepository(REPOSITORY_NAME, false);

        File workingDir = RepositoryUtil.getWorkingDir(repo.r());
        File file = new File(workingDir, loginName + USER_SUFFIX);
        File newFile = new File(workingDir, newLoginName + USER_SUFFIX);
        FileUtils.copyFile(file, newFile);
        file = new File(workingDir, loginName + AUTHORITIES_SUFFIX);
        newFile = new File(workingDir, newLoginName + AUTHORITIES_SUFFIX);
        FileUtils.copyFile(file, newFile);
        Git git = Git.wrap(repo.r());
        git.rm().addFilepattern(loginName + USER_SUFFIX).call();
        git.rm().addFilepattern(loginName + AUTHORITIES_SUFFIX).call();
        git.add().addFilepattern(newLoginName + USER_SUFFIX).call();
        git.add().addFilepattern(newLoginName + AUTHORITIES_SUFFIX).call();
        PersonIdent ident = new PersonIdent(currentUser.getLoginName(), currentUser.getEmail());
        git.commit().setAuthor(ident).setCommitter(ident)
                .setMessage("rename user " + loginName + " to " + newLoginName) //$NON-NLS-1$ //$NON-NLS-2$
                .call();
    } catch (GitAPIException e) {
        throw new IOException(e);
    } finally {
        Closeables.closeQuietly(repo);
    }
}

From source file:de.blizzy.documentr.access.UserStore.java

public void renameRole(String roleName, String newRoleName, User currentUser) throws IOException {
    Assert.hasLength(roleName);
    Assert.hasLength(newRoleName);/* w w  w .ja  va2s .c o m*/
    Assert.notNull(currentUser);
    // check that role exists by trying to load it
    getRole(roleName);
    // check that new role does not exist by trying to load it
    try {
        getRole(newRoleName);
        throw new IllegalArgumentException("role already exists: " + newRoleName); //$NON-NLS-1$
    } catch (RoleNotFoundException e) {
        // okay
    }

    log.info("renaming role: {} -> {}", roleName, newRoleName); //$NON-NLS-1$

    ILockedRepository repo = null;
    try {
        repo = globalRepositoryManager.getProjectCentralRepository(REPOSITORY_NAME, false);

        File workingDir = RepositoryUtil.getWorkingDir(repo.r());

        File file = new File(workingDir, roleName + ROLE_SUFFIX);
        File newFile = new File(workingDir, newRoleName + ROLE_SUFFIX);
        FileUtils.copyFile(file, newFile);
        Git git = Git.wrap(repo.r());
        git.rm().addFilepattern(roleName + ROLE_SUFFIX).call();
        git.add().addFilepattern(newRoleName + ROLE_SUFFIX).call();

        List<String> users = listUsers(repo);
        users.add(ANONYMOUS_USER_LOGIN_NAME);
        for (String user : users) {
            List<RoleGrantedAuthority> authorities = getUserAuthorities(user, repo);
            Set<RoleGrantedAuthority> newAuthorities = Sets.newHashSet();
            for (Iterator<RoleGrantedAuthority> iter = authorities.iterator(); iter.hasNext();) {
                RoleGrantedAuthority rga = iter.next();
                if (rga.getRoleName().equals(roleName)) {
                    RoleGrantedAuthority newRga = new RoleGrantedAuthority(rga.getTarget(), newRoleName);
                    newAuthorities.add(newRga);
                    iter.remove();
                }
            }
            if (!newAuthorities.isEmpty()) {
                authorities.addAll(newAuthorities);
                saveUserAuthorities(user, Sets.newHashSet(authorities), repo, currentUser, false);
            }
        }

        PersonIdent ident = new PersonIdent(currentUser.getLoginName(), currentUser.getEmail());
        git.commit().setAuthor(ident).setCommitter(ident)
                .setMessage("rename role " + roleName + " to " + newRoleName) //$NON-NLS-1$ //$NON-NLS-2$
                .call();
    } catch (GitAPIException e) {
        throw new IOException(e);
    } finally {
        Closeables.closeQuietly(repo);
    }
}

From source file:de.blizzy.documentr.access.UserStore.java

public void deleteRole(String roleName, User currentUser) throws IOException {
    Assert.hasLength(roleName);
    Assert.notNull(currentUser);//from w  w  w . ja  v  a  2 s  .c  om
    // check that role exists by trying to load it
    getRole(roleName);

    ILockedRepository repo = null;
    try {
        repo = globalRepositoryManager.getProjectCentralRepository(REPOSITORY_NAME, false);
        Git git = Git.wrap(repo.r());

        git.rm().addFilepattern(roleName + ROLE_SUFFIX).call();

        // remove role from all users
        List<String> users = listUsers(repo);
        users.add(ANONYMOUS_USER_LOGIN_NAME);
        for (String user : users) {
            List<RoleGrantedAuthority> authorities = getUserAuthorities(user, repo);
            boolean changed = false;
            for (Iterator<RoleGrantedAuthority> iter = authorities.iterator(); iter.hasNext();) {
                RoleGrantedAuthority rga = iter.next();
                if (rga.getRoleName().equals(roleName)) {
                    iter.remove();
                    changed = true;
                }
            }
            if (changed) {
                saveUserAuthorities(user, Sets.newHashSet(authorities), repo, currentUser, false);
            }
        }

        PersonIdent ident = new PersonIdent(currentUser.getLoginName(), currentUser.getEmail());
        git.commit().setAuthor(ident).setCommitter(ident).setMessage("delete role " + roleName) //$NON-NLS-1$
                .call();
    } catch (GitAPIException e) {
        throw new IOException(e);
    } finally {
        Closeables.closeQuietly(repo);
    }
}

From source file:de.blizzy.documentr.markdown.HtmlSerializerContext.java

public HtmlSerializerContext(String projectName, String branchName, String pagePath,
        MarkdownProcessor markdownProcessor, Authentication authentication, IPageStore pageStore,
        SystemSettingsStore systemSettingsStore, String contextPath) {

    Assert.hasLength(projectName);
    Assert.hasLength(branchName);/*from  w w  w.  ja  v a2 s . co  m*/
    // pagePath can be null for new pages
    Assert.notNull(markdownProcessor);
    Assert.notNull(authentication);
    Assert.notNull(pageStore);
    Assert.notNull(systemSettingsStore);

    this.projectName = projectName;
    this.branchName = branchName;
    this.pagePath = pagePath;
    this.markdownProcessor = markdownProcessor;
    this.authentication = authentication;
    this.pageStore = pageStore;
    this.systemSettingsStore = systemSettingsStore;
    this.contextPath = contextPath;
}

From source file:de.blizzy.documentr.markdown.macro.MessageSourceMacroDescriptor.java

MessageSourceMacroDescriptor(String macroName) {
    Assert.hasLength(macroName);
    Assert.isTrue(macroName.indexOf('.') < 0, "macro name contains dots: " + macroName); //$NON-NLS-1$

    this.macroName = macroName;
}

From source file:de.blizzy.documentr.page.CherryPicker.java

@Override
public SortedMap<String, List<CommitCherryPickResult>> cherryPick(String projectName, String branchName,
        String path, List<String> commits, Set<String> targetBranches,
        Set<CommitCherryPickConflictResolve> conflictResolves, boolean dryRun, User user, Locale locale)
        throws IOException {

    Assert.hasLength(projectName);
    Assert.hasLength(path);/*from w w  w  .j av  a  2s .c om*/
    Assert.notEmpty(commits);
    Assert.notEmpty(targetBranches);
    Assert.notNull(conflictResolves);
    Assert.notNull(user);

    // always do a dry run first and return early if it fails
    if (!dryRun) {
        SortedMap<String, List<CommitCherryPickResult>> results = cherryPick(projectName, branchName, path,
                commits, targetBranches, conflictResolves, true, user, locale);
        for (List<CommitCherryPickResult> branchResults : results.values()) {
            for (CommitCherryPickResult result : branchResults) {
                if (result.getStatus() != CommitCherryPickResult.Status.OK) {
                    return results;
                }
            }
        }
    }

    try {
        SortedMap<String, List<CommitCherryPickResult>> results = Maps.newTreeMap();
        for (String targetBranch : targetBranches) {
            List<CommitCherryPickResult> branchResults = cherryPick(projectName, branchName, path, commits,
                    targetBranch, conflictResolves, dryRun, user, locale);
            results.put(targetBranch, branchResults);
        }
        return results;
    } catch (GitAPIException e) {
        throw new IOException(e);
    }
}

From source file:de.blizzy.documentr.page.CommitCherryPickConflictResolve.java

public CommitCherryPickConflictResolve(String targetBranch, String commit, String text) {
    Assert.hasLength(targetBranch);
    Assert.hasLength(commit);/*from w  w  w  .ja  v  a  2s.  c om*/
    Assert.notNull(text);

    this.targetBranch = targetBranch;
    this.commit = commit;
    this.text = text;
}

From source file:de.blizzy.documentr.page.CommitCherryPickConflictResolve.java

boolean isApplicable(String targetBranch, String commit) {
    Assert.hasLength(targetBranch);
    Assert.hasLength(commit);/*from   w w w  .j  av  a  2  s.c om*/

    return targetBranch.equals(this.targetBranch) && commit.equals(this.commit);
}