Search in sources :

Example 6 with RegistryRole

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;
}
Also used : RegistryRole(org.commongeoregistry.adapter.metadata.RegistryRole) Organization(net.geoprism.registry.Organization) RegistryRoleConverter(net.geoprism.registry.conversion.RegistryRoleConverter) Roles(com.runwaysdk.system.Roles) LinkedList(java.util.LinkedList)

Example 7 with RegistryRole

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]);
}
Also used : RegistryRole(org.commongeoregistry.adapter.metadata.RegistryRole) Organization(net.geoprism.registry.Organization) Roles(com.runwaysdk.system.Roles) LinkedList(java.util.LinkedList) RegistryRoleConverter(net.geoprism.registry.conversion.RegistryRoleConverter) GeoprismUser(net.geoprism.GeoprismUser) HashSet(java.util.HashSet) Business(com.runwaysdk.business.Business) Request(com.runwaysdk.session.Request)

Example 8 with RegistryRole

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());
}
Also used : RegistryRole(org.commongeoregistry.adapter.metadata.RegistryRole) RegistryRoleConverter(net.geoprism.registry.conversion.RegistryRoleConverter) Roles(com.runwaysdk.system.Roles) Test(org.junit.Test) Request(com.runwaysdk.session.Request)

Example 9 with RegistryRole

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());
}
Also used : RegistryRole(org.commongeoregistry.adapter.metadata.RegistryRole) JSONObject(org.json.JSONObject)

Example 10 with RegistryRole

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 });
}
Also used : JsonArray(com.google.gson.JsonArray) RegistryRole(org.commongeoregistry.adapter.metadata.RegistryRole) RegistryRoleConverter(net.geoprism.registry.conversion.RegistryRoleConverter) Roles(com.runwaysdk.system.Roles) HashSet(java.util.HashSet)

Aggregations

RegistryRole (org.commongeoregistry.adapter.metadata.RegistryRole)13 Roles (com.runwaysdk.system.Roles)7 RegistryRoleConverter (net.geoprism.registry.conversion.RegistryRoleConverter)7 JsonArray (com.google.gson.JsonArray)6 Endpoint (com.runwaysdk.mvc.Endpoint)5 RestResponse (com.runwaysdk.mvc.RestResponse)4 JSONArray (org.json.JSONArray)4 JSONObject (org.json.JSONObject)4 Request (com.runwaysdk.session.Request)3 HashSet (java.util.HashSet)3 LinkedList (java.util.LinkedList)3 GeoprismUser (net.geoprism.GeoprismUser)2 Organization (net.geoprism.registry.Organization)2 Business (com.runwaysdk.business.Business)1 RoleDAO (com.runwaysdk.business.rbac.RoleDAO)1 RoleDAOIF (com.runwaysdk.business.rbac.RoleDAOIF)1 UserDAOIF (com.runwaysdk.business.rbac.UserDAOIF)1 AttributeValueException (com.runwaysdk.dataaccess.attributes.AttributeValueException)1 Transaction (com.runwaysdk.dataaccess.transaction.Transaction)1 RestBodyResponse (com.runwaysdk.mvc.RestBodyResponse)1