}
ACLUser oUser = new ACLUser(oConn, sUserId);
Timestamp tmFrom = new Timestamp(dtFrom.getTime());
Timestamp tmTo = new Timestamp(dtTo.getTime());
DBSubset oGroupCalendars = new DBSubset(DB.k_working_calendar + " c",
"c."+DB.gu_calendar+",c."+DB.gu_acl_group+",c."+DB.gu_user+",c."+DB.gu_geozone+",c."+DB.id_country+",c."+DB.id_state,
"c."+DB.gu_workarea+"=? AND c."+DB.id_domain+"=? AND "+
"(c."+DB.gu_user+"=? OR EXISTS (SELECT g."+DB.gu_acl_group+" FROM "+DB.k_x_group_user+" g WHERE g."+DB.gu_acl_group+"=c."+DB.gu_acl_group+" AND g."+DB.gu_user+"=?)) AND "+
"(c."+DB.dt_from+" BETWEEN ? AND ? OR c."+DB.dt_to+" BETWEEN ? AND ? OR (c."+DB.dt_from+"<=? AND c."+DB.dt_to+">=?)) "+
"ORDER BY c."+DB.dt_from, 4);
int nCals = oGroupCalendars.load(oConn, new Object[]{oUser.get(DB.gu_workarea),oUser.get(DB.id_domain),
sUserId, sUserId,
tmFrom,tmTo,tmFrom,tmTo,tmFrom,tmTo});
if (0==nCals) {
oRetCal = null;
} else {
oRetCal = new WorkingCalendar();
// Place at the bottom of the stack the group calendars without country nor state
if (DebugFile.trace) DebugFile.writeln("Scanning group calendars...");
for (int c=0; c<nCals; c++) {
if (oGroupCalendars.isNull(DB.gu_user,c) && oGroupCalendars.isNull(DB.id_country,c) && oGroupCalendars.isNull(DB.id_state,c)) {
if (DebugFile.trace) DebugFile.writeln("Found group calendar "+oGroupCalendars.getString(DB.gu_calendar,c));
oCurCal = new WorkingCalendar (oConn, oGroupCalendars.getString(DB.gu_calendar,c));
oRetCal = oRetCal.merge(oCurCal);
sName += (sName.length()==0 ? "" : "+") + oCurCal.getName();
} // fi
} // next
if (DebugFile.trace) DebugFile.writeln("Scanning country calendars...");
// The second layer are group calendars for whole countries
if (sCountryId!=null) {
for (int c=0; c<nCals; c++) {
if (oGroupCalendars.isNull(DB.gu_user,c) && sCountryId.equals(oGroupCalendars.getStringNull(DB.id_country,c,"")) && oGroupCalendars.isNull(DB.id_state,c)) {
if (DebugFile.trace) DebugFile.writeln("Found country calendar "+oGroupCalendars.getString(DB.gu_calendar,c));
oCurCal = new WorkingCalendar (oConn, oGroupCalendars.getString(DB.gu_calendar,c));
oRetCal = oRetCal.merge(oCurCal);
sName += (sName.length()==0 ? "" : "+") + oCurCal.getName();
} // fi
} // next
}
// The third layer are calendars for states
if (sStateId!=null) {
if (DebugFile.trace) DebugFile.writeln("Scanning state calendars...");
for (int c=0; c<nCals; c++) {
if (oGroupCalendars.isNull(DB.gu_user,c) && !oGroupCalendars.isNull(DB.id_country,c) && sStateId.equals(oGroupCalendars.getStringNull(DB.id_state,c,""))) {
if (DebugFile.trace) DebugFile.writeln("Found state calendar "+oGroupCalendars.getString(DB.gu_calendar,c));
oCurCal = new WorkingCalendar (oConn, oGroupCalendars.getString(DB.gu_calendar,c));
oRetCal = oRetCal.merge(oCurCal);
sName += (sName.length()==0 ? "" : "+") + oCurCal.getName();
} // fi
} // next
}
// The top layer are calendars for a single user
for (int c=0; c<nCals; c++) {
if (!oGroupCalendars.isNull(DB.gu_user,c)) {
oCurCal = new WorkingCalendar (oConn, oGroupCalendars.getString(DB.gu_calendar,c));
oRetCal = oRetCal.merge(oCurCal);
sName += (sName.length()==0 ? "" : "+") + oCurCal.getName();
} // fi
} // next
oRetCal.oCalendarInfo.replace(DB.nm_calendar, sName);