Example usage for org.springframework.data.domain Sort Sort

List of usage examples for org.springframework.data.domain Sort Sort

Introduction

In this page you can find the example usage for org.springframework.data.domain Sort Sort.

Prototype

private Sort(Direction direction, List<String> properties) 

Source Link

Document

Creates a new Sort instance.

Usage

From source file:org.starfishrespect.myconsumption.server.business.repositories.repositoriesimpl.ValuesRepositoryImpl.java

@Override
public List<SensorDataset> getSensor(Date startTime, Date endTime) throws DaoException {
    Query timeQuery = new Query(new Criteria().andOperator(Criteria.where("timestamp").gte(startTime),
            Criteria.where("timestamp").lte(endTime)));
    timeQuery.with(new Sort(Sort.Direction.ASC, "timestamp"));
    return mongoOperation.find(timeQuery, SensorDataset.class, collectionName);
}

From source file:com.epam.ta.reportportal.database.dao.LoadWithLineGraphCallbackTest.java

@Test
@Ignore/*from  w  w w.ja v a  2  s  .co  m*/
// TODO After complete widget refactoring!
public void testloadWithCallback() {
    Filter filter = new Filter(Launch.class, Condition.CONTAINS, false, "launch", "name");
    Sort sort = new Sort(Direction.DESC, "name");

    String totalField = criteriaMap.getCriteriaHolder("statistics$executions$total").getQueryCriteria();
    String failedField = criteriaMap.getCriteriaHolder("statistics$executions$failed").getQueryCriteria();
    String bugsField = criteriaMap.getCriteriaHolder("statistics$defects$product_bugs").getQueryCriteria();

    String nameField = criteriaMap.getCriteriaHolder("name").getQueryCriteria();

    List<String> chartFields = Lists.newArrayList(totalField, failedField, bugsField);
    // statistics added because MongoDB can't load fields like
    // statistics.executions.failed
    List<String> allFields = Lists.newArrayList(totalField, failedField, nameField, "statistics");

    // StatisticsDocumentHandler callback = new
    // StatisticsDocumentHandler(chartFields,
    // Lists.newArrayList(nameField));
    // launchRepository.loadWithCallback(filter, sort, 5, allFields,
    // callback, "launch");
    // List<ChartObject> result = callback.getResult();
    //
    // Map<String, List<AxisObject>> total = result.get(totalField);
    // Map<String, List<AxisObject>> failed = result.get(failedField);
    // Map<String, List<AxisObject>> bugs = result.get(bugsField);
    // Assert.assertNotNull(bugs);
    // Assert.assertNotNull(total);
    // Assert.assertNotNull(failed);
    // List<AxisObject> bugsXaxis =
    // bugs.get(StatisticsDocumentHandler.X_AXIS_DOTS);
    // List<AxisObject> bugsYaxis =
    // bugs.get(StatisticsDocumentHandler.Y_AXIS_DOTS);
    //
    // List<AxisObject> totalXaxis =
    // total.get(StatisticsDocumentHandler.X_AXIS_DOTS);
    // List<AxisObject> totalYaxis =
    // total.get(StatisticsDocumentHandler.Y_AXIS_DOTS);
    //
    // List<AxisObject> failedXaxis =
    // failed.get(StatisticsDocumentHandler.X_AXIS_DOTS);
    // List<AxisObject> failedYaxis =
    // failed.get(StatisticsDocumentHandler.Y_AXIS_DOTS);
    //
    // Assert.assertNotNull(bugsXaxis);
    // Assert.assertNotNull(bugsYaxis);
    // Assert.assertNotNull(totalXaxis);
    // Assert.assertNotNull(totalYaxis);
    // Assert.assertNotNull(failedXaxis);
    // Assert.assertNotNull(failedYaxis);
    //
    // List<String> bugzz = Lists.newArrayList("0", "0", "0");
    // for (AxisObject ax : bugsYaxis) {
    // Assert.assertEquals(ax.getValue(), bugzz.get(bugsYaxis.indexOf(ax)));
    // }
    //
    // List<String> totalzz = Lists.newArrayList("4", "4", "0");
    // for (AxisObject ax2 : totalYaxis) {
    // Assert.assertEquals(ax2.getValue(),
    // totalzz.get(totalYaxis.indexOf(ax2)));
    // }
    //
    // List<String> failedzz = Lists.newArrayList("4", "1", "0");
    // for (AxisObject ax3 : failedYaxis) {
    // Assert.assertEquals(ax3.getValue(),
    // failedzz.get(failedYaxis.indexOf(ax3)));
    // }
    //
    // List<String> bugsXaxisNames =
    // Lists.newArrayList("launch for call back validation",
    // "Demo launch_launch1-stat",
    // "Demo launch name_sxbOa2");
    // for (AxisObject axXname : bugsXaxis) {
    // Assert.assertEquals(axXname.getName(),
    // bugsXaxisNames.get(bugsXaxis.indexOf(axXname)));
    // }
    //
    // Assert.assertEquals(bugsXaxis, totalXaxis);
    // Assert.assertEquals(bugsXaxis, failedXaxis);
    // Assert.assertEquals(totalXaxis, failedXaxis);
}

From source file:org.apigw.authserver.svc.impl.AdministrationServicesImpl.java

@Override
public List<CertifiedClient> findAllCertifiedClients() {
    return certifiedClientRepository.findAll(new Sort(Sort.Direction.ASC, "id"));
}

From source file:com.restfiddle.controller.rest.ConversationController.java

@RequestMapping(value = "/api/conversations", method = RequestMethod.GET)
public @ResponseBody PaginatedResponse<ConversationDTO> findAll(
        @RequestParam(value = "page", required = false) Integer page,
        @RequestParam(value = "limit", required = false) Integer limit) {
    logger.debug("Finding all items");

    int pageNo = 0;
    if (page != null && page > 0) {
        pageNo = page;/*from  w  w w  .  j  av  a  2 s . c o m*/
    }

    int numberOfRecords = 10;
    if (limit != null && limit > 0) {
        numberOfRecords = limit;
    }

    Sort sort = new Sort(Direction.DESC, "lastModifiedDate");
    Pageable topRecords = new PageRequest(pageNo, numberOfRecords, sort);
    Page<Conversation> result = itemRepository.findAll(topRecords);

    List<Conversation> content = result.getContent();

    List<ConversationDTO> responseContent = new ArrayList<ConversationDTO>();
    for (Conversation item : content) {
        responseContent.add(EntityToDTO.toDTO(item));
    }

    PaginatedResponse<ConversationDTO> response = new PaginatedResponse<ConversationDTO>();
    response.setData(responseContent);
    response.setLimit(numberOfRecords);
    response.setPage(pageNo);
    response.setTotalElements(result.getTotalElements());
    response.setTotalPages(result.getTotalPages());

    for (Conversation item : content) {
        RfRequest rfRequest = item.getRfRequest();
        logger.debug(rfRequest.getApiUrl());
    }
    return response;
}

From source file:sk.lazyman.gizmo.web.app.PageEmails.java

private void initLayout() {
    Form form = new Form(ID_FORM);
    add(form);//w w w.ja v  a 2s .  co m

    form.add(new DateTextField(ID_FROM, new PropertyModel<Date>(filter, EmailFilterDto.F_FROM),
            GizmoUtils.DATE_FIELD_FORMAT));
    form.add(new DateTextField(ID_TO, new PropertyModel<Date>(filter, EmailFilterDto.F_TO),
            GizmoUtils.DATE_FIELD_FORMAT));

    form.add(new DropDownChoice<User>(ID_SENDER, new PropertyModel<User>(filter, EmailFilterDto.F_SENDER),
            GizmoUtils.createUsersModel(this), new IChoiceRenderer<User>() {

                @Override
                public Object getDisplayValue(User object) {
                    return object.getFullName();
                }

                @Override
                public String getIdValue(User object, int index) {
                    return Integer.toString(index);
                }
            }) {

        @Override
        protected String getNullValidKey() {
            return "PageEmails.sender";
        }
    });

    form.add(new AjaxSubmitButton(ID_FILTER, createStringResource("PageEmails.filter")) {

        @Override
        protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
            filterLogs(target);
        }

        @Override
        protected void onError(AjaxRequestTarget target, Form<?> form) {
            target.add(getFeedbackPanel());
        }
    });

    BasicDataProvider provider = new EmailDataProvider(getEmailLogRepository(), 15);
    provider.setSort(new Sort(Sort.Direction.DESC, EmailLog.F_SENT_DATE));

    List<IColumn> columns = new ArrayList<>();
    columns.add(new DateColumn(createStringResource("EmailLog.sentDate"), EmailLog.F_SENT_DATE,
            "dd. MMM, yyyy HH:mm:ss"));
    columns.add(new AbstractColumn<EmailLog, String>(createStringResource("EmailLog.sender")) {

        @Override
        public void populateItem(Item<ICellPopulator<EmailLog>> item, String componentId,
                final IModel<EmailLog> rowModel) {
            item.add(new Label(componentId, new AbstractReadOnlyModel<String>() {

                @Override
                public String getObject() {
                    EmailLog log = rowModel.getObject();
                    return log.getSender().getFullName();
                }
            }));
        }
    });
    columns.add(new IconColumn<EmailLog>(createStringResource("EmailLog.successful")) {

        @Override
        protected IModel<String> createTitleModel(IModel<EmailLog> rowModel) {
            EmailLog log = rowModel.getObject();
            String key = log.isSuccessful() ? "PageEmails.success" : "PageEmails.failure";
            return createStringResource(key);
        }

        @Override
        protected IModel<String> createIconModel(final IModel<EmailLog> rowModel) {
            return new AbstractReadOnlyModel<String>() {

                @Override
                public String getObject() {
                    EmailLog log = rowModel.getObject();
                    return "fa fa-fw fa-lg " + (log.isSuccessful() ? "fa-check-circle text-success"
                            : "fa-times-circle text-danger");
                }
            };
        }
    });
    columns.add(new PropertyColumn(createStringResource("EmailLog.mailTo"), EmailLog.F_MAIL_TO));
    columns.add(
            new DateColumn(createStringResource("EmailLog.fromDate"), EmailLog.F_FROM_DATE, "dd. MMM, yyyy"));
    columns.add(new DateColumn(createStringResource("EmailLog.toDate"), EmailLog.F_TO_DATE, "dd. MMM, yyyy"));
    columns.add(new PropertyColumn(createStringResource("EmailLog.summaryWork"), EmailLog.F_SUMMARY_WORK));
    columns.add(
            new PropertyColumn(createStringResource("EmailLog.summaryInvoice"), EmailLog.F_SUMMARY_INVOICE));
    columns.add(new AbstractColumn<EmailLog, String>(createStringResource("EmailLog.realizators")) {

        @Override
        public void populateItem(Item<ICellPopulator<EmailLog>> cellItem, String componentId,
                IModel<EmailLog> rowModel) {

            MultiLineLabel label = new MultiLineLabel(componentId, createRealizators(rowModel));
            cellItem.add(label);
        }
    });
    columns.add(new AbstractColumn<EmailLog, String>(createStringResource("EmailLog.projects")) {

        @Override
        public void populateItem(Item<ICellPopulator<EmailLog>> cellItem, String componentId,
                final IModel<EmailLog> rowModel) {
            MultiLineLabel label = new MultiLineLabel(componentId, createProjects(rowModel));
            cellItem.add(label);
        }
    });
    columns.add(new AbstractColumn<EmailLog, String>(createStringResource("EmailLog.customers")) {

        @Override
        public void populateItem(Item<ICellPopulator<EmailLog>> cellItem, String componentId,
                final IModel<EmailLog> rowModel) {
            MultiLineLabel label = new MultiLineLabel(componentId, createCustomers(rowModel));
            cellItem.add(label);
        }
    });

    TablePanel table = new TablePanel(ID_TABLE, provider, columns, 15);
    table.setOutputMarkupId(true);
    add(table);
}

From source file:com.seajas.search.profiler.service.repository.RepositoryService.java

/**
 * Retrieve a paged list of all resources within the repository.
 *
 * @param collection//from   w  w w  .j  a v a 2s . c o  m
 * @param sourceId
 * @param taxonomyMatch
 * @param startDate
 * @param endDate
 * @param pagerStart
 * @param pagerResults
 * @param parameters
 * @return RepositoryResult
 */
public RepositoryResult findResources(final String collection, final Integer sourceId,
        final String taxonomyMatch, final Date startDate, final Date endDate, final Integer pagerStart,
        final Integer pagerResults, final Map<String, String> parameters) {
    Query query = createQuery(false, collection, sourceId, taxonomyMatch, startDate, endDate, null, parameters);

    query.with(new Sort(Sort.Direction.DESC, "originalContent.dateSubmitted"));

    if (logger.isInfoEnabled())
        logger.info("About to count the number of results - which can potentially take a while - query = "
                + query.toString());

    // First perform a count

    Long totalResults = mongoTemplate.count(query, defaultCollection);

    if (logger.isInfoEnabled())
        logger.info("Counted " + totalResults + " result(s) to be retrieved from the storage back-end");

    // Then add paging parameters to the query

    query.skip(pagerStart);
    query.limit(pagerResults);

    // And build up the result

    List<RepositoryResource> results = new ArrayList<RepositoryResource>(pagerResults);
    List<CompositeEntry> entries = mongoTemplate.find(query, CompositeEntry.class, defaultCollection);

    for (CompositeEntry entry : entries)
        results.add(new RepositoryResource(entry.getOriginalContent().getUri().toString(),
                entry.getSource().getCollection(), entry.getSource().getId(),
                entry.getOriginalContent().getHostname(), entry.getOriginalContent().getDateSubmitted(),
                entry.getId().toString()));

    return new RepositoryResult(pagerStart, pagerResults, totalResults, results);
}

From source file:com.appleframework.monitor.service.AlertService.java

public List<Alert> findAlerts(String projectName) {
    Query query = Query.query(Criteria.where("projectName").is(projectName)).limit(50);
    //query.sort().on("createTime", Order.DESCENDING);
    query.with(new Sort(Direction.DESC, "createTime"));
    return mongoTemplate.find(query, Alert.class, collectionName);
}

From source file:org.centralperf.service.RunService.java

/**
 * Return last X runs accross all projects, ordered by startDate desc (newer first)
 * @return A list of run, limited to X runs
 *///from w  w w.  j a  v a2  s  .  c  o  m
public List<Run> getLastRuns() {
    return runRepository.findAll(new PageRequest(0, 10, new Sort(Sort.Direction.DESC, "startDate")))
            .getContent();
}

From source file:org.oncoblocks.centromere.sql.test.SqlBuilderTests.java

@Test
public void orderByTest() {

    Sort sort = new Sort(new Sort.Order(Sort.Direction.ASC, "name"),
            new Sort.Order(Sort.Direction.DESC, "gender"));
    SqlBuilder sqlBuilder = new SqlBuilder(tableDescription);
    sqlBuilder.orderBy(sort);//from  w  w w.  j  a v  a2  s.  com

    String sql = sqlBuilder.toSql();
    System.out.println(sql);
    Assert.notNull(sql);

    sqlBuilder.orderBy(new Sort.Order(Sort.Direction.ASC, "name"));

    sql = sqlBuilder.toSql();
    System.out.println(sql);
    Assert.notNull(sql);

    sqlBuilder.orderBy("name");

    sql = sqlBuilder.toSql();
    System.out.println(sql);
    Assert.notNull(sql);

}

From source file:com.luna.common.repository.RepositoryHelperIT.java

@Test
public void testFindAllWithSort() {

    repositoryHelper.batchUpdate("delete from User");

    User user1 = createUser();/*www . j  ava2s  .  com*/
    User user2 = createUser();
    User user3 = createUser();
    User user4 = createUser();
    repositoryHelper.getEntityManager().persist(user1);
    repositoryHelper.getEntityManager().persist(user2);
    repositoryHelper.getEntityManager().persist(user3);
    repositoryHelper.getEntityManager().persist(user4);

    String ql = "select o from User o";

    List<User> list = repositoryHelper.findAll(ql, new Sort(Sort.Direction.DESC, "id"));

    Assert.assertEquals(4, list.size());

    Assert.assertTrue(list.get(0).equals(user4));
}