/** * Return all user entries. Cache manager is not involved, poor performance is expected. * * @param groups * The available and resolved groups. * @return all user entries. Key is the user identifier. * @since 3.0.2 */ default Map<String, UserOrg> findAllNoCache(Map<String, GroupOrg> groups) { return findAll(); }
/** * Return the {@link UserOrg} corresponding to the given identifier using the user cache. * * @param id * the user identifier. * @return the {@link UserOrg} corresponding to the given identifier. May be <code>null</code>. */ default UserOrg findById(final String id) { return findAll().get(id); }
/** * Add given user to the cache. Membership is not considered. * * @param user * The new user. * @return <code>user</code> */ public UserOrg create(final UserOrg user) { cache.create(user); getUser().findAll().put(user.getId(), user); return user; }
@Override protected void checkForDeletion(final ContainerOrg container) { super.checkForDeletion(container); // Company deletion is only possible where there is no user inside this company, or inside any sub-company final Map<String, UserOrg> users = getUser().findAll(); if (getRepository().findAll().values().stream() .filter(c -> DnUtils.equalsOrParentOf(container.getDn(), c.getDn())) .anyMatch(c -> users.values().stream().map(UserOrg::getCompany).anyMatch(c.getId()::equals))) { // Locked container is inside the container to delete throw new ValidationJsonException(getTypeName(), "not-empty-company", "0", getTypeName(), "1", container.getId()); } }
/** * Remove given group from the cache. User should have been removed from each group before that, this function does * not update in memory membership. * * @param user * the user to remove. */ public void delete(final UserOrg user) { final Map<String, UserOrg> users = getUser().findAll(); // Remove from JPA cache cache.delete(user); // Remove it-self from in-memory cache users.remove(Normalizer.normalize(user.getId())); }
/** * Retrieve all elements with pagination * * @param uriInfo * pagination data. * @param typeSearch * Optional {@link DelegateType} search. * @return all elements with pagination. */ @GET public TableItem<DelegateOrgLightVo> findAll(@Context final UriInfo uriInfo, @QueryParam("type") final DelegateType typeSearch) { // Trigger cache loading getUser().findAll(); final PageRequest pageRequest = paginationJson.getPageRequest(uriInfo, ORDERED_COLUMNS); final Page<DelegateOrg> findAll = repository.findAll(securityHelper.getLogin(), DataTableAttributes.getSearch(uriInfo), typeSearch, pageRequest); // apply pagination and prevent lazy initialization issue return paginationJson.applyPagination(uriInfo, findAll, this::toVo); }
return getUser().findAll(filteredGroups, filteredCompanies, StringUtils.trimToNull(criteria), pageRequest);
/** * Empty this group by removing all members if supported by the repository. * * @param id * The group to empty. */ @POST @Path("empty/{id}") public void empty(@PathParam("id") final String id) { // Check the group exists final GroupOrg container = findByIdExpected(id); // Check the group can be updated by the current user if (!getContainersForWrite().contains(container)) { throw new ValidationJsonException(getTypeName(), BusinessException.KEY_UNKNOW_ID, "0", getTypeName(), "1", id); } // Perform the update getRepository().empty(container, getUser().findAll()); }
/** * Remove given group from the cache. * * @param group * the group to remove. */ public void delete(final GroupOrg group) { final Map<String, GroupOrg> groupsNameToDn = getGroup().findAll(); // Remove the group from the users deleteMemoryAssociations(group, getUser().findAll()); // Remove from JPA cache cache.delete(group); // Remove the group groupsNameToDn.remove(group.getId()); }
final Set<CompanyOrg> writeCompanies = getContainersForWrite(); final Set<CompanyOrg> adminCompanies = getContainersForAdmin(); final Map<String, UserOrg> users = getUser().findAll();
/** * Return groups matching to given criteria. The visible groups, trees and companies are checked. The returned * groups of each user depends on the groups the user can see/write in CN form. * * @param uriInfo * filter data. * @return found groups. */ @GET public TableItem<ContainerCountVo> findAll(@Context final UriInfo uriInfo) { final List<ContainerScope> types = containerScopeResource.findAllDescOrder(ContainerType.GROUP); final Map<String, CompanyOrg> companies = getCompany().findAll(); final Collection<CompanyOrg> visibleCompanies = organizationResource.getContainers(); final Set<GroupOrg> writeGroups = getContainersForWrite(); final Set<GroupOrg> adminGroups = getContainersForAdmin(); final Map<String, UserOrg> users = getUser().findAll(); // Search the groups final Page<GroupOrg> findAll = getContainers(DataTableAttributes.getSearch(uriInfo), paginationJson.getPageRequest(uriInfo, ORDERED_COLUMNS)); // Apply pagination and secure the users data return paginationJson.applyPagination(uriInfo, findAll, rawGroup -> { final ContainerCountVo securedUserOrg = newContainerCountVo(rawGroup, writeGroups, adminGroups, types); securedUserOrg.setCount(rawGroup.getMembers().size()); // Computed the visible members securedUserOrg.setCountVisible((int) rawGroup.getMembers().stream().map(users::get).map(UserOrg::getCompany) .map(companies::get).map(CompanyOrg::getCompanyTree) .filter(c -> CollectionUtils.containsAny(visibleCompanies, c)).count()); return securedUserOrg; }); }