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