public Map<String, Object> findHostsPaginated(String filter, boolean showArchived, int offset, int count) throws DotDataException, DotSecurityException, PortalException, SystemException {
WebContext ctx = WebContextFactory.get();
HttpServletRequest req = ctx.getHttpServletRequest();
User user = userWebAPI.getLoggedInUser(req);
PermissionAPI permissionAPI = APILocator.getPermissionAPI();
boolean respectFrontend = !userWebAPI.isLoggedToBackend(req);
List<Host> hosts = hostAPI.findAllFromDB(user, respectFrontend);
long totalResults;
List<Map<String, Object>> listOfHosts = new ArrayList<Map<String,Object>>(hosts.size());
Structure hostStructure = StructureCache.getStructureByVelocityVarName("Host");
List<Field> fields = FieldsCache.getFieldsByStructureVariableName("Host");
List<Field> searchableFields = new ArrayList<Field>(fields.size());
for(Field field : fields) {
if(field.isListed() && field.getFieldType().startsWith("text"))
searchableFields.add(field);
}
Collections.sort(hosts, new HostNameComparator());
for(Host h : hosts) {
if(h.isSystemHost())
continue;
boolean addToList = false;
if (showArchived) {
if(!UtilMethods.isSet(filter))
addToList = true;
else {
for(Field searchableField : searchableFields) {
String value = h.getStringProperty(searchableField.getVelocityVarName());
if(value != null && value.toLowerCase().contains(filter.toLowerCase()))
addToList = true;
}
}
} else if (!h.isArchived()) {
if(!UtilMethods.isSet(filter))
addToList = true;
else {
for(Field searchableField : searchableFields) {
String value = h.getStringProperty(searchableField.getVelocityVarName());
if(value != null && value.toLowerCase().contains(filter.toLowerCase()))
addToList = true;
}
}
}
if(addToList) {
boolean hostInSetup = false;
try {
hostInSetup = QuartzUtils.isJobSequentiallyScheduled("setup-host-" + h.getIdentifier(), "setup-host-group");
} catch (SchedulerException e) {
Logger.error(HostAjax.class, e.getMessage(), e);
}
Map<String, Object> hostMap = h.getMap();
hostMap.put("userPermissions", permissionAPI.getPermissionIdsFromUser(h, user));
hostMap.put("hostInSetup", hostInSetup);
hostMap.put("archived", h.isArchived());
hostMap.put("live", h.isLive());
listOfHosts.add(hostMap);
}