Search in sources :

Example 1 with ValueQuery

use of com.runwaysdk.query.ValueQuery in project geoprism-registry by terraframe.

the class MasterListVersion method values.

public JsonArray values(String value, String attributeName, String valueAttribute, String filterJson) {
    DateFormat filterFormat = new SimpleDateFormat(GeoObjectImportConfiguration.DATE_FORMAT);
    filterFormat.setTimeZone(GeoRegistryUtil.SYSTEM_TIMEZONE);
    JsonArray results = new JsonArray();
    MdBusinessDAOIF mdBusiness = MdBusinessDAO.get(this.getMdBusinessOid());
    ValueQuery vQuery = new ValueQuery(new QueryFactory());
    BusinessQuery query = new BusinessQuery(vQuery, mdBusiness.definesType());
    vQuery.SELECT_DISTINCT(query.get(attributeName, "label"), query.get(valueAttribute, "value"));
    vQuery.FROM(query);
    Map<MdAttributeConcreteDAOIF, Condition> conditionMap = this.buildQueryConditionsFromFilter(filterJson, attributeName, query, mdBusiness);
    for (Condition condition : conditionMap.values()) {
        vQuery.WHERE(condition);
    }
    if (value != null && value.length() > 0) {
        vQuery.WHERE(query.aCharacter(attributeName).LIKEi("%" + value + "%"));
    }
    vQuery.ORDER_BY_ASC(query.get(attributeName));
    OIterator<ValueObject> it = vQuery.getIterator(100, 1);
    try {
        while (it.hasNext()) {
            ValueObject vObject = it.next();
            JsonObject result = new JsonObject();
            result.addProperty("label", vObject.getValue("label"));
            result.addProperty("value", vObject.getValue("value"));
            results.add(result);
        }
    } finally {
        it.close();
    }
    return results;
}
Also used : ValueQuery(com.runwaysdk.query.ValueQuery) BusinessQuery(com.runwaysdk.business.BusinessQuery) Condition(com.runwaysdk.query.Condition) BasicCondition(com.runwaysdk.query.BasicCondition) MdBusinessDAOIF(com.runwaysdk.dataaccess.MdBusinessDAOIF) QueryFactory(com.runwaysdk.query.QueryFactory) JsonObject(com.google.gson.JsonObject) JsonArray(com.google.gson.JsonArray) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) ValueObject(com.runwaysdk.dataaccess.ValueObject) SimpleDateFormat(java.text.SimpleDateFormat) MdAttributeConcreteDAOIF(com.runwaysdk.dataaccess.MdAttributeConcreteDAOIF)

Example 2 with ValueQuery

use of com.runwaysdk.query.ValueQuery 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 3 with ValueQuery

use of com.runwaysdk.query.ValueQuery in project geoprism-registry by terraframe.

the class TaskService method getTasksForCurrentUser.

@Request(RequestType.SESSION)
public static JsonObject getTasksForCurrentUser(String sessionId, String orderBy, int pageNum, int pageSize, String whereStatus) {
    QueryFactory qf = new QueryFactory();
    ValueQuery vq = new ValueQuery(qf);
    TaskHasRoleQuery thrq = new TaskHasRoleQuery(vq);
    TaskQuery tq = new TaskQuery(vq);
    vq.WHERE(thrq.getParent().EQ(tq));
    if (whereStatus != null) {
        vq.WHERE(tq.getStatus().EQ(whereStatus));
    }
    RolesQuery rq = new RolesQuery(vq);
    vq.WHERE(thrq.getChild().EQ(rq));
    Condition cond = null;
    // Map<String, String> roles = Session.getCurrentSession().getUserRoles();
    Set<RoleDAOIF> roles = Session.getCurrentSession().getUser().assignedRoles();
    // for (String roleName : roles.keySet())
    for (RoleDAOIF role : roles) {
        String roleName = role.getRoleName();
        if (roleName.equals(DefaultConfiguration.ADMIN)) {
            continue;
        }
        if (cond == null) {
            cond = rq.getRoleName().EQ(roleName);
        } else {
            cond = cond.OR(rq.getRoleName().EQ(roleName));
        }
    }
    vq.WHERE(cond);
    LocalizedValueStoreQuery lvsqTemplate = new LocalizedValueStoreQuery(vq);
    vq.WHERE(tq.getTemplate().EQ(lvsqTemplate));
    LocalizedValueStoreQuery lvsqTitle = new LocalizedValueStoreQuery(vq);
    vq.WHERE(tq.getTitle().EQ(lvsqTitle));
    vq.SELECT(tq.getOid("oid"));
    vq.SELECT(lvsqTemplate.getStoreKey("templateKey"));
    vq.SELECT(tq.getMessage().localize("msg"));
    vq.SELECT(lvsqTitle.getStoreValue().localize("title"));
    vq.SELECT(tq.getStatus("status"));
    vq.SELECT(tq.getCreateDate("createDate"));
    vq.SELECT(tq.getLastUpdateDate("completedDate"));
    vq.ORDER_BY(tq.get(orderBy), SortOrder.DESC);
    vq.restrictRows(pageSize, pageNum);
    try (OIterator<ValueObject> it = vq.getIterator()) {
        List<JsonWrapper> results = it.getAll().stream().map(vo -> {
            JsonObject jo = new JsonObject();
            jo.addProperty("id", vo.getValue("oid"));
            jo.addProperty("templateKey", vo.getValue("templateKey"));
            jo.addProperty("msg", vo.getValue("msg"));
            jo.addProperty("title", vo.getValue("title"));
            jo.addProperty("status", vo.getValue("status"));
            jo.addProperty("createDate", ETLService.formatDate(MdAttributeDateTimeUtil.getTypeSafeValue(vo.getValue("createDate"))));
            jo.addProperty("completedDate", vo.getValue("status").equals(TaskStatus.RESOLVED.name()) ? ETLService.formatDate(MdAttributeDateTimeUtil.getTypeSafeValue(vo.getValue("completedDate"))) : null);
            return new JsonWrapper(jo);
        }).collect(Collectors.toList());
        return new Page<JsonWrapper>(vq.getCount(), pageNum, pageSize, results).toJSON();
    }
}
Also used : ValueQuery(com.runwaysdk.query.ValueQuery) Condition(com.runwaysdk.query.Condition) JsonObject(com.google.gson.JsonObject) SortOrder(com.runwaysdk.query.OrderBy.SortOrder) ProgrammingErrorException(com.runwaysdk.dataaccess.ProgrammingErrorException) RequestType(com.runwaysdk.session.RequestType) RoleDAOIF(com.runwaysdk.business.rbac.RoleDAOIF) Set(java.util.Set) ValueObject(com.runwaysdk.dataaccess.ValueObject) LocalizedValueStoreQuery(com.runwaysdk.localization.LocalizedValueStoreQuery) MdAttributeDateTimeUtil(com.runwaysdk.constants.MdAttributeDateTimeUtil) Collectors(java.util.stream.Collectors) Request(com.runwaysdk.session.Request) RolesQuery(com.runwaysdk.system.RolesQuery) DefaultConfiguration(net.geoprism.DefaultConfiguration) ETLService(net.geoprism.registry.etl.ETLService) OIterator(com.runwaysdk.query.OIterator) Page(net.geoprism.registry.view.Page) ValueQuery(com.runwaysdk.query.ValueQuery) List(java.util.List) Condition(com.runwaysdk.query.Condition) JsonWrapper(net.geoprism.registry.view.JsonWrapper) QueryFactory(com.runwaysdk.query.QueryFactory) Session(com.runwaysdk.session.Session) TaskStatus(net.geoprism.registry.task.Task.TaskStatus) QueryFactory(com.runwaysdk.query.QueryFactory) JsonObject(com.google.gson.JsonObject) JsonWrapper(net.geoprism.registry.view.JsonWrapper) RolesQuery(com.runwaysdk.system.RolesQuery) ValueObject(com.runwaysdk.dataaccess.ValueObject) RoleDAOIF(com.runwaysdk.business.rbac.RoleDAOIF) LocalizedValueStoreQuery(com.runwaysdk.localization.LocalizedValueStoreQuery) Request(com.runwaysdk.session.Request)

Example 4 with ValueQuery

use of com.runwaysdk.query.ValueQuery in project geoprism-registry by terraframe.

the class ListTypeVersion method bbox.

public JsonArray bbox(String uid) {
    MdBusinessDAOIF mdBusiness = MdBusinessDAO.get(this.getMdBusinessOid());
    String tableName = mdBusiness.getTableName();
    // collect all the views and extend the bounding box
    ValueQuery union = new ValueQuery(new QueryFactory());
    union.SELECT(union.aSQLClob(GeoserverFacade.GEOM_COLUMN, GeoserverFacade.GEOM_COLUMN, GeoserverFacade.GEOM_COLUMN));
    union.FROM(tableName, tableName);
    if (uid != null && uid.length() > 0) {
        MdAttributeConcreteDAOIF attribute = mdBusiness.definesAttribute(DefaultAttribute.UID.getName());
        String columName = attribute.getColumnName();
        union.WHERE(union.aSQLCharacter(columName, columName).EQ(uid));
    }
    ValueQuery collected = new ValueQuery(union.getQueryFactory());
    collected.SELECT(collected.aSQLAggregateClob("collected", "st_collect(" + GeoserverFacade.GEOM_COLUMN + ")", "collected"));
    collected.FROM("(" + union.getSQL() + ")", "unioned");
    ValueQuery outer = new ValueQuery(union.getQueryFactory());
    outer.SELECT(union.aSQLAggregateDouble("minx", "st_xmin(collected)"), union.aSQLAggregateDouble("miny", "st_ymin(collected)"), union.aSQLAggregateDouble("maxx", "st_xmax(collected)"), union.aSQLAggregateDouble("maxy", "st_ymax(collected)"));
    outer.FROM("(" + collected.getSQL() + ")", "collected");
    try (OIterator<? extends ValueObject> iter = outer.getIterator()) {
        ValueObject o = iter.next();
        try {
            JsonArray bboxArr = new JsonArray();
            bboxArr.add(Double.parseDouble(o.getValue("minx")));
            bboxArr.add(Double.parseDouble(o.getValue("miny")));
            bboxArr.add(Double.parseDouble(o.getValue("maxx")));
            bboxArr.add(Double.parseDouble(o.getValue("maxy")));
            return bboxArr;
        } catch (JSONException ex) {
            throw new ProgrammingErrorException(ex);
        }
    } catch (Exception e) {
        return null;
    // throw new NoLayerDataException();
    }
}
Also used : ValueQuery(com.runwaysdk.query.ValueQuery) JsonArray(com.google.gson.JsonArray) MdBusinessDAOIF(com.runwaysdk.dataaccess.MdBusinessDAOIF) QueryFactory(com.runwaysdk.query.QueryFactory) JSONException(org.json.JSONException) MdAttributeMultiLineString(com.runwaysdk.system.gis.metadata.MdAttributeMultiLineString) MdAttributeLineString(com.runwaysdk.system.gis.metadata.MdAttributeLineString) ValueObject(com.runwaysdk.dataaccess.ValueObject) ProgrammingErrorException(com.runwaysdk.dataaccess.ProgrammingErrorException) JSONException(org.json.JSONException) IOException(java.io.IOException) DataNotFoundException(com.runwaysdk.dataaccess.cache.DataNotFoundException) ParseException(java.text.ParseException) UnsupportedOperationException(com.amazonaws.services.kms.model.UnsupportedOperationException) FileNotFoundException(java.io.FileNotFoundException) ProgrammingErrorException(com.runwaysdk.dataaccess.ProgrammingErrorException) MdAttributeConcreteDAOIF(com.runwaysdk.dataaccess.MdAttributeConcreteDAOIF)

Example 5 with ValueQuery

use of com.runwaysdk.query.ValueQuery in project geoprism-registry by terraframe.

the class ListTypeVersion method values.

public JsonArray values(String value, String attributeName, JsonObject criteria) {
    ValueQuery vQuery = new ValueQuery(new QueryFactory());
    BusinessQuery query = new ListTypeVersionPageQuery(this, criteria, true, false).getQuery(vQuery);
    DateFormat filterFormat = new SimpleDateFormat(GeoObjectImportConfiguration.DATE_FORMAT);
    filterFormat.setTimeZone(GeoRegistryUtil.SYSTEM_TIMEZONE);
    JsonArray results = new JsonArray();
    vQuery.SELECT_DISTINCT(query.get(attributeName, "label"));
    vQuery.FROM(query);
    if (value != null && value.length() > 0) {
        vQuery.WHERE(F.UPPER(query.aCharacter(attributeName)).LIKEi("%" + value.toUpperCase() + "%"));
    }
    try (OIterator<ValueObject> it = vQuery.getIterator(100, 1)) {
        while (it.hasNext()) {
            ValueObject vObject = it.next();
            results.add(vObject.getValue("label"));
        // JsonObject result = new JsonObject();
        // result.addProperty("label", vObject.getValue("label"));
        // result.addProperty("value", vObject.getValue("value"));
        // 
        // results.add(result);
        }
    }
    return results;
}
Also used : ValueQuery(com.runwaysdk.query.ValueQuery) BusinessQuery(com.runwaysdk.business.BusinessQuery) JsonArray(com.google.gson.JsonArray) QueryFactory(com.runwaysdk.query.QueryFactory) ListTypeVersionPageQuery(net.geoprism.registry.query.ListTypeVersionPageQuery) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) ValueObject(com.runwaysdk.dataaccess.ValueObject) SimpleDateFormat(java.text.SimpleDateFormat)

Aggregations

ValueQuery (com.runwaysdk.query.ValueQuery)8 ValueObject (com.runwaysdk.dataaccess.ValueObject)7 QueryFactory (com.runwaysdk.query.QueryFactory)7 JsonArray (com.google.gson.JsonArray)3 JsonObject (com.google.gson.JsonObject)3 MdAttributeConcreteDAOIF (com.runwaysdk.dataaccess.MdAttributeConcreteDAOIF)3 MdBusinessDAOIF (com.runwaysdk.dataaccess.MdBusinessDAOIF)3 ProgrammingErrorException (com.runwaysdk.dataaccess.ProgrammingErrorException)3 OIterator (com.runwaysdk.query.OIterator)3 BusinessQuery (com.runwaysdk.business.BusinessQuery)2 RoleDAOIF (com.runwaysdk.business.rbac.RoleDAOIF)2 Condition (com.runwaysdk.query.Condition)2 LeftJoinEq (com.runwaysdk.query.LeftJoinEq)2 Session (com.runwaysdk.session.Session)2 IOException (java.io.IOException)2 List (java.util.List)2 Set (java.util.Set)2 Collectors (java.util.stream.Collectors)2 DefaultConfiguration (net.geoprism.DefaultConfiguration)2 JSONException (org.json.JSONException)2