Example usage for org.joda.time LocalDate toDateMidnight

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

Introduction

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

Prototype

@Deprecated
public DateMidnight toDateMidnight() 

Source Link

Document

Converts this LocalDate to a DateMidnight in the default time zone.

Usage

From source file:energy.usef.core.repository.PlanboardMessageRepository.java

License:Apache License

/**
 * Find all the planboard messages of a given type for a given document status with a time period (startDate until endDate).
 *
 * @param documentType   {@link DocumentType} document type of the planboard message.
 * @param startDate      {@link LocalDate} starting date of the period.
 * @param endDate        {@link LocalDate} end date of the period.
 * @param documentStatus {@link DocumentStatus} optional document status.
 * @return the {@link PlanboardMessage} matching the requested parameters.
 */// w  w w .  ja  v a  2 s  . c  o m
@SuppressWarnings("unchecked")
public List<PlanboardMessage> findPlanboardMessages(DocumentType documentType, LocalDate startDate,
        LocalDate endDate, DocumentStatus documentStatus) {
    StringBuilder sql = new StringBuilder();
    sql.append("SELECT pm ");
    sql.append("FROM PlanboardMessage pm ");
    sql.append("WHERE pm.documentType = :documentType ");
    sql.append(" AND pm.documentStatus <> :rejected ");
    sql.append(" AND pm.period BETWEEN :startDate AND :endDate ");
    if (documentStatus != null) {
        sql.append(" AND pm.documentStatus = :documentStatus ");
    }

    Query query = getEntityManager().createQuery(sql.toString())
            .setParameter("rejected", DocumentStatus.REJECTED).setParameter("documentType", documentType)
            .setParameter("startDate", startDate.toDateMidnight().toDate())
            .setParameter("endDate", endDate.toDateMidnight().toDate());
    if (documentStatus != null) {
        query.setParameter("documentStatus", documentStatus);
    }
    return query.getResultList();

}

From source file:energy.usef.core.repository.PlanboardMessageRepository.java

License:Apache License

/**
 * This method finds rejected {@link PlanboardMessage} based on {@link DocumentType} and {@link DocumentStatus} within a time
 * frame/*from  w  w w.j a  v a 2 s . c  o  m*/
 * (startDate - endDate).
 *
 * @param documentType The type of document, like request, offer or order.
 * @param period       The date of the planboard message
 * @return The list of {@link PlanboardMessage} which have a specific {@link DocumentType} and {@link DocumentStatus}.
 */
@SuppressWarnings("unchecked")
public List<PlanboardMessage> findRejectedPlanboardMessages(DocumentType documentType, LocalDate period) {
    StringBuilder sql = new StringBuilder();
    sql.append("SELECT pm ");
    sql.append("FROM PlanboardMessage pm ");
    sql.append("WHERE pm.documentType = :documentType ");
    sql.append(" AND pm.documentStatus = :rejected ");
    sql.append(" AND pm.period = :period ");

    Query query = getEntityManager().createQuery(sql.toString()).setParameter("documentType", documentType)
            .setParameter("rejected", DocumentStatus.REJECTED)
            .setParameter("period", period.toDateMidnight().toDate());

    return query.getResultList();

}

From source file:energy.usef.core.repository.PlanboardMessageRepository.java

License:Apache License

/**
 * Find Prognosis for period for connectionGroupIdentifier and/or ParticipantDomain.
 *
 * @param date                      period ({@link LocalDate})
 * @param connectionGroupIdentifier (optional)
 * @param participantDomain         (optional)
 * @return A {@link List} of {@link PlanboardMessage} objects
 *///from w  w w . j  a v  a  2  s . c o m
@SuppressWarnings("unchecked")
public List<PlanboardMessage> findPrognosisRelevantForDateByUsefIdentifier(LocalDate date,
        String connectionGroupIdentifier, String participantDomain) {
    StringBuilder sql = new StringBuilder();
    sql.append("SELECT pm ");
    sql.append("FROM PlanboardMessage pm ");
    sql.append("WHERE ( pm.documentType = 'A_PLAN' OR pm.documentType = 'D_PROGNOSIS' )");
    sql.append(" AND pm.period = :date ");
    sql.append(" AND pm.documentStatus IN (:statuses)  ");
    if (participantDomain != null) {
        sql.append(" AND pm.participantDomain = :participantDomain ");
    }
    if (connectionGroupIdentifier != null) {
        sql.append(" AND pm.connectionGroup.usefIdentifier = :connectionGroupIdentifier ");
    }

    Query query = getEntityManager().createQuery(sql.toString());
    query.setParameter("date", date.toDateMidnight().toDate(), TemporalType.DATE);
    query.setParameter("statuses",
            Arrays.asList(DocumentStatus.ACCEPTED, DocumentStatus.ARCHIVED, DocumentStatus.FINAL));
    if (participantDomain != null) {
        query.setParameter("participantDomain", participantDomain);
    }
    if (connectionGroupIdentifier != null) {
        query.setParameter("connectionGroupIdentifier", connectionGroupIdentifier);
    }
    return query.getResultList();
}

From source file:energy.usef.core.repository.PlanboardMessageRepository.java

License:Apache License

/**
 * Find Prognosis for period for connectionGroupIdentifier.
 *
 * @param date                      the period ({@link LocalDate})
 * @param connectionGroupIdentifier (optional)
 * @return A {@link List} of {@link PlanboardMessage} objects
 *///w w  w .j  av  a2s.  co m
@SuppressWarnings("unchecked")
public List<PlanboardMessage> findPrognosisRelevantForDate(LocalDate date, String connectionGroupIdentifier) {
    StringBuilder sql = new StringBuilder();
    sql.append("SELECT pm ");
    sql.append("FROM PlanboardMessage pm ");
    sql.append("WHERE ( pm.documentType = 'A_PLAN' OR pm.documentType = 'D_PROGNOSIS' )");
    sql.append(" AND documentStatus <> :rejected ");
    sql.append(" AND pm.period = :date ");
    sql.append(" AND pm.connectionGroup.usefIdentifier = :connectionGroupIdentifier ");

    Query query = getEntityManager().createQuery(sql.toString());
    query.setParameter("rejected", DocumentStatus.REJECTED);
    query.setParameter("date", date.toDateMidnight().toDate());
    query.setParameter("connectionGroupIdentifier", connectionGroupIdentifier);
    return query.getResultList();
}

From source file:energy.usef.core.repository.PlanboardMessageRepository.java

License:Apache License

/**
 * Delete all {@link PlanboardMessage}s created for a specific period.
 *
 * @param period//from  w ww. j a  va  2  s. c  o  m
 * @return the number of {@link PlanboardMessage}s deleted.
 */
public int cleanup(LocalDate period) {
    String sql = "DELETE FROM PlanboardMessage pm WHERE pm.period = :period";

    return entityManager.createQuery(sql).setParameter("period", period.toDateMidnight().toDate())
            .executeUpdate();
}

From source file:energy.usef.core.repository.PtuContainerRepository.java

License:Apache License

/**
 * Finds {@link PtuContainer} entity for given period and a given index. This method should only be called in a OPERATE
 * context and not in a loop. If in a loop, use {@link PtuContainerRepository#findPtuContainersMap(LocalDate)};
 *
 * @param period {@link LocalDate} period.
 * @param ptuIndex {@link Integer} The Ptu Index.
 * @return a {@link PtuContainer}.// w w  w. j av a 2s . c  o m
 */
public PtuContainer findPtuContainer(LocalDate period, Integer ptuIndex) {
    StringBuilder sql = new StringBuilder();
    sql.append("SELECT ptu ");
    sql.append("FROM PtuContainer ptu ");
    sql.append("WHERE ptu.ptuDate = :ptuDate AND ptu.ptuIndex = :ptuIndex ");
    List<PtuContainer> result = entityManager.createQuery(sql.toString(), PtuContainer.class)
            .setParameter("ptuDate", period.toDateMidnight().toDate(), TemporalType.DATE)
            .setParameter("ptuIndex", ptuIndex).getResultList();
    if (result.isEmpty()) {
        return null;
    }
    return result.get(0);
}

From source file:energy.usef.core.repository.PtuContainerRepository.java

License:Apache License

/**
 * Finds {@link PtuContainer} entities for given period.
 *
 * @param period {@link LocalDate} period.
 * @return a {@link List} of {@link PtuContainer}s.
 *//*from   w  w  w  .j av  a  2  s.  co  m*/
public List<PtuContainer> findPtuContainers(LocalDate period) {
    StringBuilder sql = new StringBuilder();
    sql.append("SELECT ptu ");
    sql.append("FROM PtuContainer ptu ");
    sql.append("WHERE ptu.ptuDate = :ptuDate ");
    sql.append("ORDER BY ptu.ptuIndex ");
    return entityManager.createQuery(sql.toString(), PtuContainer.class)
            .setParameter("ptuDate", period.toDateMidnight().toDate(), TemporalType.DATE).getResultList();
}

From source file:energy.usef.core.repository.PtuContainerRepository.java

License:Apache License

/**
 * Apply a bulk update to the PtuContainer entities.
 *
 * @param state {@link PtuContainerState} new state of the {@link PtuContainer}.
 * @param period {@link LocalDate} date of the {@link PtuContainer} that will be changed.
 * @param ptuIndex {@link Integer}. Optional filter to limit the update to a specific PTU index.
 * @return the number of records updated.
 *//* ww  w .  j a  va  2 s  .  co  m*/
@SuppressWarnings("unchecked")
public int updatePtuContainersState(PtuContainerState state, LocalDate period, Integer ptuIndex) {
    if (state == null) {
        throw new IllegalArgumentException("Cannot have a null PtuContainerState.");
    }
    if (period == null) {
        throw new IllegalArgumentException("Cannot have a null ptu period.");
    }
    StringBuilder sql = new StringBuilder();
    sql.append("SELECT p ");
    sql.append("FROM PtuState p ");
    sql.append("WHERE p.ptuContainer.ptuDate = :period ");
    if (ptuIndex != null) {
        sql.append(" AND p.ptuContainer.ptuIndex = :ptuIndex ");
    }

    Query query = getEntityManager().createQuery(sql.toString()).setParameter("period",
            period.toDateMidnight().toDate());
    if (ptuIndex != null) {
        query = query.setParameter("ptuIndex", ptuIndex);
    }

    int i = 0;
    List<PtuState> resultList = query.getResultList();
    for (PtuState ptuState : resultList) {
        ptuState.setState(state);
        i++;
    }

    return i;
}

From source file:energy.usef.core.repository.PtuContainerRepository.java

License:Apache License

/**
 * Apply a bulk update to the PtuContainer entities.
 *
 * @param phase {@link PhaseType} new PhaseType of the {@link PtuContainer}.
 * @param period {@link LocalDate} date of the {@link PtuContainer} that will be changed.
 * @param ptuIndex {@link Integer}. Optional filter to limit the update to a specific PTU index.
 * @return the number of records updated.
 *//* ww w.  ja  va  2s .  c  om*/
@Transactional(Transactional.TxType.REQUIRES_NEW)
public int updatePtuContainersPhase(PhaseType phase, LocalDate period, Integer ptuIndex) {
    boolean isPlanValidate = PhaseType.Plan.equals(phase) || PhaseType.Validate.equals(phase);

    StringBuilder sql = new StringBuilder();
    sql.append("UPDATE PtuContainer ");
    sql.append("SET phase = :phase ");
    sql.append("WHERE ptuDate = :period ");
    if (isPlanValidate && period.equals(DateTimeUtil.getCurrentDate())) {
        // only future ptus may be updated.
        sql.append(" AND ptuIndex > :currentPtu ");
    }
    if (ptuIndex != null) {
        sql.append(" AND ptuIndex = :ptuIndex ");
    }

    Query query = getEntityManager().createQuery(sql.toString()).setParameter("phase", phase)
            .setParameter("period", period.toDateMidnight().toDate());

    if (isPlanValidate && period.equals(DateTimeUtil.getCurrentDate())) {
        // only future ptus may be updated.
        int currentPtuIndex = PtuUtil.getPtuIndex(
                DateTimeUtil.getCurrentDateTime().plusSeconds(PTU_OFFSET_IN_SECONDS),
                config.getIntegerProperty(ConfigParam.PTU_DURATION));
        query = query.setParameter("currentPtu", currentPtuIndex);
    }
    if (ptuIndex != null) {
        query = query.setParameter("ptuIndex", ptuIndex);
    }
    return query.executeUpdate();
}

From source file:energy.usef.core.repository.PtuContainerRepository.java

License:Apache License

/**
 * Gets the ptuContainers for a certain day and phases.
 *
 * @param ptuDate PTU date/*  w  w w.j a  v a  2s.co  m*/
 * @param phases PTU phases
 * @return PTUContainer list
 */
@SuppressWarnings("unchecked")
public List<PtuContainer> findPtuContainers(LocalDate ptuDate, PhaseType... phases) {
    if (phases == null || phases.length == 0) {
        throw new IllegalArgumentException("Cannot have a null phase.");
    }
    StringBuilder inString = new StringBuilder();
    for (PhaseType phase : phases) {
        inString.append(inString.length() == 0 ? "" : ", ").append("'").append(phase.name()).append("'");
    }
    return entityManager
            .createQuery("SELECT pc FROM PtuContainer pc  WHERE pc.ptuDate = :ptuDate AND pc.phase IN ("
                    + inString.toString() + ")")
            .setParameter("ptuDate", ptuDate.toDateMidnight().toDate()).getResultList();
}