Saturday, January 8, 2022

Rule to read a custom object and insert values into Database table

The custom object contain a hashmap with list of values. Read the list and insert into DB table.


import org.apache.log4j.Logger;
import org.apache.log4j.Level;
import sailpoint.object.Custom;
import sailpoint.plugin.PluginBaseHelper;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.HashMap;
import java.util.List;


Logger log = Logger.getLogger("sailpoint.rules.InsertIntoDBTable");
log.setLevel(Level.DEBUG);
log.debug("-----------------------------------");

Custom customObj = context.getObject(Custom.class, "custom_object_name");
HashMap hashMap = customObj.getAttributes();
List list = hashMap.get("list_name");
Connection connection = PluginBaseHelper.getConnection();
log.debug("Connection established to DB: " + connection.getCatalog());
ResultSet resultSet = null;
PreparedStatement preparedStatement = null;

for(String value : list)
{
try {
String insertQuery = "INSERT INTO TABLE_NAME (COLUMN_NAME) VALUES(?);";
preparedStatement = connection.prepareStatement(insertQuery);
preparedStatement.setString(1, value);
log.debug("Executing the query: " + insertQuery);
resultSet = preparedStatement.execute()

} catch (Exception e) {
log.error("Exception occurred: " + e);
}
}
connection.close();

No comments:

Post a Comment

Form AllowedValues rule to filter Identities with Active Regular Active Directory accounts and identity is active and correlated

 The rule type is AllowedValues. import org.apache.log4j.Level ; import org.apache.log4j.Logger ; import sailpoint.object.Filter ; import sa...