use of org.commongeoregistry.adapter.Term 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 org.commongeoregistry.adapter.Term in project geoprism-registry by terraframe.
the class XMLImporter method addAttributes.
private void addAttributes(Element root, ServerGeoObjectType type) {
NodeList attributeList = root.getElementsByTagName("attributes");
if (attributeList.getLength() > 0) {
NodeList nList = attributeList.item(0).getChildNodes();
for (int i = 0; i < nList.getLength(); i++) {
Node nNode = nList.item(i);
if (nNode.getNodeType() == Node.ELEMENT_NODE) {
Element elem = (Element) nNode;
String code = elem.getAttribute("code");
LocalizedValue label = this.getLabel(elem);
LocalizedValue description = this.getDescription(elem);
if (elem.getTagName().equals("text")) {
type.createAttributeType(new AttributeCharacterType(code, label, description, false, false, false));
} else if (elem.getTagName().equals("boolean")) {
type.createAttributeType(new AttributeBooleanType(code, label, description, false, false, false));
} else if (elem.getTagName().equals("integer")) {
type.createAttributeType(new AttributeIntegerType(code, label, description, false, false, false));
} else if (elem.getTagName().equals("decimal")) {
AttributeFloatType attributeType = new AttributeFloatType(code, label, description, false, false, false);
attributeType.setPrecision(this.getPrecision(elem));
attributeType.setScale(this.getScale(elem));
type.createAttributeType(attributeType);
} else if (elem.getTagName().equals("date")) {
type.createAttributeType(new AttributeDateType(code, label, description, false, false, false));
} else if (elem.getTagName().equals("term")) {
AttributeTermType attributeType = new AttributeTermType(code, label, description, false, false, false);
attributeType = (AttributeTermType) type.createAttributeType(attributeType);
Term rootTerm = attributeType.getRootTerm();
this.createTermOptions(elem, rootTerm);
} else if (elem.getTagName().equals("classification")) {
String rootCode = elem.getAttribute("root");
String classificationType = elem.getAttribute("classificationType");
AttributeClassificationType attributeType = new AttributeClassificationType(code, label, description, false, false, false);
attributeType.setRootTerm(new Term(rootCode, new LocalizedValue(""), new LocalizedValue("")));
attributeType.setClassificationType(classificationType);
attributeType = (AttributeClassificationType) type.createAttributeType(attributeType);
}
}
}
}
}
use of org.commongeoregistry.adapter.Term in project geoprism-registry by terraframe.
the class ConversionTest method testAttributeTypeTermTree.
// Heads up: clean up
// @Test
// public void testAttributeTypeCharacterLeaf()
// {
// String sessionId = testData.adminClientRequest.getSessionId();
//
// // Add a new custom attribute
// AttributeType testCharacter = AttributeType.factory("testCharacter", new LocalizedValue("testCharacterLocalName"), new LocalizedValue("testCharacterLocalDescrip"), AttributeCharacterType.TYPE, false, false, false);
// testCharacter = ServiceFactory.getRegistryService().createAttributeType(sessionId, USATestData.DISTRICT.getCode(), testCharacter.toJSON().toString());
//
// // Create a new GeoObject with the custom attribute
// GeoObject geoObj = ServiceFactory.getRegistryService().newGeoObjectInstance(sessionId, USATestData.DISTRICT.getCode());
// geoObj.setCode(testGo.getCode());
// geoObj.setDisplayLabel(LocalizedValue.DEFAULT_LOCALE, "Test Label");
// geoObj.setUid(ServiceFactory.getRegistryService().getUIDS(sessionId, 1)[0]);
// geoObj.setValue(testCharacter.getName(), "ABCZ");
//
// ServiceFactory.getRegistryService().createGeoObject(sessionId, geoObj.toJSON().toString());
//
// // Get the object with the custom attribute
// GeoObject result = ServiceFactory.getRegistryService().getGeoObjectByCode(sessionId, testGo.getCode(), USATestData.DISTRICT.getCode());
//
// Assert.assertNotNull(result);
// Assert.assertEquals(geoObj.getValue(testCharacter.getName()), result.getValue(testCharacter.getName()));
// }
@Test
@SuppressWarnings("unchecked")
public void testAttributeTypeTermTree() {
String sessionId = testData.clientRequest.getSessionId();
// Add a new custom attribute
AttributeTermType testTerm = (AttributeTermType) AttributeType.factory("testTerm", new LocalizedValue("testTermLocalName"), new LocalizedValue("testTermLocalDescrip"), AttributeTermType.TYPE, false, false, false);
testTerm = (AttributeTermType) ServiceFactory.getRegistryService().createAttributeType(sessionId, USATestData.STATE.getCode(), testTerm.toJSON().toString());
Term rootTerm = testTerm.getRootTerm();
Term term2 = new Term("termValue2", new LocalizedValue("Term Value 2"), new LocalizedValue(""));
Term term = ServiceFactory.getRegistryService().createTerm(sessionId, rootTerm.getCode(), term2.toJSON().toString());
TestDataSet.refreshTerms(testTerm);
try {
// Create a new GeoObject with the custom attribute
GeoObject geoObj = ServiceFactory.getRegistryService().newGeoObjectInstance(sessionId, USATestData.STATE.getCode());
geoObj.setCode(testGo.getCode());
geoObj.setDisplayLabel(LocalizedValue.DEFAULT_LOCALE, "Test Label");
geoObj.setUid(ServiceFactory.getRegistryService().getUIDS(sessionId, 1)[0]);
geoObj.setValue(testTerm.getName(), term.getCode());
ServiceFactory.getRegistryService().createGeoObject(sessionId, geoObj.toJSON().toString(), TestDataSet.DEFAULT_OVER_TIME_DATE, TestDataSet.DEFAULT_END_TIME_DATE);
// Get the object with the custom attribute
GeoObject result = ServiceFactory.getRegistryService().getGeoObjectByCode(sessionId, testGo.getCode(), USATestData.STATE.getCode(), TestDataSet.DEFAULT_OVER_TIME_DATE);
Assert.assertNotNull(result);
Iterator<String> expected = (Iterator<String>) geoObj.getValue(testTerm.getName());
Iterator<String> test = (Iterator<String>) result.getValue(testTerm.getName());
Assert.assertTrue(expected.hasNext());
Assert.assertTrue(test.hasNext());
Assert.assertEquals(expected.next(), test.next());
} finally {
ServiceFactory.getRegistryService().deleteTerm(sessionId, rootTerm.getCode(), term.getCode());
}
}
use of org.commongeoregistry.adapter.Term in project geoprism-registry by terraframe.
the class AttributeTypeServiceTest method testCreateGeoObjectTypeTerm.
@Test
public void testCreateGeoObjectTypeTerm() {
String organizationCode = FastTestDataset.ORG_CGOV.getCode();
GeoObjectType province = MetadataFactory.newGeoObjectType(TEST_GOT.getCode(), GeometryType.POLYGON, new LocalizedValue("Province"), new LocalizedValue(""), true, organizationCode, testData.adapter);
String geoObjectTypeCode = province.getCode();
AttributeTermType attributeTermType = (AttributeTermType) AttributeType.factory("testTerm", new LocalizedValue("Test Term Name"), new LocalizedValue("Test Term Description"), AttributeTermType.TYPE, false, false, false);
Term term = new Term(TEST_GOT.getCode() + "_" + "testTerm", new LocalizedValue("Test Term Name"), new LocalizedValue("Test Term Description"));
attributeTermType.setRootTerm(term);
province.addAttribute(attributeTermType);
String gtJSON = province.toJSON().toString();
testData.adapter.createGeoObjectType(gtJSON);
String attributeTypeJSON = attributeTermType.toJSON().toString();
attributeTermType = (AttributeTermType) testData.adapter.createAttributeType(geoObjectTypeCode, attributeTypeJSON);
MdAttributeDAOIF mdAttributeConcreteDAOIF = checkAttribute(TEST_GOT.getCode(), attributeTermType.getName());
Assert.assertNotNull("A GeoObjectType did not define the attribute: " + attributeTermType.getName(), mdAttributeConcreteDAOIF);
Assert.assertTrue("A GeoObjectType did not define the attribute of the correct type: " + mdAttributeConcreteDAOIF.getType(), mdAttributeConcreteDAOIF instanceof MdAttributeTermDAOIF);
Term rootTerm = attributeTermType.getRootTerm();
Term childTerm1 = new Term("termValue1", new LocalizedValue("Term Value 1"), new LocalizedValue(""));
Term childTerm2 = new Term("termValue2", new LocalizedValue("Term Value 2"), new LocalizedValue(""));
testData.adapter.createTerm(rootTerm.getCode(), childTerm1.toJSON().toString());
testData.adapter.createTerm(rootTerm.getCode(), childTerm2.toJSON().toString());
province = testData.adapter.getGeoObjectTypes(new String[] { TEST_GOT.getCode() }, null, PermissionContext.READ)[0];
AttributeTermType attributeTermType2 = (AttributeTermType) province.getAttribute("testTerm").get();
// Check to see if the cache was updated.
checkTermsCreate(attributeTermType2);
attributeTermType.setLabel(MdAttributeLocalInfo.DEFAULT_LOCALE, "Test Term Name Update");
attributeTermType.setDescription(MdAttributeLocalInfo.DEFAULT_LOCALE, "Test Term Description Update");
attributeTermType = (AttributeTermType) testData.adapter.updateAttributeType(geoObjectTypeCode, attributeTermType.toJSON().toString());
Assert.assertEquals(attributeTermType.getLabel().getValue(), "Test Term Name Update");
Assert.assertEquals(attributeTermType.getDescription().getValue(), "Test Term Description Update");
checkTermsCreate(attributeTermType);
// Test updating the term
childTerm2 = new Term("termValue2", new LocalizedValue("Term Value 2a"), new LocalizedValue(""));
testData.adapter.updateTerm(rootTerm.getCode(), childTerm2.toJSON().toString());
province = testData.adapter.getGeoObjectTypes(new String[] { TEST_GOT.getCode() }, null, PermissionContext.READ)[0];
AttributeTermType attributeTermType3 = (AttributeTermType) province.getAttribute("testTerm").get();
checkTermsUpdate(attributeTermType3);
testData.adapter.deleteTerm(rootTerm.getCode(), "termValue2");
province = testData.adapter.getGeoObjectTypes(new String[] { TEST_GOT.getCode() }, null, PermissionContext.READ)[0];
attributeTermType3 = (AttributeTermType) province.getAttribute("testTerm").get();
System.out.println(attributeTermType3.getRootTerm().toString());
checkTermsDelete(attributeTermType3);
}
use of org.commongeoregistry.adapter.Term in project geoprism-registry by terraframe.
the class ListType method getRestriction.
public BasicVertexRestriction getRestriction(ServerGeoObjectType type, Date forDate) {
String filterJson = this.getFilterJson();
if (filterJson != null && filterJson.length() > 0) {
JsonArray filters = JsonParser.parseString(filterJson).getAsJsonArray();
CompositeRestriction restriction = new CompositeRestriction();
for (int i = 0; i < filters.size(); i++) {
JsonObject filter = filters.get(i).getAsJsonObject();
String attributeName = filter.get("attribute").getAsString();
String operation = filter.get("operation").getAsString();
AttributeType attributeType = type.getAttribute(attributeName).get();
MdAttributeDAOIF mdAttribute = type.getMdVertex().definesAttribute(attributeName);
if (attributeType instanceof AttributeDateType) {
String value = filter.get("value").getAsString();
Date date = GeoRegistryUtil.parseDate(value, false);
restriction.add(new AttributeValueRestriction(mdAttribute, operation, date, forDate));
} else if (attributeType instanceof AttributeBooleanType) {
String value = filter.get("value").getAsString();
Boolean bVal = Boolean.valueOf(value);
restriction.add(new AttributeValueRestriction(mdAttribute, operation, bVal, forDate));
} else if (attributeType instanceof AttributeTermType) {
String code = filter.get("value").getAsString();
Term root = ((AttributeTermType) attributeType).getRootTerm();
String parent = TermConverter.buildClassifierKeyFromTermCode(root.getCode());
String classifierKey = Classifier.buildKey(parent, code);
Classifier classifier = Classifier.getByKey(classifierKey);
restriction.add(new AttributeValueRestriction(mdAttribute, operation, classifier.getOid(), forDate));
} else if (attributeType instanceof AttributeClassificationType) {
JsonObject object = filter.get("value").getAsJsonObject();
Term term = Term.fromJSON(object);
MdClassificationDAOIF mdClassification = ((MdAttributeClassificationDAOIF) mdAttribute).getMdClassificationDAOIF();
MdEdgeDAOIF mdEdge = mdClassification.getReferenceMdEdgeDAO();
ClassificationType classificationType = new ClassificationType(mdClassification);
Classification classification = Classification.get(classificationType, term.getCode());
restriction.add(new AttributeValueRestriction(mdAttribute, operation, classification.getVertex().getRID(), forDate));
} else {
String value = filter.get("value").getAsString();
restriction.add(new AttributeValueRestriction(mdAttribute, operation, value, forDate));
}
}
if (restriction.getRestrictions().size() > 0) {
return restriction;
}
}
return null;
}
Aggregations