private List<AtlasClassification> toAtlasClassifications(String[] traitNames) { List<AtlasClassification> ret = new ArrayList<>(); List<String> traits = Arrays.asList(traitNames); if (CollectionUtils.isNotEmpty(traits)) { for (String trait : traits) { ret.add(new AtlasClassification(trait)); } } return ret; }
@Override public AtlasClassification createDefaultValue() { AtlasClassification ret = new AtlasClassification(classificationDef.getName()); populateDefaultValues(ret); return ret; }
@Override public AtlasClassification createDefaultValue() { AtlasClassification ret = new AtlasClassification(classificationDef.getName()); populateDefaultValues(ret); return ret; }
private boolean validateTimeBoundaries(Object classificationObj, List<String> messages) { boolean ret = true; AtlasClassification classification = null; if (classificationObj instanceof AtlasClassification) { classification = (AtlasClassification) classificationObj; } else if (classificationObj instanceof Map) { classification = new AtlasClassification((Map) classificationObj); } if (classification != null && classification.getValidityPeriods() != null) { for (TimeBoundary timeBoundary : classification.getValidityPeriods()) { if (timeBoundary != null) { ret = validateTimeBoundry(timeBoundary, messages) && ret; } } } return ret; }
@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)); } }
@Test(dependsOnMethods = "testCreate") public void associateMultipleTagsToOneEntity() throws AtlasBaseException { final String TAG_NAME = "tag_xy"; final String TAG_NAME_2 = TAG_NAME + "_2"; final String TAG_ATTRIBUTE_NAME = "testAttribute"; final String TAG_ATTRIBUTE_VALUE = "test-string"; final String TAG_ATTRIBUTE_VALUE_2 = TAG_ATTRIBUTE_VALUE + "-2"; createTag(TAG_NAME, "string"); createTag(TAG_NAME_2, "string"); List<AtlasClassification> addedClassifications = new ArrayList<>(); addedClassifications.add(new AtlasClassification(TAG_NAME, TAG_ATTRIBUTE_NAME, TAG_ATTRIBUTE_VALUE)); addedClassifications.add(new AtlasClassification(TAG_NAME_2, TAG_ATTRIBUTE_NAME, TAG_ATTRIBUTE_VALUE_2)); entityStore.addClassifications(dbEntityGuid, addedClassifications); AtlasEntity dbEntityFromDb = getEntityFromStore(dbEntityGuid); List<String> actualClassifications = (List<String>) CollectionUtils.collect(dbEntityFromDb.getClassifications(), o -> ((AtlasClassification) o).getTypeName()); Set<String> classificationSet = new HashSet<>(actualClassifications); assertTrue(classificationSet.contains(TAG_NAME)); assertTrue(classificationSet.contains(TAG_NAME_2)); for (String actualClassificationName : actualClassifications) { entityStore.deleteClassification(dbEntityGuid, actualClassificationName); } }
@Test(dependsOnMethods = {"updateClassification_PropagateTrueToFalse"}) public void deleteClassification_PropagateTrue() throws AtlasBaseException { AtlasEntity hdfs_employees = getEntity(HDFS_PATH_EMPLOYEES); AtlasClassification tag1 = new AtlasClassification("tag1"); tag1.setPropagate(true); tag1.setEntityGuid(hdfs_employees.getGuid()); deleteClassification(hdfs_employees, tag1); List<String> propagatedToEntities = Arrays.asList(EMPLOYEES1_PROCESS, EMPLOYEES2_PROCESS, EMPLOYEES1_TABLE, EMPLOYEES2_TABLE, EMPLOYEES_UNION_PROCESS, EMPLOYEES_UNION_TABLE); assertClassificationNotExistInEntities(propagatedToEntities, tag1); }
@Test(dependsOnMethods = {"updateClassification_PropagateFalseToTrue"}) public void addClassification_PropagateTrue() throws AtlasBaseException { AtlasEntity hdfs_employees = getEntity(HDFS_PATH_EMPLOYEES); AtlasClassification tag1 = new AtlasClassification("tag1"); tag1.setPropagate(true); tag1.setEntityGuid(hdfs_employees.getGuid()); // add classification with propagate flag to 'true' addClassification(hdfs_employees, tag1); List<String> propagatedToEntities = Arrays.asList(EMPLOYEES1_PROCESS, EMPLOYEES2_PROCESS, EMPLOYEES1_TABLE, EMPLOYEES2_TABLE, EMPLOYEES_UNION_PROCESS, EMPLOYEES_UNION_TABLE); assertClassificationExistInEntities(propagatedToEntities, tag1); }
@Test(dependsOnMethods = {"updateClassification_PropagateTrueToFalse"}) public void deleteClassification_PropagateTrue() throws AtlasBaseException { AtlasEntity hdfs_employees = getEntity(HDFS_PATH_EMPLOYEES); AtlasClassification tag1 = new AtlasClassification("tag1"); tag1.setPropagate(true); tag1.setEntityGuid(hdfs_employees.getGuid()); deleteClassification(hdfs_employees, tag1); List<String> propagatedToEntities = Arrays.asList(EMPLOYEES1_PROCESS, EMPLOYEES2_PROCESS, EMPLOYEES1_TABLE, EMPLOYEES2_TABLE, EMPLOYEES_UNION_PROCESS, EMPLOYEES_UNION_TABLE); assertClassificationNotExistInEntities(propagatedToEntities, tag1); }
@Test(dependsOnMethods = {"updateClassification_PropagateFalseToTrue"}) public void addClassification_PropagateTrue() throws AtlasBaseException { AtlasEntity hdfs_employees = getEntity(HDFS_PATH_EMPLOYEES); AtlasClassification tag1 = new AtlasClassification("tag1"); tag1.setPropagate(true); tag1.setEntityGuid(hdfs_employees.getGuid()); // add classification with propagate flag to 'true' addClassification(hdfs_employees, tag1); List<String> propagatedToEntities = Arrays.asList(EMPLOYEES1_PROCESS, EMPLOYEES2_PROCESS, EMPLOYEES1_TABLE, EMPLOYEES2_TABLE, EMPLOYEES_UNION_PROCESS, EMPLOYEES_UNION_TABLE); assertClassificationExistInEntities(propagatedToEntities, tag1); }
@Test(dependsOnMethods = {"addClassification_PropagateTrue"}) public void updateClassification_PropagateTrueToFalse() throws AtlasBaseException { AtlasEntity hdfs_employees = getEntity(HDFS_PATH_EMPLOYEES); AtlasClassification tag1 = new AtlasClassification("tag1"); tag1.setEntityGuid(hdfs_employees.getGuid()); List<String> propagatedToEntities = Arrays.asList(EMPLOYEES1_PROCESS, EMPLOYEES2_PROCESS, EMPLOYEES1_TABLE, EMPLOYEES2_TABLE, EMPLOYEES_UNION_PROCESS, EMPLOYEES_UNION_TABLE); // update propagate flag to 'false' tag1 = getClassification(hdfs_employees, tag1); tag1.setPropagate(false); updateClassifications(hdfs_employees, tag1); assertClassificationNotExistInEntities(propagatedToEntities, tag1); }
@Test(dependsOnMethods = {"addClassification_PropagateTrue"}) public void updateClassification_PropagateTrueToFalse() throws AtlasBaseException { AtlasEntity hdfs_employees = getEntity(HDFS_PATH_EMPLOYEES); AtlasClassification tag1 = new AtlasClassification("tag1"); tag1.setEntityGuid(hdfs_employees.getGuid()); List<String> propagatedToEntities = Arrays.asList(EMPLOYEES1_PROCESS, EMPLOYEES2_PROCESS, EMPLOYEES1_TABLE, EMPLOYEES2_TABLE, EMPLOYEES_UNION_PROCESS, EMPLOYEES_UNION_TABLE); // update propagate flag to 'false' tag1 = getClassification(hdfs_employees, tag1); tag1.setPropagate(false); updateClassifications(hdfs_employees, tag1); assertClassificationNotExistInEntities(propagatedToEntities, tag1); }
@Test(dependsOnMethods = {"addClassification_PropagateFalse"}) public void updateClassification_PropagateFalseToTrue() throws AtlasBaseException { AtlasEntity hdfs_employees = getEntity(HDFS_PATH_EMPLOYEES); AtlasClassification tag2 = new AtlasClassification("tag2"); tag2.setEntityGuid(hdfs_employees.getGuid()); //update tag2 propagate to 'true' tag2 = getClassification(hdfs_employees, tag2); tag2.setPropagate(true); updateClassifications(hdfs_employees, tag2); List<String> propagatedToEntities = Arrays.asList(EMPLOYEES1_PROCESS, EMPLOYEES2_PROCESS, EMPLOYEES1_TABLE, EMPLOYEES2_TABLE, EMPLOYEES_UNION_PROCESS, EMPLOYEES_UNION_TABLE); assertClassificationExistInEntities(propagatedToEntities, tag2); deleteClassification(hdfs_employees, tag2); }
@Test(dependsOnMethods = {"addClassification_PropagateFalse"}) public void updateClassification_PropagateFalseToTrue() throws AtlasBaseException { AtlasEntity hdfs_employees = getEntity(HDFS_PATH_EMPLOYEES); AtlasClassification tag2 = new AtlasClassification("tag2"); tag2.setEntityGuid(hdfs_employees.getGuid()); //update tag2 propagate to 'true' tag2 = getClassification(hdfs_employees, tag2); tag2.setPropagate(true); updateClassifications(hdfs_employees, tag2); List<String> propagatedToEntities = Arrays.asList(EMPLOYEES1_PROCESS, EMPLOYEES2_PROCESS, EMPLOYEES1_TABLE, EMPLOYEES2_TABLE, EMPLOYEES_UNION_PROCESS, EMPLOYEES_UNION_TABLE); assertClassificationExistInEntities(propagatedToEntities, tag2); deleteClassification(hdfs_employees, tag2); }
public AtlasClassification toAtlasClassification(AtlasVertex classificationVertex) throws AtlasBaseException { AtlasClassification ret = new AtlasClassification(getTypeName(classificationVertex)); ret.setEntityGuid(AtlasGraphUtilsV2.getEncodedProperty(classificationVertex, CLASSIFICATION_ENTITY_GUID, String.class)); ret.setEntityStatus(getClassificationEntityStatus(classificationVertex)); ret.setPropagate(isPropagationEnabled(classificationVertex)); ret.setRemovePropagationsOnEntityDelete(getRemovePropagations(classificationVertex)); String strValidityPeriods = AtlasGraphUtilsV2.getEncodedProperty(classificationVertex, CLASSIFICATION_VALIDITY_PERIODS_KEY, String.class); if (strValidityPeriods != null) { ret.setValidityPeriods(AtlasJson.fromJson(strValidityPeriods, TIME_BOUNDARIES_LIST_TYPE)); } mapAttributes(classificationVertex, ret, null); return ret; }
public AtlasClassification toAtlasClassification(AtlasVertex classificationVertex) throws AtlasBaseException { AtlasClassification ret = new AtlasClassification(getTypeName(classificationVertex)); ret.setEntityGuid(AtlasGraphUtilsV2.getEncodedProperty(classificationVertex, CLASSIFICATION_ENTITY_GUID, String.class)); ret.setEntityStatus(getClassificationEntityStatus(classificationVertex)); ret.setPropagate(isPropagationEnabled(classificationVertex)); ret.setRemovePropagationsOnEntityDelete(getRemovePropagations(classificationVertex)); String strValidityPeriods = AtlasGraphUtilsV2.getEncodedProperty(classificationVertex, CLASSIFICATION_VALIDITY_PERIODS_KEY, String.class); if (strValidityPeriods != null) { ret.setValidityPeriods(AtlasJson.fromJson(strValidityPeriods, TIME_BOUNDARIES_LIST_TYPE)); } mapAttributes(classificationVertex, ret, null); return ret; }
@Test(dependsOnMethods = {"addClassification_removePropagationsTrue_DeleteCase"}) public void addClassification_removePropagationsFalse_DeleteCase() throws AtlasBaseException { AtlasEntity employees = getEntity(EMPLOYEES_TABLE); AtlasClassification tag1 = new AtlasClassification("tag1"); tag1.setEntityGuid(employees.getGuid()); tag1.setPropagate(true); tag1.setRemovePropagationsOnEntityDelete(false); addClassification(employees, tag1); List<String> propagatedEntities = Arrays.asList(EMPLOYEES_PROCESS, US_EMPLOYEES_TABLE); assertClassificationExistInEntities(propagatedEntities, tag1); AtlasEntity employees_process = getEntity(EMPLOYEES_PROCESS); AtlasEntity us_employees = getEntity(US_EMPLOYEES_TABLE); deletePropagatedClassificationExpectFail(employees_process, tag1); deletePropagatedClassificationExpectFail(us_employees, tag1); deleteEntity(EMPLOYEES_PROCESS); assertClassificationExistInEntity(EMPLOYEES_PROCESS, tag1); assertClassificationExistInEntity(US_EMPLOYEES_TABLE, tag1); }
@Test(dependsOnMethods = {"addClassification_removePropagationsTrue_DeleteCase"}) public void addClassification_removePropagationsFalse_DeleteCase() throws AtlasBaseException { AtlasEntity employees = getEntity(EMPLOYEES_TABLE); AtlasClassification tag1 = new AtlasClassification("tag1"); tag1.setEntityGuid(employees.getGuid()); tag1.setPropagate(true); tag1.setRemovePropagationsOnEntityDelete(false); addClassification(employees, tag1); List<String> propagatedEntities = Arrays.asList(EMPLOYEES_PROCESS, US_EMPLOYEES_TABLE); assertClassificationExistInEntities(propagatedEntities, tag1); AtlasEntity employees_process = getEntity(EMPLOYEES_PROCESS); AtlasEntity us_employees = getEntity(US_EMPLOYEES_TABLE); deletePropagatedClassificationExpectFail(employees_process, tag1); deletePropagatedClassificationExpectFail(us_employees, tag1); deleteEntity(EMPLOYEES_PROCESS); assertClassificationExistInEntity(EMPLOYEES_PROCESS, tag1); assertClassificationExistInEntity(US_EMPLOYEES_TABLE, tag1); }
@Test(dependsOnMethods = {"removeBlockedPropagatedClassifications"}) public void addClassification_removePropagationsTrue_DeleteCase() throws AtlasBaseException { AtlasEntity orders = getEntity(ORDERS_TABLE); AtlasClassification tag2 = new AtlasClassification("tag2"); tag2.setEntityGuid(orders.getGuid()); tag2.setPropagate(true); tag2.setRemovePropagationsOnEntityDelete(true); addClassification(orders, tag2); List<String> propagatedEntities = Arrays.asList(EMPLOYEES_PROCESS, US_EMPLOYEES_TABLE); assertClassificationExistInEntities(propagatedEntities, tag2); AtlasEntity orders_process = getEntity(ORDERS_PROCESS); AtlasEntity us_orders = getEntity(US_ORDERS_TABLE); deletePropagatedClassificationExpectFail(orders_process, tag2); deletePropagatedClassificationExpectFail(us_orders, tag2); deleteEntity(ORDERS_TABLE); assertClassificationNotExistInEntity(ORDERS_PROCESS, tag2); assertClassificationNotExistInEntity(US_ORDERS_TABLE, tag2); }
@Test(dependsOnMethods = {"removeBlockedPropagatedClassifications"}) public void addClassification_removePropagationsTrue_DeleteCase() throws AtlasBaseException { AtlasEntity orders = getEntity(ORDERS_TABLE); AtlasClassification tag2 = new AtlasClassification("tag2"); tag2.setEntityGuid(orders.getGuid()); tag2.setPropagate(true); tag2.setRemovePropagationsOnEntityDelete(true); addClassification(orders, tag2); List<String> propagatedEntities = Arrays.asList(EMPLOYEES_PROCESS, US_EMPLOYEES_TABLE); assertClassificationExistInEntities(propagatedEntities, tag2); AtlasEntity orders_process = getEntity(ORDERS_PROCESS); AtlasEntity us_orders = getEntity(US_ORDERS_TABLE); deletePropagatedClassificationExpectFail(orders_process, tag2); deletePropagatedClassificationExpectFail(us_orders, tag2); deleteEntity(ORDERS_TABLE); assertClassificationNotExistInEntity(ORDERS_PROCESS, tag2); assertClassificationNotExistInEntity(US_ORDERS_TABLE, tag2); }