List of usage examples for org.springframework.util Assert notEmpty
@Deprecated public static void notEmpty(@Nullable Map<?, ?> map)
From source file:com.yqboots.security.core.RoleManagerImpl.java
/** * {@inheritDoc}/*from w ww . j ava 2s . c om*/ */ @Override @Transactional @Auditable(code = SecurityAudit.CODE_REMOVE_USERS_FROM_ROLE) public void removeUsers(final String path, final String... usernames) throws RoleNotFoundException { Assert.hasText(path); Assert.notEmpty(usernames); final Role role = roleRepository.findByPath(path); if (role == null) { throw new RoleNotFoundException(path); } final List<User> users = userRepository.findByRolesPath(role.getPath()); users.stream().filter(user -> ArrayUtils.contains(usernames, user.getUsername())) .forEach(user -> user.getRoles().remove(role)); }
From source file:com.yqboots.security.core.RoleManagerImpl.java
/** * {@inheritDoc}/* w w w . j a va2 s .c om*/ */ @Override @Transactional @Auditable(code = SecurityAudit.CODE_REMOVE_GROUPS_FROM_ROLE) public void removeGroups(final String path, final Long... groupIds) throws RoleNotFoundException { Assert.hasText(path); Assert.notEmpty(groupIds); final Role role = roleRepository.findByPath(path); if (role == null) { throw new RoleNotFoundException(path); } final List<Group> groups = groupRepository.findByRolesPath(role.getPath()); groups.stream().filter(group -> ArrayUtils.contains(groupIds, group.getId())) .forEach(group -> group.getRoles().remove(role)); }
From source file:com.yqboots.security.core.RoleManagerImpl.java
/** * {@inheritDoc}//from w w w . ja v a 2s. com */ @Override @Transactional @Auditable(code = SecurityAudit.CODE_REMOVE_GROUPS_FROM_ROLE) public void removeGroups(final String path, final String... groupPaths) throws RoleNotFoundException { Assert.hasText(path); Assert.notEmpty(groupPaths); final Role role = roleRepository.findByPath(path); if (role == null) { throw new RoleNotFoundException(path); } final List<Group> groups = groupRepository.findByRolesPath(role.getPath()); groups.stream().filter(group -> ArrayUtils.contains(groupPaths, group.getPath())) .forEach(group -> group.getRoles().remove(role)); }
From source file:com.yqboots.security.core.UserManagerImpl.java
/** * {@inheritDoc}//from www. j ava 2 s . com */ @Override @Transactional @Auditable(code = SecurityAudit.CODE_REMOVE_GROUPS_FROM_USER) public void removeGroups(final String username, final String... groupPaths) throws UserNotFoundException { Assert.hasText(username); Assert.notEmpty(groupPaths); final User user = userRepository.findByUsername(username); if (user == null) { throw new UserNotFoundException(username); } final List<Group> groups = groupRepository.findByPathIn(Arrays.asList(groupPaths)); groups.stream().filter(group -> ArrayUtils.contains(groupPaths, group.getPath())) .forEach(group -> user.getGroups().remove(group)); }
From source file:com.yqboots.security.core.UserManagerImpl.java
/** * {@inheritDoc}/*from w ww .j a v a2 s . c o m*/ */ @Override @Transactional @Auditable(code = SecurityAudit.CODE_REMOVE_GROUPS_FROM_USER) public void removeGroups(final String username, final Long... groupIds) throws UserNotFoundException { Assert.hasText(username); Assert.notEmpty(groupIds); User user = userRepository.findByUsername(username); if (user == null) { throw new UserNotFoundException(username); } final List<Group> groups = groupRepository.findAll(Arrays.asList(groupIds)); groups.stream().filter(group -> ArrayUtils.contains(groupIds, group.getId())) .forEach(group -> user.getGroups().remove(group)); }
From source file:com.yqboots.security.core.UserManagerImpl.java
/** * {@inheritDoc}/*from www. ja va 2 s . com*/ */ @Override @Transactional @Auditable(code = SecurityAudit.CODE_REMOVE_ROLES_FROM_USER) public void removeRoles(final String username, final String... rolePaths) throws UserNotFoundException { Assert.hasText(username); Assert.notEmpty(rolePaths); final User user = userRepository.findByUsername(username); if (user == null) { throw new UserNotFoundException(username); } final List<Role> roles = roleRepository.findByPathIn(Arrays.asList(rolePaths)); roles.stream().filter(role -> ArrayUtils.contains(rolePaths, role.getPath())) .forEach(role -> user.getRoles().remove(role)); }
From source file:com.yqboots.security.core.UserManagerImpl.java
/** * {@inheritDoc}/* w ww .j a va2s .c o m*/ */ @Override @Transactional @Auditable(code = SecurityAudit.CODE_REMOVE_ROLES_FROM_USER) public void removeRoles(final String username, final Long... roleIds) throws UserNotFoundException { Assert.hasText(username); Assert.notEmpty(roleIds); final User user = userRepository.findByUsername(username); if (user == null) { throw new UserNotFoundException(username); } final List<Role> roles = roleRepository.findAll(Arrays.asList(roleIds)); roles.stream().filter(role -> ArrayUtils.contains(roleIds, role.getId())) .forEach(role -> user.getRoles().remove(role)); }
From source file:com.yqboots.web.thymeleaf.support.Html2PdfGenerator.java
/** * Generates PDF files of multiple pages, using more than one template. * * @param templates the Thymeleaf templates * @param variables the variables passed to the template * @param output the output path/* w w w .j a v a2 s. c o m*/ * @throws IOException if error happened */ public void generate(final String[] templates, final Map<String, Object> variables, final Path output) throws IOException { Assert.notEmpty(templates); // get context final Context context = new Context(); context.setVariables(variables); final List<String> pages = new ArrayList<>(); try { for (final String template : templates) { try (final StringWriter writer = new StringWriter(); final BufferedWriter bw = new BufferedWriter(writer)) { templateEngine.process(template, context, bw); // output html bw.flush(); writer.flush(); pages.add(writer.toString()); } } toPDF(pages.toArray(new String[pages.size()]), output); } catch (Exception e) { LOG.error(e.getMessage(), e); throw new IOException(e); } }
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);// www.jav a 2 s .c o m Assert.hasLength(path); 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.PageStore.java
@Override public Map<String, String> getMarkdown(String projectName, String branchName, String path, Set<String> versions) throws IOException { Assert.hasLength(projectName);//from ww w . jav a2 s.c o m Assert.hasLength(branchName); Assert.hasLength(path); // check if page exists by trying to load it getPage(projectName, branchName, path, false); Assert.notEmpty(versions); Map<String, String> result = Maps.newHashMap(); ILockedRepository repo = null; try { repo = globalRepositoryManager.getProjectBranchRepository(projectName, branchName); String filePath = DocumentrConstants.PAGES_DIR_NAME + "/" + path + DocumentrConstants.PAGE_SUFFIX; //$NON-NLS-1$ Set<String> realVersions = Sets.newHashSet(); for (String version : versions) { if (version.equals(VERSION_LATEST)) { RevCommit latestCommit = CommitUtils.getLastCommit(repo.r(), filePath); String commitId = latestCommit.getName(); result.put(VERSION_LATEST, commitId); realVersions.add(commitId); } else if (version.equals(VERSION_PREVIOUS)) { RevCommit latestCommit = CommitUtils.getLastCommit(repo.r(), filePath); if (latestCommit.getParentCount() > 0) { RevCommit parentCommit = latestCommit.getParent(0); RevCommit previousCommit = CommitUtils.getLastCommit(repo.r(), parentCommit.getName(), filePath); if (previousCommit != null) { String commitId = previousCommit.getName(); result.put(VERSION_PREVIOUS, commitId); realVersions.add(commitId); } } } else { realVersions.add(version); } } for (String version : realVersions) { String markdown = BlobUtils.getContent(repo.r(), version, filePath); if (markdown != null) { result.put(version, markdown); } } } catch (GitAPIException e) { throw new IOException(e); } finally { Closeables.closeQuietly(repo); } return result; }