use of com.runwaysdk.query.Selectable in project geoprism-registry by terraframe.
the class AbstractBusinessPageQuery method getQuery.
protected BusinessQuery getQuery(ComponentQuery qQuery, BusinessQuery query) {
if (criteria.has("sortField") && criteria.has("sortOrder")) {
String field = criteria.get("sortField").getAsString();
SortOrder order = criteria.get("sortOrder").getAsInt() == 1 ? SortOrder.ASC : SortOrder.DESC;
qQuery.ORDER_BY(query.getS(field), order);
} else if (criteria.has("multiSortMeta")) {
JsonArray sorts = criteria.get("multiSortMeta").getAsJsonArray();
for (int i = 0; i < sorts.size(); i++) {
JsonObject sort = sorts.get(i).getAsJsonObject();
String field = sort.get("field").getAsString();
SortOrder order = sort.get("order").getAsInt() == 1 ? SortOrder.ASC : SortOrder.DESC;
qQuery.ORDER_BY(query.getS(field), order);
}
}
if (criteria.has("filters")) {
JsonObject filters = criteria.get("filters").getAsJsonObject();
Iterator<String> keys = filters.keySet().iterator();
while (keys.hasNext()) {
String attributeName = keys.next();
Selectable attribute = query.get(attributeName);
if (attribute != null) {
JsonObject filter = filters.get(attributeName).getAsJsonObject();
String mode = filter.get("matchMode").getAsString();
if (attribute instanceof SelectableMoment) {
JsonObject value = filter.get("value").getAsJsonObject();
if (value.has("startDate") && !value.get("startDate").isJsonNull()) {
String date = value.get("startDate").getAsString();
if (date.length() > 0) {
qQuery.WHERE(((SelectableMoment) attribute).GE(GeoRegistryUtil.parseDate(date)));
}
}
if (value.has("endDate") && !value.get("endDate").isJsonNull()) {
String date = value.get("endDate").getAsString();
if (date.length() > 0) {
qQuery.WHERE(((SelectableMoment) attribute).LE(GeoRegistryUtil.parseDate(date)));
}
}
} else if (attribute instanceof SelectableBoolean) {
String value = filter.get("value").getAsString();
filterBoolean(qQuery, attribute, Boolean.valueOf(value));
} else if (mode.equals("contains")) {
String value = filter.get("value").getAsString();
SelectableChar selectable = (SelectableChar) attribute;
qQuery.WHERE(selectable.LIKEi("%" + value + "%"));
} else if (mode.equals("equals")) {
String value = filter.get("value").getAsString();
qQuery.WHERE(attribute.EQ(value));
}
}
}
}
return query;
}
use of com.runwaysdk.query.Selectable in project geoprism-registry by terraframe.
the class ListTypeVersionPageQuery method getQuery.
@Override
protected BusinessQuery getQuery(ComponentQuery qQuery, BusinessQuery query) {
super.getQuery(qQuery, query);
if (!showInvalid) {
Selectable attribute = query.get(DefaultAttribute.INVALID.getName());
qQuery.WHERE(((SelectableBoolean) attribute).EQ(Boolean.FALSE));
}
return query;
}
use of com.runwaysdk.query.Selectable in project geoprism-registry by terraframe.
the class ChangeRequestService method findPageNumber.
// An attempt to do this without selectable sqls
// private int findPageNumber(String crOid, ChangeRequestQuery query, int pageSize)
// {
// QueryFactory qf = new QueryFactory();
// ValueQuery vq = new ValueQuery(qf);
//
// vq.FROM(query);
//
// vq.SELECT(query.getOid());
// vq.SELECT(query.getCreateDate());
//
// Selectable createDate = query.getCreateDate();
//
// vq.SELECT(vq.RANK("rn").OVER(null, new OrderBy(createDate, SortOrder.DESC)));
//
// vq.WHERE(query.getOid().EQ(crOid));
//
// ValueObject vo = vq.getIterator().getAll().get(0);
//
// long rowNum = Long.parseLong(vo.getValue("rn"));
//
// int pageNum = (int) ( (rowNum / pageSize) + 1 );
//
// return pageNum;
// }
private int findPageNumber(String crOid, ChangeRequestQuery query, int pageSize) {
QueryFactory qf = new QueryFactory();
ValueQuery innerVq = new ValueQuery(qf);
String sub1Sql = query.getSQL();
innerVq.FROM("(" + sub1Sql + ")", "sub1");
String createDateAlias = query.getCreateDate().getColumnAlias();
Matcher m = Pattern.compile("change_request_\\d+\\.create_date AS (create_date_\\d+),").matcher(sub1Sql);
if (m.find()) {
createDateAlias = m.group(1);
}
innerVq.SELECT(innerVq.aSQLCharacter("oid", "oid"));
// The rank function is forcing a group by, which we don't want to do. It also doesn't use our alias.
// SelectableSQLDate createDate = innerVq.aSQLDate(query.getCreateDate().getColumnAlias(), query.getCreateDate().getColumnAlias());
// AggregateFunction rank = innerVq.RANK("rn").OVER(null, new OrderBy(createDate, SortOrder.DESC));
Selectable rank = innerVq.aSQLInteger("rn", "(ROW_NUMBER() OVER (ORDER BY " + createDateAlias + " DESC))");
innerVq.SELECT(rank);
ValueQuery outerVq = new ValueQuery(qf);
outerVq.FROM("(" + innerVq.getSQL() + ")", "sub2");
Selectable oidSel = outerVq.aSQLCharacter("oid", "oid");
outerVq.SELECT(oidSel);
outerVq.SELECT(outerVq.aSQLInteger("rn", "rn"));
outerVq.WHERE(oidSel.EQ(crOid));
List<ValueObject> voList = outerVq.getIterator().getAll();
if (voList.size() > 0) {
ValueObject vo = voList.get(0);
long rowNum = Long.parseLong(vo.getValue("rn"));
int pageNum = (int) ((rowNum / pageSize) + 1);
return pageNum;
} else {
return 1;
}
}
use of com.runwaysdk.query.Selectable in project geoprism-registry by terraframe.
the class ChangeRequestService method getAllRequests.
@SuppressWarnings({ "unchecked", "rawtypes" })
@Request(RequestType.SESSION)
public Page<ChangeRequest> getAllRequests(String sessionId, int pageSize, int pageNumber, String filter, String sort, String oid) {
ChangeRequestQuery query = new ChangeRequestQuery(new QueryFactory());
if (filter != null && filter.length() > 0 && !filter.equals("ALL")) {
query.WHERE(query.getApprovalStatus().containsAll(AllGovernanceStatus.valueOf(filter)));
}
filterQueryBasedOnPermissions(query);
if (oid != null && oid.length() > 0) {
pageNumber = this.findPageNumber(oid, query, pageSize);
}
query.restrictRows(pageSize, pageNumber);
if (sort != null && sort.length() > 0 && sort != "[]") {
JsonArray ja = JsonParser.parseString(sort).getAsJsonArray();
for (int i = 0; i < ja.size(); ++i) {
JsonObject jo = ja.get(i).getAsJsonObject();
boolean ascending = jo.get("ascending").getAsBoolean();
String attribute = jo.get("attribute").getAsString();
Selectable sel = query.get(attribute);
if (attribute.equals(ChangeRequest.GEOOBJECTLABEL) || attribute.equals(ChangeRequest.GEOOBJECTTYPELABEL)) {
sel = ((AttributeLocal) sel).localize();
} else if (attribute.equals(ChangeRequest.APPROVALSTATUS)) {
sel = query.getApprovalStatus().getEnumName();
}
query.ORDER_BY(sel, ascending ? SortOrder.ASC : SortOrder.DESC);
}
} else {
query.ORDER_BY_DESC(query.getCreateDate());
}
List<? extends ChangeRequest> list = query.getIterator().getAll();
for (ChangeRequest cr : list) {
if (!ServiceFactory.getMetadataCache().getGeoObjectType(cr.getGeoObjectTypeCode()).isPresent()) {
cr.lock();
cr.clearApprovalStatus();
cr.addApprovalStatus(AllGovernanceStatus.INVALID);
cr.apply();
}
}
return new Page(query.getCount(), pageNumber, pageSize, list);
}
Aggregations