Browse code

BM-15187 Fix: Transparent meetings are returned as free, except for resources

Mehdi Rande authored on 09/09/2019 14:14:36
Showing 1 changed files
... ...
@@ -28,6 +28,7 @@ import net.bluemind.core.api.date.BmDateTime;
28 28
 import net.bluemind.core.api.date.BmDateTimeWrapper;
29 29
 import net.bluemind.core.container.model.ItemValue;
30 30
 import net.bluemind.icalendar.api.ICalendarElement.Attendee;
31
+import net.bluemind.icalendar.api.ICalendarElement.CUType;
31 32
 import net.fortuna.ical4j.model.Calendar;
32 33
 import net.fortuna.ical4j.model.Period;
33 34
 import net.fortuna.ical4j.model.PropertyList;
... ...
@@ -103,31 +104,7 @@ public class VFreebusyServiceHelper {
103 104
 
104 105
 		for (ItemValue<VEvent> item : events) {
105 106
 			VEvent event = item.value;
106
-			VFreebusy.Type type = (event.transparency == VEvent.Transparency.Opaque) ? VFreebusy.Type.BUSY
107
-					: VFreebusy.Type.FREE;
108
-
109
-			for (Attendee a : event.attendees) {
110
-				if (a.dir != null && a.dir.endsWith("/" + freebusyOwner)) {
111
-					switch (a.partStatus) {
112
-					case Accepted:
113
-						type = Type.BUSY;
114
-						break;
115
-					case Declined:
116
-						type = Type.FREE;
117
-						break;
118
-					case NeedsAction:
119
-						type = Type.BUSYTENTATIVE;
120
-						break;
121
-					case Tentative:
122
-						type = Type.BUSYTENTATIVE;
123
-						break;
124
-					default:
125
-						type = Type.BUSY;
126
-						break;
127
-					}
128
-				}
129
-			}
130
-
107
+			VFreebusy.Type type = getFreebusyType(event, freebusyOwner);
131 108
 			Slot s = Slot.create(event.dtstart, event.dtend, event.summary, type);
132 109
 			freebusy.slots.add(s);
133 110
 		}
... ...
@@ -142,6 +119,47 @@ public class VFreebusyServiceHelper {
142 119
 		return freebusy;
143 120
 	}
144 121
 
122
+	private static Type getFreebusyType(VEvent event, String freebusyOwner) {
123
+		if (event.transparency == VEvent.Transparency.Opaque ) {
124
+			return getTypeForOpaque(event, freebusyOwner);
125
+		} else {
126
+			return getTypeForTransparent(event, freebusyOwner);
127
+		}
128
+	}
129
+
130
+	private static Type getTypeForTransparent(VEvent event, String freebusyOwner) {
131
+		for (Attendee a : event.attendees) {
132
+			if (a.dir != null && a.dir.endsWith("/" + freebusyOwner)) {
133
+				if (a.cutype == CUType.Resource || a.cutype == CUType.Room) {
134
+					return getTypeForAttendee(a);
135
+				}
136
+				break;
137
+			}
138
+		}		
139
+		return Type.FREE;
140
+	}
141
+
142
+	private static Type getTypeForOpaque(VEvent event, String freebusyOwner) {
143
+		for (Attendee a : event.attendees) {
144
+			if (a.dir != null && a.dir.endsWith("/" + freebusyOwner)) {
145
+				return getTypeForAttendee(a);
146
+			}
147
+		}
148
+		return Type.BUSY;
149
+	}
150
+
151
+	private static Type getTypeForAttendee(Attendee a) {
152
+		switch (a.partStatus) {
153
+		case Declined:
154
+			return Type.FREE;
155
+		case NeedsAction:
156
+		case Tentative:
157
+			return Type.BUSYTENTATIVE;
158
+		default:
159
+			return Type.BUSY;
160
+		}
161
+	}
162
+
145 163
 	private static FreeBusy convertToIcal4jVFreebusy(Slot slot) {
146 164
 
147 165
 		net.fortuna.ical4j.model.DateTime ical4jDtStart = convertToUtcIcsDate(slot.dtstart);