use of org.apache.atlas.model.instance.AtlasClassification in project incubator-atlas by apache.
the class EntityV2JerseyResourceIT method testAddTraitWithAttribute.
@Test(dependsOnMethods = "testGetTraitNames")
public void testAddTraitWithAttribute() throws Exception {
final String traitName = "PII_Trait" + randomString();
AtlasClassificationDef piiTrait = AtlasTypeUtil.createTraitTypeDef(traitName, ImmutableSet.<String>of(), AtlasTypeUtil.createRequiredAttrDef("type", "string"));
AtlasTypesDef typesDef = new AtlasTypesDef();
typesDef.getClassificationDefs().add(piiTrait);
createType(typesDef);
AtlasClassification traitInstance = new AtlasClassification(traitName);
traitInstance.setAttribute("type", "SSN");
final String guid = createHiveTable().getGuid();
atlasClientV2.addClassifications(guid, ImmutableList.of(traitInstance));
// verify the response
AtlasEntity withAssociationByGuid = atlasClientV2.getEntityByGuid(guid).getEntity();
assertNotNull(withAssociationByGuid);
assertFalse(withAssociationByGuid.getClassifications().isEmpty());
boolean found = false;
for (AtlasClassification atlasClassification : withAssociationByGuid.getClassifications()) {
String attribute = (String) atlasClassification.getAttribute("type");
if (attribute != null && attribute.equals("SSN")) {
found = true;
break;
}
}
assertTrue(found);
}
use of org.apache.atlas.model.instance.AtlasClassification in project incubator-atlas by apache.
the class EntityV2JerseyResourceIT method testAddTraitWithNoRegistration.
@Test(expectedExceptions = AtlasServiceException.class)
public void testAddTraitWithNoRegistration() throws Exception {
final String traitName = "PII_Trait" + randomString();
AtlasTypeUtil.createTraitTypeDef(traitName, ImmutableSet.<String>of());
AtlasClassification traitInstance = new AtlasClassification(traitName);
atlasClientV2.addClassifications("random", ImmutableList.of(traitInstance));
}
use of org.apache.atlas.model.instance.AtlasClassification in project incubator-atlas by apache.
the class EntityV2JerseyResourceIT method testGetTraitDefinitionForEntity.
@Test(dependsOnMethods = "testSubmitEntity")
public void testGetTraitDefinitionForEntity() throws Exception {
traitName = "PII_Trait" + randomString();
AtlasClassificationDef piiTrait = AtlasTypeUtil.createTraitTypeDef(traitName, ImmutableSet.<String>of());
AtlasTypesDef typesDef = new AtlasTypesDef();
typesDef.getClassificationDefs().add(piiTrait);
createType(typesDef);
AtlasClassificationDef classificationByName = atlasClientV2.getClassificationDefByName(traitName);
assertNotNull(classificationByName);
AtlasEntity hiveTable = createHiveTable();
assertEquals(hiveTable.getClassifications().size(), 7);
AtlasClassification piiClassification = new AtlasClassification(piiTrait.getName());
atlasClientV2.addClassifications(hiveTable.getGuid(), Lists.newArrayList(piiClassification));
AtlasClassifications classifications = atlasClientV2.getClassifications(hiveTable.getGuid());
assertNotNull(classifications);
assertTrue(classifications.getList().size() > 0);
assertEquals(classifications.getList().size(), 8);
}
use of org.apache.atlas.model.instance.AtlasClassification in project incubator-atlas by apache.
the class FullTextMapperV2 method getIndexTextForClassifications.
/**
* Map newly associated/defined classifications for the entity with given GUID
* @param guid Entity guid
* @param classifications new classifications added to the entity
* @return Full text string ONLY for the added classifications
* @throws AtlasBaseException
*/
public String getIndexTextForClassifications(String guid, List<AtlasClassification> classifications) throws AtlasBaseException {
String ret = null;
AtlasEntityWithExtInfo entityWithExtInfo = getAndCacheEntity(guid);
if (entityWithExtInfo != null) {
StringBuilder sb = new StringBuilder();
if (CollectionUtils.isNotEmpty(classifications)) {
for (AtlasClassification classification : classifications) {
sb.append(classification.getTypeName()).append(FULL_TEXT_DELIMITER);
mapAttributes(classification.getAttributes(), entityWithExtInfo, sb, new HashSet<String>());
}
}
ret = sb.toString();
}
if (LOG.isDebugEnabled()) {
LOG.debug("FullTextMapperV2.map({}): {}", guid, ret);
}
return ret;
}
use of org.apache.atlas.model.instance.AtlasClassification in project incubator-atlas by apache.
the class AtlasEntityStoreV1Test method testTagAssociationAfterRedefinition.
@Test
public void testTagAssociationAfterRedefinition() {
AtlasClassificationDef aTag = new AtlasClassificationDef("testTag");
AtlasAttributeDef attributeDef = new AtlasAttributeDef("testAttribute", "int", true, AtlasAttributeDef.Cardinality.SINGLE, 0, 1, false, true, Collections.<AtlasStructDef.AtlasConstraintDef>emptyList());
aTag.addAttribute(attributeDef);
AtlasTypesDef typesDef = new AtlasTypesDef();
typesDef.setClassificationDefs(Arrays.asList(aTag));
try {
typeDefStore.createTypesDef(typesDef);
} catch (AtlasBaseException e) {
fail("Tag creation should've succeeded");
}
try {
typeDefStore.deleteTypesDef(typesDef);
} catch (AtlasBaseException e) {
fail("Tag deletion should've succeeded");
}
aTag = new AtlasClassificationDef("testTag");
attributeDef = new AtlasAttributeDef("testAttribute", "string", true, AtlasAttributeDef.Cardinality.SINGLE, 0, 1, false, true, Collections.<AtlasStructDef.AtlasConstraintDef>emptyList());
aTag.addAttribute(attributeDef);
typesDef.setClassificationDefs(Arrays.asList(aTag));
try {
typeDefStore.createTypesDef(typesDef);
} catch (AtlasBaseException e) {
fail("Tag re-creation should've succeeded");
}
final AtlasEntity dbEntity = TestUtilsV2.createDBEntity();
try {
EntityMutationResponse response = entityStore.createOrUpdate(new AtlasEntityStream(dbEntity), false);
List<AtlasEntityHeader> createdEntity = response.getCreatedEntities();
assertTrue(CollectionUtils.isNotEmpty(createdEntity));
String guid = createdEntity.get(0).getGuid();
entityStore.addClassification(Arrays.asList(guid), new AtlasClassification(aTag.getName(), "testAttribute", "test-string"));
} catch (AtlasBaseException e) {
fail("DB entity creation should've succeeded");
}
}
Aggregations