use of net.geoprism.registry.model.ServerHierarchyType in project geoprism-registry by terraframe.
the class VertexServerGeoObject method internalGetParentGeoObjects.
protected static ServerParentTreeNode internalGetParentGeoObjects(VertexServerGeoObject child, String[] parentTypes, boolean recursive, ServerHierarchyType htIn, Date date) {
ServerParentTreeNode tnRoot = new ServerParentTreeNode(child, htIn, date, null, null);
Map<String, Object> parameters = new HashedMap<String, Object>();
parameters.put("rid", child.getVertex().getRID());
StringBuilder statement = new StringBuilder();
statement.append("SELECT EXPAND( inE(");
if (htIn != null) {
statement.append("'" + htIn.getMdEdge().getDBClassName() + "'");
}
statement.append(")");
if (date != null || (parentTypes != null && parentTypes.length > 0)) {
statement.append("[");
if (date != null) {
statement.append(" :date BETWEEN startDate AND endDate");
parameters.put("date", date);
}
if (parentTypes != null && parentTypes.length > 0) {
if (date != null) {
statement.append(" AND");
}
statement.append("(");
for (int i = 0; i < parentTypes.length; i++) {
ServerGeoObjectType type = ServerGeoObjectType.get(parentTypes[i]);
final String paramName = "p" + Integer.toString(i);
if (i > 0) {
statement.append(" OR ");
}
statement.append("out.@class = :" + paramName);
parameters.put(paramName, type.getMdVertex().getDBClassName());
}
statement.append(")");
}
statement.append("]");
}
statement.append(") FROM :rid");
GraphQuery<EdgeObject> query = new GraphQuery<EdgeObject>(statement.toString(), parameters);
List<EdgeObject> edges = query.getResults();
for (EdgeObject edge : edges) {
MdEdgeDAOIF mdEdge = (MdEdgeDAOIF) edge.getMdClass();
if (HierarchicalRelationshipType.isEdgeAHierarchyType(mdEdge)) {
final VertexObject parentVertex = edge.getParent();
MdVertexDAOIF mdVertex = (MdVertexDAOIF) parentVertex.getMdClass();
ServerHierarchyType ht = ServerHierarchyType.get(mdEdge);
ServerGeoObjectType parentType = ServerGeoObjectType.get(mdVertex);
VertexServerGeoObject parent = new VertexServerGeoObject(parentType, parentVertex, date);
ServerParentTreeNode tnParent;
if (recursive) {
tnParent = internalGetParentGeoObjects(parent, parentTypes, recursive, ht, date);
} else {
tnParent = new ServerParentTreeNode(parent, ht, date, null, edge.getOid());
}
tnRoot.addParent(tnParent);
}
}
return tnRoot;
}
use of net.geoprism.registry.model.ServerHierarchyType 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 net.geoprism.registry.model.ServerHierarchyType in project geoprism-registry by terraframe.
the class VertexSynonymRestriction method restrict.
@Override
public void restrict(StringBuilder statement, Map<String, Object> parameters) {
statement.append(",where: (code = :label");
statement.append(" OR displayLabel_cot CONTAINS (:date BETWEEN startDate AND endDate AND " + localize("value") + " = :label)");
statement.append(" OR out('geo_vertex_has_synonym').label CONTAINS :label)");
parameters.put("label", this.label);
parameters.put("date", this.date);
if (this.parent != null && this.hierarchyType != null) {
Set<String> edges = new TreeSet<String>();
edges.add(this.hierarchyType.getMdEdge().getDBClassName());
ServerHierarchyType inheritedHierarchy = type.findHierarchy(this.hierarchyType, this.parent.getType());
if (inheritedHierarchy != null) {
edges.add(inheritedHierarchy.getMdEdge().getDBClassName());
}
statement.append("}.in(");
int i = 0;
for (String edge : edges) {
if (i > 0) {
statement.append(",");
}
statement.append("'" + edge + "'");
i++;
}
statement.append("){where: (uuid=:uuid), while: (true)");
parameters.put("uuid", this.parent.getUid());
}
}
use of net.geoprism.registry.model.ServerHierarchyType in project geoprism-registry by terraframe.
the class LocationService method getLocationInformation.
@Request(RequestType.SESSION)
public LocationInformation getLocationInformation(String sessionId, Date date, String typeCode, String hierarchyCode) {
LocationInformation information = new LocationInformation();
HierarchyService hService = ServiceFactory.getHierarchyService();
HierarchyType[] hierarchies = hService.getHierarchyTypes(sessionId, null, PermissionContext.READ);
ServerHierarchyType hierarchy = null;
if (hierarchyCode == null || hierarchyCode.length() == 0) {
hierarchy = ServerHierarchyType.get(hierarchies[0]);
} else {
hierarchy = ServerHierarchyType.get(hierarchyCode);
}
List<ServerGeoObjectType> nodes = hierarchy.getDirectRootNodes();
if (nodes.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
*/
ServerGeoObjectType type = nodes.get(0);
if (typeCode != null && typeCode.length() > 0) {
for (ServerGeoObjectType node : nodes) {
if (node.getCode().equals(typeCode)) {
type = ServerGeoObjectType.get(typeCode);
}
}
}
if (type != null) {
ServiceFactory.getGeoObjectPermissionService().enforceCanRead(type.getOrganization().getCode(), type);
information.setChildType(type.getType());
List<VertexServerGeoObject> children = this.getGeoObjects(type.getCode(), date);
for (VertexServerGeoObject child : children) {
information.addChild(child.toGeoObject(date));
}
}
}
information.setHierarchies(hierarchies);
information.setHierarchy(hierarchy.getCode());
information.setChildTypes(nodes);
return information;
}
use of net.geoprism.registry.model.ServerHierarchyType in project geoprism-registry by terraframe.
the class ServerParentTreeNodeOverTime method toJSON.
public JsonArray toJSON() {
SimpleDateFormat format = getDateFormat();
final JsonArray response = new JsonArray();
final Set<Entry<String, Hierarchy>> entrySet = this.hierarchies.entrySet();
for (Entry<String, Hierarchy> entry : entrySet) {
final Hierarchy hierarchy = entry.getValue();
final ServerHierarchyType ht = hierarchy.getType();
List<GeoObjectType> parentTypes = this.type.getTypeAncestors(ht, false);
// Populate a "types" array with all ancestors of the GOT they passed us
JsonArray types = new JsonArray();
for (GeoObjectType parent : parentTypes) {
ServerGeoObjectType pType = ServerGeoObjectType.get(parent);
if (!pType.getCode().equals(this.type.getCode())) {
JsonObject pObject = new JsonObject();
pObject.addProperty(JSON_TYPE_CODE, pType.getCode());
pObject.addProperty(JSON_TYPE_LABEL, pType.getLabel().getValue());
types.add(pObject);
}
}
// Populate an "entries" array with all the parents per time period
final JsonArray entries = new JsonArray();
final List<ServerParentTreeNode> nodes = hierarchy.getNodes();
for (ServerParentTreeNode node : nodes) {
JsonObject pArray = new JsonObject();
for (GeoObjectType parent : parentTypes) {
ServerGeoObjectType pType = ServerGeoObjectType.get(parent);
if (!pType.getCode().equals(this.type.getCode())) {
final List<ServerParentTreeNode> ptns = node.findParentOfType(pType.getCode());
if (ptns.size() > 0) {
ServerParentTreeNode sptn = ptns.get(0);
final VertexServerGeoObject sGeoObject = (VertexServerGeoObject) sptn.getGeoObject();
final GeoObject geoObject = sGeoObject.toGeoObject(node.getStartDate());
geoObject.setGeometry(null);
JsonObject pObject = new JsonObject();
pObject.add(JSON_ENTRY_PARENT_GEOOBJECT, geoObject.toJSON());
LocalizedValue label = sGeoObject.getDisplayLabel();
if (label != null) {
pObject.addProperty(JSON_ENTRY_PARENT_TEXT, label.getValue() + " : " + sGeoObject.getCode());
} else {
pObject.addProperty(JSON_ENTRY_PARENT_TEXT, "null" + " : " + sGeoObject.getCode());
}
pArray.add(pType.getCode(), pObject);
}
}
}
JsonObject object = new JsonObject();
object.addProperty(JSON_ENTRY_STARTDATE, format.format(node.getStartDate()));
if (node.getEndDate() != null) {
object.addProperty(JSON_ENTRY_ENDDATE, format.format(node.getEndDate()));
}
object.add(JSON_ENTRY_PARENTS, pArray);
object.addProperty("oid", node.getOid());
entries.add(object);
}
JsonObject object = new JsonObject();
object.addProperty(JSON_HIERARCHY_CODE, ht.getCode());
object.addProperty(JSON_HIERARCHY_LABEL, ht.getDisplayLabel().getValue());
object.add(JSON_HIERARCHY_TYPES, types);
object.add(JSON_HIERARCHY_ENTRIES, entries);
response.add(object);
}
return response;
}
Aggregations