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.FlexOrderSettlementRepository.java

License:Apache License

/**
 * Finds the Flex Order Settlement entities for the given period, ordered by participant domain, connection group and period.
 *
 * @param startDate {@link LocalDate} start date of the period (inclusive).
 * @param endDate {@link LocalDate} end date of the period (inclusive).
 * @param connectionGroup {@link Optional} USEF identifier of the connection group of the flex order settlement.
 * @param participantDomain {@link Optional} participant domain of the flex order settlement.
 * @return a {@link List} of {@link FlexOrderSettlement} entities.
 *//*from  w w w .j  a v  a 2  s .  co  m*/
public List<FlexOrderSettlement> findFlexOrderSettlementsForPeriod(LocalDate startDate, LocalDate endDate,
        Optional<String> connectionGroup, Optional<String> participantDomain) {
    StringBuilder sql = new StringBuilder();
    sql.append("SELECT fos ");
    sql.append("FROM FlexOrderSettlement fos ");
    sql.append("WHERE fos.period >= :startDate AND fos.period <= :endDate ");
    connectionGroup.ifPresent(
            usefIdentifier -> sql.append("  AND fos.connectionGroup.usefIdentifier = :usefIdentifier"));
    participantDomain
            .ifPresent(domain -> sql.append("  AND fos.flexOrder.participantDomain = :participantDomain "));
    sql.append("ORDER BY fos.flexOrder.participantDomain, fos.flexOrder.connectionGroup, fos.period ");

    TypedQuery<FlexOrderSettlement> query = getEntityManager().createQuery(sql.toString(),
            FlexOrderSettlement.class);
    query.setParameter("startDate", startDate.toDateMidnight().toDate(), TemporalType.DATE);
    query.setParameter("endDate", endDate.toDateMidnight().toDate(), TemporalType.DATE);
    connectionGroup.ifPresent(usefIdentifier -> query.setParameter("usefIdentifier", usefIdentifier));
    participantDomain.ifPresent(domain -> query.setParameter("participantDomain", domain));
    return query.getResultList();
}

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

License:Apache License

/**
 * Delete all {@link FlexOrderSettlement}s for a certain date.
 *
 * @param period//from w w  w.  j a  va2 s  .  c o m
 * @return the number of {@link FlexOrderSettlement}s deleted.
 */
public int cleanup(LocalDate period) {
    StringBuilder sql = new StringBuilder();
    sql.append("DELETE FROM FlexOrderSettlement fos WHERE fos.period = :period");

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

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

License:Apache License

/**
 * Delete all {@link MessageError}s for a certain date.
 *
 * @param period/*  w  w w.  j a va 2 s .  c o  m*/
 * @return the number of {@link MessageError}s deleted.
 */
public int cleanup(LocalDate period) {
    LocalDate endDate = period.plusDays(1);

    Date start = new Date(period.toDateMidnight().getMillis());
    Date end = new Date(endDate.toDateMidnight().getMillis());

    StringBuilder sql = new StringBuilder();
    sql.append("DELETE FROM MessageError me ");
    sql.append(
            "WHERE me.message IN (SELECT m FROM Message m WHERE m.creationTime >= :start AND m.creationTime < :end)");

    return entityManager.createQuery(sql.toString()).setParameter("start", start).setParameter("end", end)
            .executeUpdate();
}

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

License:Apache License

/**
 * Delete all {@link Message}s created on a certain date.
 *
 * @param period//w  w  w.  ja v  a2s.  c  o m
 * @return the number of {@link Message}s deleted.
 */
public int cleanup(LocalDate period) {
    LocalDate endDate = period.plusDays(1);

    Date start = new Date(period.toDateMidnight().getMillis());
    Date end = new Date(endDate.toDateMidnight().getMillis());
    StringBuilder sql = new StringBuilder();
    sql.append("DELETE FROM Message m WHERE m.creationTime >= :start AND m.creationTime < :end");

    return entityManager.createQuery(sql.toString()).setParameter("start", start, TIMESTAMP)
            .setParameter("end", end, TIMESTAMP).executeUpdate();
}

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

License:Apache License

/**
 * Finds last planboard messages corresponding to A-Plans.
 *
 * @param period period//w w  w. jav a2 s .  c  o m
 * @return last planboard messages corresponding to A-Plans
 */
@SuppressWarnings("unchecked")
public List<PlanboardMessage> findLastAPlanPlanboardMessages(LocalDate period) {
    StringBuilder sql = new StringBuilder();
    sql.append("SELECT pbm1 ");
    sql.append(" FROM PlanboardMessage pbm1");
    sql.append(" WHERE pbm1.sequence IN ");
    sql.append(" (SELECT MAX(pbm.sequence)");
    sql.append("   FROM PlanboardMessage pbm ");
    sql.append("  WHERE pbm.documentStatus <> :rejected ");
    sql.append("    AND pbm.period = :period ");
    sql.append("    AND pbm.documentType = :documentType ");
    sql.append("  GROUP BY pbm.participantDomain)");

    List<PlanboardMessage> result = entityManager.createQuery(sql.toString())
            .setParameter("rejected", DocumentStatus.REJECTED)
            .setParameter("period", period.toDateMidnight().toDate())
            .setParameter("documentType", DocumentType.A_PLAN).getResultList();

    if (result == null) {
        result = new ArrayList<>();
    }
    return result;
}

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

License:Apache License

/**
 * Finds a single plan board message by period.
 *
 * @param period            The period/*from   w  ww .  j  a  v a2 s  . com*/
 * @param documentType      document type
 * @param participantDomain - The participantDomain which is being communicated with.
 * @return a single planboard message or <code>null</code>
 */
@SuppressWarnings("unchecked")
public PlanboardMessage findSinglePlanboardMessage(LocalDate period, DocumentType documentType,
        String participantDomain) {
    StringBuilder sql = new StringBuilder();
    sql.append("SELECT pbm ");
    sql.append("FROM PlanboardMessage pbm ");
    sql.append("WHERE pbm.documentStatus <> :rejected");
    sql.append("  AND pbm.period = :period");
    sql.append("  AND pbm.documentType = :documentType ");
    sql.append("  AND pbm.participantDomain = :participantDomain ");

    List<PlanboardMessage> result = entityManager.createQuery(sql.toString())
            .setParameter("rejected", DocumentStatus.REJECTED)
            .setParameter("period", period.toDateMidnight().toDate()).setParameter("documentType", documentType)
            .setParameter("participantDomain", participantDomain).getResultList();
    if (result == null || result.isEmpty()) {
        return null;
    }
    return result.get(0);
}

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

License:Apache License

/**
 * This method finds {@link PlanboardMessage} based on {@link DocumentType} and {@link DocumentStatus} within a time frame
 * (startDate - endDate)./*w  ww.ja  v  a2  s  .com*/
 *
 * @param documentType   The type of document, like request, offer or order.
 * @param period         The date of the planboard message
 * @param documentStatus The status of document, like new, submitted or rejected.
 * @return The list of {@link PlanboardMessage} which have a specific {@link DocumentType} and {@link DocumentStatus}.
 */
@SuppressWarnings("unchecked")
public List<PlanboardMessage> findPlanboardMessages(DocumentType documentType, LocalDate period,
        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 = :period ");
    if (documentStatus != null) {
        sql.append(" AND pm.documentStatus = :documentStatus ");
    }

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

    if (documentStatus != null) {
        query.setParameter("documentStatus", documentStatus);
    }
    return query.getResultList();

}

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

License:Apache License

/**
 * Finds maximal planboard message sequence of a certain {@link DocumentType} for a given participant optionally, a specific
 * USEF identifier and the {@link DocumentStatus} of the planboard message can be specified.
 *
 * @param documentType      {@link DocumentType} mandatory document type.
 * @param participantDomain {@link String} mandatory participant domain.
 * @param period            {@link LocalDate} mandatory period.
 * @param usefIdentifier    {@link String} optional usefIdentifier of the {@link ConnectionGroup} related to the message.
 * @param documentStatus    {@link DocumentStatus} optional document status.
 * @return a {@link Long} maximal planboard message sequence, if there is no record in the table 0 value is returned .
 *//*from w  ww .  j a  v a 2 s  . c o  m*/
public Long findMaxPlanboardMessageSequence(DocumentType documentType, String participantDomain,
        LocalDate period, String usefIdentifier, DocumentStatus documentStatus) {
    StringBuilder sql = new StringBuilder();
    sql.append("SELECT MAX(pm.sequence) ");
    sql.append("FROM PlanboardMessage pm ");
    sql.append("WHERE pm.documentType = :documentType ");
    sql.append(" AND pm.documentStatus <> :rejected ");
    sql.append(" AND pm.participantDomain = :participantDomain ");
    sql.append(" AND pm.period = :period ");
    if (usefIdentifier != null) {
        sql.append(" AND pm.connectionGroup.usefIdentifier= :usefIdentifier ");
    }
    if (documentStatus != null) {
        sql.append(" AND pm.documentStatus = :documentStatus ");
    }

    Query query = getEntityManager().createQuery(sql.toString())
            .setParameter("rejected", DocumentStatus.REJECTED).setParameter("documentType", documentType)
            .setParameter("participantDomain", participantDomain)
            .setParameter("period", period.toDateMidnight().toDate());
    if (usefIdentifier != null) {
        query.setParameter("usefIdentifier", usefIdentifier);
    }
    if (documentStatus != null) {
        query.setParameter("documentStatus", documentStatus);
    }

    if (query.getResultList().isEmpty() || query.getResultList().get(0) == null) {
        return 0L;
    }

    return (Long) query.getResultList().get(0);
}

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

License:Apache License

/**
 * Finds all the {@link PlanboardMessage} entities with the given document type, for a given period and related to a given
 * connection group.//w  w  w  . j ava 2 s.c o  m
 *
 * @param documentType   {@link DocumentType} of the message.
 * @param period         {@link LocalDate} period of the message.
 * @param usefIdentifier {@link String} USEF identifier of the connection group of the message.
 * @return a {@link List} of {@link PlanboardMessage}.
 */
public List<PlanboardMessage> findAcceptedPlanboardMessagesForConnectionGroup(DocumentType documentType,
        LocalDate period, String usefIdentifier) {
    StringBuilder sql = new StringBuilder();
    sql.append("SELECT pm FROM PlanboardMessage pm ");
    sql.append("WHERE pm.documentType = :documentType ");
    sql.append("  AND pm.period = :period ");
    sql.append("  AND pm.documentStatus = :documentStatus ");
    sql.append("  AND pm.connectionGroup.usefIdentifier = :usefIdentifier ");
    sql.append("ORDER BY pm.participantDomain, pm.sequence");
    return getEntityManager().createQuery(sql.toString(), PlanboardMessage.class)
            .setParameter("documentType", documentType)
            .setParameter("period", period.toDateMidnight().toDate(), TemporalType.DATE)
            .setParameter("usefIdentifier", usefIdentifier)
            .setParameter("documentStatus", DocumentStatus.ACCEPTED).getResultList();
}

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

License:Apache License

private Query buildQueryForFindPlanboardMessage(DocumentType documentType, String participantDomain,
        String usefIdentifier, DocumentStatus documentStatus, LocalDate validFrom, LocalDate validUntil,
        StringBuilder sql) {//from   w  ww .j  a va2 s.  c o  m
    Query query = getEntityManager().createQuery(sql.toString())
            .setParameter("rejected", DocumentStatus.REJECTED).setParameter("documentType", documentType);
    if (participantDomain != null) {
        query.setParameter("participantDomain", participantDomain);
    }
    if (usefIdentifier != null) {
        query.setParameter("usefIdentifier", usefIdentifier);
    }
    if (documentStatus != null) {
        query.setParameter("documentStatus", documentStatus);
    }
    if (validFrom != null) {
        query.setParameter("validFrom", validFrom.toDateMidnight().toDate());
    }
    if (validUntil != null) {
        query.setParameter("validUntil", validUntil.toDateMidnight().toDate());
    }
    return query;
}