use of fi.otavanopisto.muikku.model.workspace.WorkspaceUserEntity in project muikku by otavanopisto.
the class AssessmentRequestRESTService method deleteAssessmentRequest.
@DELETE
@Path("/workspace/{WORKSPACEENTITYID}/assessmentRequests/{ID}")
@RESTPermitUnimplemented
public Response deleteAssessmentRequest(@PathParam("WORKSPACEENTITYID") Long workspaceEntityId, @PathParam("ID") String assessmentRequestId) {
if (!sessionController.isLoggedIn()) {
return Response.status(Status.UNAUTHORIZED).build();
}
if (assessmentRequestId == null) {
return Response.status(Status.BAD_REQUEST).entity("Invalid assessmentRequestIdentifier").build();
}
SchoolDataIdentifier assessmentRequestIdentifier = SchoolDataIdentifier.fromId(assessmentRequestId);
if (assessmentRequestIdentifier == null) {
return Response.status(Status.BAD_REQUEST).entity("Invalid assessmentRequestIdentifier").build();
}
WorkspaceEntity workspaceEntity = workspaceController.findWorkspaceEntityById(workspaceEntityId);
if (workspaceEntity == null) {
return Response.status(Status.NOT_FOUND).entity("Workspace entity not found").build();
}
WorkspaceUserEntity workspaceUserEntity = workspaceUserEntityController.findActiveWorkspaceUserByWorkspaceEntityAndUserIdentifier(workspaceEntity, sessionController.getLoggedUser());
if (workspaceUserEntity == null) {
return Response.status(Status.NOT_FOUND).entity("Workspace user entity not found").build();
}
SchoolDataIdentifier workspaceIdentifier = new SchoolDataIdentifier(workspaceEntity.getIdentifier(), workspaceEntity.getDataSource().getIdentifier());
SchoolDataIdentifier studentIdentifier = new SchoolDataIdentifier(workspaceUserEntity.getUserSchoolDataIdentifier().getIdentifier(), workspaceUserEntity.getUserSchoolDataIdentifier().getDataSource().getIdentifier());
if (!sessionController.getLoggedUser().equals(studentIdentifier)) {
return Response.status(Status.FORBIDDEN).build();
}
SchoolDataIdentifier workspaceStudentIdentifier = new SchoolDataIdentifier(workspaceUserEntity.getIdentifier(), workspaceUserEntity.getUserSchoolDataIdentifier().getDataSource().getIdentifier());
WorkspaceAssessmentRequest assessmentRequest = assessmentRequestController.findWorkspaceAssessmentRequest(assessmentRequestIdentifier, workspaceIdentifier, studentIdentifier);
if (assessmentRequest != null) {
SchoolDataIdentifier assessmentRequestWorkspaceUserIdentifier = new SchoolDataIdentifier(assessmentRequest.getWorkspaceUserIdentifier(), assessmentRequest.getSchoolDataSource());
if (assessmentRequestWorkspaceUserIdentifier.equals(workspaceStudentIdentifier)) {
assessmentRequestController.deleteWorkspaceAssessmentRequest(workspaceUserEntity, assessmentRequestIdentifier);
communicatorAssessmentRequestController.sendAssessmentRequestCancelledMessage(workspaceUserEntity);
} else {
return Response.status(Status.FORBIDDEN).build();
}
} else {
return Response.status(Status.NOT_FOUND).entity("Could not find assessment request").build();
}
return Response.noContent().build();
}
use of fi.otavanopisto.muikku.model.workspace.WorkspaceUserEntity in project muikku by otavanopisto.
the class WorkspaceController method listWorkspaceEntitiesByUser.
public List<WorkspaceEntity> listWorkspaceEntitiesByUser(UserEntity userEntity, boolean includeUnpublished) {
List<WorkspaceEntity> result = new ArrayList<>();
List<WorkspaceUserEntity> workspaceUserEntities = workspaceUserEntityController.listWorkspaceUserEntitiesByUserEntity(userEntity);
for (WorkspaceUserEntity workspaceUserEntity : workspaceUserEntities) {
if (includeUnpublished || workspaceUserEntity.getWorkspaceEntity().getPublished()) {
if (!result.contains(workspaceUserEntity.getWorkspaceEntity())) {
result.add(workspaceUserEntity.getWorkspaceEntity());
}
}
}
return result;
}
use of fi.otavanopisto.muikku.model.workspace.WorkspaceUserEntity in project muikku by otavanopisto.
the class WorkspaceController method deleteWorkspaceEntity.
private void deleteWorkspaceEntity(WorkspaceEntity workspaceEntity) {
// Delete settings
WorkspaceSettings workspaceSettings = findWorkspaceSettings(workspaceEntity);
if (workspaceSettings != null) {
workspaceSettingsDAO.delete(workspaceSettings);
}
// Workspace Users
List<WorkspaceUserEntity> workspaceUserEntities = workspaceUserEntityDAO.listByWorkspaceEntity(workspaceEntity);
for (WorkspaceUserEntity workspaceUserEntity : workspaceUserEntities) {
workspaceUserEntityDAO.delete(workspaceUserEntity);
}
workspaceEntityDAO.delete(workspaceEntity);
}
use of fi.otavanopisto.muikku.model.workspace.WorkspaceUserEntity in project muikku by otavanopisto.
the class WorkspaceEntityController method listActiveWorkspaceEntitiesByUserEntity.
public List<WorkspaceEntity> listActiveWorkspaceEntitiesByUserEntity(UserEntity userEntity) {
List<WorkspaceEntity> result = new ArrayList<>();
List<WorkspaceUserEntity> workspaceUserEntities = workspaceUserEntityController.listActiveWorkspaceUserEntitiesByUserEntity(userEntity);
for (WorkspaceUserEntity workspaceUserEntity : workspaceUserEntities) {
result.add(workspaceUserEntity.getWorkspaceEntity());
}
return result;
}
use of fi.otavanopisto.muikku.model.workspace.WorkspaceUserEntity in project muikku by otavanopisto.
the class TranscriptOfRecordsController method listStudentAssessments.
public Map<SchoolDataIdentifier, WorkspaceAssessment> listStudentAssessments(SchoolDataIdentifier studentIdentifier) {
List<WorkspaceAssessment> assessmentsByStudent = gradingController.listAssessmentsByStudent(studentIdentifier);
Map<SchoolDataIdentifier, WorkspaceAssessment> result = new HashMap<>();
for (WorkspaceAssessment assessment : assessmentsByStudent) {
WorkspaceUserEntity workspaceUserEntity = workspaceUserEntityController.findWorkspaceUserEntityByWorkspaceUserIdentifier(assessment.getWorkspaceUserIdentifier());
WorkspaceEntity workspaceEntity = workspaceUserEntity.getWorkspaceEntity();
SchoolDataIdentifier workspaceIdentifier = new SchoolDataIdentifier(workspaceEntity.getIdentifier(), workspaceEntity.getDataSource().getIdentifier());
if (!result.containsKey(workspaceIdentifier)) {
result.put(workspaceIdentifier, assessment);
} else {
WorkspaceAssessment storedAssessment = result.get(workspaceIdentifier);
if (assessment.getDate().after(storedAssessment.getDate()))
result.put(workspaceIdentifier, assessment);
}
}
return result;
}
Aggregations