Example usage for org.apache.commons.lang.time DateUtils addYears

List of usage examples for org.apache.commons.lang.time DateUtils addYears

Introduction

In this page you can find the example usage for org.apache.commons.lang.time DateUtils addYears.

Prototype

public static Date addYears(Date date, int amount) 

Source Link

Document

Adds a number of years to a date returning a new object.

Usage

From source file:com.nec.harvest.controller.SuisController.java

/**
 * Render page with path variables mapping
 * /*  ww w  .  j  a v a 2 s .  com*/
 * @param businessDay
 *            Actual business day
 * @param orgCode
 *            A path variable user's orgCode
 * @param year
 *            A path variable year
 * @param quarter
 *            A path variable quarter
 * @param model
 *            Spring's model that can be used to render a view
 * @return A redirect URL
 */
@RequestMapping(value = "/{orgCode:[a-z0-9]+}/{year:\\d{4}}/{quarter:[1-4]}", method = RequestMethod.GET)
public String render(@SessionAttribute(Constants.SESS_BUSINESS_DAY) Date businessDay,
        @PathVariable String orgCode, @PathVariable @DateTimeFormat(pattern = "yyyy") Date year,
        @PathVariable int quarter, final Model model) {

    // get three month of current quarter business
    final String CURRENT_MONTHLIES = "monthlies";
    String[] monthiesCurrentQuarter = DateUtil.getMonthliesOfQuarter(year, quarter);
    model.addAttribute(CURRENT_MONTHLIES, monthiesCurrentQuarter);

    // get final tighten
    Date finalTighten = null;
    try {
        finalTighten = getMonthlyTighten(businessDay, model);
    } catch (ServiceException ex) {
        logger.error(ex.getMessage(), ex);

        // ???????????
        model.addAttribute(ERROR_MESSAGE, getSystemError());
        model.addAttribute(ERROR, true);
        return getViewName();
    }

    // ???[?]?????
    if (!availableNext(orgCode, quarter, year, model, finalTighten, businessDay)) {
        return getViewName();
    }

    // ??????????
    if (!availablePrevious(orgCode, quarter, year, model, finalTighten)) {
        return getViewName();
    }
    // get startMonth
    String currentYear = DateFormatUtil.format(year, DateFormat.DATE_YEAR);
    String startMonth = currentYear + "04";

    // get endMonth
    String nextYear = DateFormatUtil.format(DateUtils.addYears(year, 1), DateFormat.DATE_YEAR);
    String endMonth = nextYear + "03";

    int countMonth = 12;
    try {
        Date endDate = DateFormatUtil.parse(endMonth, DateFormat.DATE_WITHOUT_DAY);
        if (endDate.after(businessDay)) {
            countMonth = countMonth - DateUtil.monthsBetween(businessDay, endDate);
            endMonth = DateFormatUtil.format(businessDay, DateFormat.DATE_WITHOUT_DAY);
        }
    } catch (NullPointerException | IllegalArgumentException | ParseException ex) {
        logger.warn(ex.getMessage());
    }

    // ???jiseki??
    Map<String, VJiseki> mapSuis = null;
    List<VJiseki> listSuisYear = null;
    try {
        listSuisYear = actualViewService.findByOrgCodeAndPeriodMonthly(orgCode, startMonth, endMonth);
    } catch (IllegalArgumentException | ObjectNotFoundException | NullPointerException ex) {
        logger.warn(ex.getMessage());

    } catch (ServiceException ex) {
        logger.error(ex.getMessage(), ex);

        // ???????????
        model.addAttribute(ERROR_MESSAGE, getSystemError());
        model.addAttribute(ERROR, true);
        return getViewName();
    }

    // ????
    try {
        mapSuis = getSuiiList(listSuisYear, DateFormatUtil.parse(startMonth, DateFormat.DATE_WITHOUT_DAY),
                countMonth);
    } catch (NullPointerException | IllegalArgumentException | ParseException ex) {
        logger.warn(ex.getMessage());
    }

    // find data budget performance
    Map<String, BudgetPerformance> mapAT023 = null;
    try {
        mapAT023 = budgetPerformanceService.findByOrgCodeAndStartMonthEndMonthAndKmkCodeJs(orgCode, startMonth,
                endMonth, Constants.DEFAULT_KMKCODEJ_K7111, Constants.DEFAULT_KMKCODEJ_K7521,
                Constants.DEFAULT_KMKCODEJ_K8110, Constants.DEFAULT_KMKCODEJ_K8210,
                Constants.DEFAULT_KMKCODEJ_K8310);
    } catch (IllegalArgumentException | ObjectNotFoundException ex) {
        logger.warn(ex.getMessage());

    } catch (ServiceException ex) {
        logger.error(ex.getMessage(), ex);

        // ???????????
        model.addAttribute(ERROR_MESSAGE, getSystemError());
        model.addAttribute(ERROR, true);
        return getViewName();
    }

    // ???
    Map<String, Double> mapAT015 = null;
    try {
        mapAT015 = inventoryService.findByOrgCodeAndPeriodMonthly(orgCode, startMonth, endMonth);
    } catch (IllegalArgumentException | ObjectNotFoundException ex) {
        logger.warn(ex.getMessage());

    } catch (ServiceException ex) {
        logger.error(ex.getMessage(), ex);

        // ???????????
        model.addAttribute(ERROR_MESSAGE, getSystemError());
        model.addAttribute(ERROR, true);
        return getViewName();
    }

    // ??
    calculateSuii(mapSuis, finalTighten, businessDay, mapAT023, mapAT015, quarter, model);
    return getViewName();
}

From source file:com.exxonmobile.ace.hybris.test.orders.B2BAcceleratorTestOrderData.java

/**
 * Create scheduled order to commence 20 years hence and cancel
 *///from   w  ww .  j a va 2  s  .c  om
protected String placeReplenishmentOrderInCancelledState(final String userID,
        final String purchaseOrderNumber) {
    String code = null;
    try {
        final TriggerData triggerData = new TriggerData();
        triggerData.setActivationTime(DateUtils.addYears(new Date(), 20));// Twenty Years From Now
        triggerData.setDaysOfWeek(Collections.singletonList(DayOfWeek.MONDAY));
        triggerData.setWeekInterval(Integer.valueOf(2));
        final Map<String, Long> products = new HashMap<String, Long>();
        products.put(PRODUCT_A, Long.valueOf(1));
        code = scheduleOrder(userID, products, createUsAddressData(), purchaseOrderNumber,
                ExxonmobilTestConstants.STANDARD_COSTCENTER, null, triggerData).getJobCode();
        if (code != null) {
            this.orderFacade.cancelReplenishment(code, userID);
        }

    } catch (final Exception e) {
        LOG.error(e.getMessage(), e);
    }
    return code;
}

From source file:gov.nih.nci.firebird.test.data.AbstractProtocolRegistrationBuilder.java

@SuppressWarnings("unchecked")
// Will always be BUILDER_TYPE
public BUILDER_TYPE complete() {
    if (getRegistration().getForm1572() != null) {
        getRegistration().getForm1572().getPracticeSites()
                .add(getOrganizationWithRoleType(OrganizationRoleType.PRACTICE_SITE));
        Organization clinicalLabOrg = getOrganizationWithRoleType(OrganizationRoleType.CLINICAL_LABORATORY);
        ClinicalLaboratory clinicalLab = (ClinicalLaboratory) clinicalLabOrg
                .getRole(OrganizationRoleType.CLINICAL_LABORATORY);
        LaboratoryCertificate cert = new LaboratoryCertificate(LaboratoryCertificateType.CAP);
        cert.setEffectiveDate(DateUtils.addYears(new Date(), -1));
        cert.setExpirationDate(DateUtils.addYears(new Date(), 1));
        cert.setCertificateFile(FirebirdFileFactory.getInstance().create());
        clinicalLab.addCertificate(cert);
        getRegistration().getForm1572().getLabs().add(clinicalLabOrg);
        getRegistration().getForm1572().getIrbs().add(getOrganizationWithRoleType(OrganizationRoleType.IRB));
    }/*from w  w  w.j  a  v  a2  s  . c om*/
    if (getRegistration().getHumanResearchCertificateForm() != null) {
        getRegistration().getHumanResearchCertificateForm().selectCertificate(
                getRegistration().getProfile().getCredentials(TrainingCertificate.class).iterator().next());
    }
    getRegistration().getFinancialDisclosure().setNoFinancialInterest(true);
    getRegistration().getFinancialDisclosure().getSupportingDocumentation()
            .add(FirebirdFileFactory.getInstance().create());
    getRegistration().getAdditionalAttachmentsForm().getAdditionalAttachments()
            .add(FirebirdFileFactory.getInstance().create());
    return (BUILDER_TYPE) this;
}

From source file:de.hybris.platform.yb2bacceleratortest.orders.B2BAcceleratorTestOrderData.java

/**
 * Create scheduled order to commence 20 years hence and cancel
 *///w  w w. jav  a  2s  .  c  o m
protected String placeReplenishmentOrderInCancelledState(final String userID,
        final String purchaseOrderNumber) {
    String code = null;
    try {
        final TriggerData triggerData = new TriggerData();
        triggerData.setActivationTime(DateUtils.addYears(new Date(), 20));// Twenty Years From Now
        triggerData.setDaysOfWeek(Collections.singletonList(DayOfWeek.MONDAY));
        triggerData.setWeekInterval(Integer.valueOf(2));
        final Map<String, Long> products = new HashMap<String, Long>();
        products.put(PRODUCT_A, Long.valueOf(1));
        code = scheduleOrder(userID, products, createUsAddressData(), purchaseOrderNumber,
                YB2BAcceleratorTestConstants.STANDARD_COSTCENTER, null, triggerData).getJobCode();
        if (code != null) {
            this.orderFacade.cancelReplenishment(code, userID);
        }

    } catch (final Exception e) {
        LOG.error(e.getMessage(), e);
    }
    return code;
}

From source file:com.mitre.test.orders.B2BAcceleratorTestOrderData.java

/**
 * Create scheduled order to commence 20 years hence and cancel
 *//*ww w.  j  a  va2s  . c om*/
protected String placeReplenishmentOrderInCancelledState(final String userID,
        final String purchaseOrderNumber) {
    String code = null;
    try {
        final TriggerData triggerData = new TriggerData();
        triggerData.setActivationTime(DateUtils.addYears(new Date(), 20));// Twenty Years From Now
        triggerData.setDaysOfWeek(Collections.singletonList(DayOfWeek.MONDAY));
        triggerData.setWeekInterval(Integer.valueOf(2));
        final Map<String, Long> products = new HashMap<String, Long>();
        products.put(PRODUCT_A, Long.valueOf(1));
        code = scheduleOrder(userID, products, createUsAddressData(), purchaseOrderNumber,
                MitreTestConstants.STANDARD_COSTCENTER, null, triggerData).getJobCode();
        if (code != null) {
            this.orderFacade.cancelReplenishment(code, userID);
        }

    } catch (final Exception e) {
        LOG.error(e.getMessage(), e);
    }
    return code;
}

From source file:com.jnj.b2b.test.orders.B2BAcceleratorTestOrderData.java

/**
 * Create scheduled order to commence 20 years hence and cancel
 *//*from w w  w  . j a v  a 2  s . c om*/
protected String placeReplenishmentOrderInCancelledState(final String userID,
        final String purchaseOrderNumber) {
    String code = null;
    try {
        final TriggerData triggerData = new TriggerData();
        triggerData.setActivationTime(DateUtils.addYears(new Date(), 20));// Twenty Years From Now
        triggerData.setDaysOfWeek(Collections.singletonList(DayOfWeek.MONDAY));
        triggerData.setWeekInterval(Integer.valueOf(2));
        final Map<String, Long> products = new HashMap<String, Long>();
        products.put(PRODUCT_A, Long.valueOf(1));
        code = scheduleOrder(userID, products, createUsAddressData(), purchaseOrderNumber,
                Jnjb2bTestConstants.STANDARD_COSTCENTER, null, triggerData).getJobCode();
        if (code != null) {
            this.orderFacade.cancelReplenishment(code, userID);
        }

    } catch (final Exception e) {
        LOG.error(e.getMessage(), e);
    }
    return code;
}

From source file:com.octanner.test.orders.B2BAcceleratorTestOrderData.java

/**
 * Create scheduled order to commence 20 years hence and cancel
 *//*from  www  . java2s. c o m*/
protected String placeReplenishmentOrderInCancelledState(final String userID,
        final String purchaseOrderNumber) {
    String code = null;
    try {
        final TriggerData triggerData = new TriggerData();
        triggerData.setActivationTime(DateUtils.addYears(new Date(), 20));// Twenty Years From Now
        triggerData.setDaysOfWeek(Collections.singletonList(DayOfWeek.MONDAY));
        triggerData.setWeekInterval(Integer.valueOf(2));
        final Map<String, Long> products = new HashMap<String, Long>();
        products.put(PRODUCT_A, Long.valueOf(1));
        code = scheduleOrder(userID, products, createUsAddressData(), purchaseOrderNumber,
                OctannerTestConstants.STANDARD_COSTCENTER, null, triggerData).getJobCode();
        if (code != null) {
            this.orderFacade.cancelReplenishment(code, userID);
        }

    } catch (final Exception e) {
        LOG.error(e.getMessage(), e);
    }
    return code;
}

From source file:gov.nih.nci.firebird.test.ScalabilityDataSetLoader.java

private void loadTestUsers() {
    DataSetBuilder builder = new DataSetBuilder(dataLoader, gridResources);
    List<FirebirdUser> investigators = Lists.newArrayList();
    for (InvestigatorLogin login : InvestigatorLogin.values()) {
        FirebirdUser investigator = builder.createInvestigatorWithCompleteProfile().withLogin(login).get();
        investigators.add(investigator);
        System.out.println(investigator.getPerson().getFirstName() + " "
                + investigator.getPerson().getLastName() + " - " + investigator.getPerson().getEmail());
        for (OrganizationAssociation association : investigator.getInvestigatorRole().getProfile()
                .getOrganizationAssociations(OrganizationRoleType.CLINICAL_LABORATORY)) {
            ClinicalLaboratory lab = (ClinicalLaboratory) association.getOrganizationRole();
            LaboratoryCertificate cert = new LaboratoryCertificate(LaboratoryCertificateType.CAP);
            cert.setEffectiveDate(DateUtils.addYears(new Date(), -1));
            cert.setExpirationDate(DateUtils.addYears(new Date(), 1));
            cert.setCertificateFile(FirebirdFileFactory.getInstance().create());
            lab.addCertificate(cert);//from w  w  w  .j a va 2 s . c om
        }
    }

    testInvestigators = Lists.newArrayList(Lists.transform(investigators, new Function<FirebirdUser, Person>() {
        public Person apply(FirebirdUser user) {
            return user.getPerson();
        }
    }));

    for (CoordinatorLogin login : CoordinatorLogin.values()) {
        builder.createCoordinator().withLogin(login).withApprovedMangedInvestigator(investigators.remove(0));
    }
    builder.createSponsor();
    builder.build();
}

From source file:mitm.common.security.certificate.GenerateTestCA.java

private void generateRoot() throws Exception {
    X509CertificateBuilder certificateBuilder = securityFactory.createX509CertificateBuilder();

    String encodedPrivateKey = "308204bf020100300d06092a864886f70d0101010500048204a9308204a5"
            + "0201000282010100b7c0b5ac2250390fe9da9b800bdb0a1b7f21614d1e7c"
            + "5db67438a9d1f793c0cf0403a3523981f17885e145dbc0e4c927a184c024"
            + "6e7a79ae29f7ad4e1a36db1db567c793547b96a8275e93d37ad17006ca51"
            + "6f3ed4bfbff9883e2a351d8c5c76a24502344e8711e76843b3ba05f7a551"
            + "5287dba46b05033c7756b531512034845fc7ae350ebc720ed83e7df7ebd8"
            + "ade16b0d961c15277fd5802b724c3d9392a7e99d2d06bf55b5d2516152b1"
            + "d9c249561e3887f075e2bebe8e331cdc3fe5de60af36285e514b14163b34"
            + "af15e6bb48e6b232366f05d73ad261714854833305ba06f1430d5b0c8383"
            + "7c49c9408c8e4d674b9a9494a6b0dc66e0b4d2107d78f26f020301000102"
            + "82010100a857d3d8bca2f47420d1d74e6b0e2467668425496ad9935d5982"
            + "a40a29a062af05c573761c1b7126f2b89cb0a43ab61329c59de68294902f"
            + "c0611994092e22764840a8b5d05b5d7df67b8e40dc2f4e4bda44daff1c18"
            + "03ffcf12ecc636a8e5f905d6e51b18aa63fbb628f85a3fa74efc7ef8da7f"
            + "fa4fe054201cfee90ca2cd98be5ab0de6f631ac574433573a05f797a6c67"
            + "f5f2ebac8abe4acb64ea926971ec6055cd3fffee636146199932f6868fbe"
            + "e39eab7e93c97c930bc8a92c75714459c74d0dc44d6a33660aec06735fa1"
            + "65d18b3511e28a225b513865c881ceb7b968379119a54e4f92c37abfb110"
            + "f760a0e3bc1b6d57141a20877dbd46819686f4f902818100e9188525d800"
            + "37f73d4f3d90a330911820228c29f80a3a63fddb09df82766d6cfdb46bdd"
            + "d163b780246edda6a4e2ec5c65453740e6cd191702afc2178b13123031ae"
            + "fd384383825d8fa60024f9b78d9c9ff1bf6f53e49528e1aba515a91f8066"
            + "54cd9488092a8f730133340dcc402d0b2cea149a3a6fdb1702f1890462a8"
            + "8f6d02818100c9cef9be785397ffbda7df90d7e6bc1d5a607950c4323114"
            + "9636e0b6c0a5ebc281fd0027463cc858fb94f8084baa0f93f1f33f18c40d"
            + "8a47666b7190efff38f869229b8e84eea8fcd559b2349873d96e187b9933"
            + "35ae63034ec926c341eaede9ac696c4b6029969fbeb8194c9f2b44e2c831"
            + "bb7c3a07c1dd5cadbf81f9deb3cb02818073e7e96d63f6d7dd6cf3161df1"
            + "c7989e727c3b4e333482cc6dd2991a36f9447849bf895387671a3bf1e1de"
            + "fd9a47ec58155351a24821fc33e0f61c81307a8f34bfbfcfd2466002571b"
            + "b2e3a77f34b28a0b4e5e6eb13c9c9ef37832628ef2471a9b588e5f068fcf"
            + "3cd47fed865ee61a7fd019a59cfb29dbbb998f191ec1202811028181008e"
            + "753c1937a992f7e632b5fff2589fdc7caaf3988f16fb4c94096331bee6a1"
            + "79a9f725ff93765edb69a52c3df6e3b2a1763f86fffd8dad5a5fb362f4b4"
            + "664f1a146568b7ffa0d5cbbcf3d7778752e85eee8b79870bd2f174294e97"
            + "bd682fe608793be6458339786985e14182b42d803032afe0b07dea71f0c8"
            + "76a264a7358d6702818100b2a67f02d933b860a2675f616a8f163eea3ef9"
            + "d23bc29416fe8b02582635a56b3278af0d98a4a8d7367c1bf21cf06841b8"
            + "f5e7f53e08062d90355aa90c4ff4e07d3eb2a5d356a5b4617e2ff114db1c"
            + "3c429ffaa552264a670b24b12b372558997b8f1fbd6df41efac697c5c9f3"
            + "2571eef344416eb642818b3886a16ec45381a3";

    String encodedPublicKey = "30820122300d06092a864886f70d01010105000382010f003082010a0282"
            + "010100b7c0b5ac2250390fe9da9b800bdb0a1b7f21614d1e7c5db67438a9"
            + "d1f793c0cf0403a3523981f17885e145dbc0e4c927a184c0246e7a79ae29"
            + "f7ad4e1a36db1db567c793547b96a8275e93d37ad17006ca516f3ed4bfbf"
            + "f9883e2a351d8c5c76a24502344e8711e76843b3ba05f7a5515287dba46b"
            + "05033c7756b531512034845fc7ae350ebc720ed83e7df7ebd8ade16b0d96"
            + "1c15277fd5802b724c3d9392a7e99d2d06bf55b5d2516152b1d9c249561e"
            + "3887f075e2bebe8e331cdc3fe5de60af36285e514b14163b34af15e6bb48"
            + "e6b232366f05d73ad261714854833305ba06f1430d5b0c83837c49c9408c"
            + "8e4d674b9a9494a6b0dc66e0b4d2107d78f26f0203010001";

    PrivateKey privateKey = decodePrivateKey(encodedPrivateKey);
    PublicKey publicKey = decodePublicKey(encodedPublicKey);

    X500PrincipalBuilder issuerBuilder = new X500PrincipalBuilder();

    String email = "root@example.com";

    issuerBuilder.setCommonName("MITM Test Root");
    issuerBuilder.setCountryCode("NL");
    issuerBuilder.setEmail(email);// ww w  .  ja  v  a  2s. co  m
    issuerBuilder.setLocality("Amsterdam");
    issuerBuilder.setState("NH");

    AltNamesBuilder altNamesBuider = new AltNamesBuilder();

    altNamesBuider.setRFC822Names(email);

    X500Principal issuer = issuerBuilder.buildPrincipal();
    GeneralNames altNames = altNamesBuider.buildAltNames();

    // use TreeSet because we want a deterministic certificate (ie. hash should not change)
    Set<KeyUsageType> keyUsage = new TreeSet<KeyUsageType>();

    keyUsage.add(KeyUsageType.KEYCERTSIGN);
    keyUsage.add(KeyUsageType.CRLSIGN);

    Set<ExtendedKeyUsageType> extendedKeyUsage = new TreeSet<ExtendedKeyUsageType>();

    extendedKeyUsage.add(ExtendedKeyUsageType.EMAILPROTECTION);
    extendedKeyUsage.add(ExtendedKeyUsageType.OCSPSIGNING);

    BigInteger serialNumber = new BigInteger("115fcac409fb2022b7d06920a00fe42", 16);

    Date now = TestUtils.parseDate("16-Nov-2007 07:38:35 GMT");

    certificateBuilder.setSubject(issuer);
    certificateBuilder.setIssuer(issuer);
    certificateBuilder.setAltNames(altNames, true);
    certificateBuilder.setKeyUsage(keyUsage, true);
    certificateBuilder.setExtendedKeyUsage(extendedKeyUsage, false);
    certificateBuilder.setNotBefore(DateUtils.addDays(now, -20));
    certificateBuilder.setNotAfter(DateUtils.addYears(now, 20));
    certificateBuilder.setPublicKey(publicKey);
    certificateBuilder.setSerialNumber(serialNumber);
    certificateBuilder.setSignatureAlgorithm("SHA1WithRSAEncryption");
    certificateBuilder.setIsCA(true, true);
    certificateBuilder.addSubjectKeyIdentifier(true);

    // generate self signed certificate
    rootCertificate = certificateBuilder.generateCertificate(privateKey, null);

    assertNotNull(rootCertificate);

    Certificate[] chain = new Certificate[] { rootCertificate };

    keyStore.setKeyEntry("root", privateKey, null, chain);

    rootPrivateKey = privateKey;
}

From source file:ch.puzzle.itc.mobiliar.business.generator.control.extracted.ResourceDependencyResolverServiceTest.java

@Test
public void testReleaseEntityComparator() {
    ReleaseComparator comparator = new ReleaseComparator();

    //release today
    ReleaseEntity currentRelease = new ReleaseEntity();
    currentRelease.setInstallationInProductionAt(new Date());

    //release in a year
    ReleaseEntity laterRelease = new ReleaseEntity();
    laterRelease.setInstallationInProductionAt(DateUtils.addYears(new Date(), 1));

    Assert.assertEquals(-1, comparator.compare(currentRelease, laterRelease));
}