Skip to content

DM-8182: send email when package successfully completed. #234

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Nov 21, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions config/mail.prop
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
mail.use.prop.file = true
mail.transport.protocol = @mail.transport.protocol@
mail.smtp.host = @mail.smtp.host@
mail.smtp.auth = @mail.smtp.auth@
mail.smtp.port = @mail.smtp.port@
mail.smtp.from = @mail.smtp.from@
mail.smtp.starttls.enable = @mail.smtp.starttls.enable@
17 changes: 4 additions & 13 deletions src/firefly/java/edu/caltech/ipac/firefly/data/ServerEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@
*/


import edu.caltech.ipac.firefly.server.ServerContext;
import edu.caltech.ipac.firefly.util.event.Name;
import edu.caltech.ipac.util.StringUtils;

import java.io.Serializable;
import java.lang.String;
Expand Down Expand Up @@ -119,24 +117,14 @@ public EventTarget(Scope scope, String connID, String channel, String userKey) {
this.connID = connID;
this.channel = channel;
this.userKey = userKey;
if (scope == ServerEvent.Scope.CHANNEL && channel == null) {
this.channel = ServerContext.getRequestOwner().getEventChannel();
} else if (scope == Scope.USER && userKey == null) {
this.userKey =ServerContext.getRequestOwner().getUserKey();
} else if (scope == Scope.SELF && connID == null) {
this.connID =ServerContext.getRequestOwner().getEventConnID();
}
}

/**
* returns true if a destination information can be resolved.
* @return
*/
public boolean hasDestination() {
return scope == Scope.WORLD
|| scope == ServerEvent.Scope.CHANNEL && !StringUtils.isEmpty(this.channel)
|| scope == ServerEvent.Scope.USER && !StringUtils.isEmpty(this.userKey)
|| scope == ServerEvent.Scope.SELF && !StringUtils.isEmpty(this.connID);
return scope != null;
}

public Scope getScope() {
Expand All @@ -162,6 +150,9 @@ public void setChannel(String channel) {
public String getUserKey() {
return userKey;
}
public void setUserKey(String userKey) {
this.userKey = userKey;
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,15 @@ public static void fireEvent(ServerEvent sev) {
if (sev == null || sev.getTarget() == null || !sev.getTarget().hasDestination()) {
LOG.warn("Something is wrong with this ServerEvent: " + String.valueOf(sev));
} else {
ServerEvent.Scope scope = sev.getTarget().getScope();
// if target is missing key information, get it from RequestOwner
if (scope == ServerEvent.Scope.CHANNEL && sev.getTarget().getChannel() == null) {
sev.getTarget().setChannel(ServerContext.getRequestOwner().getEventChannel());
} else if (scope == ServerEvent.Scope.USER && sev.getTarget().getUserKey() == null) {
sev.getTarget().setUserKey(ServerContext.getRequestOwner().getUserKey());
} else if (scope == ServerEvent.Scope.SELF && sev.getTarget().getConnID() == null) {
sev.getTarget().setConnID(ServerContext.getRequestOwner().getEventConnID());
}
eventWorker.deliver(sev);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ public void fireStatusUpdate(BackgroundInfo info) {
}
}

public String getBID() {
return _key.getUniqueString();
}

public BackgroundStatus getStatus() {
BackgroundInfo info= getInfo();
return info==null ? null : info.getStatus();
Expand All @@ -94,6 +98,13 @@ public boolean isCanceled() {
return info == null || info.isCanceled();
}

public boolean isSuccess() {
BackgroundInfo info= getInfo();
return info != null
&& info.getStatus() != null
&& info.getStatus().getState() == BackgroundState.SUCCESS;
}

public String getEmailAddress() {
BackgroundInfo info= getInfo();
return (info==null) ? null : info.getEmailAddress();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import edu.caltech.ipac.firefly.rpc.SearchServices;
import edu.caltech.ipac.firefly.server.ServCommand;
import edu.caltech.ipac.firefly.server.ServerContext;
import edu.caltech.ipac.firefly.server.packagedata.BackgroundInfoCacher;
import edu.caltech.ipac.firefly.server.rpc.SearchServicesImpl;
import edu.caltech.ipac.firefly.server.util.QueryUtil;
import edu.caltech.ipac.firefly.server.util.ipactable.DataGroupPart;
Expand All @@ -32,6 +33,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
* @author Trey Roby
Expand Down Expand Up @@ -256,8 +258,11 @@ public static class ResendEmail extends BaseSearchServerCommand {
@Override
public String doCommand(Map<String, String[]> paramMap) throws Exception {
SrvParam sp= new SrvParam(paramMap);
List<String> idList = sp.getIDList();
String email= sp.getRequired(ServerParams.EMAIL);
List<String> idList = BackgroundEnv.getUserBackgroundInfo().stream()
.filter( (bic) -> bic.isSuccess())
.map( (bic) -> bic.getBID() )
.collect(Collectors.toList());
BackgroundEnv.resendEmail(idList,email);
return "true";
}
Expand Down
4 changes: 3 additions & 1 deletion src/firefly/java/edu/caltech/ipac/util/IpacTableUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,9 @@ public static String getColMeta(Collection<DataGroup.Attribute> metas, String cn
* @return
*/
public static List<DataGroup.Attribute> getAllColMeta(Collection<DataGroup.Attribute> metas, String cname) {
return metas.stream().filter(m -> String.valueOf(m.getKey()).startsWith("col." + cname)).collect(Collectors.toList());
return metas.stream()
.filter(m -> String.valueOf(m.getKey()).startsWith("col." + cname))
.collect(Collectors.toList());
}

public static void setDataType(List<DataType> cols, String line) {
Expand Down
1 change: 1 addition & 0 deletions src/firefly/js/core/background/BackgroundCntlr.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ function bgSetEmail(action) {
const {email} = action.payload;
if (email) {
SearchServices.setEmail(email);
SearchServices.resendEmail(email);
dispatch(action);
}
};
Expand Down
12 changes: 3 additions & 9 deletions src/firefly/js/rpc/SearchServicesJson.js
Original file line number Diff line number Diff line change
Expand Up @@ -299,18 +299,12 @@ export const getEmail= function(id) {
};

/**
*
* @param {array|string} ids - one id or an array of ids
* resend email notification to all successfully completed background jobs.
* @param {string} email
* @return {Promise}
*/
export const resendEmail= function(ids, email) {
var idList= Array.isArray(ids) ? ids : [ids];
var paramList= idList.map( (id) => {
return {name:ServerParams.ID, value: id};
} );
paramList.push({name:ServerParams.EMAIL, value:email});
return doService(doJsonP(), ServerParams.RESEND_EMAIL, paramList
export const resendEmail= function(email) {
return doService(doJsonP(), ServerParams.RESEND_EMAIL, {[ServerParams.EMAIL]: email}
).then( () => true);
};

Expand Down