List of usage examples for org.joda.time LocalDate toDate
@SuppressWarnings("deprecation") public Date toDate()
java.util.Date
. From source file:org.alexlg.bankit.dao.OperationDao.java
License:Open Source License
/** * Get operations from startDay to endDay. * /*from w ww.j a v a 2 s . co m*/ * @param startDay Day from which retrieve operations. * @param endDay Day to which retrieve operations * @return Operation list history * sorted by operation date and id. */ public List<Operation> getHistory(LocalDate startDay, LocalDate endDay) { CriteriaBuilder b = getBuilder(); //creating criteria CriteriaQuery<Operation> q = b.createQuery(Operation.class); Root<Operation> op = q.from(Operation.class); q.select(op); //adding restriction // - every operation between the start and end date // - every planned operation not sync before start date q.where(b.or(b.between(op.get(Operation_.operationDate), startDay.toDate(), endDay.toDate()), b.and(b.lessThan(op.get(Operation_.operationDate), startDay.toDate()), b.isNull(op.get(Operation_.amount))))); //ordering q.orderBy(b.asc(op.get(Operation_.operationDate)), b.asc(op.get(Operation_.operationId))); return getEm().createQuery(q).getResultList(); }
From source file:org.alexlg.bankit.dao.OperationDao.java
License:Open Source License
/** * Get balance of the account for previous operations. * @param day Get the balance for operation before this day * to the opening of the account * @return Balance of the account//from w ww .ja va 2s . co m */ public BigDecimal getBalanceHistory(LocalDate day) { CriteriaBuilder b = getBuilder(); //creating criteria CriteriaQuery<BigDecimal> q = b.createQuery(BigDecimal.class); Root<Operation> op = q.from(Operation.class); q.select(b.sum(op.get(Operation_.amount))); //adding restriction q.where(b.lessThan(op.get(Operation_.operationDate), day.toDate())); return getEm().createQuery(q).getSingleResult(); }
From source file:org.alexlg.bankit.dao.OperationDao.java
License:Open Source License
/** * Get all future planned operation beyond a day. * @param day Day from which get future operation * @return Future operation ordered by operation date and id *///from ww w. j a v a 2s .co m public List<Operation> getFuture(LocalDate day) { CriteriaBuilder b = getBuilder(); //creating criteria CriteriaQuery<Operation> q = b.createQuery(Operation.class); Root<Operation> op = q.from(Operation.class); q.select(op); //adding restriction q.where(b.greaterThan(op.get(Operation_.operationDate), day.toDate())); //ordering q.orderBy(b.asc(op.get(Operation_.operationDate)), b.asc(op.get(Operation_.operationId))); return getEm().createQuery(q).getResultList(); }
From source file:org.alexlg.bankit.dao.OperationDao.java
License:Open Source License
/** * Retrieve all planned operations with no amount before a date (included). * @param day Date from which retrieve the old operations. * @return List of old operations/*from www . ja v a2 s .c om*/ */ public List<Operation> getOldPlannedOps(LocalDate day) { CriteriaBuilder b = getBuilder(); //creating criteria CriteriaQuery<Operation> q = b.createQuery(Operation.class); Root<Operation> op = q.from(Operation.class); q.select(op); //adding restriction q.where(b.and(b.isNull(op.get(Operation_.amount)), b.lessThanOrEqualTo(op.get(Operation_.operationDate), day.toDate()))); return getEm().createQuery(q).getResultList(); }
From source file:org.alexlg.bankit.services.SyncService.java
License:Open Source License
/** * This function take all the costs between * the last execution to create the associated * operations in the operation list.//from www . ja va2 s . c o m * It runs every day at midnight and 5 seconds */ @Transactional @Scheduled(cron = "5 0 0 * * *") public void materializeCostsIntoOperation() { logger.info("Starting materializeCostsIntoOperation"); //materialize operations 2 days beyond current date LocalDate endDate = getEndSyncDate().plusDays(2); Date startSync = optionsService.getDate(COST_SYNC_OPT); if (startSync == null) { optionsService.set(COST_SYNC_OPT, endDate.toDate()); return; } LocalDate startDate = new LocalDate(startSync); //retrieve costs list List<Cost> costs = null; int nbMonth = 1; if (endDate.getYear() == startDate.getYear() && endDate.getMonthOfYear() == startDate.getMonthOfYear()) { //only retrieve the costs between this 2 "days" costs = costDao.getList(startDate.getDayOfMonth(), endDate.getDayOfMonth()); } else { //getting all costs costs = costDao.getList(); //we generate a least for the current month (as nbMonth = 1) //then we add whole months between start and end. nbMonth += Months.monthsBetween(startDate, endDate).getMonths(); //as monthsBetween calculate for whole month, if start is for example the 24-09 //and the end is the 02-10, monthsBetween will return 0 but we need to have //2 loops, one for september and one for november so we add a month. if (endDate.getDayOfMonth() <= startDate.getDayOfMonth()) { nbMonth++; } } //going through each month and each cost to create the operation for (int m = 0; m < nbMonth; m++) { LocalDate curMonth = startDate.plusMonths(m); int lastDayOfMonth = curMonth.dayOfMonth().getMaximumValue(); for (Cost cost : costs) { int costDay = cost.getDay(); //if the operation is planned after the last day of month //set it to the last day if (costDay > lastDayOfMonth) costDay = lastDayOfMonth; //creating operation date LocalDate opDate = new LocalDate(curMonth.getYear(), curMonth.getMonthOfYear(), costDay); //check if date is in the date interval before creating op if (opDate.isAfter(startDate) && opDate.compareTo(endDate) <= 0) { Operation op = new Operation(); op.setOperationDate(opDate.toDate()); op.setLabel(cost.getLabel()); op.setPlanned(cost.getAmount()); op.setCategory(cost.getCategory()); operationDao.save(op); } } } optionsService.set(COST_SYNC_OPT, endDate.toDate()); }
From source file:org.alexlg.bankit.services.SyncService.java
License:Open Source License
/** * Sync a list of operation with current ones. * @param operations Operations to sync. *//* w ww. ja v a 2 s. c o m*/ public void syncOpList(List<Operation> operations) { if (operations == null) return; Date start = optionsService.getDate(OP_SYNC_OPT); LocalDate startSync = start == null ? null : LocalDate.fromDateFields(start); LocalDate maxDate = null; //older operation date for (Operation op : operations) { LocalDate opDate = LocalDate.fromDateFields(op.getOperationDate()); if (startSync == null || opDate.isAfter(startSync)) { operationDao.insert(op); //checking if operation if after maxDate if (maxDate == null || opDate.isAfter(maxDate)) maxDate = opDate; } } //setting last execution if (maxDate != null) optionsService.set(OP_SYNC_OPT, maxDate.toDate()); }
From source file:org.apache.cayenne.joda.access.types.LocalDateType.java
License:Apache License
@Override public void setJdbcObject(PreparedStatement statement, LocalDate value, int pos, int type, int scale) throws Exception { if (value == null) { statement.setNull(pos, type);/*from w ww .j a v a 2 s.co m*/ } else { long time = value.toDate().getTime(); if (type == Types.DATE) { statement.setDate(pos, new Date(time)); } else { statement.setTimestamp(pos, new Timestamp(time)); } } }
From source file:org.apache.fineract.infrastructure.scheduledemail.domain.EmailCampaign.java
License:Apache License
private EmailCampaign(final String campaignName, final Integer campaignType, final Report businessRuleId, final String paramValue, final String emailSubject, final String emailMessage, final LocalDate submittedOnDate, final AppUser submittedBy, final Report stretchyReport, final String stretchyReportParamMap, final ScheduledEmailAttachmentFileFormat emailAttachmentFileFormat, final String recurrence, final LocalDateTime localDateTime) { this.campaignName = campaignName; this.campaignType = EmailCampaignType.fromInt(campaignType).getValue(); this.businessRuleId = businessRuleId; this.paramValue = paramValue; this.status = EmailCampaignStatus.PENDING.getValue(); this.emailSubject = emailSubject; this.emailMessage = emailMessage; this.emailAttachmentFileFormat = emailAttachmentFileFormat.getValue(); this.stretchyReport = stretchyReport; this.stretchyReportParamMap = stretchyReportParamMap; this.submittedOnDate = submittedOnDate.toDate(); this.submittedBy = submittedBy; this.recurrence = recurrence; LocalDateTime recurrenceStartDate = new LocalDateTime(); this.isVisible = true; if (localDateTime != null) { this.recurrenceStartDate = localDateTime.toDate(); } else {//from ww w . j ava 2 s. c om this.recurrenceStartDate = recurrenceStartDate.toDate(); } }
From source file:org.apache.fineract.infrastructure.scheduledemail.domain.EmailCampaign.java
License:Apache License
public void activate(final AppUser currentUser, final DateTimeFormatter formatter, final LocalDate activationLocalDate) { if (isActive()) { //handle errors if already activated final String defaultUserMessage = "Cannot activate campaign. Campaign is already active."; final ApiParameterError error = ApiParameterError.parameterError("error.msg.campaign.already.active", defaultUserMessage, EmailCampaignValidator.activationDateParamName, activationLocalDate.toString(formatter)); final List<ApiParameterError> dataValidationErrors = new ArrayList<ApiParameterError>(); dataValidationErrors.add(error); throw new PlatformApiDataValidationException(dataValidationErrors); }// ww w . j a v a2 s . co m this.approvedOnDate = activationLocalDate.toDate(); this.approvedBy = currentUser; this.status = EmailCampaignStatus.ACTIVE.getValue(); validate(); }
From source file:org.apache.fineract.infrastructure.scheduledemail.domain.EmailCampaign.java
License:Apache License
public void close(final AppUser currentUser, final DateTimeFormatter dateTimeFormatter, final LocalDate closureLocalDate) { if (isClosed()) { //handle errors if already activated final String defaultUserMessage = "Cannot close campaign. Campaign already in closed state."; final ApiParameterError error = ApiParameterError.parameterError("error.msg.campaign.already.closed", defaultUserMessage, EmailCampaignValidator.statusParamName, EmailCampaignStatus.fromInt(this.status).getCode()); final List<ApiParameterError> dataValidationErrors = new ArrayList<ApiParameterError>(); dataValidationErrors.add(error); throw new PlatformApiDataValidationException(dataValidationErrors); }/* www . j av a 2 s . c om*/ if (this.campaignType.intValue() == EmailCampaignType.SCHEDULE.getValue()) { this.nextTriggerDate = null; this.lastTriggerDate = null; } this.closedBy = currentUser; this.closureDate = closureLocalDate.toDate(); this.status = EmailCampaignStatus.CLOSED.getValue(); validateClosureDate(); }