Search in sources :

Example 16 with UserGroupEntity

use of fi.otavanopisto.muikku.model.users.UserGroupEntity in project muikku by otavanopisto.

the class PyramusUpdater method updateStudyProgramme.

public void updateStudyProgramme(Long pyramusId) {
    StudyProgramme studentGroup = pyramusClient.get().get(String.format("/students/studyProgrammes/%d", pyramusId), StudyProgramme.class);
    String identifier = identifierMapper.getStudyProgrammeIdentifier(pyramusId);
    UserGroupEntity userGroupEntity = userGroupEntityController.findUserGroupEntityByDataSourceAndIdentifier(SchoolDataPyramusPluginDescriptor.SCHOOL_DATA_SOURCE, identifier, true);
    if (studentGroup == null) {
        if (userGroupEntity != null)
            fireUserGroupRemoved(identifier);
    } else {
        if (userGroupEntity == null) {
            fireUserGroupDiscovered(identifier);
        } else {
            fireUserGroupUpdated(identifier);
        }
    }
}
Also used : StudyProgramme(fi.otavanopisto.pyramus.rest.model.StudyProgramme) UserGroupEntity(fi.otavanopisto.muikku.model.users.UserGroupEntity)

Example 17 with UserGroupEntity

use of fi.otavanopisto.muikku.model.users.UserGroupEntity in project muikku by otavanopisto.

the class DefaultSchoolDataUserGroupListener method onSchoolDataUserGroupUserUpdatedEvent.

public void onSchoolDataUserGroupUserUpdatedEvent(@Observes SchoolDataUserGroupUserUpdatedEvent event) {
    UserGroupUserEntity userGroupUserEntity = userGroupEntityController.findUserGroupUserEntityByDataSourceAndIdentifier(event.getDataSource(), event.getIdentifier());
    UserGroupEntity userGroupEntity = userGroupEntityController.findUserGroupEntityByDataSourceAndIdentifier(event.getUserGroupDataSource(), event.getUserGroupIdentifier());
    UserSchoolDataIdentifier userSchoolDataIdentifier = userSchoolDataIdentifierController.findUserSchoolDataIdentifierByDataSourceAndIdentifier(event.getUserDataSource(), event.getUserIdentifier());
    if ((userGroupUserEntity != null) && (userGroupEntity != null) && (userSchoolDataIdentifier != null)) {
        userGroupEntityController.updateUserGroupEntity(userGroupUserEntity, userGroupEntity);
        userGroupEntityController.updateUserSchoolDataIdentifier(userGroupUserEntity, userSchoolDataIdentifier);
    } else
        logger.warning(String.format("Couldn't find userGroupUserEntity (%s) or userGroupEntity (%s)", event.getIdentifier(), event.getUserGroupIdentifier()));
}
Also used : UserSchoolDataIdentifier(fi.otavanopisto.muikku.model.users.UserSchoolDataIdentifier) UserGroupUserEntity(fi.otavanopisto.muikku.model.users.UserGroupUserEntity) UserGroupEntity(fi.otavanopisto.muikku.model.users.UserGroupEntity)

Example 18 with UserGroupEntity

use of fi.otavanopisto.muikku.model.users.UserGroupEntity in project muikku by otavanopisto.

the class DefaultSchoolDataUserGroupListener method onSchoolDataUserGroupUserDiscoveredEvent.

public void onSchoolDataUserGroupUserDiscoveredEvent(@Observes SchoolDataUserGroupUserDiscoveredEvent event) {
    String discoverId = getUserGroupUserDiscoveryId(event.getDataSource(), event.getIdentifier());
    if (discoveredUserGroupUsers.containsKey(discoverId)) {
        event.setDiscoveredUserGroupUserEntityId(discoveredUserGroupUsers.get(discoverId));
        return;
    }
    UserGroupEntity userGroupEntity = userGroupEntityController.findUserGroupEntityByDataSourceAndIdentifier(event.getUserGroupDataSource(), event.getUserGroupIdentifier(), true);
    if (userGroupEntity != null) {
        if (!userGroupEntity.getArchived()) {
            UserGroupUserEntity userGroupUserEntity = userGroupEntityController.findUserGroupUserEntityByDataSourceAndIdentifier(event.getDataSource(), event.getIdentifier(), true);
            if ((userGroupUserEntity == null) || (userGroupUserEntity.getArchived())) {
                UserSchoolDataIdentifier userSchoolDataIdentifier = userSchoolDataIdentifierController.findUserSchoolDataIdentifierByDataSourceAndIdentifier(event.getUserDataSource(), event.getUserIdentifier());
                if (userSchoolDataIdentifier != null) {
                    if (userGroupUserEntity == null) {
                        userGroupUserEntity = userGroupEntityController.createUserGroupUserEntity(userGroupEntity, event.getDataSource(), event.getIdentifier(), userSchoolDataIdentifier);
                    } else {
                        userGroupEntityController.unarchiveUserGroupUserEntity(userGroupUserEntity);
                        userGroupEntityController.updateUserSchoolDataIdentifier(userGroupUserEntity, userSchoolDataIdentifier);
                    }
                    discoveredUserGroupUsers.put(discoverId, userGroupUserEntity.getId());
                    event.setDiscoveredUserGroupUserEntityId(userGroupUserEntity.getId());
                } else {
                    logger.warning("could not add group user because UserSchoolDataIdentifier for " + event.getUserIdentifier() + "/" + event.getUserDataSource() + " wasn't found");
                }
            } else {
                logger.warning("UserGroupUserEntity for " + event.getIdentifier() + "/" + event.getDataSource() + " already exists");
            }
        }
    } else {
        logger.warning("could not init user group user because usergroup #" + event.getUserGroupIdentifier() + '/' + event.getUserGroupDataSource() + " could not be found");
    }
}
Also used : UserSchoolDataIdentifier(fi.otavanopisto.muikku.model.users.UserSchoolDataIdentifier) UserGroupUserEntity(fi.otavanopisto.muikku.model.users.UserGroupUserEntity) UserGroupEntity(fi.otavanopisto.muikku.model.users.UserGroupEntity)

Example 19 with UserGroupEntity

use of fi.otavanopisto.muikku.model.users.UserGroupEntity in project muikku by otavanopisto.

the class DefaultSchoolDataUserGroupListener method onSchoolDataUserGroupDiscoveredEvent.

public void onSchoolDataUserGroupDiscoveredEvent(@Observes SchoolDataUserGroupDiscoveredEvent event) {
    String discoverId = getUserGroupDiscoveryId(event.getDataSource(), event.getIdentifier());
    if (discoveredUserGroups.containsKey(discoverId)) {
        event.setDiscoveredUserGroupEntityId(discoveredUserGroups.get(discoverId));
        return;
    }
    UserGroupEntity userGroupEntity = userGroupEntityController.findUserGroupEntityByDataSourceAndIdentifier(event.getDataSource(), event.getIdentifier(), true);
    if ((userGroupEntity == null) || (userGroupEntity.getArchived())) {
        if (userGroupEntity == null) {
            userGroupEntity = userGroupEntityController.createUserGroupEntity(event.getDataSource(), event.getIdentifier());
        } else {
            userGroupEntityController.unarchiveUserGroupEntity(userGroupEntity);
        }
        discoveredUserGroups.put(discoverId, userGroupEntity.getId());
        event.setDiscoveredUserGroupEntityId(userGroupEntity.getId());
    } else {
        logger.warning("UserGroupEntity for " + event.getIdentifier() + "/" + event.getDataSource() + " already exists");
    }
}
Also used : UserGroupEntity(fi.otavanopisto.muikku.model.users.UserGroupEntity)

Example 20 with UserGroupEntity

use of fi.otavanopisto.muikku.model.users.UserGroupEntity in project muikku by otavanopisto.

the class WorkspacePermissionsManagementBackingBean method init.

@RequestAction
public String init() {
    String urlName = getWorkspaceUrlName();
    if (StringUtils.isBlank(urlName)) {
        return NavigationRules.NOT_FOUND;
    }
    WorkspaceEntity workspaceEntity = workspaceController.findWorkspaceEntityByUrlName(urlName);
    if (workspaceEntity == null) {
        return NavigationRules.NOT_FOUND;
    }
    if (!sessionController.hasWorkspacePermission(MuikkuPermissions.WORKSPACE_MANAGE_PERMISSIONS, workspaceEntity)) {
        return NavigationRules.NOT_FOUND;
    }
    workspaceEntityId = workspaceEntity.getId();
    workspaceBackingBean.setWorkspaceUrlName(urlName);
    workspaceName = workspaceBackingBean.getWorkspaceName();
    userGroupBeans = new ArrayList<WorkspacePermissionsManagementBackingBean.UserGroupBean>();
    permissions = new ArrayList<Permission>();
    // TODO: atm we only support the sign up permission
    Permission permission = permissionController.findByName(MuikkuPermissions.WORKSPACE_SIGNUP);
    permissions.add(permission);
    List<UserGroupEntity> userGroupEntities;
    String permissionGroupIds = pluginSettingsController.getPluginSetting("workspace", "permission-group-ids");
    if (permissionGroupIds == null) {
        userGroupEntities = userGroupEntityController.listUserGroupEntities();
    } else {
        userGroupEntities = new ArrayList<UserGroupEntity>();
        String[] idArray = permissionGroupIds.split(",");
        for (int i = 0; i < idArray.length; i++) {
            Long groupId = NumberUtils.createLong(idArray[i]);
            if (groupId != null) {
                UserGroupEntity userGroupEntity = userGroupEntityController.findUserGroupEntityById(groupId);
                if (userGroupEntity == null) {
                    logger.warning(String.format("Missing group %d in plugin setting workspace.permission-group-ids", groupId));
                } else {
                    userGroupEntities.add(userGroupEntity);
                }
            } else {
                logger.warning(String.format("Malformatted plugin setting workspace.permission-group-ids %s", permissionGroupIds));
            }
        }
    }
    for (UserGroupEntity userGroupEntity : userGroupEntities) {
        UserGroup userGroup = userGroupController.findUserGroup(userGroupEntity);
        userGroupBeans.add(new UserGroupBean(userGroupEntity.getId(), userGroup.getName()));
    }
    Collections.sort(userGroupBeans, new Comparator<UserGroupBean>() {

        @Override
        public int compare(UserGroupBean o1, UserGroupBean o2) {
            return o1.getName().compareTo(o2.getName());
        }
    });
    return null;
}
Also used : UserGroupEntity(fi.otavanopisto.muikku.model.users.UserGroupEntity) UserGroup(fi.otavanopisto.muikku.schooldata.entity.UserGroup) WorkspaceEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceEntity) Permission(fi.otavanopisto.muikku.model.security.Permission) RequestAction(org.ocpsoft.rewrite.annotation.RequestAction)

Aggregations

UserGroupEntity (fi.otavanopisto.muikku.model.users.UserGroupEntity)40 WorkspaceEntity (fi.otavanopisto.muikku.model.workspace.WorkspaceEntity)14 UserEntity (fi.otavanopisto.muikku.model.users.UserEntity)12 UserGroupUserEntity (fi.otavanopisto.muikku.model.users.UserGroupUserEntity)12 Path (javax.ws.rs.Path)12 ArrayList (java.util.ArrayList)11 UserSchoolDataIdentifier (fi.otavanopisto.muikku.model.users.UserSchoolDataIdentifier)10 RESTPermit (fi.otavanopisto.security.rest.RESTPermit)9 EntityManager (javax.persistence.EntityManager)8 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)8 WorkspaceUserEntity (fi.otavanopisto.muikku.model.workspace.WorkspaceUserEntity)7 UserGroup (fi.otavanopisto.muikku.schooldata.entity.UserGroup)6 SchoolDataIdentifier (fi.otavanopisto.muikku.schooldata.SchoolDataIdentifier)5 HashMap (java.util.HashMap)5 POST (javax.ws.rs.POST)5 Permission (fi.otavanopisto.muikku.model.security.Permission)4 Announcement (fi.otavanopisto.muikku.plugins.announcer.model.Announcement)4 Tag (fi.otavanopisto.muikku.model.base.Tag)3 EnvironmentRoleArchetype (fi.otavanopisto.muikku.model.users.EnvironmentRoleArchetype)3 CommunicatorMessage (fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessage)3