2016-09-27 16:27:28 +02:00
package org.gcube.dataanalysis.ecoengine.interfaces ;
2016-09-29 12:49:16 +02:00
import java.net.URLEncoder ;
2016-09-27 16:27:28 +02:00
2016-09-29 12:49:16 +02:00
import org.gcube.contentmanagement.graphtools.utils.HttpRequest ;
2016-09-27 16:27:28 +02:00
import org.gcube.contentmanagement.lexicalmatcher.utils.AnalysisLogger ;
2016-09-29 12:49:16 +02:00
import org.gcube.dataanalysis.executor.util.InfraRetrieval ;
public abstract class StandardLocalInfraAlgorithm extends StandardLocalExternalAlgorithm {
2016-09-27 16:27:28 +02:00
2016-09-29 12:49:16 +02:00
public void sendNotificationEmail ( String subject , String body ) throws Exception {
AnalysisLogger . getLogger ( ) . debug ( " Emailing System->Starting request of email in scope " + config . getGcubeScope ( ) ) ;
String serviceAddress = InfraRetrieval . findEmailingSystemAddress ( config . getGcubeScope ( ) ) ;
String requestForMessage = serviceAddress + " /messages/writeMessageToUsers " + " ?gcube-token= " + config . getGcubeToken ( ) ;
2016-09-29 12:52:56 +02:00
requestForMessage = requestForMessage . replace ( " http:// " , " https:// " ) . replace ( " 80 " , " " ) ; // remove the port (or set it to 443) otherwise you get an SSL error
2016-09-29 12:49:16 +02:00
AnalysisLogger . getLogger ( ) . debug ( " Emailing System->Request url is going to be " + requestForMessage ) ;
// put the sender, the recipients, subject and body of the mail here
subject = URLEncoder . encode ( subject , " UTF-8 " ) ;
body = URLEncoder . encode ( body , " UTF-8 " ) ;
String requestParameters = " sender=dataminer&recipients= " + config . getGcubeUserName ( ) + " &subject= " + subject + " &body= " + body ;
String response = HttpRequest . sendPostRequest ( requestForMessage , requestParameters ) ;
AnalysisLogger . getLogger ( ) . debug ( " Emailing System->Emailing response OK " ) ;
if ( response = = null ) {
Exception e = new Exception ( " Error in email sending response " ) ;
throw e ;
}
2016-09-27 16:27:28 +02:00
}
2016-09-29 12:49:16 +02:00
2016-09-27 16:27:28 +02:00
}