Friday, 23 March 2018

OIM API - Code Snippet to Read ITResource Data for the given ITResource Name.

public Map<String, String> getITResourceMap(String itResName) {
        final String logp = CN + " :: getITResourceMap - ";
        LOGGER.debug(logp + "START");
        Map<String, String> itResourceMap = new HashMap<String, String>();
        Thor.API.Operations.tcITResourceInstanceOperationsIntf itResourceInstOps = null;
       
        if (null == itResName || itResName.isEmpty()) {
                return null;
        }
       
        LOGGER.info(logp + "IT resources Name :: " + itResName);
   
        try {
            HashMap<String, String> itMap = new HashMap<String, String>();
            itMap.put("IT Resources.Name", itResName);
            itResourceInstOps = Platform.getService(
tcITResourceInstanceOperationsIntf.class);
       
            tcResultSet itRS = itResourceInstOps.findITResourceInstances(itMap);
            LOGGER.info(logp + "Number of IT resources found for " + itResName + " = " + itRS.getRowCount());

            if (!itRS.isEmpty() && itRS.getRowCount() == 1) {
                itRS.goToRow(0);
                long itKey = itRS.getLongValue("IT Resource.Key");
                itRS = itResourceInstOps.getITResourceInstanceParameters(itKey);
                String name, value;
                for (int i = 0; i < itRS.getRowCount(); i++) {
                    itRS.goToRow(i);
                    name = itRS.getStringValue("IT Resources Type Parameter.Name");
                    value = itRS.getStringValue("IT Resources Type Parameter Value.Value");
                    itResourceMap.put(name, value);
                }
            }
        } catch (Exception e) {
            LOGGER.error("Exception while getting IT Resource details. " + e);
        } finally {
            if (null != itResourceInstOps) {
                itResourceInstOps.close();
                LOGGER.info(logp + "tcITResourceInstanceOperationsIntf instance closed successfully.");
            }
        }

        LOGGER.debug(logp + "END");
        return itResourceMap;
 }


Happy Learning!!!

No comments:

Post a Comment