Teams and Roles

Why Roles?

The difference of a Role compared to a Mixin is the following. While a Mixin can be defined single standing, a role is always defined within a group with other roles, which is called team. Roles can therefore only get assigned to an object, if all roles of this team are assigned at the same time. The team itself can have attributes that are connected to all roles of the team, e.g. the company, an employee, and an employer are working at.

Contexts.RoleType
Role

Abstract supertype for all role types. Roles represent context-dependent behaviors or responsibilities.

Concrete roles should be defined within the @newTeam and @newDynamicTeam macro.

source
Contexts.TeamType
Team

Abstract supertype for all team types. Teams group roles and their relationships in a relational context.

Concrete teams should be defined within the @newTeam and @newDynamicTeam macro.

source
Contexts.@newTeamMacro
@newTeam(contextName, teamName, teamContent)

Macro to define a new Team type for a context, with specified roles and attributes. Creates a mutable struct subtype of Team and role structs, and registers them.

A Team always contains a fixed number of roles. Once a team is created, the role assignment cannot be changed without dissolving the team and creating a new one.

Arguments:

  • contextName: The context for the team
  • teamName: The name of the team
  • teamContent: Block containing:
- @relationalAttributes: relational attributes of the team
- @role: role definitions

@role definitions must contain at least two roles. The syntax for defining roles is: @role RoleName << NaturalType [<: RoleSuperType] begin # role-specific attributes end

Example: @context Tournament @newTeam ChessGame begin @relationalAttributes begin place::String end @role BlackPlayer << Person <: Player begin end @role WhitePlayer << Person <: Player begin end end

source
@newTeam(teamName, teamContent)

Macro to define a new Team type without a context. Creates a mutable struct subtype of Team and role structs, and registers them.

A Team always contains a fixed number of roles. Once a team is created, the role assignment cannot be changed without dissolving the team and creating a new one.

Arguments:

  • teamName: The name of the team
  • teamContent: Block containing:
- @relationalAttributes: relational attributes of the team
- @role: role definitions

@role definitions must contain at least two roles. The syntax for defining roles is: @role RoleName << NaturalType [<: RoleSuperType] begin # role-specific attributes end

Example: @newTeam ChessGame begin @relationalAttributes begin place::String end @role BlackPlayer << Person <: Player begin end @role WhitePlayer << Person <: Player begin end end

source
Contexts.assignRolesMethod
assignRoles(context::Union{Context, Nothing}, team::Team, roles...)

Assigns roles to objects in a team within a context.

Arguments:

  • context: Context or nothing
  • team: Team
  • roles...: Pairs of (object, Role)

Example: assignRoles(ctx, team, obj1 => RoleA, obj2 => RoleB)

source
Contexts.disassignRolesMethod
disassignRoles(context::Union{Context, Nothing}, t::Team, roles::Pair...)

Removes role assignments from objects in a team within a context.

Arguments:

  • context: Context or nothing
  • t: Team
  • roles...: Pairs of (Role, object)

Example: disassignRoles(ctx, team, RoleA => obj1, RoleB => obj2)

source
Contexts.getRolesMethod
getRoles(context::Union{Context, Nothing}, obj, role::Type, teamType::Type)

Returns all roles of a given type in a team of a given type for an object in a context.

Arguments:

  • context: Context or nothing
  • obj: Object
  • role: Role type
  • teamType: Team type

Example: getRoles(MyContext, obj, Manager, ProjectTeam)

source
Contexts.getRoleMethod
getRole(context::Union{Context, Nothing}, obj::T, team::DynamicTeam) where T

Returns the role for an object in a dynamic team in a context.

Arguments:

  • context: Context or nothing
  • obj: Object
  • team: DynamicTeam type

Example: getRole(MyContext, obj, MyDynTeam)

source
Contexts.getRolesOfTeamMethod
getRolesOfTeam(context::Union{Context, Nothing}, team::Team)

Returns all roles in a team in a context.

Arguments:

  • context: Context or nothing
  • team: Team type

Example: getRolesOfTeam(MyContext, MyTeam)

source
Contexts.getTeamFunction
getTeam(context::Union{Context, Nothing}, teamType::Type, rolePairs...)

Returns the first team in a context that matches the given role pairs.

Arguments:

  • context: Context or nothing
  • teamType: Team type
  • rolePairs: Vararg of role type and object type pairs

Example: getTeam(MyContext, MyTeam, RoleA=>Person, RoleB=>Manager)

source
Contexts.hasRoleMethod
hasRole(context::Union{Context, Nothing}, obj, role::Type, team::Team)

Checks if an object has a specific role in a specific team in a context.

Arguments:

  • context: Context or nothing
  • obj: Object
  • role: Role type
  • team: Team type

Returns true or false.

Example: hasRole(MyContext, obj, Manager, MyTeam)

source
Contexts.getTeamPartnersMethod
getTeamPartners(context::Union{Context, Nothing}, obj::Any, roleType::Type, team::Team)

Returns the partner object in a team for the specified object and role type in a context.

Arguments:

  • context: Context or nothing
  • obj: Object to find partner for
  • roleType: Role type
  • team: Team type

Returns a partner group (Dict).

Example: getTeamPartners(ctx, alice, Manager, MyTeam)

source
Contexts.getObjectOfRoleMethod
getObjectOfRole(context::Union{Context, Nothing}, team::Type, role::Type)

Returns all objects in a context that have a specific role in a specific team.

Arguments:

  • context: Context or nothing
  • team: Team type
  • role: Role type

Example: getObjectOfRole(MyContext, MyTeam, Manager)

source
Contexts.getObjectOfRoleMethod
getObjectOfRole(context::Union{Context, Nothing}, role::Role)

Returns the object in a context that has a specific role.

Arguments:

  • context: Context or nothing
  • role: Role type

Example: getObjectOfRole(MyContext, Manager)

source
Contexts.getObjectOfRoleMethod
getObjectOfRole(role::Role)

Convenience function to getObjectOfRole with no context.

Arguments:

  • role: Role type

Example: getObjectOfRole(Manager)

source

Teams and roles allow you to model collaborative structures in contexts. Use @newTeam to define teams and their roles, and assignRoles/disassignRoles to manage role assignments. Query roles and teams with the provided functions.

See also: assignRoles, getRoles