[Building Sakai] Samigo email notifications on assessment submission

Miguel Carro Pellicer miguel at educlever.es
Mon Mar 24 01:33:53 PDT 2014


Hi Jaques, this is a custom development that sends an email to all roles 
with "assessment.gradeAssessment.own" or 
"assessment.gradeAssessment.any" permission.

Also i did some changes over SamigoEmailService to send mails using 
Sakai's ETS properties.

Miguel.

El 24/03/2014 9:12, Jaques Smith escribió:
> Hi Miguel,
>
> Is this just in your local source? I don't see anything in Samigo.
> Yes please extract the change, would really help to see how you 
> approached it.
>
> Thanks,
> Jaques
>
> 2014-03-20 15:30 GMT+02:00 Miguel Carro Pellicer <miguel at educlever.es 
> <mailto:miguel at educlever.es>>:
>
>     I added it some years ago, if you are interested i can extract the
>     changes from the source :)
>
>     Miguel.
>
>     El 19/03/2014 9:46, Jaques Smith escribió:
>>     Hi All,
>>
>>     Is there a way or has anybody added the ability to send a email
>>     notification to the lecturer when a student submit a assessment
>>     in Samigo?
>>
>>     Cheers,
>>     Jaques
>>
>>     ------------------------------------------------------------------------
>>     See OpenCollab email disclaimer at
>>     http://www.opencollab.co.za/email-disclaimer
>>
>>
>>     _______________________________________________
>>     sakai-dev mailing list
>>     sakai-dev at collab.sakaiproject.org  <mailto:sakai-dev at collab.sakaiproject.org>
>>     http://collab.sakaiproject.org/mailman/listinfo/sakai-dev
>>
>>     TO UNSUBSCRIBE: send email tosakai-dev-unsubscribe at collab.sakaiproject.org  <mailto:sakai-dev-unsubscribe at collab.sakaiproject.org>  with a subject of "unsubscribe"
>
>     -- 
>     Logo 	
>
>     Miguel Carro
>     Pellicer<http://es.linkedin.com/pub/miguel-carro-pellicer/38/502/b92>
>     /IT Consultant - Elearning solutions/
>
>     Phone: +34 - 686266485
>     Email: miguel at educlever.es <mailto:miguel at educlever.es>
>
>     No me imprimas si no es necesario. Protejamos el medio ambiente
>
>
>     AVISO LEGAL: El contenido de este mensaje de correo electrónico,
>     incluidos los ficheros adjuntos, es confidencial y está protegido
>     por el artículo 18.3 de la Constitución Española, que garantiza el
>     secreto de las comunicaciones.
>     Si usted recibe este mensaje por error, por favor póngase en
>     contacto con el remitente para informarle de este hecho, y no
>     difunda su contenido ni haga copias.
>     *** Este mensaje ha sido verificado con herramientas de
>     eliminación de virus y contenido malicioso ***
>     Este aviso legal ha sido incorporado automáticamente al mensaje.
>
>
>
> ------------------------------------------------------------------------
> See OpenCollab email disclaimer at 
> http://www.opencollab.co.za/email-disclaimer 
> <http://www.opencollab.co.za/email-disclaimer> 

-- 
Miguel Carro Pellicer
Logo 	

Miguel Carro 
Pellicer<http://es.linkedin.com/pub/miguel-carro-pellicer/38/502/b92>
/IT Consultant - Elearning solutions/

Phone: +34 - 686266485
Email: miguel at educlever.es <mailto:miguel at educlever.es>

No me imprimas si no es necesario. Protejamos el medio ambiente


AVISO LEGAL: El contenido de este mensaje de correo electrónico, 
incluidos los ficheros adjuntos, es confidencial y está protegido por el 
artículo 18.3 de la Constitución Española, que garantiza el secreto de 
las comunicaciones.
Si usted recibe este mensaje por error, por favor póngase en contacto 
con el remitente para informarle de este hecho, y no difunda su 
contenido ni haga copias.
*** Este mensaje ha sido verificado con herramientas de eliminación de 
virus y contenido malicioso ***
Este aviso legal ha sido incorporado automáticamente al mensaje.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://collab.sakaiproject.org/pipermail/sakai-dev/attachments/20140324/d7beca12/attachment.html 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: image/png
Size: 8960 bytes
Desc: not available
Url : http://collab.sakaiproject.org/pipermail/sakai-dev/attachments/20140324/d7beca12/attachment.png 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: image/jpeg
Size: 1103 bytes
Desc: not available
Url : http://collab.sakaiproject.org/pipermail/sakai-dev/attachments/20140324/d7beca12/attachment.jpe 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: AF-BRAND---EDUCLEVER-01.png
Type: image/png
Size: 8960 bytes
Desc: not available
Url : http://collab.sakaiproject.org/pipermail/sakai-dev/attachments/20140324/d7beca12/attachment-0001.png 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: linkedin.jpg
Type: image/jpeg
Size: 1103 bytes
Desc: not available
Url : http://collab.sakaiproject.org/pipermail/sakai-dev/attachments/20140324/d7beca12/attachment.jpg 
-------------- next part --------------
Index: samigo-2.9.0/samigo-app/src/java/org/sakaiproject/tool/assessment/bundle/DeliveryMessages_es.properties
===================================================================
--- samigo-2.9.0/samigo-app/src/java/org/sakaiproject/tool/assessment/bundle/DeliveryMessages_es.properties	(revisión: 298)
+++ samigo-2.9.0/samigo-app/src/java/org/sakaiproject/tool/assessment/bundle/DeliveryMessages_es.properties	(revisión: 299)
@@ -458,4 +458,7 @@
 email_subject=Asunto:
 email_to=Para:
 
-candidateAnnotationText = Anotaciones
\ No newline at end of file
+candidateAnnotationText = Anotaciones
+
+submission_email_subject=Nueva entrega de examen en el sitio {0}
+submission_email_message=Tienes una nueva entrega del examen {0} en el sitio {1}.
\ No newline at end of file
Index: samigo-2.9.0/samigo-app/src/java/org/sakaiproject/tool/assessment/bundle/DeliveryMessages.properties
===================================================================
--- samigo-2.9.0/samigo-app/src/java/org/sakaiproject/tool/assessment/bundle/DeliveryMessages.properties	(revisión: 298)
+++ samigo-2.9.0/samigo-app/src/java/org/sakaiproject/tool/assessment/bundle/DeliveryMessages.properties	(revisión: 299)
@@ -514,4 +514,7 @@
 email_subject=Subject:
 email_to=To:
 
-candidateAnnotationText = Annotations
\ No newline at end of file
+candidateAnnotationText = Annotations
+
+submission_email_subject=New submission in the site {0}
+submission_email_message=You have a new submission for the assessment {0} in the site {1}.
\ No newline at end of file
Index: samigo-2.9.0/samigo-app/src/java/org/sakaiproject/tool/assessment/ui/bean/delivery/DeliveryBean.java
===================================================================
--- samigo-2.9.0/samigo-app/src/java/org/sakaiproject/tool/assessment/ui/bean/delivery/DeliveryBean.java	(revisión: 298)
+++ samigo-2.9.0/samigo-app/src/java/org/sakaiproject/tool/assessment/ui/bean/delivery/DeliveryBean.java	(revisión: 299)
@@ -30,6 +30,7 @@
 import java.io.IOException;
 import java.io.Serializable;
 import java.text.SimpleDateFormat;
+import java.text.MessageFormat;
 import java.util.ArrayList;
 import java.util.Calendar;
 import java.util.Date;
@@ -52,6 +53,7 @@
 import org.sakaiproject.site.api.SitePage;
 import org.sakaiproject.site.api.ToolConfiguration;
 import org.sakaiproject.site.cover.SiteService;
+import org.sakaiproject.authz.cover.SecurityService;
 import org.sakaiproject.tool.api.Placement;
 import org.sakaiproject.tool.assessment.api.SamigoApiFactory;
 import org.sakaiproject.tool.assessment.data.dao.assessment.PublishedAssessmentData;
@@ -92,8 +94,11 @@
 import org.sakaiproject.tool.cover.SessionManager;
 import org.sakaiproject.tool.api.Session;
 import org.sakaiproject.util.ResourceLoader;
+import org.sakaiproject.user.api.User;
+import org.sakaiproject.user.cover.UserDirectoryService;
 import org.sakaiproject.event.cover.EventTrackingService;
 import org.sakaiproject.event.cover.NotificationService;
+import org.sakaiproject.tool.assessment.util.SamigoEmailService;
 
 /**
  *
@@ -1472,6 +1477,18 @@
 		  gradingService.completeItemGradingData(adata);
 	  }
 
+	  /***Custom Code - Send Email notifications***/
+	  try{
+		  ArrayList<String> recipientsAddresses = getSubmissionRecipientsList();
+		  String ccMe = "";
+		  String message=MessageFormat.format((String)ContextUtil.getLocalizedString("org.sakaiproject.tool.assessment.bundle.DeliveryMessages", "submission_email_message"),this.getAssessmentTitle(),this.getCurrentSite(AgentFacade.getCurrentSiteId()).getTitle());
+		  String subject=MessageFormat.format((String)ContextUtil.getLocalizedString("org.sakaiproject.tool.assessment.bundle.DeliveryMessages", "submission_email_subject"),this.getCurrentSite(AgentFacade.getCurrentSiteId()).getTitle());
+		  SamigoEmailService samigoEmailService = new SamigoEmailService(null, recipientsAddresses, ccMe, subject, message);
+		  samigoEmailService.sendMail();
+		}catch(Exception ex){
+			log.error("***** submitForGrade: Error sending emails confirming the new submission siteId=" + AgentFacade.getCurrentSiteId() + ", submissionId=" + adata.getAssessmentGradingId());
+		}		
+	  /***Custom Code - Send Email notifications***/
 	  String returnValue="submitAssessment";
 	  if (!isFromTimer) {
 		  if (this.actionMode == TAKE_ASSESSMENT_VIA_URL) // this is for accessing via published url
@@ -3553,5 +3570,36 @@
 	  {
 		this.candidateAnnotationText = candidateAnnotationText;
 	  }
+	  
+	  public ArrayList<String> getSubmissionRecipientsList()
+	{
+		ArrayList<String> ret = new ArrayList<String>();
+		try 
+		{
+			Site site = SiteService.getSite(ToolManager.getCurrentPlacement().getContext());
+			String locationId = site.getReference();
+			// get all users from site
+			Set<String> set = site.getUsers();
+			for (String s : set) 
+			{
+				try 
+				{
+					// check permissions
+					if (SecurityService.unlock(s, "assessment.gradeAssessment.all", locationId) || SecurityService.unlock(s, "assessment.gradeAssessment.any", locationId) || SecurityService.unlock(s, "assessment.gradeAssessment.own", locationId)) 
+					{
+						User u = UserDirectoryService.getUser(s);
+						if(!"".equals(u.getEmail()) && u.getEmail() != null)
+							ret.add(new String(u.getEmail()));
+					}
+				} catch (Exception ex) {
+					log.warn("getSubmissionRecipientsList (user: " + s + ") -> " + ex);
+				}
+			}
+		} catch (Exception e) {
+			log.warn("getSubmissionRecipientsList -> " + e);
+		}
+
+		return ret;
+	}
 }
 
Index: samigo-2.9.0/samigo-app/src/java/org/sakaiproject/tool/assessment/util/SamigoEmailService.java
===================================================================
--- samigo-2.9.0/samigo-app/src/java/org/sakaiproject/tool/assessment/util/SamigoEmailService.java	(revisión: 298)
+++ samigo-2.9.0/samigo-app/src/java/org/sakaiproject/tool/assessment/util/SamigoEmailService.java	(revisión: 299)
@@ -36,6 +36,7 @@
 import javax.activation.FileDataSource;
 import javax.mail.Message;
 import javax.mail.MessagingException;
+import javax.mail.PasswordAuthentication;
 import javax.mail.Multipart;
 import javax.mail.SendFailedException;
 import javax.mail.Session;
@@ -77,6 +78,9 @@
 	private String message;
 	private String smtpServer;
 	private String smtpPort;
+	private String smtpUser;
+	private String smtpPassword;
+	private String smtpUseSSL;
 	private String prefixedPath;
 	
 	/**
@@ -92,8 +96,11 @@
 		this.ccMe = ccMe;
 		this.subject = subject;
 		this.message = message;
-		this.smtpServer = ServerConfigurationService.getString("samigo.smtp.server");
-		this.smtpPort = ServerConfigurationService.getString("samigo.smtp.port");
+		this.smtpServer = ServerConfigurationService.getString("smtp at org.sakaiproject.email.api.EmailService");
+		this.smtpPort = ServerConfigurationService.getString("smtpPort at org.sakaiproject.email.api.EmailService","25");
+		this.smtpUser = ServerConfigurationService.getString("smtpUser at org.sakaiproject.email.api.EmailService");
+		this.smtpPassword = ServerConfigurationService.getString("smtpPassword at org.sakaiproject.email.api.EmailService");
+		this.smtpUseSSL = ServerConfigurationService.getString("smtpUseSSL at org.sakaiproject.email.api.EmailService","false");
 		this.prefixedPath = ServerConfigurationService.getString("samigo.email.prefixedPath");
 	}
 	
@@ -235,7 +242,36 @@
 	public String sendMail() {
 		try {
 			Properties props = new Properties();
-
+			// From
+			if (fromEmailAddress == null || fromEmailAddress.equals("")) {
+				log.info("smtpFrom is not set");
+				fromEmailAddress = ServerConfigurationService.getString("smtpFrom at org.sakaiproject.email.api.EmailService");
+				if (fromEmailAddress == null || fromEmailAddress.equals("")) {
+					log.info("smtpFrom at org.sakaiproject.email.api.EmailService is not set");
+					log.error("Please set the value of smtpFrom at org.sakaiproject.email.api.EmailService");
+					return "error";
+				}
+			}
+			// User
+			if (smtpUser == null || smtpUser.equals("")) {
+				log.info("smtpUser is not set");
+				smtpUser = ServerConfigurationService.getString("smtpUser at org.sakaiproject.email.api.EmailService");
+				if (smtpUser == null || smtpUser.equals("")) {
+					log.info("smtpUser at org.sakaiproject.email.api.EmailService is not set");
+					log.error("Please set the value of smtpUser at org.sakaiproject.email.api.EmailService");
+					return "error";
+				}
+			}
+			// Password
+			if (smtpPassword == null || smtpPassword.equals("")) {
+				log.info("smtpPassword is not set");
+				smtpPassword = ServerConfigurationService.getString("smtpPassword at org.sakaiproject.email.api.EmailService");
+				if (smtpPassword == null || smtpPassword.equals("")) {
+					log.info("smtpPassword at org.sakaiproject.email.api.EmailService is not set");
+					log.error("Please set the value of smtpPassword at org.sakaiproject.email.api.EmailService");
+					return "error";
+				}
+			}
 			// Server
 			if (smtpServer == null || smtpServer.equals("")) {
 				log.info("samigo.email.smtpServer is not set");
@@ -251,13 +287,21 @@
 			// Port
 			if (smtpPort == null || smtpPort.equals("")) {
 				log.warn("samigo.email.smtpPort is not set. The default port 25 will be used.");
-			} else {
-				props.setProperty("mail.smtp.port", smtpPort);
+				smtpPort = ServerConfigurationService.getString("smtpPort at org.sakaiproject.email.api.EmailService","25");
 			}
 			
+			props.setProperty("mail.smtp.port", smtpPort);
+			//Undefined Email parameters
+			props.put("mail.smtp.auth", "true");
+			props.put("mail.smtp.starttls.enable","true");
+			props.put("mail.smtp.ssl.enable", ServerConfigurationService.getString("smtpUseSSL at org.sakaiproject.email.api.EmailService","false"));
 			props.put("mail.smtp.sendpartial", "true");
 			
-			Session session = Session.getInstance(props, null);
+			Session session = Session.getInstance(props, new javax.mail.Authenticator() {
+			protected PasswordAuthentication getPasswordAuthentication() {
+				return new PasswordAuthentication(smtpUser, smtpPassword);
+			}
+		  });
 			session.setDebug(true);
 			MimeMessage msg = new MimeMessage(session);
 


More information about the sakai-dev mailing list