Example usage for org.joda.time DateTime plusMonths

List of usage examples for org.joda.time DateTime plusMonths

Introduction

In this page you can find the example usage for org.joda.time DateTime plusMonths.

Prototype

public DateTime plusMonths(int months) 

Source Link

Document

Returns a copy of this datetime plus the specified number of months.

Usage

From source file:adwords.axis.v201409.remarketing.AddRuleBasedUserLists.java

License:Open Source License

public static void runExample(AdWordsServices adWordsServices, AdWordsSession session) throws Exception {

    // Get the AdwordsUserListService.
    AdwordsUserListServiceInterface userListService = adWordsServices.get(session,
            AdwordsUserListServiceInterface.class);

    // First rule item group - users who visited the checkout page and had more than one item
    // in their shopping cart.
    StringKey pageTypeKey = new StringKey("ecomm_pagetype");

    StringRuleItem checkoutStringRuleItem = new StringRuleItem();
    checkoutStringRuleItem.setKey(pageTypeKey);
    checkoutStringRuleItem.setOp(StringRuleItemStringOperator.EQUALS);
    checkoutStringRuleItem.setValue("checkout");

    RuleItem checkoutRuleItem = new RuleItem();
    checkoutRuleItem.setStringRuleItem(checkoutStringRuleItem);

    NumberKey cartSizeKey = new NumberKey("cartsize");

    NumberRuleItem cartSizeNumberRuleItem = new NumberRuleItem();
    cartSizeNumberRuleItem.setKey(cartSizeKey);
    cartSizeNumberRuleItem.setOp(NumberRuleItemNumberOperator.GREATER_THAN);
    cartSizeNumberRuleItem.setValue(1.0);

    RuleItem cartSizeRuleItem = new RuleItem();
    cartSizeRuleItem.setNumberRuleItem(cartSizeNumberRuleItem);

    // Combine the two rule items into a RuleItemGroup so AdWords will AND their rules
    // together.//from   w  w  w .  j av  a  2  s.  co m
    RuleItemGroup checkoutMultipleItemGroup = new RuleItemGroup();
    checkoutMultipleItemGroup.setItems(new RuleItem[] { checkoutRuleItem, cartSizeRuleItem });

    // Second rule item group - users who checked out within the next 3 months.
    DateKey checkoutDateKey = new DateKey("checkoutdate");

    DateRuleItem startDateDateRuleItem = new DateRuleItem();
    startDateDateRuleItem.setKey(checkoutDateKey);
    startDateDateRuleItem.setOp(DateRuleItemDateOperator.AFTER);
    startDateDateRuleItem.setValue(new DateTime().toString(DATE_FORMAT_STRING));

    RuleItem startDateRuleItem = new RuleItem();
    startDateRuleItem.setDateRuleItem(startDateDateRuleItem);

    DateRuleItem endDateDateRuleItem = new DateRuleItem();
    endDateDateRuleItem.setKey(checkoutDateKey);
    endDateDateRuleItem.setOp(DateRuleItemDateOperator.BEFORE);
    endDateDateRuleItem.setValue(new DateTime().plusMonths(3).toString(DATE_FORMAT_STRING));

    RuleItem endDateRuleItem = new RuleItem();
    endDateRuleItem.setDateRuleItem(endDateDateRuleItem);

    // Combine the date rule items into a RuleItemGroup.
    RuleItemGroup checkedOutNextThreeMonthsItemGroup = new RuleItemGroup();
    checkedOutNextThreeMonthsItemGroup.setItems(new RuleItem[] { startDateRuleItem, endDateRuleItem });

    // Combine the rule item groups into a Rule so AdWords will OR the groups together.
    Rule rule = new Rule();
    rule.setGroups(new RuleItemGroup[] { checkoutMultipleItemGroup, checkedOutNextThreeMonthsItemGroup });

    // Create the user list with no restrictions on site visit date.
    ExpressionRuleUserList expressionUserList = new ExpressionRuleUserList();
    expressionUserList
            .setName("Expression based user list created at " + new DateTime().toString("yyyyMMdd_HHmmss"));
    expressionUserList
            .setDescription("Users who checked out in three month window OR visited the checkout page "
                    + "with more than one item in their cart");
    expressionUserList.setRule(rule);

    // Create the user list restricted to users who visit your site within the next six months.
    DateTime startDate = new DateTime();
    DateTime endDate = startDate.plusMonths(6);

    DateSpecificRuleUserList dateUserList = new DateSpecificRuleUserList();
    dateUserList.setName("Date rule user list created at " + new DateTime().toString("yyyyMMdd_HHmmss"));
    dateUserList.setDescription(String.format(
            "Users who visited the site between %s and %s and "
                    + "checked out in three month window OR visited the checkout page "
                    + "with more than one item in their cart",
            startDate.toString(DATE_FORMAT_STRING), endDate.toString(DATE_FORMAT_STRING)));
    dateUserList.setRule(rule);

    // Set the start and end dates of the user list.
    dateUserList.setStartDate(startDate.toString(DATE_FORMAT_STRING));
    dateUserList.setEndDate(endDate.toString(DATE_FORMAT_STRING));

    // Create operations to add the user lists.
    List<UserListOperation> operations = Lists.newArrayList();
    for (UserList userList : new UserList[] { expressionUserList, dateUserList }) {
        UserListOperation operation = new UserListOperation();
        operation.setOperand(userList);
        operation.setOperator(Operator.ADD);
        operations.add(operation);
    }

    // Submit the operations.
    UserListReturnValue result = userListService
            .mutate(operations.toArray(new UserListOperation[operations.size()]));

    // Display the results.
    for (UserList userListResult : result.getValue()) {
        System.out.printf(
                "User list added with ID %d, name '%s', status '%s', list type '%s',"
                        + " accountUserListStatus '%s', description '%s'.%n",
                userListResult.getId(), userListResult.getName(), userListResult.getStatus().getValue(),
                userListResult.getListType() == null ? null : userListResult.getListType().getValue(),
                userListResult.getAccountUserListStatus().getValue(), userListResult.getDescription());
    }
}

From source file:be.fedict.eid.tsl.BelgianTrustServiceListFactory.java

License:Open Source License

/**
 * Creates a new instance of a trust service list for Belgium according to
 * the given time frame./*www .j  a v  a  2  s .co m*/
 * 
 * @param year
 *            the year for which the TSL should be valid.
 * @param trimester
 *            the trimester for which the TSL should be valid.
 * @return the trust service list object.
 */
public static TrustServiceList newInstance(int year, Trimester trimester) {
    if (2010 != year && 2011 != year && 2012 != year && 2013 != year && 2014 != year && 2015 != year) {
        throw new IllegalArgumentException(
                "cannot create a TSL for year (NEW): " + year + " trimester " + trimester);
    }

    BigInteger tslSequenceNumber;
    DateTime listIssueDateTime;
    Document euTSLDocument;
    X509Certificate euSSLCertificate = null;

    // setup
    TrustServiceList trustServiceList = TrustServiceListFactory.newInstance();
    setupTSL(trustServiceList);

    // trust service provider list: certipost
    LOG.debug("Create TSP: Certipost");
    TrustServiceProvider certipostTrustServiceProvider = createTSP_certipost();
    LOG.debug("Add TSP_certipost to Trustlist");
    trustServiceList.addTrustServiceProvider(certipostTrustServiceProvider);

    // Certipost trust services: Root CA and Root CA2
    LOG.debug("Add Trustservice BRCA1 to TSP_Certipost");
    certipostTrustServiceProvider.addTrustService(createTSPService_BRCA1());
    LOG.debug("Add Trustservice BRCA2 to TSP_Certipost");
    certipostTrustServiceProvider.addTrustService(createTSPService_BRCA2());

    if (2010 == year) {
        switch (trimester) {
        case FIRST:
            tslSequenceNumber = BigInteger.valueOf(1);
            listIssueDateTime = new DateTime(2010, 1, 1, 0, 0, 0, 0, DateTimeZone.UTC);
            euTSLDocument = loadDocumentFromResource("eu/tl-mp.xml");
            break;
        case SECOND:
            tslSequenceNumber = BigInteger.valueOf(2);
            listIssueDateTime = new DateTime(2010, 5, 1, 0, 0, 0, 0, DateTimeZone.UTC);
            euTSLDocument = loadDocumentFromResource("eu/tl-mp-2.xml");
            break;
        case THIRD:
            tslSequenceNumber = BigInteger.valueOf(3);
            listIssueDateTime = new DateTime(2010, 9, 1, 0, 0, 0, 0, DateTimeZone.UTC);
            euTSLDocument = loadDocumentFromResource("eu/tl-mp-2.xml");
            break;
        default:
            throw new IllegalArgumentException(trimester.toString());
        }
    } else if (2011 == year) {
        // year == 2011
        switch (trimester) {
        case FIRST:
            tslSequenceNumber = BigInteger.valueOf(4);
            listIssueDateTime = new DateTime(2011, 1, 1, 0, 0, 0, 0, DateTimeZone.UTC);
            euTSLDocument = loadDocumentFromResource("eu/tl-mp-2.xml");
            euSSLCertificate = loadCertificateFromResource("eu/ec.europa.eu.der");
            break;
        case SECOND:
            tslSequenceNumber = BigInteger.valueOf(5);
            listIssueDateTime = new DateTime(2011, 5, 1, 0, 0, 0, 0, DateTimeZone.UTC);
            euTSLDocument = loadDocumentFromResource("eu/tl-mp-2.xml");
            euSSLCertificate = loadCertificateFromResource("eu/ec.europa.eu.der");
            break;
        case THIRD:
            tslSequenceNumber = BigInteger.valueOf(6);
            listIssueDateTime = new DateTime(2011, 9, 1, 0, 0, 0, 0, DateTimeZone.UTC);
            euTSLDocument = loadDocumentFromResource("eu/tl-mp-2.xml");
            euSSLCertificate = loadCertificateFromResource("eu/ec.europa.eu.der");
            break;
        default:
            throw new IllegalArgumentException(trimester.toString());
        }
    } else if (2012 == year) {
        // year == 2012
        switch (trimester) {
        case FIRST:
            tslSequenceNumber = BigInteger.valueOf(7);
            listIssueDateTime = new DateTime(2012, 1, 1, 0, 0, 0, 0, DateTimeZone.UTC);
            euTSLDocument = loadDocumentFromResource("eu/tl-mp-2.xml");
            euSSLCertificate = loadCertificateFromResource("eu/ec.europa.eu.der");
            break;
        case SECOND: {
            tslSequenceNumber = BigInteger.valueOf(8);
            listIssueDateTime = new DateTime(2012, 5, 1, 0, 0, 0, 0, DateTimeZone.UTC);
            euTSLDocument = loadDocumentFromResource("eu/tl-mp-33.xml");
            euSSLCertificate = loadCertificateFromResource("eu/ec.europa.eu.der");

            createTSPService_AdditionelServices_Certipost(certipostTrustServiceProvider);
            break;
        }
        case THIRD: {
            tslSequenceNumber = BigInteger.valueOf(9);
            listIssueDateTime = new DateTime(2012, 9, 1, 0, 0, 0, 0, DateTimeZone.UTC);
            euTSLDocument = loadDocumentFromResource("eu/tl-mp-33.xml");
            euSSLCertificate = loadCertificateFromResource("eu/ec.europa.eu.der");

            createTSPService_AdditionelServices_Certipost(certipostTrustServiceProvider);
            break;
        }
        default:
            throw new IllegalArgumentException(trimester.toString());
        }
    } else if (2013 == year) {
        switch (trimester) {
        case FIRST: {
            tslSequenceNumber = BigInteger.valueOf(10);
            listIssueDateTime = new DateTime(2013, 1, 1, 0, 0, 0, 0, DateTimeZone.UTC);
            euTSLDocument = loadDocumentFromResource("eu/tl-mp-33.xml");
            euSSLCertificate = loadCertificateFromResource("eu/ec.europa.eu.der");

            createTSPService_AdditionelServices_Certipost(certipostTrustServiceProvider);
            break;
        }
        case SECOND: {
            tslSequenceNumber = BigInteger.valueOf(11);
            listIssueDateTime = new DateTime(2013, 5, 1, 0, 0, 0, 0, DateTimeZone.UTC);
            euTSLDocument = loadDocumentFromResource("eu/tl-mp-33.xml");
            euSSLCertificate = loadCertificateFromResource("eu/ec.europa.eu.der");

            createTSPService_AdditionelServices_Certipost(certipostTrustServiceProvider);
            break;
        }
        case THIRD: {
            tslSequenceNumber = BigInteger.valueOf(12);
            listIssueDateTime = new DateTime(2013, 9, 1, 0, 0, 0, 0, DateTimeZone.UTC);
            euTSLDocument = loadDocumentFromResource("eu/tl-mp-33.xml");
            euSSLCertificate = loadCertificateFromResource("eu/ec.europa.eu.2013-2015.der");

            // BRCA 3 en BRCA 4
            LOG.debug("Add Trustservice BRCA3 to TSP_Certipost");
            certipostTrustServiceProvider.addTrustService(createTSPService_BRCA3());
            LOG.debug("Add Trustservice BRCA4 to TSP_Certipost");
            certipostTrustServiceProvider.addTrustService(createTSPService_BRCA4());

            createTSPService_AdditionelServices_Certipost(certipostTrustServiceProvider);

            // SWIFT
            LOG.debug("Create TSP: Swift");
            TrustServiceProvider swiftTrustServiceProvider = createTSP_swift();
            LOG.debug("Add TSP_swift to Trustlist");
            trustServiceList.addTrustServiceProvider(swiftTrustServiceProvider);
            LOG.debug("Add Trustservice SwiftNetPKI to TSP_Swift");
            swiftTrustServiceProvider.addTrustService(createTSPService_SWIFTNetPKI());

            break;
        }
        default:
            throw new IllegalArgumentException(trimester.toString());
        }
    } else if (2014 == year) {
        switch (trimester) {
        case FIRST: {
            tslSequenceNumber = BigInteger.valueOf(16);
            listIssueDateTime = new DateTime(2014, 2, 14, 0, 0, 0, 0, DateTimeZone.UTC);
            euTSLDocument = loadDocumentFromResource("eu/tl-mp-33.xml");
            euSSLCertificate = loadCertificateFromResource("eu/ec.europa.eu.2013-2015.der");

            // BRCA 3 en BRCA 4
            LOG.debug("Add Trustservice BRCA3 to TSP_Certipost");
            certipostTrustServiceProvider.addTrustService(createTSPService_BRCA3());
            LOG.debug("Add Trustservice BRCA4 to TSP_Certipost");
            certipostTrustServiceProvider.addTrustService(createTSPService_BRCA4());

            createTSPService_AdditionelServices_Certipost(certipostTrustServiceProvider);

            // SWIFT
            LOG.debug("Create TSP: Swift");
            TrustServiceProvider swiftTrustServiceProvider = createTSP_swift();
            LOG.debug("Add TSP_swift to Trustlist");
            trustServiceList.addTrustServiceProvider(swiftTrustServiceProvider);
            LOG.debug("Add Trustservice SwiftNetPKI to TSP_Swift");
            swiftTrustServiceProvider.addTrustService(createTSPService_SWIFTNetPKI());
            break;
        }
        case SECOND: {
            tslSequenceNumber = BigInteger.valueOf(17);
            listIssueDateTime = new DateTime(2014, 6, 20, 0, 0, 0, 0, DateTimeZone.UTC);
            euTSLDocument = loadDocumentFromResource("eu/tl-mp-33.xml");
            euSSLCertificate = loadCertificateFromResource("eu/ec.europa.eu.2013-2015.der");

            // BRCA 3 en BRCA 4
            LOG.debug("Add Trustservice BRCA3 to TSP_Certipost");
            certipostTrustServiceProvider.addTrustService(createTSPService_BRCA3());
            LOG.debug("Add Trustservice BRCA4 to TSP_Certipost");
            certipostTrustServiceProvider.addTrustService(createTSPService_BRCA4());

            createTSPService_AdditionelServices_Certipost(certipostTrustServiceProvider);

            // SWIFT
            LOG.debug("Create TSP: Swift");
            TrustServiceProvider swiftTrustServiceProvider = createTSP_swift();
            LOG.debug("Add TSP_swift to Trustlist");
            trustServiceList.addTrustServiceProvider(swiftTrustServiceProvider);
            LOG.debug("Add Trustservice SwiftNetPKI to TSP_Swift");
            swiftTrustServiceProvider.addTrustService(createTSPService_SWIFTNetPKI());
            break;
        }
        case THIRD: {
            tslSequenceNumber = BigInteger.valueOf(19);
            listIssueDateTime = new DateTime(2014, 10, 9, 0, 0, 0, 0, DateTimeZone.UTC);
            euTSLDocument = loadDocumentFromResource("eu/tl-mp-33.xml");
            euSSLCertificate = loadCertificateFromResource("eu/ec.europa.eu.2013-2015.der");

            // BRCA 3 en BRCA 4
            LOG.debug("Add Trustservice BRCA3 to TSP_Certipost");
            certipostTrustServiceProvider.addTrustService(createTSPService_BRCA3());
            LOG.debug("Add Trustservice BRCA4 to TSP_Certipost");
            certipostTrustServiceProvider.addTrustService(createTSPService_BRCA4());

            createTSPService_AdditionelServices_Certipost(certipostTrustServiceProvider);

            // SWIFT
            LOG.debug("Create TSP: Swift");
            TrustServiceProvider swiftTrustServiceProvider = createTSP_swift();
            LOG.debug("Add TSP_swift to Trustlist");
            trustServiceList.addTrustServiceProvider(swiftTrustServiceProvider);
            LOG.debug("Add Trustservice SwiftNetPKI to TSP_Swift");
            swiftTrustServiceProvider.addTrustService(createTSPService_SWIFTNetPKI());

            //Quovadis
            LOG.debug("Create TSP Qua Vadis");
            TrustServiceProvider quovadisTrustServiceProvider = createTSP_Quovadis();
            LOG.debug("Add TSP_QuoVadis to Trustlist");
            trustServiceList.addTrustServiceProvider(quovadisTrustServiceProvider);
            LOG.debug("Add QuoVadis BE PKI CertificationAuthority");
            quovadisTrustServiceProvider
                    .addTrustService(createTSPService_QuoVadisBEPKICertificationAuthority());

            break;
        }
        default:
            throw new IllegalArgumentException(trimester.toString());
        }
    } else if (2015 == year) {
        switch (trimester) {
        case FIRST: {
            tslSequenceNumber = BigInteger.valueOf(20);
            listIssueDateTime = new DateTime(2015, 2, 19, 0, 0, 0, 0, DateTimeZone.UTC);
            euTSLDocument = loadDocumentFromResource("eu/tl-mp-33.xml");
            euSSLCertificate = loadCertificateFromResource("eu/ec.europa.eu.2013-2015.der");

            // BRCA 3 en BRCA 4
            LOG.debug("Add Trustservice BRCA3 to TSP_Certipost");
            certipostTrustServiceProvider.addTrustService(createTSPService_BRCA3());
            LOG.debug("Add Trustservice BRCA4 to TSP_Certipost");
            certipostTrustServiceProvider.addTrustService(createTSPService_BRCA4());

            createTSPService_AdditionelServices_Certipost(certipostTrustServiceProvider);

            // SWIFT
            LOG.debug("Create TSP: Swift");
            TrustServiceProvider swiftTrustServiceProvider = createTSP_swift();
            LOG.debug("Add TSP_swift to Trustlist");
            trustServiceList.addTrustServiceProvider(swiftTrustServiceProvider);
            LOG.debug("Add Trustservice SwiftNetPKI to TSP_Swift");
            swiftTrustServiceProvider.addTrustService(createTSPService_SWIFTNetPKI());

            //Quovadis
            LOG.debug("Create TSP Qua Vadis");
            TrustServiceProvider quovadisTrustServiceProvider = createTSP_Quovadis();
            LOG.debug("Add TSP_QuoVadis to Trustlist");
            trustServiceList.addTrustServiceProvider(quovadisTrustServiceProvider);
            LOG.debug("Add QuoVadis BE PKI CertificationAuthority");
            quovadisTrustServiceProvider
                    .addTrustService(createTSPService_QuoVadisBEPKICertificationAuthority());

            break;
        }
        case SECOND: {
            tslSequenceNumber = BigInteger.valueOf(21);
            listIssueDateTime = new DateTime(2015, 6, 25, 0, 0, 0, 0, DateTimeZone.UTC);
            euTSLDocument = loadDocumentFromResource("eu/tl-mp-33.xml");
            euSSLCertificate = loadCertificateFromResource("eu/ec.europa.eu.2013-2015.der");

            // BRCA 3 en BRCA 4
            LOG.debug("Add Trustservice BRCA3 to TSP_Certipost");
            certipostTrustServiceProvider.addTrustService(createTSPService_BRCA3());
            LOG.debug("Add Trustservice BRCA4 to TSP_Certipost");
            certipostTrustServiceProvider.addTrustService(createTSPService_BRCA4());

            createTSPService_AdditionelServices_Certipost(certipostTrustServiceProvider);

            // SWIFT
            LOG.debug("Create TSP: Swift");
            TrustServiceProvider swiftTrustServiceProvider = createTSP_swift();
            LOG.debug("Add TSP_swift to Trustlist");
            trustServiceList.addTrustServiceProvider(swiftTrustServiceProvider);
            LOG.debug("Add Trustservice SwiftNetPKI to TSP_Swift");
            swiftTrustServiceProvider.addTrustService(createTSPService_SWIFTNetPKI());

            //Quovadis
            LOG.debug("Create TSP Qua Vadis");
            TrustServiceProvider quovadisTrustServiceProvider = createTSP_Quovadis();
            LOG.debug("Add TSP_QuoVadis to Trustlist");
            trustServiceList.addTrustServiceProvider(quovadisTrustServiceProvider);
            LOG.debug("Add QuoVadis BE PKI CertificationAuthority");
            quovadisTrustServiceProvider
                    .addTrustService(createTSPService_QuoVadisBEPKICertificationAuthority());

            break;
        }
        case THIRD: {
            tslSequenceNumber = BigInteger.valueOf(22);
            listIssueDateTime = new DateTime(2015, 11, 5, 0, 0, 0, 0, DateTimeZone.UTC);
            euTSLDocument = loadDocumentFromResource("eu/tl-mp-33.xml");
            euSSLCertificate = loadCertificateFromResource("eu/ec.europa.eu.2013-2015.der");

            // BRCA 3 en BRCA 4
            LOG.debug("Add Trustservice BRCA3 to TSP_Certipost");
            certipostTrustServiceProvider.addTrustService(createTSPService_BRCA3());
            LOG.debug("Add Trustservice BRCA4 to TSP_Certipost");
            certipostTrustServiceProvider.addTrustService(createTSPService_BRCA4());

            createTSPService_AdditionelServices_Certipost(certipostTrustServiceProvider);

            // SWIFT
            LOG.debug("Create TSP: Swift");
            TrustServiceProvider swiftTrustServiceProvider = createTSP_swift();
            LOG.debug("Add TSP_swift to Trustlist");
            trustServiceList.addTrustServiceProvider(swiftTrustServiceProvider);
            LOG.debug("Add Trustservice SwiftNetPKI to TSP_Swift");
            swiftTrustServiceProvider.addTrustService(createTSPService_SWIFTNetPKI());

            //Quovadis
            LOG.debug("Create TSP Qua Vadis");
            TrustServiceProvider quovadisTrustServiceProvider = createTSP_Quovadis();
            LOG.debug("Add TSP_QuoVadis to Trustlist");
            trustServiceList.addTrustServiceProvider(quovadisTrustServiceProvider);
            LOG.debug("Add QuoVadis BE PKI CertificationAuthority");
            quovadisTrustServiceProvider
                    .addTrustService(createTSPService_QuoVadisBEPKICertificationAuthority());

            break;
        }
        default:
            throw new IllegalArgumentException(trimester.toString());
        }
    } else {
        throw new IllegalArgumentException("unsupported year");
    }

    //set sequencenumber
    trustServiceList.setTSLSequenceNumber(tslSequenceNumber);
    //set issuedate
    trustServiceList.setListIssueDateTime(listIssueDateTime);
    // next update
    int operationalOverlapWeeks = 2;
    DateTime nextUpdateDateTime = listIssueDateTime.plusMonths(12 / 3).plusWeeks(operationalOverlapWeeks);
    trustServiceList.setNextUpdate(nextUpdateDateTime);

    trustServiceList.addOtherTSLPointer(
            "https://ec.europa.eu/information_society/policy/esignature/trusted-list/tl-hr.pdf",
            "application/pdf", "http://uri.etsi.org/TrstSvc/TrustedList/TSLType/EUlistofthelists", "EU",
            "European Commission", "http://uri.etsi.org/TrstSvc/TrustedList/schemerules/EUlistofthelists",
            Locale.ENGLISH, euSSLCertificate);

    TrustServiceList euTSL;
    try {
        euTSL = TrustServiceListFactory.newInstance(euTSLDocument);
    } catch (IOException e) {
        throw new RuntimeException("could not load EU trust list: " + e.getMessage(), e);
    }
    X509Certificate euCertificate = euTSL.verifySignature();
    LOG.debug("EU certificate: " + euCertificate);

    trustServiceList.addOtherTSLPointer(
            "https://ec.europa.eu/information_society/policy/esignature/trusted-list/tl-mp.xml",
            "application/vnd.etsi.tsl+xml", "http://uri.etsi.org/TrstSvc/TrustedList/TSLType/EUlistofthelists",
            "EU", "European Commission", "http://uri.etsi.org/TrstSvc/TrustedList/schemerules/EUlistofthelists",
            Locale.ENGLISH, euCertificate);

    /*
    Collections.sort(certipostTrustServiceProvider.getTrustServices(),new TrustServiceComparer());
    Collections.sort(trustServiceList.getTrustServiceProviders(), new TrustServiceProviderComparer());
    */
    return trustServiceList;
}

From source file:br.com.nerv.eva.service.listener.ProcessSellDeposit.java

@Transactional
public void listen(@Observes @Sell PropertyCustomer pc) {
    final String value = format(pc.getProperty().getValue());

    if (!value.equals(format(pc.getDepositValue()))) {
        throw new BusinessException("O valor do depsito no corresponde " + "ao valor anunciado");
    }/*ww  w.  ja  v  a 2  s.  c  o m*/

    DateTime dt = new DateTime();
    if (dt.dayOfMonth().get() <= pc.getPaymentDay())
        dt.plusMonths(1);

    PaymentRegister payment = build(pc);
    payment.setDate(dt.dayOfMonth().setCopy(pc.getPaymentDay()).toDate());
    prDAO.save(payment);
}

From source file:com.addthis.hydra.task.source.AbstractPersistentStreamSource.java

License:Apache License

/**
 * @return a list of dates given the start/end range from the config
 *///from  www  . j  a va  2 s .  c  om
private void fillDateList(DateTime start, DateTime end) {
    DateTime mark = start;
    while (mark.isBefore(end) || mark.isEqual(end)) {
        if (reverse) {
            dates.addFirst(mark);
        } else {
            dates.addLast(mark);
        }
        if ((dateIncrements != null && dateIncrements.equals("DAYS")) || dateFormat.length() == 6) {
            mark = mark.plusDays(1);
        } else if ((dateIncrements != null && dateIncrements.equals("HOURS")) || dateFormat.length() == 8) {
            mark = mark.plusHours(1);
        } else if ((dateIncrements != null && dateIncrements.equals("MONTHS"))) {
            mark = mark.plusMonths(1);
        } else if (dateIncrements == null) {
            log.warn("Non-Standard dateFormat: " + dateFormat + " defaulting to daily time increments\n"
                    + "This can be modified to hourly time increments by setting dateIncrements to 'HOURS'");
            mark = mark.plusDays(1);
        }
    }
}

From source file:com.barchart.feed.ddf.message.enums.DDF_TradeDay.java

License:BSD License

/**
 * recover full trade date from DDF day code and todays date
 * //from  ww  w  .ja va 2 s  .  c  om
 * expressed in UTC zone
 * 
 * year, month, day : should be treated as local market trade date.
 *
 * @param tradeDay the trade day
 * @param todayDate the today date
 * @return the time value
 */
public static TimeValue tradeDateFrom(final DDF_TradeDay tradeDay, final DateTime todayDate) {

    // trading day of month reported by the feed
    final int tradingDayNum = tradeDay.day;

    // current day of month
    final int currentDayNum = todayDate.getDayOfMonth();

    // positive for same month if trading date is in the future
    // unless day enum is not a day in the month ???
    final int difference = tradingDayNum - currentDayNum;

    final boolean isSmall = Math.abs(difference) <= HOLIDAY_THESHOLD;
    final boolean isLarge = !isSmall;

    //

    final boolean isSameMonthSameDay = (difference == 0);

    final boolean isSameMonthPastDay = difference < 0 & isSmall;
    final boolean isSameMonthNextDay = difference > 0 & isSmall;

    final boolean isPastMonthPastDay = difference > 0 & isLarge;
    final boolean isNextMonthNextDay = difference < 0 & isLarge;

    //

    DateTime generated;

    try {
        if (isSameMonthSameDay) {
            generated = todayDate;
        } else if (isSameMonthPastDay) {
            generated = todayDate.withDayOfMonth(tradingDayNum);
        } else if (isSameMonthNextDay) {
            generated = todayDate.withDayOfMonth(tradingDayNum);
        } else if (isPastMonthPastDay) {
            generated = todayDate.minusMonths(1).withDayOfMonth(tradingDayNum);
        } else if (isNextMonthNextDay) {
            generated = todayDate.plusMonths(1).withDayOfMonth(tradingDayNum);
        } else {
            logger.error("should not happen");
            generated = todayDate;
        }
    } catch (final Exception e) {
        generated = todayDate;
    }

    final DateTime result = new DateTime(//
            generated.getYear(), //
            generated.getMonthOfYear(), //
            generated.getDayOfMonth(), //
            0, 0, 0, 0, ZONE_UTC);

    final long millisUTC = result.getMillis();

    return ValueBuilder.newTime(millisUTC);

}

From source file:com.cisco.dvbu.ps.utils.date.DateAddDate.java

License:Open Source License

/**
 * Called to invoke the stored procedure.  Will only be called a
 * single time per instance.  Can throw CustomProcedureException or
 * SQLException if there is an error during invoke.
 *//* w w  w  .j a  v a2s  .co  m*/
@Override
public void invoke(Object[] inputValues) throws CustomProcedureException, SQLException {
    java.util.Date startDate = null;
    Calendar startCal = null;
    DateTime startDateTime = null;
    DateTime endDateTime = null;
    String datePart = null;
    int dateLength = 0;

    try {
        result = null;
        if (inputValues[0] == null || inputValues[1] == null || inputValues[2] == null) {
            return;
        }

        datePart = (String) inputValues[0];
        dateLength = (Integer) inputValues[1];

        startDate = (java.util.Date) inputValues[2];
        startCal = Calendar.getInstance();
        startCal.setTime(startDate);
        startDateTime = new DateTime(startCal.get(Calendar.YEAR), startCal.get(Calendar.MONTH) + 1,
                startCal.get(Calendar.DAY_OF_MONTH), 0, 0, 0, 0);

        if (datePart.equalsIgnoreCase("second")) {
            endDateTime = startDateTime.plusSeconds(dateLength);
        }

        if (datePart.equalsIgnoreCase("minute")) {
            endDateTime = startDateTime.plusMinutes(dateLength);
        }

        if (datePart.equalsIgnoreCase("hour")) {
            endDateTime = startDateTime.plusHours(dateLength);
        }

        if (datePart.equalsIgnoreCase("day")) {
            endDateTime = startDateTime.plusDays(dateLength);
        }

        if (datePart.equalsIgnoreCase("week")) {
            endDateTime = startDateTime.plusWeeks(dateLength);
        }

        if (datePart.equalsIgnoreCase("month")) {
            endDateTime = startDateTime.plusMonths(dateLength);
        }

        if (datePart.equalsIgnoreCase("year")) {
            endDateTime = startDateTime.plusYears(dateLength);
        }

        result = new java.sql.Date(endDateTime.getMillis());
    } catch (Throwable t) {
        throw new CustomProcedureException(t);
    }
}

From source file:com.cisco.dvbu.ps.utils.date.DateAddTimestamp.java

License:Open Source License

/**
 * Called to invoke the stored procedure.  Will only be called a
 * single time per instance.  Can throw CustomProcedureException or
 * SQLException if there is an error during invoke.
 *///from   www . jav a2 s .c om
@Override
public void invoke(Object[] inputValues) throws CustomProcedureException, SQLException {
    Timestamp startDate = null;
    Calendar startCal = null;
    DateTime startDateTime = null;
    DateTime endDateTime = null;
    String datePart = null;
    int dateLength = 0;

    try {
        result = null;
        if (inputValues[0] == null || inputValues[1] == null || inputValues[2] == null) {
            return;
        }

        datePart = (String) inputValues[0];
        dateLength = (Integer) inputValues[1];

        startDate = (Timestamp) inputValues[2];
        startCal = Calendar.getInstance();
        startCal.setTime(startDate);
        startDateTime = new DateTime(startCal.get(Calendar.YEAR), startCal.get(Calendar.MONTH) + 1,
                startCal.get(Calendar.DAY_OF_MONTH), startCal.get(Calendar.HOUR_OF_DAY),
                startCal.get(Calendar.MINUTE), startCal.get(Calendar.SECOND),
                startCal.get(Calendar.MILLISECOND));

        if (datePart.equalsIgnoreCase("second")) {
            endDateTime = startDateTime.plusSeconds(dateLength);
        }

        if (datePart.equalsIgnoreCase("minute")) {
            endDateTime = startDateTime.plusMinutes(dateLength);
        }

        if (datePart.equalsIgnoreCase("hour")) {
            endDateTime = startDateTime.plusHours(dateLength);
        }

        if (datePart.equalsIgnoreCase("day")) {
            endDateTime = startDateTime.plusDays(dateLength);
        }

        if (datePart.equalsIgnoreCase("week")) {
            endDateTime = startDateTime.plusWeeks(dateLength);
        }

        if (datePart.equalsIgnoreCase("month")) {
            endDateTime = startDateTime.plusMonths(dateLength);
        }

        if (datePart.equalsIgnoreCase("year")) {
            endDateTime = startDateTime.plusYears(dateLength);
        }

        result = new Timestamp(endDateTime.toDate().getTime());
    } catch (Throwable t) {
        throw new CustomProcedureException(t);
    }
}

From source file:com.cloudhopper.commons.util.time.DateTimePeriod.java

License:Apache License

/**
 * Converts this period to a list of month periods.  Partial months will not be
 * included.  For example, a period of "2009" will return a list
 * of 12 months - one for each month in 2009.  On the other hand, a period
 * of "January 20, 2009" would return an empty list since partial
 * months are not included./*from  w  w  w . j  a  va 2  s  . co  m*/
 * @return A list of month periods contained within this period
 */
public List<DateTimePeriod> toMonths() {
    ArrayList<DateTimePeriod> list = new ArrayList<DateTimePeriod>();

    // default "current" month to start datetime
    DateTime currentStart = getStart();
    // calculate "next" month
    DateTime nextStart = currentStart.plusMonths(1);
    // continue adding until we've reached the end
    while (nextStart.isBefore(getEnd()) || nextStart.isEqual(getEnd())) {
        // its okay to add the current
        list.add(new DateTimeMonth(currentStart, nextStart));
        // increment both
        currentStart = nextStart;
        nextStart = currentStart.plusMonths(1);
    }

    return list;
}

From source file:com.cloudhopper.commons.util.time.DateTimePeriod.java

License:Apache License

static public DateTimePeriod createMonth(DateTime start) {
    DateTime end = start.plusMonths(1);
    return new DateTimeMonth(start, end);
}

From source file:com.court.controller.CollectionSheetFxmlController.java

private java.util.Date getInstallmentDate(java.util.Date lastInstDate) {
    DateTimeZone zone = DateTimeZone.forID("Asia/Colombo");
    DateTime lastInst = new DateTime(new SimpleDateFormat("yyyy-MM-dd").format(lastInstDate), zone);
    DateTime nowDate = lastInst.plusMonths(1);
    return nowDate.toDate();
}