Search in sources :

Example 66 with SchoolDataIdentifier

use of fi.otavanopisto.muikku.schooldata.SchoolDataIdentifier in project muikku by otavanopisto.

the class DefaultSchoolDataWorkspaceListener method onSchoolDataWorkspaceUserUpdatedEvent.

public void onSchoolDataWorkspaceUserUpdatedEvent(@Observes SchoolDataWorkspaceUserUpdatedEvent event) {
    UserEntity userEntity = userEntityController.findUserEntityByDataSourceAndIdentifier(event.getUserDataSource(), event.getUserIdentifier());
    if (userEntity != null) {
        WorkspaceEntity workspaceEntity = workspaceEntityController.findWorkspaceByDataSourceAndIdentifier(event.getWorkspaceDataSource(), event.getWorkspaceIdentifier());
        if (workspaceEntity != null) {
            SchoolDataIdentifier workspaceUserIdentifier = new SchoolDataIdentifier(event.getIdentifier(), event.getDataSource());
            WorkspaceUserEntity workspaceUserEntity = workspaceUserEntityController.findWorkspaceUserEntityByWorkspaceUserIdentifierIncludeArchived(workspaceUserIdentifier);
            if (workspaceUserEntity != null) {
                String currentUserIdentifier = workspaceUserEntity.getUserSchoolDataIdentifier().getIdentifier();
                if (!StringUtils.equals(currentUserIdentifier, event.getUserIdentifier())) {
                    // WorkspaceUserEntity found, but it points to a new study program
                    UserSchoolDataIdentifier newUserIdentifier = userSchoolDataIdentifierController.findUserSchoolDataIdentifierByDataSourceAndIdentifier(event.getUserDataSource(), event.getUserIdentifier());
                    if (newUserIdentifier == null) {
                        logger.warning(String.format("Unable to update workspace user. UserSchoolDataIdentifier for %s/%s not found", event.getUserDataSource(), event.getUserIdentifier()));
                    } else {
                        WorkspaceUserEntity existingUser = workspaceUserEntityController.findWorkspaceUserEntityByWorkspaceAndUserSchoolDataIdentifierIncludeArchived(workspaceEntity, newUserIdentifier);
                        if (existingUser != null) {
                            if (!existingUser.getArchived().equals(workspaceUserEntity.getArchived())) {
                                if (existingUser.getArchived()) {
                                    workspaceUserEntityController.unarchiveWorkspaceUserEntity(existingUser);
                                } else {
                                    workspaceUserEntityController.archiveWorkspaceUserEntity(existingUser);
                                }
                            }
                            workspaceUserEntityController.updateIdentifier(existingUser, workspaceUserEntity.getIdentifier());
                            // #3308: If the new study program is active, reactivate the corresponding workspace student in Muikku
                            if (event.getIsActive() && !existingUser.getActive()) {
                                workspaceUserEntityController.updateActive(existingUser, event.getIsActive());
                            }
                            workspaceUserEntityController.archiveWorkspaceUserEntity(workspaceUserEntity);
                        } else {
                            workspaceUserEntityController.updateUserSchoolDataIdentifier(workspaceUserEntity, newUserIdentifier);
                            // #3308: If the new study program is active, reactivate the corresponding workspace student in Muikku
                            if (event.getIsActive() && !workspaceUserEntity.getActive()) {
                                workspaceUserEntityController.updateActive(workspaceUserEntity, event.getIsActive());
                            }
                        }
                    }
                } else {
                    WorkspaceRoleEntity workspaceRoleEntity = workspaceController.findWorkspaceRoleEntityByDataSourceAndIdentifier(event.getRoleDataSource(), event.getRoleIdentifier());
                    if (workspaceRoleEntity != null && !workspaceRoleEntity.getId().equals(workspaceUserEntity.getWorkspaceUserRole().getId())) {
                        workspaceUserEntityController.updateWorkspaceUserRole(workspaceUserEntity, workspaceRoleEntity);
                    }
                }
                if (!event.getIsActive() && workspaceUserEntity.getActive()) {
                    workspaceUserEntityController.updateActive(workspaceUserEntity, event.getIsActive());
                }
            }
        } else {
            logger.warning("could not update workspace user because workspace entity #" + event.getWorkspaceIdentifier() + '/' + event.getWorkspaceDataSource() + " could not be found");
        }
    } else {
        logger.warning("could not update workspace user because user entity #" + event.getUserIdentifier() + '/' + event.getUserDataSource() + " could not be found");
    }
}
Also used : SchoolDataIdentifier(fi.otavanopisto.muikku.schooldata.SchoolDataIdentifier) UserSchoolDataIdentifier(fi.otavanopisto.muikku.model.users.UserSchoolDataIdentifier) UserSchoolDataIdentifier(fi.otavanopisto.muikku.model.users.UserSchoolDataIdentifier) WorkspaceUserEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceUserEntity) WorkspaceEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceEntity) WorkspaceRoleEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceRoleEntity) WorkspaceUserEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceUserEntity) UserEntity(fi.otavanopisto.muikku.model.users.UserEntity)

Example 67 with SchoolDataIdentifier

use of fi.otavanopisto.muikku.schooldata.SchoolDataIdentifier in project muikku by otavanopisto.

the class FlagController method hasFlagPermission.

public boolean hasFlagPermission(Flag flag, SchoolDataIdentifier userIdentifier) {
    UserSchoolDataIdentifier owner = flag.getOwnerIdentifier();
    SchoolDataIdentifier ownerIdentfier = toIdentifier(owner);
    if (ownerIdentfier.equals(userIdentifier)) {
        return true;
    }
    UserSchoolDataIdentifier userSchoolDataIdentifier = userSchoolDataIdentifierController.findUserSchoolDataIdentifierBySchoolDataIdentifier(userIdentifier);
    if (userSchoolDataIdentifier == null) {
        logger.severe(String.format("Could not find school data user by identifier %s", userIdentifier));
        return false;
    }
    FlagShare flagShare = flagShareDAO.findByFlagAndUserIdentifier(flag, userSchoolDataIdentifier);
    if (flagShare != null) {
        return true;
    }
    return false;
}
Also used : SchoolDataIdentifier(fi.otavanopisto.muikku.schooldata.SchoolDataIdentifier) UserSchoolDataIdentifier(fi.otavanopisto.muikku.model.users.UserSchoolDataIdentifier) UserSchoolDataIdentifier(fi.otavanopisto.muikku.model.users.UserSchoolDataIdentifier) FlagShare(fi.otavanopisto.muikku.model.users.FlagShare)

Example 68 with SchoolDataIdentifier

use of fi.otavanopisto.muikku.schooldata.SchoolDataIdentifier in project muikku by otavanopisto.

the class WorkspaceUserEntityController method listWorkspaceEntitiesByUserEntity.

public List<WorkspaceEntity> listWorkspaceEntitiesByUserEntity(UserEntity userEntity) {
    SchoolDataIdentifier schoolDataIdentifier = toSchoolDataIdentifier(userEntity);
    List<WorkspaceEntity> result = new ArrayList<>();
    List<WorkspaceUserEntity> workspaceUserEntities = listWorkspaceUserEntitiesByUserIdentifier(schoolDataIdentifier);
    for (WorkspaceUserEntity workspaceUserEntity : workspaceUserEntities) {
        result.add(workspaceUserEntity.getWorkspaceEntity());
    }
    return result;
}
Also used : SchoolDataIdentifier(fi.otavanopisto.muikku.schooldata.SchoolDataIdentifier) UserSchoolDataIdentifier(fi.otavanopisto.muikku.model.users.UserSchoolDataIdentifier) WorkspaceUserEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceUserEntity) WorkspaceEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceEntity) ArrayList(java.util.ArrayList)

Example 69 with SchoolDataIdentifier

use of fi.otavanopisto.muikku.schooldata.SchoolDataIdentifier in project muikku by otavanopisto.

the class WorkspaceUserEntityController method listActiveWorkspaceEntitiesByUserEntity.

public List<WorkspaceEntity> listActiveWorkspaceEntitiesByUserEntity(UserEntity userEntity) {
    SchoolDataIdentifier schoolDataIdentifier = toSchoolDataIdentifier(userEntity);
    List<WorkspaceEntity> result = new ArrayList<>();
    List<WorkspaceUserEntity> workspaceUserEntities = listActiveWorkspaceUserEntitiesByUserIdentifier(schoolDataIdentifier);
    for (WorkspaceUserEntity workspaceUserEntity : workspaceUserEntities) {
        result.add(workspaceUserEntity.getWorkspaceEntity());
    }
    return result;
}
Also used : SchoolDataIdentifier(fi.otavanopisto.muikku.schooldata.SchoolDataIdentifier) UserSchoolDataIdentifier(fi.otavanopisto.muikku.model.users.UserSchoolDataIdentifier) WorkspaceUserEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceUserEntity) WorkspaceEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceEntity) ArrayList(java.util.ArrayList)

Example 70 with SchoolDataIdentifier

use of fi.otavanopisto.muikku.schooldata.SchoolDataIdentifier in project muikku by otavanopisto.

the class IndexEntityProcessor method process.

public Map<String, Object> process(Object entity) throws IllegalArgumentException, IllegalAccessException, IntrospectionException, InvocationTargetException, IndexIdMissingException {
    if (isIndexable(entity)) {
        String id = getEnitityId(entity);
        if (StringUtils.isBlank(id)) {
            throw new IndexIdMissingException("Indexable object is missing an id.");
        }
        Map<String, Object> indexObject = new HashMap<String, Object>();
        indexObject.put("id", id);
        for (Method indexableGetter : getIndexableGetters(entity)) {
            String fieldName = StringUtils.uncapitalize(indexableGetter.getName().substring(3));
            IndexField indexField = findIndexField(indexableGetter);
            if (indexField != null) {
                if (indexField.skip()) {
                    continue;
                }
                String name = indexField.name();
                if (StringUtils.isNotBlank(name)) {
                    fieldName = name;
                }
            }
            Object fieldValue = indexableGetter.invoke(entity);
            if (indexField != null && indexField.toId()) {
                if (fieldValue != null) {
                    if (fieldValue instanceof Collection) {
                        Collection<?> collection = (Collection<?>) fieldValue;
                        Set<String> ids = new HashSet<String>();
                        for (Object o : collection) {
                            if (o != null) {
                                if (o instanceof SchoolDataIdentifier)
                                    ids.add(((SchoolDataIdentifier) o).toId());
                                else {
                                    logger.severe(String.format("@Indexable toId for Collection must be Collection<SchoolDataIdentifier> but was Collection<%s>", o.getClass().getName()));
                                }
                            }
                        }
                        fieldValue = ids;
                    } else if (fieldValue instanceof SchoolDataIdentifier) {
                        fieldValue = ((SchoolDataIdentifier) fieldValue).toId();
                    } else {
                        logger.severe(String.format("@Indexable toId must be SchoolDataIdentifier but was %s", fieldValue.getClass().getName()));
                    }
                }
            }
            indexObject.put(fieldName, fieldValue);
        }
        return indexObject;
    }
    return null;
}
Also used : SchoolDataIdentifier(fi.otavanopisto.muikku.schooldata.SchoolDataIdentifier) HashMap(java.util.HashMap) Collection(java.util.Collection) Method(java.lang.reflect.Method) IndexField(fi.otavanopisto.muikku.search.annotations.IndexField) HashSet(java.util.HashSet)

Aggregations

SchoolDataIdentifier (fi.otavanopisto.muikku.schooldata.SchoolDataIdentifier)130 Path (javax.ws.rs.Path)63 WorkspaceUserEntity (fi.otavanopisto.muikku.model.workspace.WorkspaceUserEntity)59 RESTPermit (fi.otavanopisto.security.rest.RESTPermit)58 UserEntity (fi.otavanopisto.muikku.model.users.UserEntity)53 UserSchoolDataIdentifier (fi.otavanopisto.muikku.model.users.UserSchoolDataIdentifier)50 WorkspaceEntity (fi.otavanopisto.muikku.model.workspace.WorkspaceEntity)48 ArrayList (java.util.ArrayList)38 GET (javax.ws.rs.GET)36 User (fi.otavanopisto.muikku.schooldata.entity.User)30 HashMap (java.util.HashMap)19 Workspace (fi.otavanopisto.muikku.schooldata.entity.Workspace)13 SearchResult (fi.otavanopisto.muikku.search.SearchResult)13 WorkspaceUser (fi.otavanopisto.muikku.schooldata.entity.WorkspaceUser)12 Date (java.util.Date)11 POST (javax.ws.rs.POST)11 GradingScaleItem (fi.otavanopisto.muikku.schooldata.entity.GradingScaleItem)10 WorkspaceAssessment (fi.otavanopisto.muikku.schooldata.entity.WorkspaceAssessment)10 HashSet (java.util.HashSet)9 PUT (javax.ws.rs.PUT)9