Browse code

BM-14501 Fix: do not print refused event in PDF

Vincent Vignaud authored on 27/11/2019 16:40:04
Showing 1 changed files
... ...
@@ -56,7 +56,8 @@ import org.w3c.dom.DOMImplementation;
56 56
 import org.w3c.dom.Document;
57 57
 import org.w3c.dom.Element;
58 58
 
59
-import net.bluemind.calendar.api.ICalendarUids;
59
+import com.google.common.base.Strings;
60
+
60 61
 import net.bluemind.calendar.api.PrintOptions;
61 62
 import net.bluemind.calendar.api.VEvent;
62 63
 import net.bluemind.core.api.date.BmDateTime;
... ...
@@ -294,37 +295,46 @@ public abstract class PrintCalendar {
294 295
 	}
295 296
 
296 297
 	/**
297
-	 * TODO should go in a service ? or an utility class ?
298
-	 * 
299
-	 * @return <code>true</code> if the given event is a declined invitation i.e.:
300
-	 *         this event is declined by X and the event's calendar is the X's
301
-	 *         default calendar
298
+	 * @return <code>true</code> if the given event is a declined invitation
299
+	 *         i.e.: this event is declined by X and the event's calendar is the
300
+	 *         X's default calendar
302 301
 	 */
303
-	private boolean isADeclinedInvitation(final ItemContainerValue<VEvent> event) {
302
+	private boolean isADeclinedInvitation(ItemContainerValue<VEvent> event) {
304 303
 		if (event.value.attendees == null || event.value.attendees.isEmpty()) {
305 304
 			// no attendee, so it is not an invitation
306 305
 			return false;
307 306
 		}
308 307
 
309 308
 		// search for a declined attendee in her own default calendar
310
-		for (final Attendee attendee : event.value.attendees) {
311
-			if (ParticipationStatus.Declined == attendee.partStatus && attendee.dir != null
312
-					&& !attendee.dir.isEmpty()) {
313
-				// power tip: the user uid is hidden in the attendee.dir field !
314
-				final int lastSlashIndex = attendee.dir.lastIndexOf('/');
315
-				if (lastSlashIndex > 0) {
316
-					final String attendeeDefaultCalendarUid = ICalendarUids
317
-							.defaultUserCalendar(attendee.dir.substring(lastSlashIndex + 1));
318
-					if (event.containerUid.equals(attendeeDefaultCalendarUid)) {
319
-						return true;
320
-					}
321
-				}
309
+		String calendarUid = this.extractUidFromItemContainerUid(event.containerUid);
310
+		for (Attendee attendee : event.value.attendees) {
311
+			if (ParticipationStatus.Declined == attendee.partStatus) {
312
+				String attendeeUid = this.extractUidFromAttendeeDir(attendee.dir);
313
+				return attendeeUid.equals(calendarUid);
322 314
 			}
323 315
 		}
324 316
 
325 317
 		return false;
326 318
 	}
327 319
 
320
+	/**
321
+	 * The uid of the attendee is found at the very end after the last
322
+	 * <b>&#47;</b> and the last <b>:</b>.
323
+	 */
324
+	private String extractUidFromAttendeeDir(String attendeeDir) {
325
+		String[] split = Strings.nullToEmpty(attendeeDir).split("[/:]");
326
+		return split[split.length - 1];
327
+	}
328
+
329
+	/**
330
+	 * The uid of the container is found at the very end after the last
331
+	 * <b>:</b>.
332
+	 */
333
+	private String extractUidFromItemContainerUid(String itemContainerUid) {
334
+		String[] split = itemContainerUid.split(":");
335
+		return split[split.length - 1];
336
+	}
337
+
328 338
 	public byte[] sendSVGString() throws ServerFault {
329 339
 		byte[] ret = null;
330 340
 		try {