Search in sources :

Example 1 with ACResourceInfo

use of org.olat.resource.accesscontrol.model.ACResourceInfo in project OpenOLAT by OpenOLAT.

the class ACFrontendManager method getResourceInfos.

@Override
public List<ACResourceInfo> getResourceInfos(List<OLATResource> resources) {
    if (resources == null || resources.isEmpty()) {
        return Collections.emptyList();
    }
    List<OLATResource> groupResources = new ArrayList<OLATResource>(resources.size());
    List<OLATResource> repositoryResources = new ArrayList<OLATResource>(resources.size());
    for (OLATResource resource : resources) {
        String resourceType = resource.getResourceableTypeName();
        if ("BusinessGroup".equals(resourceType)) {
            groupResources.add(resource);
        } else {
            repositoryResources.add(resource);
        }
    }
    List<ACResourceInfo> resourceInfos = new ArrayList<ACResourceInfo>(resources.size());
    if (!groupResources.isEmpty()) {
        List<Long> groupKeys = new ArrayList<Long>(groupResources.size());
        Map<Long, OLATResource> groupMapKeys = new HashMap<Long, OLATResource>(groupResources.size() * 2 + 1);
        for (OLATResource groupResource : groupResources) {
            groupKeys.add(groupResource.getResourceableId());
        }
        List<BusinessGroup> groups = businessGroupService.loadBusinessGroups(groupKeys);
        for (BusinessGroup group : groups) {
            ACResourceInfoImpl info = new ACResourceInfoImpl();
            info.setResource(groupMapKeys.get(group.getKey()));
            info.setName(group.getName());
            info.setDescription(group.getDescription());
            info.setResource(group.getResource());
            resourceInfos.add(info);
        }
    }
    if (!repositoryResources.isEmpty()) {
        List<RepositoryEntryShort> repoEntries = repositoryManager.loadRepositoryEntryShorts(repositoryResources);
        for (RepositoryEntryShort repoEntry : repoEntries) {
            ACResourceInfoImpl info = new ACResourceInfoImpl();
            info.setName(repoEntry.getDisplayname());
            info.setDescription(((RepositoryEntryShortImpl) repoEntry).getDescription());
            info.setResource(((RepositoryEntryShortImpl) repoEntry).getOlatResource());
            resourceInfos.add(info);
        }
    }
    return resourceInfos;
}
Also used : ACResourceInfoImpl(org.olat.resource.accesscontrol.model.ACResourceInfoImpl) RepositoryEntryShort(org.olat.repository.RepositoryEntryShort) HashMap(java.util.HashMap) BusinessGroup(org.olat.group.BusinessGroup) ACResourceInfo(org.olat.resource.accesscontrol.model.ACResourceInfo) ArrayList(java.util.ArrayList) OLATResource(org.olat.resource.OLATResource)

Example 2 with ACResourceInfo

use of org.olat.resource.accesscontrol.model.ACResourceInfo in project openolat by klemens.

the class ACFrontendManager method getResourceInfos.

@Override
public List<ACResourceInfo> getResourceInfos(List<OLATResource> resources) {
    if (resources == null || resources.isEmpty()) {
        return Collections.emptyList();
    }
    List<OLATResource> groupResources = new ArrayList<OLATResource>(resources.size());
    List<OLATResource> repositoryResources = new ArrayList<OLATResource>(resources.size());
    for (OLATResource resource : resources) {
        String resourceType = resource.getResourceableTypeName();
        if ("BusinessGroup".equals(resourceType)) {
            groupResources.add(resource);
        } else {
            repositoryResources.add(resource);
        }
    }
    List<ACResourceInfo> resourceInfos = new ArrayList<ACResourceInfo>(resources.size());
    if (!groupResources.isEmpty()) {
        List<Long> groupKeys = new ArrayList<Long>(groupResources.size());
        Map<Long, OLATResource> groupMapKeys = new HashMap<Long, OLATResource>(groupResources.size() * 2 + 1);
        for (OLATResource groupResource : groupResources) {
            groupKeys.add(groupResource.getResourceableId());
        }
        List<BusinessGroup> groups = businessGroupService.loadBusinessGroups(groupKeys);
        for (BusinessGroup group : groups) {
            ACResourceInfoImpl info = new ACResourceInfoImpl();
            info.setResource(groupMapKeys.get(group.getKey()));
            info.setName(group.getName());
            info.setDescription(group.getDescription());
            info.setResource(group.getResource());
            resourceInfos.add(info);
        }
    }
    if (!repositoryResources.isEmpty()) {
        List<RepositoryEntryShort> repoEntries = repositoryManager.loadRepositoryEntryShorts(repositoryResources);
        for (RepositoryEntryShort repoEntry : repoEntries) {
            ACResourceInfoImpl info = new ACResourceInfoImpl();
            info.setName(repoEntry.getDisplayname());
            info.setDescription(((RepositoryEntryShortImpl) repoEntry).getDescription());
            info.setResource(((RepositoryEntryShortImpl) repoEntry).getOlatResource());
            resourceInfos.add(info);
        }
    }
    return resourceInfos;
}
Also used : ACResourceInfoImpl(org.olat.resource.accesscontrol.model.ACResourceInfoImpl) RepositoryEntryShort(org.olat.repository.RepositoryEntryShort) HashMap(java.util.HashMap) BusinessGroup(org.olat.group.BusinessGroup) ACResourceInfo(org.olat.resource.accesscontrol.model.ACResourceInfo) ArrayList(java.util.ArrayList) OLATResource(org.olat.resource.OLATResource)

Aggregations

ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 BusinessGroup (org.olat.group.BusinessGroup)2 RepositoryEntryShort (org.olat.repository.RepositoryEntryShort)2 OLATResource (org.olat.resource.OLATResource)2 ACResourceInfo (org.olat.resource.accesscontrol.model.ACResourceInfo)2 ACResourceInfoImpl (org.olat.resource.accesscontrol.model.ACResourceInfoImpl)2