List of usage examples for com.mongodb QueryBuilder QueryBuilder
public QueryBuilder()
From source file:io.hawkcd.services.PipelineService.java
License:Apache License
@Override @Authorization(scope = PermissionScope.PIPELINE, type = PermissionType.VIEWER) public ServiceResult getAllUpdatedUnpreparedPipelinesInProgress() { ServiceResult result = null;//from w ww . j a v a 2 s . co m switch (super.DATABASE_TYPE) { case REDIS: result = this.getAll(); List<Pipeline> pipelines = (List<Pipeline>) result.getEntity(); List<Pipeline> updatedPipelines = pipelines.stream() .filter(p -> p.areMaterialsUpdated() && !p.isPrepared() && (p.getStatus() == PipelineStatus.IN_PROGRESS)) .sorted((p1, p2) -> p1.getStartTime().compareTo(p2.getStartTime())) .collect(Collectors.toList()); result.setEntity(updatedPipelines); return result; case MONGODB: List<DBObject> queriesArray = new ArrayList<>(); queriesArray.add((new QueryBuilder().start().put("areMaterialsUpdated").is(true).get())); queriesArray.add((new QueryBuilder().start().put("isPrepared").is(false).get())); queriesArray.add( (new QueryBuilder().start().put("status").is(PipelineStatus.IN_PROGRESS.toString()).get())); BasicDBObject query = (BasicDBObject) new QueryBuilder().start() .and(new QueryBuilder().start().and(queriesArray.get(0), queriesArray.get(1)).get(), queriesArray.get(2)) .get(); BasicDBObject sortingFiler = new BasicDBObject("startTime", 1); result = this.getPipelineMongoService().QueryExecutor(query, sortingFiler); } return result; }
From source file:io.hawkcd.services.PipelineService.java
License:Apache License
@Override @Authorization(scope = PermissionScope.PIPELINE, type = PermissionType.VIEWER) public ServiceResult getAllPreparedPipelinesInProgress() { ServiceResult result = null;/* w w w . ja v a 2s .co m*/ switch (super.DATABASE_TYPE) { case REDIS: result = this.getAll(); List<Pipeline> pipelines = (List<Pipeline>) result.getEntity(); List<Pipeline> updatedPipelines = pipelines.stream() .filter(p -> p.isPrepared() && (p.getStatus() == PipelineStatus.IN_PROGRESS)) .sorted((p1, p2) -> p1.getStartTime().compareTo(p2.getStartTime())) .collect(Collectors.toList()); result.setEntity(updatedPipelines); break; case MONGODB: List<DBObject> queriesArray = new ArrayList<>(); queriesArray.add((new QueryBuilder().start().put("isPrepared").is(true).get())); queriesArray.add( (new QueryBuilder().start().put("status").is(PipelineStatus.IN_PROGRESS.toString()).get())); BasicDBObject query = (BasicDBObject) new QueryBuilder().start() .and(queriesArray.get(0), queriesArray.get(1)).get(); BasicDBObject sortingFiler = new BasicDBObject("startTime", 1); result = this.getPipelineMongoService().QueryExecutor(query, sortingFiler); break; } return result; }
From source file:io.hawkcd.services.PipelineService.java
License:Apache License
@Override @Authorization(scope = PermissionScope.PIPELINE, type = PermissionType.VIEWER) public ServiceResult getAllPreparedAwaitingPipelines() { ServiceResult result = null;//from w w w. j av a 2s. co m switch (super.DATABASE_TYPE) { case REDIS: result = this.getAll(); List<Pipeline> pipelines = (List<Pipeline>) result.getEntity(); List<Pipeline> updatedPipelines = pipelines.stream() .filter(p -> p.isPrepared() && (p.getStatus() == PipelineStatus.AWAITING)) .sorted((p1, p2) -> p1.getStartTime().compareTo(p2.getStartTime())) .collect(Collectors.toList()); result.setEntity(updatedPipelines); break; case MONGODB: List<DBObject> queriesArray = new ArrayList<>(); queriesArray.add((new QueryBuilder().start().put("isPrepared").is(true).get())); queriesArray .add((new QueryBuilder().start().put("status").is(PipelineStatus.AWAITING.toString()).get())); BasicDBObject query = (BasicDBObject) new QueryBuilder().start() .and(queriesArray.get(0), queriesArray.get(1)).get(); BasicDBObject sortingFiler = new BasicDBObject("startTime", 1); result = this.getPipelineMongoService().QueryExecutor(query, sortingFiler); break; } return result; }
From source file:io.hawkcd.services.PipelineService.java
License:Apache License
@Override @Authorization(scope = PermissionScope.PIPELINE, type = PermissionType.NONE) public ServiceResult getAllPipelineHistoryDTOs(String pipelineDefinitionId, Integer numberOfPipelines, String pipelineId) {/* w ww . ja v a 2 s .c o m*/ ServiceResult result = null; switch (super.DATABASE_TYPE) { case REDIS: result = this.getAllByDefinitionId(pipelineDefinitionId); List<Pipeline> pipelines = (List<Pipeline>) result.getEntity(); List<Pipeline> filteredPipelines = pipelines.stream() .sorted((p1, p2) -> p2.getStartTime().compareTo(p1.getStartTime())) .collect(Collectors.toList()); int indexOfPipeline = this.getIndexOfPipeline(filteredPipelines, pipelineId); if (indexOfPipeline == -1) { filteredPipelines = filteredPipelines.stream().limit(numberOfPipelines) .collect(Collectors.toList()); } else { filteredPipelines = filteredPipelines.stream().skip(indexOfPipeline + 1).limit(numberOfPipelines) .collect(Collectors.toList()); } List<PipelineDto> pipelineDtos = new ArrayList<>(); for (Pipeline pipeline : filteredPipelines) { PipelineDto pipelineDto = new PipelineDto(); pipelineDto.constructHistoryPipelineDto(pipeline); pipelineDtos.add(pipelineDto); } result.setEntity(pipelineDtos); break; case MONGODB: BasicDBObject query = (BasicDBObject) new QueryBuilder().start().put("pipelineDefinitionId") .is(pipelineDefinitionId).get(); BasicDBObject sortingFiler = new BasicDBObject("executionId", -1); if (pipelineId.isEmpty() || pipelineId == null || pipelineId.equals("undefined")) { result = this.getPipelineMongoService().QueryExecutor(query, sortingFiler, 0, numberOfPipelines); } else { Pipeline lastPipeline = (Pipeline) this.getById(pipelineId).getEntity(); Integer executionId = lastPipeline.getExecutionId(); List<DBObject> queriesArray = new ArrayList<>(); queriesArray.add(query); queriesArray.add((new QueryBuilder().start().put("executionId").lessThan(executionId).get())); query = (BasicDBObject) new QueryBuilder().start().and(queriesArray.get(0), queriesArray.get(1)) .get(); result = this.getPipelineMongoService().QueryExecutor(query, sortingFiler, 0, numberOfPipelines); } break; } return result; }
From source file:io.hawkcd.services.PipelineService.java
License:Apache License
@Override @Authorization(scope = PermissionScope.PIPELINE, type = PermissionType.NONE) public ServiceResult getAllPipelineArtifactDTOs(String searchCriteria, Integer numberOfPipelines, Integer skip, String pipelineId) {//from w w w .ja v a2 s . c o m ServiceResult result = null; List<Pipeline> pipelines = null; List<Pipeline> filteredPipelines = null; switch (super.DATABASE_TYPE) { case REDIS: result = this.getAll(); pipelines = (List<Pipeline>) result.getEntity(); filteredPipelines = pipelines.stream() .filter(p -> p.getPipelineDefinitionName().toLowerCase().contains(searchCriteria.toLowerCase())) .sorted((p1, p2) -> p2.getStartTime().compareTo(p1.getStartTime())) .collect(Collectors.toList()); int indexOfPipeline = this.getIndexOfPipeline(filteredPipelines, pipelineId); if (indexOfPipeline == -1) { filteredPipelines = filteredPipelines.stream().limit(numberOfPipelines) .collect(Collectors.toList()); } else { filteredPipelines = filteredPipelines.stream().skip(indexOfPipeline + 1).limit(numberOfPipelines) .collect(Collectors.toList()); } break; case MONGODB: BasicDBObject query = (BasicDBObject) new QueryBuilder().start().put("pipelineDefinitionName") .regex(Pattern.compile(searchCriteria, Pattern.CASE_INSENSITIVE)).get(); BasicDBObject sortingFiler = new BasicDBObject("pipelineDefinitionId", -1); sortingFiler.append("executionId", -1); if (pipelineId.isEmpty() || pipelineId == null || pipelineId.equals("undefined")) { result = this.getPipelineMongoService().QueryExecutor(query, sortingFiler, 0, numberOfPipelines); } else { result = this.getPipelineMongoService().QueryExecutor(query, sortingFiler, skip, numberOfPipelines); } filteredPipelines = (List<Pipeline>) result.getEntity(); break; } List<PipelineDto> pipelineDtos = new ArrayList<>(); for (Pipeline pipeline : filteredPipelines) { PipelineDto pipelineDto = new PipelineDto(); boolean isScrollCall = false; if (pipelineId.length() > 0) { isScrollCall = true; } pipelineDto.constructArtifactPipelineDto(pipeline, isScrollCall); pipelineDtos.add(pipelineDto); } result.setEntity(pipelineDtos); return result; }
From source file:it.sayservice.platform.smartplanner.controllers.BikeSharingCtrl.java
License:Apache License
@RequestMapping(method = RequestMethod.GET, value = "/{router}/rest/getBikeSharing") public @ResponseBody List<Parking> getBikeSharing(@PathVariable String router) throws SmartPlannerException { List<Parking> result = new ArrayList<Parking>(); try {/* www .j a va 2 s .c o m*/ BikeStationRepository bikeStationRepository = mongoRouterMapper.getBikeStationRepository(router); if (mongoRouterMapper.getMongoTemplateMap().containsKey(router)) { template = mongoRouterMapper.getMongoTemplateMap().get(router); } if (bikeStationRepository != null && template != null) { List<BikeStation> stations = bikeStationRepository.findAll(); for (BikeStation station : stations) { QueryBuilder qb = new QueryBuilder(); qb.start("_id").is(station.getId()); Criteria criteria = new Criteria("_id").is(station.getId()); Query query = new Query(criteria); DynamicBikeStation alert = template.findOne(query, DynamicBikeStation.class, Constants.ALERT_BIKE_REPO); if (alert != null) { int places = -1; if (!station.isMonitored()) { places = -2; } else if (alert != null) { places = alert.getPosts(); if (places > station.getPosts() || (System.currentTimeMillis() - alert.getDuration() > PARKING_DATA_VALIDITY)) { places = -1; } } Parking parking = new Parking(); // parking.setName(station.getStationId().getId()); parking.setName(station.getBikeStationName()); parking.setDescription(station.getFullName()); // parking.setSlotsAvailable(alert.getPosts()); parking.setSlotsAvailable(places); parking.setSlotsTotal(station.getPosts()); parking.setPosition(station.getPosition()); parking.setMonitored(station.isMonitored()); parking.getExtra().put("bikes", alert.getBikes()); result.add(parking); } } } else { throw new SmartPlannerException(HttpStatus.INTERNAL_SERVER_ERROR.value(), "router|template null"); } } catch (Exception e) { throw new SmartPlannerException(HttpStatus.INTERNAL_SERVER_ERROR.value(), e.getMessage()); } return result; }
From source file:it.sayservice.platform.smartplanner.controllers.BikeSharingCtrl.java
License:Apache License
private Parking getParkingFromBikeStation(BikeStation bikeStation, String agencyId) { Parking parking = null;//from w ww.ja v a 2 s . c om if (agencyId != null && !bikeStation.getStationId().getAgencyId().equals(agencyId)) { return null; } QueryBuilder qb = new QueryBuilder(); qb.start("_id").is(bikeStation.getId()); Criteria criteria = new Criteria("_id").is(bikeStation.getId()); Query query = new Query(criteria); DynamicBikeStation alert = template.findOne(query, DynamicBikeStation.class, Constants.ALERT_BIKE_REPO); if (alert != null) { int places = -1; if (!bikeStation.isMonitored()) { places = -2; } else if (alert != null) { places = alert.getPosts(); if (places > bikeStation.getPosts() || (System.currentTimeMillis() - alert.getDuration() > PARKING_DATA_VALIDITY)) { places = -1; } } parking = new Parking(); // parking.setName(bikeStation.getStationId().getId()); parking.setName(bikeStation.getBikeStationName()); parking.setDescription(bikeStation.getFullName()); parking.setSlotsAvailable(places); parking.setSlotsTotal(bikeStation.getPosts()); parking.setPosition(bikeStation.getPosition()); parking.setMonitored(bikeStation.isMonitored()); parking.getExtra().put("bikes", alert.getBikes()); } return parking; }
From source file:it.sayservice.platform.smartplanner.controllers.CarParkingCtrl.java
License:Apache License
/** * Get Parkings./*from w w w .j a v a2 s .com*/ * @param router * @return * @throws SmartPlannerException */ @RequestMapping(method = RequestMethod.GET, value = "/{router}/rest/getParkings") public @ResponseBody List<Parking> getParkings(@PathVariable String router) throws SmartPlannerException { List<Parking> result = new ArrayList<Parking>(); try { CarStationRepository carStationRepository = mongoRouterMapper.getCarStationRepository(router);// Repository(CarStationRepository.class); if (mongoRouterMapper.getMongoTemplateMap().containsKey(router)) { template = mongoRouterMapper.getMongoTemplateMap().get(router); } if (carStationRepository != null && template != null) { List<CarStation> stations = carStationRepository.findAll(); for (CarStation station : stations) { if (!"CAR-PARKING".equals(station.getType())) { continue; } QueryBuilder qb = new QueryBuilder(); qb.start("_id").is(station.getId()); Criteria criteria = new Criteria("_id").is(station.getId()); Query query = new Query(criteria); DynamicCarStation alert = template.findOne(query, DynamicCarStation.class, Constants.ALERT_CAR_REPO); int places = -1; if (!station.isMonitored()) { places = -2; } else if (alert != null) { places = alert.getPosts(); if (places > station.getPosts() || (System.currentTimeMillis() - alert.getDuration() > PARKING_DATA_VALIDITY)) { places = -1; } } Parking parking = new Parking(); // parking.setName(station.getStationId().getId()); parking.setName(station.getCarStationName()); parking.setDescription(station.getFullName()); parking.setSlotsAvailable(places); parking.setSlotsTotal(station.getPosts()); parking.setPosition(station.getPosition()); parking.setMonitored(station.isMonitored()); parking.getExtra().put("parkAndRide", station.isParkAndRide()); result.add(parking); } } else { throw new SmartPlannerException(HttpStatus.INTERNAL_SERVER_ERROR.value(), "router|template null"); } } catch (Exception e) { throw new SmartPlannerException(HttpStatus.INTERNAL_SERVER_ERROR.value(), e.getMessage()); } return result; }
From source file:it.sayservice.platform.smartplanner.controllers.CarParkingCtrl.java
License:Apache License
@RequestMapping(method = RequestMethod.GET, value = "/{router}/rest/getParkingsByAgency") public @ResponseBody List<Parking> getParkingsByAgency(@PathVariable String router, @RequestParam("agencyId") String agencyId) throws SmartPlannerException { List<Parking> result = new ArrayList<Parking>(); try {/* w ww . j a v a 2 s . c om*/ CarStationRepository carStationRepository = mongoRouterMapper.getCarStationRepository(router); if (mongoRouterMapper.getMongoTemplateMap().containsKey(router)) { template = mongoRouterMapper.getMongoTemplateMap().get(router); } if (carStationRepository != null && template != null) { List<CarStation> stations = carStationRepository.findAll(); for (CarStation station : stations) { if (!"CAR-PARKING".equals(station.getType())) { continue; } if (!station.getStationId().getAgencyId().equals(agencyId)) { continue; } QueryBuilder qb = new QueryBuilder(); qb.start("_id").is(station.getId()); Criteria criteria = new Criteria("_id").is(station.getId()); Query query = new Query(criteria); DynamicCarStation alert = template.findOne(query, DynamicCarStation.class, Constants.ALERT_CAR_REPO); int places = -1; if (!station.isMonitored()) { places = -2; } else if (alert != null) { places = alert.getPosts(); if (places > station.getPosts() || (System.currentTimeMillis() - alert.getDuration() > PARKING_DATA_VALIDITY)) { places = -1; } } Parking parking = new Parking(); // parking.setName(station.getStationId().getId()); parking.setName(station.getCarStationName()); parking.setDescription(station.getFullName()); parking.setSlotsAvailable(places); parking.setSlotsTotal(station.getPosts()); parking.setPosition(station.getPosition()); parking.setMonitored(station.isMonitored()); parking.getExtra().put("parkAndRide", station.isParkAndRide()); result.add(parking); } } else { throw new SmartPlannerException(HttpStatus.INTERNAL_SERVER_ERROR.value(), "router|template null"); } } catch (Exception e) { throw new SmartPlannerException(HttpStatus.INTERNAL_SERVER_ERROR.value(), e.getMessage()); } return result; }
From source file:it.sayservice.platform.smartplanner.otp.OTPManager.java
License:Apache License
private List<AlertDelay> getAlertDelay(String router, String routeId, String tripId, boolean now) { QueryBuilder qb = new QueryBuilder(); qb = qb.start("transport.routeId").is(routeId).and("transport.tripId").is(tripId); if (now) {/*from ww w . j ava2 s . c o m*/ long time = System.currentTimeMillis(); qb = qb.and("from").lessThanEquals(time); qb = qb.and("to").greaterThanEquals(time); } List<AlertDelay> delays = (List) storage.getObjectsByQuery( mongoRouterMapper.getMongoTemplateMap().get(router), qb.get(), Constants.ALERT_DELAYS, AlertDelay.class, "delay"); return delays; }