List of usage examples for org.springframework.data.domain Sort Sort
private Sort(Direction direction, List<String> properties)
From source file:com.traffitruck.service.MongoDAO.java
public List<Load> getLoadsWithoutTruckByFilter(Double sourceLat, Double sourceLng, Integer source_radius, Double destinationLat, Double destinationLng, Integer destination_radius) { // The criteria API isn't good enough String query = "{"; query += "weight: { $exists: true } "; // dummy for handling commas if (sourceLat != null && sourceLng != null && source_radius != null) { query += ", sourceLocation : { $geoWithin : { $centerSphere: [ [" + sourceLng + ", " + sourceLat + "], " + source_radius / EARTH_RADIUS_IN_RADIANS + "] } }"; }/*from ww w. j a v a2 s . c om*/ if (destinationLat != null && destinationLng != null && destination_radius != null) { query += ", destinationLocation : { $geoWithin : { $centerSphere: [ [" + destinationLng + ", " + destinationLat + "], " + destination_radius / EARTH_RADIUS_IN_RADIANS + "] } }"; } // no need for the photo here query += "} , {loadPhoto:0}"; BasicQuery queryobj = new BasicQuery(query); // sort results queryobj.with(new Sort(Direction.DESC, "driveDate")); List<Load> coll = mongoTemplate.find(queryobj, Load.class); coll.stream().forEach(load -> load.setLoadPhoto(null)); return coll; }
From source file:org.wallride.service.UserService.java
public List<UserInvitation> getUserInvitations() { return userInvitationRepository.findAll(new Sort(Sort.Direction.DESC, "createdAt")); }
From source file:com.mobileman.kuravis.core.services.event.impl.EventServiceImpl.java
@Override public TreatmentEvent findLastTreatmentEvent(String userId, String diseaseId, String treatmentId) { Query query = Query.query(Criteria.where(TreatmentEvent.USER_ID).is(userId).and(TreatmentEvent.DISEASE_ID) .is(diseaseId).and(TreatmentEvent.TREATMENT_ID).is(treatmentId)); query.with(new Sort(Sort.Direction.DESC, TreatmentEvent.CREATED_ON)); query.limit(1);//from ww w . j ava 2 s . com return getMongoTemplate().findOne(query, TreatmentEvent.class); }
From source file:org.callistasoftware.netcare.core.spi.impl.HealthPlanServiceImpl.java
@Override public ServiceResult<HealthPlanStatistics> getStatisticsForHealthPlan(Long healthPlanId) { getLog().info("Getting statistics for health plans..."); final HealthPlanStatistics stats = new HealthPlanStatistics(); final HealthPlanEntity healthPlan = this.repo.findOne(healthPlanId); if (healthPlan == null) { return ServiceResultImpl .createFailedResult(new EntityNotFoundMessage(HealthPlanEntity.class, healthPlanId)); }//from ww w . j a v a 2 s.c o m this.verifyReadAccess(healthPlan); getLog().debug("Calculating health plan overview..."); final ScheduledActivity[] activities = this.getScheduledActivitiesForHealthPlan(healthPlanId).getData(); final List<ActivityCount> activityCount = new ArrayList<ActivityCount>(); for (final ScheduledActivity ac : activities) { final String name = ac.getActivityDefinition().getType().getName(); final ActivityCount act = new ActivityCount(name); final ActivityCount existing = this.findActivityCount(name, activityCount); if (existing == null) { getLog().debug("Activity count not in list. Adding {}", act.getName()); activityCount.add(act); } this.findActivityCount(name, activityCount).increaseCount(); } stats.setActivities(activityCount); getLog().debug("Health plan overview calculated."); /* * Get all reported activities */ getLog().debug("Calculating reported activities..."); final List<ScheduledActivityEntity> ents = this.scheduledActivityRepository .findReportedActivitiesForHealthPlan(healthPlanId, healthPlan.getStartDate(), new Date(), new Sort(Sort.Direction.ASC, "scheduledTime")); final List<MeasuredValue> measuredValues = new ArrayList<MeasuredValue>(); for (final ScheduledActivityEntity schedActivityEntity : ents) { final ReportedActivity ra = new ReportedActivity(); ra.setName(schedActivityEntity.getActivityDefinitionEntity().getActivityType().getName()); ra.setNote(schedActivityEntity.getNote()); ra.setReportedAt(DateUtil.toDateTime(schedActivityEntity.getReportedTime())); ra.setLabel(DateUtil.toDateTime(schedActivityEntity.getScheduledTime())); final List<ActivityItemValuesEntity> activityItemValues = schedActivityEntity.getActivities(); for (final ActivityItemValuesEntity valueEntity : activityItemValues) { if (valueEntity instanceof MeasurementEntity) { MeasurementEntity m = (MeasurementEntity) valueEntity; MeasurementTypeEntity type = (MeasurementTypeEntity) m.getActivityItemDefinitionEntity() .getActivityItemType(); final String measurementName = type.getName(); MeasuredValue mv = this.findMeasuredValue(measurementName, measuredValues); if (mv == null) { mv = new MeasuredValue(); mv.setName(schedActivityEntity.getActivityDefinitionEntity().getActivityType().getName()); mv.setDefinitionId(schedActivityEntity.getActivityDefinitionEntity().getId()); mv.setValueType(new Option(measurementName, null)); mv.setUnit(MeasureUnitImpl.newFromEntity(type.getUnit())); mv.setInterval(type.equals(MeasurementValueType.INTERVAL)); measuredValues.add(mv); } final ReportedValue rv = new ReportedValue(); switch (type.getValueType()) { case INTERVAL: rv.setMaxTargetValue((float) m.getMaxTarget()); rv.setMinTargetValue((float) m.getMinTarget()); break; case SINGLE_VALUE: rv.setTargetValue((float) m.getTarget()); break; } rv.setReportedValue((float) m.getReportedValue()); rv.setReportedAt(DateUtil.toDateTime(schedActivityEntity.getScheduledTime())); mv.getReportedValues().add(rv); } } ra.setMeasures(measuredValues); } stats.setMeasuredValues(measuredValues); return ServiceResultImpl.createSuccessResult(stats, new GenericSuccessMessage()); }
From source file:org.tylproject.vaadin.addon.MongoContainer.java
@Override public void sort(Object[] propertyId, boolean[] ascending) { if (propertyId.length != ascending.length) throw new IllegalArgumentException( String.format("propertyId array length does not match" + "ascending array length (%d!=%d)", propertyId.length, ascending.length)); Sort result = null;/*from w w w . ja v a2 s . co m*/ // if the arrays are empty, will just the conditions if (propertyId.length != 0) { result = new Sort(ascending[0] ? Sort.Direction.ASC : Sort.Direction.DESC, propertyId[0].toString()); for (int i = 1; i < propertyId.length; i++) { result = result.and(new Sort(ascending[i] ? Sort.Direction.ASC : Sort.Direction.DESC, propertyId[i].toString())); } } resetQuery(); applySort(this.query, result); applyCriteriaList(this.query, appliedCriteria); this.sort = result; refresh(); fireItemSetChange(); }
From source file:com.iyonger.apm.web.controller.PerfTestController.java
/** * Get the last perf test details in the form of json. //w ww. j a v a 2s . c o m * @param page page * @param size size of retrieved perf test * @return json string */ @RestAPI @RequestMapping(value = { "/api/last", "/api", "/api/" }, method = RequestMethod.GET) public HttpEntity<String> getAll(@RequestParam(value = "page", defaultValue = "0") int page, @RequestParam(value = "size", defaultValue = "1") int size) { PageRequest pageRequest = new PageRequest(page, size, new Sort(Direction.DESC, "id")); Page<PerfTest> testList = perfTestService.getPagedAll(getCurrentUser(), null, null, null, pageRequest); return toJsonHttpEntity(testList.getContent()); }
From source file:org.lareferencia.backend.rest.BackEndController.java
@RequestMapping(value = "/public/listProviderStats", method = RequestMethod.GET) @ResponseBody// www . jav a 2s. c o m public PageResource<OAIProviderStat> listProviderStats(@RequestParam(required = false) Integer page, @RequestParam(required = false) Integer size) { if (page == null) page = 0; if (size == null) size = 100; Page<OAIProviderStat> pageResult = oaiProviderStatRepository .findAll(new PageRequest(page, size, new Sort(Sort.Direction.DESC, "requestCount"))); return new PageResource<OAIProviderStat>(pageResult, "page", "size"); }
From source file:org.ngrinder.perftest.controller.PerfTestController.java
/** * Get the last perf test details in the form of json. * * @param user user// ww w.ja v a2 s . c o m * @param page page * @param size size of retrieved perf test * @return json string */ @RestAPI @RequestMapping(value = { "/api/last", "/api", "/api/" }, method = RequestMethod.GET) public HttpEntity<String> getAll(User user, @RequestParam(value = "page", defaultValue = "0") int page, @RequestParam(value = "size", defaultValue = "1") int size) { PageRequest pageRequest = new PageRequest(page, size, new Sort(Direction.DESC, "id")); Page<PerfTest> testList = perfTestService.getPagedAll(user, null, null, null, pageRequest); return toJsonHttpEntity(testList.getContent()); }
From source file:org.eclipse.hawkbit.repository.jpa.JpaRolloutManagement.java
private void handleCreateRollout(final JpaRollout rollout) { LOGGER.debug("handleCreateRollout called for rollout {}", rollout.getId()); final List<RolloutGroup> rolloutGroups = rolloutGroupManagement .findRolloutGroupsByRolloutId(rollout.getId(), new PageRequest(0, quotaManagement.getMaxRolloutGroupsPerRollout(), new Sort(Direction.ASC, "id"))) .getContent();//w w w . ja v a2s .c o m int readyGroups = 0; int totalTargets = 0; for (final RolloutGroup group : rolloutGroups) { if (RolloutGroupStatus.READY.equals(group.getStatus())) { readyGroups++; totalTargets += group.getTotalTargets(); continue; } final RolloutGroup filledGroup = fillRolloutGroupWithTargets(rollout, group); if (RolloutGroupStatus.READY.equals(filledGroup.getStatus())) { readyGroups++; totalTargets += filledGroup.getTotalTargets(); } } // When all groups are ready the rollout status can be changed to be // ready, too. if (readyGroups == rolloutGroups.size()) { LOGGER.debug("rollout {} creatin done. Switch to READY.", rollout.getId()); rollout.setStatus(RolloutStatus.READY); rollout.setLastCheck(0); rollout.setTotalTargets(totalTargets); rolloutRepository.save(rollout); } }