Search in sources :

Example 11 with Roles

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]);
}
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 12 with Roles

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());
}
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 13 with Roles

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();
}
Also used : ServerHierarchyType(net.geoprism.registry.model.ServerHierarchyType) Roles(com.runwaysdk.system.Roles)

Example 14 with Roles

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);
}
Also used : RoleDAO(com.runwaysdk.business.rbac.RoleDAO) Roles(com.runwaysdk.system.Roles)

Example 15 with Roles

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 });
}
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

Roles (com.runwaysdk.system.Roles)25 RegistryRoleConverter (net.geoprism.registry.conversion.RegistryRoleConverter)7 RegistryRole (org.commongeoregistry.adapter.metadata.RegistryRole)7 RoleDAO (com.runwaysdk.business.rbac.RoleDAO)6 Transaction (com.runwaysdk.dataaccess.transaction.Transaction)4 Request (com.runwaysdk.session.Request)4 Locale (java.util.Locale)4 Organization (net.geoprism.registry.Organization)4 LocalizedValue (org.commongeoregistry.adapter.dataaccess.LocalizedValue)4 MdVertexDAOIF (com.runwaysdk.dataaccess.MdVertexDAOIF)3 Actor (com.runwaysdk.system.Actor)3 HashMap (java.util.HashMap)3 HashSet (java.util.HashSet)3 LinkedList (java.util.LinkedList)3 ServerGeoObjectType (net.geoprism.registry.model.ServerGeoObjectType)3 MdVertexDAO (com.runwaysdk.dataaccess.metadata.graph.MdVertexDAO)2 LocalizedValueStore (com.runwaysdk.localization.LocalizedValueStore)2 GeoprismUser (net.geoprism.GeoprismUser)2 ServerHierarchyType (net.geoprism.registry.model.ServerHierarchyType)2 JsonArray (com.google.gson.JsonArray)1