Search in sources :

Example 11 with ServerParentTreeNode

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;
}
Also used : ServerHierarchyType(net.geoprism.registry.model.ServerHierarchyType) ServerParentTreeNode(net.geoprism.registry.model.ServerParentTreeNode) ServerGeoObjectType(net.geoprism.registry.model.ServerGeoObjectType) JsonObject(com.google.gson.JsonObject) JsonArray(com.google.gson.JsonArray) Entry(java.util.Map.Entry) LocalizedValue(org.commongeoregistry.adapter.dataaccess.LocalizedValue) ServerGeoObjectType(net.geoprism.registry.model.ServerGeoObjectType) GeoObjectType(org.commongeoregistry.adapter.metadata.GeoObjectType) VertexServerGeoObject(net.geoprism.registry.model.graph.VertexServerGeoObject) GeoObject(org.commongeoregistry.adapter.dataaccess.GeoObject) VertexServerGeoObject(net.geoprism.registry.model.graph.VertexServerGeoObject) SimpleDateFormat(java.text.SimpleDateFormat)

Example 12 with ServerParentTreeNode

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);
            }
        }
    }
}
Also used : ServerHierarchyType(net.geoprism.registry.model.ServerHierarchyType) ServerParentTreeNode(net.geoprism.registry.model.ServerParentTreeNode) ServerGeoObjectIF(net.geoprism.registry.model.ServerGeoObjectIF) ServerGeoObjectType(net.geoprism.registry.model.ServerGeoObjectType)

Example 13 with ServerParentTreeNode

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());
}
Also used : VertexGeoObjectStrategy(net.geoprism.registry.conversion.VertexGeoObjectStrategy) ServerGeoObjectIF(net.geoprism.registry.model.ServerGeoObjectIF) ServerParentTreeNode(net.geoprism.registry.model.ServerParentTreeNode) Test(org.junit.Test) Request(com.runwaysdk.session.Request)

Example 14 with ServerParentTreeNode

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 + "\"" + "}" + "]" + "}";
}
Also used : ServerGeoObjectIF(net.geoprism.registry.model.ServerGeoObjectIF) ServerParentTreeNode(net.geoprism.registry.model.ServerParentTreeNode) Request(com.runwaysdk.session.Request) ChangeRequest(net.geoprism.registry.action.ChangeRequest)

Example 15 with ServerParentTreeNode

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;
}
Also used : ServerParentTreeNode(net.geoprism.registry.model.ServerParentTreeNode) ServerParentTreeNodeOverTime(net.geoprism.registry.view.ServerParentTreeNodeOverTime) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) Request(com.runwaysdk.session.Request) ChangeRequest(net.geoprism.registry.action.ChangeRequest)

Aggregations

ServerParentTreeNode (net.geoprism.registry.model.ServerParentTreeNode)16 ServerGeoObjectIF (net.geoprism.registry.model.ServerGeoObjectIF)9 ServerHierarchyType (net.geoprism.registry.model.ServerHierarchyType)9 ServerGeoObjectType (net.geoprism.registry.model.ServerGeoObjectType)7 EdgeObject (com.runwaysdk.business.graph.EdgeObject)5 Request (com.runwaysdk.session.Request)5 Entry (java.util.Map.Entry)4 JsonObject (com.google.gson.JsonObject)3 VertexObject (com.runwaysdk.business.graph.VertexObject)3 MdVertexDAOIF (com.runwaysdk.dataaccess.MdVertexDAOIF)3 LineString (com.vividsolutions.jts.geom.LineString)3 MultiLineString (com.vividsolutions.jts.geom.MultiLineString)3 MultiPoint (com.vividsolutions.jts.geom.MultiPoint)3 Point (com.vividsolutions.jts.geom.Point)3 Date (java.util.Date)3 VertexServerGeoObject (net.geoprism.registry.model.graph.VertexServerGeoObject)3 LocalizedValue (org.commongeoregistry.adapter.dataaccess.LocalizedValue)3 GraphObject (com.runwaysdk.business.graph.GraphObject)2 GraphQuery (com.runwaysdk.business.graph.GraphQuery)2 MdEdgeDAOIF (com.runwaysdk.dataaccess.MdEdgeDAOIF)2