Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SAK-42608 Samigo display user notifications for available assessments #11943

Merged
merged 35 commits into from
Oct 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
2e74226
SAK-42608: display user notifications for available tests and quizzes…
jkjanetschek Sep 26, 2023
b574c58
Update SamigoConstants.java
jkjanetschek Sep 26, 2023
e19e0f0
Update samigo/samigo-app/src/java/org/sakaiproject/tool/assessment/ui…
jkjanetschek Sep 28, 2023
2e9e6ca
Update samigo/samigo-app/src/java/org/sakaiproject/tool/assessment/ui…
jkjanetschek Sep 28, 2023
7b428af
Update samigo/samigo-app/src/java/org/sakaiproject/tool/assessment/ui…
jkjanetschek Sep 28, 2023
5e92c36
Update samigo/samigo-app/src/java/org/sakaiproject/tool/assessment/ui…
jkjanetschek Sep 28, 2023
3a524ab
Update samigo/samigo-app/src/java/org/sakaiproject/tool/assessment/ui…
jkjanetschek Sep 28, 2023
f21e572
Update samigo/samigo-app/src/java/org/sakaiproject/tool/assessment/ui…
jkjanetschek Sep 28, 2023
1e885a6
Update samigo/samigo-app/src/java/org/sakaiproject/tool/assessment/ui…
jkjanetschek Sep 28, 2023
a0c7f04
Update samigo/samigo-app/src/java/org/sakaiproject/tool/assessment/ui…
jkjanetschek Sep 28, 2023
ce079b2
Update samigo/samigo-app/src/java/org/sakaiproject/tool/assessment/ui…
jkjanetschek Sep 28, 2023
83c3ea1
Update samigo/samigo-app/src/java/org/sakaiproject/tool/assessment/ui…
jkjanetschek Sep 28, 2023
0637039
Update samigo/samigo-app/src/java/org/sakaiproject/tool/assessment/ui…
jkjanetschek Sep 28, 2023
79f0567
Update samigo/samigo-app/src/java/org/sakaiproject/tool/assessment/ui…
jkjanetschek Sep 28, 2023
fbaa075
Update samigo/samigo-app/src/java/org/sakaiproject/tool/assessment/ui…
jkjanetschek Sep 28, 2023
f6d3ee0
Update samigo/samigo-app/src/java/org/sakaiproject/tool/assessment/ui…
jkjanetschek Sep 28, 2023
3839fa6
Update samigo/samigo-app/src/java/org/sakaiproject/tool/assessment/ui…
jkjanetschek Sep 28, 2023
6260a7b
Update samigo/samigo-app/src/java/org/sakaiproject/tool/assessment/ui…
jkjanetschek Sep 28, 2023
8186b7d
Update samigo/samigo-app/src/java/org/sakaiproject/tool/assessment/ui…
jkjanetschek Sep 28, 2023
59b6b64
Update samigo/samigo-app/src/java/org/sakaiproject/tool/assessment/ui…
jkjanetschek Sep 28, 2023
c1ccfa3
Update samigo/samigo-app/src/java/org/sakaiproject/tool/assessment/ui…
jkjanetschek Sep 28, 2023
eba23f2
Update samigo/samigo-app/src/java/org/sakaiproject/tool/assessment/ui…
jkjanetschek Sep 28, 2023
5f5804a
Update samigo/samigo-app/src/java/org/sakaiproject/tool/assessment/ui…
jkjanetschek Sep 28, 2023
1c9aec5
Update samigo/samigo-app/src/java/org/sakaiproject/tool/assessment/ui…
jkjanetschek Sep 28, 2023
55ce9e1
Update samigo/samigo-app/src/java/org/sakaiproject/tool/assessment/ui…
jkjanetschek Sep 28, 2023
e81b412
Update samigo/samigo-app/src/java/org/sakaiproject/tool/assessment/ui…
jkjanetschek Sep 28, 2023
7c45b7e
Update samigo/samigo-app/src/java/org/sakaiproject/tool/assessment/ui…
jkjanetschek Sep 28, 2023
00c1e8a
Update samigo/samigo-app/src/java/org/sakaiproject/tool/assessment/ui…
jkjanetschek Sep 28, 2023
d459b6e
Update samigo/samigo-app/src/java/org/sakaiproject/tool/assessment/ui…
jkjanetschek Sep 28, 2023
3eb7d1c
Update samigo/samigo-app/src/java/org/sakaiproject/tool/assessment/ui…
jkjanetschek Sep 28, 2023
0763e13
Update samigo/samigo-app/src/java/org/sakaiproject/tool/assessment/ui…
jkjanetschek Sep 28, 2023
b56dc90
Update samigo/samigo-app/src/java/org/sakaiproject/tool/assessment/ui…
jkjanetschek Sep 28, 2023
b5516ef
Update samigo/samigo-app/src/java/org/sakaiproject/tool/assessment/ui…
adrianfish Sep 28, 2023
62406c8
Update samigo/samigo-app/src/java/org/sakaiproject/tool/assessment/ui…
adrianfish Sep 28, 2023
6a5ea18
Update SavePublishedSettingsListener.java
jkjanetschek Sep 28, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ public final class SamigoConstants {
public static final String EVENT_ASSESSMENT_PUBLISH = "sam.assessment.publish";
public static final String EVENT_ASSESSMENT_ATTACHMENT_NEW = "sam.assessment.attachment.new";
public static final String EVENT_ASSESSMENT_ATTACHMENT_DELETE = "sam.assessment.attachment.delete";
public static final String EVENT_ASSESSMENT_AVAILABLE = "sam.assessment.available";
public static final String EVENT_ASSESSMENT_UPDATE_AVAILABLE = "sam.assessment.update.available";
public static final String EVENT_ASSESSMENT_DELETE = "sam.assessment.delete";


//Published assessment events
public static final String EVENT_PUBLISHED_ASSESSMENT_REVISE = "sam.pubassessment.revise";
Expand All @@ -86,6 +90,8 @@ public final class SamigoConstants {
public static final String EVENT_PUBLISHED_ASSESSMENT_REPUBLISH = "sam.pubassessment.republish";
public static final String EVENT_PUBLISHED_ASSESSMENT_SETTING_EDIT = "sam.pubsetting.edit";
public static final String EVENT_PUBLISHED_ASSESSMENT_UNINDEXITEM = "sam.pubassessment.unindexitem";
public static final String EVENT_PUBLISHED_ASSESSMENT_RETRACTED = "sam.pubassessment.retracted";


//Question pool events
public static final String EVENT_QUESTIONPOOL_QUESTIONMOVED = "sam.questionpool.questionmoved";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.sakaiproject.component.cover.ServerConfigurationService;
import org.sakaiproject.samigo.api.SamigoAvailableNotificationService;
import org.sakaiproject.tool.assessment.data.ifc.assessment.AssessmentBaseIfc;
import org.sakaiproject.tool.assessment.data.ifc.assessment.AssessmentIfc;
import org.sakaiproject.tool.assessment.facade.AgentFacade;
import org.sakaiproject.tool.assessment.facade.AssessmentFacade;
import org.sakaiproject.tool.assessment.facade.PublishedAssessmentFacade;
Expand All @@ -48,6 +49,12 @@
import org.sakaiproject.tool.assessment.ui.listener.util.ContextUtil;
import org.sakaiproject.tool.cover.ToolManager;

import static org.sakaiproject.samigo.util.SamigoConstants.EVENT_PUBLISHED_ASSESSMENT_RETRACTED;
import static org.sakaiproject.samigo.util.SamigoConstants.EVENT_ASSESSMENT_AVAILABLE;
import org.sakaiproject.event.cover.EventTrackingService;

import java.util.Objects;

/**
* <p>Title: Samigo</p>2
* <p>Description: Sakai Assessment Manager</p>
Expand Down Expand Up @@ -78,6 +85,28 @@ public void processAction(ActionEvent ae) throws AbortProcessingException
author.setIsEditPoolFlow(false);
}

//cancel not fired event and fire event for userNotification alert deletion
AssessmentBean assessmentBean = (AssessmentBean) ContextUtil
.lookupBean("assessmentBean");
String assessmentId = assessmentBean.getAssessmentId();


//check if draft
if ((assessmentId != null && assessmentBean.getAssessment() == null)
|| (assessmentId != null && assessmentBean.getAssessment() != null
&& assessmentBean.getAssessment().getAssessmentBaseId() != null
&& !Long.toString(assessmentBean.getAssessment().getAssessmentBaseId()).equals(assessmentId))) {
PublishedAssessmentService publishedAssessmentService = new PublishedAssessmentService();
try {
PublishedAssessmentFacade assessment = publishedAssessmentService.getPublishedAssessment(assessmentId);
if (!Objects.equals(assessment.getStatus(), AssessmentIfc.RETRACT_FOR_EDIT_STATUS)) {
EventTrackingService.cancelDelays("siteId=" + AgentFacade.getCurrentSiteId() + ", assessmentId=" + assessment.getAssessmentId() + ", publishedAssessmentId=" + assessment.getPublishedAssessmentId(), EVENT_ASSESSMENT_AVAILABLE);
EventTrackingService.post(EventTrackingService.newEvent(EVENT_PUBLISHED_ASSESSMENT_RETRACTED,"siteId=" + AgentFacade.getCurrentSiteId() + ", assessmentId=" + assessment.getAssessmentId() + ", publishedAssessmentId=" + assessment.getPublishedAssessmentId() ,true));
}
} catch (Exception e) {
log.warn("Could not get published Assessment for id {}", assessmentId);
}
}

if (editType != null) {
if ("pendingAssessment".equals(editType)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
import org.sakaiproject.component.cover.ComponentManager;
import org.sakaiproject.component.cover.ServerConfigurationService;
import org.sakaiproject.email.cover.EmailService;
import org.sakaiproject.event.cover.EventTrackingService;
import org.sakaiproject.event.api.EventTrackingService;
import org.sakaiproject.exception.IdUnusedException;
import org.sakaiproject.grading.api.InvalidCategoryException;
import org.sakaiproject.rubrics.api.RubricsConstants;
Expand Down Expand Up @@ -98,6 +98,13 @@
import org.sakaiproject.util.ResourceLoader;
import org.springframework.web.client.HttpClientErrorException;


import org.sakaiproject.tool.assessment.data.dao.assessment.ExtendedTime;
import org.sakaiproject.time.api.Time;
import java.util.ListIterator;
import java.time.Instant;
import org.sakaiproject.tool.assessment.data.dao.assessment.ExtendedTime;

/**
* <p>Title: Samigo</p>2
* <p>Description: Sakai Assessment Manager</p>
Expand All @@ -121,11 +128,13 @@ public class PublishAssessmentListener
private RubricsService rubricsService;
private TaskService taskService;
private SamigoAvailableNotificationService samigoAvailableNotificationService;
private EventTrackingService eventTrackingService;

public PublishAssessmentListener() {
rubricsService = ComponentManager.get(RubricsService.class);
taskService = ComponentManager.get(TaskService.class);
samigoAvailableNotificationService = ComponentManager.get(SamigoAvailableNotificationService.class);
eventTrackingService = ComponentManager.get(EventTrackingService.class);
}

public void processAction(ActionEvent ae) throws AbortProcessingException {
Expand Down Expand Up @@ -271,13 +280,41 @@ private void publish(AssessmentFacade assessment,
ExtendedTimeFacade extendedTimeFacade = PersistenceService.getInstance().getExtendedTimeFacade();
extendedTimeFacade.copyEntriesToPub(pub.getData(), assessmentSettings.getExtendedTimes());

EventTrackingService.post(EventTrackingService.newEvent(SamigoConstants.EVENT_ASSESSMENT_PUBLISH, "siteId=" + AgentFacade.getCurrentSiteId() + ", assessmentId=" + assessment.getAssessmentId() + ", publishedAssessmentId=" + pub.getPublishedAssessmentId(), true));
eventTrackingService.post(eventTrackingService.newEvent(SamigoConstants.EVENT_ASSESSMENT_PUBLISH, "siteId=" + AgentFacade.getCurrentSiteId() + ", assessmentId=" + assessment.getAssessmentId() + ", publishedAssessmentId=" + pub.getPublishedAssessmentId(), true));

/*
* UserNotification: check if event should be fired immediately or/and must be delayed --> subsequent events are handled by TestsAndQuizzesUserNotificationHandler
*/
List<ExtendedTime> extendedTimes = assessmentSettings.getExtendedTimes();
Instant instant = pub.getStartDate().toInstant();
if (instant.isBefore(Instant.now())) {
eventTrackingService.post(eventTrackingService.newEvent(SamigoConstants.EVENT_ASSESSMENT_AVAILABLE, "siteId=" + AgentFacade.getCurrentSiteId() + ", assessmentId=" + assessment.getAssessmentId() + ", publishedAssessmentId=" + pub.getPublishedAssessmentId(), true));
} else {
Instant earliestDelayInstant = instant;
if (assessmentSettings.getExtendedTimesSize() != 0) {
ListIterator<ExtendedTime> it = extendedTimes.listIterator();
boolean postEvent = false;
while (it.hasNext()) {
ExtendedTime exTime = (ExtendedTime) it.next();
Instant startInstant = exTime.getStartDate().toInstant();
if (startInstant.isBefore(Instant.now()) && !postEvent) {
postEvent = true;
} else if (startInstant.isBefore(instant)) {
earliestDelayInstant = startInstant;
}
}
if (postEvent) {
eventTrackingService.post(eventTrackingService.newEvent(SamigoConstants.EVENT_ASSESSMENT_AVAILABLE, "siteId=" + AgentFacade.getCurrentSiteId() + ", assessmentId=" + assessment.getAssessmentId() + ", publishedAssessmentId=" + pub.getPublishedAssessmentId(), true));
}
}
eventTrackingService.delay(eventTrackingService.newEvent(SamigoConstants.EVENT_ASSESSMENT_AVAILABLE, "siteId=" + AgentFacade.getCurrentSiteId() + ", assessmentId=" + assessment.getAssessmentId() + ", publishedAssessmentId=" + pub.getPublishedAssessmentId(), true), earliestDelayInstant);
}

for (Object sectionObj : pub.getSectionSet()){
PublishedSectionData sectionData = (PublishedSectionData) sectionObj;
for (Object itemObj : sectionData.getItemSet()){
PublishedItemData itemData = (PublishedItemData) itemObj;
EventTrackingService.post(EventTrackingService.newEvent(SamigoConstants.EVENT_PUBLISHED_ASSESSMENT_SAVEITEM, "/sam/" + AgentFacade.getCurrentSiteId() + "/publish, publishedItemId=" + itemData.getItemIdString(), true));
eventTrackingService.post(eventTrackingService.newEvent(SamigoConstants.EVENT_PUBLISHED_ASSESSMENT_SAVEITEM, "/sam/" + AgentFacade.getCurrentSiteId() + "/publish, publishedItemId=" + itemData.getItemIdString(), true));

try {
Optional<ToolItemRubricAssociation> rubricAssociation = rubricsService.getRubricAssociation(RubricsConstants.RBCS_TOOL_SAMIGO, assessmentSettings.getAssessmentId().toString() + "." + itemData.getOriginalItemId().toString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@

import lombok.extern.slf4j.Slf4j;
import org.sakaiproject.component.cover.ComponentManager;
import org.sakaiproject.event.api.EventTrackingService;
import org.sakaiproject.samigo.api.SamigoAvailableNotificationService;
import org.sakaiproject.samigo.api.SamigoReferenceReckoner;
import org.sakaiproject.samigo.util.SamigoConstants;
import org.apache.commons.lang3.StringUtils;
import org.sakaiproject.component.cover.ComponentManager;
import org.sakaiproject.event.cover.EventTrackingService;
import org.sakaiproject.site.api.Site;
import org.sakaiproject.site.cover.SiteService;
import org.sakaiproject.spring.SpringBeanLocator;
Expand Down Expand Up @@ -70,6 +70,12 @@
import org.sakaiproject.tool.cover.ToolManager;
import org.sakaiproject.util.ResourceLoader;

import org.sakaiproject.tool.assessment.data.dao.assessment.ExtendedTime;
import org.sakaiproject.time.api.Time;
import java.util.ListIterator;
import java.time.Instant;
import org.sakaiproject.component.cover.ComponentManager;

@Slf4j
public class RepublishAssessmentListener implements ActionListener {

Expand All @@ -82,7 +88,10 @@ public class RepublishAssessmentListener implements ActionListener {
private TaskService taskService = ComponentManager.get(TaskService.class);;
private static final ResourceLoader rl = new ResourceLoader("org.sakaiproject.tool.assessment.bundle.AssessmentSettingsMessages");
private final SamigoAvailableNotificationService samigoAvailableNotificationService = ComponentManager.get(SamigoAvailableNotificationService.class);

private EventTrackingService eventTrackingService;
public RepublishAssessmentListener() {
eventTrackingService = ComponentManager.get(EventTrackingService.class);
}
public void processAction(ActionEvent ae) throws AbortProcessingException {
AssessmentBean assessmentBean = (AssessmentBean) ContextUtil
.lookupBean("assessmentBean");
Expand All @@ -94,7 +103,7 @@ public void processAction(ActionEvent ae) throws AbortProcessingException {

// Go to database to get the newly updated data. The data inside beans might not be up to date.
PublishedAssessmentFacade assessment = publishedAssessmentService.getPublishedAssessment(publishedAssessmentId);
EventTrackingService.post(EventTrackingService.newEvent(SamigoConstants.EVENT_PUBLISHED_ASSESSMENT_REPUBLISH, "siteId=" + AgentFacade.getCurrentSiteId() + ", publishedAssessmentId=" + publishedAssessmentId, true));
eventTrackingService.post(eventTrackingService.newEvent(SamigoConstants.EVENT_PUBLISHED_ASSESSMENT_REPUBLISH, "siteId=" + AgentFacade.getCurrentSiteId() + ", publishedAssessmentId=" + publishedAssessmentId, true));

assessment.setStatus(AssessmentBaseIfc.ACTIVE_STATUS);
publishedAssessmentService.saveAssessment(assessment);
Expand All @@ -105,15 +114,16 @@ public void processAction(ActionEvent ae) throws AbortProcessingException {
if (author.getIsRepublishAndRegrade() && hasGradingData) {
regradeRepublishedAssessment(publishedAssessmentService, assessment);
}

EventTrackingService.post(EventTrackingService.newEvent(SamigoConstants.EVENT_PUBLISHED_ASSESSMENT_REPUBLISH, "siteId=" + AgentFacade.getCurrentSiteId() + ", publishedAssessmentId=" + publishedAssessmentId, true));
PublishedAssessmentSettingsBean publishedAssessmentSettings = (PublishedAssessmentSettingsBean) ContextUtil.lookupBean("publishedSettings");
postUserNotification(assessment, publishedAssessmentSettings);
eventTrackingService.post(eventTrackingService.newEvent(SamigoConstants.EVENT_PUBLISHED_ASSESSMENT_REPUBLISH, "siteId=" + AgentFacade.getCurrentSiteId() + ", publishedAssessmentId=" + publishedAssessmentId, true));
assessment.setStatus(AssessmentBaseIfc.ACTIVE_STATUS);
publishedAssessmentService.saveAssessment(assessment);
updateGB(assessment);

PublishRepublishNotificationBean publishRepublishNotification = (PublishRepublishNotificationBean) ContextUtil.lookupBean("publishRepublishNotification");

PublishedAssessmentSettingsBean publishedAssessmentSettings = (PublishedAssessmentSettingsBean) ContextUtil.lookupBean("publishedSettings");

PublishAssessmentListener publishAssessmentListener = new PublishAssessmentListener();
String subject = publishRepublishNotification.getNotificationSubject();
String notificationMessage = publishAssessmentListener.getNotificationMessage(publishRepublishNotification, publishedAssessmentSettings.getTitle(), publishedAssessmentSettings.getReleaseTo(),
Expand Down Expand Up @@ -173,6 +183,39 @@ public void processAction(ActionEvent ae) throws AbortProcessingException {
samigoAvailableNotificationService.scheduleAssessmentAvailableNotification(publishedAssessmentId);
author.setOutcome("author");
}

private void postUserNotification(PublishedAssessmentFacade assessment, PublishedAssessmentSettingsBean publishedAssessmentSettings) {

List<ExtendedTime> extendedTimes = publishedAssessmentSettings.getExtendedTimes();
Instant instant = assessment.getStartDate().toInstant();
if (instant.isBefore(Instant.now())) {
eventTrackingService.post(eventTrackingService.newEvent(SamigoConstants.EVENT_ASSESSMENT_UPDATE_AVAILABLE, "siteId=" + AgentFacade.getCurrentSiteId() + ", assessmentId=" + assessment.getAssessmentId() + ", publishedAssessmentId=" + assessment.getPublishedAssessmentId(), true));
if (publishedAssessmentSettings.getExtendedTimesSize() != 0) {
ListIterator<ExtendedTime> it = extendedTimes.listIterator();
while (it.hasNext()) {
ExtendedTime exTime = (ExtendedTime) it.next();
Instant startInstant = exTime.getStartDate().toInstant();
if (startInstant.isAfter(Instant.now())) {
eventTrackingService.delay(eventTrackingService.newEvent(SamigoConstants.EVENT_ASSESSMENT_AVAILABLE, "siteId=" + AgentFacade.getCurrentSiteId() + ", assessmentId=" + assessment.getAssessmentId() + ", publishedAssessmentId=" + assessment.getPublishedAssessmentId(), true), startInstant);
}
}
}
} else {
eventTrackingService.delay(eventTrackingService.newEvent(SamigoConstants.EVENT_ASSESSMENT_AVAILABLE, "siteId=" + AgentFacade.getCurrentSiteId() + ", assessmentId=" + assessment.getAssessmentId() + ", publishedAssessmentId=" + assessment.getPublishedAssessmentId(), true), instant);
if (publishedAssessmentSettings.getExtendedTimesSize() != 0) {
ListIterator<ExtendedTime> it = extendedTimes.listIterator();
while (it.hasNext()) {
ExtendedTime exTime = (ExtendedTime) it.next();
Instant startInstant = exTime.getStartDate().toInstant();
if (startInstant.isBefore(Instant.now())) {
eventTrackingService.post(eventTrackingService.newEvent(SamigoConstants.EVENT_ASSESSMENT_UPDATE_AVAILABLE, "siteId=" + AgentFacade.getCurrentSiteId() + ", assessmentId=" + assessment.getAssessmentId() + ", publishedAssessmentId=" + assessment.getPublishedAssessmentId(), true));
} else if (startInstant.isAfter(Instant.now()) && !instant.equals(startInstant)) {
eventTrackingService.delay(eventTrackingService.newEvent(SamigoConstants.EVENT_ASSESSMENT_AVAILABLE, "siteId=" + AgentFacade.getCurrentSiteId() + ", assessmentId=" + assessment.getAssessmentId() + ", publishedAssessmentId=" + assessment.getPublishedAssessmentId(), true), startInstant);
}
}
}
}
}

private void regradeRepublishedAssessment (PublishedAssessmentService pubService, PublishedAssessmentFacade publishedAssessment) {
Map publishedItemHash = pubService.preparePublishedItemHash(publishedAssessment);
Expand Down
Loading