/** * Add given company to the cache. * * @param company * The new company. * @return <code>company</code> */ public CompanyOrg create(final CompanyOrg company) { cache.create(company); getCompany().findAll().put(company.getId(), company); return company; }
/** * Remove given company from the cache. Warning, it is assumed there is no more user associated to the deleted * company. * * @param company * The company to remove. */ public void delete(final CompanyOrg company) { final Map<String, CompanyOrg> companiesNameToDn = getCompany().findAll(); // Remove from JPA cache cache.delete(company); // Remove from in-memory cache companiesNameToDn.remove(company.getId()); }
@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()); } }
final Page<CompanyOrg> findAll = getRepository().findAll(visibleCompanies, DataTableAttributes.getSearch(uriInfo), pageRequest, Collections.singletonMap(TYPE_ATTRIBUTE, new TypeComparator(types)));
/** * 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; }); }
final Map<String, CompanyOrg> allCompanies = getCompany().findAll(); final Map<String, GroupOrg> allGroups = getGroup().findAll();