if(permList == null) {
permList = new ArrayList<Permission>();
permByInode.put(p.getInode(), permList);
}
permList.add(p);
Identifier ident = APILocator.getIdentifierAPI().findFromInode(p.getInode());
if(ident.getAssetType().equals("folder")) {
Folder f = APILocator.getFolderAPI().find(p.getInode(), systemUser, respectFrontendRoles);
permAssets.add(f);
} else {
Host h = hostAPI.find(p.getInode(), systemUser, respectFrontendRoles);
if(h != null) {
permAssets.add(h);
}
}
}
List<Map<String, Object>> hostMaps = new ArrayList<Map<String,Object>>();
List<Map<String, Object>> folderMaps = new ArrayList<Map<String,Object>>();
boolean systemHostInList = false;
for(Object i : permAssets) {
if(i instanceof Host && ((Host)i).isSystemHost())
systemHostInList = true;
Map<String, Object> assetMap = i instanceof Host?((Host)i).getMap():((Inode)i).getMap();
String assetId = i instanceof Host?((Host)i).getIdentifier():((Inode)i).getInode();
List<Map<String, Object>> permissionsList = new ArrayList<Map<String,Object>>();
for(Permission p: permByInode.get(assetId)) {
permissionsList.add(p.getMap());
}
assetMap.put("permissions", permissionsList);
if(i instanceof Host) {
assetMap.put("type", "host");
hostMaps.add(assetMap);
} else {
Folder f = (Folder) i;
Identifier id = APILocator.getIdentifierAPI().find(f);
String hostId = f.getHostId();
Host h = hostAPI.find(hostId, systemUser, false);
assetMap.put("fullPath", h.getHostname() + ":" + id.getParentPath() + f.getName());
folderMaps.add(assetMap);
}
boolean permissionToEditPermissions = permAPI.doesUserHavePermission((Permissionable)i, PermissionAPI.PERMISSION_EDIT_PERMISSIONS, user, respectFrontendRoles);
assetMap.put("permissionToEditPermissions", permissionToEditPermissions);
}