diff --git a/deep_sequencing_unit/source/java/ch/ethz/bsse/cisd/dsu/tracking/email/Email.java b/deep_sequencing_unit/source/java/ch/ethz/bsse/cisd/dsu/tracking/email/Email.java index f153d20b7aa5c255f2d0637136d77503be668cd2..2d4b6fc9c6c0384d11d9b59bab7c3e5611133dd6 100644 --- a/deep_sequencing_unit/source/java/ch/ethz/bsse/cisd/dsu/tracking/email/Email.java +++ b/deep_sequencing_unit/source/java/ch/ethz/bsse/cisd/dsu/tracking/email/Email.java @@ -16,12 +16,12 @@ package ch.ethz.bsse.cisd.dsu.tracking.email; +import ch.systemsx.cisd.common.mail.EMailAddress; import ch.systemsx.cisd.common.mail.From; import ch.systemsx.cisd.common.mail.IMailClient; /** - * Simple encapsulation of {@link IMailClient#sendMessage(String, String, String, From, String...)} - * method parameters. + * Simple encapsulation of {@link IMailClient#sendMessage(String, String, String, From, String...)} method parameters. * * @author Piotr Buczek */ @@ -31,14 +31,14 @@ public class Email private final String content; - private final String replyToOrNull; + private final EMailAddress replyToOrNull; - private final From fromOrNull; + private final EMailAddress fromOrNull; - private final String[] recipients; + private final EMailAddress[] recipients; - public Email(String subject, String content, String replyToOrNull, From fromOrNull, - String... recipients) + public Email(String subject, String content, EMailAddress replyToOrNull, EMailAddress fromOrNull, + EMailAddress... recipients) { super(); this.subject = subject; @@ -48,10 +48,10 @@ public class Email this.recipients = recipients; } - public Email(String subject, String content, String replyToOrNull, String fromOrNull, - String... recipients) + public Email(String subject, String content, EMailAddress replyToOrNull, String fromOrNull, + EMailAddress... recipients) { - this(subject, content, replyToOrNull, new From(fromOrNull), recipients); + this(subject, content, replyToOrNull, new EMailAddress(fromOrNull), recipients); } public String getSubject() @@ -64,17 +64,17 @@ public class Email return content; } - public String getReplyToOrNull() + public EMailAddress getReplyToOrNull() { return replyToOrNull; } - public From getFromOrNull() + public EMailAddress getFromOrNull() { return fromOrNull; } - public String[] getRecipients() + public EMailAddress[] getRecipients() { return recipients; } diff --git a/deep_sequencing_unit/source/java/ch/ethz/bsse/cisd/dsu/tracking/email/EntityTrackingEmailData.java b/deep_sequencing_unit/source/java/ch/ethz/bsse/cisd/dsu/tracking/email/EntityTrackingEmailData.java index 4baae2d63089c24acd8f8345a49b867e9fc7f81c..08c7d402190da2d672fbce90c2d6212808f2f68b 100644 --- a/deep_sequencing_unit/source/java/ch/ethz/bsse/cisd/dsu/tracking/email/EntityTrackingEmailData.java +++ b/deep_sequencing_unit/source/java/ch/ethz/bsse/cisd/dsu/tracking/email/EntityTrackingEmailData.java @@ -19,13 +19,13 @@ package ch.ethz.bsse.cisd.dsu.tracking.email; import java.util.ArrayList; import java.util.List; +import ch.systemsx.cisd.common.mail.EMailAddress; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.AbstractExternalData; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Sample; /** - * Structure containing all data about tracked entities that will be used in a single email to an - * recipient. Its purpose is to group data that will be used to generate content of an email - * containing merged information about all events that the recipient should be notified about. + * Structure containing all data about tracked entities that will be used in a single email to an recipient. Its purpose is to group data that will be + * used to generate content of an email containing merged information about all events that the recipient should be notified about. * * @author Piotr Buczek */ @@ -37,15 +37,15 @@ public class EntityTrackingEmailData private final List<AbstractExternalData> dataSets = new ArrayList<AbstractExternalData>(0); - private final String recipient; + private final EMailAddress recipient; /** creates email data for given <var>recipient</var> */ - public EntityTrackingEmailData(String recipient) + public EntityTrackingEmailData(EMailAddress recipient) { this.recipient = recipient; } - public String getRecipient() + public EMailAddress getRecipient() { return recipient; } diff --git a/deep_sequencing_unit/source/java/ch/ethz/bsse/cisd/dsu/tracking/email/EntityTrackingEmailDataManager.java b/deep_sequencing_unit/source/java/ch/ethz/bsse/cisd/dsu/tracking/email/EntityTrackingEmailDataManager.java index 2b83c189661a4fe017d70abd909e2a1267da9c47..86223c97de4b1476fdeb9538102c0dbae79e0712 100644 --- a/deep_sequencing_unit/source/java/ch/ethz/bsse/cisd/dsu/tracking/email/EntityTrackingEmailDataManager.java +++ b/deep_sequencing_unit/source/java/ch/ethz/bsse/cisd/dsu/tracking/email/EntityTrackingEmailDataManager.java @@ -24,6 +24,7 @@ import java.util.Map; import java.util.Set; import ch.ethz.bsse.cisd.dsu.tracking.dto.TrackedEntities; +import ch.systemsx.cisd.common.mail.EMailAddress; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.AbstractExternalData; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.IEntityProperty; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Sample; @@ -56,8 +57,8 @@ class EntityTrackingEmailDataManager { assert recipientsByAffiliation != null : "recipientsByAffiliation not initialized"; // <recipients email, email data> - final Map<String, EntityTrackingEmailData> dataByRecipient = - new HashMap<String, EntityTrackingEmailData>(); + final Map<EMailAddress, EntityTrackingEmailData> dataByRecipient = + new HashMap<EMailAddress, EntityTrackingEmailData>(); groupSequencingSamplesToBeProcessed(dataByRecipient, trackedEntities); groupSequencingSamplesProcessed(dataByRecipient, trackedEntities); groupDataSetSamples(dataByRecipient, trackedEntities); @@ -66,11 +67,11 @@ class EntityTrackingEmailDataManager /** Puts tracked sequencing samples to be processed grouped by recipient into <var>result</var>. */ private static void groupSequencingSamplesToBeProcessed( - Map<String, EntityTrackingEmailData> result, TrackedEntities trackedEntities) + Map<EMailAddress, EntityTrackingEmailData> result, TrackedEntities trackedEntities) { for (Sample sequencingSample : trackedEntities.getSequencingSamplesToBeProcessed()) { - for (String recipient : getSequencingSampleTrackingRecipients(Collections + for (EMailAddress recipient : getSequencingSampleTrackingRecipients(Collections .singleton(sequencingSample))) { final EntityTrackingEmailData emailData = @@ -82,11 +83,11 @@ class EntityTrackingEmailDataManager /** Puts tracked processed sequencing samples grouped by recipient into <var>result</var>. */ private static void groupSequencingSamplesProcessed( - Map<String, EntityTrackingEmailData> result, TrackedEntities trackedEntities) + Map<EMailAddress, EntityTrackingEmailData> result, TrackedEntities trackedEntities) { for (Sample sequencingSample : trackedEntities.getSequencingSamplesProcessed()) { - for (String recipient : getSequencingSampleTrackingRecipients(Collections + for (EMailAddress recipient : getSequencingSampleTrackingRecipients(Collections .singleton(sequencingSample))) { final EntityTrackingEmailData emailData = @@ -97,12 +98,12 @@ class EntityTrackingEmailDataManager } /** Puts tracked data sets grouped by recipient into <var>result</var>. */ - private static void groupDataSetSamples(Map<String, EntityTrackingEmailData> result, + private static void groupDataSetSamples(Map<EMailAddress, EntityTrackingEmailData> result, TrackedEntities trackedEntities) { for (AbstractExternalData dataSet : trackedEntities.getDataSets()) { - for (String recipient : getDataSetTrackingRecipients(dataSet)) + for (EMailAddress recipient : getDataSetTrackingRecipients(dataSet)) { final EntityTrackingEmailData emailData = getOrCreateRecipientEmailData(result, recipient); @@ -112,7 +113,7 @@ class EntityTrackingEmailDataManager } private static EntityTrackingEmailData getOrCreateRecipientEmailData( - Map<String, EntityTrackingEmailData> dataByRecipient, String recipient) + Map<EMailAddress, EntityTrackingEmailData> dataByRecipient, EMailAddress recipient) { EntityTrackingEmailData emailDataOrNull = dataByRecipient.get(recipient); if (emailDataOrNull == null) @@ -127,12 +128,12 @@ class EntityTrackingEmailDataManager * Returns a set of emails of recipients that should get a tracking information about given <var>sequencingSample</var>.<br> */ // NOTE: Set is needed because one recipient can occur in many roles for one sample - private static Set<String> getSequencingSampleTrackingRecipients( + private static Set<EMailAddress> getSequencingSampleTrackingRecipients( Collection<Sample> sequencingSamples) { assert sequencingSamples != null; - final Set<String> recipients = new HashSet<String>(); + final Set<EMailAddress> recipients = new HashSet<EMailAddress>(); // Recipients are taken from properties of the sequencing sample. final Set<String> recipientPropertyTypeCodes = new HashSet<String>(); @@ -147,45 +148,11 @@ class EntityTrackingEmailDataManager findMasterSample(sequencingSample, recipients); - // SampleType seqSampleSampleType = sequencingSample.getSampleType(); - // if (seqSampleSampleType.equals(masterSampleType)) - // { - // Set<String> r = extractProperties(recipientPropertyTypeCodes, sequencingSample); - // recipients.addAll(r); - // } - // else - // { - // Set<Sample> parents = sequencingSample.getParents(); - // assert parents != null; - // for (Sample parent : parents) - // { - // SampleType sampleType = parent.getSampleType(); - // - // if (false == sampleType.equals(masterSampleType)) - // { - // Set<Sample> grandParents = parent.getParents(); - // for (Sample grandparent : grandParents) - // { - // Set<String> r = extractProperties(recipientPropertyTypeCodes, grandparent); - // recipients.addAll(r); - // } - // } - // else - // { - // { - // Set<String> r = extractProperties(recipientPropertyTypeCodes, sequencingSample); - // recipients.addAll(r); - // } - // } - // - // } - // - // } } return recipients; } - private static void findMasterSample(Sample s, Set<String> recipients) + private static void findMasterSample(Sample s, Set<EMailAddress> recipients) { SampleType masterSampleType = new SampleType(); masterSampleType.setCode(MASTER_SAMPLE_TYPE); @@ -197,7 +164,7 @@ class EntityTrackingEmailDataManager SampleType seqSampleSampleType = s.getSampleType(); if (seqSampleSampleType.equals(masterSampleType)) { - Set<String> r = extractProperties(recipientPropertyTypeCodes, s); + Set<EMailAddress> r = extractProperties(recipientPropertyTypeCodes, s); recipients.addAll(r); } else @@ -211,13 +178,13 @@ class EntityTrackingEmailDataManager } - private static Set<String> extractProperties(final Set<String> recipientPropertyTypeCodes, Sample sequencingSample) + private static Set<EMailAddress> extractProperties(final Set<String> recipientPropertyTypeCodes, Sample sequencingSample) { - Set<String> recipients = new HashSet<String>(); + Set<EMailAddress> recipients = new HashSet<EMailAddress>(); for (IEntityProperty property : sequencingSample.getProperties()) { final String propertyCode = property.getPropertyType().getCode(); - final String propertyValue = property.tryGetAsString(); + EMailAddress propertyValue = new EMailAddress(property.tryGetAsString()); if (recipientPropertyTypeCodes.contains(propertyCode)) { recipients.add(propertyValue); @@ -226,8 +193,8 @@ class EntityTrackingEmailDataManager // add recipient for affiliation if his email was specified in properties if (propertyCode.equals(AFFILIATION)) { - String affiliationRecipientOrNull = - recipientsByAffiliation.get(propertyValue); + EMailAddress affiliationRecipientOrNull = new EMailAddress( + recipientsByAffiliation.get(propertyValue)); if (affiliationRecipientOrNull != null) { recipients.add(affiliationRecipientOrNull); @@ -241,7 +208,7 @@ class EntityTrackingEmailDataManager /** * Returns a set of emails of recipients that should get a tracking information about given <var>flowLaneSample</var>. */ - private static Set<String> getSampleTrackingRecipients(Sample sample) + private static Set<EMailAddress> getSampleTrackingRecipients(Sample sample) { // Recipients are taken from properties of master sample // that is a parent/grandparent of a library/raw sample @@ -252,7 +219,7 @@ class EntityTrackingEmailDataManager /** * Returns a set of emails of recipients that should get a tracking information about given <var>dataSet</var>. */ - private static Set<String> getDataSetTrackingRecipients(AbstractExternalData dataSet) + private static Set<EMailAddress> getDataSetTrackingRecipients(AbstractExternalData dataSet) { // Recipients are taken from properties of master sample // that is a parent/grandparent of a library/raw sample connected with the data set. diff --git a/deep_sequencing_unit/source/java/ch/ethz/bsse/cisd/dsu/tracking/email/EntityTrackingEmailGenerator.java b/deep_sequencing_unit/source/java/ch/ethz/bsse/cisd/dsu/tracking/email/EntityTrackingEmailGenerator.java index c17eb0b22d69c2cfa2b587ee6eb9157c1610de78..35a8e19d03c3b270c413e3386f8c72bb0fc2684b 100644 --- a/deep_sequencing_unit/source/java/ch/ethz/bsse/cisd/dsu/tracking/email/EntityTrackingEmailGenerator.java +++ b/deep_sequencing_unit/source/java/ch/ethz/bsse/cisd/dsu/tracking/email/EntityTrackingEmailGenerator.java @@ -30,6 +30,7 @@ import java.util.Set; import java.util.TreeMap; import ch.ethz.bsse.cisd.dsu.tracking.dto.TrackedEntities; +import ch.systemsx.cisd.common.mail.EMailAddress; import ch.systemsx.cisd.common.properties.PropertyUtils; import ch.systemsx.cisd.common.shared.basic.string.StringUtils; import ch.systemsx.cisd.openbis.generic.client.web.client.application.util.lang.StringEscapeUtils; @@ -52,9 +53,9 @@ public class EntityTrackingEmailGenerator implements IEntityTrackingEmailGenerat private static final String AFFILIATION_NOTIFICATION_EMAIL_CONTACT_SUFFIX = "-affiliation-notification-email-contact"; - private final String from; + private final EMailAddress from; - private final String replyTo; + private final EMailAddress replyTo; private final String subject; @@ -62,8 +63,8 @@ public class EntityTrackingEmailGenerator implements IEntityTrackingEmailGenerat public EntityTrackingEmailGenerator(Properties properties, String template) { - this.from = PropertyUtils.getMandatoryProperty(properties, NOTIFICATION_EMAIL_FROM); - this.replyTo = PropertyUtils.getMandatoryProperty(properties, NOTIFICATION_EMAIL_REPLY_TO); + this.from = new EMailAddress(PropertyUtils.getMandatoryProperty(properties, NOTIFICATION_EMAIL_FROM)); + this.replyTo = new EMailAddress(PropertyUtils.getMandatoryProperty(properties, NOTIFICATION_EMAIL_REPLY_TO)); this.subject = PropertyUtils.getMandatoryProperty(properties, NOTIFICATION_EMAIL_SUBJECT); this.template = template; @@ -116,8 +117,19 @@ public class EntityTrackingEmailGenerator implements IEntityTrackingEmailGenerat private Email createEmail(EntityTrackingEmailData emailData) { String content = EmailContentGenerator.fillTemplateWithData(template, emailData); - String recipient = emailData.getRecipient(); - return new Email(subject, content, replyTo, from, filterBlanks(recipient.split(",|;| "))); + EMailAddress recipients = emailData.getRecipient(); + + String[] mailStringArray = filterBlanks(recipients.tryGetEmailAddress().split(",|;| ")); + EMailAddress[] recipientsArray = new EMailAddress[mailStringArray.length]; + + for (int i = 0; i < mailStringArray.length; ++i) + { + EMailAddress e = new EMailAddress(mailStringArray[i]); + recipientsArray[i] = e; + } + + return new Email(subject, content, replyTo, from, recipientsArray); + } private static String[] filterBlanks(String[] arr) @@ -298,6 +310,7 @@ public class EntityTrackingEmailGenerator implements IEntityTrackingEmailGenerat String Index1 = getIndex1(dataSet); String Index2 = getIndex2(dataSet); + String externalSampleName = externalSampleNameFromDataSet(dataSet); String Index = null; if (Index1 != null) @@ -309,10 +322,10 @@ public class EntityTrackingEmailGenerator implements IEntityTrackingEmailGenerat Index = Index + "-" + Index2; } - if (Index != null) + if (Index != null && externalSampleName != null) { appendln(sb, "Data Set Type: " + dataSet.getDataSetType().toString() + - " Index: " + Index); + " Index: " + Index + ", External Sample Name: " + externalSampleName); } else { @@ -371,6 +384,25 @@ public class EntityTrackingEmailGenerator implements IEntityTrackingEmailGenerat return null; } + private static String externalSampleNameFromDataSet(AbstractExternalData dataSet) + { + List<IEntityProperty> properties = dataSet.getProperties(); + + String externalSampleName = null; + for (IEntityProperty p : properties) + { + if (p.getPropertyType().getCode().equals(EXTERNAL_SAMPLE_NAME_PROPERTY_CODE)) + { + externalSampleName = p.getValue(); + if (!externalSampleName.equals(null)) + { + return externalSampleName; + } + } + } + return null; + } + private static String tryGetSamplePropertyValue(Sample sequencingSample, String propertyCode) { String result = null; @@ -425,11 +457,4 @@ public class EntityTrackingEmailGenerator implements IEntityTrackingEmailGenerat } } - - public static void findSampleWithExternalSampleName(Sample sequencingSample) - { - // TODO Auto-generated method stub - - } - } diff --git a/deep_sequencing_unit/source/java/ch/ethz/bsse/cisd/dsu/tracking/main/TrackingBO.java b/deep_sequencing_unit/source/java/ch/ethz/bsse/cisd/dsu/tracking/main/TrackingBO.java index 888cf720ab96387b7da2da4033bbff0f9f696fea..36b121623cf42207b03b374ccae996574b5fbcff 100644 --- a/deep_sequencing_unit/source/java/ch/ethz/bsse/cisd/dsu/tracking/main/TrackingBO.java +++ b/deep_sequencing_unit/source/java/ch/ethz/bsse/cisd/dsu/tracking/main/TrackingBO.java @@ -17,6 +17,7 @@ package ch.ethz.bsse.cisd.dsu.tracking.main; import java.util.ArrayList; +import java.util.Arrays; import java.util.EnumSet; import java.util.HashSet; import java.util.List; @@ -31,7 +32,7 @@ import ch.ethz.bsse.cisd.dsu.tracking.email.EmailWithSummary; import ch.ethz.bsse.cisd.dsu.tracking.email.IEntityTrackingEmailGenerator; import ch.ethz.bsse.cisd.dsu.tracking.utils.LogUtils; import ch.systemsx.cisd.common.collection.CollectionUtils; -import ch.systemsx.cisd.common.mail.From; +import ch.systemsx.cisd.common.mail.EMailAddress; import ch.systemsx.cisd.common.mail.IMailClient; import ch.systemsx.cisd.openbis.generic.shared.ITrackingServer; import ch.systemsx.cisd.openbis.generic.shared.api.v1.IGeneralInformationService; @@ -56,6 +57,8 @@ import ch.systemsx.cisd.openbis.generic.shared.dto.SessionContextDTO; */ public class TrackingBO { + private static final List<String> SEQUENCING_SAMPLE_TYPES = Arrays.asList("ILLUMINA_SEQUENCING", "ILLUMINA_SEQUENCING_NEUROSTEMX"); + private static final String EXTERNAL_SAMPLE_NAME = "EXTERNAL_SAMPLE_NAME"; private static final String LIBRARY_SAMPLE_TYPE = "LIBRARY"; @@ -168,11 +171,15 @@ public class TrackingBO { String subject = email.getSubject(); String content = email.getContent(); - String replyToOrNull = email.getReplyToOrNull(); - From fromOrNull = email.getFromOrNull(); - String[] recipients = email.getRecipients(); + EMailAddress replyToOrNull = email.getReplyToOrNull(); + EMailAddress fromOrNull = email.getFromOrNull(); + EMailAddress[] recipients = email.getRecipients(); + + mailClient.sendEmailMessage(subject, content, replyToOrNull, fromOrNull, recipients); + + // sendEmailMessage(String subject, String content, EMailAddress replyToOrNull, + // EMailAddress fromOrNull, EMailAddress... recipients) - mailClient.sendMessage(subject, content, replyToOrNull, fromOrNull, recipients); } private static void appendLine(StringBuilder sb, String msg) @@ -214,8 +221,16 @@ public class TrackingBO Set<Long> alreadyTrackedSampleIds, ITrackingServer trackingServer, IGeneralInformationService gis, SessionContextDTO session) { - return listSamples(SampleType, propertyTypeCode, propertyValue, alreadyTrackedSampleIds, - trackingServer, gis, session); + List<Sample> completeList = new ArrayList<Sample>(); + + for (String sampleType : SEQUENCING_SAMPLE_TYPES) + { + completeList.addAll(listSamples(SampleType, propertyTypeCode, propertyValue, alreadyTrackedSampleIds, + trackingServer, gis, session)); + + } + return completeList; + } private static List<Sample> listSamples(String sampleType, String propertyTypeCode,