Java Code Examples for org.apache.atlas.model.instance.AtlasEntity#getClassifications()
The following examples show how to use
org.apache.atlas.model.instance.AtlasEntity#getClassifications() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ImportTransformer.java From atlas with Apache License 2.0 | 6 votes |
@Override public Object apply(Object o) { if (!(o instanceof AtlasEntity)) { return o; } AtlasEntity entity = (AtlasEntity) o; if(!passThruFilters(entity)) { return o; } if(entity.getClassifications() == null) { entity.setClassifications(new ArrayList<AtlasClassification>()); } for (AtlasClassification c : entity.getClassifications()) { if (c.getTypeName().equals(classificationName)) { return entity; } } entity.getClassifications().add(new AtlasClassification(classificationName)); return entity; }
Example 2
Source File: EntityGraphMapper.java From atlas with Apache License 2.0 | 6 votes |
public void updateClassificationTextAndNames(AtlasVertex vertex) throws AtlasBaseException { if(CollectionUtils.isEmpty(vertex.getPropertyValues(Constants.TRAIT_NAMES_PROPERTY_KEY, String.class)) && CollectionUtils.isEmpty(vertex.getPropertyValues(Constants.PROPAGATED_TRAIT_NAMES_PROPERTY_KEY, String.class))) { return; } String guid = graphHelper.getGuid(vertex); AtlasEntity entity = instanceConverter.getAndCacheEntity(guid, ENTITY_CHANGE_NOTIFY_IGNORE_RELATIONSHIP_ATTRIBUTES); List<String> classificationNames = new ArrayList<>(); List<String> propagatedClassificationNames = new ArrayList<>(); for (AtlasClassification classification : entity.getClassifications()) { if (isPropagatedClassification(classification, guid)) { propagatedClassificationNames.add(classification.getTypeName()); } else { classificationNames.add(classification.getTypeName()); } } vertex.setProperty(CLASSIFICATION_NAMES_KEY, getDelimitedClassificationNames(classificationNames)); vertex.setProperty(PROPAGATED_CLASSIFICATION_NAMES_KEY, getDelimitedClassificationNames(propagatedClassificationNames)); vertex.setProperty(CLASSIFICATION_TEXT_KEY, fullTextMapperV2.getClassificationTextForEntity(entity)); }
Example 3
Source File: Action.java From atlas with Apache License 2.0 | 6 votes |
@Override public void apply(AtlasTransformableEntity transformableEntity) { AtlasEntity entity = transformableEntity.getEntity(); if (entity.getClassifications() == null) { entity.setClassifications(new ArrayList<>()); } boolean hasClassification = false; for (AtlasClassification c : entity.getClassifications()) { hasClassification = c.getTypeName().equals(classificationName); if (hasClassification) { break; } } if (!hasClassification) { entity.getClassifications().add(new AtlasClassification(classificationName)); } }
Example 4
Source File: FullTextMapperV2.java From incubator-atlas with Apache License 2.0 | 6 votes |
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); } } }
Example 5
Source File: BaseResourceIT.java From atlas with Apache License 2.0 | 5 votes |
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_TAG), new AtlasClassification(PHI_TAG), new AtlasClassification(PCI_TAG), new AtlasClassification(SOX_TAG), new AtlasClassification(SEC_TAG), new AtlasClassification(FINANCE_TAG)) ); 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); tableInstance.setAttribute("tableType", "MANAGED"); // enum 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; }
Example 6
Source File: ExportTypeProcessor.java From atlas with Apache License 2.0 | 5 votes |
public void addTypes(AtlasEntity entity, ExportService.ExportContext context) { addEntityType(entity.getTypeName(), context); if(CollectionUtils.isNotEmpty(entity.getClassifications())) { for (AtlasClassification c : entity.getClassifications()) { addClassificationType(c.getTypeName(), context); } } }
Example 7
Source File: ImportTransformer.java From atlas with Apache License 2.0 | 5 votes |
@Override public Object apply(Object o) { if (!(o instanceof AtlasEntity)) { return o; } AtlasEntity entity = (AtlasEntity) o; if(entity.getClassifications().size() == 0) { return o; } List<AtlasClassification> toRemove = null; for (AtlasClassification classification : entity.getClassifications()) { if (classification.getTypeName().equals(classificationToBeRemoved)) { if (toRemove == null) { toRemove = new ArrayList<AtlasClassification>(); } toRemove.add(classification); } } if (toRemove != null) { entity.getClassifications().removeAll(toRemove); } return entity; }
Example 8
Source File: FullTextMapperV2.java From atlas with Apache License 2.0 | 5 votes |
private void map(AtlasEntity entity, AtlasEntityExtInfo entityExtInfo, StringBuilder sb, Set<String> processedGuids, boolean isClassificationOnly) throws AtlasBaseException { if (entity == null || processedGuids.contains(entity.getGuid())) { return; } final AtlasEntityType entityType = typeRegistry.getEntityTypeByName(entity.getTypeName()); final Set<String> excludeAttributes = getExcludeAttributesForIndexText(entity.getTypeName()); processedGuids.add(entity.getGuid()); if(!isClassificationOnly) { sb.append(entity.getTypeName()).append(FULL_TEXT_DELIMITER); mapAttributes(entityType, entity.getAttributes(), entityExtInfo, sb, processedGuids, excludeAttributes, isClassificationOnly); } final List<AtlasClassification> classifications = entity.getClassifications(); if (CollectionUtils.isNotEmpty(classifications)) { for (AtlasClassification classification : classifications) { final AtlasClassificationType classificationType = typeRegistry.getClassificationTypeByName(classification.getTypeName()); final Set<String> excludeClassificationAttributes = getExcludeAttributesForIndexText(classification.getTypeName()); sb.append(classification.getTypeName()).append(FULL_TEXT_DELIMITER); mapAttributes(classificationType, classification.getAttributes(), entityExtInfo, sb, processedGuids, excludeClassificationAttributes, isClassificationOnly); } } }
Example 9
Source File: EntityGraphMapper.java From atlas with Apache License 2.0 | 5 votes |
private AtlasEntityHeader constructHeader(AtlasEntity entity, AtlasVertex vertex) throws AtlasBaseException { AtlasEntityHeader header = entityRetriever.toAtlasEntityHeaderWithClassifications(vertex); if (entity.getClassifications() == null) { entity.setClassifications(header.getClassifications()); } return header; }
Example 10
Source File: ImportTransformsTest.java From atlas with Apache License 2.0 | 5 votes |
@Test public void addClassification_AddsClassificationToEntitiy() throws AtlasBaseException { AtlasEntity entity = getHiveTableAtlasEntity(); int existingClassificationsCount = entity.getClassifications() != null ? entity.getClassifications().size() : 0; ImportTransforms t = ImportTransforms.fromJson(jsonAddClasification); assertTrue(t.getTransforms().size() > 0); t.apply(entity); assertNotNull(t); assertEquals(entity.getClassifications().size(), existingClassificationsCount + 1); addClassification_ExistingClassificationsAreHandled(entity); addClassification_MultipleClassificationsAreAdded(entity); }
Example 11
Source File: ImportTransformsTest.java From atlas with Apache License 2.0 | 5 votes |
private void addClassification_ExistingClassificationsAreHandled(AtlasEntity entity) throws AtlasBaseException { int existingClassificationsCount = entity.getClassifications() != null ? entity.getClassifications().size() : 0; assertTrue(existingClassificationsCount > 0); ImportTransforms.fromJson(jsonAddClasification).apply(entity); assertEquals(entity.getClassifications().size(), existingClassificationsCount); }
Example 12
Source File: BaseResourceIT.java From incubator-atlas with Apache License 2.0 | 5 votes |
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); tableInstance.setAttribute("tableType", "MANAGED"); // enum 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; }
Example 13
Source File: EntityV2JerseyResourceIT.java From incubator-atlas with Apache License 2.0 | 5 votes |
@Test(dependsOnMethods = "testGetTraitNames") public void testAddTraitWithAttribute() throws Exception { final String traitName = "PII_Trait" + randomString(); AtlasClassificationDef piiTrait = AtlasTypeUtil .createTraitTypeDef(traitName, ImmutableSet.<String>of(), AtlasTypeUtil.createRequiredAttrDef("type", "string")); AtlasTypesDef typesDef = new AtlasTypesDef(); typesDef.getClassificationDefs().add(piiTrait); createType(typesDef); AtlasClassification traitInstance = new AtlasClassification(traitName); traitInstance.setAttribute("type", "SSN"); final String guid = createHiveTable().getGuid(); atlasClientV2.addClassifications(guid, ImmutableList.of(traitInstance)); // verify the response AtlasEntity withAssociationByGuid = atlasClientV2.getEntityByGuid(guid).getEntity(); assertNotNull(withAssociationByGuid); assertFalse(withAssociationByGuid.getClassifications().isEmpty()); boolean found = false; for (AtlasClassification atlasClassification : withAssociationByGuid.getClassifications()) { String attribute = (String)atlasClassification.getAttribute("type"); if (attribute != null && attribute.equals("SSN")) { found = true; break; } } assertTrue(found); }
Example 14
Source File: ExportService.java From incubator-atlas with Apache License 2.0 | 5 votes |
private void addTypes(AtlasEntity entity, ExportContext context) { addEntityType(entity.getTypeName(), context); if(CollectionUtils.isNotEmpty(entity.getClassifications())) { for (AtlasClassification c : entity.getClassifications()) { addClassificationType(c.getTypeName(), context); } } }