List of usage examples for org.joda.time LocalDate toDateMidnight
@Deprecated
public DateMidnight toDateMidnight()
From source file:energy.usef.core.repository.PtuFlexOrderRepository.java
License:Apache License
/** * Find and return all accepted {@link PtuFlexOrder}s for an usefIdentifier on a certain date that are not processed yet. * * @param usefIdentifier//www. ja v a 2 s .c o m * @param ptuDate * @return */ @SuppressWarnings("unchecked") public List<PtuFlexOrder> findAcceptedFlexOrdersByDateAndUsefIdentifier(Optional<String> usefIdentifier, LocalDate ptuDate) { StringBuilder sql = new StringBuilder(); sql.append("SELECT fo FROM PtuFlexOrder fo "); sql.append("WHERE fo.ptuContainer.ptuDate = :ptuDate "); sql.append(" AND fo.acknowledgementStatus = :acknowledgementStatus "); usefIdentifier.ifPresent( usefIdentifierValue -> sql.append(" AND fo.connectionGroup.usefIdentifier = :usefIdentifier")); Query query = entityManager.createQuery(sql.toString()) .setParameter("ptuDate", ptuDate.toDateMidnight().toDate()) .setParameter("acknowledgementStatus", AcknowledgementStatus.ACCEPTED); usefIdentifier.ifPresent(usefIdentifierValue -> query.setParameter("usefIdentifier", usefIdentifierValue)); return query.getResultList(); }
From source file:energy.usef.core.repository.PtuFlexOrderRepository.java
License:Apache License
/** * Delete all {@link PtuFlexOrder}s for a certain date. * * @param period//from www .java2 s . c om * @return the number of {@link PtuFlexOrder}s deleted. */ public int cleanup(LocalDate period) { StringBuilder sql = new StringBuilder(); sql.append("DELETE FROM PtuFlexOrder pfo "); sql.append("WHERE pfo.ptuContainer IN (SELECT pc FROM PtuContainer pc WHERE pc.ptuDate = :ptuDate)"); return entityManager.createQuery(sql.toString()).setParameter("ptuDate", period.toDateMidnight().toDate()) .executeUpdate(); }
From source file:energy.usef.core.repository.PtuFlexRequestRepository.java
License:Apache License
/** * Find the latest flex request document with a {@link DispositionAvailableRequested#REQUESTED} disposition. * * @param usefIdentifier {@link String} usefIdentifier of the {@link ConnectionGroup} related to the flex request. * @param period {@link LocalDate} day period of the flex request. * @param sequence {@link Long} sequence of the flex request message. * @return the latest {@link PtuFlexRequest} element of the planboard for the given parameter. *//*from ww w. j ava2 s .co m*/ public PtuFlexRequest findLastFlexRequestDocumentWithDispositionRequested(String usefIdentifier, LocalDate period, Long sequence) { TypedQuery<PtuFlexRequest> query = entityManager.createQuery("" + " SELECT fr FROM PtuFlexRequest fr " + " WHERE fr.ptuContainer.ptuDate = :period " + " AND fr.connectionGroup.usefIdentifier= :usefIdentifier " + " AND fr.disposition = :disposition " + " AND fr.sequence = :sequence " + " AND fr.ptuContainer.ptuIndex = (SELECT MAX(subFR.ptuContainer.ptuIndex) FROM PtuFlexRequest subFR " + " WHERE subFR.ptuContainer.ptuDate = :period " + " AND subFR.connectionGroup.usefIdentifier = :usefIdentifier " + " AND subFR.disposition = :disposition " + " AND subFR.sequence = :sequence)", PtuFlexRequest.class); query.setParameter("disposition", DispositionAvailableRequested.REQUESTED); query.setParameter("period", period.toDateMidnight().toDate(), TemporalType.DATE); query.setParameter("usefIdentifier", usefIdentifier); query.setParameter("sequence", sequence); List<PtuFlexRequest> results = query.getResultList(); if (results.size() == 1) { return results.get(0); } return null; }
From source file:energy.usef.core.repository.PtuFlexRequestRepository.java
License:Apache License
/** * Finds all flex requests candidate to settlement process (period of the flex request within the interval defined by the two * given dates and status ACCEPTED)./*from w w w . j a v a 2 s . c o m*/ * * @param startDate {@link LocalDate} start date of the settlement (inclusive). * @param endDate {@link LocalDate} end date of the settlement (inclusive). * @return a {@link List} of {@link PtuFlexRequest}. */ public List<PtuFlexRequest> findFlexRequestsForSettlement(LocalDate startDate, LocalDate endDate) { StringBuilder sql = new StringBuilder(); sql.append("SELECT request "); sql.append("FROM PtuFlexRequest request, PlanboardMessage pm "); sql.append("WHERE request.ptuContainer.ptuDate >= :startDate "); sql.append(" AND request.ptuContainer.ptuDate <= :endDate "); sql.append(" AND pm.period = request.ptuContainer.ptuDate "); sql.append(" AND pm.participantDomain = request.participantDomain "); sql.append(" AND pm.sequence = request.sequence "); sql.append(" AND pm.connectionGroup = request.connectionGroup "); sql.append(" AND pm.documentStatus IN (:statuses) "); sql.append( "ORDER BY request.ptuContainer.ptuDate, request.participantDomain, request.ptuContainer.ptuIndex "); return getEntityManager().createQuery(sql.toString(), PtuFlexRequest.class) .setParameter("startDate", startDate.toDateMidnight().toDate(), TemporalType.DATE) .setParameter("endDate", endDate.toDateMidnight().toDate(), TemporalType.DATE) .setParameter("statuses", Arrays.asList(DocumentStatus.ACCEPTED, DocumentStatus.RECEIVED_OFFER, DocumentStatus.RECEIVED_EMPTY_OFFER, DocumentStatus.PROCESSED)) .getResultList(); }
From source file:energy.usef.core.repository.PtuFlexRequestRepository.java
License:Apache License
/** * Delete all {@link PtuFlexRequest}s for a certain date. * * @param period/* www . j a va2 s .c o m*/ * @return the number of {@link PtuFlexRequest}s deleted. */ public int cleanup(LocalDate period) { StringBuilder sql = new StringBuilder(); sql.append("DELETE FROM PtuFlexRequest pfr "); sql.append("WHERE pfr.ptuContainer IN (SELECT pc FROM PtuContainer pc WHERE pc.ptuDate = :ptuDate)"); return entityManager.createQuery(sql.toString()).setParameter("ptuDate", period.toDateMidnight().toDate()) .executeUpdate(); }
From source file:energy.usef.core.repository.PtuPrognosisRepository.java
License:Apache License
/** * Returns the last prognoses of a specified period and prognosis type and optional usefIdentifier and documentstatus. * * @param period the period {@link LocalDate} * @param type (Optional) {@link PrognosisType} * @param usefIdentifier (Optional) usefIdentifier {@link String} * @param documentStatus (Optional) {@link DocumentStatus} * @return A {@link List} of {@link PtuPrognosis} objects. *//*from w ww. ja v a2s . c o m*/ @SuppressWarnings("unchecked") public List<PtuPrognosis> findLastPrognoses(LocalDate period, Optional<PrognosisType> type, Optional<String> usefIdentifier, Optional<DocumentStatus> documentStatus) { StringBuilder subselect = new StringBuilder(); subselect.append("SELECT MAX(p.sequence) "); subselect.append("FROM PtuPrognosis p "); subselect.append("WHERE p.ptuContainer.ptuDate = :period "); if (type.isPresent()) { subselect.append("AND p.type = :type "); } subselect.append("GROUP BY p.participantDomain, p.connectionGroup "); StringBuilder sql = new StringBuilder(); sql.append("SELECT p2 "); sql.append("FROM PtuPrognosis p2 "); if (documentStatus.isPresent()) { sql.append(", PlanboardMessage pm "); } sql.append("WHERE p2.sequence IN (").append(subselect).append(")"); sql.append("AND p2.ptuContainer.ptuDate = :period "); if (type.isPresent()) { sql.append("AND p2.type = :type "); } if (usefIdentifier.isPresent()) { sql.append("AND p2.connectionGroup.usefIdentifier = :usefIdentifier "); } if (documentStatus.isPresent()) { sql.append("AND pm.period = p2.ptuContainer.ptuDate "); sql.append("AND pm.participantDomain = p2.participantDomain "); sql.append("AND pm.sequence = p2.sequence "); sql.append("AND pm.connectionGroup = p2.connectionGroup "); sql.append("AND pm.documentStatus = :documentStatus "); } Query query = getEntityManager().createQuery(sql.toString()); query.setParameter("period", period.toDateMidnight().toDate(), TemporalType.DATE); if (type.isPresent()) { query.setParameter("type", type.get()); } if (usefIdentifier.isPresent()) { query.setParameter("usefIdentifier", usefIdentifier.get()); } if (documentStatus.isPresent()) { query.setParameter("documentStatus", documentStatus.get()); } return query.getResultList(); }
From source file:energy.usef.core.repository.PtuPrognosisRepository.java
License:Apache License
/** * Find all the Prognosis information needed for initiating the settlement. Prognoses with a period within the interval * defined by the variables and with status {@link DocumentStatus#ACCEPTED}, {@link DocumentStatus#FINAL} and {@link * DocumentStatus#ARCHIVED} will be retrieved. * * @param startDate {@link LocalDate} start date of the settlement (inclusive). * @param endDate {@link LocalDate} end date of the settlement (inclusive). * @return a {@link List} of {@link PtuPrognosis} ordered by period, participant domain and ptu index. *//*from w w w .j a va 2s .c o m*/ public List<PtuPrognosis> findPrognosesForSettlement(LocalDate startDate, LocalDate endDate) { StringBuilder sql = new StringBuilder(); sql.append("SELECT prognosis "); sql.append("FROM PtuPrognosis prognosis, PlanboardMessage pm "); sql.append("WHERE prognosis.ptuContainer.ptuDate >= :startDate "); sql.append(" AND prognosis.ptuContainer.ptuDate <= :endDate "); sql.append(" AND pm.period = prognosis.ptuContainer.ptuDate "); sql.append(" AND pm.participantDomain = prognosis.participantDomain "); sql.append(" AND pm.sequence = prognosis.sequence "); sql.append(" AND pm.connectionGroup = prognosis.connectionGroup "); sql.append(" AND pm.documentStatus IN (:documentStatuses) "); sql.append( "ORDER BY prognosis.ptuContainer.ptuDate, prognosis.participantDomain, prognosis.ptuContainer.ptuIndex "); return getEntityManager().createQuery(sql.toString(), PtuPrognosis.class) .setParameter("startDate", startDate.toDateMidnight().toDate(), TemporalType.DATE) .setParameter("endDate", endDate.toDateMidnight().toDate(), TemporalType.DATE) .setParameter("documentStatuses", Arrays.asList(DocumentStatus.ACCEPTED, DocumentStatus.FINAL, DocumentStatus.ARCHIVED)) .getResultList(); }
From source file:energy.usef.core.repository.PtuPrognosisRepository.java
License:Apache License
/** * Finds all the distinct prognoses offers that are linked to a flex order during the given period. * * @param period {@link LocalDate} period. * @return a {@link LocalDate} of all the {@link PtuPrognosis} entities. *//*from www .j a v a2 s.c om*/ public List<PtuPrognosis> findPrognosesWithOrderInPeriod(LocalDate period) { StringBuilder sql = new StringBuilder(); sql.append("SELECT DISTINCT prognosis "); sql.append( "FROM PtuPrognosis prognosis, PtuFlexRequest frequest, PtuFlexOffer foffer, PtuFlexOrder forder "); sql.append("WHERE prognosis.ptuContainer.ptuDate = :period "); sql.append(" AND frequest.ptuContainer.ptuDate = :period "); sql.append(" AND foffer.ptuContainer.ptuDate = :period "); sql.append(" AND forder.ptuContainer.ptuDate = :period "); sql.append(" AND forder.participantDomain = foffer.participantDomain "); sql.append(" AND foffer.participantDomain = frequest.participantDomain "); sql.append(" AND frequest.participantDomain = prognosis.participantDomain "); sql.append(" AND forder.flexOfferSequence = foffer.sequence "); sql.append(" AND foffer.flexRequestSequence = frequest.sequence "); sql.append(" AND frequest.prognosisSequence = prognosis.sequence "); sql.append(" AND forder.ptuContainer.ptuIndex = foffer.ptuContainer.ptuIndex "); sql.append(" AND foffer.ptuContainer.ptuIndex = frequest.ptuContainer.ptuIndex "); sql.append(" AND frequest.ptuContainer.ptuIndex = prognosis.ptuContainer.ptuIndex "); return getEntityManager().createQuery(sql.toString(), PtuPrognosis.class) .setParameter("period", period.toDateMidnight().toDate(), TemporalType.DATE).getResultList(); }
From source file:energy.usef.core.repository.PtuPrognosisRepository.java
License:Apache License
/** * Delete all {@link PtuPrognosis}s for a certain date. * * @param period/*from ww w. j a v a 2s. c o m*/ * @return the number of {@link PtuPrognosis}s deleted. */ public int cleanup(LocalDate period) { StringBuilder sql = new StringBuilder(); sql.append("DELETE FROM PtuPrognosis pp "); sql.append("WHERE pp.ptuContainer IN (SELECT pc FROM PtuContainer pc WHERE pc.ptuDate = :ptuDate)"); return entityManager.createQuery(sql.toString()).setParameter("ptuDate", period.toDateMidnight().toDate()) .executeUpdate(); }
From source file:energy.usef.core.repository.PtuSettlementRepository.java
License:Apache License
/** * Delete all {@link PtuSettlement}s for a certain date. * * @param period//from w ww . j a v a 2s . co m * @return the number of {@link PtuSettlement}s deleted. */ public int cleanup(LocalDate period) { StringBuilder sql = new StringBuilder(); sql.append("DELETE FROM PtuSettlement ps "); sql.append("WHERE ps.ptuContainer IN (SELECT pc FROM PtuContainer pc WHERE pc.ptuDate = :ptuDate)"); return entityManager.createQuery(sql.toString()).setParameter("ptuDate", period.toDateMidnight().toDate()) .executeUpdate(); }