List of usage examples for org.joda.time LocalDate isBefore
public boolean isBefore(ReadablePartial partial)
From source file:energy.usef.agr.service.business.AgrValidationBusinessService.java
License:Apache License
/** * FlexOrders should only be accepted if they refer to a future period or contain future PTU's with a power value != 0. * * @param order is the {@link FlexOrder} to validate * @throws BusinessValidationException//ww w. j av a 2 s . c o m */ public void validateFlexOrderTiming(FlexOrder order) throws BusinessValidationException { Integer ptuDuration = config.getIntegerProperty(ConfigParam.PTU_DURATION); LocalDateTime currentDateTime = DateTimeUtil.getCurrentDateTime(); LocalDate currentPeriod = DateTimeUtil.getCurrentDate(); int numberOfPtus = PtuUtil.getNumberOfPtusPerDay(currentPeriod, ptuDuration); int currentPtu = PtuUtil.getPtuIndex(currentDateTime, ptuDuration); // No further checking if the flex order is entirely in the future if (currentPeriod.isBefore(order.getPeriod())) { return; } // Do not accept the flex order if it is entirely in the past if (currentPeriod.isAfter(order.getPeriod())) { LOGGER.warn("Flex offer not acceptable, period is in the past. "); throw new BusinessValidationException(AgrBusinessError.FLEX_ORDER_PERIOD_IN_THE_PAST, order); } // Only accept flex order that have at least one future PTU with a power value <> 0 List<PTU> orderPTUs = order.getPTU(); orderPTUs = PtuListConverter.normalize(orderPTUs); boolean valid = false; for (int i = currentPtu - 1; i < numberOfPtus && !valid; i++) { if (orderPTUs.get(i).getPower().compareTo(BigInteger.ZERO) != 0) { valid = true; } } if (!valid) { LOGGER.warn("Flex order not acceptable, no future PTU's with non-zero power values. "); throw new BusinessValidationException(AgrBusinessError.FLEX_ORDER_WITHOUT_NON_ZERO_FUTURE_POWER, order); } }
From source file:energy.usef.agr.workflow.step.AgrNonUdiReOptimizePortfolioStub.java
License:Apache License
@SuppressWarnings("unchecked") private boolean validateInput(WorkflowContext context) { boolean validInput = true; LocalDate ptuDate = context.get(IN.PTU_DATE.name(), LocalDate.class); List<ConnectionPortfolioDto> connectionPortfolio = context.get(IN.CONNECTION_PORTFOLIO_IN.name(), List.class); List<FlexOrderDto> flexOrders = context.get(IN.RECEIVED_FLEXORDER_LIST.name(), List.class); List<PrognosisDto> dPrognosis = context.get(IN.LATEST_D_PROGNOSIS_DTO_LIST.name(), List.class); List<PrognosisDto> aPlans = context.get(IN.LATEST_A_PLAN_DTO_LIST.name(), List.class); if (connectionPortfolio.isEmpty()) { validInput = false;/*from ww w .j a va 2 s . c om*/ LOGGER.info("No connections in portfolio, unable to re-optimize portfolio."); } LocalDate currentDate = DateTimeUtil.getCurrentDate(); if (ptuDate.isBefore(currentDate)) { validInput = false; LOGGER.error("Unable to re-optimize portfolio for periods in the past: {}", ptuDate); } if (dPrognosis.isEmpty() && aPlans.isEmpty()) { validInput = false; LOGGER.error("D-Prognosis and/or A-Plans expected, but none were found in the input."); } return validInput; }
From source file:energy.usef.agr.workflow.step.AgrReOptimizePortfolioStub.java
License:Apache License
@SuppressWarnings("unchecked") private boolean validateInput(WorkflowContext context) { boolean validInput = true; LocalDate ptuDate = context.get(ReOptimizePortfolioStepParameter.IN.PTU_DATE.name(), LocalDate.class); List<ConnectionPortfolioDto> connectionPortfolio = context .get(ReOptimizePortfolioStepParameter.IN.CONNECTION_PORTFOLIO_IN.name(), List.class); List<FlexOrderDto> flexOrders = context .get(ReOptimizePortfolioStepParameter.IN.RECEIVED_FLEXORDER_LIST.name(), List.class); List<PrognosisDto> dPrognosis = context .get(ReOptimizePortfolioStepParameter.IN.LATEST_D_PROGNOSIS_DTO_LIST.name(), List.class); List<PrognosisDto> aPlans = context.get(ReOptimizePortfolioStepParameter.IN.LATEST_A_PLAN_DTO_LIST.name(), List.class); if (connectionPortfolio.isEmpty()) { validInput = false;/* w w w . j a va2s . co m*/ LOGGER.info("No connections in portfolio, unable to re-optimize portfolio."); } LocalDate currentDate = DateTimeUtil.getCurrentDate(); if (ptuDate.isBefore(currentDate)) { validInput = false; LOGGER.error("Unable to re-optimize portfolio for periods in the past: {}", ptuDate); } if ((dPrognosis == null || dPrognosis.isEmpty()) && (aPlans == null || aPlans.isEmpty())) { validInput = false; LOGGER.error("D-Prognosis and/or A-Plans expected, but non were found in the input."); } return validInput; }
From source file:energy.usef.brp.service.business.BrpPlanboardValidatorService.java
License:Apache License
/** * Validate period of message.//from ww w . ja va 2 s .c o m * * @param periodDate * @throws BusinessValidationException */ public void validatePeriod(LocalDate periodDate) throws BusinessValidationException { if (periodDate == null || periodDate.isBefore(DateTimeUtil.getCurrentDate())) { throw new BusinessValidationException(BrpBusinessError.INVALID_PERIOD); } }
From source file:energy.usef.dso.service.business.DsoPlanboardValidatorService.java
License:Apache License
/** * Validate period of message.//from ww w . j av a2s .c o m * * @param periodDate * @throws BusinessValidationException */ public void validatePeriod(LocalDate periodDate) throws BusinessValidationException { if (periodDate == null || periodDate.isBefore(DateTimeUtil.getCurrentDate())) { throw new BusinessValidationException(DsoBusinessError.INVALID_PERIOD); } }
From source file:eu.ggnet.dwoss.uniqueunit.op.UniqueUnitReporterOperation.java
License:Open Source License
@Override public FileJacket quality(Date start, Date end, TradeName contractor) { SubMonitor m = monitorFactory.newSubMonitor("Gertequalittsreport", 10); m.start();/*from w ww . j a v a 2 s . c o m*/ m.message("Loading reciepted Units"); LocalDate current = new LocalDate(start.getTime()); LocalDate endDate = new LocalDate(end.getTime()); List<UniqueUnit> units = new UniqueUnitEao(em).findBetweenInputDatesAndContractor(start, end, contractor); m.worked(5, "Sorting Data"); Set<String> months = new HashSet<>(); //prepare set of months while (current.isBefore(endDate)) { months.add(current.toString(MONTH_PATTERN)); current = current.plusDays(1); } //prepare Map sorted by months that contains a map sorted by condition SortedMap<String, UnitQualityContainer> unitMap = new TreeMap<>(); for (String month : months) { unitMap.put(month, new UnitQualityContainer()); } m.worked(1); //count monthly receipted units sorted by condition for (UniqueUnit uniqueUnit : units) { current = new LocalDate(uniqueUnit.getInputDate().getTime()); switch (uniqueUnit.getCondition()) { case AS_NEW: unitMap.get(current.toString(MONTH_PATTERN)).incrementAsNew(); break; case ALMOST_NEW: unitMap.get(current.toString(MONTH_PATTERN)).incrementAlmostNew(); break; case USED: unitMap.get(current.toString(MONTH_PATTERN)).incrementUsed(); break; } } m.worked(2, "Creating Document"); List<Object[]> rows = new ArrayList<>(); for (String month : unitMap.keySet()) { rows.add(new Object[] { month, unitMap.get(month).getAsNew(), unitMap.get(month).getAlmostNew(), unitMap.get(month).getUsed() }); m.worked(5); } STable table = new STable(); table.setTableFormat(new CFormat(BLACK, WHITE, new CBorder(BLACK))); table.setHeadlineFormat( new CFormat(CFormat.FontStyle.BOLD, Color.BLACK, Color.YELLOW, CFormat.HorizontalAlignment.LEFT, CFormat.VerticalAlignment.BOTTOM, CFormat.Representation.DEFAULT)); table.add(new STableColumn("Monat", 15)).add(new STableColumn("neuwertig", 15)) .add(new STableColumn("nahezu neuwerig", 15)).add(new STableColumn("gebraucht", 15)); table.setModel(new STableModelList(rows)); CCalcDocument cdoc = new TempCalcDocument("Qualitaet_"); cdoc.add(new CSheet("Sheet1", table)); File file = LucidCalc.createWriter(LucidCalc.Backend.XLS).write(cdoc); m.finish(); return new FileJacket("Aufnahme_nach_Qualitt_" + contractor + "_" + DateFormats.ISO.format(start) + "_" + DateFormats.ISO.format(end), ".xls", file); }
From source file:info.matchingservice.dom.Actor.Person.java
License:Apache License
@Programmatic public String validateNewDemand(final String needDescription, final LocalDate demandOrSupplyProfileStartDate, final LocalDate demandOrSupplyProfileEndDate, final Actor needOwner) { // if you are not the owner if (!needOwner.getOwnedBy().equals(currentUserName())) { return "NOT_THE_OWNER"; }/* w ww. j a v a2 s . c o m*/ // if you have not Principal Role if (!((Person) needOwner).getIsPrincipal()) { return "ONE_INSTANCE_AT_MOST"; } final LocalDate today = LocalDate.now(); if (demandOrSupplyProfileEndDate != null && demandOrSupplyProfileEndDate.isBefore(today)) { return "ENDDATE_BEFORE_TODAY"; } if (demandOrSupplyProfileEndDate != null && demandOrSupplyProfileStartDate != null && demandOrSupplyProfileEndDate.isBefore(demandOrSupplyProfileStartDate) ) { return "ENDDATE_BEFORE_STARTDATE"; } return null; }
From source file:info.matchingservice.dom.DemandSupply.Demand.java
License:Apache License
public String validateUpdateDemand(final String demandDescription, final String demandSummary, final String demandStory, final Blob demandAttachment, final LocalDate demandOrSupplyProfileStartDate, final LocalDate demandOrSupplyProfileEndDate) { final LocalDate today = LocalDate.now(); if (demandOrSupplyProfileEndDate != null && demandOrSupplyProfileEndDate.isBefore(today)) { return "ENDDATE_BEFORE_TODAY"; }/*from ww w .j a v a 2 s . c o m*/ if (demandOrSupplyProfileEndDate != null && demandOrSupplyProfileStartDate != null && demandOrSupplyProfileEndDate.isBefore(demandOrSupplyProfileStartDate) ) { return "ENDDATE_BEFORE_STARTDATE"; } return null; }
From source file:info.matchingservice.dom.DemandSupply.Supply.java
License:Apache License
public String validateUpdateSupply(final String supplyDescription, final LocalDate demandOrSupplyProfileStartDate, final LocalDate demandOrSupplyProfileEndDate) { final LocalDate today = LocalDate.now(); if (demandOrSupplyProfileEndDate != null && demandOrSupplyProfileEndDate.isBefore(today)) { return "ENDDATE_BEFORE_TODAY"; }/*from w w w . j av a 2s .c o m*/ if (demandOrSupplyProfileEndDate != null && demandOrSupplyProfileStartDate != null && demandOrSupplyProfileEndDate.isBefore(demandOrSupplyProfileStartDate) ) { return "ENDDATE_BEFORE_STARTDATE"; } return null; }
From source file:info.matchingservice.dom.Profile.Profile.java
License:Apache License
public String validateCreateTimePeriodElement(final LocalDate startDate, final LocalDate endDate, final Integer weight) { QueryDefault<ProfileElementTimePeriod> query = QueryDefault.create(ProfileElementTimePeriod.class, "findProfileElementOfType", "profileElementOwner", this, "profileElementType", ProfileElementType.TIME_PERIOD); if (container.firstMatch(query) != null) { return "ONE_INSTANCE_AT_MOST"; }//from w w w . ja v a 2 s .c o m if (this.profileType != ProfileType.PERSON_PROFILE && this.profileType != ProfileType.ORGANISATION_PROFILE) { return "ONLY_ON_PERSON_OR_ORGANISATION_PROFILE"; } if (this.getDemandOrSupply() != DemandOrSupply.DEMAND) { return "ONLY_ON_DEMAND"; } //Date validation final LocalDate today = LocalDate.now(); if (endDate != null && endDate.isBefore(today)) { return "ENDDATE_BEFORE_TODAY"; } if (endDate != null && startDate != null && endDate.isBefore(startDate) ) { return "ENDDATE_BEFORE_STARTDATE"; } return null; }