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);
}
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();
}
}
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;
}
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();
}
}
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();
}
}
Aggregations