Commits

mark...@ucop.edu  committed d3adbff

Simplified notification requested by Carly for Datashare et. al.

  • Participants
  • Parent commits 287dc59

Comments (0)

Files changed (4)

File ingest-src/src/main/java/org/cdlib/mrt/ingest/ProfileState.java

     private String misc = null;
     private String dataoneNodeID = null;
     private String ezidCoowner = null;
-    private FormatType notificationFormat = null;		// default
+    private FormatType notificationFormat = null;	// response type
+    private String notificationType = null;		// human readable notification 
 
     final String[] OBJECTTYPE = { "MRT-curatorial", "MRT-system" };
     final String[] OBJECTROLE = { "MRT-content", "MRT-class" };
         return notificationFormat;
     }
 
+    public String getNotificationType() {
+        return notificationType;
+    }
+
     public String getEzidCoowner() {
         return ezidCoowner;
     }
         }
     }
 
+    public void setNotificationType(String notificationType) {
+	this.notificationType = notificationType;
+    }
+
     public String dump(String header)
     {
         return header

File ingest-src/src/main/java/org/cdlib/mrt/ingest/handlers/HandlerNotification.java

         JobState jobState = ingestRequest.getJob();
 	boolean isBatch = true;
 	boolean batchComplete = false;
+	boolean verbose = false;
         FormatterUtil formatterUtil = new FormatterUtil();
 	FormatType formatType = null;
 
 	try {
+            if (profileState.getNotificationType().equalsIgnoreCase("verbose")) {
+                if (DEBUG) System.out.println("[info] " + MESSAGE + "Detected 'verbose' format type.");
+                verbose = true;
+            }
+
 	    // Is this a batch submission?
 	    if (jobState.grabBatchID().getValue().equalsIgnoreCase(ProfileUtil.DEFAULT_BATCH_ID)) {
 		isBatch = false;
 		       aggregate = "[" + profileState.getAggregateType() + "] ";
 		} catch (NullPointerException npe) {}
 
-  	        email.setSubject(FormatterUtil.getSubject(SERVICE, server, status, "Submission Processed", aggregate + batchState.getBatchID().getValue()));
+		if (! verbose) 
+  	            email.setSubject(FormatterUtil.getSubject(SERVICE, server, status, "Submission Processed", aggregate + batchState.getBatchID().getValue()));
+		else {
+		    try {
+  	                email.setSubject("Submission Processed: " + jobState.getLocalID().getValue());
+		    } catch (Exception e) {
+  	                email.setSubject("Submission Processed: " + jobState.getPrimaryID().getValue());
+		    }
+		}
 
 		// Comma delimited
 		//email.attach(new ByteArrayDataSource(batchState.dump("", false, true), "text/csv; header=present"),
 			 batchID + ".txt", "Full report for " +  batchID, EmailAttachment.ATTACHMENT);
 		}
 
-		email.setMsg(batchState.dump("", false, false));	// summary only
+		if (! verbose) 
+		    email.setMsg(batchState.dump("", false, false));	// summary only
+		else
+  	            email.setMsg(getVerboseMsg(jobState));
+
 		try {
   	            email.send();
 		} catch (Exception e) {
 	}
     }
 
+    private String getVerboseMsg(JobState jobState) {
+
+	String id = null;
+        try {
+	    id = jobState.getLocalID().getValue();
+	} catch (Exception e) {
+	    id = jobState.getPrimaryID().getValue();
+	}
+
+	String msg = 
+	    "The dataset \"" + jobState.getObjectTitle() + "\" was successfully uploaded at " + jobState.getCompletionDate().toString() + ".\n"
+	  + "The identifier associated with this dataset is " + id + ". Please retain\n"
+	  + "this email for your records.\n\n"
+	  + "To access this dataset and associated metadata, use the following URL: \n"
+	  + jobState.getPersistentURL() + "\n";
+	return msg;
+    }
 
     public String getName() {
 	return NAME;

File ingest-src/src/main/java/org/cdlib/mrt/ingest/handlers/queue/HandlerNotification.java

         String batchID = batchState.getBatchID().getValue();
 
 	try {
+	    if (profileState.getNotificationType().equalsIgnoreCase("verbose")) {
+                if (DEBUG) System.out.println("[info] " + MESSAGE + "Detected 'verbose' format type.  Skipping notification.");
+                return new HandlerResult(true, "SUCCESS: " + NAME + " no notification required", 0);
+	    }
 
   	    email.setHostName("localhost");	// production machines are SMTP enabled
 	    for (Notification recipient : profileState.getContactsEmail()) {
 		    notify(e.getMessage() + " - " + recipient.getContactEmail(), profileState, ingestRequest); 
 		}
 	    }
+            if (profileState.getAdmin() != null) {
+                for (Iterator<String> admin = profileState.getAdmin().iterator(); admin.hasNext(); ) {
+                    // admin will receive all completion notifications
+                    String recipient = admin.next();
+                    if (StringUtil.isNotEmpty(recipient)) email.addBcc(recipient);
+                }
+            }
+
   	    email.setFrom("uc3@ucop.edu", "UC3 Merritt Support");
 
             String server = null;

File ingest-src/src/main/java/org/cdlib/mrt/ingest/utility/ProfileUtil.java

     private static final String matchContext = "Context";
     private static final String matchEzidCoowner = "EZID_co-owner";
     private static final String matchNotificationFormat = "NotificationFormat";
+    private static final String matchNotificationType = "NotificationType";
     
     public static synchronized ProfileState getProfile(Identifier profileName, String ingestDir)
         throws TException
 		} else if (key.startsWith(matchNotificationFormat)) {
                     if (DEBUG) System.out.println("[debug] notification format: " + value);
 		    profileState.setNotificationFormat(value);
+		} else if (key.startsWith(matchNotificationType)) {
+                    if (DEBUG) System.out.println("[debug] notification type: " + value);
+		    profileState.setNotificationType(value);
 	        } else {
                     if (DEBUG) System.out.println("[debug] could not procces profile parameter: " + key);
 		}