Search in sources :

Example 6 with SearchFilter

use of org.apache.atlas.model.SearchFilter in project atlas by apache.

the class QuickStartV2 method verifyTypesCreated.

private void verifyTypesCreated() throws Exception {
    MultivaluedMap<String, String> searchParams = new MultivaluedMapImpl();
    for (String typeName : TYPES) {
        searchParams.clear();
        searchParams.add(SearchFilter.PARAM_NAME, typeName);
        SearchFilter searchFilter = new SearchFilter(searchParams);
        AtlasTypesDef searchDefs = atlasClientV2.getAllTypeDefs(searchFilter);
        assert (!searchDefs.isEmpty());
        System.out.println("Created type [" + typeName + "]");
    }
}
Also used : MultivaluedMapImpl(com.sun.jersey.core.util.MultivaluedMapImpl) SearchFilter(org.apache.atlas.model.SearchFilter) AtlasTypesDef(org.apache.atlas.model.typedef.AtlasTypesDef)

Example 7 with SearchFilter

use of org.apache.atlas.model.SearchFilter 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);
}
Also used : AtlasEntityDef(org.apache.atlas.model.typedef.AtlasEntityDef) AtlasAttributeDef(org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef) MultivaluedMapImpl(com.sun.jersey.core.util.MultivaluedMapImpl) SearchFilter(org.apache.atlas.model.SearchFilter) AtlasTypesDef(org.apache.atlas.model.typedef.AtlasTypesDef) Test(org.testng.annotations.Test)

Example 8 with SearchFilter

use of org.apache.atlas.model.SearchFilter in project atlas by apache.

the class TypedefsJerseyResourceIT method testUpdate.

@Test
public void testUpdate() throws Exception {
    String entityType = randomString();
    AtlasEntityDef typeDefinition = createClassTypeDef(entityType, Collections.<String>emptySet(), AtlasTypeUtil.createUniqueRequiredAttrDef("name", "string"));
    AtlasTypesDef atlasTypesDef = new AtlasTypesDef();
    atlasTypesDef.getEntityDefs().add(typeDefinition);
    AtlasTypesDef createdTypeDefs = clientV2.createAtlasTypeDefs(atlasTypesDef);
    assertNotNull(createdTypeDefs);
    assertEquals(createdTypeDefs.getEntityDefs().size(), atlasTypesDef.getEntityDefs().size());
    // Add attribute description
    typeDefinition = createClassTypeDef(typeDefinition.getName(), Collections.<String>emptySet(), AtlasTypeUtil.createUniqueRequiredAttrDef("name", "string"), AtlasTypeUtil.createOptionalAttrDef("description", "string"));
    emptyTypeDefs(atlasTypesDef);
    atlasTypesDef.getEntityDefs().add(typeDefinition);
    AtlasTypesDef updatedTypeDefs = clientV2.updateAtlasTypeDefs(atlasTypesDef);
    assertNotNull(updatedTypeDefs);
    assertEquals(updatedTypeDefs.getEntityDefs().size(), atlasTypesDef.getEntityDefs().size());
    assertEquals(updatedTypeDefs.getEntityDefs().get(0).getName(), atlasTypesDef.getEntityDefs().get(0).getName());
    MultivaluedMap<String, String> filterParams = new MultivaluedMapImpl();
    filterParams.add(SearchFilter.PARAM_TYPE, "ENTITY");
    AtlasTypesDef allTypeDefs = clientV2.getAllTypeDefs(new SearchFilter(filterParams));
    assertNotNull(allTypeDefs);
    Boolean entityDefFound = false;
    for (AtlasEntityDef atlasEntityDef : allTypeDefs.getEntityDefs()) {
        if (atlasEntityDef.getName().equals(typeDefinition.getName())) {
            assertEquals(atlasEntityDef.getAttributeDefs().size(), 2);
            entityDefFound = true;
            break;
        }
    }
    assertTrue(entityDefFound, "Required entityDef not found.");
}
Also used : AtlasEntityDef(org.apache.atlas.model.typedef.AtlasEntityDef) MultivaluedMapImpl(com.sun.jersey.core.util.MultivaluedMapImpl) SearchFilter(org.apache.atlas.model.SearchFilter) AtlasTypesDef(org.apache.atlas.model.typedef.AtlasTypesDef) Test(org.testng.annotations.Test)

Example 9 with SearchFilter

use of org.apache.atlas.model.SearchFilter in project incubator-atlas by apache.

the class AtlasTypeDefGraphStoreTest method testCreateDept.

@Test(dependsOnMethods = { "testGet" }, dataProvider = "validCreateDeptTypes")
public void testCreateDept(AtlasTypesDef atlasTypesDef) {
    AtlasTypesDef existingTypesDef = null;
    try {
        existingTypesDef = typeDefStore.searchTypesDef(new SearchFilter());
    } catch (AtlasBaseException e) {
    // ignore
    }
    assertNotEquals(atlasTypesDef, existingTypesDef, "Types to be created already exist in the system");
    AtlasTypesDef createdTypesDef = null;
    try {
        createdTypesDef = typeDefStore.createTypesDef(atlasTypesDef);
        assertNotNull(createdTypesDef);
        assertTrue(createdTypesDef.getEnumDefs().containsAll(atlasTypesDef.getEnumDefs()), "EnumDefs create failed");
        assertTrue(createdTypesDef.getClassificationDefs().containsAll(atlasTypesDef.getClassificationDefs()), "ClassificationDef create failed");
        assertTrue(createdTypesDef.getStructDefs().containsAll(atlasTypesDef.getStructDefs()), "StructDef creation failed");
        Assert.assertEquals(createdTypesDef.getEntityDefs(), atlasTypesDef.getEntityDefs());
    } catch (AtlasBaseException e) {
        fail("Creation of Types should've been a success", e);
    }
}
Also used : AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) SearchFilter(org.apache.atlas.model.SearchFilter) AtlasTypesDef(org.apache.atlas.model.typedef.AtlasTypesDef) Test(org.testng.annotations.Test)

Example 10 with SearchFilter

use of org.apache.atlas.model.SearchFilter in project incubator-atlas by apache.

the class AtlasTypeDefGraphStoreTest method testSearchFunctionality.

@Test(dependsOnMethods = "testGet")
public void testSearchFunctionality() {
    SearchFilter searchFilter = new SearchFilter();
    searchFilter.setParam(SearchFilter.PARAM_SUPERTYPE, "Person");
    try {
        AtlasTypesDef typesDef = typeDefStore.searchTypesDef(searchFilter);
        assertNotNull(typesDef);
        assertNotNull(typesDef.getEntityDefs());
        assertEquals(typesDef.getEntityDefs().size(), 3);
    } catch (AtlasBaseException e) {
        fail("Search should've succeeded", e);
    }
}
Also used : AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) SearchFilter(org.apache.atlas.model.SearchFilter) AtlasTypesDef(org.apache.atlas.model.typedef.AtlasTypesDef) Test(org.testng.annotations.Test)

Aggregations

SearchFilter (org.apache.atlas.model.SearchFilter)20 AtlasTypesDef (org.apache.atlas.model.typedef.AtlasTypesDef)14 Test (org.testng.annotations.Test)10 MultivaluedMapImpl (com.sun.jersey.core.util.MultivaluedMapImpl)7 AtlasBaseException (org.apache.atlas.exception.AtlasBaseException)6 AtlasEntityDef (org.apache.atlas.model.typedef.AtlasEntityDef)4 AtlasAttributeDef (org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef)2 BeforeTest (org.testng.annotations.BeforeTest)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 AtlasClientV2 (org.apache.atlas.AtlasClientV2)1 AtlasServiceException (org.apache.atlas.AtlasServiceException)1 AtlasSearchResult (org.apache.atlas.model.discovery.AtlasSearchResult)1 SearchParameters (org.apache.atlas.model.discovery.SearchParameters)1 AtlasClassification (org.apache.atlas.model.instance.AtlasClassification)1 AtlasEntityHeader (org.apache.atlas.model.instance.AtlasEntityHeader)1 AtlasTypeRegistry (org.apache.atlas.type.AtlasTypeRegistry)1