Search in sources :

Example 31 with BeanComparator

use of org.apache.commons.beanutils.BeanComparator in project entando-core by entando.

the class AbstractApiAction method getPermissionAutorityOptions.

public List<SelectItem> getPermissionAutorityOptions() {
    List<SelectItem> items = new ArrayList<SelectItem>();
    try {
        List<Permission> permissions = new ArrayList<Permission>();
        permissions.addAll(this.getRoleManager().getPermissions());
        BeanComparator comparator = new BeanComparator("description");
        Collections.sort(permissions, comparator);
        for (int i = 0; i < permissions.size(); i++) {
            Permission permission = permissions.get(i);
            items.add(new SelectItem(permission.getName(), this.getPermissionAutorityOptionPrefix() + permission.getDescription()));
        }
    } catch (Throwable t) {
        _logger.error("Error extracting autority options", t);
    }
    return items;
}
Also used : SelectItem(com.agiletec.aps.util.SelectItem) ArrayList(java.util.ArrayList) Permission(com.agiletec.aps.system.services.role.Permission) BeanComparator(org.apache.commons.beanutils.BeanComparator)

Example 32 with BeanComparator

use of org.apache.commons.beanutils.BeanComparator in project entando-core by entando.

the class ApiServiceFinderAction method getServiceFlavours.

public Map<String, List<ApiSelectItem>> getServiceFlavours() {
    Map<String, List<ApiSelectItem>> groups = new HashMap<String, List<ApiSelectItem>>();
    try {
        this.buildServiceGroups(groups);
        Iterator<List<ApiSelectItem>> groupIter = groups.values().iterator();
        while (groupIter.hasNext()) {
            List<ApiSelectItem> group = groupIter.next();
            BeanComparator comparator = new BeanComparator("value");
            Collections.sort(group, comparator);
        }
    } catch (Throwable t) {
        _logger.error("Error extracting Flavours services", t);
        // ApsSystemUtils.logThrowable(t, this, "getServiceFlavours");
        throw new RuntimeException("Error extracting Flavours services", t);
    }
    return groups;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) List(java.util.List) ApiSelectItem(org.entando.entando.apsadmin.api.model.ApiSelectItem) BeanComparator(org.apache.commons.beanutils.BeanComparator)

Example 33 with BeanComparator

use of org.apache.commons.beanutils.BeanComparator in project entando-core by entando.

the class PageModelFinderAction method getPageModels.

public List<PageModel> getPageModels() {
    List<PageModel> models = new ArrayList<PageModel>();
    models.addAll(this.getPageModelManager().getPageModels());
    BeanComparator c = new BeanComparator("description");
    Collections.sort(models, c);
    return models;
}
Also used : ArrayList(java.util.ArrayList) PageModel(com.agiletec.aps.system.services.pagemodel.PageModel) BeanComparator(org.apache.commons.beanutils.BeanComparator)

Example 34 with BeanComparator

use of org.apache.commons.beanutils.BeanComparator in project entando-core by entando.

the class EntityTypesInfoTag method getMasterObject.

@Override
protected Object getMasterObject(String keyValue) throws Throwable {
    String managerNameValue = (String) super.findValue(keyValue, String.class);
    try {
        IEntityManager entityManager = (IEntityManager) ApsWebApplicationUtils.getBean(managerNameValue, this.pageContext);
        if (null != entityManager) {
            List<IApsEntity> entityTypes = new ArrayList<IApsEntity>();
            Map<String, IApsEntity> typeMap = entityManager.getEntityPrototypes();
            if (null != typeMap) {
                BeanComparator c = new BeanComparator(this.getOrderBy());
                entityTypes.addAll(typeMap.values());
                Collections.sort(entityTypes, c);
            }
            return entityTypes;
        } else {
            _logger.debug("Null entity manager : service name '{}'", managerNameValue);
        }
    } catch (Throwable t) {
        String message = "Error extracting entity types : entity manager '" + managerNameValue + "'";
        _logger.error("Error extracting entity types : entity manager '{}'", managerNameValue, t);
        // ApsSystemUtils.logThrowable(t, this, "getMasterObject", message);
        throw new ApsSystemException(message, t);
    }
    return null;
}
Also used : IEntityManager(com.agiletec.aps.system.common.entity.IEntityManager) ArrayList(java.util.ArrayList) IApsEntity(com.agiletec.aps.system.common.entity.model.IApsEntity) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) BeanComparator(org.apache.commons.beanutils.BeanComparator)

Example 35 with BeanComparator

use of org.apache.commons.beanutils.BeanComparator in project entando-core by entando.

the class ShortcutListTag method getAllowedShortcutSelectItems.

public List<SelectItem> getAllowedShortcutSelectItems(List<Shortcut> myShortcuts, UserDetails currentUser) {
    List<SelectItem> items = new ArrayList<SelectItem>();
    if (null == myShortcuts || myShortcuts.isEmpty()) {
        _logger.debug("shortcut list null");
        return items;
    }
    try {
        Map<String, List<SelectItem>> groups = new HashMap<String, List<SelectItem>>();
        for (int i = 0; i < myShortcuts.size(); i++) {
            Shortcut shortcut = myShortcuts.get(i);
            String groupCode = shortcut.getSource();
            String optgroup = shortcut.getSource();
            if (groupCode.equals("core")) {
                groupCode += " - " + shortcut.getMenuSection().getId();
                String sectDescrKey = shortcut.getMenuSection().getDescriptionKey();
                String sectDescr = this.getText(sectDescrKey);
                if (null == sectDescrKey || sectDescrKey.equals(sectDescr)) {
                    sectDescr = shortcut.getMenuSection().getDescription();
                }
                optgroup += " - " + sectDescr;
            } else {
                String labelCode = optgroup + ".name";
                String optgroupDescr = this.getText(labelCode);
                if (!optgroupDescr.equals(labelCode)) {
                    optgroup = optgroupDescr;
                }
            }
            String descrKey = shortcut.getDescriptionKey();
            String descr = this.getText(descrKey);
            if (null == descrKey || descrKey.equals(descr)) {
                descr = shortcut.getDescription();
            }
            List<SelectItem> itemsByGroup = groups.get(groupCode);
            if (null == itemsByGroup) {
                itemsByGroup = new ArrayList<SelectItem>();
                groups.put(groupCode, itemsByGroup);
            }
            SelectItem selectItem = new SelectItem(shortcut.getId(), descr, optgroup);
            itemsByGroup.add(selectItem);
        }
        List<String> keys = new ArrayList<String>(groups.keySet());
        Collections.sort(keys);
        for (int i = 0; i < keys.size(); i++) {
            List<SelectItem> itemsByGroup = groups.get(keys.get(i));
            BeanComparator comparator = new BeanComparator("value");
            Collections.sort(itemsByGroup, comparator);
            items.addAll(itemsByGroup);
        }
    } catch (Throwable t) {
        _logger.error("Error extracting allowed shortcut items by user {}", currentUser.getUsername(), t);
        throw new RuntimeException("Error extracting allowed shortcut items by user " + currentUser.getUsername(), t);
    }
    return items;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) BeanComparator(org.apache.commons.beanutils.BeanComparator) SelectItem(com.agiletec.aps.util.SelectItem) Shortcut(org.entando.entando.apsadmin.system.services.shortcut.model.Shortcut) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

BeanComparator (org.apache.commons.beanutils.BeanComparator)50 ArrayList (java.util.ArrayList)25 SelectItem (com.agiletec.aps.util.SelectItem)6 NullComparator (org.apache.commons.collections.comparators.NullComparator)6 IEntityManager (com.agiletec.aps.system.common.entity.IEntityManager)5 Group (com.agiletec.aps.system.services.group.Group)5 IApsEntity (com.agiletec.aps.system.common.entity.model.IApsEntity)4 ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)4 AttributeInterface (com.agiletec.aps.system.common.entity.model.attribute.AttributeInterface)3 Comparator (java.util.Comparator)3 HashMap (java.util.HashMap)3 List (java.util.List)3 ComparatorChain (org.apache.commons.collections.comparators.ComparatorChain)3 ReverseComparator (org.apache.commons.collections.comparators.ReverseComparator)3 Role (com.agiletec.aps.system.services.role.Role)2 WebApplicationContext (org.springframework.web.context.WebApplicationContext)2 SmallEntityType (com.agiletec.aps.system.common.entity.model.SmallEntityType)1 AbstractListAttribute (com.agiletec.aps.system.common.entity.model.attribute.AbstractListAttribute)1 AttributeRole (com.agiletec.aps.system.common.entity.model.attribute.AttributeRole)1 ListAttribute (com.agiletec.aps.system.common.entity.model.attribute.ListAttribute)1