robinrajasekaran / caldav4j

Automatically exported from code.google.com/p/caldav4j
0 stars 0 forks source link

Methods for finding calendars #3

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
It would be great to have an API in caldav4j to find calendars for specific
users.

I would like to add this functionnality but honestly, I don't know where to
add it.  Should we modify CalendarQuery.java for adding this support ?

Original issue reported on code.google.com by pascal.p...@gmail.com on 5 Nov 2007 at 9:09

GoogleCodeExporter commented 8 years ago
Hi Pascal,

how do you think to implement it? can you write a sample caldav-query?
Peace, R.

Original comment by robipo...@gmail.com on 25 Mar 2008 at 2:26

GoogleCodeExporter commented 8 years ago
Hi guys,

I also faced the same problem. 
For the while, I just loop on all the calendars for a time-range and look up 
for the
good SENT_BY...Very inefficient I know :(

Generate such a query would be great.

<?xml version="1.0" encoding="utf-8" ?>
   <C:calendar-query xmlns:C="urn:ietf:params:xml:ns:caldav">
     <D:prop xmlns:D="DAV:">
       <D:getetag/>
       <C:calendar-data/>
     </D:prop>
     <C:filter>
       <C:comp-filter name="VCALENDAR">
         <C:comp-filter name="VEVENT">
           <C:prop-filter name="SENT-BY">
             <C:text-match collation="i;ascii-casemap">
              mailto:lisa@example.com
             </C:text-match>
           </C:prop-filter>
         </C:comp-filter>
       </C:comp-filter>
     </C:filter>
   </C:calendar-query>

Original comment by cteaudaxis on 11 Aug 2009 at 8:45

GoogleCodeExporter commented 8 years ago
did you try with GenerateQuery ?

Original comment by robipo...@gmail.com on 17 Aug 2009 at 2:36

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
In fact, I made a mistake. In the above query, "SENT-BY" is not a Property, but 
a
Paramerter of "ORGANIZER". So the query should look like 

<?xml version="1.0" encoding="utf-8" ?>
   <C:calendar-query xmlns:C="urn:ietf:params:xml:ns:caldav">
     <D:prop xmlns:D="DAV:">
       <D:getetag/>
       <C:calendar-data/>
     </D:prop>
     <C:filter>
       <C:comp-filter name="VCALENDAR">
         <C:comp-filter name="VEVENT">
           <C:prop-filter name="ORGANIZER">
             <C:param-filter name="SENT-BY">
               <C:text-match collation="i;ascii-casemap">
                 mailto:lisa@example.com
               </C:text-match>
             </C:param-filter>
           </C:prop-filter>
         </C:comp-filter>
       </C:comp-filter>
     </C:filter>
   </C:calendar-query>

I tried to use GenerateQuery as advised, but there is no getter/setter into 
Class
ParamFilter for the variable "name"...Is it missing ? If I have this, I can 
create
the necessary "ParamFilter".

Original comment by cteaudaxis on 18 Aug 2009 at 10:15

GoogleCodeExporter commented 8 years ago
It seems it's missing. Can you create a test method ParamFilterTest too?

LetMeKnow+Peace,
R.

Original comment by robipo...@gmail.com on 24 Aug 2009 at 9:54

GoogleCodeExporter commented 8 years ago
I don't really know where/how to commit (what is my login ? cteaudaxis not 
working).

Nevertheless, after adding the getter and setter for name, this is the method I 
use,
that can be used as ParamFilterTest:

 /**
   * 
   * @param property The Property name to query (i.e: Property.ORGANIZER)
   * @param param The Parameter to query (i.e: Parameter.SENT-BY)
   * @param textToMatch (i.e: "mailto:lisa@caldav4j.org")
   * @return <p>A query matching a given text for the given Property or Parameter of
a VEVENT 
   * (With priority to the parameter if provided !)</p>
   */

protected CalendarQuery getQueryForPropertyAndParameter(String property, String
param, String textToMatch){
         CalendarQuery query  = null;
         try {
             //Generate a basic query
             GenerateQuery genQuery = new GenerateQuery();
             genQuery.setFilterComponent(Component.VEVENT);
             query  = genQuery.generateQuery();
             CompFilter vEventCompFilter = query.getCompFilter();

             //Create the Property Filter with text match to add
             PropFilter propFilter = new PropFilter("C");
             propFilter.setName(property);
             if(!StringUtils.isEmpty(param)){
                 ParamFilter paramFilter = new ParamFilter("C");
                 paramFilter.setName(param);
                 paramFilter.setTextMatch(new TextMatch("C", null, null, null, textToMatch));
                 propFilter.addParamFilter(paramFilter);
             }else{
                 //filter on property if parameter is empty
                 propFilter.setTextMatch(new TextMatch("C", null, null, null, textToMatch));
             }

             //Add the Property filter
             vEventCompFilter.addPropFilter(propFilter);
             query.setCompFilter(vEventCompFilter);

             //Print the query
             //System.out.println(GenerateQuery.printQuery(query));
         }
         catch (CalDAV4JException e) {
             log.error(e.getMessage());
         }

         return query;
     }

Original comment by cteaudaxis on 24 Aug 2009 at 12:24

GoogleCodeExporter commented 8 years ago
thx! I'll put something like that in the GenerateQuery test. 
The game is just add getter/setter and create ae ParamFilterTest like

public class ParamFilterTest {

... testSimpleConstructor() {
 ParamFilter p = new ParamFilter("C");
 p.validate();
 }

.. testSetter() {
 ParamFilter p = new ParamFilter("C");
 p.setName("newname");
 p.validate();

 }
}

if you like to join the project you should start with posting junit+patch to 
caldav4j 
list.

Original comment by robipo...@gmail.com on 24 Aug 2009 at 1:14