99 lines
2.9 KiB
Java
99 lines
2.9 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 {
|
|
|
|
private Calendar startTime;
|
|
|
|
private String taskId;
|
|
|
|
private String scope;
|
|
|
|
private Exception executionException;
|
|
|
|
public NotificationHelper() {
|
|
***REMOVED***
|
|
|
|
public void setStartTime(Calendar startTime) {
|
|
this.startTime = startTime;
|
|
***REMOVED***
|
|
|
|
public void setTaskId(String taskId) {
|
|
this.taskId = taskId;
|
|
***REMOVED***
|
|
|
|
public void setScope(String scope) {
|
|
this.scope = scope;
|
|
***REMOVED***
|
|
|
|
private String getSubjectHeader() {
|
|
return "[DataMinerGhostInstallationRequestReport]";
|
|
***REMOVED***
|
|
|
|
private String getSpecificVREName() {
|
|
if(this.scope!=null) {
|
|
String[] parts = this.scope.split("/");
|
|
if(parts.length>=3) {
|
|
return StringUtils.join(Arrays.copyOfRange(parts, 3, parts.length), "/");
|
|
***REMOVED***
|
|
***REMOVED***
|
|
return this.scope;
|
|
***REMOVED***
|
|
|
|
private boolean isError() {
|
|
return this.executionException!=null;
|
|
***REMOVED***
|
|
|
|
public void setExecutionException(Exception executionException) {
|
|
this.executionException = executionException;
|
|
***REMOVED***
|
|
|
|
private String getSuccessSubject() {
|
|
return String.format("%s Results for your experiment '%s' are ready", this.getSubjectHeader(), this.taskId);
|
|
***REMOVED***
|
|
|
|
private String getFailedSubject() {
|
|
return String.format("%s An error occurred while executing your experiment '%s'", this.getSubjectHeader(), this.taskId);
|
|
***REMOVED***
|
|
|
|
private String getFormattedStartTime() {
|
|
SimpleDateFormat sdf = new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss Z");
|
|
return sdf.format(this.startTime.getTime());
|
|
***REMOVED***
|
|
|
|
private String getSuccessBody() {
|
|
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() {
|
|
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() {
|
|
if(this.isError()) {
|
|
return this.getFailedSubject();
|
|
***REMOVED*** else {
|
|
return this.getSuccessSubject();
|
|
***REMOVED***
|
|
***REMOVED***
|
|
|
|
public String getBody() {
|
|
if(this.isError()) {
|
|
return this.getFailedBody();
|
|
***REMOVED*** else {
|
|
return this.getSuccessBody();
|
|
***REMOVED***
|
|
***REMOVED***
|
|
|
|
***REMOVED***
|