Thursday, 29 March 2018

OIM API - Code Snippet to get the IT Resource Key by the IT Resource Name.

  public long getITResourceKeyByITResourceName(String itResName){
        final String logp = CN + " :: getITResourceKeyByITResourceName() - ";
        logger.info(logp + "START");
        long itResKey = 0L;
        tcITResourceInstanceOperationsIntf itResourceInstOps = null;
       
        if (null == itResName || itResName.isEmpty()){
            return itResKey;
        }
       
        try {
            HashMap<String, String> itMap = new HashMap<String, String>();
            itMap.put("IT Resources.Name", itResName);

            itResourceInstOps = Platform.getService(Thor.API.Operations.tcITResourceInstanceOperationsIntf.class);

            tcResultSet itRS = itResourceInstOps.findITResourceInstances(itMap);

            LOGGER.debug(logp + "Number of IT resources found for " + itResName + " = " + itRS.getRowCount());

            if (!itRS.isEmpty() && itRS.getRowCount() == 1) {
                itRS.goToRow(0);
                itResKey = itRS.getLongValue("IT Resource.Key");      
            }
        }catch(Exception e) {
            LOGGER.error(logp + "Exception while getting IT Resource Key for - " + itResName + " :: " + e, e);
        } finally {
            if (null != itResourceInstOps) {
                itResourceInstOps.close();
            }
        }
        logger.info(logp + "IT Resource Key : " + itResKey);
        logger.info(logp + "END");
        return itResKey;
  }


Happy Learning!!!

No comments:

Post a Comment