Menu

What about warnings ?

2013-07-22
2013-07-31
  • Caruyer Perrine

    Caruyer Perrine - 2013-07-22

    Hello,

    Today the developper can get warnings like this :

        System.out.println("  ****** WARNINGS ******");
        List<String> warnings = ical.validate();
        for (String warning : warnings){
          System.out.println(warning);
        }
        System.out.println("  ****** FIN - WARNINGS ******");
    

    ** WARNINGS *
    [ICalendar > VEvent > VAlarm]: The trigger must specify which date field its duration is relative to.
    FIN - WARNINGS ***

    It's really interesting to debug when there is a problem with an iCal, but it's difficult to use it in the code.
    I thought about taking a Map instead of a List, and store warnings with a key like "METHOD", "VERSION", so that we can get it in the code to know if there is a problem or not with one property. The problem is for the properties that appear several times in an iCal...

    I leave you to consider the question, it was just an idea ;)

     
  • Michael Angstadt

    Thanks for the suggestion. I like the idea of organizing the validation warnings in some way. Do you think something like this would be more useful?

    :::java
    List<ValidationWarning> warnings = ical.validate();
    for (ValidationWarning warning : warnings){
      System.out.println("Property name: " + warning.getProperty().getClass().getSimpleName());
      System.out.println("Message(s): " + warning.getMessages());
    }
    
    class ValidationWarning{
      private ICalProperty property;
      private List<ICalComponent> parents;
      private List<String> messages;
    }
    
     

    Last edit: Michael Angstadt 2013-07-22
  • Caruyer Perrine

    Caruyer Perrine - 2013-07-26

    I think it is better, but this is not exactly what I had imagined ..
    I wish I could get the warnings directly related to property:

    Map <String, String> warnings = new HashMap <String, String> ();
    for (String warning: warnings.keySet ()) {
    System.out.println (warning + "->" + warnings.get (warning));
    }
    

    So that if I want to be shure that METHOD, for example, is correct, I test:

    if (warnings.containsKey ("METHOD")) {
        System.out.println ("Ooops!");
    }
    

    The problem is for properties that may be present in several locations in iCal. I have no immediate solution to this question ....

     
  • Michael Angstadt

    What about this?

    :::java
    ValidationWarnings warnings = ical.validate();
    List<String> methodWarnings = warnings.getByProperty(Method.class);
    if (!methodWarnings.isEmpty()){
      System.out.println ("Ooops!");
    }
    
     
  • Caruyer Perrine

    Caruyer Perrine - 2013-07-28

    Yes, better! :)
    But how can we do if we have several events in the same iCal file, to know in which event the problem is ?

     
  • Michael Angstadt

    Could do this:

    :::java
    ValidationWarnings warnings = ical.validate();
    List<WarningsGroup> methodWarnings = warnings.getByProperty(Method.class);
    if (!methodWarnings.isEmpty()){
      System.out.println ("Ooops!");
    }
    
    class WarningsGroup{
      private ICalProperty property;
      private List<ICalComponent> parents;
      private List<String> messages;
    }
    
     
  • Caruyer Perrine

    Caruyer Perrine - 2013-07-30

    Yes good !!
    I think it can useful :) But you do as you prefer :)

     
  • Michael Angstadt

    This functionality makes sense to have. Thanks for your input! Added in r208.

     

Anonymous
Anonymous

Add attachments
Cancel