use of com.runwaysdk.business.graph.GraphQuery in project geoprism-registry by terraframe.
the class VertexServerGeoObject method buildAncestorQueryFast.
/**
* @param hierarchy
* @param parents
* The parent types, sorted from the top to the bottom
* @return
*/
private GraphQuery<Map<String, Object>> buildAncestorQueryFast(ServerHierarchyType hierarchy, List<ServerGeoObjectType> parents) {
LinkedList<ServerHierarchyType> inheritancePath = new LinkedList<ServerHierarchyType>();
inheritancePath.add(hierarchy);
for (int i = parents.size() - 1; i >= 0; --i) {
ServerGeoObjectType parent = parents.get(i);
if (parent.isRoot(hierarchy)) {
ServerHierarchyType inheritedHierarchy = parent.getInheritedHierarchy(hierarchy);
if (inheritedHierarchy != null) {
inheritancePath.addFirst(inheritedHierarchy);
}
}
}
String dbClassName = this.getMdClass().getDBClassName();
// select code, displayLabel_cot from (
// TRAVERSE inE('adh0')[DATE('2021-06-10','yyyy-MM-dd') between startDate
// AND endDate].outV() FROM (
// TRAVERSE inE('hfgh0')[DATE('2021-06-10','yyyy-MM-dd') between startDate
// AND endDate].outV() FROM (
// SELECT FROM ch0 WHERE @rid=#65:0
// )
// )
// )
// WHERE
// exists_cot CONTAINS (value CONTAINS
// 'ea48a4be-aa38-4b92-9d5b-dfd10e0005ba' AND
// DATE('2021-06-10','yyyy-MM-dd') BETWEEN startDate AND endDate)
StringBuilder statement = new StringBuilder();
statement.append("SELECT @class AS cl, " + DefaultAttribute.CODE.getName() + " AS code, " + DefaultAttribute.DISPLAY_LABEL.getName() + "_cot AS label FROM (");
for (ServerHierarchyType hier : inheritancePath) {
if (this.date != null) {
statement.append("TRAVERSE inE('" + hier.getMdEdge().getDBClassName() + "')[:date between startDate AND endDate].outV() FROM (");
} else {
statement.append("TRAVERSE inE('" + hier.getMdEdge().getDBClassName() + "').outV() FROM (");
}
}
statement.append("SELECT FROM " + dbClassName + " WHERE @rid=:rid");
for (ServerHierarchyType hier : inheritancePath) {
statement.append(")");
}
if (this.date != null) {
statement.append(") WHERE exists_cot CONTAINS (value=true AND :date BETWEEN startDate AND endDate)");
} else {
statement.append(") WHERE exists_cot CONTAINS (value=true)");
}
GraphQuery<Map<String, Object>> query = new GraphQuery<Map<String, Object>>(statement.toString());
query.setParameter("rid", this.vertex.getRID());
if (this.date != null) {
query.setParameter("date", this.date);
}
return query;
}
use of com.runwaysdk.business.graph.GraphQuery in project geoprism-registry by terraframe.
the class SearchService method search.
public List<ServerGeoObjectIF> search(String text, Date date, Long limit) {
String suffix = this.getSuffix();
RolePermissionService service = new RolePermissionService();
MdVertexDAOIF mdVertex = MdVertexDAO.getMdVertexDAO(PACKAGE + "." + VERTEX_PREFIX + suffix);
MdAttributeDAOIF code = mdVertex.definesAttribute(CODE);
MdAttributeDAOIF startDate = mdVertex.definesAttribute(START_DATE);
MdAttributeDAOIF endDate = mdVertex.definesAttribute(END_DATE);
MdAttributeDAOIF label = mdVertex.definesAttribute(LABEL);
MdAttributeDAOIF vertexType = mdVertex.definesAttribute(VERTEX_TYPE);
MdEdgeDAOIF mdEdge = MdEdgeDAO.getMdEdgeDAO(PACKAGE + "." + EDGE_PREFIX + suffix);
String attributeName = label.getValue(MdAttributeTextInfo.NAME);
String className = mdVertex.getDBClassName();
String indexName = className + "." + attributeName;
StringBuilder statement = new StringBuilder();
statement.append("SELECT EXPAND(out('" + mdEdge.getDBClassName() + "'))");
statement.append(" FROM " + mdVertex.getDBClassName());
if (text != null) {
String regex = "([+\\-!\\(\\){}\\[\\]^\"~*?:\\\\]|[&\\|]{2})";
String escapedText = text.replaceAll(regex, "\\\\\\\\$1").trim();
statement.append(" WHERE (SEARCH_INDEX(\"" + indexName + "\", \"+" + label.getColumnName() + ":" + escapedText + "*\") = true");
statement.append(" OR :code = " + code.getColumnName() + ")");
} else {
statement.append(" WHERE " + code.getColumnName() + " IS NOT NULL");
}
if (date != null) {
statement.append(" AND :date BETWEEN " + startDate.getColumnName() + " AND " + endDate.getColumnName());
}
if (!service.isSRA() && service.hasSessionUser()) {
statement.append(" AND " + vertexType.getColumnName() + " IN ( :vertexTypes )");
}
statement.append(" ORDER BY " + label.getColumnName() + " DESC");
if (limit != null) {
statement.append(" LIMIT " + limit);
}
List<ServerGeoObjectIF> list = new LinkedList<ServerGeoObjectIF>();
GraphQuery<VertexObject> query = new GraphQuery<VertexObject>(statement.toString());
if (text != null) {
query.setParameter("code", text);
}
if (date != null) {
query.setParameter("date", date);
}
if (!service.isSRA() && service.hasSessionUser()) {
List<String> vertexTypes = new GeoObjectPermissionService().getMandateTypes(service.getOrganization());
query.setParameter("vertexTypes", vertexTypes);
}
List<VertexObject> results = query.getResults();
for (VertexObject result : results) {
MdVertexDAOIF mdVertexType = (MdVertexDAOIF) result.getMdClass();
ServerGeoObjectType type = ServerGeoObjectType.get(mdVertexType);
list.add(new VertexServerGeoObject(type, result, date));
}
return list;
}
use of com.runwaysdk.business.graph.GraphQuery in project geoprism-registry by terraframe.
the class HistoricalRow method getCount.
public static Long getCount(ServerGeoObjectType type, Date startDate, Date endDate) {
MdVertexDAOIF transitionVertex = MdVertexDAO.getMdVertexDAO(Transition.CLASS);
MdAttributeDAOIF eventAttribute = transitionVertex.definesAttribute(Transition.EVENT);
MdVertexDAOIF eventVertex = MdVertexDAO.getMdVertexDAO(TransitionEvent.CLASS);
MdAttributeDAOIF beforeTypeCode = eventVertex.definesAttribute(TransitionEvent.BEFORETYPECODE);
MdAttributeDAOIF afterTypeCode = eventVertex.definesAttribute(TransitionEvent.AFTERTYPECODE);
MdAttributeDAOIF eventDate = eventVertex.definesAttribute(TransitionEvent.EVENTDATE);
List<ServerGeoObjectType> types = new LinkedList<ServerGeoObjectType>();
types.add(type);
types.addAll(type.getSubtypes());
List<String> codes = types.stream().map(t -> t.getCode()).distinct().collect(Collectors.toList());
StringBuilder statement = new StringBuilder();
statement.append("SELECT COUNT(*)");
statement.append(" FROM " + transitionVertex.getDBClassName());
statement.append(" WHERE ( " + eventAttribute.getColumnName() + "." + beforeTypeCode.getColumnName() + " IN :typeCode");
statement.append(" OR " + eventAttribute.getColumnName() + "." + afterTypeCode.getColumnName() + " IN :typeCode )");
statement.append(" AND " + eventAttribute.getColumnName() + "." + eventDate.getColumnName() + " BETWEEN :startDate AND :endDate");
GraphQuery<Long> query = new GraphQuery<Long>(statement.toString());
query.setParameter("typeCode", codes);
query.setParameter("startDate", startDate);
query.setParameter("endDate", endDate);
return query.getSingleResult();
}
use of com.runwaysdk.business.graph.GraphQuery in project geoprism-registry by terraframe.
the class HistoricalRow method getHistoricalReport.
public static Page<HistoricalRow> getHistoricalReport(ServerGeoObjectType type, Date startDate, Date endDate, Integer pageSize, Integer pageNumber) {
MdVertexDAOIF transitionVertex = MdVertexDAO.getMdVertexDAO(Transition.CLASS);
MdAttributeDAOIF eventAttribute = transitionVertex.definesAttribute(Transition.EVENT);
MdAttributeDAOIF sourceAttribute = transitionVertex.definesAttribute(Transition.SOURCE);
MdAttributeDAOIF targetAttribute = transitionVertex.definesAttribute(Transition.TARGET);
MdAttributeDAOIF transitionAttribute = transitionVertex.definesAttribute(Transition.TRANSITIONTYPE);
MdVertexDAOIF eventVertex = MdVertexDAO.getMdVertexDAO(TransitionEvent.CLASS);
MdAttributeDAOIF eventId = eventVertex.definesAttribute(TransitionEvent.EVENTID);
MdAttributeDAOIF beforeTypeCode = eventVertex.definesAttribute(TransitionEvent.BEFORETYPECODE);
MdAttributeDAOIF afterTypeCode = eventVertex.definesAttribute(TransitionEvent.AFTERTYPECODE);
MdAttributeDAOIF eventDate = eventVertex.definesAttribute(TransitionEvent.EVENTDATE);
MdAttributeDAOIF description = eventVertex.definesAttribute(TransitionEvent.DESCRIPTION);
List<ServerGeoObjectType> types = new LinkedList<ServerGeoObjectType>();
types.add(type);
types.addAll(type.getSubtypes());
List<String> codes = types.stream().map(t -> t.getCode()).distinct().collect(Collectors.toList());
StringBuilder statement = new StringBuilder();
statement.append("SELECT " + eventAttribute.getColumnName() + "." + eventId.getColumnName() + " AS " + HistoricalRow.EVENT_ID);
statement.append(", " + eventAttribute.getColumnName() + "." + eventDate.getColumnName() + " AS " + HistoricalRow.EVENT_DATE);
statement.append(", " + transitionAttribute.getColumnName() + " AS " + HistoricalRow.EVENT_TYPE);
statement.append(", " + eventAttribute.getColumnName() + "." + description.getColumnName() + " AS " + HistoricalRow.DESCRIPTION);
statement.append(", " + eventAttribute.getColumnName() + "." + beforeTypeCode.getColumnName() + " AS " + HistoricalRow.BEFORE_TYPE);
statement.append(", " + sourceAttribute.getColumnName() + ".code AS " + HistoricalRow.BEFORE_CODE);
statement.append(", " + sourceAttribute.getColumnName() + ".displayLabel_cot AS " + HistoricalRow.BEFORE_LABEL);
statement.append(", " + eventAttribute.getColumnName() + "." + afterTypeCode.getColumnName() + " AS " + HistoricalRow.AFTER_TYPE);
statement.append(", " + targetAttribute.getColumnName() + ".code AS " + HistoricalRow.AFTER_CODE);
statement.append(", " + targetAttribute.getColumnName() + ".displayLabel_cot AS " + HistoricalRow.AFTER_LABEL);
statement.append(" FROM " + transitionVertex.getDBClassName());
statement.append(" WHERE ( " + eventAttribute.getColumnName() + "." + beforeTypeCode.getColumnName() + " IN :typeCode");
statement.append(" OR " + eventAttribute.getColumnName() + "." + afterTypeCode.getColumnName() + " IN :typeCode )");
statement.append(" AND " + eventAttribute.getColumnName() + "." + eventDate.getColumnName() + " BETWEEN :startDate AND :endDate");
statement.append(" ORDER BY " + eventAttribute.getColumnName() + "." + eventDate.getColumnName() + " DESC");
statement.append(", " + eventAttribute.getColumnName() + "." + eventId.getColumnName());
statement.append(", " + sourceAttribute.getColumnName() + ".code");
statement.append(", " + targetAttribute.getColumnName() + ".code");
if (pageNumber != null && pageSize != null) {
statement.append(" SKIP " + ((pageNumber - 1) * pageSize) + " LIMIT " + pageSize);
}
GraphQuery<Map<String, Object>> query = new GraphQuery<Map<String, Object>>(statement.toString());
query.setParameter("typeCode", codes);
query.setParameter("startDate", startDate);
query.setParameter("endDate", endDate);
Long count = getCount(type, startDate, endDate);
List<HistoricalRow> results = query.getRawResults().stream().map(list -> HistoricalRow.parse(list)).collect(Collectors.toList());
return new Page<HistoricalRow>(count, pageNumber, pageSize, results);
}
use of com.runwaysdk.business.graph.GraphQuery in project geoprism-registry by terraframe.
the class DHIS2ServiceTest method deleteExternalIds.
@Request
private void deleteExternalIds() {
final MdEdgeDAOIF mdEdge = MdEdgeDAO.getMdEdgeDAO(GeoVertex.EXTERNAL_ID);
StringBuilder builder = new StringBuilder();
builder.append("SELECT FROM " + mdEdge.getDBClassName());
builder.append(" WHERE out = :system");
final GraphQuery<EdgeObject> query = new GraphQuery<EdgeObject>(builder.toString());
query.setParameter("system", this.system.getRID());
List<EdgeObject> edges = query.getResults();
for (EdgeObject edge : edges) {
edge.delete();
}
}
Aggregations