use of fi.otavanopisto.muikku.schooldata.entity.Workspace in project muikku by otavanopisto.
the class RequestedAssessmentSupplementationsNotificationStrategy method sendNotifications.
@Override
public void sendNotifications() {
Collection<Long> groups = getGroups();
if (groups.isEmpty()) {
return;
}
// Iterate through active students who belong to pre-configured groups (read: study programs)
SearchResult searchResult = requestedAssessmentSupplementationsNotificationController.searchActiveStudentIds(groups, FIRST_RESULT + offset, MAX_RESULTS);
logger.log(Level.INFO, String.format("%s processing %d/%d", getClass().getSimpleName(), offset, searchResult.getTotalHitCount()));
if ((offset + MAX_RESULTS) > searchResult.getTotalHitCount()) {
offset = 0;
} else {
offset += MAX_RESULTS;
}
for (Map<String, Object> result : searchResult.getResults()) {
String studentId = (String) result.get("id");
if (StringUtils.isBlank(studentId)) {
logger.severe("Could not process user found from search index because it had a null id");
continue;
}
String[] studentIdParts = studentId.split("/", 2);
SchoolDataIdentifier studentIdentifier = studentIdParts.length == 2 ? new SchoolDataIdentifier(studentIdParts[0], studentIdParts[1]) : null;
if (studentIdentifier == null) {
logger.severe(String.format("Could not process user found from search index with id %s", studentId));
continue;
}
UserEntity studentEntity = userEntityController.findUserEntityByUserIdentifier(studentIdentifier);
if (studentEntity == null) {
logger.severe(String.format("UserEntity with identifier %s not found", studentIdentifier));
continue;
}
// Iterate through the workspaces in which the student is currently active
List<WorkspaceEntity> workspaceEntities = workspaceUserEntityController.listActiveWorkspaceEntitiesByUserIdentifier(studentIdentifier);
for (WorkspaceEntity workspaceEntity : workspaceEntities) {
SchoolDataIdentifier workspaceIdentifier = new SchoolDataIdentifier(workspaceEntity.getIdentifier(), workspaceEntity.getDataSource().getIdentifier());
if (requestedAssessmentSupplementationsNotificationController.countByStudentIdentifierAndWorkspaceIdentifier(studentIdentifier, workspaceIdentifier) == 0) {
// Skip if workspace doesn't have a supplementation request
SupplementationRequest supplementationRequest = supplementationRequestDAO.findByStudentAndWorkspace(studentEntity.getId(), workspaceEntity.getId());
if (supplementationRequest == null) {
continue;
}
// Skip if workspace assessment is newer than supplementation request
WorkspaceAssessment workspaceAssessment = gradingController.findLatestWorkspaceAssessment(workspaceIdentifier, studentIdentifier);
if (workspaceAssessment != null && workspaceAssessment.getDate().getTime() >= supplementationRequest.getRequestDate().getTime()) {
continue;
}
// Skip if assessment request is newer than supplementation request
// TODO: At some point, refactor to simply fetch latest request by student + workspace
WorkspaceAssessmentRequest latestAssesmentRequest = null;
List<WorkspaceAssessmentRequest> studentAssesmentRequests = gradingController.listWorkspaceAssessmentRequests(workspaceIdentifier.getDataSource(), workspaceIdentifier.getIdentifier(), studentIdentifier.getIdentifier());
for (WorkspaceAssessmentRequest assessmentRequest : studentAssesmentRequests) {
Date assessmentRequestDate = assessmentRequest.getDate();
if (assessmentRequestDate != null) {
if (latestAssesmentRequest == null || latestAssesmentRequest.getDate().before(assessmentRequestDate)) {
latestAssesmentRequest = assessmentRequest;
}
}
}
if (latestAssesmentRequest != null && latestAssesmentRequest.getDate().getTime() >= supplementationRequest.getRequestDate().getTime()) {
continue;
}
if (!supplementationRequest.getRequestDate().before(Date.from(OffsetDateTime.now().minusDays(NOTIFICATION_THRESHOLD_DAYS).toInstant()))) {
continue;
}
// If we haven't skipped so far, student needs to be notified
Workspace workspace = workspaceController.findWorkspace(workspaceIdentifier);
if (workspace != null) {
String workspaceName = StringUtils.isBlank(workspace.getNameExtension()) ? workspace.getName() : String.format("%s (%s)", workspace.getName(), workspace.getNameExtension());
Locale studentLocale = localeController.resolveLocale(LocaleUtils.toLocale(studentEntity.getLocale()));
Map<String, Object> templateModel = new HashMap<>();
templateModel.put("workspaceName", workspaceName);
templateModel.put("locale", studentLocale);
templateModel.put("localeHelper", jadeLocaleHelper);
String notificationContent = renderNotificationTemplate("requested-assessment-supplementation-notification", templateModel);
notificationController.sendNotification(localeController.getText(studentLocale, "plugin.timednotifications.notification.category"), localeController.getText(studentLocale, "plugin.timednotifications.notification.requestedassessmentsupplementation.subject"), notificationContent, studentEntity, studentIdentifier, "requestedassessmentsupplementation");
// Store notification to avoid duplicates in the future
requestedAssessmentSupplementationsNotificationController.createRequestedAssessmentSupplementationNotification(studentIdentifier, workspaceIdentifier);
} else {
logger.log(Level.SEVERE, String.format("Cannot send notification to student with identifier %s because UserEntity or workspace was not found", studentIdentifier.toId()));
}
}
}
}
}
use of fi.otavanopisto.muikku.schooldata.entity.Workspace in project muikku by otavanopisto.
the class WorkspaceBackingBean method setWorkspaceUrlName.
public void setWorkspaceUrlName(String workspaceUrlName) {
WorkspaceEntity workspaceEntity = resolveWorkspaceEntity(workspaceUrlName);
if (workspaceEntity != null) {
this.workspaceEntityId = workspaceEntity.getId();
this.workspaceUrlName = workspaceEntity.getUrlName();
}
homeVisible = workspaceToolSettingsController.getToolVisible(workspaceEntity, "home");
guidesVisible = workspaceToolSettingsController.getToolVisible(workspaceEntity, "guides");
materialsVisible = workspaceToolSettingsController.getToolVisible(workspaceEntity, "materials");
discussionsVisible = sessionController.hasWorkspacePermission(ForumResourcePermissionCollection.FORUM_ACCESSWORKSPACEFORUMS, workspaceEntity) && workspaceToolSettingsController.getToolVisible(workspaceEntity, "discussions");
usersVisible = sessionController.hasWorkspacePermission(MuikkuPermissions.MANAGE_WORKSPACE_MEMBERS, workspaceEntity) && workspaceToolSettingsController.getToolVisible(workspaceEntity, "users");
journalVisible = sessionController.hasWorkspacePermission(MuikkuPermissions.ACCESS_WORKSPACE_JOURNAL, workspaceEntity) && workspaceToolSettingsController.getToolVisible(workspaceEntity, "journal");
// Assessment state
if (sessionController.isLoggedIn() && sessionController.hasWorkspacePermission(MuikkuPermissions.REQUEST_WORKSPACE_ASSESSMENT, workspaceEntity)) {
WorkspaceUserEntity workspaceUserEntity = workspaceUserEntityController.findActiveWorkspaceUserByWorkspaceEntityAndUserIdentifier(workspaceEntity, sessionController.getLoggedUser());
if (workspaceUserEntity != null) {
WorkspaceAssessmentState workspaceAssessmentState = assessmentRequestController.getWorkspaceAssessmentState(workspaceUserEntity);
this.assessmentState = workspaceAssessmentState == null ? null : workspaceAssessmentState.getState();
}
} else {
this.assessmentState = null;
}
schoolDataBridgeSessionController.startSystemSession();
try {
Workspace workspace = workspaceController.findWorkspace(workspaceEntity);
if (workspace != null) {
this.workspaceName = workspace.getName();
this.workspaceNameExtension = workspace.getNameExtension();
}
} finally {
schoolDataBridgeSessionController.endSystemSession();
}
}
use of fi.otavanopisto.muikku.schooldata.entity.Workspace in project muikku by otavanopisto.
the class CoursePickerRESTService method createWorkspaceUser.
@POST
@Path("/workspaces/{ID}/signup")
@RESTPermit(handling = Handling.INLINE)
public Response createWorkspaceUser(@PathParam("ID") Long workspaceEntityId, fi.otavanopisto.muikku.plugins.workspace.rest.model.WorkspaceUserSignup entity) {
if (!sessionController.isLoggedIn()) {
return Response.status(Status.UNAUTHORIZED).build();
}
WorkspaceEntity workspaceEntity = workspaceController.findWorkspaceEntityById(workspaceEntityId);
if (workspaceEntity == null) {
return Response.status(Status.BAD_REQUEST).build();
}
if (!sessionController.hasWorkspacePermission(MuikkuPermissions.WORKSPACE_SIGNUP, workspaceEntity)) {
return Response.status(Status.UNAUTHORIZED).build();
}
User user = userController.findUserByDataSourceAndIdentifier(sessionController.getLoggedUserSchoolDataSource(), sessionController.getLoggedUserIdentifier());
Long workspaceStudentRoleId = getWorkspaceStudentRoleId();
WorkspaceRoleEntity workspaceRole = roleController.findWorkspaceRoleEntityById(workspaceStudentRoleId);
Workspace workspace = workspaceController.findWorkspace(workspaceEntity);
Role role = roleController.findRoleByDataSourceAndRoleEntity(user.getSchoolDataSource(), workspaceRole);
SchoolDataIdentifier workspaceIdentifier = new SchoolDataIdentifier(workspace.getIdentifier(), workspace.getSchoolDataSource());
SchoolDataIdentifier userIdentifier = new SchoolDataIdentifier(user.getIdentifier(), user.getSchoolDataSource());
WorkspaceUserEntity workspaceUserEntity = workspaceUserEntityController.findWorkspaceUserEntityByWorkspaceAndUserIdentifierIncludeArchived(workspaceEntity, userIdentifier);
if (workspaceUserEntity != null && Boolean.TRUE.equals(workspaceUserEntity.getArchived())) {
workspaceUserEntityController.unarchiveWorkspaceUserEntity(workspaceUserEntity);
}
if (workspaceUserEntity != null && Boolean.FALSE.equals(workspaceUserEntity.getActive())) {
workspaceUserEntityController.updateActive(workspaceUserEntity, Boolean.TRUE);
userIndexer.indexUser(workspaceUserEntity.getUserSchoolDataIdentifier().getUserEntity());
}
fi.otavanopisto.muikku.schooldata.entity.WorkspaceUser workspaceUser = workspaceController.findWorkspaceUserByWorkspaceAndUser(workspaceIdentifier, userIdentifier);
if (workspaceUser == null) {
workspaceUser = workspaceController.createWorkspaceUser(workspace, user, role);
waitForWorkspaceUserEntity(workspaceEntity, userIdentifier);
} else {
workspaceController.updateWorkspaceStudentActivity(workspaceUser, true);
}
// TODO: should this work based on permission? Permission -> Roles -> Recipients
// TODO: Messaging should be moved into a CDI event listener
List<WorkspaceUserEntity> workspaceTeachers = workspaceUserEntityController.listActiveWorkspaceStaffMembers(workspaceEntity);
List<UserEntity> teachers = new ArrayList<UserEntity>();
String workspaceName = workspace.getName();
if (!StringUtils.isBlank(workspace.getNameExtension())) {
workspaceName += String.format(" (%s)", workspace.getNameExtension());
}
String userName = user.getNickName() == null ? user.getDisplayName() : String.format("%s \"%s\" %s (%s)", user.getFirstName(), user.getNickName(), user.getLastName(), user.getStudyProgrammeName());
for (WorkspaceUserEntity workspaceTeacher : workspaceTeachers) {
teachers.add(workspaceTeacher.getUserSchoolDataIdentifier().getUserEntity());
}
UserSchoolDataIdentifier userSchoolDataIdentifier = userSchoolDataIdentifierController.findUserSchoolDataIdentifierBySchoolDataIdentifier(userIdentifier);
workspaceController.createWorkspaceUserSignup(workspaceEntity, userSchoolDataIdentifier.getUserEntity(), new Date(), entity.getMessage());
String caption = localeController.getText(sessionController.getLocale(), "rest.workspace.joinWorkspace.joinNotification.caption");
caption = MessageFormat.format(caption, workspaceName);
String workspaceLink = String.format("<a href=\"%s/workspace/%s\" >%s</a>", baseUrl, workspaceEntity.getUrlName(), workspaceName);
SchoolDataIdentifier studentIdentifier = new SchoolDataIdentifier(user.getIdentifier(), user.getSchoolDataSource());
String studentLink = String.format("<a href=\"%s/guider#userprofile/%s\" >%s</a>", baseUrl, studentIdentifier.toId(), userName);
String content;
if (StringUtils.isEmpty(entity.getMessage())) {
content = localeController.getText(sessionController.getLocale(), "rest.workspace.joinWorkspace.joinNotification.content");
content = MessageFormat.format(content, studentLink, workspaceLink);
} else {
content = localeController.getText(sessionController.getLocale(), "rest.workspace.joinWorkspace.joinNotification.contentwmessage");
String blockquoteMessage = String.format("<blockquote>%s</blockquote>", entity.getMessage());
content = MessageFormat.format(content, studentLink, workspaceLink, blockquoteMessage);
}
for (MessagingWidget messagingWidget : messagingWidgets) {
// TODO: Category?
messagingWidget.postMessage(userSchoolDataIdentifier.getUserEntity(), "message", caption, content, teachers);
}
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, caption, content);
}
return Response.noContent().build();
}
use of fi.otavanopisto.muikku.schooldata.entity.Workspace in project muikku by otavanopisto.
the class PyramusWorkspaceSchoolDataBridge method listWorkspaces.
@Override
public List<Workspace> listWorkspaces() {
List<Workspace> result = new ArrayList<Workspace>();
Course[] courses = pyramusClient.get("/courses/courses/", Course[].class);
if (courses != null) {
for (Course course : courses) {
result.add(createWorkspaceEntity(course));
}
}
return result;
}
use of fi.otavanopisto.muikku.schooldata.entity.Workspace in project muikku by otavanopisto.
the class EvaluationController method notifyOfIncompleteWorkspace.
private void notifyOfIncompleteWorkspace(UserEntity teacher, UserEntity student, WorkspaceEntity workspaceEntity, String verbalAssessment) {
// Workspace
Workspace workspace = workspaceController.findWorkspace(workspaceEntity);
String workspaceUrl = String.format("%s/workspace/%s/materials", baseUrl, workspaceEntity.getUrlName());
String workspaceName = workspace.getName();
if (!StringUtils.isBlank(workspace.getNameExtension())) {
workspaceName = String.format("%s (%s)", workspaceName, workspace.getNameExtension());
}
Locale locale = userEntityController.getLocale(student);
CommunicatorMessageCategory category = communicatorController.persistCategory("assessments");
communicatorController.createMessage(communicatorController.createMessageId(), teacher, Arrays.asList(student), null, null, null, category, localeController.getText(locale, "plugin.evaluation.workspaceIncomplete.notificationCaption"), localeController.getText(locale, "plugin.evaluation.workspaceIncomplete.notificationText", new Object[] { workspaceUrl, workspaceName, verbalAssessment }), Collections.<Tag>emptySet());
}
Aggregations