Search in sources :

Example 11 with AtlasClassification

use of org.apache.atlas.model.instance.AtlasClassification in project incubator-atlas by apache.

the class EntityGraphRetriever method getClassifications.

private List<AtlasClassification> getClassifications(AtlasVertex instanceVertex, @Nullable String classificationNameFilter) throws AtlasBaseException {
    List<AtlasClassification> classifications = new ArrayList<>();
    List<String> classificationNames = GraphHelper.getTraitNames(instanceVertex);
    if (CollectionUtils.isNotEmpty(classificationNames)) {
        for (String classificationName : classificationNames) {
            AtlasClassification classification;
            if (StringUtils.isNotEmpty(classificationNameFilter)) {
                if (classificationName.equals(classificationNameFilter)) {
                    classification = getClassification(instanceVertex, classificationName);
                    classifications.add(classification);
                    return classifications;
                }
            } else {
                classification = getClassification(instanceVertex, classificationName);
                classifications.add(classification);
            }
        }
        if (StringUtils.isNotEmpty(classificationNameFilter)) {
            //Should not reach here if classification present
            throw new AtlasBaseException(AtlasErrorCode.CLASSIFICATION_NOT_FOUND, classificationNameFilter);
        }
    }
    return classifications;
}
Also used : AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) ArrayList(java.util.ArrayList) AtlasClassification(org.apache.atlas.model.instance.AtlasClassification)

Example 12 with AtlasClassification

use of org.apache.atlas.model.instance.AtlasClassification in project incubator-atlas by apache.

the class TestEntityREST method testAddAndUpdateClassificationWithAttributes.

@Test(dependsOnMethods = "testGetEntityById")
public void testAddAndUpdateClassificationWithAttributes() throws Exception {
    phiClassification = new AtlasClassification(TestUtilsV2.PHI, new HashMap<String, Object>() {

        {
            put("stringAttr", "sample_string");
            put("booleanAttr", true);
            put("integerAttr", 100);
        }
    });
    testClassification = new AtlasClassification(TestUtilsV2.CLASSIFICATION, new HashMap<String, Object>() {

        {
            put("tag", "tagName");
        }
    });
    entityREST.addClassifications(dbEntity.getGuid(), new ArrayList<>(Arrays.asList(phiClassification)));
    final AtlasClassifications retrievedClassifications = entityREST.getClassifications(dbEntity.getGuid());
    Assert.assertNotNull(retrievedClassifications);
    final List<AtlasClassification> retrievedClassificationsList = retrievedClassifications.getList();
    Assert.assertNotNull(retrievedClassificationsList);
    final AtlasClassification retrievedClassification = entityREST.getClassification(dbEntity.getGuid(), TestUtilsV2.PHI);
    Assert.assertNotNull(retrievedClassification);
    Assert.assertEquals(retrievedClassification, phiClassification);
    for (String attrName : retrievedClassification.getAttributes().keySet()) {
        Assert.assertEquals(retrievedClassification.getAttribute(attrName), phiClassification.getAttribute(attrName));
    }
    // update multiple tags attributes
    phiClassification = new AtlasClassification(TestUtilsV2.PHI, new HashMap<String, Object>() {

        {
            put("stringAttr", "sample_string_v2");
            put("integerAttr", 200);
        }
    });
    testClassification = new AtlasClassification(TestUtilsV2.CLASSIFICATION, new HashMap<String, Object>() {

        {
            put("tag", "tagName_updated");
        }
    });
    entityREST.updateClassification(dbEntity.getGuid(), new ArrayList<>(Arrays.asList(phiClassification, testClassification)));
    AtlasClassification updatedClassification = entityREST.getClassification(dbEntity.getGuid(), TestUtilsV2.PHI);
    Assert.assertNotNull(updatedClassification);
    Assert.assertEquals(updatedClassification.getAttribute("stringAttr"), "sample_string_v2");
    Assert.assertEquals(updatedClassification.getAttribute("integerAttr"), 200);
    Assert.assertEquals(updatedClassification.getAttribute("booleanAttr"), true);
    updatedClassification = entityREST.getClassification(dbEntity.getGuid(), TestUtilsV2.CLASSIFICATION);
    Assert.assertNotNull(updatedClassification);
    Assert.assertEquals(updatedClassification.getAttribute("tag"), testClassification.getAttribute("tag"));
    entityREST.deleteClassification(dbEntity.getGuid(), TestUtilsV2.PHI);
}
Also used : HashMap(java.util.HashMap) AtlasClassifications(org.apache.atlas.model.instance.AtlasClassification.AtlasClassifications) AtlasClassification(org.apache.atlas.model.instance.AtlasClassification) Test(org.testng.annotations.Test)

Example 13 with AtlasClassification

use of org.apache.atlas.model.instance.AtlasClassification in project incubator-atlas by apache.

the class TestEntityREST method testGetEntityWithAssociations.

@Test(dependsOnMethods = "testAddAndGetClassification")
public void testGetEntityWithAssociations() throws Exception {
    AtlasEntityWithExtInfo entity = entityREST.getById(dbEntity.getGuid());
    final List<AtlasClassification> retrievedClassifications = entity.getEntity().getClassifications();
    Assert.assertNotNull(retrievedClassifications);
    Assert.assertEquals(new ArrayList<AtlasClassification>() {

        {
            add(testClassification);
        }
    }, retrievedClassifications);
}
Also used : AtlasEntityWithExtInfo(org.apache.atlas.model.instance.AtlasEntity.AtlasEntityWithExtInfo) AtlasClassification(org.apache.atlas.model.instance.AtlasClassification) Test(org.testng.annotations.Test)

Example 14 with AtlasClassification

use of org.apache.atlas.model.instance.AtlasClassification in project incubator-atlas by apache.

the class AtlasClassificationType method createDefaultValue.

@Override
public AtlasClassification createDefaultValue() {
    AtlasClassification ret = new AtlasClassification(classificationDef.getName());
    populateDefaultValues(ret);
    return ret;
}
Also used : AtlasClassification(org.apache.atlas.model.instance.AtlasClassification)

Example 15 with AtlasClassification

use of org.apache.atlas.model.instance.AtlasClassification in project incubator-atlas by apache.

the class ModelTestUtil method newClassification.

public static AtlasClassification newClassification(AtlasClassificationDef classificationDef, AtlasTypeRegistry typesRegistry) {
    AtlasClassification ret = null;
    AtlasClassificationType classificationType = typesRegistry.getClassificationTypeByName(classificationDef.getName());
    if (classificationType != null) {
        ret = classificationType.createDefaultValue();
    } else {
        LOG.error("failed to get classification-type {}", classificationDef.getName());
    }
    return ret;
}
Also used : AtlasClassificationType(org.apache.atlas.type.AtlasClassificationType) AtlasClassification(org.apache.atlas.model.instance.AtlasClassification)

Aggregations

AtlasClassification (org.apache.atlas.model.instance.AtlasClassification)30 AtlasBaseException (org.apache.atlas.exception.AtlasBaseException)13 Test (org.testng.annotations.Test)10 ArrayList (java.util.ArrayList)6 AtlasEntity (org.apache.atlas.model.instance.AtlasEntity)5 AtlasClassificationDef (org.apache.atlas.model.typedef.AtlasClassificationDef)4 AtlasTypesDef (org.apache.atlas.model.typedef.AtlasTypesDef)4 IStruct (org.apache.atlas.typesystem.IStruct)4 AtlasPerfTracer (org.apache.atlas.utils.AtlasPerfTracer)4 AtlasClassifications (org.apache.atlas.model.instance.AtlasClassification.AtlasClassifications)3 AtlasClassificationType (org.apache.atlas.type.AtlasClassificationType)3 JSONObject (org.codehaus.jettison.json.JSONObject)3 HashMap (java.util.HashMap)2 AtlasException (org.apache.atlas.AtlasException)2 GraphTransaction (org.apache.atlas.annotation.GraphTransaction)2 AtlasEntityWithExtInfo (org.apache.atlas.model.instance.AtlasEntity.AtlasEntityWithExtInfo)2 AtlasVertex (org.apache.atlas.repository.graphdb.AtlasVertex)2 AtlasEntityType (org.apache.atlas.type.AtlasEntityType)2 JSONArray (org.codehaus.jettison.json.JSONArray)2 Map (java.util.Map)1