Search in sources :

Example 1 with Describable

use of ubic.gemma.model.common.Describable in project Gemma by PavlidisLab.

the class SecurityControllerImpl method securables2VOs.

/**
 * @param securables   securables
 * @param currentGroup A specific group that we're focusing on. Can be null
 * @return security info VOs
 */
private <T extends Securable> Collection<SecurityInfoValueObject> securables2VOs(Collection<T> securables, String currentGroup) {
    Collection<SecurityInfoValueObject> result = new HashSet<>();
    if (securables.isEmpty()) {
        return result;
    }
    /*
         * Fast computations out-of-loop
         */
    Collection<String> groupsForCurrentUser = this.getGroupsForCurrentUser();
    Map<T, Boolean> privacy = securityService.arePrivate(securables);
    Map<T, Boolean> sharedness = securityService.areShared(securables);
    Map<T, Sid> owners = securityService.getOwners(securables);
    Map<T, Collection<String>> groupsReadableBy = securityService.getGroupsReadableBy(securables);
    Map<T, Collection<String>> groupsEditableBy = securityService.getGroupsEditableBy(securables);
    // int i = 0; // TESTING
    for (Securable s : securables) {
        Collection<String> groupsThatCanRead = groupsReadableBy.get(s);
        Collection<String> groupsThatCanWrite = groupsEditableBy.get(s);
        SecurityInfoValueObject vo = new SecurityInfoValueObject(s);
        vo.setCurrentGroup(currentGroup);
        vo.setAvailableGroups(groupsForCurrentUser);
        vo.setPubliclyReadable(!privacy.get(s));
        vo.setShared(sharedness.get(s));
        vo.setOwner(new SidValueObject(owners.get(s)));
        // FIXME this does not seem to be used in the UI and it fixes issue #41: https://github.com/ppavlidis/Gemma/issues/41
        // securityService.isOwnedByCurrentUser( s ) );
        vo.setCurrentUserOwns(false);
        vo.setCurrentUserCanwrite(securityService.isEditable(s));
        vo.setGroupsThatCanRead(groupsThatCanRead == null ? new HashSet<String>() : groupsThatCanRead);
        vo.setGroupsThatCanWrite(groupsThatCanWrite == null ? new HashSet<String>() : groupsThatCanWrite);
        vo.setEntityClazz(s.getClass().getName());
        if (currentGroup != null) {
            vo.setCurrentGroupCanRead(groupsThatCanRead != null && groupsThatCanRead.contains(currentGroup));
            vo.setCurrentGroupCanWrite(groupsThatCanWrite != null && groupsThatCanWrite.contains(currentGroup));
        }
        if (ExpressionExperiment.class.isAssignableFrom(s.getClass())) {
            vo.setEntityShortName(((ExpressionExperiment) s).getShortName());
            vo.setEntityName(((ExpressionExperiment) s).getName());
        } else if (Describable.class.isAssignableFrom(s.getClass())) {
            vo.setEntityShortName(((Describable) s).getName());
            vo.setEntityName(((Describable) s).getDescription());
        }
        result.add(vo);
    // if ( ++i > 10 ) break; // TESTING
    }
    return result;
}
Also used : Securable(gemma.gsec.model.Securable) Describable(ubic.gemma.model.common.Describable) Sid(org.springframework.security.acls.model.Sid)

Aggregations

Securable (gemma.gsec.model.Securable)1 Sid (org.springframework.security.acls.model.Sid)1 Describable (ubic.gemma.model.common.Describable)1