Search in sources :

Example 31 with WorkspaceUserEntity

use of fi.otavanopisto.muikku.model.workspace.WorkspaceUserEntity in project muikku by otavanopisto.

the class AssessmentRequestController method setCommunicatorMessageId.

public void setCommunicatorMessageId(WorkspaceAssessmentRequest assessmentRequest, CommunicatorMessageId communicatorMessageId) {
    SchoolDataIdentifier workspaceUserIdentifier = new SchoolDataIdentifier(assessmentRequest.getWorkspaceUserIdentifier(), assessmentRequest.getWorkspaceUserSchoolDataSource());
    WorkspaceUserEntity workspaceUserEntity = workspaceUserEntityController.findWorkspaceUserEntityByWorkspaceUserIdentifier(workspaceUserIdentifier);
    AssessmentRequestMessageId requestMessageId = assessmentRequestMessageIdDAO.findByWorkspaceUser(workspaceUserEntity);
    if (requestMessageId == null)
        assessmentRequestMessageIdDAO.create(workspaceUserEntity, communicatorMessageId);
    else
        assessmentRequestMessageIdDAO.updateMessageId(requestMessageId, communicatorMessageId);
}
Also used : SchoolDataIdentifier(fi.otavanopisto.muikku.schooldata.SchoolDataIdentifier) WorkspaceUserEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceUserEntity)

Example 32 with WorkspaceUserEntity

use of fi.otavanopisto.muikku.model.workspace.WorkspaceUserEntity in project muikku by otavanopisto.

the class AssessmentRequestRESTService method createAssessmentRequest.

@POST
@Path("/workspace/{WORKSPACEENTITYID}/assessmentRequests")
@RESTPermitUnimplemented
public Response createAssessmentRequest(@PathParam("WORKSPACEENTITYID") Long workspaceEntityId, AssessmentRequestRESTModel newAssessmentRequest) {
    WorkspaceEntity workspaceEntity = workspaceController.findWorkspaceEntityById(workspaceEntityId);
    if (workspaceEntity == null) {
        return Response.status(Status.BAD_REQUEST).build();
    }
    if (!sessionController.isLoggedIn()) {
        return Response.status(Status.UNAUTHORIZED).build();
    }
    WorkspaceUserEntity workspaceUserEntity = workspaceUserEntityController.findActiveWorkspaceUserByWorkspaceEntityAndUserIdentifier(workspaceEntity, sessionController.getLoggedUser());
    try {
        WorkspaceAssessmentRequest assessmentRequest = assessmentRequestController.createWorkspaceAssessmentRequest(workspaceUserEntity, newAssessmentRequest.getRequestText());
        communicatorAssessmentRequestController.sendAssessmentRequestMessage(assessmentRequest);
        return Response.ok(restModel(assessmentRequest)).build();
    } catch (Exception e) {
        logger.log(Level.SEVERE, "Couldn't create workspace assessment request.", e);
        return Response.status(Status.INTERNAL_SERVER_ERROR).build();
    }
}
Also used : WorkspaceUserEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceUserEntity) WorkspaceEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceEntity) WorkspaceAssessmentRequest(fi.otavanopisto.muikku.schooldata.entity.WorkspaceAssessmentRequest) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) RESTPermitUnimplemented(fi.otavanopisto.muikku.rest.RESTPermitUnimplemented)

Example 33 with WorkspaceUserEntity

use of fi.otavanopisto.muikku.model.workspace.WorkspaceUserEntity in project muikku by otavanopisto.

the class AssessmentRequestRESTService method restModel.

private AssessmentRequestRESTModel restModel(WorkspaceAssessmentRequest workspaceAssessmentRequest) {
    SchoolDataIdentifier workspaceUserIdentifier = new SchoolDataIdentifier(workspaceAssessmentRequest.getWorkspaceUserIdentifier(), workspaceAssessmentRequest.getWorkspaceUserSchoolDataSource());
    WorkspaceUserEntity workspaceUserEntity = workspaceUserEntityController.findWorkspaceUserEntityByWorkspaceUserIdentifier(workspaceUserIdentifier);
    if (workspaceUserEntity != null) {
        SchoolDataIdentifier userIdentifier = new SchoolDataIdentifier(workspaceUserEntity.getUserSchoolDataIdentifier().getIdentifier(), workspaceUserEntity.getUserSchoolDataIdentifier().getDataSource().getIdentifier());
        SchoolDataIdentifier workspaceAssessmentRequestIdentifier = new SchoolDataIdentifier(workspaceAssessmentRequest.getIdentifier(), workspaceAssessmentRequest.getSchoolDataSource());
        WorkspaceEntity workspaceEntity = workspaceUserEntity.getWorkspaceEntity();
        UserEntity userEntity = workspaceUserEntity.getUserSchoolDataIdentifier().getUserEntity();
        AssessmentRequestRESTModel restAssessmentRequest = new AssessmentRequestRESTModel(workspaceAssessmentRequestIdentifier.toId(), userIdentifier.toId(), workspaceUserIdentifier.toId(), workspaceEntity.getId(), userEntity.getId(), workspaceAssessmentRequest.getRequestText(), workspaceAssessmentRequest.getDate());
        return restAssessmentRequest;
    }
    return null;
}
Also used : SchoolDataIdentifier(fi.otavanopisto.muikku.schooldata.SchoolDataIdentifier) WorkspaceUserEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceUserEntity) WorkspaceEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceEntity) AssessmentRequestRESTModel(fi.otavanopisto.muikku.plugins.assessmentrequest.rest.model.AssessmentRequestRESTModel) WorkspaceUserEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceUserEntity) UserEntity(fi.otavanopisto.muikku.model.users.UserEntity)

Example 34 with WorkspaceUserEntity

use of fi.otavanopisto.muikku.model.workspace.WorkspaceUserEntity in project muikku by otavanopisto.

the class AssessmentRequestRESTService method listAssessmentRequestsByWorkspaceId.

@GET
@Path("/workspace/{WORKSPACEENTITYID}/assessmentRequests")
@RESTPermit(handling = Handling.INLINE)
public Response listAssessmentRequestsByWorkspaceId(@PathParam("WORKSPACEENTITYID") Long workspaceEntityId, @QueryParam("studentIdentifier") String studentId) {
    WorkspaceEntity workspaceEntity = workspaceController.findWorkspaceEntityById(workspaceEntityId);
    if (workspaceEntity == null) {
        return Response.status(Status.NOT_FOUND).entity("Workspace not found").build();
    }
    SchoolDataIdentifier studentIdentifier = SchoolDataIdentifier.fromId(studentId);
    if (studentIdentifier != null) {
        if (!studentIdentifier.equals(sessionController.getLoggedUser())) {
            if (!sessionController.hasPermission(AssessmentRequestPermissions.LIST_WORKSPACE_ASSESSMENTREQUESTS, workspaceEntity)) {
                return Response.status(Status.FORBIDDEN).build();
            }
        }
        WorkspaceUserEntity workspaceUserEntity = workspaceUserEntityController.findWorkspaceUserEntityByWorkspaceAndUserIdentifier(workspaceEntity, studentIdentifier);
        if (workspaceUserEntity == null) {
            return Response.status(Status.BAD_REQUEST).entity("WorkspaceUserEntity could not find").build();
        }
        return Response.ok(restModel(assessmentRequestController.listByWorkspaceUser(workspaceUserEntity))).build();
    } else {
        if (!sessionController.hasPermission(AssessmentRequestPermissions.LIST_WORKSPACE_ASSESSMENTREQUESTS, workspaceEntity)) {
            return Response.status(Status.FORBIDDEN).build();
        }
        List<WorkspaceAssessmentRequest> assessmentRequests = assessmentRequestController.listByWorkspace(workspaceEntity);
        return Response.ok(restModel(assessmentRequests)).build();
    }
}
Also used : SchoolDataIdentifier(fi.otavanopisto.muikku.schooldata.SchoolDataIdentifier) WorkspaceUserEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceUserEntity) WorkspaceEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceEntity) WorkspaceAssessmentRequest(fi.otavanopisto.muikku.schooldata.entity.WorkspaceAssessmentRequest) Path(javax.ws.rs.Path) RESTPermit(fi.otavanopisto.security.rest.RESTPermit) GET(javax.ws.rs.GET)

Example 35 with WorkspaceUserEntity

use of fi.otavanopisto.muikku.model.workspace.WorkspaceUserEntity in project muikku by otavanopisto.

the class CommunicatorAssessmentRequestController method sendAssessmentRequestCancelledMessage.

public void sendAssessmentRequestCancelledMessage(WorkspaceUserEntity workspaceUserEntity) {
    CommunicatorMessageId communicatorMessageId = assessmentRequestController.findCommunicatorMessageId(workspaceUserEntity);
    if (communicatorMessageId == null) {
        communicatorMessageId = communicatorController.createMessageId();
    }
    UserSchoolDataIdentifier userSchoolDataIdentifier = workspaceUserEntity.getUserSchoolDataIdentifier();
    if (userSchoolDataIdentifier == null) {
        logger.severe(String.format("Could not find userSchoolDataIdentifier for workspace user entity %d", workspaceUserEntity.getId()));
        return;
    }
    WorkspaceEntity workspaceEntity = workspaceUserEntity.getWorkspaceEntity();
    if (workspaceEntity == null) {
        logger.severe(String.format("Could not find workspaceEntity for workspace user entity %d", workspaceUserEntity.getId()));
        return;
    }
    UserEntity studentEntity = userSchoolDataIdentifier.getUserEntity();
    if (studentEntity == null) {
        logger.severe(String.format("Could not find studentEntity for workspace user entity %d", workspaceUserEntity.getId()));
        return;
    }
    schoolDataBridgeSessionController.startSystemSession();
    try {
        List<UserEntity> teachers = new ArrayList<UserEntity>();
        List<WorkspaceUserEntity> workspaceTeachers = workspaceUserEntityController.listActiveWorkspaceStaffMembers(workspaceEntity);
        for (WorkspaceUserEntity workspaceTeacher : workspaceTeachers) {
            teachers.add(workspaceTeacher.getUserSchoolDataIdentifier().getUserEntity());
        }
        SchoolDataIdentifier studentIdentifier = new SchoolDataIdentifier(userSchoolDataIdentifier.getIdentifier(), userSchoolDataIdentifier.getDataSource().getIdentifier());
        User student = userController.findUserByIdentifier(studentIdentifier);
        if (student == null) {
            logger.severe(String.format("Could not find student %s", studentIdentifier));
            return;
        }
        Workspace workspace = workspaceController.findWorkspace(workspaceEntity);
        if (workspace == null) {
            logger.severe(String.format("Could not find workspace for workspace entity %d", workspaceEntity.getId()));
            return;
        }
        String messageCategory = getText("plugin.communicator.assessmentrequest.category");
        String messageTitle = assessmentCancelledTitle(workspace, student);
        String messageBody = assessmentCancelledBody(workspace, student);
        List<String> teacherEmails = new ArrayList<>(teachers.size());
        for (UserEntity teacher : teachers) {
            String teacherEmail = userEmailEntityController.getUserDefaultEmailAddress(teacher, false);
            if (StringUtils.isNotBlank(teacherEmail)) {
                teacherEmails.add(teacherEmail);
            }
        }
        if (!teacherEmails.isEmpty()) {
            mailer.sendMail(MailType.HTML, teacherEmails, messageTitle, messageBody);
        }
        communicatorController.replyToMessage(studentEntity, messageCategory, messageTitle, messageBody, teachers, communicatorMessageId);
    } 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) CommunicatorMessageId(fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessageId) User(fi.otavanopisto.muikku.schooldata.entity.User) ArrayList(java.util.ArrayList) WorkspaceUserEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceUserEntity) UserEntity(fi.otavanopisto.muikku.model.users.UserEntity) WorkspaceUserEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceUserEntity) WorkspaceEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceEntity) Workspace(fi.otavanopisto.muikku.schooldata.entity.Workspace)

Aggregations

WorkspaceUserEntity (fi.otavanopisto.muikku.model.workspace.WorkspaceUserEntity)65 WorkspaceEntity (fi.otavanopisto.muikku.model.workspace.WorkspaceEntity)43 SchoolDataIdentifier (fi.otavanopisto.muikku.schooldata.SchoolDataIdentifier)33 UserSchoolDataIdentifier (fi.otavanopisto.muikku.model.users.UserSchoolDataIdentifier)25 Path (javax.ws.rs.Path)20 RESTPermit (fi.otavanopisto.security.rest.RESTPermit)17 ArrayList (java.util.ArrayList)17 UserEntity (fi.otavanopisto.muikku.model.users.UserEntity)16 EntityManager (javax.persistence.EntityManager)14 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)14 GET (javax.ws.rs.GET)10 User (fi.otavanopisto.muikku.schooldata.entity.User)9 WorkspaceUser (fi.otavanopisto.muikku.schooldata.entity.WorkspaceUser)7 WorkspaceRoleEntity (fi.otavanopisto.muikku.model.workspace.WorkspaceRoleEntity)6 Workspace (fi.otavanopisto.muikku.schooldata.entity.Workspace)6 RoleSchoolDataIdentifier (fi.otavanopisto.muikku.model.users.RoleSchoolDataIdentifier)5 Date (java.util.Date)5 UserGroupEntity (fi.otavanopisto.muikku.model.users.UserGroupEntity)4 HashMap (java.util.HashMap)4 DELETE (javax.ws.rs.DELETE)4