Search in sources :

Example 1 with SingleActor

use of com.runwaysdk.system.SingleActor 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();
    }
}
Also used : ArrayList(java.util.ArrayList) GeoprismUser(net.geoprism.GeoprismUser) SingleActorDAOIF(com.runwaysdk.business.rbac.SingleActorDAOIF) RoleDAOIF(com.runwaysdk.business.rbac.RoleDAOIF) SendEmailCommand(net.geoprism.registry.command.SendEmailCommand) SingleActor(com.runwaysdk.system.SingleActor)

Example 2 with SingleActor

use of com.runwaysdk.system.SingleActor in project geoprism-registry by terraframe.

the class ChangeRequest method execute.

@Transaction
public void execute(String maintainerNotes, String additionalNotes) {
    if (this.getApprovalStatus().contains(AllGovernanceStatus.PENDING)) {
        List<AbstractAction> actions = this.getOrderedActions();
        Set<AllGovernanceStatus> statuses = new TreeSet<AllGovernanceStatus>();
        for (AbstractAction action : actions) {
            if (action instanceof UpdateAttributeAction && action.getApprovalStatus().contains(AllGovernanceStatus.PENDING)) {
                throw new ActionExecuteException("Unable to execute an action with the pending status");
            } else if (action instanceof CreateGeoObjectAction && action.getApprovalStatus().contains(AllGovernanceStatus.PENDING)) {
                action.appLock();
                action.clearApprovalStatus();
                action.addApprovalStatus(AllGovernanceStatus.ACCEPTED);
                action.apply();
                action.execute();
                statuses.add(AllGovernanceStatus.ACCEPTED);
            } else if (action.getApprovalStatus().contains(AllGovernanceStatus.ACCEPTED)) {
                action.execute();
                statuses.add(AllGovernanceStatus.ACCEPTED);
            } else if (action.getApprovalStatus().contains(AllGovernanceStatus.REJECTED) || action.getApprovalStatus().contains(AllGovernanceStatus.INVALID)) {
                statuses.add(AllGovernanceStatus.REJECTED);
            }
        }
        AllGovernanceStatus status = AllGovernanceStatus.REJECTED;
        if (statuses.size() > 0) {
            status = statuses.size() == 1 ? statuses.iterator().next() : AllGovernanceStatus.PARTIAL;
        }
        this.appLock();
        this.setMaintainerNotes(maintainerNotes);
        this.setAdditionalNotes(additionalNotes);
        this.clearApprovalStatus();
        this.addApprovalStatus(status);
        this.apply();
        // Email the contributor
        try {
            SingleActor actor = this.getCreatedBy();
            if (actor instanceof GeoprismUser) {
                String email = ((GeoprismUser) actor).getEmail();
                if (email != null && email.length() > 0 && !email.contains("@noreply")) {
                    final String statusLabel = status.getDisplayLabel().toLowerCase(Session.getCurrentLocale());
                    String subject = LocalizationFacade.getFromBundles("change.request.email.implement.subject");
                    subject = subject.replaceAll("\\{status\\}", StringUtils.capitalize(statusLabel));
                    String body = LocalizationFacade.getFromBundles("change.request.email.implement.body");
                    body = body.replaceAll("\\\\n", "\n");
                    body = body.replaceAll("\\{status\\}", statusLabel);
                    body = body.replaceAll("\\{geoobject\\}", this.getGeoObject().getDisplayLabel().getValue());
                    String link = GeoregistryProperties.getRemoteServerUrl() + "cgr/manage#/registry/change-requests/" + this.getOid();
                    body = body.replaceAll("\\{link\\}", link);
                    EmailSetting.sendEmail(subject, body, new String[] { email });
                }
            }
        } catch (Throwable t) {
            t.printStackTrace();
        }
    }
}
Also used : CreateGeoObjectAction(net.geoprism.registry.action.geoobject.CreateGeoObjectAction) TreeSet(java.util.TreeSet) GeoprismUser(net.geoprism.GeoprismUser) UpdateAttributeAction(net.geoprism.registry.action.geoobject.UpdateAttributeAction) SingleActor(com.runwaysdk.system.SingleActor) Transaction(com.runwaysdk.dataaccess.transaction.Transaction)

Aggregations

SingleActor (com.runwaysdk.system.SingleActor)2 GeoprismUser (net.geoprism.GeoprismUser)2 RoleDAOIF (com.runwaysdk.business.rbac.RoleDAOIF)1 SingleActorDAOIF (com.runwaysdk.business.rbac.SingleActorDAOIF)1 Transaction (com.runwaysdk.dataaccess.transaction.Transaction)1 ArrayList (java.util.ArrayList)1 TreeSet (java.util.TreeSet)1 CreateGeoObjectAction (net.geoprism.registry.action.geoobject.CreateGeoObjectAction)1 UpdateAttributeAction (net.geoprism.registry.action.geoobject.UpdateAttributeAction)1 SendEmailCommand (net.geoprism.registry.command.SendEmailCommand)1