use of com.tremolosecurity.provisioning.core.providers.BasicDBInterface in project OpenUnison by TremoloSecurity.
the class Drupal7GetSequence method doTask.
@Override
public boolean doTask(User user, Map<String, Object> request) throws ProvisioningException {
try {
if (logger.isDebugEnabled()) {
logger.debug("Searching for users.id");
logger.debug("Looking for user : '" + user.getUserID() + "'");
}
User looking = task.getConfigManager().getProvisioningEngine().getTarget(this.targetName).findUser(user.getUserID(), new HashMap<String, Object>());
if (logger.isDebugEnabled()) {
logger.debug("User object : '" + looking + "'");
}
if (looking == null) {
if (logger.isDebugEnabled()) {
logger.debug("User not found");
}
}
if (looking != null) {
if (logger.isDebugEnabled()) {
logger.debug("User found, setting to user id : '" + looking.getAttribs().get("uid").getValues().get(0) + "'");
}
user.getAttribs().put("drupalid", new Attribute("drupalid", looking.getAttribs().get("uid").getValues().get(0)));
return true;
}
} catch (ProvisioningException pe) {
// do nothing
pe.printStackTrace();
}
UserStoreProvider provider = task.getConfigManager().getProvisioningEngine().getTarget(this.targetName).getProvider();
BasicDBInterface dbprovider = (BasicDBInterface) provider;
Connection con = null;
try {
if (logger.isDebugEnabled()) {
logger.debug("Getting Connection");
}
con = dbprovider.getDS().getConnection();
if (logger.isDebugEnabled()) {
logger.debug("Preparing Statement");
}
PreparedStatement ps = con.prepareStatement("INSERT INTO sequences () VALUES ()", Statement.RETURN_GENERATED_KEYS);
if (logger.isDebugEnabled()) {
logger.debug("Executing Statement");
}
ps.executeUpdate();
if (logger.isDebugEnabled()) {
logger.debug("Getting key");
}
ResultSet rs = ps.getGeneratedKeys();
rs.next();
int id = rs.getInt(1);
if (logger.isDebugEnabled()) {
logger.debug("ID: '" + id + "'");
}
rs.close();
ps.close();
user.getAttribs().put("drupalid", new Attribute("drupalid", Integer.toString(id)));
return true;
} catch (SQLException e) {
throw new ProvisioningException("Could not generate userid", e);
} finally {
if (con != null) {
try {
logger.info("Closing connection");
con.close();
} catch (Exception e1) {
// do nothing
}
}
}
}
Aggregations