Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package org.unitedinternet.cosmo.model.filter;

public enum FilterEval {
FILTER_PARENT_NOTNULL,

INSTANCE_OF_NOTE_ITEM_FILTER,

INSTANCE_OF_CONTENT_ITEM_FILTER,

FILTER_DISPLAY_NAME_NOT_NULL,

FILTER_UID_NOT_NULL
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.util.HashMap;
import java.util.List;

import org.springframework.context.annotation.FilterType;
import org.unitedinternet.cosmo.model.CollectionItem;
import org.unitedinternet.cosmo.model.QName;

Expand Down Expand Up @@ -46,7 +47,27 @@ public class ItemFilter {

public ItemFilter() {
}


public FilterEval judgeItemFilter(ItemFilter filter){

if(filter.getParent()!=null)
return FilterEval.FILTER_PARENT_NOTNULL;

if(filter instanceof NoteItemFilter)
return FilterEval.INSTANCE_OF_NOTE_ITEM_FILTER;

if(filter instanceof ContentItemFilter)
return FilterEval.INSTANCE_OF_CONTENT_ITEM_FILTER;

if(filter.getDisplayName()!=null)
return FilterEval.FILTER_DISPLAY_NAME_NOT_NULL;

if(filter.getUid()!=null)
return FilterEval.FILTER_UID_NOT_NULL;

return null;
}

/**
* List of AttributeFilters. If there are multiple attribute filters,
* each filter must match for an item to match the ItemFilter.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -649,9 +649,7 @@ private Date icalDate(String original)
normalized = original.replace("Z", "GMT-00:00");
}
// 2002-10-10T00:00:00+05:00
else if (original.indexOf("GMT") == -1 &&
(original.charAt(original.length()-6) == '+' ||
original.charAt(original.length()-6) == '-')) {
else if (needsGmtConversion(original)) {
String tzId = "GMT" + original.substring(original.length()-6);
normalized = original.substring(0, original.length()-6) + tzId;
}
Expand All @@ -675,4 +673,16 @@ else if (original.indexOf("GMT") == -1 &&

return dt;
}

private boolean isPlusOrMinusAtPosition(String original, int position) {
return original.charAt(position) == '+' || original.charAt(position) == '-';
}

private boolean needsGmtConversion(String original) {
return !original.contains("GMT") && isPlusOrMinusAtPosition(original, original.length() - 6);
}
}




Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public CalendarFilterEvaluater() {}
* @throws UnsupportedQueryException if filter represents a query
* that the server does not support
*/
public boolean evaluate(Calendar calendar, CalendarFilter filter) {
public boolean evaluateCalendarFilter(Calendar calendar, CalendarFilter filter) {
ComponentFilter rootFilter = filter.getFilter();

// root filter must be "VCALENDAR"
Expand Down Expand Up @@ -100,7 +100,7 @@ public boolean evaluate(Calendar calendar, CalendarFilter filter) {
* @param filter The component filter.
* @return The result.
*/
private boolean evaluate(ComponentList<? extends Component> comps, ComponentFilter filter) {
private boolean evaluateComponentFilter(ComponentList<? extends Component> comps, ComponentFilter filter) {
// Evaluate component filter against a set of components.
// If any component matches, then evaluation succeeds.
// This is basically a big OR
Expand All @@ -121,7 +121,7 @@ private boolean evaluate(ComponentList<? extends Component> comps, ComponentFilt
* @param filter The property filter.
* @return The result.
*/
private boolean evaluate(ComponentList<? extends Component> comps, PropertyFilter filter) {
private boolean evaluatePropertyFilter(ComponentList<? extends Component> comps, PropertyFilter filter) {

// Evaluate property filter against a set of components.
// If any component matches, then evaluation succeeds.
Expand Down Expand Up @@ -180,13 +180,13 @@ private boolean evaluateComps(ComponentList<? extends Component> components, Com
}

for(Iterator<ComponentFilter> it = filter.getComponentFilters().iterator(); it.hasNext();) {
if(evaluate(comps, it.next())==false) {
if(evaluateComponentFilter(comps, it.next())==false) {
return false;
}
}

for(Iterator<PropertyFilter> it = filter.getPropFilters().iterator(); it.hasNext();) {
if(evaluate(comps, it.next())==false) {
if(evaluatePropertyFilter(comps, it.next())==false) {
return false;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public boolean filterQuery(ICalendarItem item, CalendarFilter filter) {

Calendar calendar = entityConverter.convertContent(item);
if(calendar!=null) {
return new CalendarFilterEvaluater().evaluate(calendar, filter);
return new CalendarFilterEvaluater().evaluateCalendarFilter(calendar, filter);
}
else {
return false;
Expand Down Expand Up @@ -249,79 +249,50 @@ protected void doFreeBusyQuery(PeriodList busyPeriods,
busyTentativePeriods, busyUnavailablePeriods);
}
}

/**
* Adds relevant periods.
* @param calendar The calendar.
* @param timezone The timezone.
* @param freeBusyRange
* @param busyPeriods
* @param busyTentativePeriods
* @param busyUnavailablePeriods
*/
protected void addBusyPeriods(Calendar calendar, TimeZone timezone,
Period freeBusyRange, PeriodList busyPeriods,
PeriodList busyTentativePeriods, PeriodList busyUnavailablePeriods) {

// Create list of instances within the specified time-range
InstanceList instances = new InstanceList();
instances.setUTC(true);
instances.setTimezone(timezone);

// Look at each VEVENT/VFREEBUSY component only
ComponentList<Component> overrides = new ComponentList<>();
for (Object comp: calendar.getComponents()) {
if (comp instanceof VEvent) {
VEvent vcomp = (VEvent) comp;
// See if this is the master instance
if (vcomp.getRecurrenceId() == null) {
instances.addComponent(vcomp, freeBusyRange.getStart(),
freeBusyRange.getEnd());
} else {
overrides.add(vcomp);
}
} else if (comp instanceof VFreeBusy) {
// Add all FREEBUSY BUSY/BUSY-TENTATIVE/BUSY-UNAVAILABLE to the periods
List<FreeBusy> fbs = ((Component)comp).getProperties().getProperties(Property.FREEBUSY);
for (FreeBusy fb : fbs) {
FbType fbt = (FbType) fb.getParameters().getParameter(
Parameter.FBTYPE);
if (fbt == null || FbType.BUSY.equals(fbt)) {
addRelevantPeriods(busyPeriods, fb.getPeriods(),
freeBusyRange);
} else if (FbType.BUSY_TENTATIVE.equals(fbt)) {
addRelevantPeriods(busyTentativePeriods, fb
.getPeriods(), freeBusyRange);
} else if (FbType.BUSY_UNAVAILABLE.equals(fbt)) {
addRelevantPeriods(busyUnavailablePeriods, fb
.getPeriods(), freeBusyRange);
}
}
}
}
private VEvent addComponentsToInstances(Calendar calendar, Period freeBusyRange, InstanceList instances, Object comp) {

for (Iterator<Component> i = overrides.iterator(); i.hasNext();) {
Component comp = i.next();
instances.addComponent(comp, freeBusyRange.getStart(),
VEvent vcomp = (VEvent) comp;
// See if this is the master instance
if (vcomp.getRecurrenceId() == null) {
instances.addComponent(vcomp, freeBusyRange.getStart(),
freeBusyRange.getEnd());
} else {
return vcomp;
}
return vcomp;
}

// See if there is nothing to do (should not really happen)
if (instances.size() == 0) {
return;
private void addFreeBusyPeriods(Object comp, Period freeBusyRange, PeriodList busyPeriods, PeriodList busyTentativePeriods, PeriodList busyUnavailablePeriods) {
List<FreeBusy> fbs = ((Component)comp).getProperties().getProperties(Property.FREEBUSY);
for (FreeBusy fb : fbs) {
FbType fbt = (FbType) fb.getParameters().getParameter(
Parameter.FBTYPE);
if (fbt == null || FbType.BUSY.equals(fbt)) {
addRelevantPeriods(busyPeriods, fb.getPeriods(),
freeBusyRange);
} else if (FbType.BUSY_TENTATIVE.equals(fbt)) {
addRelevantPeriods(busyTentativePeriods, fb
.getPeriods(), freeBusyRange);
} else if (FbType.BUSY_UNAVAILABLE.equals(fbt)) {
addRelevantPeriods(busyUnavailablePeriods, fb
.getPeriods(), freeBusyRange);
}
}
}

private void addPeriodsToBusyLists(InstanceList instances, Period freeBusyRange, PeriodList busyPeriods, PeriodList busyTentativePeriods) {

// Add start/end period for each instance
for (Iterator<Entry<String, Instance>> i = instances.entrySet().iterator(); i.hasNext();) {
Map.Entry<?, ?> entry = i.next();

Object instanceObj = entry.getValue();

if(!(instanceObj instanceof Instance)){
continue;
}
Instance instance = (Instance) instanceObj;

// Check that the VEVENT has the proper busy status
if (Transp.TRANSPARENT.equals(instance.getComp().getProperties()
.getProperty(Property.TRANSP))) {
Expand All @@ -335,10 +306,10 @@ protected void addBusyPeriods(Calendar calendar, TimeZone timezone,
// Can only have DATE-TIME values in PERIODs
Date start = null;
Date end = null;

start = instance.getStart();
end = instance.getEnd();

if (start.compareTo(freeBusyRange.getStart()) < 0) {
start = (DateTime) org.unitedinternet.cosmo.calendar.util.Dates.getInstance(freeBusyRange
.getStart(), start);
Expand All @@ -355,8 +326,52 @@ protected void addBusyPeriods(Calendar calendar, TimeZone timezone,
} else {
busyPeriods.add(new Period(dtStart, dtEnd));
}


}

}

/**
* Adds relevant periods.
* @param calendar The calendar.
* @param timezone The timezone.
* @param freeBusyRange
* @param busyPeriods
* @param busyTentativePeriods
* @param busyUnavailablePeriods
*/
protected void addBusyPeriods(Calendar calendar, TimeZone timezone,
Period freeBusyRange, PeriodList busyPeriods,
PeriodList busyTentativePeriods, PeriodList busyUnavailablePeriods) {

// Create list of instances within the specified time-range
InstanceList instances = new InstanceList();
instances.setUTC(true);
instances.setTimezone(timezone);

// Look at each VEVENT/VFREEBUSY component only
ComponentList<Component> overrides = new ComponentList<>();
for (Object comp: calendar.getComponents()) {
if (comp instanceof VEvent) {
overrides.add(addComponentsToInstances(calendar,freeBusyRange, instances,comp));
} else if (comp instanceof VFreeBusy) {
// Add all FREEBUSY BUSY/BUSY-TENTATIVE/BUSY-UNAVAILABLE to the periods
addFreeBusyPeriods(comp, freeBusyRange, busyPeriods, busyTentativePeriods, busyUnavailablePeriods);
}
}

for (Iterator<Component> i = overrides.iterator(); i.hasNext();) {
Component comp = i.next();
instances.addComponent(comp, freeBusyRange.getStart(),
freeBusyRange.getEnd());
}

// See if there is nothing to do (should not really happen)
if (instances.size() == 0) {
return;
}

addPeriodsToBusyLists(instances,freeBusyRange, busyPeriods, busyTentativePeriods);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public Set<ICalendarItem> findCalendarItems(CollectionItem collection, CalendarF
ICalendarItem content = (ICalendarItem) child;
Calendar calendar = entityConverter.convertContent(content);

if (calendar != null && evaluater.evaluate(calendar, filter)) {
if (calendar != null && evaluater.evaluateCalendarFilter(calendar, filter)) {
results.add(content);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,14 @@
*/
public abstract class CaldavMultiStatusReport extends MultiStatusReport
implements CaldavConstants {

private OutputFilter outputFilter;

// ReportBase methods


// MultiStatusReport methods

protected OutputFilter outputFilter;

/**
* Removes <code>CALDAV:calendar-data</code> from the property spec
* since it doesn't represent a real property.
Expand Down Expand Up @@ -88,9 +88,6 @@ public OutputFilter getOutputFilter() {
return outputFilter;
}

public void setOutputFilter(OutputFilter outputFilter) {
this.outputFilter = outputFilter;
}

/**
* Parses an output filter out of the given report info.
Expand Down Expand Up @@ -128,4 +125,20 @@ private String readCalendarData(DavCalendarResource resource)
}
return builder.toString();
}

public void setReportSpecifics(ReportInfo info) throws CosmoDavException {
setPropFindProps(info.getPropertyNameSet());
if (info.containsContentElement(XML_ALLPROP, NAMESPACE)) {
setPropFindType(PROPFIND_ALL_PROP);
} else if (info.containsContentElement(XML_PROPNAME, NAMESPACE)) {
setPropFindType(PROPFIND_PROPERTY_NAMES);
} else {
setPropFindType(PROPFIND_BY_PROPERTY);
setOutputFilter(findOutputFilter(info));
}
}

public void setOutputFilter(OutputFilter outputFilter) {
this.outputFilter = outputFilter;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,7 @@ protected void parseReport(ReportInfo info) throws CosmoDavException {
throw new CosmoDavException("Report not of type " + getType().getReportName());
}

setPropFindProps(info.getPropertyNameSet());
if (info.containsContentElement(XML_ALLPROP, NAMESPACE)) {
setPropFindType(PROPFIND_ALL_PROP);
} else if (info.containsContentElement(XML_PROPNAME, NAMESPACE)) {
setPropFindType(PROPFIND_PROPERTY_NAMES);
} else {
setPropFindType(PROPFIND_BY_PROPERTY);
setOutputFilter(findOutputFilter(info));
}
setReportSpecifics(info);

List<Element> hrefElements =
info.getContentElements(XML_HREF, NAMESPACE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,7 @@ protected void parseReport(ReportInfo info)
throw new CosmoDavException("Report not of type " + getType());
}

setPropFindProps(info.getPropertyNameSet());
if (info.containsContentElement(XML_ALLPROP, NAMESPACE)) {
setPropFindType(PROPFIND_ALL_PROP);
} else if (info.containsContentElement(XML_PROPNAME, NAMESPACE)) {
setPropFindType(PROPFIND_PROPERTY_NAMES);
} else {
setPropFindType(PROPFIND_BY_PROPERTY);
setOutputFilter(findOutputFilter(info));
}
setReportSpecifics(info);

tz = findTimeZone(info);
if ( tz == null && getResource() instanceof DavCalendarCollection) {
Expand Down
Loading