use of net.geoprism.registry.model.ServerHierarchyType in project geoprism-registry by terraframe.
the class ServerParentTreeNodeOverTime method isSame.
public boolean isSame(ServerParentTreeNodeOverTime other, ServerGeoObjectIF exclude) {
Set<Entry<String, Hierarchy>> entries = other.hierarchies.entrySet();
for (Entry<String, Hierarchy> entry : entries) {
Hierarchy hierarchy = entry.getValue();
ServerHierarchyType ht = hierarchy.getType();
if (this.hasEntries(ht) && hierarchy.nodes.size() == this.getEntries(ht).size()) {
for (int i = 0; i < hierarchy.nodes.size(); i++) {
ServerParentTreeNode node = hierarchy.nodes.get(i);
ServerParentTreeNode oNode = this.getEntries(ht).get(i);
if (!node.isSame(oNode, exclude)) {
return false;
}
}
} else {
return false;
}
}
return true;
}
use of net.geoprism.registry.model.ServerHierarchyType in project geoprism-registry by terraframe.
the class UpdateParentValueOverTimeView method executeParent.
public void executeParent(UpdateChangeOverTimeAttributeView cotView, VertexServerGeoObject go, SortedSet<EdgeObject> looseVotc) {
UpdateParentView parentView = (UpdateParentView) cotView;
final ServerHierarchyType hierarchyType = ServerHierarchyType.get(parentView.getHierarchyCode());
if (this.action.equals(UpdateActionType.DELETE)) {
EdgeObject edge = this.getEdgeByOid(looseVotc, this.oid);
if (edge == null) {
ExecuteOutOfDateChangeRequestException ex = new ExecuteOutOfDateChangeRequestException();
throw ex;
}
edge.delete();
looseVotc.remove(edge);
} else if (this.action.equals(UpdateActionType.UPDATE)) {
EdgeObject edge = this.getEdgeByOid(looseVotc, this.oid);
if (edge == null) {
ExecuteOutOfDateChangeRequestException ex = new ExecuteOutOfDateChangeRequestException();
throw ex;
}
final VertexServerGeoObject newParent = this.getNewValueAsGO();
final String parentCode = newParent == null ? null : newParent.getCode();
String currentCode = edge.getParent().getObjectValue(DefaultAttribute.CODE.getName());
// Parent values can only be changed by deleting the current edge and creating a new one unfortunately
if (this.newValue != null && (currentCode != parentCode)) {
Date _newStartDate = this.newStartDate;
Date _newEndDate = this.newEndDate;
if (_newStartDate == null) {
_newStartDate = edge.getObjectValue(GeoVertex.START_DATE);
}
if (_newEndDate == null) {
_newEndDate = edge.getObjectValue(GeoVertex.END_DATE);
}
edge.delete();
looseVotc.remove(edge);
if (newParent != null) {
// We unfortunately can't use this method because we have to bypass the votc reordering and validation
// go.addParent(newParent, hierarchyType, _newStartDate, _newEndDate);
EdgeObject newEdge = go.getVertex().addParent(((VertexComponent) newParent).getVertex(), hierarchyType.getMdEdge());
newEdge.setValue(GeoVertex.START_DATE, _newStartDate);
newEdge.setValue(GeoVertex.END_DATE, _newEndDate);
newEdge.apply();
looseVotc.add(newEdge);
}
return;
}
if (newStartDate != null) {
edge.setValue(GeoVertex.START_DATE, newStartDate);
}
if (newEndDate != null) {
edge.setValue(GeoVertex.END_DATE, newEndDate);
}
edge.apply();
} else if (this.action.equals(UpdateActionType.CREATE)) {
final VertexServerGeoObject newParent = this.getNewValueAsGO();
if (newParent == null || this.newStartDate == null || this.newEndDate == null) {
throw new InvalidChangeRequestException();
}
EdgeObject edge = go.getEdge(newParent, hierarchyType, this.newStartDate, this.newEndDate);
if (edge != null) {
ExecuteOutOfDateChangeRequestException ex = new ExecuteOutOfDateChangeRequestException();
throw ex;
}
// We unfortunately can't use this method because we have to bypass the votc reordering and validation
// go.addParent(newParent, hierarchyType, this.newStartDate, this.newEndDate);
EdgeObject newEdge = go.getVertex().addParent(((VertexComponent) newParent).getVertex(), hierarchyType.getMdEdge());
newEdge.setValue(GeoVertex.START_DATE, this.newStartDate);
newEdge.setValue(GeoVertex.END_DATE, this.newEndDate);
newEdge.apply();
looseVotc.add(newEdge);
} else {
throw new UnsupportedOperationException("Unsupported action type [" + this.action + "].");
}
}
use of net.geoprism.registry.model.ServerHierarchyType in project geoprism-registry by terraframe.
the class XMLImporter method addChildren.
private void addChildren(ServerHierarchyType hierarchy, ServerGeoObjectType parent, Element root) {
NodeList childNodes = root.getChildNodes();
for (int i = 0; i < childNodes.getLength(); i++) {
Node childNode = childNodes.item(i);
if (childNode.getNodeType() == Node.ELEMENT_NODE) {
Element elem = (Element) childNode;
String code = elem.getAttribute("code");
ServerGeoObjectType child = ServerGeoObjectType.get(code);
hierarchy.addToHierarchy(parent, child, false);
if (root.hasAttribute("extends")) {
String inheritedHierarchyCode = root.getAttribute("extends");
ServerHierarchyType inheritedHierarchy = ServerHierarchyType.get(inheritedHierarchyCode);
child.setInheritedHierarchy(hierarchy, inheritedHierarchy);
}
this.addChildren(hierarchy, child, elem);
}
}
}
use of net.geoprism.registry.model.ServerHierarchyType in project geoprism-registry by terraframe.
the class GeoObjectImporterTest method testUpdateErrorCount.
/**
* Tests to make sure that we are recording the correct amount of import errors.
*
* @throws InterruptedException
*/
@Test
@Request
public void testUpdateErrorCount() throws InterruptedException {
InputStream istream = this.getClass().getResourceAsStream("/test-spreadsheet3.xlsx");
Assert.assertNotNull(istream);
ExcelService service = new ExcelService();
ServerHierarchyType hierarchyType = ServerHierarchyType.get(USATestData.HIER_ADMIN.getCode());
GeoObjectImportConfiguration config = this.getTestConfiguration(istream, service, null, ImportStrategy.NEW_ONLY);
config.setHierarchy(hierarchyType);
// First, import the spreadsheet. It should be succesful
ImportHistory hist = importExcelFile(testData.clientRequest.getSessionId(), config.toJSON().toString());
SchedulerTestUtils.waitUntilStatus(hist.getOid(), AllJobStatus.SUCCESS);
hist = ImportHistory.get(hist.getOid());
Assert.assertEquals(new Long(10), hist.getWorkTotal());
Assert.assertEquals(new Long(10), hist.getWorkProgress());
Assert.assertEquals(new Long(10), hist.getImportedRecords());
Assert.assertEquals(ImportStage.COMPLETE, hist.getStage().get(0));
// Import a second spreadsheet, which should have a few duplicate records.
InputStream istream2 = this.getClass().getResourceAsStream("/test-spreadsheet4.xlsx");
GeoObjectImportConfiguration config2 = this.getTestConfiguration(istream2, service, null, ImportStrategy.NEW_ONLY);
config2.setHierarchy(hierarchyType);
ImportHistory hist2 = importExcelFile(testData.clientRequest.getSessionId(), config2.toJSON().toString());
SchedulerTestUtils.waitUntilStatus(hist2.getOid(), AllJobStatus.FEEDBACK);
hist2 = ImportHistory.get(hist2.getOid());
Assert.assertEquals(new Long(17), hist2.getWorkTotal());
Assert.assertEquals(new Long(17), hist2.getWorkProgress());
Assert.assertEquals(new Long(7), hist2.getImportedRecords());
Assert.assertEquals(ImportStage.IMPORT_RESOLVE, hist2.getStage().get(0));
JSONObject json = new JSONObject(new ETLService().getImportErrors(testData.clientRequest.getSessionId(), hist2.getOid(), false, 100, 1).toString());
Assert.assertEquals(10, json.getJSONArray("resultSet").length());
}
use of net.geoprism.registry.model.ServerHierarchyType in project geoprism-registry by terraframe.
the class ShapefileServiceTest method testImportShapefileWithBadParentCode.
@Test
@Request
public void testImportShapefileWithBadParentCode() throws Throwable {
GeoObject geoObj = ServiceFactory.getRegistryService().newGeoObjectInstance(testData.clientRequest.getSessionId(), USATestData.COUNTRY.getCode());
geoObj.setCode("00");
geoObj.setDisplayLabel(LocalizedValue.DEFAULT_LOCALE, "Test Label");
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);
geoObj = RegistryService.getInstance().getGeoObjectByCode(Session.getCurrentSession().getOid(), serverGO.getCode(), serverGO.getType().getCode(), TestDataSet.DEFAULT_OVER_TIME_DATE);
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("GEOID"), ParentMatchStrategy.CODE));
ImportHistory hist = mockImport(config);
Assert.assertTrue(hist.getStatus().get(0).equals(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));
final GeoObjectImportConfiguration test = new GeoObjectImportConfiguration();
test.fromJSON(hist.getConfigJson(), false);
// TODO
// Assert.assertEquals(config.getParentLookupType(),
// test.getParentLookupType());
// JSONArray errors = new JSONArray(hist.getErrorJson());
//
// Assert.assertEquals(0, errors.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());
}
Aggregations