Example usage for org.joda.time LocalDate plusDays

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

Introduction

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

Prototype

public LocalDate plusDays(int days) 

Source Link

Document

Returns a copy of this date plus the specified number of days.

Usage

From source file:edu.uic.apk.APKBuilder.java

License:Open Source License

protected static LocalDate getSimulationDate() {
    //the current year (in decimals)
    LocalDate now = simulation_start_date;
    double shift = Math.ceil(RepastEssentials.GetTickCount()); //note: the tick starts at -1
    now = now.plusDays((int) shift);
    return now;/*w ww . j av a2s. c o m*/
}

From source file:edu.uic.apk.IDUbuilder1.java

License:Open Source License

public IDU generate_SynthNEP(HashMap<String, Object> generator_params) throws Exception {
    DrugUser modelDU = null;//from   w  ww  . ja va  2s.  co m
    Integer max_trials = 50;
    if (generator_params.containsKey("max_trials")) {
        max_trials = (Integer) generator_params.get("max_trials");
    }
    for (int trial = 0; trial < max_trials; trial++) {
        try {
            modelDU = pg.generate(generator_params);
            assert modelDU != null;
            break;
        } catch (Exception e) {
            System.out.println("x");
            modelDU = null;
        }
    }
    if (modelDU == null) {
        throw new Exception("failed to generate");
    }

    IDU idu = new IDU();
    idu.setAgeStarted(modelDU.getAgeStarted());

    LocalDate b_day = modelDU.getBirthDate();
    LocalDate age_at_survey = modelDU.getSurveyDate();
    LocalDate sim_date = APKBuilder.getSimulationDate();
    b_day = b_day.plusYears(sim_date.getYear() - age_at_survey.getYear());
    b_day = b_day.plusDays(sim_date.getDayOfYear() - age_at_survey.getDayOfYear());
    b_day = b_day.plusDays((int) (0.05 * 365 * (RandomHelper.nextDouble() - 0.5))); //some slight jitter (0.05 of a year)
    idu.setBirthDate(b_day);
    //System.out.println("Age:" + idu.getAge() + "Model age:" + modelDU.getAge());

    idu.setDatabaseLabel(modelDU.getDatabaseLabel());
    idu.setEntryDate(LocalDate.now());
    idu.setDrugGivingDegree(modelDU.getDrugGivingDegree());
    idu.setDrugReceptDegree(modelDU.getDrugReceptDegree());
    idu.setFractionReceptSharing(modelDU.getFractionReceptSharing());
    idu.setGender(modelDU.getGender());
    if (modelDU.getHcvState() == HCV_state.ABPOS) {
        double roll = RandomHelper.nextDouble() - ab_prob_chronic;
        if (roll < 0) {
            idu.setHcvInitialState(HCV_state.chronic);
        } else if (roll - ab_prob_acute < 0) {
            idu.setHcvInitialState(HCV_state.infectiousacute);
        } else {
            idu.setHcvInitialState(HCV_state.recovered);
        }
    } else {
        idu.setHcvInitialState(HCV_state.susceptible);
    }
    idu.setInjectionIntensity(modelDU.getInjectionIntensity());
    if (idu.getName() == null) {
        if (idu.getGender() == Gender.Male) {
            idu.setName(IDU.male_names[RandomHelper.nextIntFromTo(0, IDU.male_names.length - 1)]);
        } else {
            idu.setName(IDU.female_names[RandomHelper.nextIntFromTo(0, IDU.female_names.length - 1)]);
        }
    }
    idu.setPreliminaryZip(modelDU.getPreliminaryZip());
    idu.setRace(modelDU.getRace());
    idu.setSyringe_source(modelDU.getSyringe_source());
    return idu;
}

From source file:edu.wayne.cs.fms.controller.CRUD.java

public static DBCursor Search(SearchInfo sInfo, String colName, MongoClient mongoClient) {

    BasicDBObject query = new BasicDBObject();

    //Time Range/*from  w ww  .j  av  a 2  s.c  o m*/
    if (sInfo.getUpDate() != null && sInfo.getDownDate() != null) {
        String upDateStr = sInfo.getUpDate().toString();
        String downDateStr = sInfo.getDownDate().toString();
        DateTimeFormatter df = DateTimeFormat.forPattern("yyyy-MM-dd");
        LocalDate upDate = df.parseLocalDate(upDateStr);
        LocalDate downDate = df.parseLocalDate(downDateStr);
        ArrayList dates = new ArrayList();
        for (LocalDate date = downDate; date.isBefore(upDate.plusDays(1)); date = date.plusDays(1)) {
            dates.add(date.toString());
        }
        query.append("FL_DATE", new BasicDBObject("$in", dates));
    }
    //Carrier
    if (sInfo.getCarrier() != null) {
        query.append("UNIQUE_CARRIER", sInfo.getCarrier());
    }
    //TailNum
    if (sInfo.getTailNum() != 0) {
        query.append("FL_NUM", sInfo.getTailNum());
    }
    //DepCity
    if (sInfo.getDepCity() != null) {
        query.append("ORIGIN_CITY_NAME", sInfo.getDepCity());
    }
    //ArrCity
    if (sInfo.getArrCity() != null) {
        query.append("DEST_CITY_NAME", sInfo.getArrCity());
    }
    //DistanceRange
    query.append("DISTANCE", new BasicDBObject("$gt", sInfo.getDownDis()).append("$lt", sInfo.getUpDis()));
    //DepTimeRange
    query.append("CRS_DEP_TIME",
            new BasicDBObject("$gt", sInfo.getDownDepTime()).append("$lt", sInfo.getUpDepTime()));
    //ArrTimeRange
    query.append("CRS_ARR_TIME",
            new BasicDBObject("$gt", sInfo.getDownArrTime()).append("$lt", sInfo.getUpArrTime()));
    //Cancel
    if (sInfo.getCancel() != -1) {
        query.append("CANCELLED", sInfo.getCancel());
    }

    System.out.println(query);
    //MongoClient mongoClient = Connector.connect("localhost", 27017);
    DB db = mongoClient.getDB("project");
    DBCollection flight = db.getCollection(colName);
    DBCursor cursor = flight.find(query);
    return cursor;
}

From source file:edu.wisc.hr.demo.support.PayPeriodGenerator.java

License:Apache License

/**
 * Returns a List of pay periods, where pay periods are Strings of the form
 * "Date - Date", as in "2013-08-02 - 2013-08-16".
 * @param howMany a positive integer or zero
 * @return a List of howMany Strings representing pay periods
 * @throws IllegalArgumentException if howMany < 0
 *//*from  w ww  .  ja  v  a  2 s  . c om*/
public List<String> payPeriods(int howMany) {

    if (howMany < 0) {
        throw new IllegalArgumentException("Cannot generate negative number of pay periods.");
    }

    // if this method were expensive or frequently called we could cache results since it's the same
    // result for each call for a given howMany.  Indeed, could further optimize since howMany( N + 1) is
    // howMany( N) with an additional pay period prepended.
    //
    // compute cycles are cheap and premature optimization is

    List<String> payPeriods = new LinkedList<String>();

    int daysAgoToStart = ((PERIOD_DURATION_IN_DAYS + 2) * howMany);

    LocalDate startNextPayPeriod = new LocalDate().minusDays(daysAgoToStart);

    // TODO: calculate the exact number of days to add once and skip the loop
    while (startNextPayPeriod.getDayOfWeek() != PERIOD_START_DAY) {
        startNextPayPeriod = startNextPayPeriod.plusDays(1);
    }

    // startNextPayPeriod is now a PERIOD_START_DAY (e.g., Sunday) sufficiently long ago that
    // we can generate howMany periods from there and not quite hit today

    for (int i = 0; i < howMany; i++) {
        LocalDate startThisPayPeriod = startNextPayPeriod;
        LocalDate endThisPayPeriod = startThisPayPeriod.plusDays(PERIOD_DURATION_IN_DAYS - 1);

        // TODO: use a format string for better self-respect
        String payPeriodRepresentation = startThisPayPeriod.toString().concat(" - ")
                .concat(endThisPayPeriod.toString());

        payPeriods.add(payPeriodRepresentation);

        startNextPayPeriod = endThisPayPeriod.plusDays(1);
    }

    return payPeriods;
}

From source file:ee.ut.soras.ajavtV2.mudel.ajavaljend.arvutus.TimeMLDateTimePoint.java

License:Open Source License

public void seekField(Granulaarsus field, int direction, int soughtValue, boolean excludingCurrent) {
    // ---------------------------------
    //  DAY_OF_MONTH
    // ---------------------------------
    if (field == Granulaarsus.DAY_OF_MONTH && direction != 0 && soughtValue == 0) {
        int dir = (direction > 0) ? (1) : (-1);
        LocalDate ajaFookus = new LocalDate(this.underlyingDate);
        LocalDate nihutatudFookus = ajaFookus.plusDays(1 * dir);
        ajaFookus = nihutatudFookus;/*from  ww  w .  ja va2  s .co  m*/
        this.underlyingDate = ajaFookus;
        updateDateRepresentation(Granulaarsus.DAY_OF_MONTH, null, false, ADD_TYPE_OPERATION);
        functionOtherThanSetUsed = true;
        this.dateModified = true;
    }
    // ---------------------------------
    //  DAY_OF_WEEK
    // ---------------------------------
    if (field == Granulaarsus.DAY_OF_WEEK && soughtValue >= DateTimeConstants.MONDAY
            && soughtValue <= DateTimeConstants.SUNDAY && direction != 0) {
        int dir = (direction > 0) ? (1) : (-1);
        LocalDate ajaFookus = new LocalDate(this.underlyingDate);
        // Algne p2ev ehk p2ev, millest tahame tingimata m66duda
        int algneNadalapaev = (excludingCurrent) ? (ajaFookus.getDayOfWeek()) : (-1);
        if (!excludingCurrent) {
            // V6tame sammu tagasi, et esimene nihe tooks meid t2pselt k2esolevale p2evale            
            ajaFookus = ajaFookus.plusDays(dir * (-1));
        }
        int count = 0;
        while (true) {
            LocalDate nihutatudFookus = ajaFookus.plusDays(1 * dir);
            ajaFookus = nihutatudFookus;
            int uusNadalapaev = ajaFookus.getDayOfWeek();
            if (algneNadalapaev != -1) {
                if (algneNadalapaev == uusNadalapaev) {
                    continue;
                } else {
                    algneNadalapaev = -1;
                }
            }
            if (uusNadalapaev == soughtValue) {
                algneNadalapaev = uusNadalapaev;
                count++;
                if (count == Math.abs(direction)) {
                    break;
                }
            }
        }
        this.underlyingDate = ajaFookus;
        updateDateRepresentation(Granulaarsus.DAY_OF_MONTH, null, false, ADD_TYPE_OPERATION);
        functionOtherThanSetUsed = true;
        this.dateModified = true;
    }
    // ---------------------------------
    //  WEEK OF YEAR
    // ---------------------------------
    if (field == Granulaarsus.WEEK_OF_YEAR && soughtValue == 0 && direction != 0) {
        int dir = (direction > 0) ? (1) : (-1);
        LocalDate ajaFookus = new LocalDate(this.underlyingDate);
        // Algne n2dal ehk n2dal, millest tahame m88duda
        int algneNadal = (excludingCurrent) ? (ajaFookus.getWeekOfWeekyear()) : (-1);
        if (!excludingCurrent) {
            // V6tame sammu tagasi, et esimene nihe tooks meid t2pselt k2esolevale p2evale            
            ajaFookus = ajaFookus.plusDays(dir * (-1));
        }
        int count = 0;
        while (true) {
            LocalDate nihutatudFookus = ajaFookus.plusDays(1 * dir);
            ajaFookus = nihutatudFookus;
            int uusNadal = nihutatudFookus.getWeekOfWeekyear();
            if (algneNadal != -1) {
                if (algneNadal == uusNadal) {
                    continue;
                } else {
                    algneNadal = -1;
                }
            }
            if (soughtValue == 0) {
                algneNadal = uusNadal;
                count++;
                if (count == Math.abs(direction)) {
                    break;
                }
            }
        }
        this.underlyingDate = ajaFookus;
        updateDateRepresentation(Granulaarsus.WEEK_OF_YEAR, null, false, ADD_TYPE_OPERATION);
        functionOtherThanSetUsed = true;
        this.dateModified = true;
    }
    // ---------------------------------
    //  MONTH
    // ---------------------------------
    if (field == Granulaarsus.MONTH
            && (soughtValue == 0
                    || DateTimeConstants.JANUARY <= soughtValue && soughtValue <= DateTimeConstants.DECEMBER)
            && direction != 0) {
        int dir = (direction > 0) ? (1) : (-1);
        LocalDate ajaFookus = new LocalDate(this.underlyingDate);
        // Algne kuu ehk kuu, millest tahame m88duda
        int algneKuu = (excludingCurrent) ? (ajaFookus.getMonthOfYear()) : (-1);
        if (!excludingCurrent) {
            // V6tame sammu tagasi, et esimene nihe tooks meid t2pselt k2esolevale kuule      
            ajaFookus = ajaFookus.plusMonths(dir * (-1));
        }
        int count = 0;
        while (true) {
            LocalDate nihutatudFookus = ajaFookus.plusMonths(1 * dir);
            ajaFookus = nihutatudFookus;
            int uusKuu = nihutatudFookus.getMonthOfYear();
            if (algneKuu != -1) {
                if (algneKuu == uusKuu) {
                    continue;
                } else {
                    algneKuu = -1;
                }
            }
            if (soughtValue == 0 || (soughtValue != 0 && uusKuu == soughtValue)) {
                algneKuu = uusKuu;
                count++;
                if (count == Math.abs(direction)) {
                    break;
                }
            }
        }
        this.underlyingDate = ajaFookus;
        updateDateRepresentation(Granulaarsus.MONTH, null, false, ADD_TYPE_OPERATION);
        functionOtherThanSetUsed = true;
        this.dateModified = true;
    }
    // ---------------------------------
    //   YEAR
    // ---------------------------------
    if (field == Granulaarsus.YEAR && soughtValue == 0 && direction != 0) {
        int dir = (direction > 0) ? (1) : (-1);
        LocalDate ajaFookus = new LocalDate(this.underlyingDate);
        // Algne aasta ehk aasta, millest tahame m88duda
        int algneAasta = (excludingCurrent) ? (ajaFookus.getYear()) : (-1);
        if (!excludingCurrent) {
            // V6tame sammu tagasi, et esimene nihe tooks meid t2pselt k2esolevale kuule      
            ajaFookus = ajaFookus.plusMonths(dir * (-1));
        }
        int count = 0;
        while (true) {
            LocalDate nihutatudFookus = ajaFookus.plusMonths(1 * dir);
            ajaFookus = nihutatudFookus;
            int uusAasta = nihutatudFookus.getYear();
            if (algneAasta != -1) {
                if (algneAasta == uusAasta) {
                    continue;
                } else {
                    algneAasta = -1;
                }
            }
            if (soughtValue == 0) {
                algneAasta = uusAasta;
                count++;
                if (count == Math.abs(direction)) {
                    break;
                }
            }
        }
        this.underlyingDate = ajaFookus;
        updateDateRepresentation(Granulaarsus.YEAR, null, false, ADD_TYPE_OPERATION);
        functionOtherThanSetUsed = true;
        this.dateModified = true;
    }
    // ---------------------------------
    //   YEAR_OF_CENTURY
    // ---------------------------------
    if (field == Granulaarsus.YEAR_OF_CENTURY && direction != 0) {
        int minValue = SemLeidmiseAbimeetodid.getLocalDateTimeFieldExtremum(this.underlyingDate,
                DateTimeFieldType.yearOfCentury(), false);
        int maxValue = SemLeidmiseAbimeetodid.getLocalDateTimeFieldExtremum(this.underlyingDate,
                DateTimeFieldType.yearOfCentury(), true);
        if (minValue <= soughtValue && soughtValue <= maxValue) {
            int dir = (direction > 0) ? (1) : (-1);
            LocalDate ajaFookus = new LocalDate(this.underlyingDate);
            // Algne aasta ehk aasta, millest tahame m88duda
            int algneAasta = (excludingCurrent) ? (ajaFookus.getYearOfCentury()) : (-1);
            if (!excludingCurrent) {
                // V6tame sammu tagasi, et esimene nihe tooks meid t2pselt k2esolevale aastale      
                ajaFookus = ajaFookus.plusYears(dir * (-1));
            }
            int count = 0;
            int cycleCount = 0;
            while (true) {
                LocalDate nihutatudFookus = ajaFookus.plusYears(1 * dir);
                cycleCount++;
                ajaFookus = nihutatudFookus;
                int uusAasta = nihutatudFookus.getYearOfCentury();
                if (algneAasta != -1) {
                    if (algneAasta == uusAasta) {
                        continue;
                    } else {
                        algneAasta = -1;
                    }
                }
                if (uusAasta == soughtValue) {
                    algneAasta = uusAasta;
                    count++;
                    if (count == Math.abs(direction)) {
                        break;
                    }
                }
            }
            this.underlyingDate = ajaFookus;
            updateDateRepresentation(Granulaarsus.YEAR, null, false, ADD_TYPE_OPERATION);
            functionOtherThanSetUsed = true;
            this.dateModified = true;
        }
    }
    // ---------------------------------
    //   CENTURY_OF_ERA
    // ---------------------------------
    if (field == Granulaarsus.CENTURY_OF_ERA && soughtValue == 0 && direction != 0) {
        int dir = (direction > 0) ? (1) : (-1);
        LocalDate ajaFookus = new LocalDate(this.underlyingDate);
        // Algne saj ehk sajand, millest tahame m88duda
        int algneSajand = (excludingCurrent) ? (ajaFookus.getCenturyOfEra()) : (Integer.MIN_VALUE);
        if (!excludingCurrent) {
            // V6tame sammu tagasi, et esimene nihe tooks meid t2pselt k2esolevale aastale      
            ajaFookus = ajaFookus.plusYears(dir * (-10));
        }
        int count = 0;
        while (true) {
            LocalDate nihutatudFookus = ajaFookus.plusYears(10 * dir);
            ajaFookus = nihutatudFookus;
            int uusSajand = nihutatudFookus.getCenturyOfEra();
            if (algneSajand != Integer.MIN_VALUE) {
                if (algneSajand == uusSajand) {
                    continue;
                } else {
                    algneSajand = Integer.MIN_VALUE;
                }
            }
            if (soughtValue == 0) {
                algneSajand = uusSajand;
                count++;
                if (count == Math.abs(direction)) {
                    break;
                }
            }
        }
        this.underlyingDate = ajaFookus;
        updateDateRepresentation(Granulaarsus.CENTURY_OF_ERA, null, false, ADD_TYPE_OPERATION);
        functionOtherThanSetUsed = true;
        this.dateModified = true;
    }

}

From source file:energy.usef.agr.service.business.AgrPortfolioBusinessService.java

License:Apache License

/**
 * Create Missing Udis.//  w  ww  .j a  va2  s . c o  m
 *
 * @param period the period for creating udis.
 * @param connectionPortfolioDTOs the connection portfolio
 */
public void createUdis(final LocalDate period, List<ConnectionPortfolioDto> connectionPortfolioDTOs) {
    Map<String, Connection> connectionMap = corePlanboardBusinessService
            .findActiveConnections(period, Optional.empty()).stream()
            .collect(Collectors.toMap(Connection::getEntityAddress, Function.identity()));
    List<Object> toBePersisted = new ArrayList<>();
    Map<String, Udi> activeUdis = udiRepository.findActiveUdisMappedPerEndpoint(DateTimeUtil.getCurrentDate());
    Integer initializationDuration = configAgr
            .getIntegerProperty(ConfigAgrParam.AGR_INITIALIZE_PLANBOARD_DAYS_INTERVAL);
    LocalDate validUntil = period.plusDays(initializationDuration);

    for (ConnectionPortfolioDto connectionPortfolioDTO : connectionPortfolioDTOs) {
        Connection connection = connectionMap.get(connectionPortfolioDTO.getConnectionEntityAddress());
        for (UdiPortfolioDto udiPortfolioDto : connectionPortfolioDTO.getUdis()) {
            if (activeUdis.containsKey(udiPortfolioDto.getEndpoint())) {
                activeUdis.get(udiPortfolioDto.getEndpoint()).setValidUntil(validUntil);
                continue;
            }
            toBePersisted.add(createUdi(udiPortfolioDto, connection, period, validUntil));
        }
    }
    udiRepository.persistBatch(toBePersisted);
}

From source file:energy.usef.agr.workflow.plan.connection.forecast.AgrCommonReferenceQueryCoordinator.java

License:Apache License

/**
 * Initialize the PTU containers and PTU Reoptimization.
 *///from w  ww  .  j av  a 2s.  c om
private void initializePtuContainers() {
    Integer initializationDelay = 1;
    Integer initializationDuration = configAgr
            .getIntegerProperty(ConfigAgrParam.AGR_INITIALIZE_PLANBOARD_DAYS_INTERVAL);
    LocalDate initializationDate = DateTimeUtil.getCurrentDate().plusDays(initializationDelay);
    for (int i = 0; i < initializationDuration; ++i) {
        corePlanboardBusinessService.findOrCreatePtuContainersForPeriod(initializationDate.plusDays(i));
    }
}

From source file:energy.usef.agr.workflow.plan.connection.profile.AgrCreateConnectionProfileCoordinator.java

License:Apache License

/**
 * Create the connection profile power values for the connection portfolio for the period starting the next day and ending
 * {@link ConfigAgrParam#AGR_INITIALIZE_PLANBOARD_DAYS_INTERVAL} later.
 *
 * @param createConnectionProfileEvent {@link CreateConnectionProfileEvent} event triggering the workflow.
 *///from  w ww. ja  va 2s .  co m
@Asynchronous
@Lock(LockType.WRITE)
@SuppressWarnings("unchecked")
public void createConnectionProfile(
        @Observes(during = TransactionPhase.AFTER_COMPLETION) CreateConnectionProfileEvent createConnectionProfileEvent)
        throws BusinessValidationException {
    LOGGER.info(USEFConstants.LOG_COORDINATOR_START_HANDLING_EVENT, createConnectionProfileEvent);
    eventValidationService.validateEventPeriodInFuture(createConnectionProfileEvent);

    LocalDate initializationDate = createConnectionProfileEvent.getPeriod();
    Integer ptuDuration = config.getIntegerProperty(ConfigParam.PTU_DURATION);
    Integer initializeDaysInterval = configAgr
            .getIntegerProperty(ConfigAgrParam.AGR_INITIALIZE_PLANBOARD_DAYS_INTERVAL);
    for (int i = 0; i < initializeDaysInterval; ++i) {
        LocalDate period = initializationDate.plusDays(i);

        List<ConnectionPortfolioDto> connectionPortfolioDto = agrPortfolioBusinessService
                .findConnectionPortfolioDto(period);

        if (connectionPortfolioDto.isEmpty()) {
            LOGGER.debug(
                    "No connections in the portfolio for period [{}]. Workflow will proceed for next periods.",
                    period);
            continue;
        }

        Map<String, List<ElementDto>> elementsPerConnection = agrElementBusinessService.findElementDtos(period)
                .stream().collect(Collectors.groupingBy(ElementDto::getConnectionEntityAddress));

        List<ConnectionPortfolioDto> connectionPortfolioDTOs = invokeCreateConnectionProfilePbc(ptuDuration,
                period, connectionPortfolioDto, elementsPerConnection);

        agrPortfolioBusinessService.createConnectionProfiles(period, connectionPortfolioDTOs);
    }

    if (!configAgr.getBooleanProperty(ConfigAgrParam.AGR_IS_NON_UDI_AGGREGATOR)) {
        createUdiEventManager.fire(new CreateUdiEvent(createConnectionProfileEvent.getPeriod()));
    }
    LOGGER.info(USEFConstants.LOG_COORDINATOR_FINISHED_HANDLING_EVENT, createConnectionProfileEvent);
}

From source file:energy.usef.agr.workflow.plan.connection.profile.AgrCreateUdiCoordinator.java

License:Apache License

/**
 * Create the Udi's for the active connection Profile.
 *
 * @param createUdiEvent {@link CreateUdiEvent} event triggering the workflow.
 *//*from   www. j av a2s  .  c  om*/
@Asynchronous
@Lock(LockType.WRITE)
@SuppressWarnings("unchecked")
public void createUdis(@Observes(during = TransactionPhase.AFTER_COMPLETION) CreateUdiEvent createUdiEvent)
        throws BusinessValidationException {
    LOGGER.info(USEFConstants.LOG_COORDINATOR_START_HANDLING_EVENT, createUdiEvent);
    eventValidationService.validateEventPeriodInFuture(createUdiEvent);

    LocalDate initializationDate = createUdiEvent.getPeriod();
    Integer ptuDuration = config.getIntegerProperty(ConfigParam.PTU_DURATION);
    Integer initializeDaysInterval = configAgr
            .getIntegerProperty(ConfigAgrParam.AGR_INITIALIZE_PLANBOARD_DAYS_INTERVAL);
    for (int i = 0; i < initializeDaysInterval; ++i) {
        LocalDate period = initializationDate.plusDays(i);

        List<ConnectionPortfolioDto> connectionPortfolioDto = agrPortfolioBusinessService
                .findConnectionPortfolioDto(period);

        if (connectionPortfolioDto.isEmpty()) {
            LOGGER.debug(
                    "No connections in the portfolio for period [{}]. Workflow will proceed for next periods.",
                    period);
            continue;
        }

        Map<String, List<ElementDto>> elementsPerConnection = agrElementBusinessService.findElementDtos(period)
                .stream().collect(Collectors.groupingBy(ElementDto::getConnectionEntityAddress));

        WorkflowContext resultContext = invokeCreateUdiPbc(ptuDuration, period, connectionPortfolioDto,
                elementsPerConnection);

        List<ConnectionPortfolioDto> connectionPortfolioDTOList = (List<ConnectionPortfolioDto>) resultContext
                .getValue(OUT.CONNECTION_PORTFOLIO_DTO_LIST.name());
        Map<String, List<UdiEventDto>> udiEvents = (Map<String, List<UdiEventDto>>) resultContext
                .getValue(OUT.UDI_EVENTS_PER_UDI_MAP.name());

        agrPortfolioBusinessService.createUdis(period, connectionPortfolioDTOList);

        List<UdiEventDto> udiEventDtos = udiEvents.values().stream().flatMap(Collection::stream)
                .collect(Collectors.toList());
        agrDeviceCapabilityBusinessService.updateUdiEvents(period, udiEventDtos);
    }
    LOGGER.info(USEFConstants.LOG_COORDINATOR_FINISHED_HANDLING_EVENT, createUdiEvent);
}

From source file:energy.usef.brp.workflow.plan.connection.forecast.BrpCommonReferenceQueryCoordinator.java

License:Apache License

/**
 * Initialize the PTU containers./*from ww  w  . ja  v a2 s.c o m*/
 */
private void initializePtuContainers() {
    // initialize the PTU containers
    Integer initializationDelay = 1;
    Integer initializationDuration = configBrp
            .getIntegerProperty(ConfigBrpParam.BRP_INITIALIZE_PLANBOARD_DAYS_INTERVAL);
    LocalDate initializationDate = DateTimeUtil.getCurrentDate().plusDays(initializationDelay);
    for (int i = 0; i < initializationDuration; ++i) {
        corePlanboardBusinessService.findOrCreatePtuContainersForPeriod(initializationDate.plusDays(i));
    }
}