Hi All,
I came through this scenario.
Scenario : A request is submitted by the Requester or User to get access through OIM. Once the request is submitted by the user, either user/Manager/Higher Administrator should be able to approve the request untill manager does not approve the request.Once the request is approved by manager,no one should be able to edit the request.
Steps and JAVA Code :
Assumption: Approval with multi-level approvals already exists for the Resource XXX.
1. Create a jar from the below code and place it into OIM_HOME/xellerate/JavaTasks
a. Import XML TaskAdapter.xml(Email me if you need this file)(Creation of Adapters)
2. Modify the Object Form (Design Console -> Development Tools -> Form Designer).
a. Add two String type fields into it and specify any :
i. Response
ii. RequestId
b. Make these two fields hidden from “Properties” Tab
c. Add any other fields as per requirement.
3. Modify the Approval Process for “XXX Resource Object”.
a. Create Task Named as “Update Request Id”
i. Attach adpCopyValue adapter and do the mapping as follows:
1. Input -> Request Info -> Request Id
2. Adapter Return Value -> Object Data -> RequestId
4. Go To Data Object Manager in Design Console and Search for Resource Object Form for Resource XXX.
a. In Pre-Update -> Assign -> adpRequestPermission adapter.
b. Do the mapping as follows:
i. ReqId -> Entity Field -> ResquestId (Field name will be as created in 2.a.ii)
ii. Adapter Return Value -> Entity Field -> Response (Field name will be as created in 2.a.i)
5. Error Message is “ADAPTER.PERMISSION.ERROR”. You can change the description of the error as per requirement. (Design Conole -> Development Tools -> Error Message Definition and search for “ADAPTER.PERMISSION.ERROR” as code key)
JAVA CODE :
package com.requestmodify.adapter;
import java.util.HashMap;
import java.util.Hashtable;
import Thor.API.tcResultSet;
import Thor.API.tcUtilityFactory;
import Thor.API.Operations.tcRequestOperationsIntf;
import Thor.API.Operations.tcUserOperationsIntf;
import com.thortech.util.logging.Logger;
import com.thortech.xl.crypto.tcCryptoUtil;
import com.thortech.xl.crypto.tcSignatureMessage;
import com.thortech.xl.util.config.ConfigurationClient;
public class RequestModifyPermisions {
public static Logger logger = Logger.getLogger("UPDATE.LOGGERS");
String response = null;
HashMap requestAssignMap = new HashMap();
HashMap requestMap = new HashMap();
HashMap userMap = new HashMap();
int countRequestAssignedToUser;
long managerKey;
ConfigurationClient.ComplexSetting config = ConfigurationClient.getComplexSettingByPath("Discovery.CoreServer");
final Hashtable env = config.getAllSettings();
public String modifyRequest(String reqId) {
logger.debug("reqId :: " + reqId);
try {
tcSignatureMessage moSignature = tcCryptoUtil.sign("xelsysadm","PrivateKey");
tcUtilityFactory utilityFactory = new tcUtilityFactory(env, moSignature);
tcRequestOperationsIntf requestIntf = (tcRequestOperationsIntf)utilityFactory.getUtility("Thor.API.Operations.tcRequestOperationsIntf");
requestMap.put("Requests.Request ID", reqId);
tcResultSet requestResultSet = requestIntf.getRequestTargets(Long.parseLong(reqId));
requestResultSet.goToRow(0);
String targetUser = requestResultSet.getStringValue("Users.User ID");
logger.debug("targetUser :: " + targetUser);
userMap.put("Users.User ID", targetUser);
tcUserOperationsIntf userOperationsIntf = (tcUserOperationsIntf)utilityFactory.getUtility("Thor.API.Operations.tcUserOperationsIntf");
tcResultSet findUserSet = userOperationsIntf.findAllUsers(userMap);
findUserSet.goToRow(0);
managerKey = findUserSet.getLongValue("Users.Manager Key");
logger.debug("managerKey :: " + managerKey);
tcResultSet requestAssignedToUser = requestIntf.getApprovalTasksAssignedToUser(managerKey, requestMap);
countRequestAssignedToUser = requestAssignedToUser.getRowCount();
logger.debug("countRequestAssignedToUser :: " + countRequestAssignedToUser);
if(countRequestAssignedToUser == 1 ){
response = "SUCCESS";
} else {
response = "FAILURE";
}
} catch (Exception e) {
logger.error("Exceprion in modifyRequest :: ", e);
}
logger.debug("response :: " + response);
return response;
}
}