Tuesday 19 December 2017

OIM API - Code snippet to get Application Instance from OIM for the given Application Instance Name.


Using Search Criteria:

public ApplicationInstance getApplicationInstance(String appIntName){
        final String logp = CN + "::
getApplicationInstance - ";
        LOGGER.debug(logp + "START");

        if(null == appIntName || appIntName.trim().length() == 0){
                LOGGER.error(logp + "Application Instance name is null or empty");
                return null;
        }
        appIntName = appIntName.trim();

        ApplicationInstance appInst = null;
        try{
            SearchCriteria criteria = new SearchCriteria(ApplicationInstance.APPINST_NAME, appIntName, SearchCriteria.Operator.EQUAL);
           
            //get application instance service
            ApplicationInstanceService appInstService = Platform.getService(ApplicationInstanceService.class);
            List<ApplicationInstance> appInstList = appInstService.findApplicationInstance(criteria, null);

            if(appInstList.size() == 0 || appInstList.size() > 1) {
                LOGGER.error(logp + "Improper number of ApplicationInstance found in OIM for Application Instance name " + appIntName + " - " + appInstList.size());
            }else{
                appInst = appInstList.get(0);


                LOGGER.info(logp + "Successfully obtained ApplicationInstance - " + appInst);
                LOGGER.info(logp + "Application Instance Key :: " + appInst.getApplicationInstanceKey());
                LOGGER.info(logp + "Display Name :: " + appInst.getDisplayName());
                LOGGER.info(logp + "Application Instance Name :: " + appInst.getApplicationInstanceName());
            }
        }catch(Exception e) {
                LOGGER.error(logp + "Exception while fetching ApplicationInstance for Application Instance name " + appIntName + " - " + e, e);
        }

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


Without Search Criteria:

public ApplicationInstance getApplicationInstance(String applicationInstanceName) throws Exception{
        //get application instance service
        ApplicationInstanceService service= Platform.getService(ApplicationInstanceService.class);
      
        ApplicationInstance appInstance = service.findApplicationInstanceByName(applicationInstanceName);
       
        System.out.println("Display Name :: " + appInstance.getDisplayName());


        System.out.println("Application Instance Name :: " + appInstance.getApplicationInstanceName());


        System.out.println("Application Instance Key :: " + appInstance.getApplicationInstanceKey());
        return appInstance;
 }


Happy Learning!!!

No comments:

Post a Comment