use of net.geoprism.registry.io.Location in project geoprism-registry by terraframe.
the class BusinessObjectImportConfiguration method fromJSON.
@Request
public BusinessObjectImportConfiguration fromJSON(String json, boolean includeCoordinates) {
super.fromJSON(json);
SimpleDateFormat format = new SimpleDateFormat(BusinessObjectImportConfiguration.DATE_FORMAT);
format.setTimeZone(GeoRegistryUtil.SYSTEM_TIMEZONE);
JSONObject config = new JSONObject(json);
JSONObject type = config.getJSONObject(TYPE);
JSONArray locations = config.has(LOCATIONS) ? config.getJSONArray(LOCATIONS) : new JSONArray();
JSONArray attributes = type.getJSONArray(GeoObjectType.JSON_ATTRIBUTES);
String code = type.getString(GeoObjectType.JSON_CODE);
BusinessType businessType = BusinessType.getByCode(code);
this.setType(businessType);
try {
if (config.has(BusinessObjectImportConfiguration.DATE)) {
this.setDate(format.parse(config.getString(BusinessObjectImportConfiguration.DATE)));
}
} catch (ParseException e) {
throw new ProgrammingErrorException(e);
}
if (config.has(HIERARCHY)) {
String hCode = config.getString(HIERARCHY);
if (hCode.length() > 0) {
ServerHierarchyType hierarchyType = ServerHierarchyType.get(hCode);
this.setHierarchy(hierarchyType);
}
}
if (config.has(EXCLUSIONS)) {
JSONArray exclusions = config.getJSONArray(EXCLUSIONS);
for (int i = 0; i < exclusions.length(); i++) {
JSONObject exclusion = exclusions.getJSONObject(i);
String attributeName = exclusion.getString(AttributeType.JSON_CODE);
String value = exclusion.getString(VALUE);
this.addExclusion(attributeName, value);
}
}
for (int i = 0; i < attributes.length(); i++) {
JSONObject attribute = attributes.getJSONObject(i);
if (attribute.has(TARGET)) {
String attributeName = attribute.getString(AttributeType.JSON_CODE);
// In the case of a spreadsheet, this ends up being the column header
String target = attribute.getString(TARGET);
if (attribute.has("locale")) {
String locale = attribute.getString("locale");
if (this.getFunction(attributeName) == null) {
this.setFunction(attributeName, new LocalizedValueFunction());
}
LocalizedValueFunction function = (LocalizedValueFunction) this.getFunction(attributeName);
function.add(locale, new BasicColumnFunction(target));
} else {
this.setFunction(attributeName, new BasicColumnFunction(target));
}
}
}
for (int i = 0; i < locations.length(); i++) {
JSONObject location = locations.getJSONObject(i);
if (location.has(TARGET) && location.getString(TARGET).length() > 0 && location.has(MATCH_STRATEGY) && location.getString(MATCH_STRATEGY).length() > 0) {
String pCode = location.getString(AttributeType.JSON_CODE);
ServerGeoObjectType pType = ServerGeoObjectType.get(pCode);
String target = location.getString(TARGET);
ParentMatchStrategy matchStrategy = ParentMatchStrategy.valueOf(location.getString(MATCH_STRATEGY));
// coming in with use BasicColumnFunctions
if (location.has("type") && location.getString("type").equals(ConstantShapefileFunction.class.getName())) {
this.addLocation(new Location(pType, this.hierarchy, new ConstantShapefileFunction(target), matchStrategy));
} else {
this.addLocation(new Location(pType, this.hierarchy, new BasicColumnFunction(target), matchStrategy));
}
}
}
return this;
}
use of net.geoprism.registry.io.Location in project geoprism-registry by terraframe.
the class BusinessObjectImportConfiguration method toJSON.
@Request
@Override
public JSONObject toJSON() {
JSONObject config = new JSONObject();
super.toJSON(config);
SimpleDateFormat format = new SimpleDateFormat(BusinessObjectImportConfiguration.DATE_FORMAT);
format.setTimeZone(GeoRegistryUtil.SYSTEM_TIMEZONE);
JSONObject type = new JSONObject(this.type.toJSON(true).toString());
JSONArray attributes = type.getJSONArray(GeoObjectType.JSON_ATTRIBUTES);
for (int i = 0; i < attributes.length(); i++) {
JSONObject attribute = attributes.getJSONObject(i);
String attributeName = attribute.getString(AttributeType.JSON_CODE);
if (this.functions.containsKey(attributeName)) {
ShapefileFunction function = this.functions.get(attributeName);
if (function instanceof LocalizedValueFunction) {
String locale = attribute.getString("locale");
ShapefileFunction localeFunction = ((LocalizedValueFunction) function).getFunction(locale);
if (localeFunction != null) {
attribute.put(TARGET, localeFunction.toJson());
}
} else {
attribute.put(TARGET, function.toJson());
}
}
}
JSONArray locations = new JSONArray();
for (Location location : this.locations) {
locations.put(location.toJSON());
}
config.put(BusinessObjectImportConfiguration.TYPE, type);
config.put(BusinessObjectImportConfiguration.LOCATIONS, locations);
if (this.getDate() != null) {
config.put(BusinessObjectImportConfiguration.DATE, format.format(this.getDate()));
}
if (this.hierarchy != null) {
config.put(BusinessObjectImportConfiguration.HIERARCHY, this.getHierarchy().getCode());
}
if (this.exclusions.size() > 0) {
JSONArray exclusions = new JSONArray();
this.exclusions.forEach((key, set) -> {
set.forEach(value -> {
JSONObject object = new JSONObject();
object.put(AttributeType.JSON_CODE, key);
object.put(VALUE, value);
exclusions.put(object);
});
});
config.put(EXCLUSIONS, exclusions);
}
return config;
}
use of net.geoprism.registry.io.Location in project geoprism-registry by terraframe.
the class ShapefileServiceTest method testBadParentSynonymAndResume.
@Test
@Request
public void testBadParentSynonymAndResume() throws Throwable {
InputStream istream = this.getClass().getResourceAsStream("/cb_2017_us_state_500k.zip.test");
Assert.assertNotNull(istream);
ShapefileService service = new ShapefileService();
GeoObjectImportConfiguration config = this.getTestConfiguration(istream, service, null, ImportStrategy.NEW_AND_UPDATE);
ServerHierarchyType hierarchyType = ServerHierarchyType.get(USATestData.HIER_ADMIN.getCode());
config.setHierarchy(hierarchyType);
config.addParent(new Location(USATestData.COUNTRY.getServerObject(), hierarchyType, new BasicColumnFunction("LSAD"), ParentMatchStrategy.ALL));
// ImportHistory hist = mockImport(config);
// Assert.assertTrue(hist.getStatus().get(0).equals(AllJobStatus.FEEDBACK));
ImportHistory hist = importShapefile(testData.clientRequest.getSessionId(), config.toJSON().toString());
SchedulerTestUtils.waitUntilStatus(hist.getOid(), AllJobStatus.FEEDBACK);
hist = ImportHistory.get(hist.getOid());
Assert.assertEquals(new Long(56), hist.getWorkTotal());
Assert.assertEquals(new Long(56), hist.getWorkProgress());
Assert.assertEquals(new Long(0), hist.getImportedRecords());
Assert.assertEquals(ImportStage.VALIDATION_RESOLVE, hist.getStage().get(0));
JSONObject page = new JSONObject(new ETLService().getValidationProblems(testData.clientRequest.getSessionId(), hist.getOid(), false, 100, 1).toString());
JSONArray results = page.getJSONArray("resultSet");
Assert.assertEquals(1, results.length());
// Ensure the geo objects were not created
ServerGeoObjectQuery query = new ServerGeoObjectService().createQuery(USATestData.STATE.getServerObject(), config.getStartDate());
query.setRestriction(new ServerCodeRestriction("01"));
Assert.assertNull(query.getSingleResult());
// Resolve the import problem with a synonym
GeoObject geoObj = ServiceFactory.getRegistryService().newGeoObjectInstance(testData.clientRequest.getSessionId(), USATestData.COUNTRY.getCode());
geoObj.setCode("99");
geoObj.setDisplayLabel(LocalizedValue.DEFAULT_LOCALE, "Test Label99");
geoObj.setUid(ServiceFactory.getIdService().getUids(1)[0]);
ServerGeoObjectIF serverGo = new ServerGeoObjectService(new AllowAllGeoObjectPermissionService()).apply(geoObj, TestDataSet.DEFAULT_OVER_TIME_DATE, TestDataSet.DEFAULT_END_TIME_DATE, true, false);
JSONObject valRes = new JSONObject();
valRes.put("validationProblemId", results.getJSONObject(0).getString("id"));
valRes.put("resolution", ValidationResolution.SYNONYM);
valRes.put("code", serverGo.getCode());
valRes.put("typeCode", serverGo.getType().getCode());
valRes.put("label", "00");
new ETLService().submitValidationProblemResolution(testData.clientRequest.getSessionId(), valRes.toString());
ValidationProblem vp = ValidationProblem.get(results.getJSONObject(0).getString("id"));
Assert.assertEquals(ValidationResolution.SYNONYM.name(), vp.getResolution());
Assert.assertEquals(ParentReferenceProblem.DEFAULT_SEVERITY, vp.getSeverity());
ImportHistory hist2 = importShapefile(testData.clientRequest.getSessionId(), hist.getConfigJson());
Assert.assertEquals(hist.getOid(), hist2.getOid());
SchedulerTestUtils.waitUntilStatus(hist.getOid(), AllJobStatus.SUCCESS);
hist = ImportHistory.get(hist.getOid());
Assert.assertEquals(ImportStage.COMPLETE, hist.getStage().get(0));
Assert.assertEquals(new Long(56), hist.getWorkTotal());
Assert.assertEquals(new Long(56), hist.getWorkProgress());
Assert.assertEquals(new Long(56), hist.getImportedRecords());
String sessionId = testData.clientRequest.getSessionId();
GeoObject go = ServiceFactory.getRegistryService().getGeoObjectByCode(sessionId, "01", USATestData.STATE.getCode(), TestDataSet.DEFAULT_OVER_TIME_DATE);
Assert.assertEquals("01", go.getCode());
ParentTreeNode nodes = ServiceFactory.getRegistryService().getParentGeoObjects(sessionId, go.getCode(), config.getType().getCode(), new String[] { USATestData.COUNTRY.getCode() }, false, TestDataSet.DEFAULT_OVER_TIME_DATE);
List<ParentTreeNode> parents = nodes.getParents();
Assert.assertEquals(1, parents.size());
JSONObject page2 = new JSONObject(new ETLService().getValidationProblems(testData.clientRequest.getSessionId(), hist.getOid(), false, 100, 1).toString());
JSONArray results2 = page2.getJSONArray("resultSet");
Assert.assertEquals(0, results2.length());
Assert.assertEquals(0, page2.getInt("count"));
}
Aggregations