cloudPreviousValues in JDBC rule

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;
"

Hi @Manju22,

can you elaborate regarding cloudPreviousValue thing. What exactly you’re looking for?

Thank You.

@gogubapu I like to read the “cloudPreviousValues” attribute value from Provisioning Plan and update the pervious and new value into another table using insert.

can you confirm this attribute is identity attribute or account attribute

Hi @gogubapu,

Attribute “cloudPreviousValue” is just ISC representation of old values of attributes of your schema.

If there is any change it the attributes, then the old values will be present in this list.

Thanks

I want to use Attributes → cloudPreviousValues and AttributeRequest → name and update them as newvalue and oldvalue as below.

PGUID Field OldValue NewValue
Hekm IsActive TRUE 0
Hekm LastName Internal_8826 Heck

Hi @Manju22,

I think in JDBC provisioning rule unable get identity data, but we can do one thing to get old values, execute single user query then get last name from the user. use the old values for providing, find below code to get user account old values.

     String lastname="";
    String Isactive = "";
    
try 
{ 
	PreparedStatement stmt = connection.prepareStatement("single account fetch query");

     // Set the input parameter 
     stmt.setString(1, userId); 

     // Execute the query 
     ResultSet rs = stmt.executeQuery();

     // Print the user data
    while(rs.next()) 
	{ 
        log.info(\"============lastname===================\");
		lastname = rs.getString(\"lastname\"); 
    } 
} 
catch (Exception e) 
{ 
    // Handle SQL exception 
	log.info(\"======Error=======\"+e); 
} 

I Hope this will helps you.

Am looking for similar thing like this in JDBC rule.

Hi @Manju22,

You may try below method to get object values.

Map cloudPreviousValues = new HashMap();
cloudPreviousValues.putAll(AccountRequest.get(“Attributes”));

Thank You.

1 Like

As you are iterating AccountRequests, you can call
Map cloudPreviousValues = account.getArgument("cloudPreviousValues")
to retrieve that HashMap

Hi @Manju22,

Find below code snippet to get cloudPreviousValues:

 if (accounts != null) {
	//print first account Request using below // Get the first AccountRequest
	AccountRequest accountRequest = accounts.get(0);
	// Use getArguments() to get attributes
	Map cloudPreviousValues = accountRequest.getArguments();
	log.info("----=cloudPreviousValues=====  "+cloudPreviousValues);
	Map values=cloudPreviousValues.get("cloudPreviousValues");
	String lastname=values.get("LastName");
	log.info("----======  "+values);
	} else {
		log.info("No account requests found.");
	}

Thank You.

1 Like