Search in sources :

Example 1 with GroupUtilizer

use of com.agiletec.aps.system.services.group.GroupUtilizer in project entando-core by entando.

the class GroupService method getReferencesInfo.

public Map<String, Boolean> getReferencesInfo(Group group) {
    Map<String, Boolean> references = new HashMap<String, Boolean>();
    try {
        String[] defNames = applicationContext.getBeanNamesForType(GroupUtilizer.class);
        for (int i = 0; i < defNames.length; i++) {
            Object service = null;
            try {
                service = applicationContext.getBean(defNames[i]);
            } catch (Throwable t) {
                logger.error("error in hasReferencingObjects", t);
                service = null;
            }
            if (service != null) {
                GroupUtilizer<?> groupUtilizer = (GroupUtilizer<?>) service;
                List<?> utilizers = groupUtilizer.getGroupUtilizers(group.getName());
                if (utilizers != null && !utilizers.isEmpty()) {
                    references.put(groupUtilizer.getName(), true);
                } else {
                    references.put(groupUtilizer.getName(), false);
                }
            }
        }
    } catch (ApsSystemException ex) {
        logger.error("error loading references for group {}", group.getName(), ex);
        throw new RestServerError("error in getReferencingObjects ", ex);
    }
    return references;
}
Also used : HashMap(java.util.HashMap) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) RestServerError(org.entando.entando.aps.system.exception.RestServerError) GroupUtilizer(com.agiletec.aps.system.services.group.GroupUtilizer)

Example 2 with GroupUtilizer

use of com.agiletec.aps.system.services.group.GroupUtilizer in project entando-core by entando.

the class TestGroupUtilizer method testGetGroupsUtilizers.

public void testGetGroupsUtilizers() throws Throwable {
    String[] names = this.getApplicationContext().getBeanNamesForType(GroupUtilizer.class);
    assertTrue(names.length >= 4);
    for (int i = 0; i < names.length; i++) {
        GroupUtilizer service = (GroupUtilizer) this.getApplicationContext().getBean(names[i]);
        List utilizers = service.getGroupUtilizers("coach");
        if (names[i].equals(JacmsSystemConstants.CONTENT_MANAGER)) {
            assertEquals(6, utilizers.size());
        } else if (names[i].equals(JacmsSystemConstants.RESOURCE_MANAGER)) {
            assertEquals(0, utilizers.size());
        }
    }
}
Also used : List(java.util.List) GroupUtilizer(com.agiletec.aps.system.services.group.GroupUtilizer)

Example 3 with GroupUtilizer

use of com.agiletec.aps.system.services.group.GroupUtilizer in project entando-core by entando.

the class GroupActionHelper method getReferencingObjects.

@Override
public Map<String, List<Object>> getReferencingObjects(Group group, HttpServletRequest request) throws ApsSystemException {
    Map<String, List<Object>> references = new HashMap<String, List<Object>>();
    try {
        String[] defNames = ApsWebApplicationUtils.getWebApplicationContext(request).getBeanNamesForType(GroupUtilizer.class);
        for (int i = 0; i < defNames.length; i++) {
            Object service = null;
            try {
                service = ApsWebApplicationUtils.getWebApplicationContext(request).getBean(defNames[i]);
            } catch (Throwable t) {
                _logger.error("error in hasReferencingObjects", t);
                // ApsSystemUtils.logThrowable(t, this, "hasReferencingObjects");
                service = null;
            }
            if (service != null) {
                GroupUtilizer groupUtilizer = (GroupUtilizer) service;
                List<Object> utilizers = groupUtilizer.getGroupUtilizers(group.getName());
                if (utilizers != null && !utilizers.isEmpty()) {
                    // FIXME UNIFORMARE E STUDIARE CHIAVE IDONEA
                    references.put(groupUtilizer.getName() + "Utilizers", utilizers);
                }
            }
        }
    } catch (Throwable t) {
        throw new ApsSystemException("Errore in getReferencingObjects", t);
    }
    return references;
}
Also used : HashMap(java.util.HashMap) List(java.util.List) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) GroupUtilizer(com.agiletec.aps.system.services.group.GroupUtilizer)

Example 4 with GroupUtilizer

use of com.agiletec.aps.system.services.group.GroupUtilizer in project entando-core by entando.

the class TestUtilizer method testGetGroupsUtilizers.

public void testGetGroupsUtilizers() throws Throwable {
    String[] names = this.getApplicationContext().getBeanNamesForType(GroupUtilizer.class);
    assertTrue(names.length >= 4);
    for (int i = 0; i < names.length; i++) {
        GroupUtilizer service = (GroupUtilizer) this.getApplicationContext().getBean(names[i]);
        List utilizers = service.getGroupUtilizers("coach");
        if (names[i].equals("DataTypeManager")) {
            assertEquals(6, utilizers.size());
        }
    }
}
Also used : List(java.util.List) GroupUtilizer(com.agiletec.aps.system.services.group.GroupUtilizer)

Example 5 with GroupUtilizer

use of com.agiletec.aps.system.services.group.GroupUtilizer in project entando-core by entando.

the class DataObjectService method getGroupUtilizer.

@Override
public List<DataObjectDto> getGroupUtilizer(String groupCode) {
    try {
        DataObjectManager entityManager = (DataObjectManager) this.extractEntityManager(this.getManagerName());
        List<String> idList = ((GroupUtilizer<String>) entityManager).getGroupUtilizers(groupCode);
        return this.buildDtoList(idList, entityManager);
    } catch (ApsSystemException ex) {
        logger.error("Error loading dataobject references for group {}", groupCode, ex);
        throw new RestServerError("Error loading dataobject references for group", ex);
    }
}
Also used : RestServerError(org.entando.entando.aps.system.exception.RestServerError) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) GroupUtilizer(com.agiletec.aps.system.services.group.GroupUtilizer)

Aggregations

GroupUtilizer (com.agiletec.aps.system.services.group.GroupUtilizer)6 ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)4 List (java.util.List)3 RestServerError (org.entando.entando.aps.system.exception.RestServerError)3 HashMap (java.util.HashMap)2 ArrayList (java.util.ArrayList)1 UserDto (org.entando.entando.aps.system.services.user.model.UserDto)1