Search in sources :

Example 1 with ValueObject

use of com.runwaysdk.dataaccess.ValueObject 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 ValueObject

use of com.runwaysdk.dataaccess.ValueObject in project geoprism-registry by terraframe.

the class UserInfo method serializePage.

private static JSONObject serializePage(Integer pageSize, Integer pageNumber, JSONArray externalSystems, ValueQuery vQuery) {
    JSONArray results = new JSONArray();
    OIterator<ValueObject> it = vQuery.getIterator(pageSize, pageNumber);
    try {
        while (it.hasNext()) {
            ValueObject vObject = it.next();
            JSONObject result = new JSONObject();
            result.put(GeoprismUser.OID, vObject.getValue(GeoprismUser.OID));
            result.put(GeoprismUser.USERNAME, vObject.getValue(GeoprismUser.USERNAME));
            result.put(GeoprismUser.FIRSTNAME, vObject.getValue(GeoprismUser.FIRSTNAME));
            result.put(GeoprismUser.LASTNAME, vObject.getValue(GeoprismUser.LASTNAME));
            result.put(GeoprismUser.PHONENUMBER, vObject.getValue(GeoprismUser.PHONENUMBER));
            result.put(GeoprismUser.EMAIL, vObject.getValue(GeoprismUser.EMAIL));
            result.put(GeoprismUser.INACTIVE, AttributeBoolean.getBooleanValue((AttributeBooleanIF) vObject.getAttributeIF(GeoprismUser.INACTIVE)));
            result.put(UserInfo.ALTFIRSTNAME, vObject.getValue(UserInfo.ALTFIRSTNAME));
            result.put(UserInfo.ALTLASTNAME, vObject.getValue(UserInfo.ALTLASTNAME));
            result.put(UserInfo.ALTPHONENUMBER, vObject.getValue(UserInfo.ALTPHONENUMBER));
            result.put(UserInfo.POSITION, vObject.getValue(UserInfo.POSITION));
            result.put(UserInfo.EXTERNALSYSTEMOID, vObject.getValue(UserInfo.EXTERNALSYSTEMOID));
            results.put(result);
        }
    } finally {
        it.close();
    }
    JSONObject page = new JSONObject();
    page.put("resultSet", results);
    page.put("count", vQuery.getCount());
    page.put("pageNumber", pageNumber);
    page.put("pageSize", pageSize);
    page.put("externalSystems", externalSystems);
    return page;
}
Also used : JSONObject(org.json.JSONObject) AttributeBooleanIF(com.runwaysdk.dataaccess.AttributeBooleanIF) JSONArray(org.json.JSONArray) ValueObject(com.runwaysdk.dataaccess.ValueObject)

Example 3 with ValueObject

use of com.runwaysdk.dataaccess.ValueObject 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 ValueObject

use of com.runwaysdk.dataaccess.ValueObject 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 ValueObject

use of com.runwaysdk.dataaccess.ValueObject 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

ValueObject (com.runwaysdk.dataaccess.ValueObject)7 ValueQuery (com.runwaysdk.query.ValueQuery)6 QueryFactory (com.runwaysdk.query.QueryFactory)5 JsonArray (com.google.gson.JsonArray)3 MdAttributeConcreteDAOIF (com.runwaysdk.dataaccess.MdAttributeConcreteDAOIF)3 MdBusinessDAOIF (com.runwaysdk.dataaccess.MdBusinessDAOIF)3 ProgrammingErrorException (com.runwaysdk.dataaccess.ProgrammingErrorException)3 JsonObject (com.google.gson.JsonObject)2 BusinessQuery (com.runwaysdk.business.BusinessQuery)2 Condition (com.runwaysdk.query.Condition)2 OIterator (com.runwaysdk.query.OIterator)2 IOException (java.io.IOException)2 DateFormat (java.text.DateFormat)2 JSONException (org.json.JSONException)2 UnsupportedOperationException (com.amazonaws.services.kms.model.UnsupportedOperationException)1 RoleDAOIF (com.runwaysdk.business.rbac.RoleDAOIF)1 MdAttributeDateTimeUtil (com.runwaysdk.constants.MdAttributeDateTimeUtil)1 AttributeBooleanIF (com.runwaysdk.dataaccess.AttributeBooleanIF)1 AttributeIF (com.runwaysdk.dataaccess.AttributeIF)1 DataNotFoundException (com.runwaysdk.dataaccess.cache.DataNotFoundException)1