Java Code Examples for org.apache.atlas.model.discovery.SearchParameters#setSortBy()

The following examples show how to use org.apache.atlas.model.discovery.SearchParameters#setSortBy() . 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: AtlasAuditService.java    From atlas with Apache License 2.0 6 votes vote down vote up
private SearchParameters getSearchParameters(AuditSearchParameters auditSearchParameters) throws AtlasBaseException {
    SearchParameters searchParameters = new SearchParameters();
    searchParameters.setTypeName(ENTITY_TYPE_AUDIT_ENTRY);

    SearchParameters.FilterCriteria validFilter = getNonEmptyFilter(auditSearchParameters.getAuditFilters());
    searchParameters.setEntityFilters(validFilter);

    searchParameters.setLimit(auditSearchParameters.getLimit());
    searchParameters.setOffset(auditSearchParameters.getOffset());

    String sortBy = auditSearchParameters.getSortBy();
    validateSortByParameter(sortBy);

    searchParameters.setSortBy(auditSearchParameters.getSortBy());
    searchParameters.setSortOrder(auditSearchParameters.getSortOrder());

    return searchParameters;
}
 
Example 2
Source File: EntitySearchProcessorTest.java    From atlas with Apache License 2.0 5 votes vote down vote up
@Test
public void searchByClassificationSortBy() throws AtlasBaseException {
    SearchParameters params = new SearchParameters();
    params.setTypeName("hive_table");
    params.setClassification("Metric");
    params.setLimit(10);
    params.setSortBy("createTime");
    params.setSortOrder(SortOrder.ASCENDING);

    SearchContext context = new SearchContext(params, typeRegistry, graph, Collections.<String>emptySet());
    EntitySearchProcessor processor = new EntitySearchProcessor(context);

    List<AtlasVertex> vertices = processor.execute();

    assertEquals(processor.getResultCount(), 4);
    assertEquals(vertices.size(), 4);


    AtlasVertex firstVertex = vertices.get(0);

    Date firstDate = (Date) entityRetriever.toAtlasEntityHeader(firstVertex, Sets.newHashSet(params.getSortBy())).getAttribute(params.getSortBy());

    AtlasVertex secondVertex = vertices.get(1);
    Date secondDate = (Date) entityRetriever.toAtlasEntityHeader(secondVertex, Sets.newHashSet(params.getSortBy())).getAttribute(params.getSortBy());

    assertTrue(firstDate.before(secondDate));
}
 
Example 3
Source File: FreeTextSearchProcessorTest.java    From atlas with Apache License 2.0 5 votes vote down vote up
@Test
public void searchByNameSortBy() throws AtlasBaseException, InterruptedException {
    SearchParameters params = new SearchParameters();
    params.setTypeName("hive_table");
    params.setQuery("sales");
    params.setExcludeDeletedEntities(true);
    params.setLimit(3);
    params.setSortBy("owner");
    params.setSortOrder(SortOrder.ASCENDING);

    SearchContext context = new SearchContext(params, typeRegistry, graph, Collections.<String>emptySet());

    FreeTextSearchProcessor processor = new FreeTextSearchProcessor(context);

    List<AtlasVertex> vertices = processor.execute();

    assertEquals(processor.getResultCount(), 3);
    assertEquals(vertices.size(), 3);

    AtlasVertex firstVertex = vertices.get(0);

    String firstOwner = (String) entityRetriever.toAtlasEntityHeader(firstVertex, Sets.newHashSet(params.getSortBy())).getAttribute(params.getSortBy());

    AtlasVertex secondVertex = vertices.get(1);
    String secondOwner = (String) entityRetriever.toAtlasEntityHeader(secondVertex, Sets.newHashSet(params.getSortBy())).getAttribute(params.getSortBy());

    assertEquals(firstOwner, "Jane BI");
    assertEquals(secondOwner, "Joe");
}