Example usage for org.joda.time LocalDate toDate

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

Introduction

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

Prototype

@SuppressWarnings("deprecation")
public Date toDate() 

Source Link

Document

Get the date time as a java.util.Date.

Usage

From source file:com.squid.kraken.v4.core.analysis.datamatrix.CompareMerger.java

License:Open Source License

@Override
protected Object translateLeftToRight(Object left) {
    if (left instanceof Date && offset != null) {
        LocalDate delta = (new LocalDate(((Date) left).getTime())).minus(offset);
        return new java.sql.Date(delta.toDate().getTime());
    } else {//from  ww  w. ja va  2s .c om
        return right;
    }
}

From source file:com.studium.joda.converters.JodaLocalDateConverter.java

License:Apache License

public Date convertToDatabaseColumn(LocalDate localDate) {
    return localDate == null ? null : new Date(localDate.toDate().getTime());
}

From source file:com.tomtom.speedtools.mongodb.mappers.LocalDateMapper.java

License:Apache License

@Nullable
@Override// w  ww  .  ja  v  a 2 s.  c  o m
public Date toDb(@Nullable final LocalDate value) {
    if (value == null) {
        return null;
    }
    return value.toDate();
}

From source file:com.tourapp.tour.util.script.importdata.ImportOTACodeTablesProcess.java

License:Open Source License

/**
 * Run Method.//from   w  ww . j  av a  2  s.  co m
 */
public void run() {
    try {
        OTACodeTable recOTACodeTable = (OTACodeTable) this.getMainRecord();
        OTACodes recOTACodes = (OTACodes) this.getRecord(OTACodes.OTA_CODES_FILE);

        String strFilePath = this.getProperty("filepath");
        String NONE = "none";
        String VALUE_PARAM = ".value";

        IBindingFactory jc = BindingDirectory.getFactory(CodeTables.class);
        IUnmarshallingContext unmarshaller = jc.createUnmarshallingContext();
        InputStream inStream = new FileInputStream(strFilePath);
        CodeTables codeTables = (CodeTables) unmarshaller.unmarshalDocument(inStream, Constants.URL_ENCODING);

        if (codeTables.getCodeTableList() != null)
            for (CodeTables.CodeTable table : codeTables.getCodeTableList()) {
                String strName = table.getName();
                String strNameCode = table.getNameCode();
                LocalDate calCreate = table.getCreationDate();
                LocalDate calDeletion = table.getMarkedForDeletionDate();
                CodeTables.CodeTable.Descriptions descriptions = table.getDescriptions();
                Map<String, Object> properties = null;
                if (descriptions != null)
                    for (FreeText desc : descriptions.getDescriptionList()) {
                        String strLanguage = desc.getLanguage();
                        String strValue = desc.getString();
                        if ((strLanguage == null) || (strLanguage.length() == 0))
                            strLanguage = NONE;
                        if (properties == null)
                            properties = new HashMap<String, Object>();
                        properties.put(strLanguage, strValue);
                    }

                recOTACodeTable.addNew();
                recOTACodeTable.getField(OTACodeTable.NAME).setString(strName);
                recOTACodeTable.getField(OTACodeTable.NAME_CODE).setString(strNameCode);
                if (calCreate != null)
                    ((DateField) recOTACodeTable.getField(OTACodeTable.CREATION_DATE))
                            .setDate(calCreate.toDateMidnight().toDate(), true, DBConstants.SCREEN_MOVE);
                if (calDeletion != null)
                    ((DateField) recOTACodeTable.getField(OTACodeTable.DELETION_DATE))
                            .setDate(calDeletion.toDateMidnight().toDate(), true, DBConstants.SCREEN_MOVE);
                ((PropertiesField) recOTACodeTable.getField(OTACodeTable.PROPERTIES)).setProperties(properties);
                recOTACodeTable.add();
                Object bookmark = recOTACodeTable.getLastModified(DBConstants.BOOKMARK_HANDLE);

                if (table.getCodes() != null)
                    if (table.getCodes().getCodeList() != null)
                        for (CodeTables.CodeTable.Codes.Code code : table.getCodes().getCodeList()) {
                            String strValue2 = code.getValue();
                            LocalDate calCreate2 = code.getCreationDate();
                            LocalDate calDeletion2 = code.getMarkedForDeletionDate();
                            java.util.List<CodeContent> contents = code.getCodeContentList();

                            String strNameDefault = null;
                            properties = null;
                            if (contents != null)
                                for (CodeContent contentType : contents) {
                                    String strLanguage = contentType.getLanguage();
                                    String strName3 = contentType.getName();
                                    String strValue3 = contentType.getString();

                                    if (((strLanguage == null) || (strLanguage.length() == 0))
                                            || (strNameDefault == null))
                                        strNameDefault = strName3;
                                    if ((strLanguage == null) || (strLanguage.length() == 0))
                                        strLanguage = NONE;
                                    if (properties == null)
                                        properties = new HashMap<String, Object>();
                                    if ((strName3 != null) && (strName3.length() > 0))
                                        properties.put(strLanguage, strName3);
                                    if ((strValue3 != null) && (strValue3.length() > 0))
                                        properties.put(strLanguage + VALUE_PARAM, strValue3);
                                }

                            recOTACodes.addNew();
                            recOTACodes.getField(OTACodes.OTA_CODE_TABLE_ID).setString(bookmark.toString());
                            recOTACodes.getField(OTACodes.VALUE).setString(strValue2);
                            recOTACodes.getField(OTACodes.NAME).setString(strNameDefault);
                            if (calCreate2 != null)
                                ((DateField) recOTACodes.getField(OTACodes.CREATION_DATE)).setDate(
                                        calCreate2.toDateMidnight().toDate(), true, DBConstants.SCREEN_MOVE);
                            if (calDeletion2 != null)
                                ((DateField) recOTACodes.getField(OTACodes.DELETION_DATE)).setDate(
                                        calDeletion2.toDateMidnight().toDate(), true, DBConstants.SCREEN_MOVE);
                            ((PropertiesField) recOTACodes.getField(OTACodes.PROPERTIES))
                                    .setProperties(properties);
                            recOTACodes.add();

                        }
            }

    } catch (DBException ex) {
        ex.printStackTrace();
    } catch (FileNotFoundException ex) {
        ex.printStackTrace();
    } catch (JiBXException e) {
        e.printStackTrace();
    }
}

From source file:com.tourgeek.tour.util.script.importdata.ImportOTACodeTablesProcess.java

License:Open Source License

/**
 * Run Method.//from   w  w  w  .jav a2 s . c  om
 */
public void run() {
    try {
        OTACodeTable recOTACodeTable = (OTACodeTable) this.getMainRecord();
        OTACodes recOTACodes = (OTACodes) this.getRecord(OTACodes.OTA_CODES_FILE);

        String strFilePath = this.getProperty("filepath");
        String NONE = "none";
        String VALUE_PARAM = ".value";

        IBindingFactory jc = BindingDirectory.getFactory(CodeTables.class);
        IUnmarshallingContext unmarshaller = jc.createUnmarshallingContext();
        InputStream inStream = new FileInputStream(strFilePath);
        CodeTables codeTables = (CodeTables) unmarshaller.unmarshalDocument(inStream, Constants.URL_ENCODING);

        if (codeTables.getCodeTableList() != null)
            for (CodeTables.CodeTable table : codeTables.getCodeTableList()) {
                String strName = table.getName();
                String strNameCode = table.getNameCode();
                LocalDate calCreate = table.getCreationDate();
                LocalDate calDeletion = table.getMarkedForDeletionDate();
                CodeTables.CodeTable.Descriptions descriptions = table.getDescriptions();
                Map<String, Object> properties = null;
                if (descriptions != null)
                    for (org.jibx.schema.org.opentravel._2012B.base.FreeText desc : descriptions
                            .getDescriptionList()) {
                        String strLanguage = desc.getLanguage();
                        String strValue = desc.getString();
                        if ((strLanguage == null) || (strLanguage.length() == 0))
                            strLanguage = NONE;
                        if (properties == null)
                            properties = new HashMap<String, Object>();
                        properties.put(strLanguage, strValue);
                    }

                recOTACodeTable.addNew();
                recOTACodeTable.getField(OTACodeTable.NAME).setString(strName);
                recOTACodeTable.getField(OTACodeTable.NAME_CODE).setString(strNameCode);
                if (calCreate != null)
                    ((DateField) recOTACodeTable.getField(OTACodeTable.CREATION_DATE))
                            .setDate(calCreate.toDateMidnight().toDate(), true, DBConstants.SCREEN_MOVE);
                if (calDeletion != null)
                    ((DateField) recOTACodeTable.getField(OTACodeTable.DELETION_DATE))
                            .setDate(calDeletion.toDateMidnight().toDate(), true, DBConstants.SCREEN_MOVE);
                ((PropertiesField) recOTACodeTable.getField(OTACodeTable.PROPERTIES)).setProperties(properties);
                recOTACodeTable.add();
                Object bookmark = recOTACodeTable.getLastModified(DBConstants.BOOKMARK_HANDLE);

                if (table.getCodes() != null)
                    if (table.getCodes().getCodeList() != null)
                        for (CodeTables.CodeTable.Codes.Code code : table.getCodes().getCodeList()) {
                            String strValue2 = code.getValue();
                            LocalDate calCreate2 = code.getCreationDate();
                            LocalDate calDeletion2 = code.getMarkedForDeletionDate();
                            java.util.List<CodeContent> contents = code.getCodeContentList();

                            String strNameDefault = null;
                            properties = null;
                            if (contents != null)
                                for (CodeContent contentType : contents) {
                                    String strLanguage = contentType.getLanguage();
                                    String strName3 = contentType.getName();
                                    String strValue3 = contentType.getString();

                                    if (((strLanguage == null) || (strLanguage.length() == 0))
                                            || (strNameDefault == null))
                                        strNameDefault = strName3;
                                    if ((strLanguage == null) || (strLanguage.length() == 0))
                                        strLanguage = NONE;
                                    if (properties == null)
                                        properties = new HashMap<String, Object>();
                                    if ((strName3 != null) && (strName3.length() > 0))
                                        properties.put(strLanguage, strName3);
                                    if ((strValue3 != null) && (strValue3.length() > 0))
                                        properties.put(strLanguage + VALUE_PARAM, strValue3);
                                }

                            recOTACodes.addNew();
                            recOTACodes.getField(OTACodes.OTA_CODE_TABLE_ID).setString(bookmark.toString());
                            recOTACodes.getField(OTACodes.VALUE).setString(strValue2);
                            recOTACodes.getField(OTACodes.NAME).setString(strNameDefault);
                            if (calCreate2 != null)
                                ((DateField) recOTACodes.getField(OTACodes.CREATION_DATE)).setDate(
                                        calCreate2.toDateMidnight().toDate(), true, DBConstants.SCREEN_MOVE);
                            if (calDeletion2 != null)
                                ((DateField) recOTACodes.getField(OTACodes.DELETION_DATE)).setDate(
                                        calDeletion2.toDateMidnight().toDate(), true, DBConstants.SCREEN_MOVE);
                            ((PropertiesField) recOTACodes.getField(OTACodes.PROPERTIES))
                                    .setProperties(properties);
                            recOTACodes.add();

                        }
            }

    } catch (DBException ex) {
        ex.printStackTrace();
    } catch (FileNotFoundException ex) {
        ex.printStackTrace();
    } catch (JiBXException e) {
        e.printStackTrace();
    }
}

From source file:com.tysanclan.site.projectewok.beans.impl.DemocracyServiceImpl.java

License:Open Source License

@Override
@Transactional(propagation = Propagation.REQUIRED)
public void checkSenatorElections() {
    final SenateElection current = getCurrentSenateElection();

    if (current != null)
        return;// w  w w. ja  va2s . c o m

    LocalDate sixMonthsAgo = LocalDate.now().minusMonths(6);

    SenateElectionFilter electionsMoreThanSixMonthsAgo = new SenateElectionFilter();
    electionsMoreThanSixMonthsAgo.setStartBefore(sixMonthsAgo.toDate());
    electionsMoreThanSixMonthsAgo.addOrderBy("start", false);

    SenateElectionFilter electionsLessThanSixMonthsAgo = new SenateElectionFilter();
    electionsLessThanSixMonthsAgo.setStartAfter(sixMonthsAgo.toDate());
    electionsLessThanSixMonthsAgo.addOrderBy("start", false);

    final boolean thereWasAnElectionMoreThanSixMonthsAgo = senateElectionDAO
            .countByFilter(electionsMoreThanSixMonthsAgo) > 0;
    final boolean thereWasNoElectionLessThanSixMonthsAgo = senateElectionDAO
            .countByFilter(electionsLessThanSixMonthsAgo) == 0;
    final boolean thereHasNeverBeenAnElection = senateElectionDAO.countAll() == 0;
    if (thereHasNeverBeenAnElection
            || (thereWasAnElectionMoreThanSixMonthsAgo && thereWasNoElectionLessThanSixMonthsAgo)) {
        if (thereHasNeverBeenAnElection) {
            logService.logSystemAction("Democracy", "There has never been a Senate election");
        } else {
            logService.logSystemAction("Democracy", "Last Senate election more than six months ago");
        }
        createSenateElection();
    } else {

        SenateElectionFilter lastSenateElectionFilter = new SenateElectionFilter();
        lastSenateElectionFilter.addOrderBy("start", false);
        List<SenateElection> elections = senateElectionDAO.findByFilter(lastSenateElectionFilter, 0, 1);

        final long senators = userDAO.countByRank(Rank.SENATOR);

        if (senators <= 1) {
            logService.logSystemAction("Democracy", "Only one Senator left");
            createSenateElection();
            return;
        }

        for (SenateElection election : elections) {
            final int seats = election.getSeats();

            if (seats > 0) {

                int fraction = (int) ((senators * 100) / seats);

                if (fraction < 40) {
                    logService.logSystemAction("Democracy",
                            "Senate size less than 40% of last election's seats");
                    createSenateElection();
                }
            }
            break;

        }
    }

}

From source file:com.vmware.photon.controller.model.adapters.awsadapter.util.AWSCsvBillParser.java

License:Open Source License

public Map<String, AwsAccountDetailDto> parseDetailedCsvBill(List<String> ignorableInvoiceCharge,
        Path csvBillZipFilePath, LocalDate monthDate) throws IOException {

    Path workingDirPath = csvBillZipFilePath.getParent();
    unzip(csvBillZipFilePath.toString(), workingDirPath.toString());
    String unzippedCsvFilePathStr = csvBillZipFilePath.toString().substring(0,
            csvBillZipFilePath.toString().lastIndexOf('.'));
    Path unzippedCsvFilePath = Paths.get(unzippedCsvFilePathStr);

    Map<String, AwsAccountDetailDto> accountToDetailsMap;
    try (InputStream extractedObjectContentInputStream = new FileInputStream(unzippedCsvFilePath.toFile())) {
        accountToDetailsMap = parseDetailedCsvBill(extractedObjectContentInputStream, ignorableInvoiceCharge);
    } finally {//from  ww  w. j  a  v  a2  s .c o  m
        Files.deleteIfExists(unzippedCsvFilePath);
    }

    for (Map.Entry<String, AwsAccountDetailDto> accountDetailEntry : accountToDetailsMap.entrySet()) {
        AwsAccountDetailDto accountDetail = accountDetailEntry.getValue();
        accountDetail.month = monthDate.toDate().getTime();
    }
    return accountToDetailsMap;
}

From source file:dao.RegistroDao.java

public List<Registro> getListBetween(Date dt1, Date dt2) {
    List<Registro> result = new ArrayList<Registro>();
    try {/*from   w  w  w.  j a  v  a  2  s  . c  om*/
        LocalDate dtTmp = LocalDate.fromDateFields(dt1);
        while (dt2.compareTo(dtTmp.dayOfMonth().withMinimumValue().toDate()) >= 0) {
            List<Registro> listTmp = getListByMonth(dtTmp.toDate());
            if (listTmp != null) {
                result.addAll(listTmp);
                //ordena a lista 
                Collections.sort(result, regComparator);
            }
            dtTmp = dtTmp.plusMonths(1);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return result;
}

From source file:de.dreier.mytargets.shared.utils.typeconverters.LocalDateConverter.java

License:Open Source License

@Override
public Long getDBValue(LocalDate model) {
    if (model != null) {
        return model.toDate().getTime();
    }/*w ww. j a v a 2s .c om*/

    return null;
}

From source file:de.hh.changeRing.infrastructure.eclipselink.JodaLocalDateConverter.java

License:Open Source License

@Override
public java.util.Date toDatabaseLayerType(org.joda.time.LocalDate objectValue) {
    return objectValue.toDateMidnight().toDate();
}