Search in sources :

Example 1 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 2 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 3 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)

Example 4 with AtlasClassification

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

the class FullTextMapperV2 method map.

private void map(AtlasEntity entity, AtlasEntityExtInfo entityExtInfo, StringBuilder sb, Set<String> processedGuids) throws AtlasBaseException {
    if (entity == null || processedGuids.contains(entity.getGuid())) {
        return;
    }
    processedGuids.add(entity.getGuid());
    sb.append(entity.getTypeName()).append(FULL_TEXT_DELIMITER);
    mapAttributes(entity.getAttributes(), entityExtInfo, sb, processedGuids);
    List<AtlasClassification> classifications = entity.getClassifications();
    if (CollectionUtils.isNotEmpty(classifications)) {
        for (AtlasClassification classification : classifications) {
            sb.append(classification.getTypeName()).append(FULL_TEXT_DELIMITER);
            mapAttributes(classification.getAttributes(), entityExtInfo, sb, processedGuids);
        }
    }
}
Also used : AtlasClassification(org.apache.atlas.model.instance.AtlasClassification)

Example 5 with AtlasClassification

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

the class EntityResource method getTraitDefinitionsForEntity.

/**
     * Fetches the trait definitions of all the traits associated to the given entity
     * @param guid globally unique identifier for the entity
     */
@GET
@Path("{guid}/traitDefinitions")
@Produces(Servlets.JSON_MEDIA_TYPE)
public Response getTraitDefinitionsForEntity(@PathParam("guid") String guid) {
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> EntityResource.getTraitDefinitionsForEntity({})", guid);
    }
    AtlasPerfTracer perf = null;
    try {
        if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
            perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "EntityResource.getTraitDefinitionsForEntity(" + guid + ")");
        }
        if (LOG.isDebugEnabled()) {
            LOG.debug("Fetching all trait definitions for entity={}", guid);
        }
        final List<AtlasClassification> classifications = entitiesStore.getClassifications(guid);
        JSONArray traits = new JSONArray();
        for (AtlasClassification classification : classifications) {
            IStruct trait = restAdapters.getTrait(classification);
            traits.put(new JSONObject(InstanceSerialization.toJson(trait, true)));
        }
        JSONObject response = new JSONObject();
        response.put(AtlasClient.REQUEST_ID, Servlets.getRequestId());
        response.put(AtlasClient.RESULTS, traits);
        response.put(AtlasClient.COUNT, traits.length());
        return Response.ok(response).build();
    } catch (AtlasBaseException e) {
        LOG.error("Unable to get trait definition for entity {}", guid, e);
        throw toWebApplicationException(e);
    } catch (IllegalArgumentException e) {
        LOG.error("Unable to get trait definition for entity {}", guid, e);
        throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.BAD_REQUEST));
    } catch (WebApplicationException e) {
        LOG.error("Unable to get trait definitions for entity {}", guid, e);
        throw e;
    } catch (Throwable e) {
        LOG.error("Unable to get trait definitions for entity {}", guid, e);
        throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.INTERNAL_SERVER_ERROR));
    } finally {
        AtlasPerfTracer.log(perf);
        if (LOG.isDebugEnabled()) {
            LOG.debug("<== EntityResource.getTraitDefinitionsForEntity({})", guid);
        }
    }
}
Also used : AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) JSONObject(org.codehaus.jettison.json.JSONObject) AtlasPerfTracer(org.apache.atlas.utils.AtlasPerfTracer) JSONArray(org.codehaus.jettison.json.JSONArray) AtlasClassification(org.apache.atlas.model.instance.AtlasClassification) IStruct(org.apache.atlas.typesystem.IStruct)

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