use of com.runwaysdk.business.graph.VertexObject in project geoprism-registry by terraframe.
the class VertexSelectGeoObjectQuery method getResults.
public List<VertexServerGeoObject> getResults() {
List<VertexServerGeoObject> list = new LinkedList<VertexServerGeoObject>();
GraphQuery<VertexObject> query = this.getQuery();
List<VertexObject> results = query.getResults();
for (VertexObject result : results) {
list.add(new VertexServerGeoObject(type, result, this.date));
}
return list;
}
use of com.runwaysdk.business.graph.VertexObject 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.VertexObject 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;
}
use of com.runwaysdk.business.graph.VertexObject in project geoprism-registry by terraframe.
the class SearchService method remove.
// @Transaction
public void remove(String code) {
// String suffix = this.getSuffix();
//
// MdVertexDAOIF mdVertex = MdVertexDAO.getMdVertexDAO(PACKAGE + "." +
// VERTEX_PREFIX + suffix);
// MdAttributeDAOIF mdCode = mdVertex.definesAttribute(CODE);
//
// StringBuilder statement = new StringBuilder();
// statement.append("DELETE VERTEX " + mdVertex.getDBClassName());
// statement.append(" WHERE " + mdCode.getColumnName() + " = :code");
//
// Map<String, Object> parameters = new HashMap<String, Object>();
// parameters.put("code", code);
//
// GraphDBService service = GraphDBService.getInstance();
// GraphRequest request = service.getGraphDBRequest();
//
// service.command(request, statement.toString(), parameters);
String suffix = this.getSuffix();
MdVertexDAOIF mdVertex = MdVertexDAO.getMdVertexDAO(PACKAGE + "." + VERTEX_PREFIX + suffix);
MdAttributeDAOIF mdCode = mdVertex.definesAttribute(CODE);
StringBuilder statement = new StringBuilder();
statement.append("SELECT FROM " + mdVertex.getDBClassName());
statement.append(" WHERE :code = " + mdCode.getColumnName());
GraphQuery<VertexObject> query = new GraphQuery<VertexObject>(statement.toString());
query.setParameter("code", code);
List<VertexObject> results = query.getResults();
for (VertexObject result : results) {
result.delete();
}
}
use of com.runwaysdk.business.graph.VertexObject in project geoprism-registry by terraframe.
the class SearchService method insert.
// @Transaction
public void insert(VertexServerGeoObject object) {
this.remove(object.getCode());
String suffix = this.getSuffix();
MdVertexDAOIF mdVertex = MdVertexDAO.getMdVertexDAO(PACKAGE + "." + VERTEX_PREFIX + suffix);
MdEdgeDAOIF mdEdge = MdEdgeDAO.getMdEdgeDAO(PACKAGE + "." + EDGE_PREFIX + suffix);
ValueOverTimeCollection vots = object.getValuesOverTime(DefaultAttribute.DISPLAY_LABEL.getName());
for (ValueOverTime vot : vots) {
VertexObjectDAOIF value = (VertexObjectDAOIF) vot.getValue();
Set<String> attributeNames = LocalizationService.getLocaleNames();
for (String attributeName : attributeNames) {
String label = value.getObjectValue(attributeName);
if (label != null && label.length() > 0) {
VertexObject vertex = new VertexObject(mdVertex.definesType());
vertex.setValue(START_DATE, vot.getStartDate());
vertex.setValue(END_DATE, vot.getEndDate());
vertex.setValue(CODE, object.getCode());
vertex.setValue(LABEL, label);
vertex.setValue(VERTEX_TYPE, object.getType().getCode());
vertex.apply();
vertex.addChild(object.getVertex(), mdEdge).apply();
}
}
}
}
Aggregations