How we can use cloudPreviousValues in JDBC rule?
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Types;
import java.util.List;
import java.util.ArrayList;
import sailpoint.api.SailPointContext;
import sailpoint.connector.JDBCConnector;
import sailpoint.object.Application;
import sailpoint.object.ProvisioningPlan;
import sailpoint.object.ProvisioningPlan.AccountRequest;
import sailpoint.object.ProvisioningPlan.AttributeRequest;
import sailpoint.object.ProvisioningPlan.PermissionRequest;
import sailpoint.object.ProvisioningResult;
import sailpoint.object.Schema;
public String getAttributeRequestValue(AccountRequest acctReq, String attribute) {
if (acctReq != null) {
AttributeRequest attrReq = acctReq.getAttributeRequest(attribute);
if (attrReq != null) {
return attrReq.getValue();
}
}
return null;
}
ProvisioningResult result = new ProvisioningResult();
PreparedStatement statement;
if (plan != null) {
List accounts = plan.getAccountRequests();
if ((accounts != null) && (accounts.size() > 0)) {
for (AccountRequest account: accounts) {
try {
if (AccountRequest.Operation.Create.equals(account.getOperation())) {
log.error("Create EPIP account");
statement = connection.prepareStatement("insert into LUsers (PGUID,Email,FirstName,LastName,CreatedDate,Isactive) values (?,?,?,?,CURRENT_TIMESTAMP,1)");
statement.setString(1, account.getNativeIdentity());
statement.setString(2, getAttributeRequestValue(account, "Email"));
statement.setString(3, getAttributeRequestValue(account, "FirstName"));
statement.setString(4, getAttributeRequestValue(account, "LastName"));
statement.executeUpdate();
result.setStatus(ProvisioningResult.STATUS_COMMITTED);
} else if (AccountRequest.Operation.Modify.equals(account.getOperation())) {
String nativeID = account.getNativeIdentity();
log.error("Modify EPIP account for Native ID::: " + nativeID);
List attributeRequests = account.getAttributeRequests();
if (attributeRequests != null && attributeRequests.size() > 0) {
for (ProvisioningPlan.AttributeRequest attrRequest: attributeRequests) {
log.error("Attr Req name::: " + attrRequest.getName());
if (attrRequest.getName().equals("IsActive")) {
log.error("Found attrequest for IsActive..");
PreparedStatement statement = connection.prepareStatement("update LUsers set Isactive = ? where PGUID= ?");
statement.setString(2, nativeID);
statement.setString(1, getAttributeRequestValue(account, "IsActive"));
log.error("Executing update IsActive attr sync...");
statement.executeUpdate();
} else if (attrRequest.getName().equals("EPIP_Status")) {
log.error("Found attrequest for EPIP_Status..");
log.error("Attr getOperation::: " + attrRequest.getOperation());
if (attrRequest.getOperation().toString().equalsIgnoreCase("add")) {
log.error("Found attrequest for EPIP_Status Add..");
PreparedStatement statement = connection.prepareStatement("update LUsers set Isactive = 1 where PGUID= ?");
statement.setString(1, nativeID);
log.error("Executing update EPIP_Status Add...");
statement.executeUpdate();
} else if (attrRequest.getOperation().toString().equalsIgnoreCase("remove")) {
log.error("Found attrequest for EPIP_Status Remove..");
PreparedStatement statement = connection.prepareStatement("update LUsers set Isactive = 0 where PGUID= ? ");
statement.setString(1, nativeID);
log.error("Executing update EPIP_Status remove...");
statement.executeUpdate();
}
}
}
} else {
log.error("Attribute requests null or empty.");
}
log.error("Provisioning successful.");
result.setStatus(ProvisioningResult.STATUS_COMMITTED);
}
} catch (SQLException e) {
result.setStatus(ProvisioningResult.STATUS_FAILED);
result.addError(e);
} finally {
if (statement != null) {
statement.close();
}
}
}
}
}
return result;
"