use of org.commongeoregistry.adapter.dataaccess.GeoObject 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.GeoObject 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.GeoObject in project geoprism-registry by terraframe.
the class RegistryController method updateGeoObject.
/**
* Update a new GeoObject in the Common Geo-Registry
*
* @pre
* @post
*
* @param geoObject
* in GeoJSON format to be updated.
* @throws ParseException
*
* @returns
* @throws //TODO
*/
@Endpoint(method = ServletMethod.POST, error = ErrorSerialization.JSON, url = RegistryUrls.GEO_OBJECT_UPDATE)
public ResponseIF updateGeoObject(ClientRequestIF request, @RequestParamter(name = RegistryUrls.GEO_OBJECT_UPDATE_PARAM_GEOOBJECT) String jGeoObj, @RequestParamter(name = "startDate") String startDateString, @RequestParamter(name = "endDate") String endDateString) throws ParseException {
Date startDate = (startDateString != null && startDateString.length() > 0) ? GeoRegistryUtil.parseDate(startDateString, true) : null;
Date endDate = (endDateString != null && endDateString.length() > 0) ? GeoRegistryUtil.parseDate(endDateString, true) : null;
GeoObject geoObject = this.registryService.updateGeoObject(request.getSessionId(), jGeoObj, startDate, endDate);
CustomSerializer serializer = this.registryService.serializer(request.getSessionId());
return new RestBodyResponse(geoObject.toJSON(serializer));
}
use of org.commongeoregistry.adapter.dataaccess.GeoObject in project geoprism-registry by terraframe.
the class RegistryController method createGeoObject.
/**
* Creates a new GeoObject in the Common Geo-Registry
*
* @pre
* @post
*
* @param geoObject
* in GeoJSON format to be created.
* @throws ParseException
*
* @returns
* @throws //TODO
*/
@Endpoint(method = ServletMethod.POST, error = ErrorSerialization.JSON, url = RegistryUrls.GEO_OBJECT_CREATE)
public ResponseIF createGeoObject(ClientRequestIF request, @RequestParamter(name = RegistryUrls.GEO_OBJECT_CREATE_PARAM_GEOOBJECT) String jGeoObj, @RequestParamter(name = "startDate") String startDateString, @RequestParamter(name = "endDate") String endDateString) throws ParseException {
Date startDate = (startDateString != null && startDateString.length() > 0) ? GeoRegistryUtil.parseDate(startDateString, true) : null;
Date endDate = (endDateString != null && endDateString.length() > 0) ? GeoRegistryUtil.parseDate(endDateString, true) : null;
GeoObject geoObject = this.registryService.createGeoObject(request.getSessionId(), jGeoObj, startDate, endDate);
CustomSerializer serializer = this.registryService.serializer(request.getSessionId());
return new RestBodyResponse(geoObject.toJSON(serializer));
}
use of org.commongeoregistry.adapter.dataaccess.GeoObject in project geoprism-registry by terraframe.
the class RegistryController method getGeoObject.
/**
* Returns a GeoObject with the given uid.
*
* @pre @post
*
* @param uid
* The UID of the GeoObject.
*
* @returns a GeoObject in GeoJSON format with the given uid. @throws
*/
@Endpoint(method = ServletMethod.GET, error = ErrorSerialization.JSON, url = RegistryUrls.GEO_OBJECT_GET)
public ResponseIF getGeoObject(ClientRequestIF request, @RequestParamter(name = RegistryUrls.GEO_OBJECT_GET_PARAM_ID) String id, @RequestParamter(name = RegistryUrls.GEO_OBJECT_GET_PARAM_TYPE_CODE) String typeCode, @RequestParamter(name = "date") String date) throws JSONException {
GeoObject geoObject = this.registryService.getGeoObject(request.getSessionId(), id, typeCode, GeoRegistryUtil.parseDate(date, true));
CustomSerializer serializer = this.registryService.serializer(request.getSessionId());
return new RestBodyResponse(geoObject.toJSON(serializer));
}
Aggregations