use of org.commongeoregistry.adapter.Term in project geoprism-registry by terraframe.
the class ServerGeoObjectType method updateMdAttributeFromAttributeType.
/**
* Creates an {@link MdAttributeConcrete} for the given {@link MdBusiness}
* from the given {@link AttributeType}
*
* @pre assumes no attribute has been defined on the type with the given name.
*
* @param mdBusiness
* Type to receive attribute definition
* @param attributeType
* newly defined attribute
*
* @return {@link AttributeType}
*/
@Transaction
public static MdAttributeConcrete updateMdAttributeFromAttributeType(MdClass mdClass, AttributeType attributeType) {
MdAttributeConcreteDAOIF mdAttributeConcreteDAOIF = getMdAttribute(mdClass, attributeType.getName());
if (mdAttributeConcreteDAOIF != null) {
// Get the type safe version
MdAttributeConcrete mdAttribute = (MdAttributeConcrete) BusinessFacade.get(mdAttributeConcreteDAOIF);
mdAttribute.lock();
try {
// The name cannot be updated
// mdAttribute.setAttributeName(attributeType.getName());
LocalizedValueConverter.populate(mdAttribute.getDisplayLabel(), attributeType.getLabel());
LocalizedValueConverter.populate(mdAttribute.getDescription(), attributeType.getDescription());
if (attributeType instanceof AttributeFloatType) {
// Refresh the terms
AttributeFloatType attributeFloatType = (AttributeFloatType) attributeType;
mdAttribute.setValue(MdAttributeDoubleInfo.LENGTH, Integer.toString(attributeFloatType.getPrecision()));
mdAttribute.setValue(MdAttributeDoubleInfo.DECIMAL, Integer.toString(attributeFloatType.getScale()));
} else if (attributeType instanceof AttributeClassificationType) {
MdAttributeClassification mdAttributeTerm = (MdAttributeClassification) mdAttribute;
AttributeClassificationType attributeClassificationType = (AttributeClassificationType) attributeType;
String classificationTypeCode = attributeClassificationType.getClassificationType();
ClassificationType classificationType = ClassificationType.getByCode(classificationTypeCode);
Term root = attributeClassificationType.getRootTerm();
if (root != null) {
Classification classification = Classification.get(classificationType, root.getCode());
mdAttributeTerm.setValue(MdAttributeClassification.ROOT, classification.getOid());
}
}
mdAttribute.apply();
} finally {
mdAttribute.unlock();
}
if (attributeType instanceof AttributeTermType) {
// Refresh the terms
AttributeTermType attributeTermType = (AttributeTermType) attributeType;
org.commongeoregistry.adapter.Term getRootTerm = attributeTermType.getRootTerm();
String classifierKey = TermConverter.buildClassifierKeyFromTermCode(getRootTerm.getCode());
TermConverter termBuilder = new TermConverter(classifierKey);
attributeTermType.setRootTerm(termBuilder.build());
}
return mdAttribute;
}
return null;
}
use of org.commongeoregistry.adapter.Term in project geoprism-registry by terraframe.
the class VertexServerGeoObject method populate.
@SuppressWarnings("unchecked")
@Override
public void populate(GeoObject geoObject, Date startDate, Date endDate) {
Map<String, AttributeType> attributes = geoObject.getType().getAttributeMap();
attributes.forEach((attributeName, attribute) -> {
if (attributeName.equals(DefaultAttribute.INVALID.getName()) || attributeName.equals(DefaultAttribute.EXISTS.getName()) || attributeName.equals(DefaultAttribute.DISPLAY_LABEL.getName()) || attributeName.equals(DefaultAttribute.CODE.getName()) || attributeName.equals(DefaultAttribute.UID.getName()) || attributeName.equals(GeoVertex.LASTUPDATEDATE) || attributeName.equals(GeoVertex.CREATEDATE)) {
// Ignore the attributes
} else if (this.vertex.hasAttribute(attributeName) && !this.vertex.getMdAttributeDAO(attributeName).isSystem()) {
if (attribute instanceof AttributeTermType) {
Iterator<String> it = (Iterator<String>) geoObject.getValue(attributeName);
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(), startDate, endDate);
} else {
this.vertex.setValue(attributeName, (String) null, startDate, endDate);
}
} else if (attribute instanceof AttributeClassificationType) {
String value = (String) geoObject.getValue(attributeName);
if (value != null) {
Classification classification = Classification.get((AttributeClassificationType) attribute, value);
this.vertex.setValue(attributeName, classification.getVertex(), startDate, endDate);
} else {
this.vertex.setValue(attributeName, (String) null, startDate, endDate);
}
} else {
Object value = geoObject.getValue(attributeName);
if (value != null) {
this.vertex.setValue(attributeName, value, startDate, endDate);
} else {
this.vertex.setValue(attributeName, (String) null, startDate, endDate);
}
}
}
});
this.setInvalid(geoObject.getInvalid());
this.setUid(geoObject.getUid());
this.setCode(geoObject.getCode());
this.setExists(geoObject.getExists(), startDate, endDate);
this.setDisplayLabel(geoObject.getDisplayLabel(), startDate, endDate);
this.setGeometry(geoObject.getGeometry(), startDate, endDate);
}
use of org.commongeoregistry.adapter.Term in project geoprism-registry by terraframe.
the class RegistryService method createTerm.
/**
* Creates a new {@link Term} object and makes it a child of the term with the
* given code.
*
* @param sessionId
* @param parentTemCode
* The code of the parent [@link Term}.
* @param termJSON
* JSON of the term object.
*
* @return Newly created {@link Term} object.
*/
@Request(RequestType.SESSION)
public Term createTerm(String sessionId, String parentTermCode, String termJSON) {
JsonObject termJSONobj = JsonParser.parseString(termJSON).getAsJsonObject();
LocalizedValue label = LocalizedValue.fromJSON(termJSONobj.get(Term.JSON_LOCALIZED_LABEL).getAsJsonObject());
Term term = new Term(termJSONobj.get(Term.JSON_CODE).getAsString(), label, new LocalizedValue(""));
Classifier classifier = TermConverter.createClassifierFromTerm(parentTermCode, term);
TermConverter termBuilder = new TermConverter(classifier.getKeyName());
Term returnTerm = termBuilder.build();
List<MdAttributeConcrete> mdAttrList = this.findRootClassifier(classifier);
this.refreshAttributeTermTypeInCache(mdAttrList);
return returnTerm;
}
use of org.commongeoregistry.adapter.Term in project geoprism-registry by terraframe.
the class XMLImporter method createTermOptions.
private void createTermOptions(Element attributeNode, Term root) {
NodeList attributeList = attributeNode.getElementsByTagName("option");
for (int i = 0; i < attributeList.getLength(); i++) {
Node nNode = attributeList.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);
Term term = new Term(code, label, description);
Classifier classifier = TermConverter.createClassifierFromTerm(root.getCode(), term);
TermConverter termBuilder = new TermConverter(classifier.getKeyName());
termBuilder.build();
}
}
}
use of org.commongeoregistry.adapter.Term in project geoprism-registry by terraframe.
the class XMLImporterTest method testImport.
@Request
@Test
public void testImport() throws IOException {
Organization organization = new Organization();
organization.setCode("TEST_ORG");
organization.getDisplayLabel().setValue("Test Org");
organization.apply();
try (InputStream istream = this.getClass().getResourceAsStream("/xml/test-domain.xml")) {
XMLImporter xmlImporter = new XMLImporter();
List<ServerElement> results = xmlImporter.importXMLDefinitions(organization, istream);
try {
RegistryService.getInstance().refreshMetadataCache();
Assert.assertEquals(4, results.size());
ServerGeoObjectType type = ServerGeoObjectType.get(results.get(0).getCode());
Assert.assertEquals("TEST_VILLAGE", type.getCode());
Assert.assertEquals("Test Village", type.getLabel().getValue(LocalizedValue.DEFAULT_LOCALE));
Assert.assertEquals(GeometryType.MULTIPOINT, type.getGeometryType());
Assert.assertFalse(type.getIsPrivate());
Assert.assertFalse(type.isGeometryEditable());
Assert.assertTrue(type.getIsAbstract());
Optional<AttributeType> oattribute = type.getAttribute("TEST_TEXT");
Assert.assertTrue(oattribute.isPresent());
AttributeType attributeType = oattribute.get();
Assert.assertEquals("Test Text", attributeType.getLabel().getValue(LocalizedValue.DEFAULT_LOCALE));
Assert.assertEquals("Test Text Description", attributeType.getDescription().getValue(LocalizedValue.DEFAULT_LOCALE));
oattribute = type.getAttribute("TEST_BOOLEAN");
Assert.assertTrue(oattribute.isPresent());
attributeType = oattribute.get();
Assert.assertEquals("Test Boolean", attributeType.getLabel().getValue(LocalizedValue.DEFAULT_LOCALE));
Assert.assertEquals("Test Boolean Description", attributeType.getDescription().getValue(LocalizedValue.DEFAULT_LOCALE));
oattribute = type.getAttribute("TEST_INTEGER");
Assert.assertTrue(oattribute.isPresent());
attributeType = oattribute.get();
Assert.assertEquals("Test Integer", attributeType.getLabel().getValue(LocalizedValue.DEFAULT_LOCALE));
Assert.assertEquals("Test Integer Description", attributeType.getDescription().getValue(LocalizedValue.DEFAULT_LOCALE));
oattribute = type.getAttribute("TEST_DATE");
Assert.assertTrue(oattribute.isPresent());
attributeType = oattribute.get();
Assert.assertEquals("Test Date", attributeType.getLabel().getValue(LocalizedValue.DEFAULT_LOCALE));
Assert.assertEquals("Test Date Description", attributeType.getDescription().getValue(LocalizedValue.DEFAULT_LOCALE));
oattribute = type.getAttribute("TEST_DECIMAL");
Assert.assertTrue(oattribute.isPresent());
attributeType = oattribute.get();
Assert.assertEquals("Test Decimal", attributeType.getLabel().getValue(LocalizedValue.DEFAULT_LOCALE));
Assert.assertEquals("Test Decimal Description", attributeType.getDescription().getValue(LocalizedValue.DEFAULT_LOCALE));
oattribute = type.getAttribute("TEST_TERM");
Assert.assertTrue(oattribute.isPresent());
attributeType = oattribute.get();
Assert.assertEquals("Test Term", attributeType.getLabel().getValue(LocalizedValue.DEFAULT_LOCALE));
Assert.assertEquals("Test Term Description", attributeType.getDescription().getValue(LocalizedValue.DEFAULT_LOCALE));
List<Term> terms = ((AttributeTermType) attributeType).getTerms();
Assert.assertEquals(3, terms.size());
oattribute = type.getAttribute("TEST_CLASSIFICATION");
Assert.assertTrue(oattribute.isPresent());
attributeType = oattribute.get();
Assert.assertEquals("Test Classification", attributeType.getLabel().getValue(LocalizedValue.DEFAULT_LOCALE));
Assert.assertEquals("Test Text Classification", attributeType.getDescription().getValue(LocalizedValue.DEFAULT_LOCALE));
Assert.assertEquals("TEST_PROG", ((AttributeClassificationType) attributeType).getClassificationType());
Assert.assertEquals(ROOT_CODE, ((AttributeClassificationType) attributeType).getRootTerm().getCode());
type = ServerGeoObjectType.get(results.get(1).getCode());
Assert.assertEquals("TEST_GI", type.getCode());
Assert.assertEquals("Test GI", type.getLabel().getValue(LocalizedValue.DEFAULT_LOCALE));
Assert.assertEquals(GeometryType.MULTIPOINT, type.getGeometryType());
Assert.assertFalse(type.getIsPrivate());
Assert.assertFalse(type.isGeometryEditable());
Assert.assertFalse(type.getIsAbstract());
Assert.assertEquals("TEST_VILLAGE", type.getSuperType().getCode());
ServerHierarchyType hierarchy = ServerHierarchyType.get(results.get(3).getCode());
Assert.assertEquals("TEST_HIERARCHY", hierarchy.getCode());
Assert.assertEquals("Test Hierarchy", hierarchy.getDisplayLabel().getValue(LocalizedValue.DEFAULT_LOCALE));
Assert.assertEquals("Test Hierarchy Description", hierarchy.getDescription().getValue(LocalizedValue.DEFAULT_LOCALE));
Assert.assertEquals("Test Progress", hierarchy.getProgress());
Assert.assertEquals("Test Disclaimer", hierarchy.getDisclaimer());
Assert.assertEquals("Test Access Constraints", hierarchy.getAccessConstraints());
Assert.assertEquals("Test Use Constraints", hierarchy.getUseConstraints());
Assert.assertEquals("Test Acknowledgement", hierarchy.getAcknowledgement());
List<HierarchyNode> nodes = hierarchy.getRootGeoObjectTypes();
Assert.assertEquals(1, nodes.size());
HierarchyNode node = nodes.get(0);
Assert.assertEquals("TEST_DISTRICT", node.getGeoObjectType().getCode());
nodes = node.getChildren();
Assert.assertEquals(1, nodes.size());
node = nodes.get(0);
Assert.assertEquals("TEST_VILLAGE", node.getGeoObjectType().getCode());
} finally {
Collections.reverse(results);
for (ServerElement result : results) {
result.delete();
}
}
} finally {
organization.delete();
}
}
Aggregations