Showing posts with label Bundle. Show all posts
Showing posts with label Bundle. Show all posts

Sunday, March 7, 2021

Sailpoint IdentityIQ Creating Business Role Using API

 Creating Business Role Using API

public static void buildRole(HashMap lineHash) {
		 
		String roleName = lineHash.get("RoleName").toString();
		String roleType = lineHash.get("RoleType").toString();
		String locCity = lineHash.get("locCity").toString();
		String coNumber = lineHash.get("coNumber").toString();
		
		System.out.println("locCity " + locCity );
		System.out.println("coNumber " + coNumber );
		
		//Added
		String displayName = lineHash.get("displayName").toString();
		String subRoleName = lineHash.get("requiredRole").toString();

		
		String roleOwner = "";
		String roleExists = "yes";
		Bundle role;
		System.out.println("Data " + lineHash );
		try {
		    role = context.getObject(Bundle.class, roleName);
			if (null == role) {
				role = new sailpoint.object.Bundle();
				roleExists = "no";
			}
			if (roleType.equalsIgnoreCase("business") && roleExists.equalsIgnoreCase("no")) {
				System.out.println("Creating Role :" + roleName );
				AccountSelectorRules rules = new AccountSelectorRules();
				role.setAccountSelectorRules(rules);
				
				HashMap mapDesc = new HashMap();
				mapDesc.put("en_US", "This is the BR " + roleName);
				
				Identity ownerId = context.getObject(Identity.class, roleOwner);
				if (null == ownerId) {
					ownerId = context.getObject(Identity.class, "spadmin");
				}
				role.setName(roleName);
				role.setDescriptions(mapDesc);
				role.setType("business");
				role.setAllowDuplicateAccounts(false);
				role.setAllowMultipleAssignments(false);
				role.setMergeTemplates(false);
				role.setOwner(ownerId);
				
				//Added
				role.setDisplayName(displayName);
				Bundle requiredRole = context.getObjectByName(Bundle.class, subRoleName);
				role.addRequirement(requiredRole);			

				IdentitySelector is = new IdentitySelector();
				MatchExpression me = new MatchExpression();
				me.setAnd(false);

				MatchTerm term = new MatchTerm();
				MatchTerm term1 = new MatchTerm();
				MatchTerm term2 = new MatchTerm();
				
				if((!(locCity.equalsIgnoreCase(""))) && (!(coNumber.equalsIgnoreCase("")))){
				
				term1.setName("locCity");
				term1.setValue(locCity);
				term.addChild(term1);
				
				term2.setName("coNumber");
				term2.setValue(coNumber);
				term.addChild(term2);
				
				term.setAnd(true);
				term.setContainer(true);
				me.addTerm(term);
				
				}else if(locCity.equalsIgnoreCase("")){
				
				term2.setName("coNumber");
				term2.setValue(coNumber);
				me.addTerm(term2);
				}else if(coNumber.equalsIgnoreCase("")){
				term2.setName("locCity");
				term2.setValue(locCity);
				me.addTerm(term2);
				}
				
				is.setMatchExpression(me);
				role.setSelector(is);
				context.saveObject(role);
				context.commitTransaction();
				context.decache();
			
			}else if(roleType.equalsIgnoreCase("business") && roleExists.equalsIgnoreCase("yes")){			
			    
				IdentitySelector is = role.getSelector();
				MatchExpression me = is.getMatchExpression();
				MatchTerm term = new MatchTerm();
				MatchTerm term1 = new MatchTerm();
				MatchTerm term2 = new MatchTerm();

				if((!(locCity.equalsIgnoreCase(""))) && (!(coNumber.equalsIgnoreCase("")))){
				
				term1.setName("locCity");
				term1.setValue(locCity);
				term.addChild(term1);
				
				term2.setName("coNumber");
				term2.setValue(coNumber);
				term.addChild(term2);
				
				term.setAnd(true);
				term.setContainer(true);
				me.addTerm(term);
				}else if(locCity.equalsIgnoreCase("")){		
				term2.setName("coNumber");
				term2.setValue(coNumber);
				me.addTerm(term2);
				}else if(coNumber.equalsIgnoreCase("")){
				term2.setName("locCity");
				term2.setValue(locCity);
				me.addTerm(term2);
				}
				
				is.setMatchExpression(me);
				role.setSelector(is);
				
				context.saveObject(role);
				context.commitTransaction();
				context.decache();
			} else{
			
			System.out.println("Doing Nothing !" );
			
			}
		} catch (GeneralException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		}