use of fi.otavanopisto.muikku.schooldata.entity.Workspace in project muikku by otavanopisto.
the class EvaluationRESTService method createWorkspaceAssessment.
@POST
@Path("/workspaces/{WORKSPACEENTITYID}/students/{STUDENTID}/assessments")
@RESTPermit(handling = Handling.INLINE, requireLoggedIn = true)
public Response createWorkspaceAssessment(@PathParam("WORKSPACEENTITYID") Long workspaceEntityId, @PathParam("STUDENTID") String studentId, WorkspaceAssessment payload) {
if (!sessionController.isLoggedIn()) {
return Response.status(Status.UNAUTHORIZED).build();
}
SchoolDataIdentifier studentIdentifier = SchoolDataIdentifier.fromId(studentId);
if (studentIdentifier == null) {
return Response.status(Status.BAD_REQUEST).entity(String.format("Malformed student identifier %s", studentId)).build();
}
WorkspaceEntity workspaceEntity = workspaceController.findWorkspaceEntityById(workspaceEntityId);
if (workspaceEntity == null) {
return Response.status(Status.NOT_FOUND).entity(String.format("Could not find workspace entity %d", workspaceEntityId)).build();
}
WorkspaceUserEntity workspaceStudentEntity = workspaceUserEntityController.findActiveWorkspaceUserByWorkspaceEntityAndUserIdentifier(workspaceEntity, studentIdentifier);
if (workspaceStudentEntity == null) {
return Response.status(Status.NOT_FOUND).entity(String.format("Could not find workspace student entity %s from workspace entity %d", studentIdentifier, workspaceEntityId)).build();
}
if (!sessionController.hasWorkspacePermission(MuikkuPermissions.EVALUATE_USER, workspaceEntity)) {
return Response.status(Status.FORBIDDEN).build();
}
if (payload.getEvaluated() == null) {
return Response.status(Status.BAD_REQUEST).entity("evaluated is missing").build();
}
if (payload.getAssessorEntityId() == null) {
return Response.status(Status.BAD_REQUEST).entity("assessorEntityId is missing").build();
}
if (payload.getGradeSchoolDataSource() == null) {
return Response.status(Status.BAD_REQUEST).entity("gradeSchoolDataSource is missing").build();
}
if (payload.getGradeIdentifier() == null) {
return Response.status(Status.BAD_REQUEST).entity("gradeIdentifier is missing").build();
}
UserEntity assessor = userEntityController.findUserEntityById(payload.getAssessorEntityId());
if (assessor == null) {
return Response.status(Status.BAD_REQUEST).entity("assessor is invalid").build();
}
User assessingUser = userController.findUserByUserEntityDefaults(assessor);
if (assessingUser == null) {
return Response.status(Status.BAD_REQUEST).entity("Could not find assessor from school data source").build();
}
GradingScale gradingScale = gradingController.findGradingScale(payload.getGradingScaleSchoolDataSource(), payload.getGradingScaleIdentifier());
if (gradingScale == null) {
return Response.status(Status.BAD_REQUEST).entity("gradingScale is invalid").build();
}
GradingScaleItem grade = gradingController.findGradingScaleItem(gradingScale, payload.getGradeSchoolDataSource(), payload.getGradeIdentifier());
if (grade == null) {
return Response.status(Status.BAD_REQUEST).entity("grade is invalid").build();
}
fi.otavanopisto.muikku.schooldata.entity.WorkspaceUser workspaceStudent = workspaceController.findWorkspaceUser(workspaceStudentEntity);
if (workspaceStudent == null) {
return Response.status(Status.INTERNAL_SERVER_ERROR).entity(String.format("Failed to get workspace student for workspace student entity %d from school data source", workspaceStudentEntity.getId())).build();
}
Date evaluated = payload.getEvaluated();
UserEntity student = userEntityController.findUserEntityByUserIdentifier(workspaceStudent.getUserIdentifier());
Workspace workspace = workspaceController.findWorkspace(workspaceEntity);
fi.otavanopisto.muikku.schooldata.entity.WorkspaceAssessment assessment = gradingController.createWorkspaceAssessment(workspaceStudent.getSchoolDataSource(), workspaceStudent, assessingUser, grade, payload.getVerbalAssessment(), evaluated);
if (student != null && workspace != null && assessment != null) {
sendAssessmentNotification(workspaceEntity, payload, assessor, student, workspace, grade.getName());
}
return Response.ok(createRestModel(workspaceEntity, assessment)).build();
}
use of fi.otavanopisto.muikku.schooldata.entity.Workspace 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();
}
use of fi.otavanopisto.muikku.schooldata.entity.Workspace 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();
}
use of fi.otavanopisto.muikku.schooldata.entity.Workspace in project muikku by otavanopisto.
the class ChatRoomSyncScheduler method updateChatRooms.
@Schedule(second = "*", minute = "*/15", hour = "*", persistent = false)
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public void updateChatRooms() {
String enabledWorkspacesCsv = pluginSettingsController.getPluginSetting("chat", "enabledWorkspaces");
if (enabledWorkspacesCsv == null) {
return;
}
List<String> enabledWorkspaces = Arrays.asList(enabledWorkspacesCsv.split(","));
String openfireToken = pluginSettingsController.getPluginSetting("chat", "openfireToken");
if (openfireToken == null) {
logger.log(Level.INFO, "No openfire token set, skipping room sync");
return;
}
String openfireUrl = pluginSettingsController.getPluginSetting("chat", "openfireUrl");
if (openfireUrl == null) {
logger.log(Level.INFO, "No openfire url set, skipping room sync");
return;
}
String openfirePort = pluginSettingsController.getPluginSetting("chat", "openfirePort");
if (openfirePort == null) {
logger.log(Level.INFO, "No openfire port set, skipping room sync");
return;
}
if (!StringUtils.isNumeric(openfirePort)) {
logger.log(Level.WARNING, "Invalid openfire port, skipping room sync");
return;
}
AuthenticationToken token = new AuthenticationToken(openfireToken);
RestApiClient client = new RestApiClient(openfireUrl, Integer.parseInt(openfirePort, 10), token);
for (String enabledWorkspace : enabledWorkspaces) {
try {
// Checking before creating is subject to a race condition, but in the worst case
// the creation just fails, resulting in a log entry
MUCRoomEntity chatRoomEntity = client.getChatRoom(enabledWorkspace);
if (chatRoomEntity == null) {
logger.log(Level.INFO, "Syncing chat workspace " + enabledWorkspace);
SchoolDataIdentifier identifier = SchoolDataIdentifier.fromId(enabledWorkspace);
if (identifier == null) {
logger.log(Level.WARNING, "Invalid workspace identifier " + enabledWorkspace + ", skipping...");
continue;
}
WorkspaceEntity workspaceEntity = workspaceEntityController.findWorkspaceByUrlName(enabledWorkspace);
if (workspaceEntity == null) {
logger.log(Level.WARNING, "No workspace entity found for identifier " + enabledWorkspace + ", skipping...");
continue;
}
Workspace workspace = workspaceController.findWorkspace(workspaceEntity);
chatRoomEntity = new MUCRoomEntity(enabledWorkspace, workspace.getName(), workspace.getDescription());
client.createChatRoom(chatRoomEntity);
}
} catch (Exception e) {
logger.log(Level.INFO, "Exception when syncing chat workspace " + enabledWorkspace, e);
}
}
}
use of fi.otavanopisto.muikku.schooldata.entity.Workspace in project muikku by otavanopisto.
the class CommunicatorAssessmentRequestController method sendAssessmentRequestMessage.
public CommunicatorMessage sendAssessmentRequestMessage(WorkspaceAssessmentRequest assessmentRequest) {
SchoolDataIdentifier workspaceUserIdentifier = new SchoolDataIdentifier(assessmentRequest.getWorkspaceUserIdentifier(), assessmentRequest.getWorkspaceUserSchoolDataSource());
WorkspaceUserEntity workspaceUserEntity = workspaceUserEntityController.findWorkspaceUserEntityByWorkspaceUserIdentifier(workspaceUserIdentifier);
if (workspaceUserEntity == null) {
logger.severe(String.format("Could not find workspace user entity for identifier", workspaceUserIdentifier));
return null;
}
UserSchoolDataIdentifier userSchoolDataIdentifier = workspaceUserEntity.getUserSchoolDataIdentifier();
if (userSchoolDataIdentifier == null) {
logger.severe(String.format("Could not find userSchoolDataIdentifier for workspace user entity %d", workspaceUserEntity.getId()));
return null;
}
WorkspaceEntity workspaceEntity = workspaceUserEntity.getWorkspaceEntity();
if (workspaceEntity == null) {
logger.severe(String.format("Could not find workspaceEntity for workspace user entity %d", workspaceUserEntity.getId()));
return null;
}
UserEntity studentEntity = userSchoolDataIdentifier.getUserEntity();
if (studentEntity == null) {
logger.severe(String.format("Could not find studentEntity for workspace user entity %d", workspaceUserEntity.getId()));
return null;
}
CommunicatorMessageId communicatorMessageId = assessmentRequestController.findCommunicatorMessageId(workspaceUserEntity);
schoolDataBridgeSessionController.startSystemSession();
try {
SchoolDataIdentifier studentIdentifier = new SchoolDataIdentifier(userSchoolDataIdentifier.getIdentifier(), userSchoolDataIdentifier.getDataSource().getIdentifier());
List<UserEntity> teachers = new ArrayList<UserEntity>();
List<WorkspaceUserEntity> workspaceTeachers = workspaceUserEntityController.listActiveWorkspaceStaffMembers(workspaceEntity);
for (WorkspaceUserEntity workspaceTeacher : workspaceTeachers) {
teachers.add(workspaceTeacher.getUserSchoolDataIdentifier().getUserEntity());
}
User student = userController.findUserByIdentifier(studentIdentifier);
if (student == null) {
logger.severe(String.format("Could not find student %s", studentIdentifier));
return null;
}
Workspace workspace = workspaceController.findWorkspace(workspaceEntity);
if (workspace == null) {
logger.severe(String.format("Could not find workspace for workspace entity %d", workspaceEntity.getId()));
return null;
}
String messageCategory = getText("plugin.communicator.assessmentrequest.category");
String messageTitle = assessmentRequestTitle(workspace, student);
String messageBody = assessmentRequestBody(workspace, student, assessmentRequest.getRequestText());
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);
}
if (communicatorMessageId != null) {
return communicatorController.replyToMessage(studentEntity, messageCategory, messageTitle, messageBody, teachers, communicatorMessageId);
} else {
CommunicatorMessage postMessage = communicatorController.postMessage(studentEntity, messageCategory, messageTitle, messageBody, teachers);
assessmentRequestController.setCommunicatorMessageId(assessmentRequest, postMessage.getCommunicatorMessageId());
return postMessage;
}
} finally {
schoolDataBridgeSessionController.endSystemSession();
}
}
Aggregations