Search in sources :

Example 1 with ValidationException

use of net.fortuna.ical4j.validate.ValidationException in project fineract by apache.

the class CalendarUtils method getICalRecur.

public static Recur getICalRecur(final String recurringRule) {
    // Construct RRule
    try {
        final RRule rrule = new RRule(recurringRule);
        rrule.validate();
        final Recur recur = rrule.getRecur();
        return recur;
    } catch (final ParseException e) {
        // TODO Auto-generated catch block
        LOG.error("Problem occurred in getICalRecur function", e);
    } catch (final ValidationException e) {
        // TODO Auto-generated catch block
        LOG.error("Problem occurred in getICalRecur function", e);
    }
    return null;
}
Also used : ValidationException(net.fortuna.ical4j.validate.ValidationException) RRule(net.fortuna.ical4j.model.property.RRule) ParseException(java.text.ParseException) Recur(net.fortuna.ical4j.model.Recur)

Example 2 with ValidationException

use of net.fortuna.ical4j.validate.ValidationException in project ical4j by ical4j.

the class AbstractPropertyTest method assertValidationError.

/**
 * @param property
 */
protected void assertValidationError(final Property property) {
    try {
        ValidationResult result = property.validate();
        assertTrue(result.hasErrors());
    } catch (ValidationException ve) {
        LOG.debug("Exception caught", ve);
        return;
    }
}
Also used : ValidationException(net.fortuna.ical4j.validate.ValidationException) ValidationResult(net.fortuna.ical4j.validate.ValidationResult)

Example 3 with ValidationException

use of net.fortuna.ical4j.validate.ValidationException in project ical4j by ical4j.

the class ComponentTest method suite.

/**
 * @return
 */
@SuppressWarnings("serial")
public static TestSuite suite() throws ValidationException, ParseException, IOException, URISyntaxException, ParserException {
    TestSuite suite = new TestSuite();
    Component component = new Component("test") {

        @Override
        public ValidationResult validate(boolean recurse) throws ValidationException {
            return null;
        }
    };
    suite.addTest(new ComponentTest("testCalculateRecurrenceSet", component, new Period(new DateTime(), java.time.Duration.ofDays(1)), new PeriodList()));
    component = new Component("test") {

        @Override
        public ValidationResult validate(boolean recurse) throws ValidationException {
            return null;
        }
    };
    // 10am-12pm for 7 days..
    component.getProperties().add(new DtStart("20080601T100000Z"));
    component.getProperties().add(new DtEnd("20080601T120000Z"));
    Recur recur = new Recur.Builder().frequency(Recur.Frequency.DAILY).count(7).build();
    component.getProperties().add(new RRule(recur));
    PeriodList expectedPeriods = new PeriodList();
    expectedPeriods.add(new Period("20080601T100000Z/PT2H"));
    expectedPeriods.add(new Period("20080602T100000Z/PT2H"));
    expectedPeriods.add(new Period("20080603T100000Z/PT2H"));
    expectedPeriods.add(new Period("20080604T100000Z/PT2H"));
    expectedPeriods.add(new Period("20080605T100000Z/PT2H"));
    expectedPeriods.add(new Period("20080606T100000Z/PT2H"));
    expectedPeriods.add(new Period("20080607T100000Z/PT2H"));
    suite.addTest(new ComponentTest("testCalculateRecurrenceSet", component, new Period(new DateTime("20080601T000000Z"), java.time.Duration.ofDays(7)), expectedPeriods));
    component = new Component("test") {

        @Override
        public ValidationResult validate(boolean recurse) throws ValidationException {
            return null;
        }
    };
    // weekly for 5 instances using DATE format and due date.
    component.getProperties().add(new DtStart(new Date("20080601")));
    component.getProperties().add(new Due(new Date("20080602")));
    recur = new Recur.Builder().frequency(Recur.Frequency.WEEKLY).count(5).build();
    component.getProperties().add(new RRule(recur));
    expectedPeriods = new PeriodList();
    expectedPeriods.add(new Period("20080601T000000Z/P1D"));
    expectedPeriods.add(new Period("20080608T000000Z/P1D"));
    expectedPeriods.add(new Period("20080615T000000Z/P1D"));
    expectedPeriods.add(new Period("20080622T000000Z/P1D"));
    expectedPeriods.add(new Period("20080629T000000Z/P1D"));
    suite.addTest(new ComponentTest("testCalculateRecurrenceSet", component, new Period(new DateTime("20080601T000000Z"), java.time.Period.ofWeeks(6)), expectedPeriods));
    return suite;
}
Also used : ValidationException(net.fortuna.ical4j.validate.ValidationException) RRule(net.fortuna.ical4j.model.property.RRule) ValidationResult(net.fortuna.ical4j.validate.ValidationResult) DtStart(net.fortuna.ical4j.model.property.DtStart) TestSuite(junit.framework.TestSuite) Due(net.fortuna.ical4j.model.property.Due) CalendarComponent(net.fortuna.ical4j.model.component.CalendarComponent) DtEnd(net.fortuna.ical4j.model.property.DtEnd)

Example 4 with ValidationException

use of net.fortuna.ical4j.validate.ValidationException in project ical4j by ical4j.

the class CalendarBuilderTest method testBuildInvalid.

/**
 * @throws IOException
 * @throws ParserException
 */
public void testBuildInvalid() throws IOException {
    try {
        Calendar calendar = new CalendarBuilder().build(fin);
        ValidationResult result = calendar.validate();
        assertTrue(result.hasErrors());
    // fail("Should throw ParserException or ValidationException");
    } catch (ValidationException | ParserException e) {
        log.trace("Caught exception: [" + filename + "," + e.getMessage() + "]");
    }
}
Also used : ValidationException(net.fortuna.ical4j.validate.ValidationException) Calendar(net.fortuna.ical4j.model.Calendar) ValidationResult(net.fortuna.ical4j.validate.ValidationResult)

Example 5 with ValidationException

use of net.fortuna.ical4j.validate.ValidationException in project ical4j by ical4j.

the class VTimeZoneValidator method validate.

@Override
public ValidationResult validate(VTimeZone target) throws ValidationException {
    ValidationResult result = ComponentValidator.VTIMEZONE.validate(target);
    /*
         * ; one of 'standardc' or 'daylightc' MUST occur ..; and each MAY occur more than once. standardc / daylightc /
         */
    if (target.getObservances().getComponent(Observance.STANDARD) == null && target.getObservances().getComponent(Observance.DAYLIGHT) == null) {
        throw new ValidationException("Sub-components [" + Observance.STANDARD + "," + Observance.DAYLIGHT + "] must be specified at least once");
    }
    target.getObservances().forEach(ComponentValidator.OBSERVANCE_ITIP::validate);
    return result;
}
Also used : ValidationException(net.fortuna.ical4j.validate.ValidationException) ValidationResult(net.fortuna.ical4j.validate.ValidationResult)

Aggregations

ValidationException (net.fortuna.ical4j.validate.ValidationException)20 ValidationResult (net.fortuna.ical4j.validate.ValidationResult)9 IOException (java.io.IOException)5 ParseException (java.text.ParseException)5 Calendar (net.fortuna.ical4j.model.Calendar)5 RRule (net.fortuna.ical4j.model.property.RRule)5 InputStream (java.io.InputStream)2 URISyntaxException (java.net.URISyntaxException)2 TestSuite (junit.framework.TestSuite)2 Recur (net.fortuna.ical4j.model.Recur)2 WeekDay (net.fortuna.ical4j.model.WeekDay)2 CalendarComponent (net.fortuna.ical4j.model.component.CalendarComponent)2 PlatformDataIntegrityException (org.apache.fineract.infrastructure.core.exception.PlatformDataIntegrityException)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 FileInputStream (java.io.FileInputStream)1 URL (java.net.URL)1 LocalDate (java.time.LocalDate)1 DateTimeFormatter (java.time.format.DateTimeFormatter)1 ArrayList (java.util.ArrayList)1 Calendar (java.util.Calendar)1