use of net.geoprism.registry.model.graph.VertexServerGeoObject 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 net.geoprism.registry.model.graph.VertexServerGeoObject 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;
}
use of net.geoprism.registry.model.graph.VertexServerGeoObject in project geoprism-registry by terraframe.
the class ChangeRequestServiceTest method testUpdateGeoObjectLocalizedValueCR_applyCR.
@Request
private String[] testUpdateGeoObjectLocalizedValueCR_applyCR() throws Exception {
ChangeRequest cr = new ChangeRequest();
cr.addApprovalStatus(AllGovernanceStatus.PENDING);
cr.setOrganizationCode(FastTestDataset.ORG_CGOV.getCode());
cr.setGeoObjectCode(FastTestDataset.CAMBODIA.getCode());
cr.setGeoObjectTypeCode(FastTestDataset.CAMBODIA.getGeoObjectType().getCode());
cr.apply();
UpdateAttributeAction action = new UpdateAttributeAction();
action.setApiVersion("1.0");
((UpdateAttributeActionBase) action).setAttributeName(DefaultAttribute.DISPLAY_LABEL.getName());
JsonObject diff = new JsonObject();
VertexServerGeoObject cambodia = (VertexServerGeoObject) FastTestDataset.CAMBODIA.getServerObject();
ValueOverTime vot = cambodia.getValuesOverTime(DefaultAttribute.DISPLAY_LABEL.getName()).getValueOverTime(FastTestDataset.DEFAULT_OVER_TIME_DATE, TestDataSet.DEFAULT_END_TIME_DATE);
JsonArray valuesOverTime = JsonParser.parseString("[" + "{" + " \"oid\": \"" + vot.getOid() + "\"," + " \"action\": \"UPDATE\"," + " \"oldEndDate\": \"" + OLD_END_DATE + "\"," + " \"oldStartDate\": \"" + OLD_START_DATE + "\"," + " \"oldValue\": \"\"," + " \"newValue\": \"\"," + " \"newStartDate\": \"" + NEW_START_DATE + "\"," + " \"newEndDate\": \"" + NEW_END_DATE + "\"" + "}" + "]").getAsJsonArray();
valuesOverTime.get(0).getAsJsonObject().add("oldValue", cambodia.getDisplayLabel(FastTestDataset.DEFAULT_OVER_TIME_DATE).toJSON());
LocalizedValue newValue = new LocalizedValue("localizeTest");
valuesOverTime.get(0).getAsJsonObject().add("newValue", newValue.toJSON());
diff.add("valuesOverTime", valuesOverTime);
((UpdateAttributeActionBase) action).setJson(diff.toString());
action.addApprovalStatus(AllGovernanceStatus.ACCEPTED);
action.setCreateActionDate(new Date());
action.apply();
cr.addAction(action).apply();
String serializedCR = cr.toJSON().toString();
return new String[] { serializedCR, vot.getOid() };
}
use of net.geoprism.registry.model.graph.VertexServerGeoObject in project geoprism-registry by terraframe.
the class ChangeRequestServiceTest method testUpdateGeoObjectTermCR_applyCR.
@Request
private String[] testUpdateGeoObjectTermCR_applyCR() throws Exception {
final String attrName = FastTestDataset.AT_RELIGION.getAttributeName();
ChangeRequest cr = new ChangeRequest();
cr.addApprovalStatus(AllGovernanceStatus.PENDING);
cr.setOrganizationCode(FastTestDataset.ORG_CGOV.getCode());
cr.setGeoObjectCode(FastTestDataset.CAMBODIA.getCode());
cr.setGeoObjectTypeCode(FastTestDataset.CAMBODIA.getGeoObjectType().getCode());
cr.apply();
UpdateAttributeAction action = new UpdateAttributeAction();
action.setApiVersion("1.0");
((UpdateAttributeActionBase) action).setAttributeName(attrName);
JsonObject diff = new JsonObject();
VertexServerGeoObject cambodia = (VertexServerGeoObject) FastTestDataset.CAMBODIA.getServerObject();
ValueOverTime vot = cambodia.getValuesOverTime(attrName).getValueOverTime(FastTestDataset.DEFAULT_OVER_TIME_DATE, TestDataSet.DEFAULT_END_TIME_DATE);
JsonArray valuesOverTime = JsonParser.parseString("[" + "{" + " \"oid\": \"" + vot.getOid() + "\"," + " \"action\": \"UPDATE\"," + " \"oldEndDate\": \"" + OLD_END_DATE + "\"," + " \"oldStartDate\": \"" + OLD_START_DATE + "\"," + " \"oldValue\": [\"" + ((Term) FastTestDataset.CAMBODIA.getDefaultValue(attrName)).getCode() + "\"]," + " \"newValue\": [\"" + FastTestDataset.T_Islam.getCode() + "\"]," + " \"newStartDate\": \"" + NEW_START_DATE + "\"," + " \"newEndDate\": \"" + NEW_END_DATE + "\"" + "}" + "]").getAsJsonArray();
diff.add("valuesOverTime", valuesOverTime);
((UpdateAttributeActionBase) action).setJson(diff.toString());
action.addApprovalStatus(AllGovernanceStatus.ACCEPTED);
action.setCreateActionDate(new Date());
action.apply();
cr.addAction(action).apply();
String serializedCR = cr.toJSON().toString();
return new String[] { serializedCR, vot.getOid() };
}
use of net.geoprism.registry.model.graph.VertexServerGeoObject in project geoprism-registry by terraframe.
the class ChangeRequestServiceTest method testUpdateGeoObjectDateCR_Verify.
@Request
private void testUpdateGeoObjectDateCR_Verify(Object[] data) throws Exception {
final String attrName = FastTestDataset.AT_DATE_OF_FORMATION.getAttributeName();
final String oldOid = (String) data[1];
final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
sdf.setTimeZone(GeoRegistryUtil.SYSTEM_TIMEZONE);
final Date newStartDate = sdf.parse(NEW_START_DATE);
final Date newEndDate = sdf.parse(NEW_END_DATE);
ChangeRequestQuery crq = new ChangeRequestQuery(new QueryFactory());
Assert.assertEquals(1, crq.getCount());
ChangeRequest cr = crq.getIterator().next();
Assert.assertEquals(AllGovernanceStatus.ACCEPTED.name(), cr.getGovernanceStatus().name());
AbstractAction action = cr.getAllAction().next();
Assert.assertTrue(action instanceof UpdateAttributeAction);
Assert.assertEquals(FastTestDataset.CAMBODIA.getCode(), cr.getGeoObjectCode());
Assert.assertEquals(FastTestDataset.CAMBODIA.getGeoObjectType().getCode(), cr.getGeoObjectTypeCode());
Assert.assertEquals(FastTestDataset.ORG_CGOV.getCode(), cr.getOrganizationCode());
VertexServerGeoObject cambodia = (VertexServerGeoObject) FastTestDataset.CAMBODIA.getServerObject();
ValueOverTimeCollection votc = cambodia.getValuesOverTime(attrName);
Assert.assertEquals(1, votc.size());
ValueOverTime vot1 = votc.get(0);
Assert.assertNotNull(vot1.getOid());
Assert.assertEquals(oldOid, vot1.getOid());
Assert.assertEquals(newStartDate, vot1.getStartDate());
Assert.assertEquals(newEndDate, vot1.getEndDate());
Calendar expected = Calendar.getInstance();
expected.setTime(new Date((Long) data[2]));
// It's surprising how imprecise Runway's dates are...
expected.set(Calendar.SECOND, 0);
expected.set(Calendar.MILLISECOND, 0);
Calendar actual = Calendar.getInstance();
actual.setTime((Date) cambodia.getValue(attrName));
actual.set(Calendar.SECOND, 0);
actual.set(Calendar.MILLISECOND, 0);
Assert.assertEquals(expected.getTime(), actual.getTime());
}
Aggregations