if (DebugFile.trace) {
DebugFile.writeln("Begin GCalendarSynchronizer.connect([JDCConnection], "+sUser+","+sWorkArea+"[DistributedCachePeer])");
DebugFile.incIdent();
}
PasswordRecord oPrec = null;
sGuUser = sUser;
sGuWorkArea = sWorkArea;
boolean bCalendarFound = false;
PreparedStatement oStmt;
ResultSet oRSet;
iIdDomain = oWrkA.get(sWorkArea);
if (null==iIdDomain) {
oStmt = oConn.prepareStatement("SELECT "+DB.id_domain+" FROM "+DB.k_workareas+" WHERE "+DB.gu_workarea+"=?");
oStmt.setString(1, sWorkArea);
oRSet = oStmt.executeQuery();
if (oRSet.next()) {
iIdDomain = new Integer(oRSet.getInt(1));
oWrkA.put(sWorkArea, iIdDomain);
}
oRSet.close();
oStmt.close();
}
if (null==iIdDomain) throw new SQLException("WorkArea "+sWorkArea+" not found");
if (oCache!=null) {
oPrec = (PasswordRecord) oCache.get(sUser+"[gmail]");
}
if (null==oPrec) {
oPrec = new PasswordRecord();
if (DebugFile.trace)
DebugFile.writeln("JDCConnection.prepareStatement(SELECT "+DB.gu_pwd+" FROM "+DB.k_user_pwd+" WHERE "+DB.gu_user+"='"+sUser+"' AND "+DB.id_pwd+"='gmail'");
oStmt = oConn.prepareStatement("SELECT "+DB.gu_pwd+" FROM "+DB.k_user_pwd+" WHERE "+DB.gu_user+"=? AND "+DB.id_pwd+"='gmail'",
ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
oStmt.setString(1, sUser);
oRSet = oStmt.executeQuery();
if (oRSet.next())
oPrec.load(oConn, oRSet.getString(1));
oRSet.close();
oStmt.close();
if (oPrec.getValueOf("cal")==null)
oPrec = new PasswordRecord();
else if (oPrec.getValueOf("cal").length()==0)
oPrec = new PasswordRecord();
if (oCache!=null) oCache.put(sUser+"[gmail]", oPrec);
} else {
if (DebugFile.trace)
DebugFile.writeln("cache hit for GMail account of user "+sUser);
}
if (oPrec.lines().size()>0) {
if (DebugFile.trace)
DebugFile.writeln("CalendarService.setUserCredentials("+oPrec.getValueOf("user")+", ...)");
oCalSrv.setUserCredentials(oPrec.getValueOf("user"), oPrec.getValueOf("pwd"));
URL feedUrl = new URL("https://www.google.com/calendar/feeds/default/allcalendars/full");
CalendarFeed oFeed = oCalSrv.getFeed(feedUrl, CalendarFeed.class);
for (int i = 0; i < oFeed.getEntries().size() && !bCalendarFound; i++) {
CalendarEntry oCalendar = oFeed.getEntries().get(i);
bCalendarFound = oCalendar.getTitle().getPlainText().equals(oPrec.getValueOf("cal"));
} // next
if (bCalendarFound) {
sEMail = oPrec.getValueOf("user");
} else {
if (oCache!=null) {
oCache.expire(sUser+"[gmail]");
oCache.put(sUser+"[gmail]", new PasswordRecord());
}
}
} // fi
if (DebugFile.trace) {