use of fi.otavanopisto.muikku.model.workspace.WorkspaceEntity in project muikku by otavanopisto.
the class AssessmentRequestController method getWorkspaceAssessmentState.
public WorkspaceAssessmentState getWorkspaceAssessmentState(WorkspaceUserEntity workspaceUserEntity) {
WorkspaceEntity workspaceEntity = workspaceUserEntity.getWorkspaceEntity();
// List all asssessments
List<WorkspaceAssessment> workspaceAssessments = gradingController.listWorkspaceAssessments(workspaceEntity.getDataSource().getIdentifier(), workspaceEntity.getIdentifier(), workspaceUserEntity.getUserSchoolDataIdentifier().getIdentifier());
// Sort latest assessment first
if (!workspaceAssessments.isEmpty()) {
workspaceAssessments.sort(new Comparator<WorkspaceAssessment>() {
public int compare(WorkspaceAssessment o1, WorkspaceAssessment o2) {
return o2.getDate().compareTo(o1.getDate());
}
});
}
// List all assessment requests
List<WorkspaceAssessmentRequest> assessmentRequests = gradingController.listWorkspaceAssessmentRequests(workspaceEntity.getDataSource().getIdentifier(), workspaceEntity.getIdentifier(), workspaceUserEntity.getUserSchoolDataIdentifier().getIdentifier());
if (!assessmentRequests.isEmpty()) {
// Strip assessment requests that have been handled (TODO could be handled in Pyramus)
for (int i = assessmentRequests.size() - 1; i >= 0; i--) {
if (assessmentRequests.get(i).getHandled()) {
assessmentRequests.remove(i);
}
}
if (!assessmentRequests.isEmpty()) {
// Sort latest assessment request first
assessmentRequests.sort(new Comparator<WorkspaceAssessmentRequest>() {
public int compare(WorkspaceAssessmentRequest o1, WorkspaceAssessmentRequest o2) {
return o2.getDate().compareTo(o1.getDate());
}
});
}
}
WorkspaceAssessment latestAssessment = workspaceAssessments.isEmpty() ? null : workspaceAssessments.get(0);
WorkspaceAssessmentRequest latestRequest = assessmentRequests.isEmpty() ? null : assessmentRequests.get(0);
if (latestAssessment != null && (latestRequest == null || latestRequest.getDate().before(latestAssessment.getDate()))) {
// Has assessment and no request, or the request is older
GradingScale gradingScale = gradingController.findGradingScale(latestAssessment.getGradingScaleIdentifier());
GradingScaleItem grade = gradingController.findGradingScaleItem(gradingScale, latestAssessment.getGradeIdentifier());
return grade.isPassingGrade() ? new WorkspaceAssessmentState(WorkspaceAssessmentState.PASS, latestAssessment.getDate()) : new WorkspaceAssessmentState(WorkspaceAssessmentState.FAIL, latestAssessment.getDate());
} else if (latestRequest != null && (latestAssessment == null || latestAssessment.getDate().before(latestRequest.getDate()))) {
// Has request and no assessment, or the assessment is older
if (latestAssessment == null) {
return new WorkspaceAssessmentState(WorkspaceAssessmentState.PENDING, latestRequest.getDate());
} else if (Boolean.TRUE.equals(latestAssessment.getPassing())) {
return new WorkspaceAssessmentState(WorkspaceAssessmentState.PENDING_PASS, latestRequest.getDate());
} else {
return new WorkspaceAssessmentState(WorkspaceAssessmentState.PENDING_FAIL, latestRequest.getDate());
}
} else {
// Has neither assessment nor request
return new WorkspaceAssessmentState(WorkspaceAssessmentState.UNASSESSED);
}
}
use of fi.otavanopisto.muikku.model.workspace.WorkspaceEntity 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();
}
}
use of fi.otavanopisto.muikku.model.workspace.WorkspaceEntity 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;
}
use of fi.otavanopisto.muikku.model.workspace.WorkspaceEntity 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();
}
}
use of fi.otavanopisto.muikku.model.workspace.WorkspaceEntity in project muikku by otavanopisto.
the class WorkspaceAnnouncementsViewBackingBean 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 (!workspaceEntity.getPublished()) {
if (!sessionController.hasWorkspacePermission(MuikkuPermissions.ACCESS_UNPUBLISHED_WORKSPACE, workspaceEntity)) {
return NavigationRules.NOT_FOUND;
}
}
if (workspaceEntity.getAccess() != WorkspaceAccess.ANYONE) {
if (!sessionController.hasWorkspacePermission(AnnouncerPermissions.LIST_WORKSPACE_ANNOUNCEMENTS, workspaceEntity)) {
if (!sessionController.isLoggedIn()) {
return navigationController.requireLogin();
} else {
return NavigationRules.ACCESS_DENIED;
}
}
}
workspaceEntityId = workspaceEntity.getId();
workspaceBackingBean.setWorkspaceUrlName(urlName);
workspaceName = workspaceBackingBean.getWorkspaceName();
workspaceNameExtension = workspaceBackingBean.getWorkspaceNameExtension();
if (announcementId != null) {
currentAnnouncement = announcementController.findById(announcementId);
}
activeAnnouncements = announcementController.listActiveByWorkspaceEntities(Collections.singletonList(workspaceEntity));
return null;
}
Aggregations