Search in sources :

Example 1 with ValueOverTimeCollectionDTO

use of org.commongeoregistry.adapter.dataaccess.ValueOverTimeCollectionDTO in project geoprism-registry by terraframe.

the class VertexServerGeoObject method populate.

@SuppressWarnings("unchecked")
@Override
public void populate(GeoObjectOverTime goTime) {
    Map<String, AttributeType> attributes = goTime.getType().getAttributeMap();
    attributes.forEach((attributeName, attribute) -> {
        if (attributeName.equals(DefaultAttribute.INVALID.getName()) || attributeName.equals(DefaultAttribute.CODE.getName()) || attributeName.equals(DefaultAttribute.UID.getName()) || attributeName.equals(GeoVertex.LASTUPDATEDATE) || attributeName.equals(GeoVertex.CREATEDATE)) {
        // Ignore the attributes
        } else // }
        if (attributeName.equals(DefaultAttribute.DISPLAY_LABEL.getName())) {
            this.getValuesOverTime(attributeName).clear();
            for (ValueOverTimeDTO votDTO : goTime.getAllValues(attributeName)) {
                LocalizedValue label = (LocalizedValue) votDTO.getValue();
                this.setDisplayLabel(label, votDTO.getStartDate(), votDTO.getEndDate());
            }
        } else if (this.vertex.hasAttribute(attributeName) && !this.vertex.getMdAttributeDAO(attributeName).isSystem()) {
            this.getValuesOverTime(attributeName).clear();
            ValueOverTimeCollectionDTO collection = goTime.getAllValues(attributeName);
            for (ValueOverTimeDTO votDTO : collection) {
                if (attribute instanceof AttributeTermType) {
                    Iterator<String> it = (Iterator<String>) votDTO.getValue();
                    if (it.hasNext()) {
                        String code = it.next();
                        Term root = ((AttributeTermType) attribute).getRootTerm();
                        String parent = TermConverter.buildClassifierKeyFromTermCode(root.getCode());
                        String classifierKey = Classifier.buildKey(parent, code);
                        Classifier classifier = Classifier.getByKey(classifierKey);
                        this.vertex.setValue(attributeName, classifier.getOid(), votDTO.getStartDate(), votDTO.getEndDate());
                    } else {
                        this.vertex.setValue(attributeName, (String) null, votDTO.getStartDate(), votDTO.getEndDate());
                    }
                } else if (attribute instanceof AttributeClassificationType) {
                    String value = (String) votDTO.getValue();
                    if (value != null) {
                        Classification classification = Classification.get((AttributeClassificationType) attribute, value);
                        this.vertex.setValue(attributeName, classification.getVertex(), votDTO.getStartDate(), votDTO.getEndDate());
                    } else {
                        this.vertex.setValue(attributeName, (String) null, this.date, this.date);
                    }
                } else {
                    Object value = votDTO.getValue();
                    if (value != null) {
                        this.vertex.setValue(attributeName, value, votDTO.getStartDate(), votDTO.getEndDate());
                    } else {
                        this.vertex.setValue(attributeName, (String) null, votDTO.getStartDate(), votDTO.getEndDate());
                    }
                }
            }
        }
    });
    this.getValuesOverTime(this.getGeometryAttributeName()).clear();
    for (ValueOverTimeDTO votDTO : goTime.getAllValues(DefaultAttribute.GEOMETRY.getName())) {
        Geometry geom = goTime.getGeometry(votDTO.getStartDate());
        this.setGeometry(geom, votDTO.getStartDate(), votDTO.getEndDate());
    }
    this.setUid(goTime.getUid());
    this.setCode(goTime.getCode());
    this.setInvalid(goTime.getInvalid());
}
Also used : ValueOverTimeCollectionDTO(org.commongeoregistry.adapter.dataaccess.ValueOverTimeCollectionDTO) ValueOverTimeDTO(org.commongeoregistry.adapter.dataaccess.ValueOverTimeDTO) MultiLineString(com.vividsolutions.jts.geom.MultiLineString) LineString(com.vividsolutions.jts.geom.LineString) Term(org.commongeoregistry.adapter.Term) Classifier(net.geoprism.ontology.Classifier) AttributeClassificationType(org.commongeoregistry.adapter.metadata.AttributeClassificationType) Geometry(com.vividsolutions.jts.geom.Geometry) LocalizedValue(org.commongeoregistry.adapter.dataaccess.LocalizedValue) AttributeType(org.commongeoregistry.adapter.metadata.AttributeType) Classification(net.geoprism.registry.model.Classification) AbstractClassification(com.runwaysdk.system.AbstractClassification) Iterator(java.util.Iterator) GeoObject(org.commongeoregistry.adapter.dataaccess.GeoObject) VertexObject(com.runwaysdk.business.graph.VertexObject) EdgeObject(com.runwaysdk.business.graph.EdgeObject) AbstractServerGeoObject(net.geoprism.registry.model.AbstractServerGeoObject) GraphObject(com.runwaysdk.business.graph.GraphObject) AttributeTermType(org.commongeoregistry.adapter.metadata.AttributeTermType)

Example 2 with ValueOverTimeCollectionDTO

use of org.commongeoregistry.adapter.dataaccess.ValueOverTimeCollectionDTO in project geoprism-registry by terraframe.

the class RegistryVersionTest method testInsertDuplicateBetween.

/**
 * Tests to make sure if we set a value which is encompassed by a larger surrounding date range
 * that the operation is ignored.
 */
@Test
public void testInsertDuplicateBetween() throws ParseException {
    final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
    dateFormat.setTimeZone(GeoRegistryUtil.SYSTEM_TIMEZONE);
    this.addVersionData(FastTestDataset.PROV_CENTRAL);
    Assert.assertEquals(3, FastTestDataset.PROV_CENTRAL.getServerObject().getValuesOverTime(DefaultAttribute.EXISTS.getName()).size());
    FastTestDataset.PROV_CENTRAL.getServerObject().setExists(Boolean.TRUE, dateFormat.parse("02-10-1990"), dateFormat.parse("02-15-1990"));
    Assert.assertEquals(3, FastTestDataset.PROV_CENTRAL.getServerObject().getValuesOverTime(DefaultAttribute.EXISTS.getName()).size());
    GeoObjectOverTime goTime = testData.adapter.getGeoObjectOverTimeByCode(FastTestDataset.PROV_CENTRAL.getCode(), FastTestDataset.PROV_CENTRAL.getGeoObjectType().getCode());
    Assert.assertEquals(3, goTime.getAllValues(DefaultAttribute.EXISTS.getName()).size());
    Assert.assertEquals(FastTestDataset.PROV_CENTRAL.getCode(), goTime.getCode());
    Assert.assertEquals(Boolean.FALSE, goTime.getExists(dateFormat.parse("1990-01-01")));
    Assert.assertEquals(Boolean.TRUE, goTime.getExists(dateFormat.parse("1990-02-01")));
    Assert.assertEquals(Boolean.FALSE, goTime.getExists(dateFormat.parse("1990-03-01")));
    ValueOverTimeCollectionDTO allStatus = goTime.getAllValues(DefaultAttribute.EXISTS.getName());
    Assert.assertEquals("1990-01-01", dateFormat.format(allStatus.get(0).getStartDate()));
    Assert.assertEquals("1990-01-31", dateFormat.format(allStatus.get(0).getEndDate()));
    Assert.assertEquals("1990-02-01", dateFormat.format(allStatus.get(1).getStartDate()));
    Assert.assertEquals("1990-02-28", dateFormat.format(allStatus.get(1).getEndDate()));
    Assert.assertEquals("1990-03-01", dateFormat.format(allStatus.get(2).getStartDate()));
    Assert.assertEquals("1990-03-31", dateFormat.format(allStatus.get(2).getEndDate()));
    Geometry expectedGeom = FastTestDataset.PROV_CENTRAL.fetchGeoObject().getGeometry();
    Geometry actualGeom = ((AttributeGeometry) goTime.getAttributeOnDate(DefaultAttribute.GEOMETRY.getName(), FastTestDataset.DEFAULT_OVER_TIME_DATE)).getValue();
    Assert.assertTrue(expectedGeom.equalsTopo(actualGeom));
}
Also used : AttributeGeometry(org.commongeoregistry.adapter.dataaccess.AttributeGeometry) Geometry(com.vividsolutions.jts.geom.Geometry) ValueOverTimeCollectionDTO(org.commongeoregistry.adapter.dataaccess.ValueOverTimeCollectionDTO) AttributeGeometry(org.commongeoregistry.adapter.dataaccess.AttributeGeometry) GeoObjectOverTime(org.commongeoregistry.adapter.dataaccess.GeoObjectOverTime) SimpleDateFormat(java.text.SimpleDateFormat) Test(org.junit.Test)

Example 3 with ValueOverTimeCollectionDTO

use of org.commongeoregistry.adapter.dataaccess.ValueOverTimeCollectionDTO in project geoprism-registry by terraframe.

the class RegistryVersionTest method testGetGeoObjectOverTimeByCode.

@Test
public void testGetGeoObjectOverTimeByCode() throws ParseException {
    this.addVersionData(FastTestDataset.PROV_CENTRAL);
    GeoObjectOverTime goTime = testData.adapter.getGeoObjectOverTimeByCode(FastTestDataset.PROV_CENTRAL.getCode(), FastTestDataset.PROV_CENTRAL.getGeoObjectType().getCode());
    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
    dateFormat.setTimeZone(GeoRegistryUtil.SYSTEM_TIMEZONE);
    Assert.assertEquals(FastTestDataset.PROV_CENTRAL.getCode(), goTime.getCode());
    Assert.assertEquals(Boolean.FALSE, goTime.getExists(dateFormat.parse("1990-01-01")));
    Assert.assertEquals(Boolean.TRUE, goTime.getExists(dateFormat.parse("1990-02-01")));
    Assert.assertEquals(Boolean.FALSE, goTime.getExists(dateFormat.parse("1990-03-01")));
    ValueOverTimeCollectionDTO allStatus = goTime.getAllValues(DefaultAttribute.EXISTS.getName());
    Assert.assertEquals("1990-01-01", dateFormat.format(allStatus.get(0).getStartDate()));
    Assert.assertEquals("1990-01-31", dateFormat.format(allStatus.get(0).getEndDate()));
    Assert.assertEquals("1990-02-01", dateFormat.format(allStatus.get(1).getStartDate()));
    Assert.assertEquals("1990-02-28", dateFormat.format(allStatus.get(1).getEndDate()));
    Assert.assertEquals("1990-03-01", dateFormat.format(allStatus.get(2).getStartDate()));
    Assert.assertEquals("1990-03-31", dateFormat.format(allStatus.get(2).getEndDate()));
    Geometry expectedGeom = FastTestDataset.PROV_CENTRAL.fetchGeoObject().getGeometry();
    Geometry actualGeom = ((AttributeGeometry) goTime.getAttributeOnDate(DefaultAttribute.GEOMETRY.getName(), FastTestDataset.DEFAULT_OVER_TIME_DATE)).getValue();
    Assert.assertTrue(expectedGeom.equalsTopo(actualGeom));
}
Also used : AttributeGeometry(org.commongeoregistry.adapter.dataaccess.AttributeGeometry) Geometry(com.vividsolutions.jts.geom.Geometry) ValueOverTimeCollectionDTO(org.commongeoregistry.adapter.dataaccess.ValueOverTimeCollectionDTO) AttributeGeometry(org.commongeoregistry.adapter.dataaccess.AttributeGeometry) GeoObjectOverTime(org.commongeoregistry.adapter.dataaccess.GeoObjectOverTime) SimpleDateFormat(java.text.SimpleDateFormat) Test(org.junit.Test)

Example 4 with ValueOverTimeCollectionDTO

use of org.commongeoregistry.adapter.dataaccess.ValueOverTimeCollectionDTO in project geoprism-registry by terraframe.

the class VertexServerGeoObject method toGeoObjectOverTime.

public GeoObjectOverTime toGeoObjectOverTime(boolean generateUid) {
    Map<String, ValueOverTimeCollectionDTO> votAttributeMap = GeoObjectOverTime.buildVotAttributeMap(type.getType());
    Map<String, Attribute> attributeMap = GeoObjectOverTime.buildAttributeMap(type.getType());
    GeoObjectOverTime geoObj = new GeoObjectOverTime(type.getType(), votAttributeMap, attributeMap);
    Map<String, AttributeType> attributes = type.getAttributeMap();
    attributes.forEach((attributeName, attribute) -> {
        if (attributeName.equals(DefaultAttribute.DISPLAY_LABEL.getName())) {
            ValueOverTimeCollection votc = this.getValuesOverTime(attributeName);
            ValueOverTimeCollectionDTO votcDTO = new ValueOverTimeCollectionDTO(attribute);
            for (ValueOverTime vot : votc) {
                Object value = this.getDisplayLabel(vot.getStartDate());
                ValueOverTimeDTO votDTO = new ValueOverTimeDTO(vot.getOid(), vot.getStartDate(), vot.getEndDate(), votcDTO);
                votDTO.setValue(value);
                votcDTO.add(votDTO);
            }
            geoObj.setValueCollection(attributeName, votcDTO);
        } else // }
        if (vertex.hasAttribute(attributeName)) {
            if (attribute.isChangeOverTime()) {
                ValueOverTimeCollection votc = this.getValuesOverTime(attributeName);
                ValueOverTimeCollectionDTO votcDTO = new ValueOverTimeCollectionDTO(attribute);
                for (ValueOverTime vot : votc) {
                    // if (attributeName.equals(DefaultAttribute.STATUS.getName()))
                    // {
                    // Term statusTerm =
                    // ServiceFactory.getConversionService().geoObjectStatusToTerm(this.getStatus(vot.getStartDate()));
                    // 
                    // ValueOverTimeDTO votDTO = new ValueOverTimeDTO(vot.getOid(),
                    // vot.getStartDate(), vot.getEndDate(), votcDTO);
                    // votDTO.setValue(statusTerm.getCode());
                    // votcDTO.add(votDTO);
                    // }
                    // else
                    // {
                    Object value = vot.getValue();
                    if (value != null) {
                        if (attribute instanceof AttributeTermType) {
                            Classifier classifier = Classifier.get((String) value);
                            try {
                                ValueOverTimeDTO votDTO = new ValueOverTimeDTO(vot.getOid(), vot.getStartDate(), vot.getEndDate(), votcDTO);
                                votDTO.setValue(classifier.getClassifierId());
                                votcDTO.add(votDTO);
                            } catch (UnknownTermException e) {
                                TermValueException ex = new TermValueException();
                                ex.setAttributeLabel(e.getAttribute().getLabel().getValue());
                                ex.setCode(e.getCode());
                                throw e;
                            }
                        } else if (attribute instanceof AttributeClassificationType) {
                            String classificationTypeCode = ((AttributeClassificationType) attribute).getClassificationType();
                            ClassificationType classificationType = ClassificationType.getByCode(classificationTypeCode);
                            Classification classification = Classification.getByOid(classificationType, (String) value);
                            try {
                                ValueOverTimeDTO votDTO = new ValueOverTimeDTO(vot.getOid(), vot.getStartDate(), vot.getEndDate(), votcDTO);
                                votDTO.setValue(classification.toTerm());
                                votcDTO.add(votDTO);
                            } catch (UnknownTermException e) {
                                TermValueException ex = new TermValueException();
                                ex.setAttributeLabel(e.getAttribute().getLabel().getValue());
                                ex.setCode(e.getCode());
                                throw e;
                            }
                        } else {
                            ValueOverTimeDTO votDTO = new ValueOverTimeDTO(vot.getOid(), vot.getStartDate(), vot.getEndDate(), votcDTO);
                            votDTO.setValue(value);
                            votcDTO.add(votDTO);
                        }
                    }
                // }
                }
                geoObj.setValueCollection(attributeName, votcDTO);
            } else {
                Object value = this.getValue(attributeName);
                if (value != null) {
                    if (attribute instanceof AttributeTermType) {
                        Classifier classifier = Classifier.get((String) value);
                        try {
                            geoObj.setValue(attributeName, classifier.getClassifierId());
                        } catch (UnknownTermException e) {
                            TermValueException ex = new TermValueException();
                            ex.setAttributeLabel(e.getAttribute().getLabel().getValue());
                            ex.setCode(e.getCode());
                            throw e;
                        }
                    } else if (attribute instanceof AttributeClassificationType) {
                        String classificationType = ((AttributeClassificationType) attribute).getClassificationType();
                        MdClassificationDAOIF mdClassificationDAO = MdClassificationDAO.getMdClassificationDAO(classificationType);
                        MdVertexDAOIF mdVertexDAO = mdClassificationDAO.getReferenceMdVertexDAO();
                        VertexObject classification = VertexObject.get(mdVertexDAO, (String) value);
                        try {
                            geoObj.setValue(attributeName, classification.getObjectValue(AbstractClassification.CODE));
                        } catch (UnknownTermException e) {
                            TermValueException ex = new TermValueException();
                            ex.setAttributeLabel(e.getAttribute().getLabel().getValue());
                            ex.setCode(e.getCode());
                            throw e;
                        }
                    } else {
                        geoObj.setValue(attributeName, value);
                    }
                }
            }
        }
    });
    if (// && !vertex.isAppliedToDB())
    generateUid && vertex.isNew()) {
        geoObj.setUid(RegistryIdService.getInstance().next());
    // geoObj.setStatus(ServiceFactory.getAdapter().getMetadataCache().getTerm(DefaultTerms.GeoObjectStatusTerm.NEW.code).get(),
    // this.date, this.date);
    } else {
        geoObj.setUid(vertex.getObjectValue(RegistryConstants.UUID));
    }
    ValueOverTimeCollection votc = this.getValuesOverTime(this.getGeometryAttributeName());
    ValueOverTimeCollectionDTO votcDTO = new ValueOverTimeCollectionDTO(geoObj.getGeometryAttributeType());
    for (ValueOverTime vot : votc) {
        Object value = vot.getValue();
        ValueOverTimeDTO votDTO = new ValueOverTimeDTO(vot.getOid(), vot.getStartDate(), vot.getEndDate(), votcDTO);
        votDTO.setValue(value);
        votcDTO.add(votDTO);
    }
    geoObj.setValueCollection(DefaultAttribute.GEOMETRY.getName(), votcDTO);
    geoObj.setCode(vertex.getObjectValue(DefaultAttribute.CODE.getName()));
    return geoObj;
}
Also used : MdVertexDAOIF(com.runwaysdk.dataaccess.MdVertexDAOIF) ValueOverTimeCollectionDTO(org.commongeoregistry.adapter.dataaccess.ValueOverTimeCollectionDTO) Attribute(org.commongeoregistry.adapter.dataaccess.Attribute) DefaultAttribute(org.commongeoregistry.adapter.constants.DefaultAttribute) VertexObject(com.runwaysdk.business.graph.VertexObject) GeoObjectOverTime(org.commongeoregistry.adapter.dataaccess.GeoObjectOverTime) ValueOverTimeDTO(org.commongeoregistry.adapter.dataaccess.ValueOverTimeDTO) MultiLineString(com.vividsolutions.jts.geom.MultiLineString) LineString(com.vividsolutions.jts.geom.LineString) Classifier(net.geoprism.ontology.Classifier) AttributeClassificationType(org.commongeoregistry.adapter.metadata.AttributeClassificationType) ClassificationType(net.geoprism.registry.model.ClassificationType) AttributeClassificationType(org.commongeoregistry.adapter.metadata.AttributeClassificationType) MdClassificationDAOIF(com.runwaysdk.dataaccess.MdClassificationDAOIF) ValueOverTime(com.runwaysdk.dataaccess.graph.attributes.ValueOverTime) TermValueException(net.geoprism.registry.io.TermValueException) AttributeType(org.commongeoregistry.adapter.metadata.AttributeType) Classification(net.geoprism.registry.model.Classification) AbstractClassification(com.runwaysdk.system.AbstractClassification) ValueOverTimeCollection(com.runwaysdk.dataaccess.graph.attributes.ValueOverTimeCollection) GeoObject(org.commongeoregistry.adapter.dataaccess.GeoObject) VertexObject(com.runwaysdk.business.graph.VertexObject) EdgeObject(com.runwaysdk.business.graph.EdgeObject) AbstractServerGeoObject(net.geoprism.registry.model.AbstractServerGeoObject) GraphObject(com.runwaysdk.business.graph.GraphObject) AttributeTermType(org.commongeoregistry.adapter.metadata.AttributeTermType) UnknownTermException(org.commongeoregistry.adapter.dataaccess.UnknownTermException)

Example 5 with ValueOverTimeCollectionDTO

use of org.commongeoregistry.adapter.dataaccess.ValueOverTimeCollectionDTO in project geoprism-registry by terraframe.

the class RegistryVersionTest method genericDuplicateDatatypeTest.

private void genericDuplicateDatatypeTest(String attributeName, Object value) throws ParseException {
    final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
    dateFormat.setTimeZone(GeoRegistryUtil.SYSTEM_TIMEZONE);
    // Initial Setup : Create a VOT with a large date range
    VertexServerGeoObject serverObj = (VertexServerGeoObject) FastTestDataset.PROV_CENTRAL.getServerObject();
    serverObj.getValuesOverTime(attributeName).clear();
    serverObj.setValue(attributeName, value, dateFormat.parse("1990-01-01"), dateFormat.parse("1990-02-01"));
    serverObj.apply(false);
    Assert.assertEquals(1, FastTestDataset.PROV_CENTRAL.getServerObject().getValuesOverTime(attributeName).size());
    // Set a value inside that date range with the same value
    VertexServerGeoObject serverObj2 = (VertexServerGeoObject) FastTestDataset.PROV_CENTRAL.getServerObject();
    serverObj2.setValue(attributeName, value, dateFormat.parse("1990-01-05"), dateFormat.parse("1990-01-10"));
    serverObj2.apply(false);
    // Fetch the object and assert values on it
    Assert.assertEquals(1, FastTestDataset.PROV_CENTRAL.getServerObject().getValuesOverTime(attributeName).size());
    GeoObjectOverTime goTime = testData.adapter.getGeoObjectOverTimeByCode(FastTestDataset.PROV_CENTRAL.getCode(), FastTestDataset.PROV_CENTRAL.getGeoObjectType().getCode());
    Assert.assertEquals(1, goTime.getAllValues(attributeName).size());
    ValueOverTimeCollectionDTO all = goTime.getAllValues(attributeName);
    Assert.assertEquals("1990-01-01", dateFormat.format(all.get(0).getStartDate()));
    Assert.assertEquals("1990-02-01", dateFormat.format(all.get(0).getEndDate()));
    Assert.assertTrue(value.equals(all.get(0).getValue()));
}
Also used : ValueOverTimeCollectionDTO(org.commongeoregistry.adapter.dataaccess.ValueOverTimeCollectionDTO) VertexServerGeoObject(net.geoprism.registry.model.graph.VertexServerGeoObject) GeoObjectOverTime(org.commongeoregistry.adapter.dataaccess.GeoObjectOverTime) SimpleDateFormat(java.text.SimpleDateFormat)

Aggregations

ValueOverTimeCollectionDTO (org.commongeoregistry.adapter.dataaccess.ValueOverTimeCollectionDTO)5 GeoObjectOverTime (org.commongeoregistry.adapter.dataaccess.GeoObjectOverTime)4 Geometry (com.vividsolutions.jts.geom.Geometry)3 SimpleDateFormat (java.text.SimpleDateFormat)3 EdgeObject (com.runwaysdk.business.graph.EdgeObject)2 GraphObject (com.runwaysdk.business.graph.GraphObject)2 VertexObject (com.runwaysdk.business.graph.VertexObject)2 AbstractClassification (com.runwaysdk.system.AbstractClassification)2 LineString (com.vividsolutions.jts.geom.LineString)2 MultiLineString (com.vividsolutions.jts.geom.MultiLineString)2 Classifier (net.geoprism.ontology.Classifier)2 AbstractServerGeoObject (net.geoprism.registry.model.AbstractServerGeoObject)2 Classification (net.geoprism.registry.model.Classification)2 AttributeGeometry (org.commongeoregistry.adapter.dataaccess.AttributeGeometry)2 GeoObject (org.commongeoregistry.adapter.dataaccess.GeoObject)2 ValueOverTimeDTO (org.commongeoregistry.adapter.dataaccess.ValueOverTimeDTO)2 AttributeClassificationType (org.commongeoregistry.adapter.metadata.AttributeClassificationType)2 AttributeTermType (org.commongeoregistry.adapter.metadata.AttributeTermType)2 AttributeType (org.commongeoregistry.adapter.metadata.AttributeType)2 Test (org.junit.Test)2