public static Role getRole( String name, int roleType, boolean autoCreate, ServiceContext serviceContext) throws PortalException { Role role = null; try { role = RoleLocalServiceUtil.getRole( serviceContext.getCompanyId(), name); if (role.getType() != roleType) { throw new DuplicateRoleException( "Role already exists with name " + name); } } catch (NoSuchRoleException nsre) { if (!autoCreate) { throw nsre; } Map<Locale, String> descriptionMap = new HashMap<>(); descriptionMap.put( LocaleUtil.getDefault(), "This is an autogenerated role from the workflow definition."); role = RoleLocalServiceUtil.addRole( serviceContext.getUserId(), null, 0, name, null, descriptionMap, roleType, null, null); } return role; }