Defining Roles
From Projectivity Documentation
Creating a new Role
Projectivity allows you to create new work roles so that you can exactly model your company. Following our Customer Management application we have to define the following roles:
- At the Company level
- CEO (cardinality: 1)
- Sales Director (cardinality: 1)
- Staff (cardinality: 0..*)
- At the Region level
- Country Manager (cardinality:1)
- Account Managers Group (cardinality:0..*)
- SalesMan (cardinality:0..*)
- At the Customer level
- Account Manager (cardinality:1)
The Framework Development SDK has a WorkRoleDTO object that allows you to create these roles in a very easy way:
// Create the roles for the Company Type WorkRoleDTO _roleCompanyCEO = new WorkRoleDTO(null, "CEO", "CEO", 1, 1); WorkRoleDTO _roleCompanySALESDIR = new WorkRoleDTO(null, "Sales Director", "Sales Director", 1, 1); WorkRoleDTO _roleCompanySTAFF = new WorkRoleDTO(null, "Staff", "Staff", 0, WorkRoleDTO.STAR_CARDINALITY); // Create the roles for the Region Type WorkRoleDTO _roleRegionCMNGR = new WorkRoleDTO(null, "Country Manager", "Country Manager", 1, 1); WorkRoleDTO _roleRegionAMNGRGR = new WorkRoleDTO(null, "Account Managers Group", "Account Managers Group", 0, WorkRoleDTO.STAR_CARDINALITY); WorkRoleDTO _roleRegionSALESM = new WorkRoleDTO(null, "Sales Man", "Sales Man", 0, WorkRoleDTO.STAR_CARDINALITY); // Create the roles for the Customer Type WorkRoleDTO _roleCustomerAMNGR = new WorkRoleDTO(null, "Account Manager", "Account Manager", 1, 1);
At this point we have created all the roles needed, and defined there cardinalities. The next step consists of associating these roles to their corresponding workspace type (or Scope Definitions).
Associating a Role to a Workspace Type
Having created the different roles required we need to associate them to their corresponding types. First, each role needs to know about the scope definition it corresponds to:
// Set the scope definition for the Company roles _roleCompanyCEO.setScopeDefinition(defNameCompany); _roleCompanySALESDIR.setScopeDefinition(defNameCompany); _roleCompanySTAFF.setScopeDefinition(defNameCompany); // Set the Scope Definition for the Region roles _roleRegionCMNGR.setScopeDefinition(defNameRegion); _roleRegionAMNGRGR.setScopeDefinition(defNameRegion); _roleRegionSALESM.setScopeDefinition(defNameRegion); // Set the Scope Definition for the Customer role _roleCustomerAMNGR.setScopeDefinition(defNameCustomer);
Now, and for each of these roles we need to create a ScopeDefinitionWorkRole Object that will fully encapsulate your work role and also define the implied security role for it. This security role will tell Projectivity what is the minimum access level required in a workspace to play this role (it will usually be OWNER).
ScopeDefinitionWorkRole roleCompanyCEO = new ScopeDefinitionWorkRole(_roleCompanyCEO, HumanResourceDTO.SecurityRole.OWNER, false, 1, 1); ScopeDefinitionWorkRole roleCompanySALESDIR = new ScopeDefinitionWorkRole(_roleCompanySALESDIR, HumanResourceDTO.SecurityRole.MEMBER, false, 1, 1); ScopeDefinitionWorkRole roleCompanySTAFF = new ScopeDefinitionWorkRole(_roleCompanySTAFF, HumanResourceDTO.SecurityRole.MEMBER, false, 0, WorkRoleDTO.STAR_CARDINALITY); ScopeDefinitionWorkRole roleRegionCMNGR = new ScopeDefinitionWorkRole(_roleRegionCMNGR, HumanResourceDTO.SecurityRole.OWNER, false, 1, 1); ScopeDefinitionWorkRole roleRegionAMNGRGR = new ScopeDefinitionWorkRole(_roleRegionAMNGRGR, HumanResourceDTO.SecurityRole.OWNER, false, 0, WorkRoleDTO.STAR_CARDINALITY); ScopeDefinitionWorkRole roleRegionSALESM = new ScopeDefinitionWorkRole(_roleRegionSALESM, HumanResourceDTO.SecurityRole.OWNER, false, 0, WorkRoleDTO.STAR_CARDINALITY); ScopeDefinitionWorkRole roleCustomerAMNGR = new ScopeDefinitionWorkRole(_roleCustomerAMNGR, HumanResourceDTO.SecurityRole.OWNER, false, 1, 1);
Finally we need to associate each roles to the corresponding scope definition object:
// Create a Collection of roles for the Company type
Collection<ScopeDefinitionWorkRole> rolesCompany = new ArrayList<ScopeDefinitionWorkRole>();
rolesCompany.add(roleCompanyCEO);
rolesCompany.add(roleCompanySALESDIR);
rolesCompany.add(roleCompanySTAFF);
// Now associate these role to the Company scope definition
scopeDefCompany.setScopeDefinitionWorkRoles(rolesCompany);
// Create a Collection of roles for the Region type
Collection<ScopeDefinitionWorkRole> rolesRegion = new ArrayList<ScopeDefinitionWorkRole>();
rolesRegion.add(roleRegionCMNGR);
rolesRegion.add(roleRegionAMNGRGR);
rolesRegion.add(roleRegionSALESM);
// Now associate these role to the Region scope definition
scopeDefRegion.setScopeDefinitionWorkRoles(rolesRegion);
// Create a Collection of roles for the Customer type
Collection<ScopeDefinitionWorkRole> rolesCustomer = new ArrayList<ScopeDefinitionWorkRole>();
rolesCustomer.add(roleCustomerAMNGR);
// Now associate these role to the Customer scope definition
scopeDefCustomer.setScopeDefinitionWorkRoles(rolesCustomer);

