use of org.apache.atlas.model.typedef.AtlasTypesDef in project atlas by apache.
the class EntityV2JerseyResourceIT method addNewType.
private String addNewType() throws Exception {
String typeName = "test" + randomString();
AtlasEntityDef classTypeDef = AtlasTypeUtil.createClassTypeDef(typeName, Collections.<String>emptySet(), AtlasTypeUtil.createRequiredAttrDef("name", "string"), AtlasTypeUtil.createRequiredAttrDef("description", "string"));
AtlasTypesDef typesDef = new AtlasTypesDef();
typesDef.getEntityDefs().add(classTypeDef);
createType(typesDef);
return typeName;
}
use of org.apache.atlas.model.typedef.AtlasTypesDef in project atlas by apache.
the class EntityV2JerseyResourceIT method testAddTraitWithValidityPeriod.
@Test(dependsOnMethods = "testGetTraitNames")
public void testAddTraitWithValidityPeriod() throws Exception {
traitName = "PII_Trait" + randomString();
AtlasClassificationDef piiTrait = AtlasTypeUtil.createTraitTypeDef(traitName, Collections.<String>emptySet());
AtlasTypesDef typesDef = new AtlasTypesDef(Collections.emptyList(), Collections.emptyList(), Collections.singletonList(piiTrait), Collections.emptyList());
createType(typesDef);
String tableGuid = createHiveTable().getGuid();
AtlasClassification classification = new AtlasClassification(piiTrait.getName());
TimeBoundary validityPeriod = new TimeBoundary("2018/03/01 00:00:00", "2018/04/01 00:00:00", "GMT");
classification.setEntityGuid(tableGuid);
classification.addValityPeriod(validityPeriod);
atlasClientV2.addClassifications(tableGuid, Collections.singletonList(classification));
assertEntityAudit(tableGuid, EntityAuditEvent.EntityAuditAction.TAG_ADD);
AtlasClassifications classifications = atlasClientV2.getClassifications(tableGuid);
assertNotNull(classifications);
assertNotNull(classifications.getList());
assertTrue(classifications.getList().size() > 1);
boolean foundClassification = false;
for (AtlasClassification entityClassification : classifications.getList()) {
if (StringUtils.equalsIgnoreCase(entityClassification.getTypeName(), piiTrait.getName())) {
foundClassification = true;
assertEquals(entityClassification.getTypeName(), piiTrait.getName());
assertNotNull(entityClassification.getValidityPeriods());
assertEquals(entityClassification.getValidityPeriods().size(), 1);
assertEquals(entityClassification.getValidityPeriods().get(0), validityPeriod);
assertEquals(entityClassification, classification);
break;
}
}
assertTrue(foundClassification, "classification '" + piiTrait.getName() + "' is missing for entity '" + tableGuid + "'");
}
use of org.apache.atlas.model.typedef.AtlasTypesDef in project atlas by apache.
the class EntityV2JerseyResourceIT method testAddTrait.
@Test(dependsOnMethods = "testGetTraitNames")
public void testAddTrait() throws Exception {
traitName = "PII_Trait" + randomString();
AtlasClassificationDef piiTrait = AtlasTypeUtil.createTraitTypeDef(traitName, Collections.<String>emptySet());
AtlasTypesDef typesDef = new AtlasTypesDef();
typesDef.getClassificationDefs().add(piiTrait);
createType(typesDef);
atlasClientV2.addClassifications(createHiveTable().getGuid(), Collections.singletonList(new AtlasClassification(piiTrait.getName())));
assertEntityAudit(createHiveTable().getGuid(), EntityAuditEvent.EntityAuditAction.TAG_ADD);
}
use of org.apache.atlas.model.typedef.AtlasTypesDef in project atlas by apache.
the class EntityV2JerseyResourceIT method testAddTraitWithAttribute.
@Test(dependsOnMethods = "testGetTraitNames")
public void testAddTraitWithAttribute() throws Exception {
final String traitName = "PII_Trait" + randomString();
AtlasClassificationDef piiTrait = AtlasTypeUtil.createTraitTypeDef(traitName, Collections.<String>emptySet(), 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, Collections.singletonList(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);
}
use of org.apache.atlas.model.typedef.AtlasTypesDef in project atlas by apache.
the class TypedefsJerseyResourceIT method testListTypesByFilter.
@Test
public void testListTypesByFilter() throws Exception {
AtlasAttributeDef attr = AtlasTypeUtil.createOptionalAttrDef("attr", "string");
AtlasEntityDef classDefA = AtlasTypeUtil.createClassTypeDef("A" + randomString(), Collections.<String>emptySet(), attr);
AtlasEntityDef classDefA1 = AtlasTypeUtil.createClassTypeDef("A1" + randomString(), Collections.singleton(classDefA.getName()), attr);
AtlasEntityDef classDefB = AtlasTypeUtil.createClassTypeDef("B" + randomString(), Collections.<String>emptySet(), attr);
AtlasEntityDef classDefC = AtlasTypeUtil.createClassTypeDef("C" + randomString(), new HashSet<>(Arrays.asList(classDefB.getName(), classDefA.getName())), attr);
AtlasTypesDef atlasTypesDef = new AtlasTypesDef();
atlasTypesDef.getEntityDefs().add(classDefA);
atlasTypesDef.getEntityDefs().add(classDefA1);
atlasTypesDef.getEntityDefs().add(classDefB);
atlasTypesDef.getEntityDefs().add(classDefC);
AtlasTypesDef created = clientV2.createAtlasTypeDefs(atlasTypesDef);
assertNotNull(created);
assertEquals(created.getEntityDefs().size(), atlasTypesDef.getEntityDefs().size());
MultivaluedMap<String, String> searchParams = new MultivaluedMapImpl();
searchParams.add(SearchFilter.PARAM_TYPE, "CLASS");
searchParams.add(SearchFilter.PARAM_SUPERTYPE, classDefA.getName());
SearchFilter searchFilter = new SearchFilter(searchParams);
AtlasTypesDef searchDefs = clientV2.getAllTypeDefs(searchFilter);
assertNotNull(searchDefs);
assertEquals(searchDefs.getEntityDefs().size(), 2);
searchParams.add(SearchFilter.PARAM_NOT_SUPERTYPE, classDefB.getName());
searchFilter = new SearchFilter(searchParams);
searchDefs = clientV2.getAllTypeDefs(searchFilter);
assertNotNull(searchDefs);
assertEquals(searchDefs.getEntityDefs().size(), 1);
}
Aggregations