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

asked 03.03.2015 at 12:24

hungnam's gravatar image

hungnam
(suspended)
accept rate: 0%


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).

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.

alt text

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<String> roleIds = getRoleIds(roleConfig);
            Ivy.log().info(pmv+":"+roleIds);
        }
    }

    private static List<String> getRoleIds(IRoleConfiguration roleConfig) {
        List<String> roles = new ArrayList<>();
        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<IRoleConfiguration> 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<IProcessModelVersion> getPmvs() {
        List<IProcessModelVersion> activePmvs = new ArrayList<>();
        List<IProcessModel> models = Ivy.request().getApplication().getProcessModels();
        for (IProcessModel model : models) {
            for (IProcessModelVersion pmv : model.getProcessModelVersions()) {
                EnumSet<ReleaseState> runningTaskStates = EnumSet.of(
                        ReleaseState.RELEASED, ReleaseState.DEPRECATED);
                if (runningTaskStates.contains(pmv.getReleaseState())) {
                    activePmvs.add(pmv);
                }
            }
        }
        return activePmvs;
    }

}
link

answered 05.03.2015 at 11:24

Reguel%20Wermelinger's gravatar image

Reguel Werme... ♦♦
9.4k31958
accept rate: 70%

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?

(29.07.2015 at 09:41) lttung lttung's gravatar image

currently it's not possible.

link

answered 04.03.2015 at 16:44

Tamas%20KIS's gravatar image

Tamas KIS
(suspended)
accept rate: 60%

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "Title")
  • image?![alt text](/path/img.jpg "Title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×14

Asked: 03.03.2015 at 12:24

Seen: 2,465 times

Last updated: 04.08.2015 at 13:21