Search in sources :

Example 1 with ParentTreeNode

use of org.commongeoregistry.adapter.dataaccess.ParentTreeNode in project geoprism-registry by terraframe.

the class GeoObjectEditorControllerNoOverTime method applyInTransaction.

@Transaction
private GeoObject applyInTransaction(String sessionId, String sPtn, String sGo, Boolean isNew, String masterListId) {
    final Date startDate = new Date();
    final Date endDate = ValueOverTime.INFINITY_END_DATE;
    GeoObject go;
    Map<String, String> roles = Session.getCurrentSession().getUserRoles();
    if (roles.keySet().contains(RegistryConstants.REGISTRY_CONTRIBUTOR_ROLE)) {
        Instant base = Instant.now();
        int sequence = 0;
        ChangeRequest request = new ChangeRequest();
        request.addApprovalStatus(AllGovernanceStatus.PENDING);
        request.apply();
        if (!isNew) {
            UpdateGeoObjectAction action = new UpdateGeoObjectAction();
            action.addApprovalStatus(AllGovernanceStatus.PENDING);
            action.setCreateActionDate(Date.from(base.plus(sequence++, ChronoUnit.MINUTES)));
            action.setGeoObjectJson(sGo);
            action.setApiVersion(CGRAdapterProperties.getApiVersion());
            action.apply();
            request.addAction(action).apply();
        } else {
            CreateGeoObjectAction action = new CreateGeoObjectAction();
            action.addApprovalStatus(AllGovernanceStatus.PENDING);
            action.setCreateActionDate(Date.from(base.plus(sequence++, ChronoUnit.MINUTES)));
            action.setGeoObjectJson(sGo);
            action.setApiVersion(CGRAdapterProperties.getApiVersion());
            action.apply();
            request.addAction(action).apply();
        }
        ParentTreeNode ptn = ParentTreeNode.fromJSON(sPtn.toString(), ServiceFactory.getAdapter());
        applyChangeRequest(sessionId, request, ptn, isNew, base, sequence, startDate, endDate);
    } else {
        if (!isNew) {
            go = RegistryService.getInstance().updateGeoObject(sessionId, sGo.toString(), startDate, endDate);
        } else {
            go = RegistryService.getInstance().createGeoObject(sessionId, sGo.toString(), startDate, endDate);
        }
        ParentTreeNode ptn = ParentTreeNode.fromJSON(sPtn.toString(), ServiceFactory.getAdapter());
        applyPtn(sessionId, ptn, startDate, endDate);
        // Update the master list record
        if (masterListId != null) {
            ServerGeoObjectService service = new ServerGeoObjectService();
            ServerGeoObjectIF geoObject = service.getGeoObject(go);
            if (!isNew) {
                ListTypeVersion.get(masterListId).updateRecord(geoObject);
            } else {
                ListTypeVersion.get(masterListId).publishRecord(geoObject);
            }
        }
        return go;
    }
    return null;
}
Also used : CreateGeoObjectAction(net.geoprism.registry.action.geoobject.CreateGeoObjectAction) ServerGeoObjectService(net.geoprism.registry.geoobject.ServerGeoObjectService) UpdateGeoObjectAction(net.geoprism.registry.action.geoobject.UpdateGeoObjectAction) ServerGeoObjectIF(net.geoprism.registry.model.ServerGeoObjectIF) Instant(java.time.Instant) ParentTreeNode(org.commongeoregistry.adapter.dataaccess.ParentTreeNode) GeoObject(org.commongeoregistry.adapter.dataaccess.GeoObject) ChangeRequest(net.geoprism.registry.action.ChangeRequest) Date(java.util.Date) Endpoint(com.runwaysdk.mvc.Endpoint) Transaction(com.runwaysdk.dataaccess.transaction.Transaction)

Example 2 with ParentTreeNode

use of org.commongeoregistry.adapter.dataaccess.ParentTreeNode in project geoprism-registry by terraframe.

the class GeoObjectEditorControllerNoOverTime method applyChangeRequest.

public void applyChangeRequest(String sessionId, ChangeRequest request, ParentTreeNode ptn, boolean isNew, Instant base, int sequence, Date startDate, Date endDate) {
    GeoObject child = ptn.getGeoObject();
    List<ParentTreeNode> childDbParents = new LinkedList<ParentTreeNode>();
    if (!isNew) {
        childDbParents = RegistryService.getInstance().getParentGeoObjects(sessionId, child.getUid(), child.getType().getCode(), null, false, startDate).getParents();
        // create
        for (ParentTreeNode ptnDbParent : childDbParents) {
            boolean shouldRemove = true;
            for (ParentTreeNode ptnParent : ptn.getParents()) {
                if (ptnParent.getGeoObject().equals(ptnDbParent.getGeoObject()) && ptnParent.getHierachyType().getCode().equals(ptnDbParent.getHierachyType().getCode())) {
                    shouldRemove = false;
                }
            }
            if (shouldRemove) {
                GeoObject parent = ptnDbParent.getGeoObject();
                RemoveChildAction action = new RemoveChildAction();
                action.addApprovalStatus(AllGovernanceStatus.PENDING);
                action.setChildId(child.getUid());
                action.setChildTypeCode(child.getType().getCode());
                action.setParentId(parent.getUid());
                action.setParentTypeCode(parent.getType().getCode());
                action.setHierarchyTypeCode(ptnDbParent.getHierachyType().getCode());
                action.setCreateActionDate(Date.from(base.plus(sequence++, ChronoUnit.MINUTES)));
                action.setApiVersion(CGRAdapterProperties.getApiVersion());
                action.apply();
                request.addAction(action).apply();
            }
        }
    }
    // Create new relationships that don't already exist
    for (ParentTreeNode ptnParent : ptn.getParents()) {
        boolean alreadyExists = false;
        if (!isNew) {
            for (ParentTreeNode ptnDbParent : childDbParents) {
                if (ptnParent.getGeoObject().equals(ptnDbParent.getGeoObject()) && ptnParent.getHierachyType().getCode().equals(ptnDbParent.getHierachyType().getCode())) {
                    alreadyExists = true;
                }
            }
        }
        if (!alreadyExists) {
            GeoObject parent = ptnParent.getGeoObject();
            AddChildAction action = new AddChildAction();
            action.addApprovalStatus(AllGovernanceStatus.PENDING);
            action.setChildId(child.getUid());
            action.setChildTypeCode(child.getType().getCode());
            action.setParentId(parent.getUid());
            action.setParentTypeCode(parent.getType().getCode());
            action.setHierarchyTypeCode(ptnParent.getHierachyType().getCode());
            action.setCreateActionDate(Date.from(base.plus(sequence++, ChronoUnit.MINUTES)));
            action.setApiVersion(CGRAdapterProperties.getApiVersion());
            action.apply();
            request.addAction(action).apply();
        }
    }
}
Also used : RemoveChildAction(net.geoprism.registry.action.tree.RemoveChildAction) ParentTreeNode(org.commongeoregistry.adapter.dataaccess.ParentTreeNode) AddChildAction(net.geoprism.registry.action.tree.AddChildAction) GeoObject(org.commongeoregistry.adapter.dataaccess.GeoObject) LinkedList(java.util.LinkedList)

Example 3 with ParentTreeNode

use of org.commongeoregistry.adapter.dataaccess.ParentTreeNode in project geoprism-registry by terraframe.

the class ServerParentTreeNode method toNode.

public ParentTreeNode toNode(boolean enforcePermissions) {
    GeoObject geoObject = this.getGeoObject().toGeoObject(this.getStartDate());
    HierarchyType ht = this.getHierarchyType() != null ? this.getHierarchyType().toHierarchyType() : null;
    ParentTreeNode node = new ParentTreeNode(geoObject, ht);
    String orgCode = geoObject.getType().getOrganizationCode();
    ServerGeoObjectType type = ServerGeoObjectType.get(geoObject.getType());
    for (ServerParentTreeNode parent : this.parents) {
        if (!enforcePermissions || ServiceFactory.getGeoObjectRelationshipPermissionService().canViewChild(orgCode, parent.getGeoObject().getType(), type)) {
            node.addParent(parent.toNode(enforcePermissions));
        }
    }
    return node;
}
Also used : HierarchyType(org.commongeoregistry.adapter.metadata.HierarchyType) ParentTreeNode(org.commongeoregistry.adapter.dataaccess.ParentTreeNode) GeoObject(org.commongeoregistry.adapter.dataaccess.GeoObject)

Example 4 with ParentTreeNode

use of org.commongeoregistry.adapter.dataaccess.ParentTreeNode in project geoprism-registry by terraframe.

the class GeoObjectRelationshipServiceTest method testGetPrivateParentGeoObjects.

@Test
public void testGetPrivateParentGeoObjects() {
    final String childCode = FastTestDataset.PROV_CENTRAL_PRIVATE.getCode();
    final String childTypeCode = FastTestDataset.PROV_CENTRAL_PRIVATE.getGeoObjectType().getCode();
    final String[] parentTypes = new String[] { FastTestDataset.COUNTRY.getCode() };
    final List<TestGeoObjectInfo> expectedParents = new ArrayList<TestGeoObjectInfo>();
    expectedParents.add(FastTestDataset.CAMBODIA);
    TestUserInfo[] allowedUsers = new TestUserInfo[] { FastTestDataset.USER_CGOV_RA, FastTestDataset.USER_CGOV_RM_PRIVATE, FastTestDataset.USER_CGOV_RC_PRIVATE, FastTestDataset.USER_CGOV_AC_PRIVATE };
    for (TestUserInfo user : allowedUsers) {
        FastTestDataset.runAsUser(user, (request, adapter) -> {
            ParentTreeNode tn = adapter.getParentGeoObjects(childCode, childTypeCode, TestDataSet.DEFAULT_OVER_TIME_DATE, parentTypes, true);
            FastTestDataset.PROV_CENTRAL_PRIVATE.parentTreeNodeAssert(tn, expectedParents);
            Assert.assertEquals(tn.toJSON().toString(), ParentTreeNode.fromJSON(tn.toJSON().toString(), testData.adapter).toJSON().toString());
        });
    }
    TestUserInfo[] disallowedUsers = new TestUserInfo[] { FastTestDataset.USER_MOHA_RA, FastTestDataset.USER_MOHA_RM, FastTestDataset.USER_MOHA_RC, FastTestDataset.USER_MOHA_AC, FastTestDataset.USER_CGOV_RM, FastTestDataset.USER_CGOV_RC, FastTestDataset.USER_CGOV_AC };
    for (TestUserInfo user : disallowedUsers) {
        FastTestDataset.runAsUser(user, (request, adapter) -> {
            try {
                adapter.getParentGeoObjects(childCode, childTypeCode, TestDataSet.DEFAULT_OVER_TIME_DATE, parentTypes, true);
                Assert.fail("Expected a permissions error.");
            } catch (SmartExceptionDTO e) {
                Assert.assertEquals(ReadGeoObjectPermissionException.CLASS, e.getType());
            }
        });
    }
}
Also used : TestUserInfo(net.geoprism.registry.test.TestUserInfo) ArrayList(java.util.ArrayList) ParentTreeNode(org.commongeoregistry.adapter.dataaccess.ParentTreeNode) SmartExceptionDTO(com.runwaysdk.business.SmartExceptionDTO) TestGeoObjectInfo(net.geoprism.registry.test.TestGeoObjectInfo) Test(org.junit.Test)

Example 5 with ParentTreeNode

use of org.commongeoregistry.adapter.dataaccess.ParentTreeNode in project geoprism-registry by terraframe.

the class GeoObjectEditorControllerNoOverTime method applyPtn.

public void applyPtn(String sessionId, ParentTreeNode ptn, Date startDate, Date endDate) {
    GeoObject child = ptn.getGeoObject();
    List<ParentTreeNode> childDbParents = RegistryService.getInstance().getParentGeoObjects(sessionId, child.getUid(), child.getType().getCode(), null, false, startDate).getParents();
    // create
    for (ParentTreeNode ptnDbParent : childDbParents) {
        boolean shouldRemove = true;
        for (ParentTreeNode ptnParent : ptn.getParents()) {
            if (ptnParent.getGeoObject().equals(ptnDbParent.getGeoObject()) && ptnParent.getHierachyType().getCode().equals(ptnDbParent.getHierachyType().getCode())) {
                shouldRemove = false;
            }
        }
        if (shouldRemove) {
            ServiceFactory.getGeoObjectService().removeChild(sessionId, ptnDbParent.getGeoObject().getUid(), ptnDbParent.getGeoObject().getType().getCode(), child.getUid(), child.getType().getCode(), ptnDbParent.getHierachyType().getCode(), startDate, endDate);
        }
    }
    // Create new relationships that don't already exist
    for (ParentTreeNode ptnParent : ptn.getParents()) {
        boolean alreadyExists = false;
        for (ParentTreeNode ptnDbParent : childDbParents) {
            if (ptnParent.getGeoObject().equals(ptnDbParent.getGeoObject()) && ptnParent.getHierachyType().getCode().equals(ptnDbParent.getHierachyType().getCode())) {
                alreadyExists = true;
            }
        }
        if (!alreadyExists) {
            GeoObject parent = ptnParent.getGeoObject();
            ServiceFactory.getGeoObjectService().addChild(sessionId, parent.getUid(), parent.getType().getCode(), child.getUid(), child.getType().getCode(), ptnParent.getHierachyType().getCode(), startDate, endDate);
        }
    }
}
Also used : ParentTreeNode(org.commongeoregistry.adapter.dataaccess.ParentTreeNode) GeoObject(org.commongeoregistry.adapter.dataaccess.GeoObject)

Aggregations

ParentTreeNode (org.commongeoregistry.adapter.dataaccess.ParentTreeNode)11 GeoObject (org.commongeoregistry.adapter.dataaccess.GeoObject)5 Test (org.junit.Test)5 TestGeoObjectInfo (net.geoprism.registry.test.TestGeoObjectInfo)4 Endpoint (com.runwaysdk.mvc.Endpoint)2 ArrayList (java.util.ArrayList)2 Date (java.util.Date)2 ServerGeoObjectService (net.geoprism.registry.geoobject.ServerGeoObjectService)2 ServerGeoObjectIF (net.geoprism.registry.model.ServerGeoObjectIF)2 ChildTreeNode (org.commongeoregistry.adapter.dataaccess.ChildTreeNode)2 JsonArray (com.google.gson.JsonArray)1 JsonObject (com.google.gson.JsonObject)1 SmartExceptionDTO (com.runwaysdk.business.SmartExceptionDTO)1 Transaction (com.runwaysdk.dataaccess.transaction.Transaction)1 RestBodyResponse (com.runwaysdk.mvc.RestBodyResponse)1 Request (com.runwaysdk.session.Request)1 Universal (com.runwaysdk.system.gis.geo.Universal)1 InputStream (java.io.InputStream)1 Instant (java.time.Instant)1 LinkedList (java.util.LinkedList)1