<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title>Answers to: How to check whether role is obsolete?</title><link>https://answers.axonivy.com/questions/1191/how-to-check-whether-role-is-obsolete</link><description>&lt;p&gt;I have some roles in application which are obsolete because the pmv they belong to is deleted or archived. So my question is how to check these roles whether are obsolete, do we have API to to it?
Thanks for your interested&lt;/p&gt;</description><atom:link href="https://answers.axonivy.com/questions/1191/how-to-check-whether-role-is-obsolete" rel="self"></atom:link><language>en</language><lastBuildDate>Wed, 29 Jul 2015 09:41:21 -0400</lastBuildDate><item><title>Comment by lttung on Reguel Wermelinger's answer</title><link>https://answers.axonivy.com/questions/1191/how-to-check-whether-role-is-obsolete#1418</link><description>&lt;p&gt;Thanks for your suggestion. It works for us.
Could you please consider to put ch.ivyteam.ivy.user.role_xxx.jar to designer classpath or provide another API in next release so that we do not need to add external jar on designer?&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">lttung</dc:creator><pubDate>Wed, 29 Jul 2015 09:41:21 -0400</pubDate><guid>https://answers.axonivy.com/questions/1191/how-to-check-whether-role-is-obsolete#1418</guid></item><item><title>Answer by Reguel Wermelinger</title><link>https://answers.axonivy.com/questions/1191/how-to-check-whether-role-is-obsolete/1203</link><description>&lt;p&gt;Its basically possible if you analyze the RoleConfiguration-Model of active PMVs in an application. The problem is, that the classes are not available in the designer. But you could use them if you add the jar from the engine to classpath (lib/ivy/ch.ivyteam.ivy.user.role_xxx.jar). &lt;/p&gt;
&lt;p&gt;I've wrote a sample snip which reads the already deployed role configurations of an app. Don't asume that it is 100% correct and fancy. But you get a hint which APIs that are relevant.&lt;/p&gt;
&lt;p&gt;&lt;img alt="alt text" src="http://answers.axonivy.com/upfiles/deployedRoleConfigReader.png"&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;package ch.ivyteam.test;

import java.util.ArrayList;
import java.util.EnumSet;
import java.util.List;
import java.util.Set;

import org.eclipse.core.resources.IProject;

import ch.ivyteam.ivy.application.ActivityState;
import ch.ivyteam.ivy.application.IProcessModel;
import ch.ivyteam.ivy.application.IProcessModelVersion;
import ch.ivyteam.ivy.application.ReleaseState;
import ch.ivyteam.ivy.environment.Ivy;
import ch.ivyteam.ivy.project.IIvyProject;
import ch.ivyteam.ivy.resource.datamodel.ResourceDataModelException;
import ch.ivyteam.ivy.role.IRole;
import ch.ivyteam.ivy.role.IRoleConfiguration;

public class ReadPmvRoles {

    public static void readAndLog() {
        for (IProcessModelVersion pmv : getPmvs()) {
            IRoleConfiguration roleConfig = getRoleConfiguration(pmv);
            List&amp;lt;String&amp;gt; roleIds = getRoleIds(roleConfig);
            Ivy.log().info(pmv+":"+roleIds);
        }
    }

    private static List&amp;lt;String&amp;gt; getRoleIds(IRoleConfiguration roleConfig) {
        List&amp;lt;String&amp;gt; roles = new ArrayList&amp;lt;&amp;gt;();
        IRole rootRole = roleConfig.getRootRole();
        roles.add(rootRole.getIdentifier());
        for(IRole childRole : rootRole.getSubRoles())
        {
            roles.add(childRole.getIdentifier());
        }
        return roles;
    }

    private static IRoleConfiguration getRoleConfiguration(IProcessModelVersion pmv) {
        IIvyProject project = (IIvyProject) pmv.getProject().getAdapter(
                IIvyProject.class);
        try {
            Set&amp;lt;IRoleConfiguration&amp;gt; roles = project.getProjectRoleConfigurationManager().getRoleModels(null);
            return roles.iterator().next();
        } catch (ResourceDataModelException ex) {
            throw new RuntimeException("can not read role config of " + pmv);
        }
    }

    private static List&amp;lt;IProcessModelVersion&amp;gt; getPmvs() {
        List&amp;lt;IProcessModelVersion&amp;gt; activePmvs = new ArrayList&amp;lt;&amp;gt;();
        List&amp;lt;IProcessModel&amp;gt; models = Ivy.request().getApplication().getProcessModels();
        for (IProcessModel model : models) {
            for (IProcessModelVersion pmv : model.getProcessModelVersions()) {
                EnumSet&amp;lt;ReleaseState&amp;gt; runningTaskStates = EnumSet.of(
                        ReleaseState.RELEASED, ReleaseState.DEPRECATED);
                if (runningTaskStates.contains(pmv.getReleaseState())) {
                    activePmvs.add(pmv);
                }
            }
        }
        return activePmvs;
    }

}
&lt;/code&gt;&lt;/pre&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Reguel Wermelinger</dc:creator><pubDate>Thu, 05 Mar 2015 11:24:57 -0500</pubDate><guid>https://answers.axonivy.com/questions/1191/how-to-check-whether-role-is-obsolete/1203</guid></item><item><title>Answer by Tamas KIS</title><link>https://answers.axonivy.com/questions/1191/how-to-check-whether-role-is-obsolete/1198</link><description>&lt;p&gt;currently it's not possible.&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Tamas KIS</dc:creator><pubDate>Wed, 04 Mar 2015 16:44:54 -0500</pubDate><guid>https://answers.axonivy.com/questions/1191/how-to-check-whether-role-is-obsolete/1198</guid></item></channel></rss>