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;
}
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);
}
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();
}
}
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();
}
}
}
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", "");
}
}
Aggregations