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();
}
}
}
}
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();
}
}
}
}
}
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));
}
}
}
}
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());
}
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());
}
Aggregations