Example usage for org.joda.time LocalDateTime toLocalDate

List of usage examples for org.joda.time LocalDateTime toLocalDate

Introduction

In this page you can find the example usage for org.joda.time LocalDateTime toLocalDate.

Prototype

public LocalDate toLocalDate() 

Source Link

Document

Converts this object to a LocalDate with the same date and chronology.

Usage

From source file:energy.usef.dso.workflow.operate.DsoOperateCoordinator.java

License:Apache License

private PtuContainer fetchPreviousPtuContainer(LocalDateTime ptuDate, Integer ptuIndex) {
    PtuContainer previousPtuContainer;// w  w  w  . j  av  a2 s . c  om
    int previousPtuIndex = ptuIndex - 1;
    if (previousPtuIndex < 1) {
        int amountOfPtus = MINUTES_PER_DAY / config.getIntegerProperty(ConfigParam.PTU_DURATION);
        previousPtuContainer = dsoPlanboardBusinessService.findPtuContainer(ptuDate.minusDays(1).toLocalDate(),
                previousPtuIndex + amountOfPtus);
    } else {
        previousPtuContainer = dsoPlanboardBusinessService.findPtuContainer(ptuDate.toLocalDate(),
                previousPtuIndex);
    }
    return previousPtuContainer;
}

From source file:energy.usef.dso.workflow.operate.DsoOperateCoordinator.java

License:Apache License

private long handleCongestion(
        Map<String, Map<LocalDate, List<PlanboardMessage>>> offersPerCongestionPointPerDateMap,
        Map<String, Map<LocalDate, GridSafetyAnalysisDto>> gridSafetyAnalysisPerCongestionPointPerDateMap,
        CongestionPointConnectionGroup congestionPoint) {

    LocalDateTime ptuDate = DateTimeUtil.getCurrentDateTime();
    int ptuIndex = PtuUtil.getPtuIndex(ptuDate, config.getIntegerProperty(ConfigParam.PTU_DURATION));

    String usefIdentifier = congestionPoint.getUsefIdentifier();

    Map<LocalDate, List<PlanboardMessage>> flexOffersPerDate = offersPerCongestionPointPerDateMap
            .get(usefIdentifier);//  w w w.j av  a2 s  . c  om
    List<PlanboardMessage> flexOfferMessages = flexOffersPerDate != null
            ? flexOffersPerDate.get(ptuDate.toLocalDate())
            : null;

    Map<LocalDate, GridSafetyAnalysisDto> gridSafetyAnalysisForCongestionPoint = gridSafetyAnalysisPerCongestionPointPerDateMap
            .get(usefIdentifier);
    GridSafetyAnalysisDto gridSafetyAnalysisDto = gridSafetyAnalysisForCongestionPoint != null
            ? gridSafetyAnalysisForCongestionPoint.get(ptuDate.toLocalDate())
            : null;

    long orderedPower = 0L;
    if (flexOfferMessages != null && gridSafetyAnalysisDto != null) {
        List<FlexOfferDto> offerDtos = createFlexOffersDtoWithPtus(flexOfferMessages);

        List<FlexOfferDto> acceptedFlexOffers = invokePlaceOperateFlexOrdersPbc(gridSafetyAnalysisDto,
                offerDtos);

        storeAndSendFlexOrders(offersPerCongestionPointPerDateMap, acceptedFlexOffers);

        orderedPower = sumAcceptedOrderedPower(ptuIndex, offerDtos, acceptedFlexOffers);
    } else {
        LOGGER.debug("No flex offer and/or grid safety analysis for congestion point {} and date {}",
                congestionPoint.getUsefIdentifier(), ptuDate);
    }

    return orderedPower;
}

From source file:fi.riista.integration.lupahallinta.HarvestReportExportCSVDTO.java

public static HarvestReportExportCSVDTO create(final Harvest harvest, final MessageSource messageSource) {
    HarvestReportExportCSVDTO dto = new HarvestReportExportCSVDTO();

    dto.submissionRowCount = 1;/*from w w  w.ja  va  2 s.c o m*/
    dto.reportingTime = DateUtil.toLocalDateTimeNullSafe(harvest.getCreationTime());

    final Person hunter = harvest.getActualShooter();
    if (hunter != null) {
        dto.hunterName = hunter.getByName() + " " + hunter.getLastName();
        dto.hunterFirstName = hunter.getByName();
        dto.hunterLastName = hunter.getLastName();

        Address address = hunter.getAddress();
        if (address != null) {
            dto.hunterAddress = address.getStreetAddress();
            dto.hunterPostalCode = address.getPostalCode();
            dto.hunterPostalResidence = address.getCity();
        }

        dto.hunterPhone = hunter.getPhoneNumber();
        dto.hunterEmail = hunter.getEmail();
        dto.hunterHuntingCard = hunter.getHunterNumber();
    }

    dto.huntingLicenseNumber = getPermitNumberOrNull(harvest);
    dto.huntingLicenseAsList = getPermitReportsAsList(harvest.getHarvestPermit());

    readSubmitter(harvest.getHarvestReportAuthor(), dto);

    if (harvest.getRhy() != null) {
        harvest.getRhy().getClosestAncestorOfType(OrganisationType.RKA).ifPresent(rka -> {
            dto.rkkAreaId = rka.getOfficialCode();
            dto.rkkAreaName = rka.getNameFinnish();
        });
        dto.rhyAreaId = harvest.getRhy().getOfficialCode();
        dto.rhyAreaName = harvest.getRhy().getNameFinnish();
    }

    dto.coordinatesCollectionMethod = harvest.getGeoLocation().getSource();
    dto.coordinatesLatitude = harvest.getGeoLocation().getLatitude();
    dto.coordinatesLongitude = harvest.getGeoLocation().getLongitude();
    dto.coordinatesAccuracy = harvest.getGeoLocation().getAccuracy() != null
            ? harvest.getGeoLocation().getAccuracy()
            : 0;

    dto.huntingArea = harvest.getHuntingAreaType();
    dto.huntingGroup = harvest.getHuntingParty();

    if (harvest.getHuntingAreaSize() != null) {
        dto.area = Math.round(harvest.getHuntingAreaSize());
    }

    PropertyIdentifier propertyIdentifier = harvest.getPropertyIdentifier();
    if (propertyIdentifier != null) {
        dto.municipality = propertyIdentifier.getKuntanumero();
        dto.village = propertyIdentifier.getSijaintialuenumero();
        dto.property = propertyIdentifier.getRyhmanumero();
        dto.registerNumber = propertyIdentifier.getYksikkonumero();
    }

    LocalDateTime huntingTimestamp = DateUtil.toLocalDateTimeNullSafe(harvest.getPointOfTime());
    dto.dateOfCatch = huntingTimestamp.toLocalDate();
    dto.timeOfCatch = huntingTimestamp.toLocalTime();

    dto.animalId = harvest.getSpecies().getOfficialCode();
    dto.animalSpecies = harvest.getSpecies().getNameFinnish();

    if (harvest.getHuntingMethod() == HuntingMethod.SHOT) {
        dto.sealInformation = "Ammuttu";
    } else if (harvest.getHuntingMethod() == HuntingMethod.SHOT_BUT_LOST) {
        dto.sealInformation = "Ammuttu, mutta menetetty";
    } else if (harvest.getHuntingMethod() == HuntingMethod.CAPTURED_ALIVE) {
        dto.sealInformation = "Elvn pyytvll loukulla pyydetty";
    }

    dto.amount = harvest.getAmount();
    dto.genderId = transformSpecimens(harvest, genderIdTransformer());
    dto.genderName = transformSpecimens(harvest, genderNameTransformer(messageSource));
    dto.ageId = transformSpecimens(harvest, ageIdTransformer());
    dto.ageName = transformSpecimens(harvest, ageNameTransformer(messageSource));
    dto.weight = transformSpecimens(harvest, weightTransformer());
    dto.harvestAlsoReportedByPhone = harvest.getReportedWithPhoneCall();

    final Tuple2<String, String> p = createPermittedMethodPair(harvest.getPermittedMethod());
    dto.permittedMethod = p._1();
    dto.permittedMethodDescription = p._2();

    return dto;
}

From source file:net.solarnetwork.node.hw.hc.EM5600Support.java

License:Open Source License

@Override
protected Map<String, Object> readDeviceInfo(ModbusConnection conn) {
    // note the order of these elements determines the output of getDeviceInfoMessage()
    Map<String, Object> result = new LinkedHashMap<String, Object>(8);
    String str;//from w  w  w . ja v  a 2s .  c om
    Integer i;
    i = getMeterModel(conn);
    if (i != null) {
        result.put(INFO_KEY_DEVICE_MODEL, i);
    }
    LocalDateTime dt = getMeterManufactureDate(conn);
    if (dt != null) {
        result.put(INFO_KEY_DEVICE_MANUFACTURE_DATE, dt.toLocalDate());
    }
    str = getMeterSerialNumber(conn);
    if (str != null) {
        result.put(INFO_KEY_DEVICE_SERIAL_NUMBER, str);
    }
    return result;
}

From source file:net.solarnetwork.node.hw.schneider.meter.PM3200Support.java

License:Open Source License

@Override
protected Map<String, Object> readDeviceInfo(ModbusConnection conn) {
    Map<String, Object> result = new LinkedHashMap<String, Object>(8);
    String str = getMeterName(conn);
    if (str != null) {
        result.put(INFO_KEY_DEVICE_NAME, str);
    }/*from  w  w w .j av  a  2 s.  c  om*/
    str = getMeterModel(conn);
    if (str != null) {
        result.put(INFO_KEY_DEVICE_MODEL, str);
    }
    str = getMeterManufacturer(conn);
    if (result != null) {
        result.put(INFO_KEY_DEVICE_MANUFACTURER, str);
    }
    LocalDateTime dt = getMeterManufactureDate(conn);
    if (dt != null) {
        result.put(INFO_KEY_DEVICE_MANUFACTURE_DATE, dt.toLocalDate());
    }
    Long l = getMeterSerialNumber(conn);
    if (l != null) {
        result.put(INFO_KEY_DEVICE_SERIAL_NUMBER, l);
    }
    return result;
}

From source file:org.apache.fineract.infrastructure.scheduledemail.service.EmailCampaignWritePlatformCommandHandlerImpl.java

License:Apache License

private void updateTriggerDates(Long campaignId) {
    final EmailCampaign emailCampaign = this.emailCampaignRepository.findOne(campaignId);
    if (emailCampaign == null) {
        throw new EmailCampaignNotFound(campaignId);
    }//from   w  w  w.  j  av a2  s .c  o m
    LocalDateTime nextTriggerDate = emailCampaign.getNextTriggerDate();
    emailCampaign.setLastTriggerDate(nextTriggerDate.toDate());
    //calculate new trigger date and insert into next trigger date

    /**
     * next run time has to be in the future if not calculate a new future date
     */
    LocalDate nextRuntime = CalendarUtils.getNextRecurringDate(emailCampaign.getRecurrence(),
            emailCampaign.getNextTriggerDate().toLocalDate(), nextTriggerDate.toLocalDate());
    if (nextRuntime.isBefore(DateUtils.getLocalDateOfTenant())) { // means next run time is in the past calculate a new future date
        nextRuntime = CalendarUtils.getNextRecurringDate(emailCampaign.getRecurrence(),
                emailCampaign.getNextTriggerDate().toLocalDate(), DateUtils.getLocalDateOfTenant());
    }
    final LocalDateTime getTime = emailCampaign.getRecurrenceStartDateTime();
    final String dateString = nextRuntime.toString() + " " + getTime.getHourOfDay() + ":"
            + getTime.getMinuteOfHour() + ":" + getTime.getSecondOfMinute();
    final DateTimeFormatter simpleDateFormat = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss");
    final LocalDateTime newTriggerDateWithTime = LocalDateTime.parse(dateString, simpleDateFormat);

    emailCampaign.setNextTriggerDate(newTriggerDateWithTime.toDate());
    this.emailCampaignRepository.saveAndFlush(emailCampaign);
}

From source file:org.apache.fineract.infrastructure.sms.service.SmsCampaignWritePlatformCommandHandlerImpl.java

License:Apache License

private void updateTriggerDates(Long campaignId) {
    final SmsCampaign smsCampaign = this.smsCampaignRepository.findOne(campaignId);
    if (smsCampaign == null) {
        throw new SmsCampaignNotFound(campaignId);
    }/*from ww w.  j av a 2 s. com*/
    LocalDateTime nextTriggerDate = smsCampaign.getNextTriggerDate();
    smsCampaign.setLastTriggerDate(nextTriggerDate.toDate());
    //calculate new trigger date and insert into next trigger date

    /**
     * next run time has to be in the future if not calculate a new future date
     */
    LocalDate nextRuntime = CalendarUtils.getNextRecurringDate(smsCampaign.getRecurrence(),
            smsCampaign.getNextTriggerDate().toLocalDate(), nextTriggerDate.toLocalDate());
    if (nextRuntime.isBefore(DateUtils.getLocalDateOfTenant())) { // means next run time is in the past calculate a new future date
        nextRuntime = CalendarUtils.getNextRecurringDate(smsCampaign.getRecurrence(),
                smsCampaign.getNextTriggerDate().toLocalDate(), DateUtils.getLocalDateOfTenant());
    }
    final LocalDateTime getTime = smsCampaign.getRecurrenceStartDateTime();
    final String dateString = nextRuntime.toString() + " " + getTime.getHourOfDay() + ":"
            + getTime.getMinuteOfHour() + ":" + getTime.getSecondOfMinute();
    final DateTimeFormatter simpleDateFormat = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss");
    final LocalDateTime newTriggerDateWithTime = LocalDateTime.parse(dateString, simpleDateFormat);

    smsCampaign.setNextTriggerDate(newTriggerDateWithTime.toDate());
    this.smsCampaignRepository.saveAndFlush(smsCampaign);
}

From source file:org.apache.fineract.organisation.teller.data.CashierTransactionDataValidator.java

License:Apache License

public void validateOnLoanDisbursal(AppUser user, String currencyCode, BigDecimal transactionAmount) {
    LocalDateTime localDateTime = DateUtils.getLocalDateTimeOfTenant();
    if (user.getStaff() != null) {
        String sql = "select c.id from m_cashiers c where c.staff_id = " + user.getStaff().getId() + " AND "
                + " (case when c.full_day then '" + localDateTime.toLocalDate()
                + "' BETWEEN c.start_date AND c.end_date " + " else ('" + localDateTime.toLocalDate()
                + "' BETWEEN c.start_date AND c.end_date and " + " TIME('" + localDateTime.toDateTime()
                + "') BETWEEN TIME(c.start_time) AND TIME(c.end_time)  ) end)";
        try {//  w  w  w .j a  v  a  2s . c o m
            Long cashierId = this.jdbcTemplate.queryForObject(sql, Long.class);
            validateSettleCashAndCashOutTransactions(cashierId, currencyCode, transactionAmount);
        } catch (EmptyResultDataAccessException e) {

        }
    }

}

From source file:org.devgateway.eudevfin.projects.repository.CustomProjectRepositoryImpl.java

@Override
public List<Project> findAllByReportDate(LocalDateTime date) {
    //        LocalDateTime from = new LocalDateTime(date.getYear(), date.getMonthOfYear(), date.getDayOfMonth(), 0, 0);
    //        LocalDateTime to = new LocalDateTime(date.getYear(), date.getMonthOfYear(), date.getDayOfMonth(), 0, 0);

    String queryBuilder = "FROM Project tx JOIN tx.projectReports pr WHERE 1=1 AND pr.reportDate BETWEEN :begin AND :end AND pr.emailSent=false";
    Query query = em.createQuery("SELECT tx " + queryBuilder);

    if (date != null) {
        query.setParameter("begin", date.toLocalDate().toDateTimeAtStartOfDay().toLocalDateTime());
        query.setParameter("end", date.toLocalDate().plusDays(1).toDateTimeAtStartOfDay().toLocalDateTime());
    }//w  w  w  . j a  va  2 s  .c  o m

    @SuppressWarnings("rawtypes")
    List resultList = query.getResultList();

    return resultList;
}

From source file:org.estatio.dscm.services.SyncService.java

License:Apache License

/**
 * The effective playlist items e.g. the commercials and fillers combined in
 * cycles of 60 seconds. All videos take 10 seconds each for the time being
 * //  w  w  w  .j ava 2  s.co  m
 * @param playlist
 *            The main playlist e.g. commercial
 * @param dateTime
 *            The effective time
 * @return
 */
@Programmatic
public List<PlaylistItem> effectiveItems(Playlist playlist, LocalDateTime dateTime) {

    List<PlaylistItem> fillers = new ArrayList<PlaylistItem>();
    List<PlaylistItem> commercials = new ArrayList<PlaylistItem>();
    commercials.addAll(playlist.getItems());
    Playlist fillerPlaylist = playlists.findByDisplayGroupAndDateTimeAndType(playlist.getDisplayGroup(),
            dateTime.toLocalDate(), dateTime.toLocalTime(), PlaylistType.FILLERS);
    if (fillerPlaylist != null) {
        fillers.addAll(fillerPlaylist.getItems());
    }
    return PlaylistGenerator.generate(commercials, fillers, playlist.getLoopDuration());
}