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

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

Introduction

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

Prototype

public static Date addDays(Date date, int amount) 

Source Link

Document

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

Usage

From source file:gov.utah.dts.det.ccl.service.impl.FacilityServiceImpl.java

@Override
public Facility deactivateFacility(Facility facility, PickListValue reason, Date effectiveDate)
        throws CclServiceException {
    if (facility != null && facility.getStatus() != FacilityStatus.INACTIVE) {
        if (facility.getStatus() != FacilityStatus.IN_PROCESS && reason == null) {
            throw new IllegalArgumentException("Reason must not be null");
        }/*from www.  j a  va  2 s  .  c o  m*/

        if (facility.getStatus() == FacilityStatus.IN_PROCESS) {
            // delete all in process licenses
            for (Iterator<License> itr = facility.getLicenses().iterator(); itr.hasNext();) {
                License lic = itr.next();
                if (lic.getStatus() != null
                        && lic.getStatus().getValue().equalsIgnoreCase(LICENSE_STATUS_IN_PROCESS)) {
                    itr.remove();
                }
            }
            facility.setStatus(FacilityStatus.INACTIVE);
            facility = facilityDao.save(facility);
        } else {
            Date now = new Date();

            Date eDate = effectiveDate == null ? now : effectiveDate;

            // make sure the deactivation can't happen too far in the past
            if (eDate.compareTo(DateUtils.addDays(now, -60)) < 0) {
                throw new CclServiceException("Unable to deactivate facility",
                        "error.facility.deactivate.past-retroactive-deadline");
            }

            facility = performDeactivation(facility, reason, eDate);
        }
    }

    return facility;
}

From source file:cn.vlabs.umt.ui.servlet.login.LoginMethod.java

private void sendTicket(User up, Map<String, String> siteInfo, HttpServletRequest request,
        HttpServletResponse response) throws ServletException, IOException {
    boolean isVersion7 = "7".equals(request.getParameter(Attributes.UMT_VERSION));
    UMTCredential cred = (UMTCredential) factory.getBean("UMTCredUtil");
    SignedEnvelope env = null;//from w  w  w. j  a  v  a2  s  .  co  m
    if (isVersion7) {
        UserCredentialEnvelopeV7 userCredential = new UserCredentialEnvelopeV7();
        userCredential.setAuthAppId(cred.getUMTId());
        userCredential.setUser(user2UserPrincipalV7(up));
        Date tommrow = DateUtils.addDays(new Date(), 1);
        userCredential.setValidTime(DateFormatUtils.format(tommrow, "yyyy-MM-dd hh:mm:ss"));
        env = new SignedEnvelope(userCredential.toXML(), cred.getUMTId());
    } else {
        UserCredentialEnvelope userCredential = new UserCredentialEnvelope();
        userCredential.setAuthAppId(cred.getUMTId());
        userCredential.setUser(up == null ? null : up.getUserPrincipal());
        Date tommrow = DateUtils.addDays(new Date(), 1);
        userCredential.setValidTime(DateFormatUtils.format(tommrow, "yyyy-MM-dd hh:mm:ss"));
        env = new SignedEnvelope(userCredential.toXML(), cred.getUMTId());
    }
    env.genSignature(cred.getUMTKey());
    request.setAttribute("signedCredential", Base64Util.encodeBase64(env.toXML()));

    SessionService seService = (SessionService) factory.getBean("SessionService");
    String loginByDeputyResult = siteInfo.get(Attributes.APP_DEPUTY_LOGIN_RESULT_KEY);
    if (loginByDeputyResult != null) {
        request.setAttribute(Attributes.APP_DEPUTY_LOGIN_RESULT_KEY, loginByDeputyResult);
    }
    if (loginByDeputyResult == null || "success".equals(loginByDeputyResult)) {
        seService.login(siteInfo.get(Attributes.APP_NAME), up.getCstnetId(), RequestUtil.getRemoteIP(request),
                siteInfo.get(Attributes.LOGOUT_URL), "JSP", siteInfo.get(Attributes.SESSION_ID_KEY));
    }
    request.setAttribute(Attributes.RETURN_URL, siteInfo.get(Attributes.RETURN_URL));
    ServiceFactory.getAppAccessService(request).createAppAccess(up == null ? -1 : up.getId(),
            siteInfo.get(Attributes.APP_NAME));
    doForward("/post.jsp", request, response);
}

From source file:gov.nih.nci.firebird.web.action.investigator.registration.common.ReviewRegistrationFormActionProcessorTest.java

private LaboratoryCertificate getLaboratoryCertificate() {
    Date effectiveDate = DateUtils.addDays(new Date(), -5);
    Date expirationDate = new Date();
    LaboratoryCertificate laboratoryCertificate = new LaboratoryCertificate();
    laboratoryCertificate.setType(LaboratoryCertificateType.CAP);
    laboratoryCertificate.setEffectiveDate(effectiveDate);
    laboratoryCertificate.setExpirationDate(expirationDate);
    laboratoryCertificate.setId(1L);//from ww  w.ja  va 2 s  . c  om
    return laboratoryCertificate;
}

From source file:gov.nih.nci.firebird.data.InvestigatorProfileHibernateTest.java

@Test
public void testGetAnnualRegistrationsAwaitingRenewal() {
    AnnualRegistration registrationWithDueDate = addAnnualRegistration(profile,
            DateUtils.addDays(new Date(), 60 - 1));
    addAnnualRegistration(profile, null); // without due date
    AnnualRegistration registrationAlreadySubmitted = addAnnualRegistration(profile,
            DateUtils.addDays(new Date(), 60 - 1));
    registrationAlreadySubmitted.setStatus(RegistrationStatus.SUBMITTED);

    assertEquals(Sets.newHashSet(registrationWithDueDate), profile.getAnnualRegistrationsAwaitingRenewal());
}

From source file:de.iteratec.iteraplan.businesslogic.service.SvgExportServiceImplTest.java

/**
 * The ISRs contained have an Id, an IS and a RuntimePeriod.
 * /*from   w ww  . j ava2s .  c om*/
 * @return list of ISRs for testing purposes
 */
private List<InformationSystemRelease> getTestIsrList() {
    InformationSystemRelease isr1 = mtdf.getInformationSystemReleaseTestData();
    InformationSystemRelease isr2 = mtdf.getInformationSystemReleaseTestData();
    isr1.setId(Integer.valueOf(50));
    isr1.setInformationSystem(mtdf.getInformationSystem());
    isr2.setId(Integer.valueOf(51));
    isr2.setInformationSystem(mtdf.getInformationSystem());

    Date now = new Date();
    Date startDate = DateUtils.addDays(now, -5);
    Date endDate = DateUtils.addDays(now, 5);
    isr1.setRuntimePeriod(new RuntimePeriod(startDate, endDate));
    isr2.setRuntimePeriod(new RuntimePeriod(startDate, endDate));

    return Lists.newArrayList(isr1, isr2);
}

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

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

    String encodedPrivateKey = "30820276020100300d06092a864886f70d0101010500048202603082025c"
            + "0201000281810096383c89ad7b3c3be9dfcb24c1ba2b19f681847eaf862c"
            + "eec3cb2daf20da3f68f30221b46444c259228cc84f35095af19d2496a486"
            + "b4e818ce17241dd792a6c6ad07f8601c728f71f8016e1dbc5905fade3ecf"
            + "37b6374f4668bb3a5de16059125cea11ef3bd712a375dd33894670faa18b"
            + "8c733227a530ec569fcb5ade02523d020301000102818030202c24df934f"
            + "a4d234845c6e443a72c2ea938c12a7a5d5889c9b32341037a863d2170237"
            + "ed5f66370f6b4d14ecbe5a11c21b10f2a71a8477e22a0bf578623d5e961d"
            + "41151118d6114296baa55c479a33de26ef872f61eb59388bddb43c970614"
            + "52983edf79e71def89879820f06667b237be04b1fb18eaa203fb59d82ebc"
            + "71024100c9b7820310a62a3815564519a038bcfd99965ed9adf494214fca"
            + "d0d08019b9ba6821bcfc9faf448f1650e9e7aeba6b9ce3e7d6f9449c1897"
            + "d7dd7d0f4e8c39fb024100bea50896dc44c9cd710611e229fd7fe01c06f8"
            + "db7ea4428c99b243ba26937eaedfd9fae5eed02e292a8a4c7092320e29dc"
            + "143223b85cfeb43efbb1603ebce72702407bc7f82819575e20fc36ec4045"
            + "698bcfb327eb1c78fad4cb7c4360d0114bb805035170bf34de409bed7dc9"
            + "8b3a557b23d356b93c4d35dc81911d81589b42c17102406eb7cfc6358469"
            + "a2bb8a27e6ae364006baa03df4d396b7e389fb62a4007556745f22ec388f"
            + "3a2e24d044e361d935e2cde2b783eb04ce5549feee13b46e9b2caf024100"
            + "a8c35546c2241ce9b90b14c667d2b83512a6ad3b50f1511696c3eb7f608b"
            + "c292bad19c4fe11b466a045ebfdb92f371199369e22e5ce6a16578c9a25c" + "7b67e997";

    String encodedPublicKey = "30819f300d06092a864886f70d010101050003818d003081890281810096"
            + "383c89ad7b3c3be9dfcb24c1ba2b19f681847eaf862ceec3cb2daf20da3f"
            + "68f30221b46444c259228cc84f35095af19d2496a486b4e818ce17241dd7"
            + "92a6c6ad07f8601c728f71f8016e1dbc5905fade3ecf37b6374f4668bb3a"
            + "5de16059125cea11ef3bd712a375dd33894670faa18b8c733227a530ec56" + "9fcb5ade02523d0203010001";

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

    X500PrincipalBuilder subjectBuilder = new X500PrincipalBuilder();

    String email = "test@example.com";

    subjectBuilder.setCommonName("Valid certificate");
    subjectBuilder.setEmail(email);/*w w  w.  j av  a  2s. c om*/
    subjectBuilder.setCountryCode("NL");
    subjectBuilder.setLocality("Amsterdam");
    subjectBuilder.setState("NH");

    AltNamesBuilder altNamesBuider = new AltNamesBuilder();
    altNamesBuider.setRFC822Names(email);

    X500Principal subject = subjectBuilder.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.DIGITALSIGNATURE);
    keyUsage.add(KeyUsageType.NONREPUDIATION);

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

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

    BigInteger serialNumber = new BigInteger("1178c336c7b51cadd4ccecdd14daf22", 16);

    Date now = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM, Locale.UK)
            .parse("21-Nov-2007 10:38:35");

    certificateBuilder.setSubject(subject);
    certificateBuilder.setAltNames(altNames, true);
    certificateBuilder.setKeyUsage(keyUsage, true);
    certificateBuilder.setExtendedKeyUsage(extendedKeyUsage, true /* critical */);
    certificateBuilder.setNotBefore(DateUtils.addDays(now, -20));
    certificateBuilder.setNotAfter(DateUtils.addYears(now, 20));
    certificateBuilder.setPublicKey(publicKey);
    certificateBuilder.setSerialNumber(serialNumber);
    certificateBuilder.setSignatureAlgorithm("SHA1WithRSAEncryption");
    certificateBuilder.addSubjectKeyIdentifier(true);

    X509Certificate certificate = certificateBuilder.generateCertificate(caPrivateKey, caCertificate);

    assertNotNull(certificate);

    certificates.add(certificate);

    Certificate[] chain = new Certificate[] { certificate, caCertificate, rootCertificate };

    keyStore.setKeyEntry("KeyUsageNotForEncryption", privateKey, null, chain);
}

From source file:gov.nih.nci.firebird.service.protocol.ProtocolServiceBeanTest.java

private Protocol peformReactivatePacketTest(InvitationStatus investigatorStatus,
        InvitationStatus subinvestigatorStatus) {
    String comments = "These are the comments of failure";
    Protocol protocol = ProtocolFactory.getInstance().createWithForms();
    InvestigatorRegistration registration = RegistrationFactory.getInstance()
            .createInvestigatorRegistration(InvestigatorProfileFactory.getInstance().create(), protocol);
    registration.getInvitation().setInvitationStatus(investigatorStatus);
    registration.getInvitation().setInvitationChangeDate(DateUtils.addDays(new Date(), -10));
    SubInvestigatorRegistration subRegistration = RegistrationFactory.getInstance()
            .createSubinvestigatorRegistration(registration);
    subRegistration.getInvitation().setInvitationStatus(subinvestigatorStatus);
    subRegistration.getInvitation().setInvitationChangeDate(DateUtils.addDays(new Date(), -10));
    bean.deactivatePacket(registration, comments);
    bean.reactivatePacket(registration, ValueGenerator.getUniqueString());
    verify(mockSponsorNotificationService, times(2))
            .notifyOfReactivation(any(AbstractProtocolRegistration.class), anyString());
    return protocol;
}

From source file:gov.nih.nci.firebird.selenium2.tests.investigator.annual.registration.SubmitAnnualRegistrationForReviewTest.java

@Test
public void testSubmission_AfterRenewalWindow() throws IOException {
    setUpDataSet(true);/*from www .  j  a  v a2  s.  c  o  m*/
    renewal.setDueDate(DateUtils.addDays(new Date(), -50));
    dataSet.update(renewal);
    submitRegistration(navigateToOverviewTab());
    checkForRenewalDate(false);
}

From source file:gov.nih.nci.firebird.service.protocol.ProtocolServiceBeanTest.java

@Test
public void testReactivatePacket_NoResponse() {
    Protocol protocol = peformReactivatePacketTest(InvitationStatus.NO_RESPONSE, InvitationStatus.NOT_INVITED);
    InvestigatorRegistration investigatorRegistration = Iterables
            .getOnlyElement(protocol.getCurrentInvestigatorRegistrations());
    SubInvestigatorRegistration subinvestigatorRegistration = Iterables
            .getOnlyElement(protocol.getSubinvestigatorRegistrations());
    assertEquals(RegistrationStatus.NOT_STARTED, investigatorRegistration.getStatus());
    assertEquals(InvitationStatus.NO_RESPONSE, investigatorRegistration.getInvitation().getInvitationStatus());
    assertEquals(DateUtils.truncate(DateUtils.addDays(new Date(), -10), Calendar.DATE), DateUtils
            .truncate(investigatorRegistration.getInvitation().getInvitationChangeDate(), Calendar.DATE));
    checkRegistrationFormsForStatus(investigatorRegistration, NOT_STARTED);
    assertEquals(RegistrationStatus.NOT_STARTED, subinvestigatorRegistration.getStatus());
    assertEquals(InvitationStatus.NOT_INVITED,
            subinvestigatorRegistration.getInvitation().getInvitationStatus());
    assertEquals(DateUtils.truncate(DateUtils.addDays(new Date(), -10), Calendar.DATE), DateUtils
            .truncate(subinvestigatorRegistration.getInvitation().getInvitationChangeDate(), Calendar.DATE));
    checkRegistrationFormsForStatus(subinvestigatorRegistration, NOT_STARTED);
}

From source file:com.haulmont.timesheets.gui.weeklytimesheets.SimpleWeeklyTimesheets.java

protected void updateDayColumnsCaptions() {
    for (Date current = firstDayOfWeek; current.getTime() <= lastDayOfWeek.getTime(); current = DateUtils
            .addDays(current, 1)) {//  w  w  w .j a v a 2  s . c  o  m
        DayOfWeek day = DayOfWeek.fromCalendarDay(DateTimeUtils.getCalendarDayOfWeek(current));
        String columnId = day.getId() + COLUMN_SUFFIX;
        weeklyTsTable.setColumnCaption(columnId, ComponentsHelper.getColumnCaption(day.getId(), current));
    }
}