Search in sources :

Example 1 with GeoprismUserQuery

use of net.geoprism.GeoprismUserQuery in project geoprism-registry by terraframe.

the class UserInfo method getSRAs.

public static JSONObject getSRAs(Integer pageSize, Integer pageNumber) {
    RoleDAOIF role = RoleDAO.findRole(RegistryConstants.REGISTRY_SUPER_ADMIN_ROLE);
    Set<SingleActorDAOIF> actors = role.assignedActors();
    Set<String> oids = actors.parallelStream().map(actor -> actor.getOid()).collect(Collectors.toSet());
    ValueQuery vQuery = new ValueQuery(new QueryFactory());
    GeoprismUserQuery uQuery = new GeoprismUserQuery(vQuery);
    UserInfoQuery iQuery = new UserInfoQuery(vQuery);
    vQuery.SELECT(uQuery.getOid(), uQuery.getUsername(), uQuery.getFirstName(), uQuery.getLastName(), uQuery.getPhoneNumber(), uQuery.getEmail(), uQuery.getInactive());
    vQuery.SELECT(iQuery.getAltFirstName(), iQuery.getAltLastName(), iQuery.getAltPhoneNumber(), iQuery.getPosition());
    vQuery.SELECT(iQuery.getExternalSystemOid());
    vQuery.WHERE(new LeftJoinEq(uQuery.getOid(), iQuery.getGeoprismUser()));
    vQuery.AND(uQuery.getOid().IN(oids.toArray(new String[oids.size()])));
    vQuery.ORDER_BY_ASC(uQuery.getUsername());
    return serializePage(pageSize, pageNumber, new JSONArray(), vQuery);
}
Also used : RegistryRole(org.commongeoregistry.adapter.metadata.RegistryRole) JsonObject(com.google.gson.JsonObject) RegistryRoleConverter(net.geoprism.registry.conversion.RegistryRoleConverter) Transaction(com.runwaysdk.dataaccess.transaction.Transaction) ValueObject(com.runwaysdk.dataaccess.ValueObject) ConfigurationIF(net.geoprism.ConfigurationIF) Random(java.util.Random) AttributeBooleanIF(com.runwaysdk.dataaccess.AttributeBooleanIF) DefaultConfiguration(net.geoprism.DefaultConfiguration) ServiceFactory(net.geoprism.registry.service.ServiceFactory) AttributeValueException(com.runwaysdk.dataaccess.attributes.AttributeValueException) HashSet(java.util.HashSet) ValueQuery(com.runwaysdk.query.ValueQuery) JSONObject(org.json.JSONObject) GeoprismUserQuery(net.geoprism.GeoprismUserQuery) QueryFactory(com.runwaysdk.query.QueryFactory) ConfigurationService(net.geoprism.ConfigurationService) RoleDAO(com.runwaysdk.business.rbac.RoleDAO) LinkedList(java.util.LinkedList) AttributeBoolean(com.runwaysdk.dataaccess.attributes.entity.AttributeBoolean) RoleDAOIF(com.runwaysdk.business.rbac.RoleDAOIF) Set(java.util.Set) Roles(com.runwaysdk.system.Roles) Collectors(java.util.stream.Collectors) BusinessFacade(com.runwaysdk.business.BusinessFacade) UserDAO(com.runwaysdk.business.rbac.UserDAO) LeftJoinEq(com.runwaysdk.query.LeftJoinEq) OIterator(com.runwaysdk.query.OIterator) List(java.util.List) UserDAOIF(com.runwaysdk.business.rbac.UserDAOIF) GeoprismUser(net.geoprism.GeoprismUser) SingleActorDAOIF(com.runwaysdk.business.rbac.SingleActorDAOIF) ExternalSystem(net.geoprism.registry.graph.ExternalSystem) Session(com.runwaysdk.session.Session) RolePermissionService(net.geoprism.registry.permission.RolePermissionService) JSONArray(org.json.JSONArray) ValueQuery(com.runwaysdk.query.ValueQuery) LeftJoinEq(com.runwaysdk.query.LeftJoinEq) QueryFactory(com.runwaysdk.query.QueryFactory) GeoprismUserQuery(net.geoprism.GeoprismUserQuery) JSONArray(org.json.JSONArray) SingleActorDAOIF(com.runwaysdk.business.rbac.SingleActorDAOIF) RoleDAOIF(com.runwaysdk.business.rbac.RoleDAOIF)

Example 2 with GeoprismUserQuery

use of net.geoprism.GeoprismUserQuery in project geoprism-registry by terraframe.

the class UserInfoPatch method doIt.

@Transaction
private void doIt() {
    UserInfoQuery query = new UserInfoQuery(new QueryFactory());
    try (OIterator<? extends UserInfo> it = query.getIterator()) {
        while (it.hasNext()) {
            UserInfo info = it.next();
            info.appLock();
            info.apply();
        }
    }
    // Ensure all geoprism users have a user info
    GeoprismUserQuery gQuery = new GeoprismUserQuery(new QueryFactory());
    try (OIterator<? extends GeoprismUser> it = gQuery.getIterator()) {
        while (it.hasNext()) {
            GeoprismUser user = it.next();
            UserInfo info = UserInfo.getByUser(user);
            if (info == null) {
                info = new UserInfo();
                info.setGeoprismUser(user);
                info.apply();
            }
        }
    }
}
Also used : QueryFactory(com.runwaysdk.query.QueryFactory) GeoprismUserQuery(net.geoprism.GeoprismUserQuery) UserInfo(net.geoprism.registry.UserInfo) GeoprismUser(net.geoprism.GeoprismUser) UserInfoQuery(net.geoprism.registry.UserInfoQuery) Transaction(com.runwaysdk.dataaccess.transaction.Transaction)

Example 3 with GeoprismUserQuery

use of net.geoprism.GeoprismUserQuery in project geoprism-registry by terraframe.

the class TestUserInfo method getGeoprismUser.

public GeoprismUser getGeoprismUser() {
    GeoprismUserQuery query = new GeoprismUserQuery(new QueryFactory());
    query.WHERE(query.getUsername().EQ(this.username));
    OIterator<? extends GeoprismUser> it = query.getIterator();
    try {
        if (it.hasNext()) {
            return it.next();
        } else {
            return null;
        }
    } finally {
        it.close();
    }
}
Also used : QueryFactory(com.runwaysdk.query.QueryFactory) GeoprismUserQuery(net.geoprism.GeoprismUserQuery)

Example 4 with GeoprismUserQuery

use of net.geoprism.GeoprismUserQuery in project geoprism-registry by terraframe.

the class UserInfo method page.

public static JSONObject page(Integer pageSize, Integer pageNumber) {
    final RolePermissionService perms = ServiceFactory.getRolePermissionService();
    List<Organization> organizations = Organization.getUserOrganizations();
    boolean isSRA = perms.isSRA();
    boolean isRMorRCorAC = (!isSRA && !perms.isRA()) && (perms.isRM() || perms.isRC() || perms.isAC());
    List<ExternalSystem> externalSystemList = ExternalSystem.getExternalSystemsForOrg(1, 100);
    JSONArray externalSystems = new JSONArray();
    for (ExternalSystem externalSystem : externalSystemList) {
        externalSystems.put(new JSONObject(externalSystem.toJSON().toString()));
    }
    if (organizations.size() > 0 || isSRA) {
        ValueQuery vQuery = new ValueQuery(new QueryFactory());
        GeoprismUserQuery uQuery = new GeoprismUserQuery(vQuery);
        UserInfoQuery iQuery = new UserInfoQuery(vQuery);
        vQuery.SELECT(uQuery.getOid(), uQuery.getUsername(), uQuery.getFirstName(), uQuery.getLastName(), uQuery.getPhoneNumber(), uQuery.getEmail(), uQuery.getInactive());
        vQuery.SELECT(iQuery.getAltFirstName(), iQuery.getAltLastName(), iQuery.getAltPhoneNumber(), iQuery.getPosition());
        vQuery.SELECT(iQuery.getExternalSystemOid());
        vQuery.WHERE(new LeftJoinEq(uQuery.getOid(), iQuery.getGeoprismUser()));
        if (organizations.size() > 0) {
            // restrict by org code
            OrganizationQuery orgQuery = new OrganizationQuery(vQuery);
            OrganizationUserQuery relQuery = new OrganizationUserQuery(vQuery);
            for (Organization org : organizations) {
                orgQuery.OR(orgQuery.getCode().EQ(org.getCode()));
            }
            vQuery.WHERE(relQuery.parentOid().EQ(orgQuery.getOid()));
            vQuery.WHERE(uQuery.getOid().EQ(relQuery.childOid()));
        }
        if (isRMorRCorAC) {
            vQuery.WHERE(uQuery.getInactive().EQ(false));
        }
        vQuery.ORDER_BY_ASC(uQuery.getUsername());
        return serializePage(pageSize, pageNumber, externalSystems, vQuery);
    }
    JSONObject page = new JSONObject();
    page.put("resultSet", new JSONArray());
    page.put("count", 0);
    page.put("pageNumber", pageNumber);
    page.put("pageSize", pageSize);
    page.put("externalSystems", externalSystems);
    return page;
}
Also used : RolePermissionService(net.geoprism.registry.permission.RolePermissionService) ValueQuery(com.runwaysdk.query.ValueQuery) QueryFactory(com.runwaysdk.query.QueryFactory) ExternalSystem(net.geoprism.registry.graph.ExternalSystem) JSONArray(org.json.JSONArray) LeftJoinEq(com.runwaysdk.query.LeftJoinEq) JSONObject(org.json.JSONObject) GeoprismUserQuery(net.geoprism.GeoprismUserQuery)

Example 5 with GeoprismUserQuery

use of net.geoprism.GeoprismUserQuery in project geoprism-registry by terraframe.

the class UserInfo method getAdminUser.

private static GeoprismUser getAdminUser() {
    GeoprismUserQuery guq = new GeoprismUserQuery(new QueryFactory());
    guq.WHERE(guq.getUsername().EQ(RegistryConstants.ADMIN_USER_NAME));
    OIterator<? extends GeoprismUser> it = guq.getIterator();
    try {
        if (it.hasNext()) {
            return it.next();
        } else {
            return null;
        }
    } finally {
        it.close();
    }
}
Also used : QueryFactory(com.runwaysdk.query.QueryFactory) GeoprismUserQuery(net.geoprism.GeoprismUserQuery)

Aggregations

QueryFactory (com.runwaysdk.query.QueryFactory)6 GeoprismUserQuery (net.geoprism.GeoprismUserQuery)6 GeoprismUser (net.geoprism.GeoprismUser)3 Transaction (com.runwaysdk.dataaccess.transaction.Transaction)2 LeftJoinEq (com.runwaysdk.query.LeftJoinEq)2 ValueQuery (com.runwaysdk.query.ValueQuery)2 UserInfo (net.geoprism.registry.UserInfo)2 ExternalSystem (net.geoprism.registry.graph.ExternalSystem)2 RolePermissionService (net.geoprism.registry.permission.RolePermissionService)2 JSONArray (org.json.JSONArray)2 JSONObject (org.json.JSONObject)2 JsonObject (com.google.gson.JsonObject)1 BusinessFacade (com.runwaysdk.business.BusinessFacade)1 RoleDAO (com.runwaysdk.business.rbac.RoleDAO)1 RoleDAOIF (com.runwaysdk.business.rbac.RoleDAOIF)1 SingleActorDAOIF (com.runwaysdk.business.rbac.SingleActorDAOIF)1 UserDAO (com.runwaysdk.business.rbac.UserDAO)1 UserDAOIF (com.runwaysdk.business.rbac.UserDAOIF)1 AttributeBooleanIF (com.runwaysdk.dataaccess.AttributeBooleanIF)1 ValueObject (com.runwaysdk.dataaccess.ValueObject)1