List of usage examples for org.joda.time LocalDate toDateMidnight
@Deprecated
public DateMidnight toDateMidnight()
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 w w . j a v a 2 s .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> *//*from w w w . j a va 2 s. com*/ 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); }
From source file:energy.usef.dso.repository.AggregatorOnConnectionGroupStateRepository.java
License:Apache License
/** * Finds all the {@link AggregatorOnConnectionGroupState} entities with a validUntil date equal to the specified date. * * @param usefIdentifier {@link String} USEF identifier of the {@link ConnectionGroup}. * @param initializationDate {@link LocalDate} date. * @return a {@link List} of {@link AggregatorOnConnectionGroupState}. *///from w ww . jav a 2 s . co m public List<AggregatorOnConnectionGroupState> findEndingAggregatorOnConnectionGroupStates(String usefIdentifier, LocalDate initializationDate) { StringBuilder sql = new StringBuilder(); sql.append("SELECT state "); sql.append("FROM AggregatorOnConnectionGroupState state "); sql.append("WHERE state.congestionPointConnectionGroup.usefIdentifier = :usefIdentifier "); sql.append(" AND state.validUntil = :date "); return getEntityManager().createQuery(sql.toString(), AggregatorOnConnectionGroupState.class) .setParameter("usefIdentifier", usefIdentifier) .setParameter("date", initializationDate.toDateMidnight().toDate(), TemporalType.DATE) .getResultList(); }
From source file:energy.usef.dso.repository.AggregatorOnConnectionGroupStateRepository.java
License:Apache License
/** * Finds the {@link AggregatorOnConnectionGroupState} entities with an overlap over the given period. * * @param startDate {@link LocalDate} start date of the period. * @param endDate {@link LocalDate} end date of the period (inclusive). * @return a {@link List} of {@link AggregatorOnConnectionGroupState}. *///from ww w .j a v a2s . c o m public List<AggregatorOnConnectionGroupState> findAggregatorsWithOverlappingActivityForPeriod( LocalDate startDate, LocalDate endDate) { StringBuilder sql = new StringBuilder(); sql.append("SELECT state "); sql.append("FROM AggregatorOnConnectionGroupState state "); sql.append(" JOIN FETCH state.aggregator a "); sql.append(" JOIN FETCH state.congestionPointConnectionGroup c "); sql.append("WHERE state.validFrom <= :endDate "); sql.append(" AND state.validUntil > :startDate "); // valid until of a state is an excluded upper bound, so it has to be strictly bigger than the start date. return getEntityManager().createQuery(sql.toString(), AggregatorOnConnectionGroupState.class) .setParameter("startDate", startDate.toDateMidnight().toDate(), TemporalType.DATE) .setParameter("endDate", endDate.toDateMidnight().toDate(), TemporalType.DATE).getResultList(); }
From source file:energy.usef.dso.repository.ConnectionMeterEventRepository.java
License:Apache License
/** * This method finds all ConnectionMeterEvents for a certain period that where active in that period. * * @param fromDate from date/*from ww w . ja v a 2 s . c o m*/ * @param endDate end date * * @return connection meter event list */ @SuppressWarnings("unchecked") public List<ConnectionMeterEvent> findConnectionMeterEventsForPeriod(LocalDate fromDate, LocalDate endDate) { StringBuilder queryString = new StringBuilder(); queryString.append("SELECT cme FROM ConnectionMeterEvent cme "); queryString.append(" WHERE cme.dateTime >= :fromDate "); // it is inclusive because i add a day to the endDate queryString.append(" AND cme.dateTime < :endDate "); Query query = getEntityManager().createQuery(queryString.toString()); query.setParameter("fromDate", fromDate.toDateMidnight().toDateTime().toDate(), TemporalType.TIMESTAMP); query.setParameter("endDate", endDate.plusDays(1).toDateMidnight().toDateTime().toDate(), TemporalType.TIMESTAMP); return query.getResultList(); }
From source file:energy.usef.dso.repository.ConnectionMeterEventRepository.java
License:Apache License
/** * Finds connections not related to ConnectionMeterEvents. * /*from w w w .ja v a 2 s . c o m*/ * @param date date * @param connectionIncludeList connection include list * @return connection list */ public List<Connection> findConnectionsNotRelatedToConnectionMeterEvents(LocalDate date, List<String> connectionIncludeList) { StringBuilder sql = new StringBuilder(); sql.append("SELECT distinct cgs.connection FROM ConnectionGroupState cgs"); sql.append(" WHERE cgs.validFrom <= :startDate"); sql.append(" AND cgs.validUntil >= :startDate"); sql.append(" AND cgs.connection NOT IN "); sql.append( " (SELECT cme.connection FROM ConnectionMeterEvent cme WHERE cme.dateTime >= :startTime AND cme.dateTime < :endTime)"); sql.append(" AND cgs.connection.entityAddress IN :connectionIncludeList"); TypedQuery<Connection> query = entityManager.createQuery(sql.toString(), Connection.class); query.setParameter("startDate", date.toDateMidnight().toDate()); query.setParameter("startTime", date.toDateMidnight().toDateTime().toDate(), TemporalType.TIMESTAMP); query.setParameter("endTime", date.plusDays(1).toDateMidnight().toDateTime().toDate(), TemporalType.TIMESTAMP); query.setParameter("connectionIncludeList", connectionIncludeList); return query.getResultList(); }
From source file:energy.usef.dso.repository.ConnectionMeterEventRepository.java
License:Apache License
/** * This method finds a Connection for a given connection entity address and a certain period. * * @param entityAddress connection entity address * @param date date/*from w w w . j a va 2s . c o m*/ * * @return connection if exists, null otherwise */ @SuppressWarnings("unchecked") public Connection findConnectionForConnectionMeterEventsPeriod(String entityAddress, LocalDate date) { StringBuilder queryString = new StringBuilder(); queryString.append("SELECT cme.connection FROM ConnectionMeterEvent cme "); queryString.append(" WHERE cme.dateTime >= :fromTime "); queryString.append(" AND cme.dateTime < :endTime "); queryString.append(" AND cme.connection.entityAddress = :entityAddress "); Query query = getEntityManager().createQuery(queryString.toString()); query.setParameter("fromTime", date.toDateMidnight().toDateTime().toDate(), TemporalType.TIMESTAMP); query.setParameter("endTime", date.plusDays(1).toDateMidnight().toDateTime().toDate(), TemporalType.TIMESTAMP); query.setParameter("entityAddress", entityAddress); List<Connection> connections = query.getResultList(); if (connections.isEmpty()) { return null; } return connections.get(0); }
From source file:energy.usef.dso.repository.GridSafetyAnalysisRepository.java
License:Apache License
/** * Finds the {@link GridSafetyAnalysis} entities for the given parameters with disposition requested for at least one of the * ptu's.//from w w w . ja v a2 s. c o m * * @param congestionPointEntityAddress {@link String} related Congestion Point entity address. * @param ptuDate {@link LocalDate} Period of the PTU. * @return a {@link List} of {@link GridSafetyAnalysis}. */ @SuppressWarnings("unchecked") public List<GridSafetyAnalysis> findGridSafetyAnalysisWithDispositionRequested( String congestionPointEntityAddress, LocalDate ptuDate) { StringBuilder subqueryExists = new StringBuilder(); subqueryExists.append("SELECT 1 "); subqueryExists.append("FROM GridSafetyAnalysis gsa2 "); subqueryExists.append("WHERE gsa2.connectionGroup.usefIdentifier = :entityAddress "); subqueryExists.append(" AND gsa2.ptuContainer.ptuDate = :ptuDate "); subqueryExists.append(" AND gsa2.disposition = :dispositionRequested "); StringBuilder sql = new StringBuilder(); sql.append("SELECT gsa "); sql.append("FROM GridSafetyAnalysis gsa "); sql.append("WHERE gsa.connectionGroup.usefIdentifier = :entityAddress "); sql.append(" AND gsa.ptuContainer.ptuDate = :ptuDate "); sql.append(" AND EXISTS (").append(subqueryExists).append(") "); sql.append("ORDER BY gsa.ptuContainer.ptuIndex"); return getEntityManager().createQuery(sql.toString()) .setParameter("entityAddress", congestionPointEntityAddress) .setParameter("ptuDate", ptuDate.toDateMidnight().toDate()) .setParameter("dispositionRequested", DispositionAvailableRequested.REQUESTED).getResultList(); }
From source file:energy.usef.dso.repository.GridSafetyAnalysisRepository.java
License:Apache License
/** * Finds the {@link GridSafetyAnalysis} entities for a given day. * * @param congestionPointEntityAddress {@link String} related Congestion Point entity address. * @param ptuDate {@link LocalDate} Period of the PTU. * @return a {@link List} of {@link GridSafetyAnalysis}. *///from w w w.j a v a 2 s.c o m @SuppressWarnings("unchecked") public List<GridSafetyAnalysis> findGridSafetyAnalysis(String congestionPointEntityAddress, LocalDate ptuDate) { StringBuilder sql = new StringBuilder(); sql.append("SELECT gsa "); sql.append("FROM GridSafetyAnalysis gsa "); sql.append("WHERE gsa.connectionGroup.usefIdentifier = :entityAddress "); sql.append(" AND gsa.ptuContainer.ptuDate = :ptuDate "); sql.append("ORDER BY gsa.ptuContainer.ptuIndex"); return getEntityManager().createQuery(sql.toString()) .setParameter("entityAddress", congestionPointEntityAddress) .setParameter("ptuDate", ptuDate.toDateMidnight().toDate()).getResultList(); }
From source file:energy.usef.dso.repository.GridSafetyAnalysisRepository.java
License:Apache License
/** * Finds the {@link GridSafetyAnalysis} entities used in calculations to find optimal flex offer combinations required * to place flex orders./*from www. j a va 2s . com*/ * * @param currentDate current date * @return a {@link List} of {@link GridSafetyAnalysis}. */ @SuppressWarnings("unchecked") public List<GridSafetyAnalysis> findGridSafetyAnalysisRelatedToFlexOffers(LocalDate currentDate) { // Include the GridSafetyAnalysis only if there are FlexOffers that are ACCEPTED for the ConnectionGroup on that date. StringBuilder subqueryInPtuDates = new StringBuilder(); subqueryInPtuDates.append("SELECT pbm1.period FROM PlanboardMessage pbm1 "); subqueryInPtuDates.append("WHERE pbm1.documentType = :documentType "); subqueryInPtuDates.append("AND pbm1.documentStatus = :acceptedDocumentStatus "); subqueryInPtuDates.append("AND pbm1.connectionGroup.usefIdentifier = gsa.connectionGroup.usefIdentifier "); // Exclude the GridSafetyAnalysis if there are FlexOffers that are already PROCESSED for the ConnectionGroup on that date. StringBuilder subqueryNotInPtuDates = new StringBuilder(); subqueryNotInPtuDates.append("SELECT pbm2.period FROM PlanboardMessage pbm2 "); subqueryNotInPtuDates.append("WHERE pbm2.documentType = :documentType "); subqueryNotInPtuDates.append("AND pbm2.documentStatus = :processedDocumentStatus "); subqueryNotInPtuDates .append("AND pbm2.connectionGroup.usefIdentifier = gsa.connectionGroup.usefIdentifier "); StringBuilder sql = new StringBuilder(); sql.append("SELECT gsa "); sql.append("FROM GridSafetyAnalysis gsa "); sql.append("WHERE gsa.ptuContainer.ptuDate IN (").append(subqueryInPtuDates).append(") "); sql.append("AND gsa.ptuContainer.ptuDate NOT IN (").append(subqueryNotInPtuDates).append(") "); sql.append("AND gsa.ptuContainer.ptuDate >= :currentDate "); return getEntityManager().createQuery(sql.toString()).setParameter("documentType", DocumentType.FLEX_OFFER) .setParameter("acceptedDocumentStatus", DocumentStatus.ACCEPTED) .setParameter("processedDocumentStatus", DocumentStatus.PROCESSED) .setParameter("currentDate", currentDate.toDateMidnight().toDate()).getResultList(); }