0
votes

I need to check against room's availability options if it's currently available in an java xpage rest api. I tried looking at the resource reservations database after setting custom availability options, but didn't get much info. How can I check the availability rules programmatically? I know there is such thing as freetime api, but it's not really helpful and I don't want to use another service.

I found my room's document in the database and it looks like this:

{
    "@href":"\/RoomRese.nsf\/api\/data\/documents\/unid\/D6D558B1387CEA11C125842D002605C0",
    "@unid":"D6D558B1387CEA11C125842D002605C0",
    "@noteid":"902",
    "@created":"2019-07-04T06:55:18Z",
    "@modified":"2019-07-17T13:41:45Z",
    "@authors":"CN=Test User\/O=Server",
    "@form":"Resource",
    "actiontype":"SAVE",
    "ResourceType":"1",
    "Site":"Site",
    "ConferenceDatabase":"stconf.nsf",
    "InternetAddress":"[email protected]",
    "Sunday":"1",
    "Monday":"2",
    "Tuesday":"3",
    "Wednesday":"4",
    "Thursday":"5",
    "Friday":"6",
    "Saturday":"7",
    "TimeZone":"Z=-1$DO=1$DL=3 -1 1 10 -1 1$ZX=27$ZN=Central European",
    "SundayAvailable":"1",
    "MondayAvailable":"2",
    "TuesdayAvailable":"3",
    "ThursdayAvailable":"5",
    "FridayAvailable":"6",
    "SaturdayAvailable":"7",
    "LimitHow":"1",
    "LimitDays":90,
    "LimitDate":"2019-10-02",
    "OtherComments":
    {
        "type":"multipart",
        "content":        [
                    {
            "contentType":"text\/html; charset=US-ASCII",
            "contentDisposition":"inline",
            "data":"<html><body><\/body><\/html>\r\n\r\n"
          }
        ]
    },
    "Type":"Resource",
    "Author":"CN=Test User\/O=Site",
    "CommonNameResourceName":"Room 1",
    "ResourceName":"CN=Room 1\/O=Site",
    "Capacity":44,
    "AlwaysAvailable":0,
    "AutoProcessType":"0",
    "Owner":"CN=Room 1\/O=Site"
}

I can see these 'MondayAvailabile' etc. but there are only simple numbers and I have no idea what do they mean. How can I do it in java?

I have tried using session.freeTimeSearch() but it doesn't work, at least not on the server side. Here is my code:

        Session = resourceDB.getParent();
        DateRange = session.createDateRange();
        range.setStartDateTime(tStart);
        range.setEndDateTime(tEnd);

        int duration = tEnd.timeDifference(tStart);
        System.out.println("Range: " + range.getStartDateTime().toString() + " <-> " + range.getEndDateTime().toString());
        System.out.println("Duration calculated: " + duration);

        try {
            Vector<?> frs = session.freeTimeSearch(range, duration/2, "Room 1/Test Site",true);

            if(frs == null || frs.size() <= 0) {
                System.out.println("NO FREETIME !!!! " + tStart.toString() + " -> " + tEnd.toString());
                return true;
            } else {
                for(int i = 0; i < frs.size(); i++) {
                    DateRange dr = (DateRange)frs.elementAt(i);
                    System.out.println("Found " + dr.getStartDateTime().toString() + " <-> " + dr.getEndDateTime().toString());

                }
            }
        } catch (NotesException ex) {
            System.out.println("ERROR: "+ ex.getMessage());
        }

The output is like this:

Range: 07/18/2019 03:00:00 PM CEDT <-> 07/18/2019 03:30:00 PM CEDT
Duration calculated: 1800
NO FREETIME !!!! 07/18/2019 03:00:00 PM CEDT -> 07/18/2019 03:30:00 PM CEDT

I did duration/2 because I thought full-duration from daterange may not work, but it's the same.

UPDATE!! Stupid me, it works! The duration parameter should be in MINUTES, and the duration returned from timeDifference is in seconds, there fore a simple division by 60 fixed everything!

1

1 Answers

0
votes

There is a Java API for querying free time. Look at Session.freeTimeSearch().