Search in sources :

Example 1 with Condition

use of com.runwaysdk.query.Condition 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 Condition

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

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

the class ListTypeVersion method buildQueryConditionsFromFilter.

private Map<MdAttributeConcreteDAOIF, Condition> buildQueryConditionsFromFilter(String filterJson, String ignoreAttribute, ComponentQuery query, MdBusinessDAOIF mdBusiness) {
    Map<MdAttributeConcreteDAOIF, Condition> conditionMap = new HashMap<MdAttributeConcreteDAOIF, Condition>();
    if (filterJson != null && filterJson.length() > 0) {
        DateFormat filterFormat = new SimpleDateFormat(GeoObjectImportConfiguration.DATE_FORMAT);
        filterFormat.setTimeZone(GeoRegistryUtil.SYSTEM_TIMEZONE);
        JsonArray filters = JsonParser.parseString(filterJson).getAsJsonArray();
        for (int i = 0; i < filters.size(); i++) {
            JsonObject filter = filters.get(i).getAsJsonObject();
            String attribute = filter.get("attribute").getAsString();
            if (ignoreAttribute == null || !attribute.equals(ignoreAttribute)) {
                MdAttributeConcreteDAOIF mdAttr = mdBusiness.definesAttribute(attribute);
                BasicCondition condition = null;
                if (mdAttr instanceof MdAttributeMomentDAOIF) {
                    JsonObject jObject = filter.get("value").getAsJsonObject();
                    try {
                        if (jObject.has("start") && !jObject.get("start").isJsonNull()) {
                            String date = jObject.get("start").getAsString();
                            if (date.length() > 0) {
                                condition = query.aDateTime(attribute).GE(filterFormat.parse(date));
                            }
                        }
                        if (jObject.has("end") && !jObject.get("end").isJsonNull()) {
                            String date = jObject.get("end").getAsString();
                            if (date.length() > 0) {
                                condition = query.aDateTime(attribute).LE(filterFormat.parse(date));
                            }
                        }
                    } catch (ParseException e) {
                        throw new ProgrammingErrorException(e);
                    }
                } else if (mdAttr instanceof MdAttributeBooleanDAOIF) {
                    String value = filter.get("value").getAsString();
                    Boolean bVal = Boolean.valueOf(value);
                    condition = ((AttributeBoolean) query.get(attribute)).EQ(bVal);
                } else {
                    String value = filter.get("value").getAsString();
                    condition = query.get(attribute).EQ(value);
                }
                if (condition != null) {
                    if (conditionMap.containsKey(mdAttr)) {
                        conditionMap.put(mdAttr, conditionMap.get(mdAttr).OR(condition));
                    } else {
                        conditionMap.put(mdAttr, condition);
                    }
                }
            }
        }
    }
    return conditionMap;
}
Also used : Condition(com.runwaysdk.query.Condition) BasicCondition(com.runwaysdk.query.BasicCondition) MdAttributeBooleanDAOIF(com.runwaysdk.dataaccess.MdAttributeBooleanDAOIF) HashMap(java.util.HashMap) JsonObject(com.google.gson.JsonObject) MdAttributeMultiLineString(com.runwaysdk.system.gis.metadata.MdAttributeMultiLineString) MdAttributeLineString(com.runwaysdk.system.gis.metadata.MdAttributeLineString) MdAttributeMomentDAOIF(com.runwaysdk.dataaccess.MdAttributeMomentDAOIF) MultiPoint(com.vividsolutions.jts.geom.MultiPoint) MdAttributePoint(com.runwaysdk.system.gis.metadata.MdAttributePoint) MdAttributeMultiPoint(com.runwaysdk.system.gis.metadata.MdAttributeMultiPoint) Point(com.vividsolutions.jts.geom.Point) ProgrammingErrorException(com.runwaysdk.dataaccess.ProgrammingErrorException) JsonArray(com.google.gson.JsonArray) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) MdAttributeBoolean(com.runwaysdk.system.metadata.MdAttributeBoolean) AttributeBoolean(com.runwaysdk.query.AttributeBoolean) ParseException(java.text.ParseException) MdAttributeBoolean(com.runwaysdk.system.metadata.MdAttributeBoolean) AttributeBoolean(com.runwaysdk.query.AttributeBoolean) SimpleDateFormat(java.text.SimpleDateFormat) BasicCondition(com.runwaysdk.query.BasicCondition) MdAttributeConcreteDAOIF(com.runwaysdk.dataaccess.MdAttributeConcreteDAOIF)

Example 4 with Condition

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

the class ListTypeVersion method buildQuery.

public BusinessQuery buildQuery(String filterJson) {
    MdBusinessDAOIF mdBusiness = MdBusinessDAO.get(this.getMdBusinessOid());
    BusinessQuery query = new QueryFactory().businessQuery(mdBusiness.definesType());
    Map<MdAttributeConcreteDAOIF, Condition> conditionMap = this.buildQueryConditionsFromFilter(filterJson, null, query, mdBusiness);
    for (Condition condition : conditionMap.values()) {
        query.WHERE(condition);
    }
    return query;
}
Also used : 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) MdAttributeConcreteDAOIF(com.runwaysdk.dataaccess.MdAttributeConcreteDAOIF)

Example 5 with Condition

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

the class MasterListVersion method buildQuery.

public BusinessQuery buildQuery(String filterJson) {
    MdBusinessDAOIF mdBusiness = MdBusinessDAO.get(this.getMdBusinessOid());
    BusinessQuery query = new QueryFactory().businessQuery(mdBusiness.definesType());
    Map<MdAttributeConcreteDAOIF, Condition> conditionMap = this.buildQueryConditionsFromFilter(filterJson, null, query, mdBusiness);
    for (Condition condition : conditionMap.values()) {
        query.WHERE(condition);
    }
    return query;
}
Also used : 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) MdAttributeConcreteDAOIF(com.runwaysdk.dataaccess.MdAttributeConcreteDAOIF)

Aggregations

Condition (com.runwaysdk.query.Condition)8 MdAttributeConcreteDAOIF (com.runwaysdk.dataaccess.MdAttributeConcreteDAOIF)5 BasicCondition (com.runwaysdk.query.BasicCondition)5 JsonObject (com.google.gson.JsonObject)4 ProgrammingErrorException (com.runwaysdk.dataaccess.ProgrammingErrorException)4 QueryFactory (com.runwaysdk.query.QueryFactory)4 JsonArray (com.google.gson.JsonArray)3 BusinessQuery (com.runwaysdk.business.BusinessQuery)3 RoleDAOIF (com.runwaysdk.business.rbac.RoleDAOIF)3 MdBusinessDAOIF (com.runwaysdk.dataaccess.MdBusinessDAOIF)3 DateFormat (java.text.DateFormat)3 SimpleDateFormat (java.text.SimpleDateFormat)3 SingleActorDAOIF (com.runwaysdk.business.rbac.SingleActorDAOIF)2 MdAttributeBooleanDAOIF (com.runwaysdk.dataaccess.MdAttributeBooleanDAOIF)2 MdAttributeMomentDAOIF (com.runwaysdk.dataaccess.MdAttributeMomentDAOIF)2 ValueObject (com.runwaysdk.dataaccess.ValueObject)2 AttributeBoolean (com.runwaysdk.query.AttributeBoolean)2 ValueQuery (com.runwaysdk.query.ValueQuery)2 MdAttributeLineString (com.runwaysdk.system.gis.metadata.MdAttributeLineString)2 MdAttributeMultiLineString (com.runwaysdk.system.gis.metadata.MdAttributeMultiLineString)2