use of org.apache.atlas.model.instance.AtlasClassification in project incubator-atlas by apache.
the class EntityGraphRetriever method getClassification.
public AtlasClassification getClassification(String guid, String classificationName) throws AtlasBaseException {
AtlasVertex instanceVertex = AtlasGraphUtilsV1.findByGuid(guid);
if (instanceVertex == null) {
throw new AtlasBaseException(AtlasErrorCode.INSTANCE_GUID_NOT_FOUND, guid);
}
List<AtlasClassification> classifications = getClassifications(instanceVertex, classificationName);
if (CollectionUtils.isEmpty(classifications)) {
throw new AtlasBaseException(AtlasErrorCode.CLASSIFICATION_NOT_FOUND, classificationName);
}
return classifications.get(0);
}
use of org.apache.atlas.model.instance.AtlasClassification in project incubator-atlas by apache.
the class EntityGraphRetriever method getClassifications.
private List<AtlasClassification> getClassifications(AtlasVertex instanceVertex, @Nullable String classificationNameFilter) throws AtlasBaseException {
List<AtlasClassification> classifications = new ArrayList<>();
List<String> classificationNames = GraphHelper.getTraitNames(instanceVertex);
if (CollectionUtils.isNotEmpty(classificationNames)) {
for (String classificationName : classificationNames) {
AtlasClassification classification;
if (StringUtils.isNotEmpty(classificationNameFilter)) {
if (classificationName.equals(classificationNameFilter)) {
classification = getClassification(instanceVertex, classificationName);
classifications.add(classification);
return classifications;
}
} else {
classification = getClassification(instanceVertex, classificationName);
classifications.add(classification);
}
}
if (StringUtils.isNotEmpty(classificationNameFilter)) {
//Should not reach here if classification present
throw new AtlasBaseException(AtlasErrorCode.CLASSIFICATION_NOT_FOUND, classificationNameFilter);
}
}
return classifications;
}
use of org.apache.atlas.model.instance.AtlasClassification in project incubator-atlas by apache.
the class EntityGraphMapper method addClassifications.
public void addClassifications(final EntityMutationContext context, String guid, List<AtlasClassification> classifications) throws AtlasBaseException {
if (CollectionUtils.isNotEmpty(classifications)) {
AtlasVertex instanceVertex = AtlasGraphUtilsV1.findByGuid(guid);
if (instanceVertex == null) {
throw new AtlasBaseException(AtlasErrorCode.INSTANCE_GUID_NOT_FOUND, guid);
}
String entityTypeName = AtlasGraphUtilsV1.getTypeName(instanceVertex);
final AtlasEntityType entityType = typeRegistry.getEntityTypeByName(entityTypeName);
for (AtlasClassification classification : classifications) {
if (LOG.isDebugEnabled()) {
LOG.debug("mapping classification {}", classification);
}
GraphHelper.addProperty(instanceVertex, Constants.TRAIT_NAMES_PROPERTY_KEY, classification.getTypeName());
// add a new AtlasVertex for the struct or trait instance
AtlasVertex classificationVertex = createClassificationVertex(classification);
if (LOG.isDebugEnabled()) {
LOG.debug("created vertex {} for trait {}", string(classificationVertex), classification.getTypeName());
}
// add the attributes for the trait instance
mapClassification(EntityOperation.CREATE, context, classification, entityType, instanceVertex, classificationVertex);
}
}
}
use of org.apache.atlas.model.instance.AtlasClassification in project incubator-atlas by apache.
the class EntityGraphRetriever method getClassification.
private AtlasClassification getClassification(AtlasVertex instanceVertex, String classificationName) throws AtlasBaseException {
AtlasClassification ret = null;
if (LOG.isDebugEnabled()) {
LOG.debug("mapping classification {} to atlas entity", classificationName);
}
Iterable<AtlasEdge> edges = instanceVertex.getEdges(AtlasEdgeDirection.OUT, classificationName);
AtlasEdge edge = (edges != null && edges.iterator().hasNext()) ? edges.iterator().next() : null;
if (edge != null) {
ret = new AtlasClassification(classificationName);
mapAttributes(edge.getInVertex(), ret, null);
}
return ret;
}
use of org.apache.atlas.model.instance.AtlasClassification in project incubator-atlas by apache.
the class BaseResourceIT method createHiveTableInstanceV2.
protected AtlasEntity createHiveTableInstanceV2(AtlasEntity databaseInstance, String tableName) throws Exception {
AtlasEntity tableInstance = new AtlasEntity(HIVE_TABLE_TYPE_V2);
tableInstance.setClassifications(Arrays.asList(new AtlasClassification("classification"), new AtlasClassification("pii"), new AtlasClassification("phi"), new AtlasClassification("pci"), new AtlasClassification("sox"), new AtlasClassification("sec"), new AtlasClassification("finance")));
tableInstance.setAttribute(NAME, tableName);
tableInstance.setAttribute(AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, tableName);
tableInstance.setAttribute("db", AtlasTypeUtil.getAtlasObjectId(databaseInstance));
tableInstance.setAttribute(DESCRIPTION, "bar table");
tableInstance.setAttribute("lastAccessTime", "2014-07-11T08:00:00.000Z");
tableInstance.setAttribute("type", "managed");
tableInstance.setAttribute("level", 2);
// enum
tableInstance.setAttribute("tableType", "MANAGED");
tableInstance.setAttribute("compressed", false);
AtlasClassification classification = tableInstance.getClassifications().get(0);
classification.setAttribute("tag", "foundation_etl");
AtlasStruct serde1Instance = new AtlasStruct("serdeType");
serde1Instance.setAttribute(NAME, "serde1");
serde1Instance.setAttribute("serde", "serde1");
tableInstance.setAttribute("serde1", serde1Instance);
AtlasStruct serde2Instance = new AtlasStruct("serdeType");
serde2Instance.setAttribute(NAME, "serde2");
serde2Instance.setAttribute("serde", "serde2");
tableInstance.setAttribute("serde2", serde2Instance);
List<AtlasClassification> traits = tableInstance.getClassifications();
Assert.assertEquals(traits.size(), 7);
return tableInstance;
}
Aggregations