use of com.runwaysdk.business.graph.GraphQuery in project geoprism-registry by terraframe.
the class VertexServerGeoObject method getVertexByCode.
public static VertexObject getVertexByCode(ServerGeoObjectType type, String code) {
String statement = "SELECT FROM " + type.getMdVertex().getDBClassName();
statement += " WHERE code = :code";
GraphQuery<GeoVertex> query = new GraphQuery<GeoVertex>(statement);
query.setParameter("code", code);
return query.getSingleResult();
}
use of com.runwaysdk.business.graph.GraphQuery in project geoprism-registry by terraframe.
the class AbstractGraphPageQuery method getCount.
public Long getCount() {
final MdVertexDAOIF mdVertex = MdVertexDAO.getMdVertexDAO(this.type);
StringBuilder statement = new StringBuilder();
statement.append("SELECT COUNT(*) FROM " + mdVertex.getDBClassName() + "");
Map<String, Object> parameters = new HashMap<String, Object>();
if (criteria.has("filters")) {
JsonObject filters = criteria.get("filters").getAsJsonObject();
this.addCriteria(mdVertex, filters, statement, parameters);
}
final GraphQuery<Long> query = new GraphQuery<Long>(statement.toString(), parameters);
return query.getSingleResult();
}
use of com.runwaysdk.business.graph.GraphQuery in project geoprism-registry by terraframe.
the class AbstractGraphPageQuery method getPage.
public Page<T> getPage() {
int pageSize = 10;
int pageNumber = 1;
Long count = this.getCount();
final MdVertexDAOIF mdVertex = MdVertexDAO.getMdVertexDAO(this.type);
StringBuilder statement = new StringBuilder();
statement.append("SELECT ");
this.addSelectAttributes(mdVertex, statement);
statement.append(" FROM " + mdVertex.getDBClassName() + "");
Map<String, Object> parameters = new HashMap<String, Object>();
if (criteria.has("filters")) {
JsonObject filters = criteria.get("filters").getAsJsonObject();
this.addCriteria(mdVertex, filters, statement, parameters);
}
if (criteria.has("sortField") && criteria.has("sortOrder")) {
String field = criteria.get("sortField").getAsString();
SortOrder order = criteria.get("sortOrder").getAsInt() == 1 ? SortOrder.ASC : SortOrder.DESC;
MdAttributeDAOIF mdAttribute = mdVertex.definesAttribute(field);
statement.append(" ORDER BY " + this.getColumnName(mdAttribute) + " " + order.name());
} 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;
MdAttributeDAOIF mdAttribute = mdVertex.definesAttribute(field);
if (i == 0) {
statement.append(" ORDER BY " + this.getColumnName(mdAttribute) + " " + order.name());
} else {
statement.append(", " + this.getColumnName(mdAttribute) + " " + order.name());
}
}
}
if (criteria.has("first") && criteria.has("rows")) {
int first = criteria.get("first").getAsInt();
int rows = criteria.get("rows").getAsInt();
statement.append(" SKIP " + first + " LIMIT " + rows);
pageNumber = (first / rows) + 1;
}
final GraphQuery<K> query = new GraphQuery<K>(statement.toString(), parameters);
return new Page<T>(count, pageNumber, pageSize, this.getResults(query));
}
use of com.runwaysdk.business.graph.GraphQuery in project geoprism-registry by terraframe.
the class LocationService method getGeoObjects.
// @Request(RequestType.SESSION)
// public LocationInformation getLocationInformation(String sessionId, String code, String typeCode, Date date, String childTypeCode, String hierarchyCode)
// {
// LocationInformation information = new LocationInformation();
//
// ServerGeoObjectIF go = this.service.getGeoObjectByCode(code, typeCode);
// go.setDate(date);
//
// ServerGeoObjectType type = go.getType();
// List<ServerHierarchyType> hierarchies = type.getHierarchies();
//
// ServerHierarchyType hierarchy = null;
//
// if (hierarchyCode == null || hierarchyCode.length() == 0)
// {
// hierarchy = hierarchies.get(0);
// }
// else
// {
// hierarchy = ServerHierarchyType.get(hierarchyCode);
// }
//
// List<ServerGeoObjectType> childTypes = type.getChildren(hierarchy);
// ServerGeoObjectType childType = null;
//
// if (childTypes.size() > 0)
// {
// /*
// * If a typeCode is given and it is an option based on the hierarchy than
// * use that type otherwise use the first type code
// */
// childType = childTypes.get(0);
//
// if (childTypeCode != null && childTypeCode.length() > 0)
// {
// for (ServerGeoObjectType child : childTypes)
// {
// if (child.getCode().equals(childTypeCode))
// {
// childType = child;
// }
// }
// }
// }
//
// if (childType != null)
// {
// information.setChildType(childType.getType());
//
// List<VertexServerGeoObject> children = this.getGeoObjects(go.getCode(), childType.getCode(), hierarchy.getCode(), date);
//
// for (VertexServerGeoObject child : children)
// {
// information.addChild(child.toGeoObject());
// }
// }
//
// information.setChildTypes(childTypes);
// information.setHierarchies(hierarchies);
// information.setHierarchy(hierarchy.getCode());
// information.setEntity(go.toGeoObject());
//
// return information;
// }
// @Request(RequestType.SESSION)
// public JsonObject getChildrenGeoJson(String sessionId, String typeCode,
// String parentId, String hierarchyCode)
// {
// List<VertexServerGeoObject> children = parentId != null ?
// this.getGeoObjects(typeCode, parentId, hierarchyCode) :
// this.getGeoObjects(typeCode);
//
// return children;
// }
private List<VertexServerGeoObject> getGeoObjects(String typeCode, Date date) {
ServerGeoObjectType type = ServerGeoObjectType.get(typeCode);
MdVertexDAOIF mdVertex = type.getMdVertex();
StringBuilder statement = new StringBuilder();
statement.append("SELECT FROM " + mdVertex.getDBClassName());
statement.append(" ORDER BY code");
GraphQuery<VertexObject> query = new GraphQuery<VertexObject>(statement.toString());
List<VertexObject> vObjects = query.getResults();
List<VertexServerGeoObject> response = new LinkedList<VertexServerGeoObject>();
for (VertexObject vObject : vObjects) {
VertexServerGeoObject vSGO = new VertexServerGeoObject(type, vObject);
vSGO.setDate(date);
response.add(vSGO);
}
return response;
}
use of com.runwaysdk.business.graph.GraphQuery in project geoprism-registry by terraframe.
the class RegistryService method getGeoObjectSuggestions.
/*
*
* select $filteredLabel,* from province0 let $dateLabel =
* first(displayLabel_cot[(date('2020-05-01', 'yyyy-MM-dd') BETWEEN startDate
* AND endDate) AND (date('2020-05-01', 'yyyy-MM-dd') BETWEEN startDate AND
* endDate)]), $filteredLabel = COALESCE($dateLabel.value.defaultLocale) where
* ( displayLabel_cot CONTAINS ( (date('2020-05-01', 'yyyy-MM-dd') BETWEEN
* startDate AND endDate) AND (date('2020-05-01', 'yyyy-MM-dd') BETWEEN
* startDate AND endDate) AND COALESCE(value.defaultLocale).toLowerCase() LIKE
* '%' + 'a' + '%' ) OR code.toLowerCase() LIKE '%' + 'a' + '%' ) AND
* invalid=false AND ( exists_cot CONTAINS ( (date('2020-05-01', 'yyyy-MM-dd')
* BETWEEN startDate AND endDate) AND (date('2020-05-01', 'yyyy-MM-dd')
* BETWEEN startDate AND endDate) AND value=true ) ) ORDER BY $filteredLabel
* ASC LIMIT 10
*/
@Request(RequestType.SESSION)
public JsonArray getGeoObjectSuggestions(String sessionId, String text, String typeCode, String parentCode, String parentTypeCode, String hierarchyCode, Date startDate, Date endDate) {
final ServerGeoObjectType type = ServerGeoObjectType.get(typeCode);
ServerHierarchyType ht = hierarchyCode != null ? ServerHierarchyType.get(hierarchyCode) : null;
final ServerGeoObjectType parentType = ServerGeoObjectType.get(parentTypeCode);
List<String> conditions = new ArrayList<String>();
StringBuilder statement = new StringBuilder();
statement.append("select $filteredLabel,@class as clazz,* from " + type.getMdVertex().getDBClassName() + " ");
statement.append("let $dateLabel = first(displayLabel_cot");
if (startDate != null && endDate != null) {
statement.append("[(:startDate BETWEEN startDate AND endDate) AND (:endDate BETWEEN startDate AND endDate)]");
}
statement.append("), ");
statement.append("$filteredLabel = " + AbstractVertexRestriction.localize("$dateLabel.value") + " ");
statement.append("where ");
// Must be a child of parent type
if (parentTypeCode != null && parentTypeCode.length() > 0) {
StringBuilder parentCondition = new StringBuilder();
parentCondition.append("(@rid in ( TRAVERSE outE('" + ht.getMdEdge().getDBClassName() + "')");
if (startDate != null && endDate != null) {
parentCondition.append("[(:startDate BETWEEN startDate AND endDate) AND (:endDate BETWEEN startDate AND endDate)]");
}
parentCondition.append(".inV() FROM (select from " + parentType.getMdVertex().getDBClassName() + " where code='" + parentCode + "') )) ");
conditions.add(parentCondition.toString());
}
// Must have display label we expect
if (text != null && text.length() > 0) {
StringBuilder textCondition = new StringBuilder();
textCondition.append("(displayLabel_cot CONTAINS (");
if (startDate != null && endDate != null) {
textCondition.append(" (:startDate BETWEEN startDate AND endDate) AND (:endDate BETWEEN startDate AND endDate) AND ");
}
textCondition.append(AbstractVertexRestriction.localize("value") + ".toLowerCase() LIKE '%' + :text + '%'");
textCondition.append(")");
textCondition.append(" OR code.toLowerCase() LIKE '%' + :text + '%')");
conditions.add(textCondition.toString());
}
// Must not be invalid
conditions.add("invalid=false");
// Must exist at date
{
StringBuilder existCondition = new StringBuilder();
existCondition.append("(exists_cot CONTAINS (");
if (startDate != null && endDate != null) {
existCondition.append(" (:startDate BETWEEN startDate AND endDate) AND (:endDate BETWEEN startDate AND endDate) AND ");
}
existCondition.append("value=true");
existCondition.append("))");
conditions.add(existCondition.toString());
}
statement.append(StringUtils.join(conditions, " AND "));
statement.append(" ORDER BY $filteredLabel ASC LIMIT 10");
GraphQuery<VertexObject> query = new GraphQuery<VertexObject>(statement.toString());
if (startDate != null && endDate != null) {
query.setParameter("startDate", startDate);
query.setParameter("endDate", endDate);
}
if (text != null) {
query.setParameter("text", text.toLowerCase().trim());
} else {
query.setParameter("text", text);
}
@SuppressWarnings("unchecked") List<HashMap<String, Object>> results = (List<HashMap<String, Object>>) ((Object) query.getResults());
JsonArray array = new JsonArray();
for (HashMap<String, Object> row : results) {
ServerGeoObjectType rowType = ServerGeoObjectType.get((MdVertexDAOIF) MdGraphClassDAO.getMdGraphClassByTableName((String) row.get("clazz")));
if (ServiceFactory.getGeoObjectPermissionService().canRead(rowType.getOrganization().getCode(), rowType)) {
JsonObject result = new JsonObject();
result.addProperty("id", (String) row.get("oid"));
result.addProperty("name", (String) row.get("$filteredLabel"));
result.addProperty(GeoObject.CODE, (String) row.get("code"));
result.addProperty(GeoObject.UID, (String) row.get("uuid"));
result.addProperty("typeCode", rowType.getCode());
array.add(result);
}
}
return array;
}
Aggregations