Search in sources :

Example 31 with ServerHierarchyType

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;
}
Also used : ServerHierarchyType(net.geoprism.registry.model.ServerHierarchyType) Entry(java.util.Map.Entry) ServerParentTreeNode(net.geoprism.registry.model.ServerParentTreeNode)

Example 32 with ServerHierarchyType

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 + "].");
    }
}
Also used : ServerHierarchyType(net.geoprism.registry.model.ServerHierarchyType) InvalidChangeRequestException(net.geoprism.registry.action.InvalidChangeRequestException) EdgeObject(com.runwaysdk.business.graph.EdgeObject) VertexServerGeoObject(net.geoprism.registry.model.graph.VertexServerGeoObject) Date(java.util.Date) ExecuteOutOfDateChangeRequestException(net.geoprism.registry.action.ExecuteOutOfDateChangeRequestException) VertexComponent(net.geoprism.registry.model.graph.VertexComponent)

Example 33 with ServerHierarchyType

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);
        }
    }
}
Also used : ServerHierarchyType(net.geoprism.registry.model.ServerHierarchyType) ServerGeoObjectType(net.geoprism.registry.model.ServerGeoObjectType) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) ServerElement(net.geoprism.registry.model.ServerElement) Element(org.w3c.dom.Element)

Example 34 with ServerHierarchyType

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());
}
Also used : ServerHierarchyType(net.geoprism.registry.model.ServerHierarchyType) GeoObjectImportConfiguration(net.geoprism.registry.io.GeoObjectImportConfiguration) JSONObject(org.json.JSONObject) InputStream(java.io.InputStream) ExcelService(net.geoprism.registry.service.ExcelService) Test(org.junit.Test) Request(com.runwaysdk.session.Request)

Example 35 with ServerHierarchyType

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());
}
Also used : ServerGeoObjectService(net.geoprism.registry.geoobject.ServerGeoObjectService) ServerHierarchyType(net.geoprism.registry.model.ServerHierarchyType) GeoObjectImportConfiguration(net.geoprism.registry.io.GeoObjectImportConfiguration) ServerGeoObjectIF(net.geoprism.registry.model.ServerGeoObjectIF) InputStream(java.io.InputStream) BasicColumnFunction(net.geoprism.data.importer.BasicColumnFunction) ShapefileService(net.geoprism.registry.service.ShapefileService) ServerGeoObjectQuery(net.geoprism.registry.query.ServerGeoObjectQuery) GeoObject(org.commongeoregistry.adapter.dataaccess.GeoObject) ServerCodeRestriction(net.geoprism.registry.query.ServerCodeRestriction) AllowAllGeoObjectPermissionService(net.geoprism.registry.permission.AllowAllGeoObjectPermissionService) Location(net.geoprism.registry.io.Location) Test(org.junit.Test) Request(com.runwaysdk.session.Request)

Aggregations

ServerHierarchyType (net.geoprism.registry.model.ServerHierarchyType)86 ServerGeoObjectType (net.geoprism.registry.model.ServerGeoObjectType)55 Request (com.runwaysdk.session.Request)38 JsonObject (com.google.gson.JsonObject)20 ServerGeoObjectIF (net.geoprism.registry.model.ServerGeoObjectIF)18 Test (org.junit.Test)17 JsonArray (com.google.gson.JsonArray)16 LinkedList (java.util.LinkedList)14 List (java.util.List)14 Transaction (com.runwaysdk.dataaccess.transaction.Transaction)12 GeoObjectType (org.commongeoregistry.adapter.metadata.GeoObjectType)12 GeoObject (org.commongeoregistry.adapter.dataaccess.GeoObject)11 AttributeType (org.commongeoregistry.adapter.metadata.AttributeType)11 Locale (java.util.Locale)10 Point (com.vividsolutions.jts.geom.Point)9 ServerParentTreeNode (net.geoprism.registry.model.ServerParentTreeNode)9 MdBusinessDAO (com.runwaysdk.dataaccess.metadata.MdBusinessDAO)8 MdBusiness (com.runwaysdk.system.metadata.MdBusiness)8 InheritedHierarchyAnnotation (net.geoprism.registry.InheritedHierarchyAnnotation)8 Organization (net.geoprism.registry.Organization)8