Skip to content
Snippets Groups Projects
Commit ae59f565 authored by kaloyane's avatar kaloyane
Browse files

[LMS-2332] more email changes

SVN: 22119
parent 6de0794c
No related branches found
No related tags found
No related merge requests found
...@@ -19,8 +19,6 @@ from ch.systemsx.cisd.openbis.dss.etl.dto.api.v1 import SimpleImageDataConfig, I ...@@ -19,8 +19,6 @@ from ch.systemsx.cisd.openbis.dss.etl.dto.api.v1 import SimpleImageDataConfig, I
from ch.systemsx.cisd.openbis.dss.etl.custom.geexplorer import GEExplorerImageAnalysisResultParser from ch.systemsx.cisd.openbis.dss.etl.custom.geexplorer import GEExplorerImageAnalysisResultParser
from ch.systemsx.cisd.openbis.plugin.screening.shared.api.v1.dto import Geometry from ch.systemsx.cisd.openbis.plugin.screening.shared.api.v1.dto import Geometry
from ch.systemsx.cisd.openbis.dss.generic.shared import ServiceProvider
# Switch this off if there is more then one dropbox using this module, # Switch this off if there is more then one dropbox using this module,
# in this case it should be switched on manually only after the module's code has been changed on the fly # in this case it should be switched on manually only after the module's code has been changed on the fly
reload(plateinit) reload(plateinit)
...@@ -79,21 +77,52 @@ def isUserError(ex): ...@@ -79,21 +77,52 @@ def isUserError(ex):
return ex.value and (ex.value.getClass() == ValidationException("").getClass()) return ex.value and (ex.value.getClass() == ValidationException("").getClass())
def getAdminEmails(): def getAdminEmails():
admins = ServiceProvider.getOpenBISService().listAdministrators() admins = state.getOpenBisService().listAdministrators()
adminEmails = [ admin.getEmail() for admin in admins if admin.getEmail() ] adminEmails = [ admin.getEmail() for admin in admins if admin.getEmail() ]
return adminEmails return adminEmails
def getUserEmails():
global experiment
recipients = []
if experiment:
recipientsProp = experiment.getPropertyValue(EXPERIMENT_RECIPIENTS_PROPCODE)
if recipientsProp:
recipients = [ email.strip() for email in recipientsProp.split(",") ]
return recipients
def getAllEmailRecipients():
return getAdminEmails() + getUserEmails()
def commit_transaction(service, transaction):
global plateCode
incomingFileName = incoming.getName()
plateLink = createPlateLink(OPENBIS_URL, plateCode)
sendEmail("openBIS: New data registered for %s" % (plateCode), """
Dear openBIS user,
New data from folder '%(incomingFileName)s' has been successfully registered in plate %(plateLink)s.
This email has been generated automatically.
Have a nice day!
Administrator
""" % vars(), getAllEmailRecipients())
def rollback_service(service, ex): def rollback_service(service, ex):
if isUserError(ex): if isUserError(ex):
shortErrorMessage = ex.getMessage() shortErrorMessage = ex.getMessage()
if not shortErrorMessage: if not shortErrorMessage:
shortErrorMessage = ex.value.getMessage() shortErrorMessage = ex.value.getMessage()
sendUserError(service, shortErrorMessage, getDefaultEmailRecipients()) sendUserError(service, shortErrorMessage, getAllEmailRecipients())
else: else:
fullErrorMessage = ExceptionUtils.getFullStackTrace(ex) fullErrorMessage = ExceptionUtils.getFullStackTrace(ex)
sendAdminError(service, fullErrorMessage, getAdminEmails()) sendAdminError(service, fullErrorMessage, getAdminEmails())
sendSystemErrorNotificationToUser(service, getDefaultEmailRecipients()) sendSystemErrorNotificationToUser(service, getUserEmails())
def sendUserError(service, errorDetails, recipients): def sendUserError(service, errorDetails, recipients):
global plateCode global plateCode
...@@ -158,35 +187,6 @@ def sendSystemErrorNotificationToUser(service, recipients): ...@@ -158,35 +187,6 @@ def sendSystemErrorNotificationToUser(service, recipients):
openBIS Administrators openBIS Administrators
""" % vars(), recipients) """ % vars(), recipients)
def commit_transaction(service, transaction):
global plateCode
incomingFileName = incoming.getName()
plateLink = createPlateLink(OPENBIS_URL, plateCode)
sendEmail("openBIS: New data registered for %s" % (plateCode), """
Dear openBIS user,
New data from folder '%(incomingFileName)s' has been successfully registered in plate %(plateLink)s.
This email has been generated automatically.
Have a nice day!
Administrator
""" % vars(), getDefaultEmailRecipients())
def getDefaultEmailRecipients():
global experiment
recipients = []
if experiment:
recipientsProp = experiment.getPropertyValue(EXPERIMENT_RECIPIENTS_PROPCODE)
if recipientsProp:
recipients = [ email.strip() for email in recipientsProp.split(",") ]
return recipients
def sendEmail(title, content, recipients): def sendEmail(title, content, recipients):
global experiment global experiment
...@@ -321,7 +321,7 @@ class MyImageDataSetConfig(SimpleImageDataConfig): ...@@ -321,7 +321,7 @@ class MyImageDataSetConfig(SimpleImageDataConfig):
global experiment global experiment
global plateCode global plateCode
global plate global plate
if incoming.isDirectory(): if incoming.isDirectory():
experiment = None experiment = None
plateCode = None plateCode = None
......
/* /*
* Copyright 2011 ETH Zuerich, CISD * Copyright 2011 ETH Zuerich, CISD
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -32,7 +33,6 @@ import java.util.Properties; ...@@ -32,7 +33,6 @@ import java.util.Properties;
import org.apache.commons.io.FileUtils; import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.jmock.Expectations; import org.jmock.Expectations;
import org.springframework.beans.factory.BeanFactory;
import org.testng.annotations.BeforeMethod; import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test; import org.testng.annotations.Test;
...@@ -51,7 +51,6 @@ import ch.systemsx.cisd.etlserver.registrator.DataSetRegistrationService; ...@@ -51,7 +51,6 @@ import ch.systemsx.cisd.etlserver.registrator.DataSetRegistrationService;
import ch.systemsx.cisd.etlserver.registrator.DataSetStorageAlgorithmRunner; import ch.systemsx.cisd.etlserver.registrator.DataSetStorageAlgorithmRunner;
import ch.systemsx.cisd.etlserver.registrator.api.v1.impl.DataSetRegistrationTransaction; import ch.systemsx.cisd.etlserver.registrator.api.v1.impl.DataSetRegistrationTransaction;
import ch.systemsx.cisd.openbis.dss.etl.jython.JythonPlateDataSetHandler; import ch.systemsx.cisd.openbis.dss.etl.jython.JythonPlateDataSetHandler;
import ch.systemsx.cisd.openbis.dss.generic.shared.ServiceProviderTestWrapper;
import ch.systemsx.cisd.openbis.dss.generic.shared.dto.DataSetInformation; import ch.systemsx.cisd.openbis.dss.generic.shared.dto.DataSetInformation;
import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.SearchCriteria; import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.SearchCriteria;
import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.SearchCriteria.MatchClause; import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.SearchCriteria.MatchClause;
...@@ -93,8 +92,14 @@ public class SanofiDropboxJythonTest extends AbstractJythonDataSetHandlerTest ...@@ -93,8 +92,14 @@ public class SanofiDropboxJythonTest extends AbstractJythonDataSetHandlerTest
private static final String EXPERIMENT_RECIPIENTS_PROPNAME = "OBSERVER_EMAILS"; private static final String EXPERIMENT_RECIPIENTS_PROPNAME = "OBSERVER_EMAILS";
private static final String[] EXPERIMENT_RECIPIENTS = new String[] private static final String[] USER_EMAILS = new String[]
{ "admin@sanofi.com", "mickey@mouse.org" }; { "donald@duck.com", "mickey@mouse.org" };
final String[] ADMIN_EMAILS = new String[]
{ "admin@sanofi.com", "admin@openbis.org" };
final String[] ALL_EMAILS = new String[]
{ "admin@sanofi.com", "admin@openbis.org", "donald@duck.com", "mickey@mouse.org" };
private static final String MATERIAL_TYPE = "COMPOUND"; private static final String MATERIAL_TYPE = "COMPOUND";
...@@ -139,15 +144,11 @@ public class SanofiDropboxJythonTest extends AbstractJythonDataSetHandlerTest ...@@ -139,15 +144,11 @@ public class SanofiDropboxJythonTest extends AbstractJythonDataSetHandlerTest
private RecordingMatcher<String> email; private RecordingMatcher<String> email;
private BeanFactory applicationContext;
@Override @Override
@BeforeMethod @BeforeMethod
public void setUp() throws IOException public void setUp() throws IOException
{ {
super.setUp(); super.setUp();
applicationContext = context.mock(BeanFactory.class);
extendJythonLibPath(getRegistrationScriptsFolderPath()); extendJythonLibPath(getRegistrationScriptsFolderPath());
...@@ -155,29 +156,14 @@ public class SanofiDropboxJythonTest extends AbstractJythonDataSetHandlerTest ...@@ -155,29 +156,14 @@ public class SanofiDropboxJythonTest extends AbstractJythonDataSetHandlerTest
new RecordingMatcher<ch.systemsx.cisd.openbis.generic.shared.dto.AtomicEntityOperationDetails>(); new RecordingMatcher<ch.systemsx.cisd.openbis.generic.shared.dto.AtomicEntityOperationDetails>();
materialCriteria = new RecordingMatcher<ListMaterialCriteria>(); materialCriteria = new RecordingMatcher<ListMaterialCriteria>();
email = new RecordingMatcher<String>(); email = new RecordingMatcher<String>();
ServiceProviderTestWrapper.setApplicationContext(applicationContext);
context.checking(new Expectations()
{
{
allowing(applicationContext).getBean("openBIS-service");
will(returnValue(openBisService));
}
});
}
@Override
public void tearDown() throws IOException
{
super.tearDown();
ServiceProviderTestWrapper.restoreApplicationContext();
} }
@Test @Test
public void testLibraryWider() throws IOException public void testLibraryWider() throws IOException
{ {
createDataSetHandler(false, false); createDataSetHandler(false, false);
setUpListAdministratorExpectations();
final Sample plate = final Sample plate =
plateWithLibTemplateAndGeometry("1.45\t\tH\n0.12\t0.002\tL", "10_WELLS_1X10"); plateWithLibTemplateAndGeometry("1.45\t\tH\n0.12\t0.002\tL", "10_WELLS_1X10");
context.checking(new Expectations() context.checking(new Expectations()
...@@ -191,7 +177,7 @@ public class SanofiDropboxJythonTest extends AbstractJythonDataSetHandlerTest ...@@ -191,7 +177,7 @@ public class SanofiDropboxJythonTest extends AbstractJythonDataSetHandlerTest
one(mailClient).sendMessage(with(any(String.class)), with(email), one(mailClient).sendMessage(with(any(String.class)), with(email),
with(aNull(String.class)), with(any(From.class)), with(aNull(String.class)), with(any(From.class)),
with(equal(EXPERIMENT_RECIPIENTS))); with(equal(ALL_EMAILS)));
} }
}); });
...@@ -217,6 +203,8 @@ public class SanofiDropboxJythonTest extends AbstractJythonDataSetHandlerTest ...@@ -217,6 +203,8 @@ public class SanofiDropboxJythonTest extends AbstractJythonDataSetHandlerTest
createDataSetHandler(false, false); createDataSetHandler(false, false);
final Sample plate = final Sample plate =
plateWithLibTemplateAndGeometry("1.45\t\tH\n0.12\t0.002\tL", "5_WELLS_5X1"); plateWithLibTemplateAndGeometry("1.45\t\tH\n0.12\t0.002\tL", "5_WELLS_5X1");
setUpListAdministratorExpectations();
context.checking(new Expectations() context.checking(new Expectations()
{ {
{ {
...@@ -228,7 +216,7 @@ public class SanofiDropboxJythonTest extends AbstractJythonDataSetHandlerTest ...@@ -228,7 +216,7 @@ public class SanofiDropboxJythonTest extends AbstractJythonDataSetHandlerTest
one(mailClient).sendMessage(with(any(String.class)), with(email), one(mailClient).sendMessage(with(any(String.class)), with(email),
with(aNull(String.class)), with(any(From.class)), with(aNull(String.class)), with(any(From.class)),
with(equal(EXPERIMENT_RECIPIENTS))); with(equal(ALL_EMAILS)));
} }
}); });
...@@ -253,6 +241,7 @@ public class SanofiDropboxJythonTest extends AbstractJythonDataSetHandlerTest ...@@ -253,6 +241,7 @@ public class SanofiDropboxJythonTest extends AbstractJythonDataSetHandlerTest
public void testLibraryTemplateWithWellNotPresentInAbase() throws IOException public void testLibraryTemplateWithWellNotPresentInAbase() throws IOException
{ {
createDataSetHandler(false, false); createDataSetHandler(false, false);
setUpListAdministratorExpectations();
final MockDataSet<Map<String, Object>> queryResult = new MockDataSet<Map<String, Object>>(); final MockDataSet<Map<String, Object>> queryResult = new MockDataSet<Map<String, Object>>();
queryResult.add(createQueryResult("A1")); queryResult.add(createQueryResult("A1"));
...@@ -272,7 +261,7 @@ public class SanofiDropboxJythonTest extends AbstractJythonDataSetHandlerTest ...@@ -272,7 +261,7 @@ public class SanofiDropboxJythonTest extends AbstractJythonDataSetHandlerTest
one(mailClient).sendMessage(with(any(String.class)), with(email), one(mailClient).sendMessage(with(any(String.class)), with(email),
with(aNull(String.class)), with(any(From.class)), with(aNull(String.class)), with(any(From.class)),
with(equal(EXPERIMENT_RECIPIENTS))); with(equal(ALL_EMAILS)));
} }
}); });
...@@ -293,6 +282,7 @@ public class SanofiDropboxJythonTest extends AbstractJythonDataSetHandlerTest ...@@ -293,6 +282,7 @@ public class SanofiDropboxJythonTest extends AbstractJythonDataSetHandlerTest
public void testLibraryTemplateIncompleteAccordingToAbase() throws IOException public void testLibraryTemplateIncompleteAccordingToAbase() throws IOException
{ {
createDataSetHandler(false, false); createDataSetHandler(false, false);
setUpListAdministratorExpectations();
final MockDataSet<Map<String, Object>> queryResult = new MockDataSet<Map<String, Object>>(); final MockDataSet<Map<String, Object>> queryResult = new MockDataSet<Map<String, Object>>();
queryResult.add(createQueryResult("A1")); queryResult.add(createQueryResult("A1"));
...@@ -313,7 +303,7 @@ public class SanofiDropboxJythonTest extends AbstractJythonDataSetHandlerTest ...@@ -313,7 +303,7 @@ public class SanofiDropboxJythonTest extends AbstractJythonDataSetHandlerTest
one(mailClient).sendMessage(with(any(String.class)), with(email), one(mailClient).sendMessage(with(any(String.class)), with(email),
with(aNull(String.class)), with(any(From.class)), with(aNull(String.class)), with(any(From.class)),
with(equal(EXPERIMENT_RECIPIENTS))); with(equal(ALL_EMAILS)));
} }
}); });
...@@ -343,6 +333,8 @@ public class SanofiDropboxJythonTest extends AbstractJythonDataSetHandlerTest ...@@ -343,6 +333,8 @@ public class SanofiDropboxJythonTest extends AbstractJythonDataSetHandlerTest
queryResult.add(createQueryResult("B2")); queryResult.add(createQueryResult("B2"));
setDataSetExpectations(); setDataSetExpectations();
setUpListAdministratorExpectations();
context.checking(new Expectations() context.checking(new Expectations()
{ {
{ {
...@@ -371,7 +363,7 @@ public class SanofiDropboxJythonTest extends AbstractJythonDataSetHandlerTest ...@@ -371,7 +363,7 @@ public class SanofiDropboxJythonTest extends AbstractJythonDataSetHandlerTest
one(mailClient).sendMessage(with(any(String.class)), with(email), one(mailClient).sendMessage(with(any(String.class)), with(email),
with(aNull(String.class)), with(any(From.class)), with(aNull(String.class)), with(any(From.class)),
with(equal(EXPERIMENT_RECIPIENTS))); with(equal(ALL_EMAILS)));
} }
}); });
...@@ -424,12 +416,7 @@ public class SanofiDropboxJythonTest extends AbstractJythonDataSetHandlerTest ...@@ -424,12 +416,7 @@ public class SanofiDropboxJythonTest extends AbstractJythonDataSetHandlerTest
createDataSetHandler(false, false); createDataSetHandler(false, false);
final Sample plate = plateWithLibTemplateAndGeometry("0.75\tH\n54.12\tL", "8_WELLS_2X4"); final Sample plate = plateWithLibTemplateAndGeometry("0.75\tH\n54.12\tL", "8_WELLS_2X4");
final String[] adminEmails = new String[] setUpListAdministratorExpectations();
{ "admin@sanofi.com", null, "admin@openbis.org", "" };
final String[] nonEmptyAdminEmails = new String[]
{ "admin@sanofi.com", "admin@openbis.org" };
context.checking(new Expectations() context.checking(new Expectations()
{ {
{ {
...@@ -443,17 +430,13 @@ public class SanofiDropboxJythonTest extends AbstractJythonDataSetHandlerTest ...@@ -443,17 +430,13 @@ public class SanofiDropboxJythonTest extends AbstractJythonDataSetHandlerTest
one(openBisService).tryGetSampleWithExperiment(sampleIdentifier); one(openBisService).tryGetSampleWithExperiment(sampleIdentifier);
will(returnValue(plate)); will(returnValue(plate));
one(openBisService).listAdministrators();
List<String> adminEmailsList = Arrays.asList(adminEmails);
will(returnValue(createAdministrators(adminEmailsList)));
one(mailClient).sendMessage(with(any(String.class)), with(email), one(mailClient).sendMessage(with(any(String.class)), with(email),
with(aNull(String.class)), with(any(From.class)), with(aNull(String.class)), with(any(From.class)),
with(equal(nonEmptyAdminEmails))); with(equal(ADMIN_EMAILS)));
one(mailClient).sendMessage(with(any(String.class)), with(email), one(mailClient).sendMessage(with(any(String.class)), with(email),
with(aNull(String.class)), with(any(From.class)), with(aNull(String.class)), with(any(From.class)),
with(equal(EXPERIMENT_RECIPIENTS))); with(equal(USER_EMAILS)));
} }
...@@ -480,18 +463,6 @@ public class SanofiDropboxJythonTest extends AbstractJythonDataSetHandlerTest ...@@ -480,18 +463,6 @@ public class SanofiDropboxJythonTest extends AbstractJythonDataSetHandlerTest
context.assertIsSatisfied(); context.assertIsSatisfied();
} }
private List<Person> createAdministrators(List<String> adminEmails)
{
List<Person> result = new ArrayList<Person>();
for (String adminEmail : adminEmails)
{
Person person = new Person();
person.setEmail(adminEmail);
result.add(person);
}
return result;
}
@Test @Test
public void testHappyCaseWithLibraryCreationAndNonUniqueMaterials() throws IOException public void testHappyCaseWithLibraryCreationAndNonUniqueMaterials() throws IOException
{ {
...@@ -503,6 +474,8 @@ public class SanofiDropboxJythonTest extends AbstractJythonDataSetHandlerTest ...@@ -503,6 +474,8 @@ public class SanofiDropboxJythonTest extends AbstractJythonDataSetHandlerTest
queryResult.add(createQueryResult("B1", "material-1")); queryResult.add(createQueryResult("B1", "material-1"));
setDataSetExpectations(); setDataSetExpectations();
setUpListAdministratorExpectations();
context.checking(new Expectations() context.checking(new Expectations()
{ {
{ {
...@@ -530,7 +503,7 @@ public class SanofiDropboxJythonTest extends AbstractJythonDataSetHandlerTest ...@@ -530,7 +503,7 @@ public class SanofiDropboxJythonTest extends AbstractJythonDataSetHandlerTest
one(mailClient).sendMessage(with(any(String.class)), with(email), one(mailClient).sendMessage(with(any(String.class)), with(email),
with(aNull(String.class)), with(any(From.class)), with(aNull(String.class)), with(any(From.class)),
with(equal(EXPERIMENT_RECIPIENTS))); with(equal(ALL_EMAILS)));
} }
}); });
...@@ -742,6 +715,30 @@ public class SanofiDropboxJythonTest extends AbstractJythonDataSetHandlerTest ...@@ -742,6 +715,30 @@ public class SanofiDropboxJythonTest extends AbstractJythonDataSetHandlerTest
}); });
} }
private void setUpListAdministratorExpectations()
{
context.checking(new Expectations()
{
{
one(openBisService).listAdministrators();
List<String> adminEmailsList = Arrays.asList(ADMIN_EMAILS);
will(returnValue(createAdministrators(adminEmailsList)));
}
});
}
private List<Person> createAdministrators(List<String> adminEmails)
{
List<Person> result = new ArrayList<Person>();
for (String adminEmail : adminEmails)
{
Person person = new Person();
person.setEmail(adminEmail);
result.add(person);
}
return result;
}
private void createData() throws IOException private void createData() throws IOException
{ {
File dataDirectory = new File("./sourceTest/examples/" + IMAGE_DATA_SET_DIR_NAME); File dataDirectory = new File("./sourceTest/examples/" + IMAGE_DATA_SET_DIR_NAME);
...@@ -757,7 +754,7 @@ public class SanofiDropboxJythonTest extends AbstractJythonDataSetHandlerTest ...@@ -757,7 +754,7 @@ public class SanofiDropboxJythonTest extends AbstractJythonDataSetHandlerTest
ExperimentBuilder experimentBuilder = new ExperimentBuilder(); ExperimentBuilder experimentBuilder = new ExperimentBuilder();
experimentBuilder.identifier(EXPERIMENT_IDENTIFIER); experimentBuilder.identifier(EXPERIMENT_IDENTIFIER);
experimentBuilder.property(LIBRARY_TEMPLATE_PROPNAME, libraryTemplate); experimentBuilder.property(LIBRARY_TEMPLATE_PROPNAME, libraryTemplate);
String recipients = StringUtils.join(Arrays.asList(EXPERIMENT_RECIPIENTS), ","); String recipients = StringUtils.join(Arrays.asList(USER_EMAILS), ",");
experimentBuilder.property(EXPERIMENT_RECIPIENTS_PROPNAME, recipients); experimentBuilder.property(EXPERIMENT_RECIPIENTS_PROPNAME, recipients);
SampleBuilder sampleBuilder = new SampleBuilder(); SampleBuilder sampleBuilder = new SampleBuilder();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment