Search in sources :

Example 6 with MdAttributeTermDAOIF

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;
}
Also used : MdAttributeTermDAOIF(com.runwaysdk.dataaccess.MdAttributeTermDAOIF) GeoObject(org.commongeoregistry.adapter.dataaccess.GeoObject) VertexObject(com.runwaysdk.business.graph.VertexObject) EdgeObject(com.runwaysdk.business.graph.EdgeObject) AbstractServerGeoObject(net.geoprism.registry.model.AbstractServerGeoObject) GraphObject(com.runwaysdk.business.graph.GraphObject) DefaultAttribute(org.commongeoregistry.adapter.constants.DefaultAttribute) MdAttributeConcreteDAOIF(com.runwaysdk.dataaccess.MdAttributeConcreteDAOIF)

Example 7 with MdAttributeTermDAOIF

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);
}
Also used : LocalizedValue(org.commongeoregistry.adapter.dataaccess.LocalizedValue) ServerGeoObjectType(net.geoprism.registry.model.ServerGeoObjectType) GeoObjectType(org.commongeoregistry.adapter.metadata.GeoObjectType) MdAttributeDAOIF(com.runwaysdk.dataaccess.MdAttributeDAOIF) MdAttributeTermDAOIF(com.runwaysdk.dataaccess.MdAttributeTermDAOIF) Term(org.commongeoregistry.adapter.Term) AttributeTermType(org.commongeoregistry.adapter.metadata.AttributeTermType) Test(org.junit.Test) ClassificationTypeTest(net.geoprism.registry.classification.ClassificationTypeTest)

Example 8 with MdAttributeTermDAOIF

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() + "]");
}
Also used : Locale(java.util.Locale) AttributeFloatType(org.commongeoregistry.adapter.metadata.AttributeFloatType) MdClassificationDAOIF(com.runwaysdk.dataaccess.MdClassificationDAOIF) RelationshipDAOIF(com.runwaysdk.dataaccess.RelationshipDAOIF) LocalizedValue(org.commongeoregistry.adapter.dataaccess.LocalizedValue) MdAttributeEnumerationDAOIF(com.runwaysdk.dataaccess.MdAttributeEnumerationDAOIF) MdAttributeLongDAOIF(com.runwaysdk.dataaccess.MdAttributeLongDAOIF) MdAttributeIntegerDAOIF(com.runwaysdk.dataaccess.MdAttributeIntegerDAOIF) Classification(net.geoprism.registry.model.Classification) MdAttributeTermDAOIF(com.runwaysdk.dataaccess.MdAttributeTermDAOIF) List(java.util.List) MdAttributeBooleanDAOIF(com.runwaysdk.dataaccess.MdAttributeBooleanDAOIF) BusinessDAO(com.runwaysdk.dataaccess.BusinessDAO) MdAttributeDateTimeDAOIF(com.runwaysdk.dataaccess.MdAttributeDateTimeDAOIF) Term(org.commongeoregistry.adapter.Term) AttributeClassificationType(org.commongeoregistry.adapter.metadata.AttributeClassificationType) AttributeClassificationType(org.commongeoregistry.adapter.metadata.AttributeClassificationType) ClassificationType(net.geoprism.registry.model.ClassificationType) ProgrammingErrorException(com.runwaysdk.dataaccess.ProgrammingErrorException) MdAttributeLocalDAOIF(com.runwaysdk.dataaccess.MdAttributeLocalDAOIF) MdAttributeDecDAOIF(com.runwaysdk.dataaccess.MdAttributeDecDAOIF) DefaultAttribute(org.commongeoregistry.adapter.constants.DefaultAttribute) MdAttributeClassificationDAOIF(com.runwaysdk.dataaccess.MdAttributeClassificationDAOIF) MdAttributeDateDAOIF(com.runwaysdk.dataaccess.MdAttributeDateDAOIF) AttributeTermType(org.commongeoregistry.adapter.metadata.AttributeTermType) MdAttributeCharacterDAOIF(com.runwaysdk.dataaccess.MdAttributeCharacterDAOIF)

Aggregations

MdAttributeTermDAOIF (com.runwaysdk.dataaccess.MdAttributeTermDAOIF)8 MdAttributeConcreteDAOIF (com.runwaysdk.dataaccess.MdAttributeConcreteDAOIF)4 Classifier (net.geoprism.ontology.Classifier)4 Term (org.commongeoregistry.adapter.Term)4 AttributeTermType (org.commongeoregistry.adapter.metadata.AttributeTermType)4 DefaultAttribute (org.commongeoregistry.adapter.constants.DefaultAttribute)3 EdgeObject (com.runwaysdk.business.graph.EdgeObject)2 GraphObject (com.runwaysdk.business.graph.GraphObject)2 VertexObject (com.runwaysdk.business.graph.VertexObject)2 MdAttributeDAOIF (com.runwaysdk.dataaccess.MdAttributeDAOIF)2 MdAttributeMultiTermDAOIF (com.runwaysdk.dataaccess.MdAttributeMultiTermDAOIF)2 DataNotFoundException (com.runwaysdk.dataaccess.cache.DataNotFoundException)2 Transaction (com.runwaysdk.dataaccess.transaction.Transaction)2 TermReferenceProblem (net.geoprism.registry.etl.TermReferenceProblem)2 TermValueException (net.geoprism.registry.io.TermValueException)2 AbstractServerGeoObject (net.geoprism.registry.model.AbstractServerGeoObject)2 ServerGeoObjectType (net.geoprism.registry.model.ServerGeoObjectType)2 GeoObject (org.commongeoregistry.adapter.dataaccess.GeoObject)2 LocalizedValue (org.commongeoregistry.adapter.dataaccess.LocalizedValue)2 UnknownTermException (org.commongeoregistry.adapter.dataaccess.UnknownTermException)2