Sunday 1 April 2018

OIM API - Code Snippet to Publish Entity to given Organization.

public void publishEntityToOrganization(String entityKey, String type, String targetOrgName, boolean includeSubOrgs) {
    final String logp = CN + " :: publishEntityToOrganization - ";
    LOGGER.debug(logp + "START");

    try {
        PolicyConstants.Resources resourceType = null;

        if("Entitlement".equalsIgnoreCase(type)){
            resourceType = PolicyConstants.Resources.IT_RESOURCE_ENTITLEMENT;
        }else if("Application Instance".equalsIgnoreCase(type)) {
            resourceType = PolicyConstants.Resources.APPLICATION_INSTANCE;
        }else{
            LOGGER.error(logp + "Invalid entity type - " + type);
            throw new Exception("Invalid entity type - " + type);
        }

        List<EntityPublication> newPubList = new ArrayList<EntityPublication>();

        Organization org = orgManager.getDetails("Organization Name", targetOrgName, null);

        EntityPublication entPub = new EntityPublication(entityKey, resourceType, Long.valueOf(org.getEntityId()), includeSubOrgs);
        entPub.setEntityType(type);

        newPubList.add(entPub);
       
        //publish entity to organization
        entityPubService.addEntityPublications(newPubList);
        LOGGER.debug(logp + "Successfully published...");
       
    }catch(Exception e){
            LOGGER.error(logp + "Exception while publishing entity to organization");
    }

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


Happy Learning!!!

2 comments:

  1. What is the value of type that is passed as an input parameter for the function publishEntityToOrganization??

    Is entityKey passed as an input parameter for the function publishEntityToOrganization is user key??

    ReplyDelete
    Replies
    1. Yes, we need to pass entity key and entity type to this method.

      For example:
      Entity Key = 1
      Entity Type = "Application Instance"

      Entity Key = 1
      Entity Type = "Entitlement"

      Entity Type is also required because two entities may have the same entity key with different entity type.

      Delete