Example usage for org.joda.time LocalDate toDate

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

Introduction

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

Prototype

@SuppressWarnings("deprecation")
public Date toDate() 

Source Link

Document

Get the date time as a java.util.Date.

Usage

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

License:Apache License

/**
 * Finds the PTU States.//from ww w .  j a  v  a  2  s .c  o m
 * 
 * @param ptuDate PTU date
 * @param usefIdentifier USEF identifier
 * @return
 */
@SuppressWarnings("unchecked")
public List<PtuState> findPtuStates(LocalDate ptuDate, String usefIdentifier) {
    List<PtuState> results = entityManager
            .createQuery("SELECT p FROM PtuState p WHERE p.ptuContainer.ptuDate = :ptuDate AND "
                    + "p.connectionGroup.usefIdentifier = :usefIdentifier")
            .setParameter("ptuDate", ptuDate.toDateMidnight().toDate())
            .setParameter("usefIdentifier", usefIdentifier).getResultList();
    if (results == null || results.isEmpty()) {
        results = new ArrayList<>();
    }
    return results;
}

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

License:Apache License

/**
 * Finds the PTU States./*from   w w w  . j  a v  a  2s  .  c  om*/
 * 
 * @param startDate start Date
 * @param endDate end Date
 * @param regimes
 * @return
 */
@SuppressWarnings("unchecked")
public List<PtuState> findPtuStates(LocalDate startDate, LocalDate endDate, RegimeType... regimes) {
    List<PtuState> results = entityManager.createQuery(
            "SELECT p FROM PtuState p WHERE p.ptuContainer.ptuDate >= :startDate AND p.ptuContainer.ptuDate <= :endDate AND p.regime IN :regimes")
            .setParameter("startDate", startDate.toDateMidnight().toDate())
            .setParameter("endDate", endDate.toDateMidnight().toDate())
            .setParameter("regimes", Arrays.asList(regimes)).getResultList();
    if (results == null || results.isEmpty()) {
        results = new ArrayList<>();
    }
    return results;
}

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

License:Apache License

/**
 * Delete all {@link PtuState}s for a certain date.
 *
 * @param period//from   w  w  w. ja va 2 s  .co m
 * @return the number of {@link PtuState}s deleted.
 */
public int cleanup(LocalDate period) {
    StringBuilder sql = new StringBuilder();
    sql.append("DELETE FROM PtuState 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();
}

From source file:energy.usef.dso.model.AggregatorOnConnectionGroupState.java

License:Apache License

public void setValidFrom(LocalDate validFrom) {
    this.validFrom = validFrom == null ? null : validFrom.toDateMidnight().toDate();
}

From source file:energy.usef.dso.model.AggregatorOnConnectionGroupState.java

License:Apache License

public void setValidUntil(LocalDate validUntil) {
    this.validUntil = validUntil == null ? null : validUntil.toDateMidnight().toDate();
}

From source file:energy.usef.dso.repository.AggregatorOnConnectionGroupStateRepository.java

License:Apache License

/**
 * Get Aggregators by CongestionPointAddress.
 *
 * @param congestionPointAddress {@link String} entity address of the congestion point.
 * @param dateTime {@link org.joda.time.LocalDateTime} validity moment of the {@link AggregatorOnConnectionGroupState}.
 * @return list of {@link Aggregator}./*from  w w w.ja  va 2s . c  o  m*/
 */
public List<Aggregator> getAggregatorsByCongestionPointAddress(String congestionPointAddress,
        LocalDate dateTime) {
    StringBuilder sql = new StringBuilder();
    sql.append("SELECT DISTINCT state.aggregator ");
    sql.append("FROM AggregatorOnConnectionGroupState state ");
    sql.append("WHERE state.congestionPointConnectionGroup.usefIdentifier = :congestionPointEntityAddress ");
    sql.append(" AND state.validFrom <= :date ");
    sql.append(" AND state.validUntil > :date ");
    return entityManager.createQuery(sql.toString(), Aggregator.class)
            .setParameter("congestionPointEntityAddress", congestionPointAddress)
            .setParameter("date", dateTime.toDateMidnight().toDate(), TemporalType.DATE).getResultList();
}

From source file:energy.usef.dso.repository.AggregatorOnConnectionGroupStateRepository.java

License:Apache License

/**
 * Find the {@link AggregatorOnConnectionGroupState}s for this congestionPoint in a moment in time.
 *
 * @param congestionPointAddress {@link String} entity address of the congestion point.
 * @param date {@link org.joda.time.LocalDate} validity moment of the states.
 * @return list of AggregatorOnConnectionGroupState elements
 *//*  w  ww. java  2  s .  c  o m*/
public List<AggregatorOnConnectionGroupState> findAggregatorOnConnectionGroupStateByCongestionPointAddress(
        String congestionPointAddress, LocalDate date) {
    StringBuilder sql = new StringBuilder();
    sql.append("SELECT DISTINCT state ");
    sql.append("FROM AggregatorOnConnectionGroupState state ");
    sql.append("WHERE state.congestionPointConnectionGroup.usefIdentifier = :congestionPointEntityAddress ");
    sql.append(" AND state.validFrom <= :date ");
    sql.append(" AND state.validUntil > :date ");
    return entityManager.createQuery(sql.toString(), AggregatorOnConnectionGroupState.class)
            .setParameter("congestionPointEntityAddress", congestionPointAddress)
            .setParameter("date", date.toDateMidnight().toDate(), TemporalType.DATE).getResultList();
}

From source file:energy.usef.dso.repository.AggregatorOnConnectionGroupStateRepository.java

License:Apache License

/**
 * Counts the {@link AggregatorOnConnectionGroupState}s for this congestionPoint in a moment in time.
 *
 * @param entityAddress The congestion Point Entity Address.
 * @param date The day./*w  w  w .  j  a v a  2s  . c  o m*/
 * @return the number of active aggregators for congestion point on given moment in time.
 */
public long countActiveAggregatorsForCongestionPointOnDay(String entityAddress, LocalDate date) {
    StringBuilder sql = new StringBuilder();
    sql.append("SELECT COUNT ( DISTINCT state.aggregator.domain) ");
    sql.append("FROM AggregatorOnConnectionGroupState state ");
    sql.append("WHERE state.congestionPointConnectionGroup.usefIdentifier = :congestionPointEntityAddress ");
    sql.append(" AND state.validFrom <= :date ");
    sql.append(" AND state.validUntil > :date ");
    return entityManager.createQuery(sql.toString(), Long.class)
            .setParameter("congestionPointEntityAddress", entityAddress)
            .setParameter("date", date.toDateMidnight().toDate(), TemporalType.DATE).getSingleResult();
}

From source file:energy.usef.dso.repository.AggregatorOnConnectionGroupStateRepository.java

License:Apache License

/**
 * Finds the Aggregators on a congestion point.
 *
 * @param period {@link LocalDate} period.
 * @return a {@link Map} with the congestion point as key ({@link CongestionPointConnectionGroup}) and a {@link List} of
 * {@link AggregatorOnConnectionGroupState} as value.
 *//*from w  ww  .  j av a 2s  .c o  m*/
public Map<CongestionPointConnectionGroup, List<AggregatorOnConnectionGroupState>> findConnectionGroupsWithAggregators(
        LocalDate period) {
    StringBuilder sql = new StringBuilder();
    sql.append("SELECT DISTINCT state ");
    sql.append("FROM AggregatorOnConnectionGroupState state ");
    sql.append("WHERE state.validFrom <= :date ");
    sql.append("  AND state.validUntil > :date ");
    List<AggregatorOnConnectionGroupState> states = getEntityManager()
            .createQuery(sql.toString(), AggregatorOnConnectionGroupState.class)
            .setParameter("date", period.toDateMidnight().toDate(), TemporalType.DATE).getResultList();
    return states.stream().collect(
            Collectors.groupingBy(AggregatorOnConnectionGroupState::getCongestionPointConnectionGroup));
}

From source file:energy.usef.dso.repository.AggregatorOnConnectionGroupStateRepository.java

License:Apache License

/**
 * Find State for an AggregatorOnConnectionGroup.
 *
 * @param aggregator {@link Aggregator} non-nullable aggregator.
 * @param congestionPoint {@link CongestionPointConnectionGroup} the congestion point.
 * @param date {@link org.joda.time.LocalDateTime} validity moment.
 * @return an {@link AggregatorOnConnectionGroupState} or <code>null</code>
 *///  w  w w .j a v  a  2 s. co  m
public AggregatorOnConnectionGroupState findStateForAggregatorOnConnectionGroup(Aggregator aggregator,
        CongestionPointConnectionGroup congestionPoint, LocalDate date) {
    StringBuilder sql = new StringBuilder();
    sql.append("SELECT state ");
    sql.append("FROM AggregatorOnConnectionGroupState state ");
    sql.append("WHERE state.congestionPointConnectionGroup = :congestionPoint ");
    sql.append(" AND state.aggregator.domain = :aggregatorDomain");
    sql.append(" AND state.validFrom <= :date");
    sql.append(" AND state.validUntil > :date");

    List<AggregatorOnConnectionGroupState> states = getEntityManager()
            .createQuery(sql.toString(), AggregatorOnConnectionGroupState.class)
            .setParameter("aggregatorDomain", aggregator.getDomain())
            .setParameter("congestionPoint", congestionPoint)
            .setParameter("date", date.toDateMidnight().toDate(), TemporalType.DATE).getResultList();
    if (states == null || states.isEmpty()) {
        return null;
    }
    return states.get(0);
}