Search in sources :

Example 1 with WorkspaceUser

use of fi.otavanopisto.muikku.schooldata.entity.WorkspaceUser in project muikku by otavanopisto.

the class WorkspaceIndexer method indexWorkspace.

private void indexWorkspace(Workspace workspace, WorkspaceEntity workspaceEntity) {
    try {
        Map<String, Object> extra = new HashMap<>();
        extra.put("published", workspaceEntity.getPublished());
        extra.put("access", workspaceEntity.getAccess());
        if (workspace.getSubjectIdentifier() != null) {
            Subject subject = courseMetaController.findSubject(workspace.getSchoolDataSource(), workspace.getSubjectIdentifier());
            extra.put("subject", subject.getName());
        }
        List<WorkspaceUser> staffMembers = workspaceController.listWorkspaceStaffMembers(workspaceEntity);
        Set<IndexedWorkspaceUser> indexedWorkspaceStaffMembers = new HashSet<IndexedWorkspaceUser>();
        for (WorkspaceUser staffMember : staffMembers) {
            // TODO: more efficient name fetching
            User staffMemberUser = userController.findUserByIdentifier(staffMember.getUserIdentifier());
            if (staffMemberUser != null) {
                indexedWorkspaceStaffMembers.add(new IndexedWorkspaceUser(staffMember.getUserIdentifier(), staffMemberUser.getFirstName(), staffMemberUser.getLastName()));
            } else {
                String userId = staffMember.getUserIdentifier() != null ? staffMember.getUserIdentifier().toId() : "NULL";
                logger.warning(String.format("Couldn't find staffmember #%s in workspace %s", userId, workspace.getIdentifier(), workspace.getSchoolDataSource()));
            }
        }
        extra.put("staffMembers", indexedWorkspaceStaffMembers);
        indexer.index(Workspace.class.getSimpleName(), workspace, extra);
    } catch (Exception e) {
        logger.warning(String.format("could not index workspace #%s/%s", workspace.getIdentifier(), workspace.getSchoolDataSource()));
    }
}
Also used : WorkspaceUser(fi.otavanopisto.muikku.schooldata.entity.WorkspaceUser) User(fi.otavanopisto.muikku.schooldata.entity.User) HashMap(java.util.HashMap) Subject(fi.otavanopisto.muikku.schooldata.entity.Subject) WorkspaceUser(fi.otavanopisto.muikku.schooldata.entity.WorkspaceUser) HashSet(java.util.HashSet) Workspace(fi.otavanopisto.muikku.schooldata.entity.Workspace)

Example 2 with WorkspaceUser

use of fi.otavanopisto.muikku.schooldata.entity.WorkspaceUser in project muikku by otavanopisto.

the class Evaluation2RESTService method updateWorkspaceAssessment.

@PUT
@Path("/workspace/{WORKSPACEENTITYID}/user/{USERENTITYID}/assessment")
@RESTPermit(handling = Handling.INLINE, requireLoggedIn = true)
public Response updateWorkspaceAssessment(@PathParam("WORKSPACEENTITYID") Long workspaceEntityId, @PathParam("USERENTITYID") Long userEntityId, RestAssessment payload) {
    if (!sessionController.isLoggedIn()) {
        return Response.status(Status.UNAUTHORIZED).build();
    }
    if (!sessionController.hasEnvironmentPermission(MuikkuPermissions.ACCESS_EVALUATION)) {
        return Response.status(Status.FORBIDDEN).build();
    }
    // Entities and identifiers
    WorkspaceEntity workspaceEntity = workspaceEntityController.findWorkspaceEntityById(workspaceEntityId);
    UserEntity userEntity = userEntityController.findUserEntityById(userEntityId);
    Workspace workspace = workspaceController.findWorkspace(workspaceEntity);
    if (workspaceEntity == null || userEntity == null || workspace == null) {
        return Response.status(Status.BAD_REQUEST).build();
    }
    SchoolDataIdentifier workspaceIdentifier = new SchoolDataIdentifier(workspaceEntity.getIdentifier(), workspaceEntity.getDataSource().getIdentifier());
    SchoolDataIdentifier userIdentifier = new SchoolDataIdentifier(userEntity.getDefaultIdentifier(), userEntity.getDefaultSchoolDataSource().getIdentifier());
    // TODO listWorkspaceAssessments is incorrect; one student in one workspace should have one assessment at most
    List<WorkspaceAssessment> workspaceAssessments = gradingController.listWorkspaceAssessments(workspaceIdentifier, userIdentifier);
    WorkspaceAssessment workspaceAssessment = workspaceAssessments.isEmpty() ? null : workspaceAssessments.get(0);
    if (workspaceAssessment == null) {
        return Response.status(Status.NOT_FOUND).build();
    }
    // Workspace user
    WorkspaceUser workspaceUser = workspaceController.findWorkspaceUserByWorkspaceAndUser(workspaceIdentifier, userIdentifier);
    // Assessor
    SchoolDataIdentifier assessorIdentifier = SchoolDataIdentifier.fromId(payload.getAssessorIdentifier());
    User assessingUser = userController.findUserByIdentifier(assessorIdentifier);
    UserEntity assessingUserEntity = userEntityController.findUserEntityByUser(assessingUser);
    // Grade
    SchoolDataIdentifier gradingScaleIdentifier = SchoolDataIdentifier.fromId(payload.getGradingScaleIdentifier());
    GradingScale gradingScale = gradingController.findGradingScale(gradingScaleIdentifier);
    SchoolDataIdentifier gradeIdentifier = SchoolDataIdentifier.fromId(payload.getGradeIdentifier());
    GradingScaleItem gradingScaleItem = gradingController.findGradingScaleItem(gradingScale, gradeIdentifier);
    // Update
    workspaceAssessment = gradingController.updateWorkspaceAssessment(workspaceAssessment.getIdentifier(), workspaceUser, assessingUser, gradingScaleItem, payload.getVerbalAssessment(), payload.getAssessmentDate());
    // Notification
    sendAssessmentNotification(workspaceEntity, workspaceAssessment, assessingUserEntity, userEntity, workspace, gradingScaleItem.getName());
    // Back to rest
    RestAssessment restAssessment = new RestAssessment(workspaceAssessment.getIdentifier().toId(), workspaceAssessment.getAssessingUserIdentifier().toId(), workspaceAssessment.getGradingScaleIdentifier().toId(), workspaceAssessment.getGradeIdentifier().toId(), workspaceAssessment.getVerbalAssessment(), workspaceAssessment.getDate(), workspaceAssessment.getPassing());
    return Response.ok(restAssessment).build();
}
Also used : SchoolDataIdentifier(fi.otavanopisto.muikku.schooldata.SchoolDataIdentifier) CompositeGradingScale(fi.otavanopisto.muikku.schooldata.entity.CompositeGradingScale) GradingScale(fi.otavanopisto.muikku.schooldata.entity.GradingScale) WorkspaceGradingScale(fi.otavanopisto.muikku.plugins.evaluation.rest.model.WorkspaceGradingScale) WorkspaceAssessment(fi.otavanopisto.muikku.schooldata.entity.WorkspaceAssessment) User(fi.otavanopisto.muikku.schooldata.entity.User) WorkspaceUser(fi.otavanopisto.muikku.schooldata.entity.WorkspaceUser) WorkspaceEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceEntity) GradingScaleItem(fi.otavanopisto.muikku.schooldata.entity.GradingScaleItem) RestAssessment(fi.otavanopisto.muikku.plugins.evaluation.rest.model.RestAssessment) WorkspaceUser(fi.otavanopisto.muikku.schooldata.entity.WorkspaceUser) UserEntity(fi.otavanopisto.muikku.model.users.UserEntity) WorkspaceUserEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceUserEntity) Workspace(fi.otavanopisto.muikku.schooldata.entity.Workspace) Path(javax.ws.rs.Path) RESTPermit(fi.otavanopisto.security.rest.RESTPermit) PUT(javax.ws.rs.PUT)

Example 3 with WorkspaceUser

use of fi.otavanopisto.muikku.schooldata.entity.WorkspaceUser in project muikku by otavanopisto.

the class Evaluation2RESTService method createWorkspaceAssessment.

@POST
@Path("/workspace/{WORKSPACEENTITYID}/user/{USERENTITYID}/assessment")
@RESTPermit(handling = Handling.INLINE, requireLoggedIn = true)
public Response createWorkspaceAssessment(@PathParam("WORKSPACEENTITYID") Long workspaceEntityId, @PathParam("USERENTITYID") Long userEntityId, RestAssessment payload) {
    if (!sessionController.isLoggedIn()) {
        return Response.status(Status.UNAUTHORIZED).build();
    }
    if (!sessionController.hasEnvironmentPermission(MuikkuPermissions.ACCESS_EVALUATION)) {
        return Response.status(Status.FORBIDDEN).build();
    }
    // Entities and identifiers
    WorkspaceEntity workspaceEntity = workspaceEntityController.findWorkspaceEntityById(workspaceEntityId);
    UserEntity userEntity = userEntityController.findUserEntityById(userEntityId);
    Workspace workspace = workspaceController.findWorkspace(workspaceEntity);
    if (workspaceEntity == null || userEntity == null || workspace == null) {
        return Response.status(Status.BAD_REQUEST).build();
    }
    SchoolDataIdentifier workspaceIdentifier = new SchoolDataIdentifier(workspaceEntity.getIdentifier(), workspaceEntity.getDataSource().getIdentifier());
    SchoolDataIdentifier userIdentifier = new SchoolDataIdentifier(userEntity.getDefaultIdentifier(), userEntity.getDefaultSchoolDataSource().getIdentifier());
    // TODO listWorkspaceAssessments is incorrect; one student in one workspace should have one assessment at most
    List<WorkspaceAssessment> workspaceAssessments = gradingController.listWorkspaceAssessments(workspaceIdentifier, userIdentifier);
    WorkspaceAssessment workspaceAssessment = workspaceAssessments.isEmpty() ? null : workspaceAssessments.get(0);
    // Workspace user
    WorkspaceUser workspaceUser = workspaceController.findWorkspaceUserByWorkspaceAndUser(workspaceIdentifier, userIdentifier);
    // Assessor
    SchoolDataIdentifier assessorIdentifier = SchoolDataIdentifier.fromId(payload.getAssessorIdentifier());
    User assessingUser = userController.findUserByIdentifier(assessorIdentifier);
    UserEntity assessingUserEntity = assessingUser == null ? null : userEntityController.findUserEntityByUser(assessingUser);
    // Grade
    SchoolDataIdentifier gradingScaleIdentifier = SchoolDataIdentifier.fromId(payload.getGradingScaleIdentifier());
    GradingScale gradingScale = gradingController.findGradingScale(gradingScaleIdentifier);
    SchoolDataIdentifier gradeIdentifier = SchoolDataIdentifier.fromId(payload.getGradeIdentifier());
    GradingScaleItem gradingScaleItem = gradingController.findGradingScaleItem(gradingScale, gradeIdentifier);
    if (workspaceAssessment == null) {
        workspaceAssessment = gradingController.createWorkspaceAssessment(workspaceIdentifier.getDataSource(), workspaceUser, assessingUser, gradingScaleItem, payload.getVerbalAssessment(), payload.getAssessmentDate());
    } else {
        workspaceAssessment = gradingController.updateWorkspaceAssessment(workspaceAssessment.getIdentifier(), workspaceUser, assessingUser, gradingScaleItem, payload.getVerbalAssessment(), payload.getAssessmentDate());
    }
    // Delete workspace supplementation request (if any)
    SupplementationRequest supplementationRequest = evaluationController.findSupplementationRequestByStudentAndWorkspace(userEntity.getId(), workspaceEntity.getId());
    if (supplementationRequest != null) {
        evaluationController.deleteSupplementationRequest(supplementationRequest);
    }
    // Notification
    sendAssessmentNotification(workspaceEntity, workspaceAssessment, assessingUserEntity, userEntity, workspace, gradingScaleItem.getName());
    // Back to rest
    RestAssessment restAssessment = new RestAssessment(workspaceAssessment.getIdentifier().toId(), workspaceAssessment.getAssessingUserIdentifier().toId(), workspaceAssessment.getGradingScaleIdentifier().toId(), workspaceAssessment.getGradeIdentifier().toId(), workspaceAssessment.getVerbalAssessment(), workspaceAssessment.getDate(), workspaceAssessment.getPassing());
    return Response.ok(restAssessment).build();
}
Also used : SchoolDataIdentifier(fi.otavanopisto.muikku.schooldata.SchoolDataIdentifier) CompositeGradingScale(fi.otavanopisto.muikku.schooldata.entity.CompositeGradingScale) GradingScale(fi.otavanopisto.muikku.schooldata.entity.GradingScale) WorkspaceGradingScale(fi.otavanopisto.muikku.plugins.evaluation.rest.model.WorkspaceGradingScale) WorkspaceAssessment(fi.otavanopisto.muikku.schooldata.entity.WorkspaceAssessment) User(fi.otavanopisto.muikku.schooldata.entity.User) WorkspaceUser(fi.otavanopisto.muikku.schooldata.entity.WorkspaceUser) WorkspaceEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceEntity) GradingScaleItem(fi.otavanopisto.muikku.schooldata.entity.GradingScaleItem) RestAssessment(fi.otavanopisto.muikku.plugins.evaluation.rest.model.RestAssessment) SupplementationRequest(fi.otavanopisto.muikku.plugins.evaluation.model.SupplementationRequest) RestSupplementationRequest(fi.otavanopisto.muikku.plugins.evaluation.rest.model.RestSupplementationRequest) WorkspaceUser(fi.otavanopisto.muikku.schooldata.entity.WorkspaceUser) UserEntity(fi.otavanopisto.muikku.model.users.UserEntity) WorkspaceUserEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceUserEntity) Workspace(fi.otavanopisto.muikku.schooldata.entity.Workspace) Path(javax.ws.rs.Path) RESTPermit(fi.otavanopisto.security.rest.RESTPermit) POST(javax.ws.rs.POST)

Example 4 with WorkspaceUser

use of fi.otavanopisto.muikku.schooldata.entity.WorkspaceUser in project muikku by otavanopisto.

the class WorkspaceRESTService method findWorkspaceStudent.

@GET
@Path("/workspaces/{WORKSPACEENTITYID}/students/{ID}")
@RESTPermit(handling = Handling.INLINE)
public Response findWorkspaceStudent(@PathParam("WORKSPACEENTITYID") Long workspaceEntityId, @PathParam("ID") String workspaceStudentId) {
    if (!sessionController.isLoggedIn()) {
        return Response.status(Status.UNAUTHORIZED).build();
    }
    WorkspaceEntity workspaceEntity = workspaceController.findWorkspaceEntityById(workspaceEntityId);
    if (workspaceEntity == null) {
        return Response.status(Status.NOT_FOUND).build();
    }
    SchoolDataIdentifier workspaceUserIdentifier = SchoolDataIdentifier.fromId(workspaceStudentId);
    if (workspaceUserIdentifier == null) {
        return Response.status(Status.BAD_REQUEST).entity("Invalid workspace user id").build();
    }
    WorkspaceUserEntity workspaceUserEntity = workspaceUserEntityController.findWorkspaceUserEntityByWorkspaceUserIdentifierIncludeArchived(workspaceUserIdentifier);
    if (workspaceUserEntity == null) {
        return Response.status(Status.NOT_FOUND).entity("Workspace student not found").build();
    }
    fi.otavanopisto.muikku.schooldata.entity.WorkspaceUser bridgeUser = workspaceController.findWorkspaceUser(workspaceUserEntity);
    if (bridgeUser == null) {
        return Response.status(Status.NOT_FOUND).entity("School data user not found").build();
    }
    SchoolDataIdentifier userIdentifier = bridgeUser.getUserIdentifier();
    User user = userController.findUserByIdentifier(userIdentifier);
    if (user == null) {
        return Response.status(Status.NOT_FOUND).entity("School data user not found").build();
    }
    WorkspaceUser workspaceUser = workspaceController.findWorkspaceUserByWorkspaceEntityAndUser(workspaceEntity, userIdentifier);
    if (workspaceUser == null) {
        return Response.status(Status.NOT_FOUND).entity("School data workspace user not found").build();
    }
    return Response.ok(createRestModel(workspaceUserEntity.getUserSchoolDataIdentifier().getUserEntity(), user, workspaceUser, workspaceUserEntity.getActive())).build();
}
Also used : SchoolDataIdentifier(fi.otavanopisto.muikku.schooldata.SchoolDataIdentifier) UserSchoolDataIdentifier(fi.otavanopisto.muikku.model.users.UserSchoolDataIdentifier) WorkspaceUserEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceUserEntity) User(fi.otavanopisto.muikku.schooldata.entity.User) WorkspaceUser(fi.otavanopisto.muikku.schooldata.entity.WorkspaceUser) WorkspaceEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceEntity) WorkspaceUser(fi.otavanopisto.muikku.schooldata.entity.WorkspaceUser) WorkspaceUser(fi.otavanopisto.muikku.schooldata.entity.WorkspaceUser) Path(javax.ws.rs.Path) RESTPermit(fi.otavanopisto.security.rest.RESTPermit) GET(javax.ws.rs.GET)

Example 5 with WorkspaceUser

use of fi.otavanopisto.muikku.schooldata.entity.WorkspaceUser in project muikku by otavanopisto.

the class WorkspaceRESTService method listWorkspaceStaffMembers.

@GET
@Path("/workspaces/{ID}/staffMembers")
@RESTPermitUnimplemented
public Response listWorkspaceStaffMembers(@PathParam("ID") Long workspaceEntityId, @QueryParam("orderBy") String orderBy) {
    // Workspace
    WorkspaceEntity workspaceEntity = workspaceController.findWorkspaceEntityById(workspaceEntityId);
    if (workspaceEntity == null) {
        return Response.status(Status.NOT_FOUND).build();
    }
    // Access check
    if (!sessionController.hasWorkspacePermission(MuikkuPermissions.LIST_WORKSPACE_MEMBERS, workspaceEntity)) {
        return Response.status(Status.FORBIDDEN).build();
    }
    // Staff via WorkspaceSchoolDataBridge
    List<fi.otavanopisto.muikku.schooldata.entity.WorkspaceUser> schoolDataUsers = workspaceController.listWorkspaceStaffMembers(workspaceEntity);
    List<WorkspaceStaffMember> workspaceStaffMembers = new ArrayList<>();
    for (fi.otavanopisto.muikku.schooldata.entity.WorkspaceUser workspaceUser : schoolDataUsers) {
        SchoolDataIdentifier userIdentifier = workspaceUser.getUserIdentifier();
        User user = userController.findUserByIdentifier(userIdentifier);
        if (user != null) {
            UserEntity userEntity = userEntityController.findUserEntityByUser(user);
            // #3111: Workspace staff members should be limited to teachers only. A better implementation would support specified workspace roles
            WorkspaceUserEntity workspaceUserEntity = workspaceUserEntityController.findActiveWorkspaceUserByWorkspaceEntityAndUserEntity(workspaceEntity, userEntity);
            if (workspaceUserEntity == null || workspaceUserEntity.getWorkspaceUserRole().getArchetype() != WorkspaceRoleArchetype.TEACHER) {
                continue;
            }
            workspaceStaffMembers.add(new WorkspaceStaffMember(workspaceUser.getIdentifier().toId(), workspaceUser.getUserIdentifier().toId(), userEntity != null ? userEntity.getId() : null, user.getFirstName(), user.getLastName()));
        } else {
            logger.log(Level.SEVERE, String.format("Could not find user %s", userIdentifier));
        }
    }
    // Sorting
    if (StringUtils.equals(orderBy, "name")) {
        Collections.sort(workspaceStaffMembers, new Comparator<WorkspaceStaffMember>() {

            @Override
            public int compare(WorkspaceStaffMember o1, WorkspaceStaffMember o2) {
                String s1 = String.format("%s, %s", StringUtils.defaultString(o1.getLastName(), ""), StringUtils.defaultString(o1.getFirstName(), ""));
                String s2 = String.format("%s, %s", StringUtils.defaultString(o2.getLastName(), ""), StringUtils.defaultString(o2.getFirstName(), ""));
                return s1.compareTo(s2);
            }
        });
    }
    // Response
    return Response.ok(workspaceStaffMembers).build();
}
Also used : SchoolDataIdentifier(fi.otavanopisto.muikku.schooldata.SchoolDataIdentifier) UserSchoolDataIdentifier(fi.otavanopisto.muikku.model.users.UserSchoolDataIdentifier) User(fi.otavanopisto.muikku.schooldata.entity.User) WorkspaceUser(fi.otavanopisto.muikku.schooldata.entity.WorkspaceUser) ArrayList(java.util.ArrayList) WorkspaceUser(fi.otavanopisto.muikku.schooldata.entity.WorkspaceUser) UserEntity(fi.otavanopisto.muikku.model.users.UserEntity) WorkspaceUserEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceUserEntity) WorkspaceUserEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceUserEntity) WorkspaceEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceEntity) WorkspaceStaffMember(fi.otavanopisto.muikku.plugins.workspace.rest.model.WorkspaceStaffMember) WorkspaceUser(fi.otavanopisto.muikku.schooldata.entity.WorkspaceUser) Path(javax.ws.rs.Path) RESTPermitUnimplemented(fi.otavanopisto.muikku.rest.RESTPermitUnimplemented) GET(javax.ws.rs.GET)

Aggregations

WorkspaceUser (fi.otavanopisto.muikku.schooldata.entity.WorkspaceUser)7 WorkspaceEntity (fi.otavanopisto.muikku.model.workspace.WorkspaceEntity)6 WorkspaceUserEntity (fi.otavanopisto.muikku.model.workspace.WorkspaceUserEntity)6 SchoolDataIdentifier (fi.otavanopisto.muikku.schooldata.SchoolDataIdentifier)6 User (fi.otavanopisto.muikku.schooldata.entity.User)6 Path (javax.ws.rs.Path)6 RESTPermit (fi.otavanopisto.security.rest.RESTPermit)5 UserEntity (fi.otavanopisto.muikku.model.users.UserEntity)4 UserSchoolDataIdentifier (fi.otavanopisto.muikku.model.users.UserSchoolDataIdentifier)4 GET (javax.ws.rs.GET)4 Workspace (fi.otavanopisto.muikku.schooldata.entity.Workspace)3 RestAssessment (fi.otavanopisto.muikku.plugins.evaluation.rest.model.RestAssessment)2 WorkspaceGradingScale (fi.otavanopisto.muikku.plugins.evaluation.rest.model.WorkspaceGradingScale)2 CompositeGradingScale (fi.otavanopisto.muikku.schooldata.entity.CompositeGradingScale)2 GradingScale (fi.otavanopisto.muikku.schooldata.entity.GradingScale)2 GradingScaleItem (fi.otavanopisto.muikku.schooldata.entity.GradingScaleItem)2 WorkspaceAssessment (fi.otavanopisto.muikku.schooldata.entity.WorkspaceAssessment)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Flag (fi.otavanopisto.muikku.model.users.Flag)1