use of net.geoprism.registry.model.ServerParentTreeNode 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.ServerParentTreeNode in project geoprism-registry by terraframe.
the class ServerParentTreeNodeOverTime method enforceUserHasPermissionSetParents.
public void enforceUserHasPermissionSetParents(String childCode, boolean asCR) {
final Collection<ServerHierarchyType> hierarchyTypes = this.getHierarchies();
ServerGeoObjectType childType = ServerGeoObjectType.get(childCode);
for (ServerHierarchyType hierarchyType : hierarchyTypes) {
final List<ServerParentTreeNode> entries = this.getEntries(hierarchyType);
for (ServerParentTreeNode entry : entries) {
final ServerGeoObjectIF parent = entry.getGeoObject();
if (asCR) {
ServiceFactory.getGeoObjectRelationshipPermissionService().enforceCanAddChildCR(hierarchyType.getOrganization().getCode(), parent.getType(), childType);
} else {
ServiceFactory.getGeoObjectRelationshipPermissionService().enforceCanAddChild(hierarchyType.getOrganization().getCode(), parent.getType(), childType);
}
}
}
}
use of net.geoprism.registry.model.ServerParentTreeNode in project geoprism-registry by terraframe.
the class HierarchyChangeTest method testRemoveFromHierarchyWithData.
@Test
@Request
public void testRemoveFromHierarchyWithData() {
String sessionId = testData.clientSession.getSessionId();
String hierarchyCode = USATestData.HIER_ADMIN.getCode();
String countryTypeCode = USATestData.COUNTRY.getCode();
String stateTypeCode = USATestData.STATE.getCode();
String cd1TypeCode = USATestData.CO_D_ONE.getCode();
ServerGeoObjectIF geoobject = new VertexGeoObjectStrategy(USATestData.DISTRICT.getServerObject()).getGeoObjectByCode(cd1TypeCode);
ServerParentTreeNode parents = geoobject.getParentGeoObjects(null, false, TestDataSet.DEFAULT_OVER_TIME_DATE);
Assert.assertEquals(1, parents.getParents().size());
ServiceFactory.getHierarchyService().removeFromHierarchy(sessionId, hierarchyCode, countryTypeCode, stateTypeCode, true);
ServerGeoObjectIF test = new VertexGeoObjectStrategy(USATestData.DISTRICT.getServerObject()).getGeoObjectByCode(cd1TypeCode);
ServerParentTreeNode tParents = test.getParentGeoObjects(null, false, TestDataSet.DEFAULT_OVER_TIME_DATE);
Assert.assertEquals(0, tParents.getParents().size());
}
use of net.geoprism.registry.model.ServerParentTreeNode in project geoprism-registry by terraframe.
the class ChangeRequestServiceTest method setUpTestInstanceData.
@Request
private void setUpTestInstanceData() {
ServerGeoObjectIF cambodia = FastTestDataset.CAMBODIA.getServerObject();
String votOid = cambodia.getValuesOverTime(FastTestDataset.AT_National_Anthem.getAttributeName()).getValueOverTime(FastTestDataset.DEFAULT_OVER_TIME_DATE, TestDataSet.DEFAULT_END_TIME_DATE).getOid();
UPDATE_ATTR_JSON = "{" + "\"valuesOverTime\" : [" + "{" + "\"oid\" : \"" + votOid + "\"," + "\"action\" : \"UPDATE\"," + "\"oldValue\" : \"" + FastTestDataset.CAMBODIA.getDefaultValue(FastTestDataset.AT_National_Anthem.getAttributeName()) + "\"," + "\"newValue\" : \"" + NEW_ANTHEM + "\"," + "\"newStartDate\" : \"" + NEW_START_DATE + "\"," + "\"newEndDate\" : \"" + NEW_END_DATE + "\"," + "\"oldStartDate\" : \"" + OLD_START_DATE + "\"," + "\"oldEndDate\" : \"" + OLD_END_DATE + "\"" + "}" + "]" + "}";
ServerGeoObjectIF central_prov = FastTestDataset.PROV_CENTRAL.getServerObject();
ServerParentTreeNode ptn = central_prov.getParentGeoObjects(new String[] { FastTestDataset.COUNTRY.getCode() }, false, TestDataSet.DEFAULT_OVER_TIME_DATE).getParents().get(0);
UPDATE_PARENT_ATTR_JSON = "{" + "\"hierarchyCode\" : \"" + FastTestDataset.HIER_ADMIN.getCode() + "\"," + "\"valuesOverTime\" : [" + "{" + "\"oid\" : \"" + ptn.getOid() + "\"," + "\"action\" : \"UPDATE\"," + "\"oldValue\" : \"" + FastTestDataset.COUNTRY.getCode() + UpdateParentValueOverTimeView.VALUE_SPLIT_TOKEN + FastTestDataset.CAMBODIA.getCode() + "\"," + "\"newValue\" : \"" + FastTestDataset.COUNTRY.getCode() + UpdateParentValueOverTimeView.VALUE_SPLIT_TOKEN + BELIZE.getCode() + "\"," + "\"newStartDate\" : \"" + NEW_START_DATE + "\"," + "\"newEndDate\" : \"" + NEW_END_DATE + "\"," + "\"oldStartDate\" : \"" + OLD_START_DATE + "\"," + "\"oldEndDate\" : \"" + OLD_END_DATE + "\"" + "}" + "]" + "}";
}
use of net.geoprism.registry.model.ServerParentTreeNode in project geoprism-registry by terraframe.
the class ChangeRequestServiceTest method testCreateGeoObjectCR_Json.
@Request
private String[] testCreateGeoObjectCR_Json() throws Exception {
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);
String[] ret = new String[2];
ServerParentTreeNodeOverTime ptnot = new ServerParentTreeNodeOverTime(FastTestDataset.PROVINCE.getServerObject());
ServerParentTreeNode childNode = new ServerParentTreeNode(null, FastTestDataset.HIER_ADMIN.getServerObject(), newStartDate, newEndDate, null);
childNode.addParent(new ServerParentTreeNode(FastTestDataset.CAMBODIA.getServerObject(), FastTestDataset.HIER_ADMIN.getServerObject(), newStartDate, newEndDate, null));
ptnot.add(FastTestDataset.HIER_ADMIN.getServerObject(), childNode);
ret[0] = ptnot.toJSON().toString();
ret[1] = TEST_NEW_PROVINCE.newGeoObjectOverTime(ServiceFactory.getAdapter()).toJSON().toString();
return ret;
}
Aggregations