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