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