dataminer-pool-manager/src/main/java/org/gcube/dataanalysis/dataminer/poolmanager/util/NotificationHelper.java

99 lines
3.2 KiB
Java

package org.gcube.dataanalysis.dataminer.poolmanager.util;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import org.apache.commons.lang.StringUtils;
import scala.actors.threadpool.Arrays;
public class NotificationHelper ***REMOVED***
private Calendar startTime;
private String taskId;
private String scope;
private Exception executionException;
public NotificationHelper() ***REMOVED***
***REMOVED***
public void setStartTime(Calendar startTime) ***REMOVED***
this.startTime = startTime;
***REMOVED***
public void setTaskId(String taskId) ***REMOVED***
this.taskId = taskId;
***REMOVED***
public void setScope(String scope) ***REMOVED***
this.scope = scope;
***REMOVED***
private String getSubjectHeader() ***REMOVED***
return "[[DataMinerGhostInstallationRequestReport]]";
***REMOVED***
private String getSpecificVREName() ***REMOVED***
if(this.scope!=null) ***REMOVED***
String[] parts = this.scope.split("/");
if(parts.length>=3) ***REMOVED***
return StringUtils.join(Arrays.copyOfRange(parts, 3, parts.length), "/");
***REMOVED***
***REMOVED***
return this.scope;
***REMOVED***
private boolean isError() ***REMOVED***
return this.executionException!=null;
***REMOVED***
public void setExecutionException(Exception executionException) ***REMOVED***
this.executionException = executionException;
***REMOVED***
private String getSuccessSubject() ***REMOVED***
return String.format("%s Results for your experiment '%s' are ready", this.getSubjectHeader(), this.taskId);
***REMOVED***
private String getFailedSubject() ***REMOVED***
return String.format("%s An error occurred while executing your experiment '%s'", this.getSubjectHeader(), this.taskId);
***REMOVED***
private String getFormattedStartTime() ***REMOVED***
SimpleDateFormat sdf = new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss Z");
return sdf.format(this.startTime.getTime());
***REMOVED***
private String getSuccessBody() ***REMOVED***
String message = String.format("Your experiment '%s' submitted on %s in the '%s' VRE completed successfully.", this.taskId, this.getFormattedStartTime(), this.getSpecificVREName());
message+="\n\nYou can retrieve experiment results under the '/DataMiner' e-Infrastructure Workspace folder or from the DataMiner interface.";
return message;
***REMOVED***
private String getFailedBody() ***REMOVED***
String message = String.format("An error occurred while executing your experiment '%s' submitted on %s in the '%s' VRE.", this.taskId, this.getFormattedStartTime(), this.getSpecificVREName());
message+= "\n\nHere are the error details:\n\n" + this.executionException;
return message;
***REMOVED***
public String getSubject() ***REMOVED***
if(this.isError()) ***REMOVED***
return this.getFailedSubject();
***REMOVED*** else ***REMOVED***
return this.getSuccessSubject();
***REMOVED***
***REMOVED***
public String getBody() ***REMOVED***
if(this.isError()) ***REMOVED***
return this.getFailedBody();
***REMOVED*** else ***REMOVED***
return this.getSuccessBody();
***REMOVED***
***REMOVED***
***REMOVED***