use of com.runwaysdk.dataaccess.MdAttributeTermDAOIF in project geoprism-registry by terraframe.
the class VertexServerGeoObject method getValue.
@Override
public Object getValue(String attributeName) {
if (attributeName.equals(DefaultAttribute.CODE.getName())) {
return this.getCode();
} else if (attributeName.equals(DefaultAttribute.UID.getName())) {
return this.getUid();
} else if (attributeName.equals(DefaultAttribute.DISPLAY_LABEL.getName())) {
return this.getDisplayLabel();
} else if (attributeName.equals(DefaultAttribute.CREATE_DATE.getName())) {
return this.getCreateDate();
} else if (attributeName.equals(DefaultAttribute.EXISTS.getName())) {
return this.getExists();
}
DefaultAttribute defaultAttr = DefaultAttribute.getByAttributeName(attributeName);
if (defaultAttr != null && !defaultAttr.isChangeOverTime()) {
return this.vertex.getObjectValue(attributeName);
}
MdAttributeConcreteDAOIF mdAttribute = this.vertex.getMdAttributeDAO(attributeName);
Object value = this.getMostRecentValue(attributeName);
if (value != null && mdAttribute instanceof MdAttributeTermDAOIF) {
return Classifier.get((String) value);
}
return value;
}
use of com.runwaysdk.dataaccess.MdAttributeTermDAOIF 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 com.runwaysdk.dataaccess.MdAttributeTermDAOIF in project geoprism-registry by terraframe.
the class AttributeTypeConverter method build.
public AttributeType build(MdAttributeConcreteDAOIF mdAttribute) {
Locale locale = Session.getCurrentLocale();
String attributeName = mdAttribute.definesAttribute();
LocalizedValue displayLabel = AttributeTypeConverter.convert(mdAttribute.getDisplayLabel(locale), mdAttribute.getDisplayLabels());
LocalizedValue description = AttributeTypeConverter.convert(mdAttribute.getDescription(locale), mdAttribute.getDescriptions());
boolean required = mdAttribute.isRequired();
boolean unique = mdAttribute.isUnique();
boolean isChangeOverTime = true;
DefaultAttribute defaultAttr = DefaultAttribute.getByAttributeName(attributeName);
if (defaultAttr != null) {
isChangeOverTime = defaultAttr.isChangeOverTime();
}
if (mdAttribute instanceof MdAttributeBooleanDAOIF) {
return AttributeType.factory(attributeName, displayLabel, description, AttributeBooleanType.TYPE, required, unique, isChangeOverTime);
} else if (mdAttribute instanceof MdAttributeLocalDAOIF) {
return AttributeType.factory(attributeName, displayLabel, description, AttributeLocalType.TYPE, required, unique, isChangeOverTime);
} else if (mdAttribute instanceof MdAttributeCharacterDAOIF) {
return AttributeType.factory(attributeName, displayLabel, description, AttributeCharacterType.TYPE, required, unique, isChangeOverTime);
} else if (mdAttribute instanceof MdAttributeDateDAOIF || mdAttribute instanceof MdAttributeDateTimeDAOIF) {
return AttributeType.factory(attributeName, displayLabel, description, AttributeDateType.TYPE, required, unique, isChangeOverTime);
} else if (mdAttribute instanceof MdAttributeDecDAOIF) {
MdAttributeDecDAOIF mdAttributeDec = (MdAttributeDecDAOIF) mdAttribute;
AttributeFloatType attributeType = (AttributeFloatType) AttributeType.factory(attributeName, displayLabel, description, AttributeFloatType.TYPE, required, unique, isChangeOverTime);
attributeType.setPrecision(Integer.parseInt(mdAttributeDec.getLength()));
attributeType.setScale(Integer.parseInt(mdAttributeDec.getDecimal()));
return attributeType;
} else if (mdAttribute instanceof MdAttributeIntegerDAOIF || mdAttribute instanceof MdAttributeLongDAOIF) {
return AttributeType.factory(attributeName, displayLabel, description, AttributeIntegerType.TYPE, required, unique, isChangeOverTime);
} else if (mdAttribute instanceof MdAttributeClassificationDAOIF) {
MdClassificationDAOIF mdClassification = ((MdAttributeClassificationDAOIF) mdAttribute).getMdClassificationDAOIF();
AttributeClassificationType attributeType = (AttributeClassificationType) AttributeType.factory(attributeName, displayLabel, description, AttributeClassificationType.TYPE, required, unique, isChangeOverTime);
attributeType.setClassificationType(mdClassification.getValue(MdClassificationInfo.TYPE_NAME));
String rootOid = ((MdAttributeClassificationDAOIF) mdAttribute).getValue(MdAttributeClassificationInfo.ROOT);
if (rootOid != null && rootOid.length() > 0) {
ClassificationType type = new ClassificationType(mdClassification);
Classification classification = Classification.getByOid(type, rootOid);
attributeType.setRootTerm(classification.toTerm());
}
return attributeType;
} else if (mdAttribute instanceof MdAttributeEnumerationDAOIF || mdAttribute instanceof MdAttributeTermDAOIF) {
AttributeTermType attributeType = (AttributeTermType) AttributeType.factory(attributeName, displayLabel, description, AttributeTermType.TYPE, required, unique, isChangeOverTime);
if (mdAttribute instanceof MdAttributeTermDAOIF) {
List<RelationshipDAOIF> rels = ((MdAttributeTermDAOIF) mdAttribute).getAllAttributeRoots();
if (rels.size() > 0) {
RelationshipDAOIF rel = rels.get(0);
BusinessDAO classy = (BusinessDAO) rel.getChild();
TermConverter termBuilder = new TermConverter(classy.getKey());
Term adapterTerm = termBuilder.build();
attributeType.setRootTerm(adapterTerm);
} else {
throw new ProgrammingErrorException("Expected an attribute root on MdAttribute [" + mdAttribute.getKey() + "].");
}
} else {
throw new ProgrammingErrorException("Enum attributes are not supported at this time.");
}
return attributeType;
}
throw new UnsupportedOperationException("Unsupported attribute type [" + mdAttribute.getClass().getSimpleName() + "]");
}
Aggregations