Wednesday, February 11, 2015

Oracle BPM :Get list of Holiday Calendars and Working Calendar using BPM api's


package com.raylabs.bpm;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import oracle.bpel.services.bpm.common.IBPMContext;
import oracle.bpel.services.workflow.client.IWorkflowServiceClientConstants;
import oracle.bpel.services.workflow.client.WorkflowServiceClientFactory;
import oracle.bpm.client.BPMServiceClientFactory;
import oracle.bpm.services.client.IBPMServiceClient;
import oracle.bpm.services.organization.IBPMOrganizationService;
import oracle.bpm.services.organization.model.CalendarRule;
import oracle.bpm.services.organization.model.CalendarRules;
import oracle.bpm.services.organization.model.HolidayRule;
import oracle.bpm.services.organization.model.HolidayRules;
import oracle.bpm.services.organization.model.HolidayType;
import oracle.bpm.services.organization.model.Organization;
import oracle.bpm.services.organization.model.WeekDaysEnum;
import oracle.bpm.services.organization.model.WorkPeriodType;
import oracle.bpm.services.organization.model.WorkdayListType;
import oracle.bpm.services.organization.model.WorkdayType;
public class Class1 {
private static String username;
private static String password;
private static String environment;
private static String serverPort;
private Class1() {
super();
}
public static void main(String[] args) {
username = "xxx";
password = "xxx";
environment = "dev";
serverPort = "123";
BPMServiceClientFactory wfSvcClient = null;
IBPMContext bpmCtx = null;
IBPMServiceClient bPMServiceClient = null;
try {
final Map connectionProperty = getConnProp();
wfSvcClient =
BPMServiceClientFactory.getInstance(connectionProperty,
null, null);
bPMServiceClient = wfSvcClient.getBPMServiceClient();
IBPMOrganizationService bpmOrgSvc =
bPMServiceClient.getBPMOrganizationService();
bpmCtx =
(IBPMContext)wfSvcClient.getWorkflowServiceClient().getTaskQueryService().authenticate(null,
null,
null);
Organization org = bpmOrgSvc.exportOrganization(bpmCtx);
//Holiday Calendar
HolidayRules holidayRules = org.getHolidayRules();
List<HolidayRule> holidayRule = holidayRules.getHolidayRule();
Iterator<HolidayRule> iterator0 = holidayRule.iterator();
while (iterator0.hasNext()) {
HolidayRule next = iterator0.next();
System.out.println("Holiday calendar :" + next.getName());
List<HolidayType> holidays = next.getHolidays();
Iterator<HolidayType> iterator = holidays.iterator();
while (iterator.hasNext()) {
HolidayType holidayType = iterator.next();
System.out.println("Holiday name :" +
holidayType.getName() +
" Holiday date :" +
holidayType.getHolidayDate() +
" Holiday type :" +
holidayType.getHolidayPattern());
}
}
//Calendar rules
CalendarRules calendarRules = org.getCalendarRules();
List<CalendarRule> calendarRule = calendarRules.getCalendarRule();
Iterator<CalendarRule> iterator = calendarRule.iterator();
while (iterator.hasNext()) {
CalendarRule next = iterator.next();
System.out.println("Working Calendar :" + next.getName());
System.out.println("Holdiay Calendar associated with the Working Calendar :" +
next.getHolidayRuleName());
WorkdayListType list = next.getWorkdayList();
List<WorkdayType> workday = list.getWorkday();
Iterator<WorkdayType> iterator1 = workday.iterator();
while (iterator1.hasNext()) {
WorkdayType type = iterator1.next();
WeekDaysEnum day = type.getWeekDay();
System.out.println("Working days " + day);
List<WorkPeriodType> period = type.getWorkPeriod();
Iterator<WorkPeriodType> iterator2 = period.iterator();
while (iterator2.hasNext()) {
WorkPeriodType periodType = iterator2.next();
System.out.println("Start time :" +
periodType.getStartTime() +
" End time " +
periodType.getEndTime());
}
}
}
} catch (Exception e) {
e.printStackTrace();
} finally {
}
}
public static Map getConnProp() throws Exception {
final Map connProp = new HashMap();
try {
connProp.put(IWorkflowServiceClientConstants.CONNECTION_PROPERTY.EJB_INITIAL_CONTEXT_FACTORY,
"weblogic.jndi.WLInitialContextFactory");
connProp.put(IWorkflowServiceClientConstants.CONNECTION_PROPERTY.EJB_PROVIDER_URL,
"t3://" + environment +
"-abc.com:" + serverPort);
connProp.put(IWorkflowServiceClientConstants.CONNECTION_PROPERTY.EJB_SECURITY_PRINCIPAL,
username);
connProp.put(IWorkflowServiceClientConstants.CONNECTION_PROPERTY.EJB_SECURITY_CREDENTIALS,
password);
connProp.put(IWorkflowServiceClientConstants.CONNECTION_PROPERTY.CLIENT_TYPE,
WorkflowServiceClientFactory.REMOTE_CLIENT);
} catch (Exception e) {
e.printStackTrace();
}
return connProp;
}
}



No comments:

Post a Comment