Search in sources :

Example 6 with AtlasClassification

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

the class EntityREST method addClassification.

/**
     * Bulk API to associate a tag to multiple entities
     */
@POST
@Path("/bulk/classification")
@Consumes({ Servlets.JSON_MEDIA_TYPE, MediaType.APPLICATION_JSON })
@Produces(Servlets.JSON_MEDIA_TYPE)
public void addClassification(ClassificationAssociateRequest request) throws AtlasBaseException {
    AtlasPerfTracer perf = null;
    try {
        if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
            perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "EntityREST.addClassification(" + request + ")");
        }
        AtlasClassification classification = request == null ? null : request.getClassification();
        List<String> entityGuids = request == null ? null : request.getEntityGuids();
        if (classification == null || StringUtils.isEmpty(classification.getTypeName())) {
            throw new AtlasBaseException(AtlasErrorCode.INVALID_PARAMETERS, "no classification");
        }
        if (CollectionUtils.isEmpty(entityGuids)) {
            throw new AtlasBaseException(AtlasErrorCode.INVALID_PARAMETERS, "empty guid list");
        }
        entitiesStore.addClassification(entityGuids, classification);
    } finally {
        AtlasPerfTracer.log(perf);
    }
}
Also used : AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasPerfTracer(org.apache.atlas.utils.AtlasPerfTracer) AtlasClassification(org.apache.atlas.model.instance.AtlasClassification) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces)

Example 7 with AtlasClassification

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

the class QuickStartV2 method toAtlasClassifications.

private List<AtlasClassification> toAtlasClassifications(String[] traitNames) {
    List<AtlasClassification> ret = new ArrayList<>();
    ImmutableList<String> traits = ImmutableList.copyOf(traitNames);
    if (CollectionUtils.isNotEmpty(traits)) {
        for (String trait : traits) {
            ret.add(new AtlasClassification(trait));
        }
    }
    return ret;
}
Also used : ArrayList(java.util.ArrayList) AtlasClassification(org.apache.atlas.model.instance.AtlasClassification)

Example 8 with AtlasClassification

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

the class AtlasEntityStoreV1 method addClassifications.

@Override
@GraphTransaction
public void addClassifications(final String guid, final List<AtlasClassification> classifications) throws AtlasBaseException {
    if (StringUtils.isEmpty(guid)) {
        throw new AtlasBaseException(AtlasErrorCode.INVALID_PARAMETERS, "Guid(s) not specified");
    }
    if (CollectionUtils.isEmpty(classifications)) {
        throw new AtlasBaseException(AtlasErrorCode.INVALID_PARAMETERS, "classifications(s) not specified");
    }
    if (LOG.isDebugEnabled()) {
        LOG.debug("Adding classifications={} to entity={}", classifications, guid);
    }
    for (AtlasClassification classification : classifications) {
        validateAndNormalize(classification);
    }
    // validate if entity, not already associated with classifications
    validateEntityAssociations(guid, classifications);
    entityGraphMapper.addClassifications(new EntityMutationContext(), guid, classifications);
    // notify listeners on classification addition
    entityChangeNotifier.onClassificationAddedToEntity(guid, classifications);
}
Also used : AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasClassification(org.apache.atlas.model.instance.AtlasClassification) GraphTransaction(org.apache.atlas.annotation.GraphTransaction)

Example 9 with AtlasClassification

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

the class TestEntitiesREST method testTagToMultipleEntities.

@Test(dependsOnMethods = "testCreateOrUpdateEntities")
public void testTagToMultipleEntities() throws Exception {
    AtlasClassification tag = new AtlasClassification(TestUtilsV2.CLASSIFICATION, new HashMap<String, Object>() {

        {
            put("tag", "tagName");
        }
    });
    ClassificationAssociateRequest classificationAssociateRequest = new ClassificationAssociateRequest(createdGuids, tag);
    entityREST.addClassification(classificationAssociateRequest);
    for (String guid : createdGuids) {
        final AtlasClassification result_tag = entityREST.getClassification(guid, TestUtilsV2.CLASSIFICATION);
        Assert.assertNotNull(result_tag);
        Assert.assertEquals(result_tag, tag);
    }
}
Also used : ClassificationAssociateRequest(org.apache.atlas.model.instance.ClassificationAssociateRequest) AtlasClassification(org.apache.atlas.model.instance.AtlasClassification) Test(org.testng.annotations.Test)

Example 10 with AtlasClassification

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

the class TestEntityREST method testAddAndGetClassification.

@Test(dependsOnMethods = "testGetEntityById")
public void testAddAndGetClassification() throws Exception {
    List<AtlasClassification> classifications = new ArrayList<>();
    testClassification = new AtlasClassification(TestUtilsV2.CLASSIFICATION, new HashMap<String, Object>() {

        {
            put("tag", "tagName");
        }
    });
    classifications.add(testClassification);
    entityREST.addClassifications(dbEntity.getGuid(), classifications);
    final AtlasClassification.AtlasClassifications retrievedClassifications = entityREST.getClassifications(dbEntity.getGuid());
    Assert.assertNotNull(retrievedClassifications);
    final List<AtlasClassification> retrievedClassificationsList = retrievedClassifications.getList();
    Assert.assertNotNull(retrievedClassificationsList);
    Assert.assertEquals(classifications, retrievedClassificationsList);
    final AtlasClassification retrievedClassification = entityREST.getClassification(dbEntity.getGuid(), TestUtilsV2.CLASSIFICATION);
    Assert.assertNotNull(retrievedClassification);
    Assert.assertEquals(retrievedClassification, testClassification);
}
Also used : HashMap(java.util.HashMap) AtlasClassifications(org.apache.atlas.model.instance.AtlasClassification.AtlasClassifications) ArrayList(java.util.ArrayList) AtlasClassification(org.apache.atlas.model.instance.AtlasClassification) Test(org.testng.annotations.Test)

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