use of com.runwaysdk.system.Roles 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 com.runwaysdk.system.Roles 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 com.runwaysdk.system.Roles in project geoprism-registry by terraframe.
the class Organization method delete.
/**
* Removes the {@link RoleDAO}s for this {@link Organization} and Registry
* Administrator for this {@link Organization}.
*/
public void delete() {
// Can't delete if there's existing data
List<ServerHierarchyType> hierarchyTypes = ServiceFactory.getMetadataCache().getAllHierarchyTypes();
for (ServerHierarchyType ht : hierarchyTypes) {
if (ht.getOrganizationCode().equals(this.getCode())) {
throw new ObjectHasDataException();
}
}
try {
Roles raOrgRole = this.getRegistryAdminiRole();
raOrgRole.delete();
}// Heads up: clean up
catch (com.runwaysdk.dataaccess.cache.DataNotFoundException e) {
}
try {
Roles orgRole = this.getRole();
orgRole.delete();
}// Heads up: clean up
catch (com.runwaysdk.dataaccess.cache.DataNotFoundException e) {
}
super.delete();
}
use of com.runwaysdk.system.Roles in project geoprism-registry by terraframe.
the class Organization method createRegistryAdminOrganizationRole.
/**
* Creates a Registry Administrator {@link RoleDAOIF} for this
* {@link Organization}.
*
* Precondition: a {@link RoleDAOIF} does not exist for this
* {@link Organization}. Precondition: the display label for the default
* locale has a value for this {@link Organization}
*/
private void createRegistryAdminOrganizationRole() {
String registryAdminRoleName = this.getRegistryAdminRoleName();
String defaultDisplayLabel = this.getDisplayLabel().getDefaultValue() + " Registry Administrator";
// Heads up: clean up move to Roles.java?
Roles raOrgRole = new Roles();
raOrgRole.setRoleName(registryAdminRoleName);
raOrgRole.getDisplayLabel().setDefaultValue(defaultDisplayLabel);
raOrgRole.apply();
Roles orgRole = (Roles) this.getRole();
RoleDAO orgRoleDAO = (RoleDAO) BusinessFacade.getEntityDAO(orgRole);
RoleDAO raOrgRoleDAO = (RoleDAO) BusinessFacade.getEntityDAO(raOrgRole);
orgRoleDAO.addInheritance(raOrgRoleDAO);
// Inherit the permissions from the root RA role
RoleDAO rootRA_DAO = (RoleDAO) BusinessFacade.getEntityDAO(Roles.findRoleByName(RegistryConstants.REGISTRY_ADMIN_ROLE));
rootRA_DAO.addInheritance(raOrgRoleDAO);
}
use of com.runwaysdk.system.Roles 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