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;
}
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);
}
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);
}
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;
}
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;
}
Aggregations