use of net.geoprism.registry.action.geoobject.UpdateGeoObjectAction 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 net.geoprism.registry.action.geoobject.UpdateGeoObjectAction in project geoprism-registry by terraframe.
the class CRAttributePatch method patchAllCRS.
private void patchAllCRS() {
ChangeRequestQuery crq = new ChangeRequestQuery(new QueryFactory());
logger.info("Updating [" + crq.getCount() + "] ChangeRequest records and patching in permissions info.");
OIterator<? extends ChangeRequest> it = crq.getIterator();
Outer: for (ChangeRequest cr : it) {
String orgCode = null;
String gotCode = null;
String gotTypeCode = null;
cr.appLock();
boolean hasInvalidAction = false;
OIterator<? extends AbstractAction> actionIt = cr.getAllAction();
SetParentAction setParent = null;
CreateGeoObjectAction createAction = null;
for (AbstractAction action : actionIt) {
if (action instanceof SetParentAction) {
SetParentAction spa = ((SetParentAction) action);
gotCode = spa.getChildCode();
gotTypeCode = spa.getChildTypeCode();
orgCode = Organization.getRootOrganizationCode(Universal.getByKey(gotTypeCode).getOwnerOid());
setParent = (SetParentAction) action;
} else if (action instanceof CreateGeoObjectAction) {
CreateGeoObjectAction create = ((CreateGeoObjectAction) action);
gotCode = GeoObjectOverTimeJsonAdapters.GeoObjectDeserializer.getCode(create.getGeoObjectJson());
gotTypeCode = GeoObjectOverTimeJsonAdapters.GeoObjectDeserializer.getTypeCode(create.getGeoObjectJson());
orgCode = Organization.getRootOrganizationCode(Universal.getByKey(gotTypeCode).getOwnerOid());
createAction = (CreateGeoObjectAction) action;
} else if (action instanceof UpdateGeoObjectAction) {
UpdateGeoObjectAction update = ((UpdateGeoObjectAction) action);
gotCode = GeoObjectOverTimeJsonAdapters.GeoObjectDeserializer.getCode(update.getGeoObjectJson());
gotTypeCode = GeoObjectOverTimeJsonAdapters.GeoObjectDeserializer.getTypeCode(update.getGeoObjectJson());
orgCode = Organization.getRootOrganizationCode(Universal.getByKey(gotTypeCode).getOwnerOid());
hasInvalidAction = true;
} else if (action instanceof UpdateAttributeAction) {
continue Outer;
} else {
throw new UnsupportedOperationException("Unexpected action type [" + action.getType() + "].");
}
}
if (setParent != null && createAction != null) {
createAction.appLock();
createAction.setParentJson(setParent.getJson());
createAction.apply();
setParent.delete();
} else if (setParent != null || createAction != null) {
// A set parent without a create (or vice versa)? This isn't supposed to exist
cr.clearApprovalStatus();
cr.addApprovalStatus(AllGovernanceStatus.INVALID);
}
cr.setOrganizationCode(orgCode);
cr.setGeoObjectCode(gotCode);
cr.setGeoObjectTypeCode(gotTypeCode);
if (cr.getGovernanceStatus().equals(AllGovernanceStatus.PENDING) && hasInvalidAction) {
cr.clearApprovalStatus();
cr.addApprovalStatus(AllGovernanceStatus.INVALID);
}
cr.apply();
}
}
use of net.geoprism.registry.action.geoobject.UpdateGeoObjectAction in project geoprism-registry by terraframe.
the class GovernanceTest method testActionSerialization.
/**
* Tests serialization on the DTOs and also conversion to/from DTO
*/
@Test
public void testActionSerialization() {
TestGeoObjectInfo testGo = FastTestDataset.CAMBODIA;
// GeoObjectOverTime go = testGo.asGeoObject();
GeoObjectOverTime goTime = testData.adapter.getGeoObjectOverTimeByCode(FastTestDataset.CAMBODIA.getCode(), FastTestDataset.CAMBODIA.getGeoObjectType().getCode());
testGo.setRegistryId(goTime.getUid());
/*
* UpdateGeoObject
*/
UpdateGeoObjectActionDTO updateDTO = new UpdateGeoObjectActionDTO();
updateDTO.setGeoObject(goTime.toJSON());
updateDTO.setCreateActionDate(Date.from(Instant.now().minus(6, ChronoUnit.HOURS)));
updateDTO.setContributorNotes("UPDATE_CONTRIB_NOTES");
updateDTO.setMaintainerNotes("UPDATE_MAINTAIN_NOTES");
String updateJson = updateDTO.toJSON().toString();
String updateJson2 = AbstractActionDTO.parseAction(updateJson).toJSON().toString();
Assert.assertEquals(updateJson, updateJson2);
UpdateGeoObjectAction updateRA = (UpdateGeoObjectAction) AbstractAction.dtoToRegistry(updateDTO);
GeoObjectOverTime updateRAGO = GeoObjectOverTime.fromJSON(testData.adapter, updateRA.getGeoObjectJson());
// testGo.assertEquals(updateRAGO);
Assert.assertEquals(updateDTO.getContributorNotes(), updateRA.getContributorNotes());
Assert.assertEquals(updateDTO.getMaintainerNotes(), updateRA.getMaintainerNotes());
Assert.assertEquals(updateDTO.getApiVersion(), updateRA.getApiVersion());
// Assert.assertEquals(updateDTO.getCreateActionDate().getTime(),
// updateRA.getCreateActionDate().getTime()); // TODO : Runway dates are
// accurate to the second, but epoch is accurate to the milisecond.
/*
* TODO : The rest of the supported actions
*/
}
use of net.geoprism.registry.action.geoobject.UpdateGeoObjectAction in project geoprism-registry by terraframe.
the class GovernanceTest method testUpdateAction.
@Test
public void testUpdateAction() {
Date startDate = new Date();
Date endDate = new Date();
GeoObjectOverTime goTime = testData.adapter.getGeoObjectOverTimeByCode(FastTestDataset.CAMBODIA.getCode(), FastTestDataset.CAMBODIA.getGeoObjectType().getCode());
goTime.setDisplayLabel(new LocalizedValue("test 123"), startDate, endDate);
UpdateGeoObjectActionDTO updateDTO = new UpdateGeoObjectActionDTO();
updateDTO.setGeoObject(goTime.toJSON());
updateDTO.setCreateActionDate(Date.from(Instant.now().minus(6, ChronoUnit.HOURS)));
updateDTO.setContributorNotes("UPDATE_CONTRIB_NOTES");
updateDTO.setMaintainerNotes("UPDATE_MAINTAIN_NOTES");
UpdateGeoObjectAction updateRA = (UpdateGeoObjectAction) AbstractAction.dtoToRegistry(updateDTO);
execute(updateRA);
GeoObjectOverTime goTime2 = testData.adapter.getGeoObjectOverTimeByCode(FastTestDataset.CAMBODIA.getCode(), FastTestDataset.CAMBODIA.getGeoObjectType().getCode());
Assert.assertEquals("test 123", goTime2.getDisplayLabel(startDate).getValue());
}
Aggregations