use of org.springframework.data.domain.Pageable in project apollo by ctripcorp.
the class InstanceServiceTest method testFindActiveInstanceConfigs.
@Test
@Rollback
public void testFindActiveInstanceConfigs() throws Exception {
long someInstanceId = 1;
long anotherInstanceId = 2;
String someConfigAppId = "someConfigAppId";
String someConfigClusterName = "someConfigClusterName";
String someConfigNamespaceName = "someConfigNamespaceName";
Date someValidDate = new Date();
Pageable pageable = PageRequest.of(0, 10);
String someReleaseKey = "someReleaseKey";
Calendar calendar = Calendar.getInstance();
calendar.add(Calendar.DATE, -2);
Date someInvalidDate = calendar.getTime();
prepareInstanceConfigForInstance(someInstanceId, someConfigAppId, someConfigClusterName, someConfigNamespaceName, someReleaseKey, someValidDate);
prepareInstanceConfigForInstance(anotherInstanceId, someConfigAppId, someConfigClusterName, someConfigNamespaceName, someReleaseKey, someInvalidDate);
Page<InstanceConfig> validInstanceConfigs = instanceService.findActiveInstanceConfigsByReleaseKey(someReleaseKey, pageable);
assertEquals(1, validInstanceConfigs.getContent().size());
assertEquals(someInstanceId, validInstanceConfigs.getContent().get(0).getInstanceId());
}
use of org.springframework.data.domain.Pageable in project apollo by ctripcorp.
the class NamespaceServiceTest method testFindPublicAppNamespaceWithWrongNamespace.
@Test(expected = BadRequestException.class)
public void testFindPublicAppNamespaceWithWrongNamespace() {
Pageable page = PageRequest.of(0, 10);
when(appNamespaceService.findPublicNamespaceByName(testPublicAppNamespace)).thenReturn(null);
namespaceService.findPublicAppNamespaceAllNamespaces(testPublicAppNamespace, page);
}
use of org.springframework.data.domain.Pageable in project apollo by ctripcorp.
the class InstanceConfigController method getByRelease.
@GetMapping("/by-release")
public PageDTO<InstanceDTO> getByRelease(@RequestParam("releaseId") long releaseId, Pageable pageable) {
Release release = releaseService.findOne(releaseId);
if (release == null) {
throw new NotFoundException(String.format("release not found for %s", releaseId));
}
Page<InstanceConfig> instanceConfigsPage = instanceService.findActiveInstanceConfigsByReleaseKey(release.getReleaseKey(), pageable);
List<InstanceDTO> instanceDTOs = Collections.emptyList();
if (instanceConfigsPage.hasContent()) {
Multimap<Long, InstanceConfig> instanceConfigMap = HashMultimap.create();
Set<String> otherReleaseKeys = Sets.newHashSet();
for (InstanceConfig instanceConfig : instanceConfigsPage.getContent()) {
instanceConfigMap.put(instanceConfig.getInstanceId(), instanceConfig);
otherReleaseKeys.add(instanceConfig.getReleaseKey());
}
Set<Long> instanceIds = instanceConfigMap.keySet();
List<Instance> instances = instanceService.findInstancesByIds(instanceIds);
if (!CollectionUtils.isEmpty(instances)) {
instanceDTOs = BeanUtils.batchTransform(InstanceDTO.class, instances);
}
for (InstanceDTO instanceDTO : instanceDTOs) {
Collection<InstanceConfig> configs = instanceConfigMap.get(instanceDTO.getId());
List<InstanceConfigDTO> configDTOs = configs.stream().map(instanceConfig -> {
InstanceConfigDTO instanceConfigDTO = new InstanceConfigDTO();
// to save some space
instanceConfigDTO.setRelease(null);
instanceConfigDTO.setReleaseDeliveryTime(instanceConfig.getReleaseDeliveryTime());
instanceConfigDTO.setDataChangeLastModifiedTime(instanceConfig.getDataChangeLastModifiedTime());
return instanceConfigDTO;
}).collect(Collectors.toList());
instanceDTO.setConfigs(configDTOs);
}
}
return new PageDTO<>(instanceDTOs, pageable, instanceConfigsPage.getTotalElements());
}
use of org.springframework.data.domain.Pageable in project sic by belluccifranco.
the class CajaServiceImpl method getCajasCriteria.
@Override
public Page<Caja> getCajasCriteria(BusquedaCajaCriteria criteria) {
// Empresa
if (criteria.getEmpresa() == null) {
throw new EntityNotFoundException(ResourceBundle.getBundle("Mensajes").getString("mensaje_empresa_no_existente"));
}
// Fecha
if (criteria.isBuscaPorFecha() == true && (criteria.getFechaDesde() == null || criteria.getFechaHasta() == null)) {
throw new BusinessServiceException(ResourceBundle.getBundle("Mensajes").getString("mensaje_caja_fechas_invalidas"));
}
if (criteria.isBuscaPorFecha() == true) {
Calendar cal = new GregorianCalendar();
cal.setTime(criteria.getFechaDesde());
cal.set(Calendar.HOUR_OF_DAY, 0);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0);
criteria.setFechaDesde(cal.getTime());
cal.setTime(criteria.getFechaHasta());
cal.set(Calendar.HOUR_OF_DAY, 23);
cal.set(Calendar.MINUTE, 59);
cal.set(Calendar.SECOND, 59);
criteria.setFechaHasta(cal.getTime());
}
if (criteria.getEmpresa() == null) {
throw new EntityNotFoundException(ResourceBundle.getBundle("Mensajes").getString("mensaje_empresa_no_existente"));
}
QCaja qcaja = QCaja.caja;
BooleanBuilder builder = new BooleanBuilder();
builder.and(qcaja.empresa.eq(criteria.getEmpresa()).and(qcaja.eliminada.eq(false)));
if (criteria.isBuscaPorUsuario() == true) {
builder.and(qcaja.usuarioCierraCaja.eq(criteria.getUsuario()));
}
if (criteria.isBuscaPorFecha() == true) {
FormatterFechaHora formateadorFecha = new FormatterFechaHora(FormatterFechaHora.FORMATO_FECHAHORA_INTERNACIONAL);
DateExpression<Date> fDesde = Expressions.dateTemplate(Date.class, "convert({0}, datetime)", formateadorFecha.format(criteria.getFechaDesde()));
DateExpression<Date> fHasta = Expressions.dateTemplate(Date.class, "convert({0}, datetime)", formateadorFecha.format(criteria.getFechaHasta()));
builder.and(qcaja.fechaApertura.between(fDesde, fHasta));
}
int pageNumber = 0;
int pageSize = Integer.MAX_VALUE;
Sort sorting = new Sort(Sort.Direction.DESC, "fechaApertura");
if (criteria.getPageable() != null) {
pageNumber = criteria.getPageable().getPageNumber();
pageSize = criteria.getPageable().getPageSize();
sorting = criteria.getPageable().getSort();
}
Pageable pageable = new PageRequest(pageNumber, pageSize, sorting);
return cajaRepository.findAll(builder, pageable);
}
use of org.springframework.data.domain.Pageable in project sic by belluccifranco.
the class PagoController method getPagosPorClienteEntreFechas.
@GetMapping("/pagos/clientes/{idCliente}")
@ResponseStatus(HttpStatus.OK)
public Page<Pago> getPagosPorClienteEntreFechas(@PathVariable long idCliente, @RequestParam(required = false) Long desde, @RequestParam(required = false) Long hasta, @RequestParam(required = false) Integer pagina, @RequestParam(required = false) Integer tamanio) {
Calendar fechaDesde = Calendar.getInstance();
Calendar fechaHasta = Calendar.getInstance();
if ((desde != null) && (hasta != null)) {
fechaDesde.setTimeInMillis(desde);
fechaHasta.setTimeInMillis(hasta);
}
fechaDesde.set(Calendar.HOUR_OF_DAY, 0);
fechaDesde.set(Calendar.MINUTE, 0);
fechaDesde.set(Calendar.SECOND, 0);
fechaHasta.set(Calendar.HOUR_OF_DAY, 23);
fechaHasta.set(Calendar.MINUTE, 59);
fechaHasta.set(Calendar.SECOND, 59);
if (tamanio == null || tamanio <= 0) {
tamanio = TAMANIO_PAGINA_DEFAULT;
}
if (pagina == null || pagina < 0) {
pagina = 0;
}
Pageable pageable = new PageRequest(pagina, tamanio, new Sort(Sort.Direction.DESC, "fecha"));
return pagoService.getPagosPorClienteEntreFechas(idCliente, fechaDesde.getTime(), fechaHasta.getTime(), pageable);
}
Aggregations