Search in sources :

Example 6 with ValueOverTime

use of com.runwaysdk.dataaccess.graph.attributes.ValueOverTime in project geoprism-registry by terraframe.

the class SearchService method insert.

// @Transaction
public void insert(VertexServerGeoObject object) {
    this.remove(object.getCode());
    String suffix = this.getSuffix();
    MdVertexDAOIF mdVertex = MdVertexDAO.getMdVertexDAO(PACKAGE + "." + VERTEX_PREFIX + suffix);
    MdEdgeDAOIF mdEdge = MdEdgeDAO.getMdEdgeDAO(PACKAGE + "." + EDGE_PREFIX + suffix);
    ValueOverTimeCollection vots = object.getValuesOverTime(DefaultAttribute.DISPLAY_LABEL.getName());
    for (ValueOverTime vot : vots) {
        VertexObjectDAOIF value = (VertexObjectDAOIF) vot.getValue();
        Set<String> attributeNames = LocalizationService.getLocaleNames();
        for (String attributeName : attributeNames) {
            String label = value.getObjectValue(attributeName);
            if (label != null && label.length() > 0) {
                VertexObject vertex = new VertexObject(mdVertex.definesType());
                vertex.setValue(START_DATE, vot.getStartDate());
                vertex.setValue(END_DATE, vot.getEndDate());
                vertex.setValue(CODE, object.getCode());
                vertex.setValue(LABEL, label);
                vertex.setValue(VERTEX_TYPE, object.getType().getCode());
                vertex.apply();
                vertex.addChild(object.getVertex(), mdEdge).apply();
            }
        }
    }
}
Also used : MdVertexDAOIF(com.runwaysdk.dataaccess.MdVertexDAOIF) ValueOverTime(com.runwaysdk.dataaccess.graph.attributes.ValueOverTime) MdEdgeDAOIF(com.runwaysdk.dataaccess.MdEdgeDAOIF) VertexObjectDAOIF(com.runwaysdk.dataaccess.graph.VertexObjectDAOIF) VertexObject(com.runwaysdk.business.graph.VertexObject) ValueOverTimeCollection(com.runwaysdk.dataaccess.graph.attributes.ValueOverTimeCollection)

Example 7 with ValueOverTime

use of com.runwaysdk.dataaccess.graph.attributes.ValueOverTime in project geoprism-registry by terraframe.

the class UpdateChangeOverTimeAttributeView method validateValuesOverTime.

public void validateValuesOverTime(ValueOverTimeCollection votc) {
    for (ValueOverTime vot : votc) {
        if (vot.getStartDate() == null) {
            throw new InvalidChangeRequestException();
        }
        if (vot.getEndDate() == null) {
            vot.setEndDate(ValueOverTime.INFINITY_END_DATE);
        }
        if (vot.getStartDate().after(vot.getEndDate())) {
            throw new InvalidChangeRequestException();
        }
    }
    for (ValueOverTime vot : votc) {
        Date s1 = vot.getStartDate();
        Date e1 = vot.getEndDate();
        for (ValueOverTime vot2 : votc) {
            if (vot != vot2) {
                Date s2 = vot2.getStartDate();
                Date e2 = vot2.getEndDate();
                if (this.dateRangeOverlaps(s1.getTime(), e1.getTime(), s2.getTime(), e2.getTime())) {
                    throw new InvalidChangeRequestException();
                }
            }
        }
    }
}
Also used : ValueOverTime(com.runwaysdk.dataaccess.graph.attributes.ValueOverTime) InvalidChangeRequestException(net.geoprism.registry.action.InvalidChangeRequestException) Date(java.util.Date)

Example 8 with ValueOverTime

use of com.runwaysdk.dataaccess.graph.attributes.ValueOverTime in project geoprism-registry by terraframe.

the class UpdateValueOverTimeView method persistValue.

private void persistValue(ValueOverTime vot, UpdateChangeOverTimeAttributeView cotView, VertexServerGeoObject go, List<ValueOverTime> looseVotc) {
    if (this.newValue == null) {
        return;
    }
    if (cotView.getAttributeName().equals("geometry")) {
        Geometry convertedValue = null;
        if (!this.newValue.isJsonNull()) {
            GeoJSONReader reader = new GeoJSONReader();
            convertedValue = reader.read(this.newValue.toString());
            if (!go.isValidGeometry(convertedValue)) {
                GeometryTypeException ex = new GeometryTypeException();
                ex.setActualType(convertedValue.getGeometryType());
                ex.setExpectedType(go.getType().getGeometryType().name());
                throw ex;
            }
        }
        if (vot != null) {
            vot.setValue(convertedValue);
        } else {
            looseVotc.add(new ValueOverTime(this.newStartDate, this.newEndDate, convertedValue));
        }
    } else {
        ServerGeoObjectType type = go.getType();
        AttributeType attype = type.getAttribute(cotView.getAttributeName()).get();
        if (attype instanceof AttributeLocalType) {
            LocalizedValue convertedValue = null;
            if (!this.newValue.isJsonNull()) {
                convertedValue = LocalizedValue.fromJSON(this.newValue.getAsJsonObject());
            }
            final Set<Locale> locales = LocalizationFacade.getInstalledLocales();
            if (vot != null) {
                if (convertedValue != null) {
                    GraphObjectDAO votEmbeddedValue = (GraphObjectDAO) vot.getValue();
                    votEmbeddedValue.setValue(MdAttributeLocalInfo.DEFAULT_LOCALE, convertedValue.getValue(MdAttributeLocalInfo.DEFAULT_LOCALE));
                    for (Locale locale : locales) {
                        if (convertedValue.contains(locale)) {
                            votEmbeddedValue.setValue(locale.toString(), convertedValue.getValue(locale));
                        }
                    }
                } else {
                    vot.setValue(null);
                }
            } else {
                if (convertedValue != null) {
                    MdAttributeEmbeddedDAOIF mdAttrEmbedded = (MdAttributeEmbeddedDAOIF) go.getMdAttributeDAO(attype.getName());
                    VertexObjectDAO votEmbeddedValue = VertexObjectDAO.newInstance((MdVertexDAOIF) mdAttrEmbedded.getEmbeddedMdClassDAOIF());
                    votEmbeddedValue.setValue(MdAttributeLocalInfo.DEFAULT_LOCALE, convertedValue.getValue(MdAttributeLocalInfo.DEFAULT_LOCALE));
                    for (Locale locale : locales) {
                        if (convertedValue.contains(locale)) {
                            votEmbeddedValue.setValue(locale.toString(), convertedValue.getValue(locale));
                        }
                    }
                    looseVotc.add(new ValueOverTime(this.newStartDate, this.newEndDate, votEmbeddedValue));
                } else {
                    looseVotc.add(new ValueOverTime(this.newStartDate, this.newEndDate, null));
                }
            }
        } else // else if (attype.getName().equals(DefaultAttribute.EXISTS.getName()))
        // {
        // if (this.newValue.isJsonNull())
        // {
        // if (vot != null)
        // {
        // vot.setValue(null);
        // }
        // else
        // {
        // looseVotc.add(new ValueOverTime(this.newStartDate, this.newEndDate,
        // null));
        // }
        // }
        // else
        // {
        // JsonArray ja = this.newValue.getAsJsonArray();
        // 
        // if (ja.size() > 0)
        // {
        // String code = ja.get(0).getAsString();
        // 
        // if (code == null || code.length() == 0)
        // {
        // if (vot != null)
        // {
        // vot.setValue(null);
        // }
        // else
        // {
        // looseVotc.add(new ValueOverTime(this.newStartDate, this.newEndDate,
        // null));
        // }
        // }
        // else
        // {
        // Term value = ( (AttributeTermType) attype ).getTermByCode(code).get();
        // GeoObjectStatus gos =
        // ConversionService.getInstance().termToGeoObjectStatus(value);
        // 
        // if (vot != null)
        // {
        // vot.setValue(gos.getOid());
        // }
        // else
        // {
        // looseVotc.add(new ValueOverTime(this.newStartDate, this.newEndDate,
        // gos.getOid()));
        // }
        // }
        // }
        // }
        // }
        {
            Object convertedValue = null;
            if (!this.newValue.isJsonNull()) {
                if (attype instanceof AttributeDateType) {
                    long epoch = this.newValue.getAsLong();
                    convertedValue = new Date(epoch);
                } else if (attype instanceof AttributeTermType) {
                    JsonArray ja = this.newValue.getAsJsonArray();
                    if (ja.size() > 0) {
                        String code = ja.get(0).getAsString();
                        Term root = ((AttributeTermType) attype).getRootTerm();
                        String parent = TermConverter.buildClassifierKeyFromTermCode(root.getCode());
                        String classifierKey = Classifier.buildKey(parent, code);
                        Classifier classifier = Classifier.getByKey(classifierKey);
                        convertedValue = classifier.getOid();
                    }
                } else if (attype instanceof AttributeClassificationType) {
                    JsonObject object = this.newValue.getAsJsonObject();
                    String code = object.get("code").getAsString();
                    Classification classification = Classification.get((AttributeClassificationType) attype, code);
                    convertedValue = new AttributeGraphRef.ID(classification.getOid(), classification.getVertex().getRID());
                } else if (attype instanceof AttributeBooleanType) {
                    convertedValue = this.newValue.getAsBoolean();
                } else if (attype instanceof AttributeFloatType) {
                    convertedValue = this.newValue.getAsDouble();
                } else if (attype instanceof AttributeIntegerType) {
                    convertedValue = this.newValue.getAsLong();
                } else {
                    convertedValue = this.newValue.getAsString();
                }
            }
            if (vot != null) {
                vot.setValue(convertedValue);
            } else {
                looseVotc.add(new ValueOverTime(this.newStartDate, this.newEndDate, convertedValue));
            }
        }
    }
}
Also used : Locale(java.util.Locale) AttributeIntegerType(org.commongeoregistry.adapter.metadata.AttributeIntegerType) JsonObject(com.google.gson.JsonObject) Classifier(net.geoprism.ontology.Classifier) AttributeDateType(org.commongeoregistry.adapter.metadata.AttributeDateType) AttributeFloatType(org.commongeoregistry.adapter.metadata.AttributeFloatType) AttributeGraphRef(com.runwaysdk.dataaccess.graph.attributes.AttributeGraphRef) LocalizedValue(org.commongeoregistry.adapter.dataaccess.LocalizedValue) AttributeType(org.commongeoregistry.adapter.metadata.AttributeType) Classification(net.geoprism.registry.model.Classification) AttributeBooleanType(org.commongeoregistry.adapter.metadata.AttributeBooleanType) ServerGeoObjectType(net.geoprism.registry.model.ServerGeoObjectType) MdAttributeEmbeddedDAOIF(com.runwaysdk.dataaccess.MdAttributeEmbeddedDAOIF) GeometryTypeException(net.geoprism.registry.GeometryTypeException) Term(org.commongeoregistry.adapter.Term) AttributeClassificationType(org.commongeoregistry.adapter.metadata.AttributeClassificationType) Date(java.util.Date) Geometry(com.vividsolutions.jts.geom.Geometry) JsonArray(com.google.gson.JsonArray) ValueOverTime(com.runwaysdk.dataaccess.graph.attributes.ValueOverTime) AttributeLocalType(org.commongeoregistry.adapter.metadata.AttributeLocalType) GeoJSONReader(org.wololo.jts2geojson.GeoJSONReader) GraphObjectDAO(com.runwaysdk.dataaccess.graph.GraphObjectDAO) VertexObjectDAO(com.runwaysdk.dataaccess.graph.VertexObjectDAO) JsonObject(com.google.gson.JsonObject) VertexServerGeoObject(net.geoprism.registry.model.graph.VertexServerGeoObject) AttributeTermType(org.commongeoregistry.adapter.metadata.AttributeTermType)

Example 9 with ValueOverTime

use of com.runwaysdk.dataaccess.graph.attributes.ValueOverTime in project geoprism-registry by terraframe.

the class ChangeRequestServiceTest method testComplexUpdateGeoObjectCR_Verify.

@Request
private void testComplexUpdateGeoObjectCR_Verify(String[] data) throws Exception {
    final String oldOid = data[1];
    final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    sdf.setTimeZone(GeoRegistryUtil.SYSTEM_TIMEZONE);
    final Date newStartDate = sdf.parse(NEW_START_DATE);
    final Date newEndDate = sdf.parse(NEW_END_DATE);
    final Date oldStartDate = sdf.parse(OLD_START_DATE);
    final Date oldEndDate = sdf.parse(OLD_END_DATE);
    ChangeRequestQuery crq = new ChangeRequestQuery(new QueryFactory());
    Assert.assertEquals(1, crq.getCount());
    ChangeRequest cr = crq.getIterator().next();
    Assert.assertEquals(AllGovernanceStatus.ACCEPTED.name(), cr.getGovernanceStatus().name());
    AbstractAction action = cr.getAllAction().next();
    Assert.assertTrue(action instanceof UpdateAttributeAction);
    Assert.assertEquals(FastTestDataset.CAMBODIA.getCode(), cr.getGeoObjectCode());
    Assert.assertEquals(FastTestDataset.CAMBODIA.getGeoObjectType().getCode(), cr.getGeoObjectTypeCode());
    Assert.assertEquals(FastTestDataset.ORG_CGOV.getCode(), cr.getOrganizationCode());
    ServerGeoObjectIF cambodia = FastTestDataset.CAMBODIA.getServerObject();
    ValueOverTimeCollection votc = cambodia.getValuesOverTime(FastTestDataset.AT_National_Anthem.getAttributeName());
    Assert.assertEquals(2, votc.size());
    ValueOverTime vot1 = votc.get(0);
    Assert.assertNotNull(vot1.getOid());
    Assert.assertTrue(!(vot1.getOid().equals(oldOid)));
    Assert.assertEquals(NEW_ANTHEM, vot1.getValue());
    Assert.assertEquals(oldStartDate, vot1.getStartDate());
    Assert.assertEquals(oldEndDate, vot1.getEndDate());
    ValueOverTime vot2 = votc.get(1);
    Assert.assertNotNull(vot2.getOid());
    Assert.assertTrue(!(vot2.getOid().equals(oldOid)));
    Assert.assertEquals(NEW_ANTHEM, vot2.getValue());
    Assert.assertEquals(newStartDate, vot2.getStartDate());
    Assert.assertEquals(newEndDate, vot2.getEndDate());
}
Also used : ValueOverTime(com.runwaysdk.dataaccess.graph.attributes.ValueOverTime) QueryFactory(com.runwaysdk.query.QueryFactory) ServerGeoObjectIF(net.geoprism.registry.model.ServerGeoObjectIF) ChangeRequestQuery(net.geoprism.registry.action.ChangeRequestQuery) ValueOverTimeCollection(com.runwaysdk.dataaccess.graph.attributes.ValueOverTimeCollection) ChangeRequest(net.geoprism.registry.action.ChangeRequest) SimpleDateFormat(java.text.SimpleDateFormat) AbstractAction(net.geoprism.registry.action.AbstractAction) UpdateAttributeAction(net.geoprism.registry.action.geoobject.UpdateAttributeAction) Date(java.util.Date) Request(com.runwaysdk.session.Request) ChangeRequest(net.geoprism.registry.action.ChangeRequest)

Example 10 with ValueOverTime

use of com.runwaysdk.dataaccess.graph.attributes.ValueOverTime in project geoprism-registry by terraframe.

the class ChangeRequestServiceTest method testUpdateGeoObjectLocalizedValueCR_Verify.

@Request
private void testUpdateGeoObjectLocalizedValueCR_Verify(String[] data) throws Exception {
    final String oldOid = data[1];
    final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    sdf.setTimeZone(GeoRegistryUtil.SYSTEM_TIMEZONE);
    final Date newStartDate = sdf.parse(NEW_START_DATE);
    final Date newEndDate = sdf.parse(NEW_END_DATE);
    ChangeRequestQuery crq = new ChangeRequestQuery(new QueryFactory());
    Assert.assertEquals(1, crq.getCount());
    ChangeRequest cr = crq.getIterator().next();
    Assert.assertEquals(AllGovernanceStatus.ACCEPTED.name(), cr.getGovernanceStatus().name());
    AbstractAction action = cr.getAllAction().next();
    Assert.assertTrue(action instanceof UpdateAttributeAction);
    Assert.assertEquals(FastTestDataset.CAMBODIA.getCode(), cr.getGeoObjectCode());
    Assert.assertEquals(FastTestDataset.CAMBODIA.getGeoObjectType().getCode(), cr.getGeoObjectTypeCode());
    Assert.assertEquals(FastTestDataset.ORG_CGOV.getCode(), cr.getOrganizationCode());
    VertexServerGeoObject cambodia = (VertexServerGeoObject) FastTestDataset.CAMBODIA.getServerObject();
    ValueOverTimeCollection votc = cambodia.getValuesOverTime(DefaultAttribute.DISPLAY_LABEL.getName());
    Assert.assertEquals(1, votc.size());
    ValueOverTime vot1 = votc.get(0);
    Assert.assertNotNull(vot1.getOid());
    Assert.assertEquals(oldOid, vot1.getOid());
    Assert.assertEquals(newStartDate, vot1.getStartDate());
    Assert.assertEquals(newEndDate, vot1.getEndDate());
    Assert.assertEquals("localizeTest", cambodia.getDisplayLabel(newStartDate).getValue());
}
Also used : ValueOverTime(com.runwaysdk.dataaccess.graph.attributes.ValueOverTime) QueryFactory(com.runwaysdk.query.QueryFactory) ChangeRequestQuery(net.geoprism.registry.action.ChangeRequestQuery) ValueOverTimeCollection(com.runwaysdk.dataaccess.graph.attributes.ValueOverTimeCollection) VertexServerGeoObject(net.geoprism.registry.model.graph.VertexServerGeoObject) ChangeRequest(net.geoprism.registry.action.ChangeRequest) SimpleDateFormat(java.text.SimpleDateFormat) AbstractAction(net.geoprism.registry.action.AbstractAction) UpdateAttributeAction(net.geoprism.registry.action.geoobject.UpdateAttributeAction) Date(java.util.Date) Request(com.runwaysdk.session.Request) ChangeRequest(net.geoprism.registry.action.ChangeRequest)

Aggregations

ValueOverTime (com.runwaysdk.dataaccess.graph.attributes.ValueOverTime)44 ValueOverTimeCollection (com.runwaysdk.dataaccess.graph.attributes.ValueOverTimeCollection)29 Request (com.runwaysdk.session.Request)26 Date (java.util.Date)22 ServerGeoObjectIF (net.geoprism.registry.model.ServerGeoObjectIF)18 Test (org.junit.Test)16 EdgeObject (com.runwaysdk.business.graph.EdgeObject)10 ChangeRequest (net.geoprism.registry.action.ChangeRequest)10 VertexServerGeoObject (net.geoprism.registry.model.graph.VertexServerGeoObject)10 VertexObject (com.runwaysdk.business.graph.VertexObject)9 UpdateAttributeAction (net.geoprism.registry.action.geoobject.UpdateAttributeAction)9 MdVertexDAOIF (com.runwaysdk.dataaccess.MdVertexDAOIF)8 ServerGeoObjectType (net.geoprism.registry.model.ServerGeoObjectType)8 SimpleDateFormat (java.text.SimpleDateFormat)6 AbstractAction (net.geoprism.registry.action.AbstractAction)6 JsonArray (com.google.gson.JsonArray)5 JsonObject (com.google.gson.JsonObject)5 QueryFactory (com.runwaysdk.query.QueryFactory)5 TreeSet (java.util.TreeSet)5 ChangeRequestQuery (net.geoprism.registry.action.ChangeRequestQuery)5