Search in sources :

Example 21 with AtlasClassification

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);
}
Also used : AtlasClassificationDef(org.apache.atlas.model.typedef.AtlasClassificationDef) AtlasEntity(org.apache.atlas.model.instance.AtlasEntity) AtlasClassification(org.apache.atlas.model.instance.AtlasClassification) AtlasTypesDef(org.apache.atlas.model.typedef.AtlasTypesDef) Test(org.testng.annotations.Test)

Example 22 with AtlasClassification

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));
}
Also used : AtlasClassification(org.apache.atlas.model.instance.AtlasClassification) Test(org.testng.annotations.Test)

Example 23 with AtlasClassification

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);
}
Also used : AtlasClassificationDef(org.apache.atlas.model.typedef.AtlasClassificationDef) AtlasEntity(org.apache.atlas.model.instance.AtlasEntity) AtlasClassifications(org.apache.atlas.model.instance.AtlasClassification.AtlasClassifications) AtlasClassification(org.apache.atlas.model.instance.AtlasClassification) AtlasTypesDef(org.apache.atlas.model.typedef.AtlasTypesDef) Test(org.testng.annotations.Test)

Example 24 with AtlasClassification

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;
}
Also used : AtlasEntityWithExtInfo(org.apache.atlas.model.instance.AtlasEntity.AtlasEntityWithExtInfo) AtlasClassification(org.apache.atlas.model.instance.AtlasClassification)

Example 25 with AtlasClassification

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");
    }
}
Also used : AtlasClassificationDef(org.apache.atlas.model.typedef.AtlasClassificationDef) EntityMutationResponse(org.apache.atlas.model.instance.EntityMutationResponse) TestUtils.randomString(org.apache.atlas.TestUtils.randomString) AtlasStructDef(org.apache.atlas.model.typedef.AtlasStructDef) AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasEntity(org.apache.atlas.model.instance.AtlasEntity) AtlasAttributeDef(org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef) AtlasEntityHeader(org.apache.atlas.model.instance.AtlasEntityHeader) AtlasClassification(org.apache.atlas.model.instance.AtlasClassification) AtlasTypesDef(org.apache.atlas.model.typedef.AtlasTypesDef) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

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