protected void execute() { logger.info(connectorName + ": Starting task."); // //Get the tcGroupOperationsIntf object // try { // moGroupUtility = (tcGroupOperationsIntf)super.getUtility("Thor.API.Operations.tcGroupOperationsIntf"); // } catch (tcAPIException e) { // logger.error(connectorName + ": Unable to get an instance of tcGroupOperationsIntf"); // return; // } // // //Get the tcUserOperationsIntf object // try { // moUserUtility = (tcUserOperationsIntf)super.getUtility("Thor.API.Operations.tcUserOperationsIntf"); // } catch (tcAPIException e) { // logger.error(connectorName + ": Unable to get an instance of tcUserOperationsIntf"); // return; // } // Process changes in Grouper sequentially ResultSet rs = null; PreparedStatement psSelect = null; PreparedStatement psDelete = null; PreparedStatement psUpdateToFailure = null; try { ldapConnectionWrapper = new LDAPConnectionWrapper(DEBUG); grouperConn = getGrouperConnection(); psDelete = grouperConn.prepareStatement("DELETE FROM "+userName+".grp_event_log_for_oim WHERE consumer = 'grouper_ldap' AND record_id=?"); psSelect = grouperConn.prepareStatement("SELECT record_id, group_name, action, field_1, status FROM "+userName+".grp_event_log_for_oim WHERE consumer = 'grouper_ldap' ORDER BY record_id"); psUpdateToFailure = grouperConn.prepareStatement("UPDATE "+userName+".grp_event_log_for_oim SET status='FAILED' where consumer = 'grouper_ldap' AND record_id=?"); rs = psSelect.executeQuery(); while (rs.next()) { long recordId = rs.getLong(1); String groupName = rs.getString(2); String action = rs.getString(3); String field1 = rs.getString(4); String status = rs.getString(5); if (status.equals("FAILED")) { updateFailures(action, groupName, field1); continue; } groupName = urnizeGroupName(groupName); // If an add_member or delete_member fails, we won't process anymore events for that user. // If a create, delete, or rename fails, we won't process anymore events for that group. if (mustSkipUserOrGroup(action, groupName, field1)) { logger.warn(connectorName + ": Skipping record " + recordId + " due to a previous failure with another record with the same user or group."); continue; } // this part is going to be in a separate try-catch block because // if an individual update fails, we don't want to stop processing boolean isSuccess = false; try { if (action.equals("create")) { processCreate(groupName); } else if (action.equals("delete")) { processDelete(groupName); } else if (action.equals("rename")) { processRename(groupName, field1); } else if (action.equals("add_member")) { processAddMember(groupName, field1); } else if (action.equals("delete_member")) { processDeleteMember(groupName, field1); } else { throw new Exception("Unknown action for record id " + recordId); } // If we get here, then the OIM update succeeded. isSuccess = true; } catch (Exception e2) { logger.error(connectorName + ": Error while processing record " + recordId + ".", e2); } if (isSuccess) { // remove the event from the grouper db psDelete.setLong(1, recordId); psDelete.executeUpdate(); } else { // mark the event as failed psUpdateToFailure.setLong(1, recordId); psUpdateToFailure.executeUpdate(); updateFailures(action, groupName, field1); } } } catch (Exception e) { logger.error(connectorName + ": Error while running connector.", e); } finally { if (rs != null) { try { rs.close(); } catch (SQLException e) { // this is okay } } if (psSelect != null) { try { psSelect.close(); } catch (SQLException e) { // this is okay } } if (psDelete != null) { try { psDelete.close(); } catch (SQLException e) { // this is okay } } if (psUpdateToFailure != null) { try { psUpdateToFailure.close(); } catch (SQLException e) { // this is okay } } if (grouperConn != null) { try { grouperConn.close(); } catch (SQLException e) { // this is okay } } if (moGroupUtility != null) { moGroupUtility.close(); } if (moUserUtility != null) { moUserUtility.close(); } } logger.info(connectorName + ": Ending task."); }