Map<String, GWTJahiaNodeACE> map = new HashMap<String, GWTJahiaNodeACE>();
JahiaGroupManagerService groupManagerService = ServicesRegistry.getInstance().getJahiaGroupManagerService();
for (Iterator<String> iterator = m.keySet().iterator(); iterator.hasNext();) {
String principal = iterator.next();
GWTJahiaNodeACE ace = new GWTJahiaNodeACE();
ace.setPrincipalType(principal.charAt(0));
ace.setPrincipal(principal.substring(2));
if (ace.getPrincipalType() == 'g') {
JahiaGroup g = groupManagerService.lookupGroup(node.getResolveSite().getID(), ace.getPrincipal());
if (g == null) {
g = groupManagerService.lookupGroup(ace.getPrincipal());
}
if (g != null) {
ace.setHidden(g.isHidden());
ace.setPrincipalKey(g.getGroupKey());
} else {
continue;
}
} else {
JahiaUser u = ServicesRegistry.getInstance().getJahiaUserManagerService().lookupUser(ace.getPrincipal());
if (u != null) {
ace.setPrincipalKey(u.getUserKey());
} 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];
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.setInheritedPermissions(inheritedPerms);
ace.setPermissions(perms);
ace.setInherited(perms.isEmpty());
}
}
boolean aclInheritanceBreak = node.getAclInheritanceBreak();
acl.setBreakAllInheritance(aclInheritanceBreak);
if (aclInheritanceBreak) {
m = node.getParent().getAclEntries();
for (Iterator<String> iterator = m.keySet().iterator(); iterator.hasNext();) {
String principal = iterator.next();
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));
if (ace.getPrincipalType() == 'g') {
JahiaGroup g = groupManagerService.lookupGroup(node.getResolveSite().getID(),
ace.getPrincipal());
if (g == null) {
g = groupManagerService.lookupGroup(ace.getPrincipal());
}
if (g != null) {
ace.setHidden(g.isHidden());
}
}
ace.setPermissions(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];
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.setInheritedPermissions(inheritedPerms);
}
}
acl.setAce(aces);
} catch (RepositoryException e) {