Search in sources :

Example 1 with UserSchoolDataIdentifier

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

the class WorkspaceRESTService method updateWorkspaceStudent.

@PUT
@Path("/workspaces/{WORKSPACEENTITYID}/students/{ID}")
@RESTPermit(handling = Handling.INLINE)
public Response updateWorkspaceStudent(@PathParam("WORKSPACEENTITYID") Long workspaceEntityId, @PathParam("ID") String workspaceStudentId, WorkspaceStudent workspaceStudent) {
    // Workspace
    WorkspaceEntity workspaceEntity = workspaceController.findWorkspaceEntityById(workspaceEntityId);
    if (workspaceEntity == null) {
        return Response.status(Status.BAD_REQUEST).build();
    }
    // Access check
    if (!sessionController.isLoggedIn()) {
        return Response.status(Status.UNAUTHORIZED).entity("Not logged in").build();
    }
    if (!sessionController.hasWorkspacePermission(MuikkuPermissions.MANAGE_WORKSPACE_MEMBERS, workspaceEntity)) {
        return Response.status(Status.FORBIDDEN).build();
    }
    // Workspace student and school data user
    SchoolDataIdentifier workspaceUserIdentifier = SchoolDataIdentifier.fromId(workspaceStudentId);
    if (workspaceUserIdentifier == null) {
        return Response.status(Status.BAD_REQUEST).entity("Invalid workspace user id").build();
    }
    SchoolDataIdentifier workspaceIdentifier = new SchoolDataIdentifier(workspaceEntity.getIdentifier(), workspaceEntity.getDataSource().getIdentifier());
    fi.otavanopisto.muikku.schooldata.entity.WorkspaceUser bridgeUser = workspaceController.findWorkspaceUser(workspaceIdentifier, workspaceUserIdentifier);
    if (bridgeUser == null) {
        return Response.status(Status.NOT_FOUND).entity("School data user not found").build();
    }
    WorkspaceUserEntity workspaceUserEntity = workspaceUserEntityController.findWorkspaceUserEntityByWorkspaceUserIdentifier(workspaceUserIdentifier);
    // Reindex user when switching between active and inactive
    if (workspaceStudent.getActive() != null && !workspaceStudent.getActive().equals(workspaceUserEntity.getActive())) {
        workspaceController.updateWorkspaceStudentActivity(bridgeUser, workspaceStudent.getActive());
        workspaceUserEntityController.updateActive(workspaceUserEntity, workspaceStudent.getActive());
        UserSchoolDataIdentifier userSchoolDataIdentifier = workspaceUserEntity.getUserSchoolDataIdentifier();
        userIndexer.indexUser(userSchoolDataIdentifier.getDataSource().getIdentifier(), userSchoolDataIdentifier.getIdentifier());
    }
    return Response.ok(workspaceStudent).build();
}
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) WorkspaceUser(fi.otavanopisto.muikku.schooldata.entity.WorkspaceUser) Path(javax.ws.rs.Path) RESTPermit(fi.otavanopisto.security.rest.RESTPermit) PUT(javax.ws.rs.PUT)

Example 2 with UserSchoolDataIdentifier

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

the class UserIndexer method indexUser.

public void indexUser(UserEntity userEntity) {
    schoolDataBridgeSessionController.startSystemSession();
    try {
        List<UserSchoolDataIdentifier> identifiers = userSchoolDataIdentifierController.listUserSchoolDataIdentifiersByUserEntity(userEntity);
        for (UserSchoolDataIdentifier schoolDataIdentifier : identifiers) {
            SchoolDataIdentifier identifier = new SchoolDataIdentifier(schoolDataIdentifier.getIdentifier(), schoolDataIdentifier.getDataSource().getIdentifier());
            indexUser(identifier);
        }
    } finally {
        schoolDataBridgeSessionController.endSystemSession();
    }
}
Also used : SchoolDataIdentifier(fi.otavanopisto.muikku.schooldata.SchoolDataIdentifier) UserSchoolDataIdentifier(fi.otavanopisto.muikku.model.users.UserSchoolDataIdentifier) UserSchoolDataIdentifier(fi.otavanopisto.muikku.model.users.UserSchoolDataIdentifier)

Example 3 with UserSchoolDataIdentifier

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

the class UserSchoolDataIdentifierDAO method findByDataSourceAndIdentifierAndArchived.

public UserSchoolDataIdentifier findByDataSourceAndIdentifierAndArchived(SchoolDataSource dataSource, String identifier, Boolean archived) {
    EntityManager entityManager = getEntityManager();
    CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
    CriteriaQuery<UserSchoolDataIdentifier> criteria = criteriaBuilder.createQuery(UserSchoolDataIdentifier.class);
    Root<UserSchoolDataIdentifier> root = criteria.from(UserSchoolDataIdentifier.class);
    criteria.select(root);
    criteria.where(criteriaBuilder.and(criteriaBuilder.equal(root.get(UserSchoolDataIdentifier_.dataSource), dataSource), criteriaBuilder.equal(root.get(UserSchoolDataIdentifier_.identifier), identifier), criteriaBuilder.equal(root.get(UserSchoolDataIdentifier_.archived), archived)));
    return getSingleResult(entityManager.createQuery(criteria));
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) UserSchoolDataIdentifier(fi.otavanopisto.muikku.model.users.UserSchoolDataIdentifier) EntityManager(javax.persistence.EntityManager)

Example 4 with UserSchoolDataIdentifier

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

the class UserSchoolDataIdentifierDAO method create.

public UserSchoolDataIdentifier create(SchoolDataSource dataSource, String identifier, UserEntity userEntity, Boolean archived) {
    UserSchoolDataIdentifier userSchoolDataIdentifier = new UserSchoolDataIdentifier();
    userSchoolDataIdentifier.setIdentifier(identifier);
    userSchoolDataIdentifier.setDataSource(dataSource);
    userSchoolDataIdentifier.setUserEntity(userEntity);
    userSchoolDataIdentifier.setArchived(archived);
    return persist(userSchoolDataIdentifier);
}
Also used : UserSchoolDataIdentifier(fi.otavanopisto.muikku.model.users.UserSchoolDataIdentifier)

Example 5 with UserSchoolDataIdentifier

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

the class UserSchoolDataIdentifierDAO method listByDataSourceAndArchived.

public List<UserSchoolDataIdentifier> listByDataSourceAndArchived(SchoolDataSource dataSource, Boolean archived) {
    EntityManager entityManager = getEntityManager();
    CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
    CriteriaQuery<UserSchoolDataIdentifier> criteria = criteriaBuilder.createQuery(UserSchoolDataIdentifier.class);
    Root<UserSchoolDataIdentifier> root = criteria.from(UserSchoolDataIdentifier.class);
    criteria.select(root);
    criteria.where(criteriaBuilder.and(criteriaBuilder.equal(root.get(UserSchoolDataIdentifier_.dataSource), dataSource), criteriaBuilder.equal(root.get(UserSchoolDataIdentifier_.archived), archived)));
    return entityManager.createQuery(criteria).getResultList();
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) UserSchoolDataIdentifier(fi.otavanopisto.muikku.model.users.UserSchoolDataIdentifier) EntityManager(javax.persistence.EntityManager)

Aggregations

UserSchoolDataIdentifier (fi.otavanopisto.muikku.model.users.UserSchoolDataIdentifier)37 WorkspaceUserEntity (fi.otavanopisto.muikku.model.workspace.WorkspaceUserEntity)14 SchoolDataIdentifier (fi.otavanopisto.muikku.schooldata.SchoolDataIdentifier)14 UserEntity (fi.otavanopisto.muikku.model.users.UserEntity)11 UserGroupUserEntity (fi.otavanopisto.muikku.model.users.UserGroupUserEntity)10 WorkspaceEntity (fi.otavanopisto.muikku.model.workspace.WorkspaceEntity)10 ArrayList (java.util.ArrayList)10 UserGroupEntity (fi.otavanopisto.muikku.model.users.UserGroupEntity)9 EntityManager (javax.persistence.EntityManager)7 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)7 RESTPermit (fi.otavanopisto.security.rest.RESTPermit)6 Path (javax.ws.rs.Path)6 FlagStudent (fi.otavanopisto.muikku.model.users.FlagStudent)5 User (fi.otavanopisto.muikku.schooldata.entity.User)5 WorkspaceRoleEntity (fi.otavanopisto.muikku.model.workspace.WorkspaceRoleEntity)4 Date (java.util.Date)4 HashMap (java.util.HashMap)4 CommunicatorMessageId (fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessageId)3 Workspace (fi.otavanopisto.muikku.schooldata.entity.Workspace)3 Flag (fi.otavanopisto.muikku.model.users.Flag)2