List of usage examples for org.apache.commons.collections CollectionUtils intersection
public static Collection intersection(final Collection a, final Collection b)
From source file:org.compiere.mfg_scm.pluginManager.Mfg_scmUtils.java
/** * Take a dominant and recessive Map and merge the key:value pairs where the * recessive Map may add key:value pairs to the dominant Map but may not * override any existing key:value pairs. * /*from w w w . ja v a2 s . co m*/ * If we have two Maps, a dominant and recessive, and their respective keys * are as follows: * * dominantMapKeys = { a, b, c, d, e, f } recessiveMapKeys = { a, b, c, x, y, z } * * Then the result should be the following: * * resultantKeys = { a, b, c, d, e, f, x, y, z } * * @param dominantMap * Dominant Map. * @param recessiveMap * Recessive Map. * @return The result map with combined dominant and recessive values. */ @SuppressWarnings({ "rawtypes", "unchecked" }) public static Map mergeMaps(Map dominantMap, Map recessiveMap) { Map result = new HashMap(); if (dominantMap == null && recessiveMap == null) { return null; } if (dominantMap != null && recessiveMap == null) { return dominantMap; } if (dominantMap == null) { return recessiveMap; } // Grab the keys from the dominant and recessive maps. Set dominantMapKeys = dominantMap.keySet(); Set recessiveMapKeys = recessiveMap.keySet(); // Create the set of keys that will be contributed by the // recessive Map by subtracting the intersection of keys // from the recessive Map's keys. Collection contributingRecessiveKeys = CollectionUtils.subtract(recessiveMapKeys, CollectionUtils.intersection(dominantMapKeys, recessiveMapKeys)); result.putAll(dominantMap); // Now take the keys we just found and extract the values from // the recessiveMap and put the key:value pairs into the dominantMap. for (Iterator i = contributingRecessiveKeys.iterator(); i.hasNext();) { Object key = i.next(); result.put(key, recessiveMap.get(key)); } return result; }
From source file:org.eurekastreams.server.service.actions.strategies.activity.IterpolationListColliderTest.java
/** * Helper method, tests against apache commons intersection. * //w ww . j av a 2 s . c om * @param sorted * the sorted list. * @param unsorted * the unsorted list. * @param maxResults * the max results. */ @SuppressWarnings("unchecked") private static void collideTest(final Long[] sorted, final Long[] unsorted, final int maxResults) { List<Long> sortedList = Arrays.asList(sorted); List<Long> unsortedList = Arrays.asList(unsorted); Collection<Long> expected = CollectionUtils.intersection(sortedList, unsortedList); List<Long> actual = collider.collide(sortedList, unsortedList, maxResults); Assert.assertEquals(expected.size(), actual.size()); Assert.assertTrue(actual.size() <= maxResults); for (Long expectedItem : expected) { Assert.assertTrue(actual.contains(expectedItem)); } }
From source file:org.fao.geonet.api.users.UsersApi.java
@ApiOperation(value = "Delete a user", notes = "Deletes a catalog user by identifier.", nickname = "deleteUser") @RequestMapping(value = "/{userIdentifier}", produces = MediaType.APPLICATION_JSON_VALUE, method = RequestMethod.DELETE) @ResponseStatus(value = HttpStatus.OK)/*w ww.j a v a2 s . co m*/ @PreAuthorize("hasRole('UserAdmin') or hasRole('Administrator')") @ResponseBody public ResponseEntity<String> deleteUser( @ApiParam(value = "User identifier.") @PathVariable Integer userIdentifier, @ApiIgnore ServletRequest request, @ApiIgnore HttpSession httpSession) throws Exception { UserSession session = ApiUtils.getUserSession(httpSession); Profile myProfile = session.getProfile(); String myUserId = session.getUserId(); UserRepository userRepository = ApplicationContextHolder.get().getBean(UserRepository.class); UserGroupRepository userGroupRepository = ApplicationContextHolder.get().getBean(UserGroupRepository.class); UserSavedSelectionRepository userSavedSelectionRepository = ApplicationContextHolder.get() .getBean(UserSavedSelectionRepository.class); if (myUserId == null || myUserId.equals(Integer.toString(userIdentifier))) { throw new IllegalArgumentException("You cannot delete yourself from the user database"); } if (myProfile == Profile.UserAdmin) { final Integer iMyUserId = Integer.parseInt(myUserId); final List<Integer> groupIdsSessionUser = userGroupRepository.findGroupIds(where(hasUserId(iMyUserId))); final List<Integer> groupIdsUserToDelete = userGroupRepository .findGroupIds(where(hasUserId(userIdentifier))); if (CollectionUtils.intersection(groupIdsSessionUser, groupIdsUserToDelete).isEmpty()) { throw new IllegalArgumentException( "You don't have rights to delete this user because the user is not part of your group"); } } DataManager dataManager = ApplicationContextHolder.get().getBean(DataManager.class); // Before processing DELETE check that the user is not referenced // elsewhere in the GeoNetwork database - an exception is thrown if // this is the case if (dataManager.isUserMetadataOwner(userIdentifier)) { throw new IllegalArgumentException("Cannot delete a user that is also a metadata owner"); } if (dataManager.isUserMetadataStatus(userIdentifier)) { throw new IllegalArgumentException("Cannot delete a user that has set a metadata status"); } userGroupRepository.deleteAllByIdAttribute(UserGroupId_.userId, Arrays.asList(userIdentifier)); userSavedSelectionRepository.deleteAllByUser(userIdentifier); try { userRepository.delete(userIdentifier); } catch (org.springframework.dao.EmptyResultDataAccessException ex) { throw new UserNotFoundEx(Integer.toString(userIdentifier)); } return new ResponseEntity(HttpStatus.NO_CONTENT); }
From source file:org.fao.geonet.api.users.UsersApiTest.java
@Test public void deleteUserNotAllowedToUserAdmin() throws Exception { this.mockMvc = MockMvcBuilders.webAppContextSetup(this.wac).build(); final User userToDelete = _userRepo.findOneByUsername("testuser-reviewer"); Assert.assertNotNull(userToDelete);// w w w.j a v a 2 s . c o m Assert.assertTrue(userToDelete.getProfile().equals(Profile.Reviewer)); List<Integer> userToDeleteGroupIds = _userGroupRepo.findGroupIds(hasUserId(userToDelete.getId())); final User userAdmin = _userRepo.findOneByUsername("testuser-useradmin"); Assert.assertNotNull(userAdmin); Assert.assertTrue(userAdmin.getProfile().equals(Profile.UserAdmin)); List<Integer> userAdminGroupIds = _userGroupRepo.findGroupIds(hasUserId(userAdmin.getId())); // Check no common groups Assert.assertTrue(CollectionUtils.intersection(userToDeleteGroupIds, userAdminGroupIds).isEmpty()); this.mockHttpSession = loginAs(userAdmin); // Check 400 is returned and a message indicating that a user can't delete himself this.mockMvc .perform(delete("/api/users/" + userToDelete.getId()) .session(this.mockHttpSession).accept(MediaType.parseMediaType("application/json"))) .andExpect(status().is(400)) .andExpect(jsonPath("$.description", is("You don't have rights to delete this user because the user is not part of your group"))) .andExpect(content().contentType("application/json")); }
From source file:org.fao.geonet.kernel.EditLib.java
/** * TODO javadoc.//from www. j a v a 2s . c o m * * @param schema The metadata schema * @param sugg The suggestion configuration for the schema * @param parentName The name of the parent * @param element The element to fill * * @throws Exception */ private void fillElement(MetadataSchema schema, SchemaSuggestions sugg, String parentName, Element element) throws Exception { String elemName = element.getQualifiedName(); boolean isSimpleElement = schema.isSimpleElement(elemName, parentName); if (Log.isDebugEnabled(Geonet.EDITORFILLELEMENT)) { Log.debug(Geonet.EDITORFILLELEMENT, "#### Entering fillElement()"); Log.debug(Geonet.EDITORFILLELEMENT, "#### - elemName = " + elemName); Log.debug(Geonet.EDITORFILLELEMENT, "#### - parentName = " + parentName); Log.debug(Geonet.EDITORFILLELEMENT, "#### - isSimpleElement(" + elemName + ") = " + isSimpleElement); } // Nothing to fill - eg. gco:CharacterString if (isSimpleElement) { return; } MetadataType type = schema.getTypeInfo(schema.getElementType(elemName, parentName)); boolean hasSuggestion = sugg.hasSuggestion(elemName, type.getElementList()); // List<String> elementSuggestion = sugg.getSuggestedElements(elemName); // boolean hasSuggestion = elementSuggestion.size() != 0; if (Log.isDebugEnabled(Geonet.EDITORFILLELEMENT)) { Log.debug(Geonet.EDITORFILLELEMENT, "#### - Type:"); Log.debug(Geonet.EDITORFILLELEMENT, "#### - name = " + type.getName()); Log.debug(Geonet.EDITORFILLELEMENT, "#### - # attributes = " + type.getAttributeCount()); Log.debug(Geonet.EDITORFILLELEMENT, "#### - # elements = " + type.getElementCount()); Log.debug(Geonet.EDITORFILLELEMENT, "#### - # isOrType = " + type.isOrType()); Log.debug(Geonet.EDITORFILLELEMENT, "#### - type = " + type); Log.debug(Geonet.EDITORFILLELEMENT, "#### - Has suggestion = " + hasSuggestion); } //----------------------------------------------------------------------- //--- handle attributes if mandatory or suggested // for (int i = 0; i < type.getAttributeCount(); i++) { MetadataAttribute attr = type.getAttributeAt(i); if (Log.isDebugEnabled(Geonet.EDITORFILLELEMENT)) { Log.debug(Geonet.EDITORFILLELEMENT, "#### - " + i + " attribute = " + attr.name); Log.debug(Geonet.EDITORFILLELEMENT, "#### - required = " + attr.required); Log.debug(Geonet.EDITORFILLELEMENT, "#### - suggested = " + sugg.isSuggested(elemName, attr.name)); } if (attr.required || sugg.isSuggested(elemName, attr.name)) { String value = ""; if (attr.defValue != null) { value = attr.defValue; if (Log.isDebugEnabled(Geonet.EDITORFILLELEMENT)) { Log.debug(Geonet.EDITORFILLELEMENT, "#### - value = " + attr.defValue); } } String uname = getUnqualifiedName(attr.name); String ns = getNamespace(attr.name, element, schema); String prefix = getPrefix(attr.name); if (!prefix.equals("")) element.setAttribute(new Attribute(uname, value, Namespace.getNamespace(prefix, ns))); else element.setAttribute(new Attribute(uname, value)); } } //----------------------------------------------------------------------- //--- add mandatory children // // isOrType if element has substitutes and one of them should be chosen if (!type.isOrType()) { for (int i = 0; i < type.getElementCount(); i++) { String childName = type.getElementAt(i); boolean childIsMandatory = type.getMinCardinAt(i) > 0; boolean childIsSuggested = sugg.isSuggested(elemName, childName); if (Log.isDebugEnabled(Geonet.EDITORFILLELEMENT)) { Log.debug(Geonet.EDITORFILLELEMENT, "#### - " + i + " element = " + childName); Log.debug(Geonet.EDITORFILLELEMENT, "#### - suggested = " + childIsSuggested); Log.debug(Geonet.EDITORFILLELEMENT, "#### - is mandatory = " + childIsMandatory); } if (childIsMandatory || childIsSuggested) { MetadataType elemType = schema.getTypeInfo(schema.getElementType(childName, elemName)); List<String> childSuggestion = sugg.getSuggestedElements(childName); boolean childHasOneSuggestion = sugg.hasSuggestion(childName, elemType.getElementList()) && (CollectionUtils.intersection(elemType.getElementList(), childSuggestion) .size() == 1); boolean childHasOnlyCharacterStringSuggestion = childSuggestion.size() == 1 && childSuggestion.contains("gco:CharacterString"); if (Log.isDebugEnabled(Geonet.EDITORFILLELEMENT)) { Log.debug(Geonet.EDITORFILLELEMENT, "#### - is or type = " + elemType.isOrType()); Log.debug(Geonet.EDITORFILLELEMENT, "#### - has suggestion = " + childHasOneSuggestion); Log.debug(Geonet.EDITORFILLELEMENT, "#### - elem type list = " + elemType.getElementList()); Log.debug(Geonet.EDITORFILLELEMENT, "#### - suggested types list = " + sugg.getSuggestedElements(childName)); } //--- There can be 'or' elements with other 'or' elements inside them. //--- In this case we cannot expand the inner 'or' elements so the //--- only way to solve the problem is to avoid the creation of them if (schema.isSimpleElement(elemName, childName) || // eg. gco:Decimal !elemType.isOrType() || // eg. gmd:EX_Extent (elemType.isOrType() && ( // eg. depends on schema-suggestions.xml childHasOneSuggestion || // expand the only suggestion - TODO - this needs improvements (childSuggestion.size() == 0 && elemType.getElementList().contains("gco:CharacterString"))) // expand element which have no suggestion // and have a gco:CharacterString substitute. // gco:CharacterString is the default. )) { // Create the element String name = getUnqualifiedName(childName); String ns = getNamespace(childName, element, schema); String prefix = getPrefix(childName); Element child = new Element(name, prefix, ns); // Add it to the element element.addContent(child); if (childHasOnlyCharacterStringSuggestion) { child.addContent(new Element("CharacterString", Namespace.getNamespace("gco", schema.getNS("gco")))); } // Continue .... fillElement(schema, sugg, element, child); } else { // Logging some cases to avoid if (Log.isDebugEnabled(Geonet.EDITORFILLELEMENT)) { if (elemType.isOrType()) { if (elemType.getElementList().contains("gco:CharacterString") && !childHasOneSuggestion) { Log.debug(Geonet.EDITORFILLELEMENT, "#### - (INNER) Requested expansion of an OR element having gco:CharacterString substitute and no suggestion: " + element.getName()); } else { Log.debug(Geonet.EDITORFILLELEMENT, "#### - WARNING (INNER): requested expansion of an OR element : " + childName); } } } } } } } else if (type.getElementList().contains("gco:CharacterString") && !hasSuggestion) { // expand element which have no suggestion // and have a gco:CharacterString substitute. // gco:CharacterString is the default. if (Log.isDebugEnabled(Geonet.EDITORFILLELEMENT)) { Log.debug(Geonet.EDITORFILLELEMENT, "#### - Requested expansion of an OR element having gco:CharacterString substitute and no suggestion: " + element.getName()); } Element child = new Element("CharacterString", Namespace.getNamespace("gco", schema.getNS("gco"))); element.addContent(child); } else { // TODO: this could be supported if only one suggestion defined for an or element ? // It will require to get the proper namespace for the element if (Log.isDebugEnabled(Geonet.EDITORFILLELEMENT)) { Log.debug(Geonet.EDITORFILLELEMENT, "#### - WARNING : requested expansion of an OR element : " + element.getName()); } } }
From source file:org.fenixedu.academic.domain.phd.email.PhdProgramEmailBean.java
public AndPredicate<PhdIndividualProgramProcess> getManagedPhdProgramsPredicate() { final AndPredicate<PhdIndividualProgramProcess> result = new AndPredicate<PhdIndividualProgramProcess>(); if (getPhdProgram() != null) { result.add(new InlinePredicate<PhdIndividualProgramProcess, PhdProgram>(getPhdProgram()) { @Override/*from w w w. j av a2s . c o m*/ public boolean test(PhdIndividualProgramProcess toEval) { if (toEval.getPhdProgram() != null) { return getValue().equals(toEval.getPhdProgram()); } else if (toEval.getPhdProgramFocusArea() != null) { return !CollectionUtils.intersection(Collections.singleton(getValue()), toEval.getPhdProgramFocusArea().getPhdProgramsSet()).isEmpty(); } else { return false; } } }); } return result; }
From source file:org.fenixedu.academic.domain.phd.SearchPhdIndividualProgramProcessBean.java
private AndPredicate<PhdIndividualProgramProcess> getManagedPhdProgramsAndProcessesPredicate() { final AndPredicate<PhdIndividualProgramProcess> result = new AndPredicate<PhdIndividualProgramProcess>(); if (getFilterPhdPrograms() != null && getFilterPhdPrograms().booleanValue()) { result.add(new InlinePredicate<PhdIndividualProgramProcess, List<PhdProgram>>(getPhdPrograms()) { @Override/* www. j a va2 s . c o m*/ public boolean test(PhdIndividualProgramProcess toEval) { if (toEval.getPhdProgram() != null) { return getValue().contains(toEval.getPhdProgram()); } else if (toEval.getPhdProgramFocusArea() != null) { return !CollectionUtils .intersection(getValue(), toEval.getPhdProgramFocusArea().getPhdProgramsSet()) .isEmpty(); } else { return false; } } }); } if (getFilterPhdProcesses() != null && getFilterPhdProcesses().booleanValue()) { result.add(new InlinePredicate<PhdIndividualProgramProcess, List<PhdIndividualProgramProcess>>( getProcesses()) { @Override public boolean test(PhdIndividualProgramProcess toEval) { return getValue().contains(toEval); } }); } return result; }
From source file:org.fracturedatlas.athena.apa.impl.jpa.JpaApaAdapter.java
/** * Find tickets according to the AtheaSearch. * Type must be specified, but search constraints may be empty. This method honors start, end, and limit modifiers. * * If one of the fields is ValueType.TEXT, this method will throw an ApaException * * @param athenaSearch a set of search constraints and search modifiers * @return Set of tickets whose Props match the athenaSearch */// w w w . ja v a 2s .c o m @Override public Set<PTicket> findTickets(AthenaSearch athenaSearch) { logger.debug("Searching for tickets:"); logger.debug("{}", athenaSearch); checkValueTypes(athenaSearch); EntityManager em = this.emf.createEntityManager(); Query query = null; Collection<JpaRecord> finishedTicketsList = null; Set<JpaRecord> finishedTicketsSet = null; Collection<JpaRecord> ticketsList = null; if (athenaSearch.isQuerySearch()) { Set<PTicket> tickets = new HashSet<PTicket>(); Set<Object> ids = searchIndex(athenaSearch); for (Object id : ids) { PTicket ticket = getRecord(athenaSearch.getType(), id); if (ticket != null) { tickets.add(ticket); } else { logger.error("Found an id [{}] in the index that wasn't persisted in the DB", id); } } return tickets; } try { //if there are no modifiers, grab all records of (type) if (CollectionUtils.isEmpty(athenaSearch.getConstraints())) { logger.debug("No modifiers, getting all records of specified type"); finishedTicketsSet = getRecordsByType(athenaSearch, em); } else { //else, search with the modifiers //TODO: This block runs independent searches for each constraint, then just smashes those lists together //Smarter way would be to run the first constraint, then search THAT list for the next constraint //Even smarter: be clever about which constraint we search for first. for (AthenaSearchConstraint apc : athenaSearch.getConstraints()) { logger.debug("Searching on modifier: {}", apc); if (apc.getOper().equals(Operator.MATCHES)) { if (apc.getValue().equals(AthenaSearch.ANY_VALUE)) { ticketsList = getRecordsWithFieldDefined(athenaSearch.getType(), apc, em); } else { throw new UnsupportedOperationException("Regex searching is not supported"); } } else { ticketsList = getRecordsForConstraint(athenaSearch.getType(), apc, em); } logger.debug("Found {} tickets", ticketsList.size()); if (finishedTicketsList == null) { finishedTicketsList = ticketsList; } else { logger.debug("Smashing together ticket lists"); finishedTicketsList = CollectionUtils.intersection(finishedTicketsList, ticketsList); } logger.debug("{} tickets remain", finishedTicketsList.size()); } if (finishedTicketsList == null) { finishedTicketsList = new ArrayList<JpaRecord>(); } Integer limit = athenaSearch.getLimit(); Integer start = athenaSearch.getStart(); finishedTicketsSet = new HashSet<JpaRecord>(); finishedTicketsSet.addAll(finishedTicketsList); finishedTicketsSet = enforceStartAndLimit(finishedTicketsSet, start, limit); } logger.debug("Returning {} tickets", finishedTicketsSet.size()); return convert(finishedTicketsSet); } catch (ApaException ex) { throw ex; } finally { cleanup(em); } }
From source file:org.gvsig.framework.web.service.impl.OGCInfoServiceImpl.java
public WMSInfo getCapabilitiesFromWMS(String urlServerWMS, TreeSet<String> listCrs, String format, boolean isCalledByWizard) throws ServerGeoException { WMSInfo wmsInfo = new WMSInfo(); // put url on object WMSInfo wmsInfo.setServiceUrl(urlServerWMS); // Create hashmap to add the layers getted to the WMSInfo object Map<String, org.gvsig.framework.web.ogc.WMSLayer> layersMap = new HashMap<String, org.gvsig.framework.web.ogc.WMSLayer>(); // Create conexion with server WMS try {/*from ww w .ja v a2 s .c o m*/ WMSClient wms = new WMSClient(urlServerWMS); wms.connect(null); // set server information WMSServiceInformation serviceInfo = wms.getServiceInformation(); wmsInfo.setServiceAbstract(serviceInfo.abstr); wmsInfo.setServiceName(serviceInfo.name); wmsInfo.setServiceTitle(serviceInfo.title); // set id of the request wmsinfo (service name + calendar) int hashCode = (serviceInfo.name + Calendar.getInstance()).hashCode(); wmsInfo.setId(hashCode); // get and set version String version = wms.getVersion(); wmsInfo.setVersion(version); // get and set formats Vector formatVector = wms.getFormats(); TreeSet<String> formatSet = new TreeSet<String>(); formatSet.addAll(formatVector); wmsInfo.setFormatsSupported(formatSet); if (StringUtils.isEmpty(format)) { format = getFirstFormatSupported(formatSet); wmsInfo.setFormatSelected(format); } // check format if (isCalledByWizard || (!isCalledByWizard && formatVector.contains(format))) { wmsInfo.setFormatSelected(format); // get root layer WMSLayer rootLayer = wms.getRootLayer(); // get crs (srs) (belong to layer) Vector crsVector = rootLayer.getAllSrs(); // get and set all common crs supported TreeSet<String> crsTreeSet = new TreeSet<String>(); crsTreeSet.addAll(crsVector); wmsInfo.setCrsSupported(crsTreeSet); // Create tree with layer values List<TreeNode> tree = new ArrayList<TreeNode>(); // Create root node ArrayList<WMSLayer> children = rootLayer.getChildren(); TreeNode rootNode = new TreeNode("rootLayer_" + rootLayer.getName()); rootNode.setTitle(rootLayer.getTitle()); if (children.isEmpty()) { rootNode.setFolder(false); } else { rootNode.setFolder(true); rootNode.setExpanded(true); generateWMSChildrenNodes(children, tree, listCrs, rootNode, layersMap, wmsInfo); } // Set childrenLayers paramrootLayer.getChildren() wmsInfo.setChildrenCount(children.size()); // Only register the tree if it has a layer with crs defined if (rootNode.hasChildren()) { tree.add(rootNode); wmsInfo.setLayersTree(tree); } TreeSet<String> selCrs = new TreeSet<String>(); if (listCrs.isEmpty()) { selCrs.addAll(wmsInfo.getCrsSupported()); } else { selCrs.addAll(CollectionUtils.intersection(listCrs, wmsInfo.getCrsSupported())); } wmsInfo.setCrsSelected(selCrs); // Add map that contains info of all layers wmsInfo.setLayers(layersMap); } } catch (Exception exc) { // Show exception in log and create ServerGeoException which is // captured on controller and puts message to ajax response logger.error("Exception on getCapabilitiesFromWMS", exc); throw new ServerGeoException(); } return wmsInfo; }
From source file:org.jahia.ajax.gwt.helper.ContentManagerHelper.java
public GWTJahiaNodeACL getACL(String path, boolean newAcl, JCRSessionWrapper currentUserSession, Locale uiLocale) throws GWTJahiaServiceException { JCRNodeWrapper node;// w w w . j a v a2s .co m try { node = currentUserSession.getNode(path); } catch (RepositoryException e) { logger.error(e.toString(), e); throw new GWTJahiaServiceException( path + Messages.getInternal("label.gwt.error.could.not.be.accessed", uiLocale) + e.toString()); } Map<String, List<String[]>> m = node.getAclEntries(); GWTJahiaNodeACL acl = new GWTJahiaNodeACL(); try { Map<String, List<JCRNodeWrapper>> roles = node.getAvailableRoles(); Map<String, List<String>> dependencies = new HashMap<String, List<String>>(); Map<String, List<String>> availablePermissions = new HashMap<String, List<String>>(); Set<String> allAvailablePermissions = new HashSet<String>(); Map<String, String> labels = new HashMap<String, String>(); Map<String, String> tooltips = new HashMap<String, String>(); for (Map.Entry<String, List<JCRNodeWrapper>> entry : roles.entrySet()) { availablePermissions.put(entry.getKey(), new ArrayList<String>()); for (JCRNodeWrapper nodeWrapper : entry.getValue()) { String nodeName = nodeWrapper.getName(); allAvailablePermissions.add(nodeName); availablePermissions.get(entry.getKey()).add(nodeName); String label = nodeWrapper.getDisplayableName(); labels.put(nodeName, StringUtils.isEmpty(label) ? nodeName : label); if (nodeWrapper.hasProperty("jcr:description")) { tooltips.put(nodeName, nodeWrapper.getProperty("jcr:description").getString()); } List<String> d = new ArrayList<String>(); if (nodeWrapper.hasProperty("j:dependencies")) { for (Value value : nodeWrapper.getProperty("j:dependencies").getValues()) { d.add(((JCRValueWrapper) value).getNode().getName()); } } dependencies.put(nodeName, d); } } acl.setAvailableRoles(availablePermissions); acl.setRolesLabels(labels); acl.setRolesTooltips(tooltips); acl.setRoleDependencies(dependencies); List<GWTJahiaNodeACE> aces = new ArrayList<GWTJahiaNodeACE>(); Map<String, GWTJahiaNodeACE> map = new HashMap<String, GWTJahiaNodeACE>(); JahiaGroupManagerService groupManagerService = ServicesRegistry.getInstance() .getJahiaGroupManagerService(); for (String principal : m.keySet()) { GWTJahiaNodeACE ace = new GWTJahiaNodeACE(); ace.setPrincipalType(principal.charAt(0)); ace.setPrincipal(principal.substring(2)); // we set this even if we can't lookup the principal if (ace.getPrincipalType() == 'g') { JCRGroupNode g = groupManagerService.lookupGroup(node.getResolveSite().getSiteKey(), ace.getPrincipal()); if (g == null) { g = groupManagerService.lookupGroup(null, ace.getPrincipal()); } if (g != null) { ace.setHidden(g.isHidden()); ace.setPrincipalKey(g.getPath()); String groupName = g.getDisplayableName(uiLocale); ace.setPrincipalDisplayName(groupName); } else { continue; } } else { JCRUserNode u = ServicesRegistry.getInstance().getJahiaUserManagerService() .lookupUser(ace.getPrincipal(), node.getResolveSite().getName()); if (u != null) { ace.setPrincipalKey(u.getPath()); String userName = u.getDisplayableName(uiLocale); ace.setPrincipalDisplayName(userName); } else { continue; } } map.put(principal, ace); List<String[]> st = m.get(principal); Map<String, Boolean> perms = new HashMap<String, Boolean>(); Map<String, Boolean> inheritedPerms = new HashMap<String, Boolean>(); String inheritedFrom = null; for (String[] strings : st) { String pathFrom = strings[0]; String aclType = strings[1]; if (aclType.equals("GRANT") || aclType.equals("DENY")) { String role = strings[2]; if (!newAcl && path.equals(pathFrom)) { perms.put(role, aclType.equals("GRANT")); } else if (!inheritedPerms.containsKey(role)) { if (inheritedFrom == null || inheritedFrom.length() < pathFrom.length()) { inheritedFrom = pathFrom; } inheritedPerms.put(role, aclType.equals("GRANT")); } } } if (!CollectionUtils.intersection(allAvailablePermissions, inheritedPerms.keySet()).isEmpty() || !CollectionUtils.intersection(allAvailablePermissions, perms.keySet()).isEmpty()) { aces.add(ace); ace.setInheritedFrom(inheritedFrom); ace.setInheritedRoles(inheritedPerms); ace.setRoles(perms); ace.setInherited(perms.isEmpty()); } } boolean aclInheritanceBreak = node.getAclInheritanceBreak(); acl.setBreakAllInheritance(aclInheritanceBreak); if (aclInheritanceBreak) { m = node.getParent().getAclEntries(); for (String principal : m.keySet()) { GWTJahiaNodeACE ace = map.get(principal); if (ace == null) { ace = new GWTJahiaNodeACE(); map.put(principal, ace); aces.add(ace); ace.setPrincipalType(principal.charAt(0)); ace.setPrincipal(principal.substring(2)); // we set this even if we can't lookup the principal if (ace.getPrincipalType() == 'g') { JCRGroupNode g = groupManagerService.lookupGroup(node.getResolveSite().getSiteKey(), ace.getPrincipal()); if (g == null) { g = groupManagerService.lookupGroup(null, ace.getPrincipal()); } if (g != null) { ace.setHidden(g.isHidden()); String groupName = g.getDisplayableName(uiLocale); ace.setPrincipalKey(g.getPath()); ace.setPrincipalDisplayName(groupName); } } else { JCRUserNode u = ServicesRegistry.getInstance().getJahiaUserManagerService() .lookupUser(ace.getPrincipal(), node.getResolveSite().getName()); if (u != null) { ace.setPrincipalKey(u.getPath()); String userName = u.getDisplayableName(uiLocale); ace.setPrincipalDisplayName(userName); } } ace.setRoles(new HashMap<String, Boolean>()); } Map<String, Boolean> inheritedPerms = new HashMap<String, Boolean>(); List<String[]> st = m.get(principal); String inheritedFrom = null; for (String[] strings : st) { String pathFrom = strings[0]; String aclType = strings[1]; if (aclType.equals("GRANT") || aclType.equals("DENY")) { String role = strings[2]; if (!inheritedPerms.containsKey(role)) { if (inheritedFrom == null || inheritedFrom.length() < pathFrom.length()) { inheritedFrom = pathFrom; } inheritedPerms.put(role, aclType.equals("GRANT")); } } } ace.setInheritedFrom(inheritedFrom); ace.setInheritedRoles(inheritedPerms); } } acl.setAce(aces); } catch (RepositoryException e) { logger.error(e.getMessage(), e); } return acl; }