0

I have a custom XPage java REST api in Lotus to handle reservations, everything is going well so far. I have one weird "problem" though, whenever I update a meeting, the room name (like Test room/Site) is being appended to the LOCATION in iCalendar string.

The way I'm updating appointments is by finding the entry in user's calendar (NotesCalendar.getEntryByUID), then I call NotesCalendarEntry.read() to get the iCalendar string, I then manually replace values of certain iCalendar fields, like DTSTART to the ones I wish to update (I'm only updating DTSTART, DTEND and SUMMARY). Finally I call NotesCalendarEntry.update(string) to update the event. It works well, however with each update, the LOCATION field grows bigger and bigger, because the room name is being constantly appended to it, and finally it looks like:

LOCATION: Test Room/Test SiteTest Room/Test SiteTest Room/Test Site

etc.

Am I doing something wrong? How can I prevent this? I don't want to clear the location field each time, because users can put their own location and I'd like to keep it (in that case room name is also being appended to the original location text)

Code:

            NotesCalendar cal = session.getCalendar( session.getDbDirectory( session.getServerName() ).openMailDatabase() );
            NotesCalendarEntry calEntry = cal.getEntryByUNID(apptUNID); // apptUNID is taken from http json payload
            String iCalE = calEntry.read();
            // 20190326T160000Z
            String dStart = DateUtil.formatICalendar(dtStart);
            String dEnd = DateUtil.formatICalendar(dtEnd);

            iCalE = iCalE.replace("\\n", ""); // I added this because same was happening to literal \n (not actual line breaks)
            StringBuilder sb = new StringBuilder(iCalE);

            int StartIndex = iCalE.indexOf("BEGIN:VEVENT"); // DTSTART is also in BEGIN:VTIMEZONE so we need to exclude that
            int tmpIndex = iCalE.indexOf("DTSTART", StartIndex) + 7; // 7 = len of DTSTART
            int LineBreakIndex = iCalE.indexOf('\n', tmpIndex);
            if(iCalE.charAt(LineBreakIndex-1) == '\r')
                LineBreakIndex--;

            sb.delete(tmpIndex, LineBreakIndex);
            sb.insert(tmpIndex, ":" + dStart); // start date
            tmpIndex = sb.indexOf("DTEND", StartIndex) + 5;
            LineBreakIndex = sb.indexOf(Character.toString('\n'), tmpIndex);
            if(sb.charAt(LineBreakIndex-1) == '\r')
                LineBreakIndex--;

            sb.delete(tmpIndex, LineBreakIndex);
            sb.insert(tmpIndex, ":" + dEnd);
            calEntry.update(sb.toString());
            calEntry.recycle();

Also, can I safely assume that iCalendar lines are always ended with \r\n ? (they currently are, I had some problems with that but I figured it out, I'm not sure if I can safely look for '\r\n' though) I dont use ical4j because I'm literally only modifying 2 or 3 fields and nothing else.

AJ Cole
  • 169
  • 2
  • 13
  • Show your code, please. – Richard Schwartz Mar 25 '19 at 22:45
  • @RichardSchwartz code added – AJ Cole Mar 26 '19 at 07:42
  • Have you tried adding the optional arguments to the NotesCalendarentry.Update() call? A value of 1 (or CS_WRITE_MODIFY_LITERAL) in the third (flags) argument to overwrite the calendar entry without preserving prior field values? (I'm not making this an answer as I'm not an xpages guy; I'm reading from the doc for the LotusScript classes.) – Richard Schwartz Mar 27 '19 at 04:05
  • @RichardSchwartz unfortunately it didn't change anything, as far as I can see, the room name is always being appended at the end of the location field. When I set LOCATION to some custom text, it's eventually being set to `Random text\nRoom name/Site name` – AJ Cole Mar 27 '19 at 08:13
  • I temporarily fixed it by just dropping any text after a literal `\n` in the location field, but I'd prefer some proper fix. – AJ Cole Mar 27 '19 at 08:21
  • It sounds like you need to be opening a support incident with IBM (or HCL -- I'm not sure what the proper channel is nowadays). – Richard Schwartz Mar 27 '19 at 17:00

0 Answers0