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();
}
}
}
Aggregations