use of net.geoprism.registry.model.ServerHierarchyType in project geoprism-registry by terraframe.
the class VertexServerGeoObject method internalGetParentOverTime.
protected static ServerParentTreeNodeOverTime internalGetParentOverTime(VertexServerGeoObject child, String[] parentTypes, boolean recursive) {
final ServerGeoObjectType cType = child.getType();
final List<ServerHierarchyType> hierarchies = cType.getHierarchies();
ServerParentTreeNodeOverTime response = new ServerParentTreeNodeOverTime(cType);
for (ServerHierarchyType ht : hierarchies) {
response.add(ht);
}
Map<String, Object> parameters = new HashedMap<String, Object>();
parameters.put("rid", child.getVertex().getRID());
StringBuilder statement = new StringBuilder();
statement.append("SELECT EXPAND(inE()");
if (parentTypes != null && parentTypes.length > 0) {
statement.append("[");
for (int i = 0; i < parentTypes.length; i++) {
ServerGeoObjectType type = ServerGeoObjectType.get(parentTypes[i]);
if (i > 0) {
statement.append(" OR ");
}
statement.append("out.@class = :a" + i);
parameters.put("a" + Integer.toString(i), type.getMdVertex().getDBClassName());
}
statement.append("]");
}
statement.append(") FROM :rid");
statement.append(" ORDER BY startDate ASC");
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)) {
ServerHierarchyType ht = ServerHierarchyType.get(mdEdge);
VertexObject parentVertex = edge.getParent();
MdVertexDAOIF mdVertex = (MdVertexDAOIF) parentVertex.getMdClass();
ServerGeoObjectType parentType = ServerGeoObjectType.get(mdVertex);
Date date = edge.getObjectValue(GeoVertex.START_DATE);
Date endDate = edge.getObjectValue(GeoVertex.END_DATE);
String oid = edge.getObjectValue(GeoVertex.OID);
ServerParentTreeNode tnRoot = new ServerParentTreeNode(child, null, date, null, oid);
tnRoot.setEndDate(endDate);
tnRoot.setOid(oid);
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, oid);
}
tnRoot.addParent(tnParent);
response.add(ht, tnRoot);
}
}
return response;
}
use of net.geoprism.registry.model.ServerHierarchyType 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 net.geoprism.registry.model.ServerHierarchyType in project geoprism-registry by terraframe.
the class RegistryService method refreshMetadataCache.
public void refreshMetadataCache() {
ServiceFactory.getMetadataCache().rebuild();
QueryFactory qf = new QueryFactory();
UniversalQuery uq = new UniversalQuery(qf);
OIterator<? extends Universal> it = uq.getIterator();
try {
while (it.hasNext()) {
Universal uni = it.next();
if (uni.getKey().equals(Universal.ROOT_KEY)) {
continue;
}
ServerGeoObjectType type = new ServerGeoObjectTypeConverter().build(uni);
ServiceFactory.getMetadataCache().addGeoObjectType(type);
}
} finally {
it.close();
}
// We must build the hierarchy types which are inherited first
// Otherwise you will end up with a NPE when building the hierarchies
// which inherit the inherited hierarchy if it hasn't been built
HierarchicalRelationshipType.getInheritedTypes().forEach(relationship -> {
ServerHierarchyType ht = new ServerHierarchyTypeBuilder().get(relationship, false);
ServiceFactory.getMetadataCache().addHierarchyType(ht);
});
HierarchicalRelationshipType.getAll().forEach(relationship -> {
ServerHierarchyType ht = new ServerHierarchyTypeBuilder().get(relationship, false);
if (!ServiceFactory.getMetadataCache().getHierachyType(ht.getCode()).isPresent()) {
ServiceFactory.getMetadataCache().addHierarchyType(ht);
}
});
try {
// This is, unfortunately, a big hack. Some patch items need to occur
// before the organizaiton class is defined
MdClassDAO.getMdClassDAO(Organization.CLASS);
OrganizationQuery oQ = new OrganizationQuery(qf);
OIterator<? extends Organization> it3 = oQ.getIterator();
try {
while (it3.hasNext()) {
Organization organization = it3.next();
ServiceFactory.getMetadataCache().addOrganization(organization);
}
} finally {
it3.close();
}
} catch (com.runwaysdk.dataaccess.cache.DataNotFoundException e) {
// skip for now
}
}
use of net.geoprism.registry.model.ServerHierarchyType in project geoprism-registry by terraframe.
the class RegistryService method getAncestors.
@Request(RequestType.SESSION)
public List<GeoObjectType> getAncestors(String sessionId, String code, String hierarchyCode, Boolean includeInheritedTypes, Boolean includeChild) {
ServerGeoObjectType child = ServerGeoObjectType.get(code);
ServerHierarchyType hierarchyType = ServerHierarchyType.get(hierarchyCode);
List<GeoObjectType> ancestors = child.getTypeAncestors(hierarchyType, includeInheritedTypes);
if (includeChild) {
ancestors.add(child.getType());
}
return ancestors;
}
use of net.geoprism.registry.model.ServerHierarchyType in project geoprism-registry by terraframe.
the class SynchronizationConfigService method edit.
@Request(RequestType.SESSION)
public JsonObject edit(String sessionId, String oid) {
JsonObject response = new JsonObject();
if (oid != null && oid.length() > 0) {
SynchronizationConfig config = SynchronizationConfig.lock(oid);
response.add("config", config.toJSON());
}
JsonArray orgs = new JsonArray();
List<Organization> organizations = Organization.getUserAdminOrganizations();
for (Organization organization : organizations) {
JsonArray hierarchies = new JsonArray();
List<ServerHierarchyType> sHierachies = ServerHierarchyType.getForOrganization(organization);
for (ServerHierarchyType hierarchy : sHierachies) {
JsonObject object = new JsonObject();
object.addProperty("label", hierarchy.getDisplayLabel().getValue());
object.addProperty("code", hierarchy.getCode());
hierarchies.add(object);
}
JsonArray systems = new JsonArray();
List<ExternalSystem> esystems = ExternalSystem.getForOrganization(organization);
for (ExternalSystem system : esystems) {
if (system.isExportSupported()) {
LocalizedValue label = LocalizedValueConverter.convert(system.getEmbeddedComponent(ExternalSystem.LABEL));
JsonObject object = new JsonObject();
object.addProperty("label", label.getValue());
object.addProperty("oid", system.getOid());
object.addProperty("type", system.getMdClass().getTypeName());
systems.add(object);
}
}
JsonObject object = new JsonObject();
object.addProperty("label", organization.getDisplayLabel().getValue());
object.addProperty("code", organization.getCode());
object.add("hierarchies", hierarchies);
object.add("systems", systems);
orgs.add(object);
}
response.add("orgs", orgs);
return response;
}
Aggregations