Example usage for org.joda.time LocalDate isBefore

List of usage examples for org.joda.time LocalDate isBefore

Introduction

In this page you can find the example usage for org.joda.time LocalDate isBefore.

Prototype

public boolean isBefore(ReadablePartial partial) 

Source Link

Document

Is this partial earlier than the specified partial.

Usage

From source file:pt.ist.fenixedu.teacher.domain.credits.AnnualCreditsState.java

License:Open Source License

@Override
public void setFinalCalculationDate(LocalDate finalCalculationDate) {
    if (finalCalculationDate != null && !finalCalculationDate.equals(getFinalCalculationDate())
            && finalCalculationDate.isBefore(new LocalDate())) {
        throw new DomainException("renderers.validator.dateTime.beforeNow");
    }//from  ww w  .  j ava2s.c  o  m
    if (finalCalculationDate == null || !finalCalculationDate.equals(getFinalCalculationDate())) {
        setIsFinalCreditsCalculated(false);
        super.setFinalCalculationDate(finalCalculationDate);
    }
}

From source file:pt.ist.fenixedu.teacher.evaluation.task.RunCreditsQueueJobs.java

License:Open Source License

@Override
public void runTask() throws Exception {
    LocalDate today = new LocalDate();
    for (AnnualCreditsState annualCreditsState : Bennu.getInstance().getAnnualCreditsStatesSet()) {
        if (!annualCreditsState.getIsFinalCreditsCalculated()
                && annualCreditsState.getFinalCalculationDate() != null
                && !today.isBefore(annualCreditsState.getFinalCalculationDate())
                && !alreadyLaunched(CalculateCreditsQueueJob.class.getName())) {
            new CalculateCreditsQueueJob(annualCreditsState.getExecutionYear());
            taskLog("Lauched CalculateCreditsQueueJob");
        }/*from   w w w.ja  v  a 2  s.co m*/
        if (!annualCreditsState.getIsCreditsClosed() && annualCreditsState.getCloseCreditsDate() != null
                && !today.isBefore(annualCreditsState.getCloseCreditsDate())
                && !alreadyLaunched(CloseCreditsQueueJob.class.getName())) {
            new CloseCreditsQueueJob(annualCreditsState.getExecutionYear());
            taskLog("Lauched CloseCreditsQueueJob");
        }
    }
}

From source file:pt.ist.fenixWebFramework.rendererExtensions.validators.FutureLocalDateValidator.java

License:Open Source License

@Override
public void performValidation() {
    HtmlSimpleValueComponent component = (HtmlSimpleValueComponent) getComponent();

    String value = component.getValue();

    if (value == null || value.length() == 0) {
        setMessage("renderers.validator.dateTime.required");
        setValid(!isRequired());/*from  w  w w.  j av a 2s  .c o m*/
    } else {
        super.performValidation();

        if (isValid()) {
            LocalDate localDate = getCalculatedDate();

            if (localDate.isBefore(new LocalDate())) {
                setMessage("renderers.validator.dateTime.beforeNow");
                setValid(false);
            }
        }
    }
}

From source file:pt.ulisboa.tecnico.softeng.car.domain.Renting.java

private void checkArguments(String drivingLicense, LocalDate begin, LocalDate end, Vehicle vehicle) {
    if (drivingLicense == null || !drivingLicense.matches(drivingLicenseFormat) || begin == null || end == null
            || vehicle == null || end.isBefore(begin)) {
        throw new CarException();
    }/*w w  w .j  a  v a2 s  .c o  m*/
}

From source file:pt.ulisboa.tecnico.softeng.car.domain.Renting.java

/**
 * @param begin//from  w  w w. j  a va 2  s  .  c  o  m
 * @param end
 * @return <code>true</code> if this Renting conflicts with the given date
 *         range.
 */
public boolean conflict(LocalDate begin, LocalDate end) {
    if (end.isBefore(begin)) {
        throw new CarException("Error: end date is before begin date.");
    } else if ((begin.equals(this.getBegin()) || begin.isAfter(this.getBegin()))
            && (begin.isBefore(this.getEnd()) || begin.equals(this.getEnd()))) {
        return true;
    } else if ((end.equals(this.getEnd()) || end.isBefore(this.getEnd()))
            && (end.isAfter(this.getBegin()) || end.isEqual(this.getBegin()))) {
        return true;
    } else if (begin.isBefore(this.getBegin()) && end.isAfter(this.getEnd())) {
        return true;
    }

    return false;
}

From source file:Reporte.ReporteCajaList.java

/**
 * Processes requests for both HTTP/*w ww. j  ava 2s.  com*/
 * <code>GET</code> and
 * <code>POST</code> methods.
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    response.setContentType("application/json;charset=UTF-8");
    PrintWriter out = response.getWriter();
    JsonRespuesta jr = new JsonRespuesta();

    try {
        Integer id_caja = Parser.parseInt(request.getParameter("id_caja"));
        Integer id_estado = Parser.parseInt(request.getParameter("id_estado"));
        Integer id_forma = Parser.parseInt(request.getParameter("id_forma"));
        Integer id_usuario = Parser.parseInt(request.getParameter("id_usuario"));
        String fecha_desde = TFecha.formatearFechaVistaBd(request.getParameter("fecha_desde"));
        String fecha_hasta = TFecha.formatearFechaVistaBd(request.getParameter("fecha_hasta"));
        HttpSession session = request.getSession();
        Integer id_usuario_actual = (Integer) session.getAttribute("id_usuario");
        Integer id_tipo_usuario_actual = (Integer) session.getAttribute("id_tipo_usuario");

        //Si es un usuario distinto de Administrador, solo se muestran las cajas del usuario actual          
        if (!id_tipo_usuario_actual.equals(OptionsCfg.USUARIO_ADMINISTRADOR))
            id_usuario = id_usuario_actual;

        mapFormaPago = OptionsCfg.getMap(OptionsCfg.getFormaPago());
        mapMovimiento = OptionsCfg.getMap(OptionsCfg.getTipoMovimiento());
        mapEstadosCaja = OptionsCfg.getMap(OptionsCfg.getEstadosCaja());

        TCaja tc = new TCaja();
        TCaja_detalle tcd = new TCaja_detalle();
        HashMap<String, String> mapFiltro = new HashMap<String, String>();
        HashMap<String, String> mapFiltroCaja = new HashMap<String, String>();

        tc.setOrderBy(" fecha desc ");
        if (id_estado != 0)
            mapFiltroCaja.put("id_estado", id_estado.toString());
        if (id_usuario != 0)
            mapFiltroCaja.put("id_usuario", id_usuario.toString());

        List<Caja> lstCajas = tc.getListFiltro(mapFiltroCaja);

        ArrayList<CajaDet> listaDet = new ArrayList<CajaDet>();
        LocalDate desde = null;
        LocalDate hasta = null;

        if (fecha_desde != null && !fecha_desde.equals(""))
            desde = new LocalDate(fecha_desde);
        if (fecha_hasta != null && !fecha_hasta.equals(""))
            hasta = new LocalDate(fecha_hasta);

        for (Caja caja : lstCajas) {
            CajaDet cd = new CajaDet(caja);
            LocalDate fecha = new LocalDate(caja.getFecha().getFecha());
            if (desde != null && fecha.isBefore(desde))
                continue;
            if (hasta != null && fecha.isAfter(hasta))
                continue;

            mapFiltro.put("id_caja", caja.getId().toString());
            if (id_forma != 0)
                mapFiltro.put("id_forma", id_forma.toString());
            List<Caja_detalle> listFiltro = tcd.getListFiltro(mapFiltro);

            if (listFiltro == null)
                throw new BaseException("ERROR", "Ocurri&oacute; un error al listar los movimientos de caja");
            ArrayList<CajaDetalleDet> listaCajaDet = new ArrayList<CajaDetalleDet>();
            Float saldo = 0f;
            Float saldo_efectivo = 0f;
            Float saldo_cheque = 0f;
            Float saldo_transf = 0f;
            for (Caja_detalle detalle : listFiltro) {
                if (detalle.getConcepto().startsWith("Apertura "))
                    continue;
                if (detalle.getConcepto().startsWith("Diferencia "))
                    continue;
                float importe = detalle.getId_tipo() == OptionsCfg.TIPO_INGRESO ? detalle.getImporte()
                        : -1 * detalle.getImporte();
                saldo += importe;
                switch (detalle.getId_forma()) {
                case OptionsCfg.FORMA_EFECTIVO:
                    saldo_efectivo += importe;
                case OptionsCfg.FORMA_CHEQUE:
                    saldo_cheque += importe;
                case OptionsCfg.FORMA_TRANSFERENCIA:
                    saldo_transf += importe;
                }
                detalle.setSaldo(saldo);
                listaCajaDet.add(new CajaDetalleDet(detalle));
            }
            cd.setEfectivo_cierre(saldo_efectivo);
            cd.setCheque_cierre(saldo_cheque);
            cd.setTransferencia_cierre(saldo_transf);
            //if(listaCajaDet.size()>0)   {
            cd.detalle = listaCajaDet;
            listaDet.add(cd);
            //}
        }
        jr.setResult("OK");
        jr.setRecordCount(listaDet.size());
        jr.setRecords(listaDet);
    } catch (BaseException ex) {
        jr.setResult(ex.getResult());
        jr.setMessage(ex.getMessage());
    } finally {
        out.print(new Gson().toJson(jr));
        out.close();
    }
}

From source file:Reporte.ReporteComisionVendedorList.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods./*from   ww w . j a v a 2s. c  o m*/
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    response.setContentType("application/json;charset=UTF-8");
    PrintWriter out = response.getWriter();
    String pagNro = request.getParameter("pagNro");
    String codigo = request.getParameter("codigo");
    Integer id_cliente = Parser.parseInt(request.getParameter("id_cliente"));
    Integer id_propiedad = Parser.parseInt(request.getParameter("id_propiedad"));
    Integer id_tipo = Parser.parseInt(request.getParameter("id_tipo"));
    String fecha_desde = TFecha.formatearFechaVistaBd(request.getParameter("fecha_desde"));
    String fecha_hasta = TFecha.formatearFechaVistaBd(request.getParameter("fecha_hasta"));
    Integer page = Parser.parseInt(pagNro);
    LocalDate desde = null;
    LocalDate hasta = null;
    try {
        JsonRespuesta jr = new JsonRespuesta();

        List<Contrato> lista;
        mapPropietarios = new TPropietario().getMap();
        mapInquilinos = new TInquilino().getMap();
        mapPropiedades = new TPropiedad().getMap();
        mapVendedor = new TVendedor().getMap();
        mapEstados = OptionsCfg.getMap(OptionsCfg.getEstadosContrato());

        TContrato tp = new TContrato();
        HashMap<String, String> mapFiltro = new HashMap<String, String>();
        if (id_cliente != 0) {

            if (id_tipo.equals(OptionsCfg.CLIENTE_TIPO_PROPIETARIO))
                mapFiltro.put("id_propietario", id_cliente.toString());
            else if (id_tipo.equals(OptionsCfg.CLIENTE_TIPO_INQUILINO))
                mapFiltro.put("id_inquilino", id_cliente.toString());
        }

        if (id_propiedad != 0)
            mapFiltro.put("id_propiedad", id_propiedad.toString());

        lista = tp.getListFiltro(mapFiltro);
        //lista = tp.getList();

        if (fecha_desde != null && !fecha_desde.equals(""))
            desde = new LocalDate(fecha_desde);
        if (fecha_hasta != null && !fecha_hasta.equals(""))
            hasta = new LocalDate(fecha_hasta);

        if (lista != null) {
            List<Contrato> listaDet = new ArrayList<Contrato>();
            for (Contrato c : lista) {
                LocalDate fecha = new LocalDate(c.getFecha_inicio());
                if (desde != null && fecha.isBefore(desde))
                    continue;
                if (hasta != null && fecha.isAfter(hasta))
                    continue;

                listaDet.add(new ContratoDet(c));
            }
            jr.setTotalRecordCount(listaDet.size());
            jr.setResult("OK");
            jr.setRecords(listaDet);
        } else {
            jr.setResult("ERROR");
            jr.setTotalRecordCount(0);
        }

        String jsonResult = new Gson().toJson(jr);

        out.print(jsonResult);
    } finally {
        out.close();
    }
}

From source file:ru.caramel.juniperbot.module.social.service.impl.YouTubeServiceImpl.java

License:Open Source License

@Override
@Transactional//from www  .java2  s.  c  om
public void subscribe(YouTubeChannel channel) {
    LocalDate now = LocalDate.now();
    LocalDate expiredAt = channel.getExpiresAt() != null ? LocalDate.fromDateFields(channel.getExpiresAt())
            : LocalDate.now();
    if (now.isBefore(expiredAt)) {
        return;
    }

    HttpHeaders headers = new HttpHeaders();
    headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
    MultiValueMap<String, String> map = new LinkedMultiValueMap<>();
    map.add("hub.callback", String.format("%s/api/public/youtube/callback/publish?secret=%s&channel=%s",
            brandingService.getWebHost(), pubSubSecret, CommonUtils.urlEncode(channel.getChannelId())));
    map.add("hub.topic", CHANNEL_RSS_ENDPOINT + channel.getChannelId());
    map.add("hub.mode", "subscribe");
    map.add("hub.verify", "async");
    map.add("hub.verify_token", pubSubSecret);
    HttpEntity<MultiValueMap<String, String>> request = new HttpEntity<>(map, headers);

    ResponseEntity<String> response = restTemplate.postForEntity(PUSH_ENDPOINT, request, String.class);
    if (!response.getStatusCode().is2xxSuccessful()) {
        throw new IllegalStateException("Could not subscribe to " + channel.getChannelId());
    }
    channel.setExpiresAt(DateTime.now().plusDays(7).toDate());
    channelRepository.save(channel);
}

From source file:ru.codemine.ccms.router.ExpencesRouter.java

License:Open Source License

@Secured("ROLE_OFFICE")
@RequestMapping(value = "/reports/graph/expences")
public String getExpencesGraph(@RequestParam(required = false) Integer shopid,
        @RequestParam(required = false) String dateStartStr, @RequestParam(required = false) String dateEndStr,
        ModelMap model) {/*from   w ww  .  j  av a 2 s .c  o  m*/
    model.addAllAttributes(utils.prepareModel());

    DateTimeFormatter formatter = DateTimeFormat.forPattern("dd.MM.YYYY");
    LocalDate dateStart = dateStartStr == null ? LocalDate.now().withMonthOfYear(1).withDayOfMonth(1)
            : formatter.parseLocalDate(dateStartStr).withDayOfMonth(1);
    LocalDate dateEnd = dateEndStr == null ? LocalDate.now().dayOfMonth().withMaximumValue()
            : formatter.parseLocalDate(dateEndStr).dayOfMonth().withMaximumValue();

    if (dateEnd.isBefore(dateStart))
        dateEnd = dateStart;

    model.addAttribute("dateStartStr", dateStart.toString("dd.MM.YYYY"));
    model.addAttribute("dateEndStr", dateEnd.toString("dd.MM.YYYY"));

    List<Shop> shopList = shopService.getAllOpen();
    List<String> graphDataSalesTotal = new ArrayList<>();
    List<String> graphDataExpencesTotal = new ArrayList<>();

    Shop shop = shopid == null ? shopList.get(0) : shopService.getById(shopid);

    model.addAttribute("shop", shop);
    model.addAttribute("shopList", shopList);

    List<SalesMeta> smList = salesService.getByPeriod(shop, dateStart, dateEnd);

    for (SalesMeta sm : smList) {

        graphDataSalesTotal.add(sm.getGraphDataSalesTotal());
        graphDataExpencesTotal.add(sm.getGraphDataExpencesTotal());
    }

    model.addAttribute("graphDataSalesTotal", graphDataSalesTotal);
    model.addAttribute("graphDataExpencesTotal", graphDataExpencesTotal);

    return "reports/expences-graph";
}

From source file:ru.codemine.ccms.router.SalesRouter.java

License:Open Source License

@Secured("ROLE_OFFICE")
@RequestMapping(value = "/reports/sales-pass", method = RequestMethod.GET)
public String getSalesPassReport(@RequestParam(required = false) String dateStartStr,
        @RequestParam(required = false) String dateEndStr, @RequestParam(required = false) String mode,
        ModelMap model) {//from w  ww . ja v a2 s.  c  o m

    model.addAllAttributes(utils.prepareModel());

    DateTimeFormatter formatter = DateTimeFormat.forPattern("dd.MM.YYYY");
    LocalDate dateStart = dateStartStr == null ? LocalDate.now().withDayOfMonth(1)
            : formatter.parseLocalDate(dateStartStr).withDayOfMonth(1);
    LocalDate dateEnd = dateEndStr == null ? LocalDate.now().dayOfMonth().withMaximumValue()
            : formatter.parseLocalDate(dateEndStr).dayOfMonth().withMaximumValue();

    if (dateEnd.isBefore(dateStart))
        dateEnd = dateStart.dayOfMonth().withMaximumValue();

    model.addAttribute("dateStartStr", dateStart.toString("dd.MM.YYYY"));
    model.addAttribute("dateEndStr", dateEnd.toString("dd.MM.YYYY"));

    List<String> subgridColNames = new ArrayList<>();
    subgridColNames.add("?");

    if (dateStart.getMonthOfYear() == dateEnd.getMonthOfYear()) {
        for (int i = 1; i <= dateEnd.getDayOfMonth(); i++) {
            subgridColNames.add(String.valueOf(i) + dateStart.toString(".MM.YY"));
        }
    } else {
        LocalDate printDate = dateStart;
        while (printDate.isBefore(dateEnd)) {
            subgridColNames.add(printDate.toString("MMM YYYY"));
            printDate = printDate.plusMonths(1);
        }
    }

    subgridColNames.add("");

    model.addAttribute("subgridColNames", subgridColNames);

    return "print".equals(mode) ? "printforms/reports/salesAllFrm" : "reports/sales-pass";
}