Search in sources :

Example 1 with RemoveChildAction

use of net.geoprism.registry.action.tree.RemoveChildAction 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)

Aggregations

LinkedList (java.util.LinkedList)1 AddChildAction (net.geoprism.registry.action.tree.AddChildAction)1 RemoveChildAction (net.geoprism.registry.action.tree.RemoveChildAction)1 GeoObject (org.commongeoregistry.adapter.dataaccess.GeoObject)1 ParentTreeNode (org.commongeoregistry.adapter.dataaccess.ParentTreeNode)1