use of net.geoprism.registry.command.SendEmailCommand in project geoprism-registry by terraframe.
the class ChangeRequest method apply.
@Override
public void apply() {
// We aren't using 'isNew' here because isNew will be true until the transaction applies
final boolean isApplied = this.isAppliedToDB();
// Cache the Geo-Object label and type label on this object for sorting purposes
this.getGeoObjectLabel().setLocaleMap(this.getGeoObjectDisplayLabel().getLocaleMap());
this.getGeoObjectTypeLabel().setLocaleMap(this.getGeoObjectType().getLabel().getLocaleMap());
super.apply();
// Send an email to RMs telling them about this new CR
try {
if (!isApplied) {
SingleActor createdBy = this.getCreatedBy();
if (createdBy instanceof GeoprismUser) {
// Get all RM's for the GOT and Org
String rmRoleName = this.getGeoObjectType().getMaintainerRoleName();
RoleDAOIF role = RoleDAO.findRole(rmRoleName);
Set<SingleActorDAOIF> actors = role.assignedActors();
List<String> toAddresses = new ArrayList<String>();
for (SingleActorDAOIF actor : actors) {
if (actor.getType().equals(GeoprismUser.CLASS)) {
GeoprismUser geoprismUser = GeoprismUser.get(actor.getOid());
String email = geoprismUser.getEmail();
if (email != null && email.length() > 0 && !email.contains("@noreply")) {
toAddresses.add(email);
}
}
}
if (toAddresses.size() > 0) {
String subject = LocalizationFacade.getFromBundles("change.request.email.submit.subject");
String body = LocalizationFacade.getFromBundles("change.request.email.submit.body");
body = body.replaceAll("\\\\n", "\n");
body = body.replaceAll("\\{user\\}", ((GeoprismUser) createdBy).getUsername());
body = body.replaceAll("\\{geoobject\\}", this.getGeoObjectDisplayLabel().getValue());
String link = GeoregistryProperties.getRemoteServerUrl() + "cgr/manage#/registry/change-requests/" + this.getOid();
body = body.replaceAll("\\{link\\}", link);
// Aspects will weave in here and this will happen at the end of the transaction
new SendEmailCommand(subject, body, toAddresses.toArray(new String[toAddresses.size()])).doIt();
}
}
}
} catch (Throwable t) {
t.printStackTrace();
}
}
Aggregations