List of usage examples for org.joda.time LocalDate toDate
@SuppressWarnings("deprecation") public Date toDate()
java.util.Date
. From source file:energy.usef.core.repository.ConnectionRepository.java
License:Apache License
/** * Finds the connection count for a specified usef identifier at a given moment. * * @param usefIdentifier {@link String} usef identifier. * @param period {@link LocalDate} validity period. * @return a {@link Long}./*from w w w. java2s . com*/ */ public Long findConnectionCountByUsefIdentifier(String usefIdentifier, LocalDate period) { StringBuilder sql = new StringBuilder(); sql.append("SELECT COUNT(cgs.connection) "); sql.append("FROM ConnectionGroupState cgs "); sql.append("WHERE cgs.validFrom <= :date "); sql.append(" AND cgs.connectionGroup.usefIdentifier = :usefIdentifier "); sql.append(" AND cgs.validUntil > :date "); return entityManager.createQuery(sql.toString(), Long.class).setParameter("usefIdentifier", usefIdentifier) .setParameter("date", period.toDateMidnight().toDate(), TemporalType.DATE).getSingleResult(); }
From source file:energy.usef.core.repository.ConnectionRepository.java
License:Apache License
/** * Find {@link Connection} per {@link ConnectionGroup}. * * @param usefIdentifier {@link String} usef identifier of the Connection group. * @param date {@link org.joda.time.LocalDateTime} validity time. * @return a {@link java.util.List} of {@link Connection}s. */// ww w.java 2 s . co m public List<Connection> findConnectionsForConnectionGroup(String usefIdentifier, LocalDate date) { StringBuilder sql = new StringBuilder(); sql.append("SELECT cgs.connection FROM ConnectionGroupState cgs "); sql.append(" WHERE cgs.validFrom <= :date "); sql.append(" AND cgs.connectionGroup.usefIdentifier = :usefIdentifier"); sql.append(" AND cgs.validUntil > :date "); return entityManager.createQuery(sql.toString(), Connection.class) .setParameter("date", date.toDateMidnight().toDate(), TemporalType.DATE) .setParameter("usefIdentifier", usefIdentifier).getResultList(); }
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 www.jav a2s . c o 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 .ja va 2 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.PlanboardMessageRepository.java
License:Apache License
/** * Finds last planboard messages corresponding to A-Plans. * * @param period period//from ww w.j a v a 2s . 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/* w ww. j a va 2s.c om*/ * @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).//from w w w . j a va 2 s . c om * * @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 w w . j ava2 s.c om 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 ww.java2s.co 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 av a2 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; }