Search in sources :

Example 11 with GeoprismUser

use of net.geoprism.GeoprismUser in project geoprism-registry by terraframe.

the class UserInfo method deserialize.

public static GeoprismUser deserialize(JsonObject account) {
    GeoprismUser user = null;
    if (account.has(GeoprismUser.OID)) {
        String userId = account.get(GeoprismUser.OID).getAsString();
        user = GeoprismUser.get(userId);
    } else {
        user = new GeoprismUser();
    }
    user.setUsername(account.get(GeoprismUser.USERNAME).getAsString());
    user.setFirstName(account.get(GeoprismUser.FIRSTNAME).getAsString());
    user.setLastName(account.get(GeoprismUser.LASTNAME).getAsString());
    user.setEmail(account.get(GeoprismUser.EMAIL).getAsString());
    if (account.has(GeoprismUser.PHONENUMBER) && account.get(GeoprismUser.PHONENUMBER).getAsString().length() > 0) {
        user.setPhoneNumber(account.get(GeoprismUser.PHONENUMBER).getAsString());
    }
    if (account.has(GeoprismUser.INACTIVE)) {
        user.setInactive(account.get(GeoprismUser.INACTIVE).getAsBoolean());
    }
    if (account.has(GeoprismUser.PASSWORD) && account.get(GeoprismUser.PASSWORD).getAsString().length() > 0) {
        String password = account.get(GeoprismUser.PASSWORD).getAsString();
        if (password != null && password.length() > 0) {
            user.setPassword(password);
        }
    } else if (account.has(UserInfo.EXTERNALSYSTEMOID) && account.get(UserInfo.EXTERNALSYSTEMOID).getAsString().length() > 0) {
        user.setPassword(String.valueOf(new Random().nextLong()));
    }
    return user;
}
Also used : Random(java.util.Random) GeoprismUser(net.geoprism.GeoprismUser)

Example 12 with GeoprismUser

use of net.geoprism.GeoprismUser in project geoprism-registry by terraframe.

the class UserInfo method lockByUser.

@Transaction
public static JSONObject lockByUser(String userId) {
    GeoprismUser user = GeoprismUser.lock(userId);
    UserInfo info = UserInfo.getByUser(user);
    if (info != null) {
        info.lock();
    }
    return UserInfo.serialize(user, info);
}
Also used : GeoprismUser(net.geoprism.GeoprismUser) Transaction(com.runwaysdk.dataaccess.transaction.Transaction)

Example 13 with GeoprismUser

use of net.geoprism.GeoprismUser 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 14 with GeoprismUser

use of net.geoprism.GeoprismUser 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)

Example 15 with GeoprismUser

use of net.geoprism.GeoprismUser in project geoprism-registry by terraframe.

the class ChangeRequestJsonAdapters method serializeCreatedBy.

public static void serializeCreatedBy(SingleActor actor, JsonObject jo) {
    if (actor instanceof Users) {
        Users user = (Users) actor;
        user.getUsername();
        jo.addProperty(ChangeRequest.CREATEDBY, user.getUsername());
        if (user instanceof GeoprismUser) {
            jo.addProperty("email", ((GeoprismUser) user).getEmail());
            jo.addProperty("phoneNumber", ((GeoprismUser) user).getPhoneNumber());
        } else {
            jo.addProperty("email", "");
            jo.addProperty("phoneNumber", "");
        }
    } else {
        jo.addProperty(ChangeRequest.CREATEDBY, actor.getKey());
        jo.addProperty("email", "");
        jo.addProperty("phoneNumber", "");
    }
}
Also used : GeoprismUser(net.geoprism.GeoprismUser) Users(com.runwaysdk.system.Users)

Aggregations

GeoprismUser (net.geoprism.GeoprismUser)22 Transaction (com.runwaysdk.dataaccess.transaction.Transaction)9 JsonObject (com.google.gson.JsonObject)8 Request (com.runwaysdk.session.Request)8 QueryFactory (com.runwaysdk.query.QueryFactory)7 ServerGeoObjectType (net.geoprism.registry.model.ServerGeoObjectType)6 ProgrammingErrorException (com.runwaysdk.dataaccess.ProgrammingErrorException)5 JobHistory (com.runwaysdk.system.scheduler.JobHistory)5 SimpleDateFormat (java.text.SimpleDateFormat)5 LinkedList (java.util.LinkedList)5 DataExportJob (net.geoprism.registry.etl.export.DataExportJob)5 ExportHistory (net.geoprism.registry.etl.export.ExportHistory)5 RoleDAOIF (com.runwaysdk.business.rbac.RoleDAOIF)4 SingleActorDAOIF (com.runwaysdk.business.rbac.SingleActorDAOIF)3 ArrayList (java.util.ArrayList)3 RegistryRole (org.commongeoregistry.adapter.metadata.RegistryRole)3 JsonArray (com.google.gson.JsonArray)2 JsonParser (com.google.gson.JsonParser)2 JsonSyntaxException (com.google.gson.JsonSyntaxException)2 MultipartFileParameter (com.runwaysdk.controller.MultipartFileParameter)2