Accessing Business Calendars from within IS

Hello,

we’d like to use a business calendar (BC) in our services. BCs are created and edited in MWS. There is an API fro working with them. The API even seems to be available in IS – in the sense that I can create a java service and compile it against the API.

But should such service work? Because, in my view, an IS is a different runtime environment than the MWS and hence might not have access to resources (database etc.) the MWS works with.

Could someone please shed light on this?

Thanks!

it may be using Task engine package and configuration. i am not aware of API… so not sure.

AFAIK, there is no publicly available API from SAG for accessing Business calendars on MWS. They provide API’s to work with Tasks (BPM) but nothing specific to Calendars in MWS.

You are better off creating your own Framework by using custom config files holding the dates. These config files effectively become your “Calendars”.

See other thread where this question has been answered quite well.

Hi,

might be worth to open a feature request in brainstorm for this to get easier access to these items.

Regards,
Holger

That was a quite interesting thread and i completely missed it before posting a reply here. I was looking for documentation on the API’s and couldn’t find any. Were you able to create the Java service for fetching Business Calendars information?

Did you use the classes from com.webMethods.sc.calendar or from com.webMethods.caf.faces.data.calendar?

I agree with Holger about documentation for this API. This will can be a very useful feature within ESB or EAI. I am surprised that SAG did not put this in any Service development help documentation.

The API is quite clear and easy to use IMO. I was just not sure where it can be used.

This is not about how difficult it is to use API but a reference about this API feature in the documentation will help a lot of folks.

Holger, i created a feature request in Brainstorm for this. 04773.

For other folks who are wondering how this can be done, below is a sample. I could not make it work using the Central Users JDBC connection pool so i used the connection settings directly to MWS database like we do with CDS API.

Pre-requisite:
wm-calendar.jar and wm-caf-jsf.jar

import com.webMethods.sc.calendar.;
import com.webMethods.sc.calendar.impl.CalendarBuilder;
import com.webMethods.caf.faces.data.calendar.
;
import com.webMethods.sc.mws.*;

  1. Create a Business calendar in MWS with the days and start\end times as business hours.
  2. Use an appropriate name for calendars for Looking them up from IS.
  3. Use below service and that will get the working days and start\end times from MWS Business calendars.

Note:
This is not a production level code and this lists out a single operation which will get all the calendar information from MWS in to IS. You can easily modify this code to either find out if current time is within Business hours or other operations like finding if a given day is a working day or not.


IDataCursor pipelinecursor=pipeline.getCursor();
		try{
			
			System.setProperty(MWSLibrary.SYSTEM_PROP_DB_DRIVER,"com.wm.dd.jdbc.sqlserver.SQLServerDriver"); // JDBC Driver Class
			System.setProperty(MWSLibrary.SYSTEM_PROP_DB_URL,"jdbc:wm:sqlserver://localhost:1433;databaseName=WM_MWS");
			System.setProperty(MWSLibrary.SYSTEM_PROP_DB_USER, "username");
			System.setProperty(MWSLibrary.SYSTEM_PROP_DB_PASSWORD, "dontask");
			MWSLibrary.init();
			
			ICalendarSystem  calendarSystem  = CalendarSystemFactory.getCalendarSystem();
			ICalendarManager calendarManager = calendarSystem.getCalendarManager();
			
			ICalendar cal=calendarManager.getCalendarByAlias("CalendarAliasName");
			Date date=new Date();
			ICalendarEvaluator eval=calendarSystem.getCalendarEvaluator(date, (IWorkdayCalendar)cal);
			IWorkdayCalendar workday=(IWorkdayCalendar)cal;
			
			List<Workday> test= new ArrayList<Workday>();
			
			test.addAll(workday.getWorkdays());
			List<String> outdays=new ArrayList<String>();
			for(int i=0;i<test.size();i++){
				DayOfWeek dayOfWeek = DayOfWeek.of(test.get(i).getDay());
				outdays.add(dayOfWeek.getDisplayName(TextStyle.FULL, Locale.US) +" - "+String.valueOf(test.get(i).getStartHour()) +":"+String.valueOf(test.get(i).getStartMinute())
						+" - "+String.valueOf(test.get(i).getEndHour())+":"+String.valueOf(test.get(i).getEndMinute()));
				
			}
			
			IDataUtil.put(pipelinecursor, "result", outdays.toArray(new String[outdays.size()]));
			pipelinecursor.destroy();
		}
		 catch(CalendarException e){
			 IDataUtil.put(pipelinecursor, "errorMessage", e.toString());
		 }
		catch(Exception e){
			IDataUtil.put(pipelinecursor, "errorMessage", e.toString());
		}
1 Like

Hi Akshith,

Thanks for your reply, Can you please provide some inputs on holiday calendar as well.

Looking for BC → holiday’s entry

The Holiday class does not provide as many methods as the Workday class. You can use the code posted in this thread to determine if the current time is a workday, if it is not then you can mark it as either a holiday or after hours. In this way it addresses both the requirements(Holiday and workday).