use of org.commongeoregistry.adapter.metadata.RegistryRole in project geoprism-registry by terraframe.
the class AccountService method getRolesForOrganization.
private List<RegistryRole> getRolesForOrganization(String... organizationCodes) {
List<RegistryRole> registryRoleList = new LinkedList<RegistryRole>();
List<String> orgCodesToProcess = new LinkedList<String>();
for (String organizationCode : organizationCodes) {
if (!organizationCode.trim().equals("")) {
orgCodesToProcess.add(organizationCode.trim());
}
}
List<Organization> organizationList;
if (orgCodesToProcess.size() == 0) {
// Add the SRA role
String sraRoleName = RegistryRole.Type.getSRA_RoleName();
Roles sraRole = Roles.findRoleByName(sraRoleName);
registryRoleList.add(new RegistryRoleConverter().build(sraRole));
organizationList = Organization.getOrganizationsFromCache();
} else {
organizationList = new LinkedList<Organization>();
for (String organizationCode : organizationCodes) {
organizationList.add(Organization.getByCode(organizationCode));
}
}
for (Organization organization : organizationList) {
this.addRolesForOrganization(registryRoleList, organization);
}
return registryRoleList;
}
use of org.commongeoregistry.adapter.metadata.RegistryRole in project geoprism-registry by terraframe.
the class AccountService method getRolesForUser.
/**
* @param organizationCodes
* comma delimited list of registry codes. Returns all registry roles
* if empty.
*
* @return all of the roles are set to assigned equals false
*/
@Request(RequestType.SESSION)
public RegistryRole[] getRolesForUser(String sessionId, String userOID) {
GeoprismUser geoPrismUser = GeoprismUser.get(userOID);
List<RegistryRole> registryRoles = new LinkedList<RegistryRole>();
Set<String> roleNameSet = new HashSet<String>();
OIterator<? extends com.runwaysdk.system.Roles> roleIterator = geoPrismUser.getAllAssignedRole();
for (Roles role : roleIterator) {
RegistryRole registryRole = new RegistryRoleConverter().build(role);
if (registryRole != null) {
registryRole.setAssigned(true);
LocalizedValueConverter.populateOrganizationDisplayLabel(registryRole);
LocalizedValueConverter.populateGeoObjectTypeLabel(registryRole);
registryRoles.add(registryRole);
roleNameSet.add(registryRole.getName());
}
}
// Add the registry roles that the user can be a member of based on their
// organization affiliation
OIterator<? extends Business> organizationIterators = geoPrismUser.getParents(OrganizationUser.CLASS);
for (Business business : organizationIterators) {
Organization organization = (Organization) business;
List<RegistryRole> orgRoleIterator = this.getRolesForOrganization(organization.getCode());
for (RegistryRole registryRole : orgRoleIterator) {
if (!roleNameSet.contains(registryRole.getName())) {
registryRoles.add(registryRole);
}
}
}
if (!roleNameSet.contains(RegistryConstants.REGISTRY_SUPER_ADMIN_ROLE)) {
Roles sra = Roles.findRoleByName(RegistryConstants.REGISTRY_SUPER_ADMIN_ROLE);
RegistryRole rrSRA = new RegistryRoleConverter().build(sra);
rrSRA.setAssigned(false);
registryRoles.add(rrSRA);
}
return registryRoles.stream().sorted(Comparator.comparing(RegistryRole::getOrganizationCode).thenComparing(RegistryRole::getGeoObjectTypeCode)).toArray(size -> new RegistryRole[size]);
}
use of org.commongeoregistry.adapter.metadata.RegistryRole in project geoprism-registry by terraframe.
the class OrganizationAndRoleTest method testRA_RoleToRegistryRole.
@Test
@Request
public void testRA_RoleToRegistryRole() {
String organizationCode = FastTestDataset.ORG_CGOV.getCode();
String raRoleName = RegistryRole.Type.getRA_RoleName(organizationCode);
Roles raRole = Roles.findRoleByName(raRoleName);
RegistryRole registryRole = new RegistryRoleConverter().build(raRole);
Assert.assertEquals(raRoleName, registryRole.getName());
Assert.assertEquals(organizationCode, registryRole.getOrganizationCode());
}
use of org.commongeoregistry.adapter.metadata.RegistryRole in project geoprism-registry by terraframe.
the class AccountServiceControllerTest method assertReturnedRoles.
private void assertReturnedRoles(JSONArray roleJSONArray, Set<String> rolesFoundSet, boolean assignedCheck) {
for (int i = 0; i < roleJSONArray.length(); i++) {
JSONObject json = (JSONObject) roleJSONArray.get(i);
RegistryRole registryRole = RegistryRole.fromJSON(json.toString());
if (!assignedCheck || registryRole.isAssigned()) {
rolesFoundSet.remove(registryRole.getName());
}
// System.out.println(registryRole.getName()+"
// "+registryRole.isAssigned());
}
// System.out.println("");
Assert.assertEquals("Not all related roles were returned from the server", 0, rolesFoundSet.size());
}
use of org.commongeoregistry.adapter.metadata.RegistryRole in project geoprism-registry by terraframe.
the class RegistryAccountUtil method sendEmail.
public static void sendEmail(UserInvite invite, String roleIds) {
final String serverExternalUrl = GeoregistryProperties.getRemoteServerUrl();
String address = invite.getEmail();
String link = serverExternalUrl + "cgr/manage#/admin/invite-complete/" + invite.getToken();
String subject = LocalizationFacade.localize("user.invite.email.subject");
String body = LocalizationFacade.localize("user.invite.email.body");
body = body.replaceAll("\\\\n", "\n");
body = body.replace("${link}", link);
body = body.replace("${expireTime}", getLocalizedExpireTime());
JsonArray roleNameArray = JsonParser.parseString(roleIds).getAsJsonArray();
String orgLabel = "??";
Set<String> roleLabels = new HashSet<String>();
for (int i = 0; i < roleNameArray.size(); ++i) {
String roleName = roleNameArray.get(i).getAsString();
Roles role = Roles.findRoleByName(roleName);
RegistryRole registryRole = new RegistryRoleConverter().build(role);
if (orgLabel.equals("??")) {
String orgCode = registryRole.getOrganizationCode();
if (orgCode != null && orgCode.length() > 0) {
orgLabel = Organization.getByCode(orgCode).getDisplayLabel().getValue().trim();
}
}
String roleLabel;
if (RegistryRole.Type.isRA_Role(roleName)) {
roleLabel = Roles.findRoleByName("cgr.RegistryAdministrator").getDisplayLabel().getValue().trim();
} else {
roleLabel = role.getDisplayLabel().getValue().trim();
}
roleLabels.add(roleLabel);
}
body = body.replace("${roles}", StringUtils.join(roleLabels, ", "));
body = body.replace("${organization}", orgLabel);
EmailSetting.sendEmail(subject, body, new String[] { address });
}
Aggregations