use of org.commongeoregistry.adapter.dataaccess.GeoObjectOverTime in project geoprism-registry by terraframe.
the class RegistryController method createGeoObjectOverTime.
@Endpoint(method = ServletMethod.POST, error = ErrorSerialization.JSON, url = RegistryUrls.GEO_OBJECT_TIME_CREATE)
public ResponseIF createGeoObjectOverTime(ClientRequestIF request, @RequestParamter(name = RegistryUrls.GEO_OBJECT_TIME_CREATE_PARAM_GEOOBJECT) String jGeoObj) {
GeoObjectOverTime geoObject = this.registryService.createGeoObjectOverTime(request.getSessionId(), jGeoObj);
CustomSerializer serializer = this.registryService.serializer(request.getSessionId());
return new RestBodyResponse(geoObject.toJSON(serializer));
}
use of org.commongeoregistry.adapter.dataaccess.GeoObjectOverTime in project geoprism-registry by terraframe.
the class RegistryController method updateGeoObjectOverTime.
@Endpoint(method = ServletMethod.POST, error = ErrorSerialization.JSON, url = RegistryUrls.GEO_OBJECT_TIME_UPDATE)
public ResponseIF updateGeoObjectOverTime(ClientRequestIF request, @RequestParamter(name = RegistryUrls.GEO_OBJECT_TIME_UPDATE_PARAM_GEOOBJECT) String jGeoObj) {
GeoObjectOverTime goTime = this.registryService.updateGeoObjectOverTime(request.getSessionId(), jGeoObj);
CustomSerializer serializer = this.registryService.serializer(request.getSessionId());
return new RestBodyResponse(goTime.toJSON(serializer));
}
use of org.commongeoregistry.adapter.dataaccess.GeoObjectOverTime in project geoprism-registry by terraframe.
the class GeoObjectImporter method validateRow.
@Transaction
public void validateRow(FeatureRow row) throws InterruptedException {
try {
// Refresh the session because it might expire on long imports
final long curWorkProgress = this.progressListener.getWorkProgress();
if ((this.lastValidateSessionRefresh + GeoObjectImporter.refreshSessionRecordCount) < curWorkProgress) {
SessionFacade.renewSession(Session.getCurrentSession().getOid());
this.lastValidateSessionRefresh = curWorkProgress;
}
try {
/*
* 1. Check for location problems
*/
if (this.configuration.isPostalCode() && PostalCodeFactory.isAvailable(this.configuration.getType())) {
// Skip location synonym check
} else if (this.configuration.getHierarchy() != null && this.configuration.getLocations().size() > 0) {
this.getParent(row);
}
/*
* 2. Check for serialization and term problems
*/
String code = this.getCode(row);
ServerGeoObjectIF entity;
if (code == null || code.length() <= 0) {
RequiredMappingException ex = new RequiredMappingException();
ex.setAttributeLabel(GeoObjectTypeMetadata.getAttributeDisplayLabel(DefaultAttribute.CODE.getName()));
throw ex;
}
entity = service.newInstance(this.configuration.getType());
entity.setCode(code);
entity.setInvalid(false);
try {
LocalizedValue entityName = this.getName(row);
if (entityName != null && this.hasValue(entityName)) {
entity.setDisplayLabel(entityName, this.configuration.getStartDate(), this.configuration.getEndDate());
}
Geometry geometry = (Geometry) this.getFormatSpecificImporter().getGeometry(row);
if (geometry != null) {
// geometry.getSRID().
if (geometry.isValid()) {
entity.setGeometry(geometry, this.configuration.getStartDate(), this.configuration.getEndDate());
} else {
InvalidGeometryException geomEx = new InvalidGeometryException();
throw geomEx;
}
}
Map<String, AttributeType> attributes = this.configuration.getType().getAttributeMap();
Set<Entry<String, AttributeType>> entries = attributes.entrySet();
for (Entry<String, AttributeType> entry : entries) {
String attributeName = entry.getKey();
if (!attributeName.equals(GeoObject.CODE)) {
ShapefileFunction function = this.configuration.getFunction(attributeName);
if (function != null) {
Object value = function.getValue(row);
if (value != null && !this.isEmptyString(value)) {
AttributeType attributeType = entry.getValue();
this.setValue(entity, attributeType, attributeName, value);
}
}
}
}
GeoObjectOverTime go = entity.toGeoObjectOverTime(false);
go.toJSON().toString();
if (this.configuration.isExternalImport()) {
ShapefileFunction function = this.configuration.getExternalIdFunction();
Object value = function.getValue(row);
if (value == null || !(value instanceof String || value instanceof Integer || value instanceof Long) || (value instanceof String && ((String) value).length() == 0)) {
throw new InvalidExternalIdException();
}
}
} finally {
entity.unlock();
}
} catch (IgnoreRowException e) {
// Do nothing
} catch (Throwable t) {
RowValidationProblem problem = new RowValidationProblem(t);
problem.addAffectedRowNumber(curWorkProgress + 1);
problem.setHistoryId(this.configuration.historyId);
this.progressListener.addRowValidationProblem(problem);
}
this.progressListener.setWorkProgress(curWorkProgress + 1);
if (Thread.interrupted()) {
throw new InterruptedException();
}
Thread.yield();
} catch (Throwable e) {
e.printStackTrace();
}
}
use of org.commongeoregistry.adapter.dataaccess.GeoObjectOverTime in project geoprism-registry by terraframe.
the class ServerGeoObjectService method createGeoObjectInTrans.
@Transaction
public JsonObject createGeoObjectInTrans(String sPtn, String sTimeGo, String masterListId, String notes) {
GeoObjectOverTime timeGO = GeoObjectOverTime.fromJSON(ServiceFactory.getAdapter(), sTimeGo);
ServerGeoObjectType serverGOT = ServerGeoObjectType.get(timeGO.getType());
RolePermissionService perms = ServiceFactory.getRolePermissionService();
final String orgCode = serverGOT.getOrganization().getCode();
if (perms.isSRA() || perms.isRA(orgCode) || perms.isRM(orgCode, serverGOT)) {
ServerGeoObjectService service = new ServerGeoObjectService();
ServerGeoObjectIF serverGO = service.apply(timeGO, true, false);
final ServerGeoObjectType type = serverGO.getType();
if (sPtn != null) {
ServerParentTreeNodeOverTime ptnOt = ServerParentTreeNodeOverTime.fromJSON(type, sPtn);
serverGO.setParents(ptnOt);
}
// Update the master list record
if (masterListId != null) {
ListTypeVersion.get(masterListId).publishRecord(serverGO);
}
JsonObject resp = new JsonObject();
resp.addProperty("isChangeRequest", false);
resp.add("geoObject", serverGO.toGeoObjectOverTime().toJSON(ServiceFactory.getRegistryService().serializer(Session.getCurrentSession().getOid())));
return resp;
} else if (ServiceFactory.getRolePermissionService().isRC(orgCode, serverGOT)) {
Instant base = Instant.now();
int sequence = 0;
ChangeRequest request = new ChangeRequest();
request.addApprovalStatus(AllGovernanceStatus.PENDING);
request.setContributorNotes(notes);
request.setGeoObjectCode(timeGO.getCode());
request.setGeoObjectTypeCode(timeGO.getType().getCode());
request.setOrganizationCode(orgCode);
request.apply();
CreateGeoObjectAction action = new CreateGeoObjectAction();
action.addApprovalStatus(AllGovernanceStatus.PENDING);
action.setCreateActionDate(Date.from(base.plus(sequence++, ChronoUnit.MINUTES)));
action.setGeoObjectJson(sTimeGo);
action.setParentJson(sPtn);
action.setApiVersion(CGRAdapterProperties.getApiVersion());
action.setContributorNotes(notes);
action.apply();
request.addAction(action).apply();
JsonObject resp = new JsonObject();
resp.addProperty("isChangeRequest", true);
resp.addProperty("changeRequestId", request.getOid());
return resp;
} else {
throw new CGRPermissionException();
}
}
use of org.commongeoregistry.adapter.dataaccess.GeoObjectOverTime in project geoprism-registry by terraframe.
the class GeoObjectOverTimeServiceTest method updateGO.
private void updateGO(TestRegistryAdapterClient adapter, TestGeoObjectInfo go) {
go.setWkt(TestDataSet.WKT_POLYGON_2);
go.setDisplayLabel("Some new value");
GeoObjectOverTime update = go.fetchGeoObjectOverTime();
go.populate(update);
GeoObjectOverTime returnedUpdate = adapter.updateGeoObjectOverTime(update.toJSON().toString());
go.assertEquals(returnedUpdate);
go.assertApplied();
}
Aggregations