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