Dynamic Teams and Roles

Contexts.DynamicTeamType
DynamicTeam

Abstract supertype for all dynamic team types. Dynamic Teams group roles and their relationships in a relational context. Dynamic teams allow runtime changes in team composition and cardinality.

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

source
Contexts.@newDynamicTeamMacro
@newDynamicTeam(contextName, teamName, teamContent)

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

A dynamic team can change its role assignments over time, within the defined cardinalities. Roles can be assigned and disassigned dynamically without dissolving the team. Roles might be optional (i.e., minimum cardinality can be zero).

There are role-specific cardinalities as well as team-wide cardinalities.

Arguments:

  • contextName: The context for the dynamic team
  • teamName: The name of the dynamic team
  • teamContent: Block containing:
@IDAttribute: uniquely identifying attribute
@relationalAttributes: relational attributes of the team
@role: role definitions with cardinalities
@minPlayers: minimum number of players in the team (default 2)
@maxPlayers: maximum number of players in the team (default Inf)

@role definitions must contain at least two roles including their cardinalities.

The syntax for defining roles is: @role RoleName << NaturalType [minCardinality..maxCardinality] begin # role-specific attributes end

Example: @context Sports @newDynamicTeam BasketballTeam <: SportsTeam begin @IDAttribute name::String @maxPlayers 15 @relationalAttributes begin city::String end @role HeadCoach << Person [1] begin end @role PointGuard << Person <: Player [1..Inf] begin number::Int end @role ShootingGuard << Person <: Player [1..Inf] begin number::Int end @role SmallForward << Person <: Player [1..Inf] begin number::Int end @role PowerForward << Person <: Player [1..Inf] begin number::Int end @role Center << Person <: Player [1..Inf] begin number::Int end end

source
@newDynamicTeam(contextName, teamName, teamContent)

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

A dynamic team can change its role assignments over time, within the defined cardinalities. Roles can be assigned and disassigned dynamically without dissolving the team. Roles might be optional (i.e., minimum cardinality can be zero).

There are role-specific cardinalities as well as team-wide cardinalities.

Arguments:

  • teamName: The name of the dynamic team
  • teamContent: Block containing:
@IDAttribute: uniquely identifying attribute
@relationalAttributes: relational attributes of the team
@role: role definitions with cardinalities
@minPlayers: minimum number of players in the team (default 2)
@maxPlayers: maximum number of players in the team (default Inf)

@role definitions must contain at least two roles including their cardinalities.

The syntax for defining roles is: @role RoleName << NaturalType [minCardinality..maxCardinality] begin # role-specific attributes end

Example: @newDynamicTeam BasketballTeam <: SportsTeam begin @IDAttribute name::String @maxPlayers 15 @relationalAttributes begin city::String end @role HeadCoach << Person [1] begin end @role PointGuard << Person <: Player [1..Inf] begin number::Int end @role ShootingGuard << Person <: Player [1..Inf] begin number::Int end @role SmallForward << Person <: Player [1..Inf] begin number::Int end @role PowerForward << Person <: Player [1..Inf] begin number::Int end @role Center << Person <: Player [1..Inf] begin number::Int end end

source
Contexts.assignRolesFunction
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
assignRoles(context::Union{Context, Nothing}, team::DynamicTeam, roles...)

Assigns roles to objects in a dynamic team within a context.

Arguments:

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

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

source
Contexts.disassignRolesFunction
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
disassignRoles(context::Union{Context, Nothing}, teamType::Type, roles::Pair...)

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

Arguments:

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

Example: disassignRoles(ctx, TeamType, RoleA => obj1)

source
disassignRoles(context::Union{Context, Nothing}, team::DynamicTeam)

Removes all role assignments from a dynamic team within a context.

Arguments:

  • context: Context or nothing
  • team: DynamicTeam

Example: disassignRoles(ctx, team)

source
disassignRoles(team::DynamicTeam)

Removes all role assignments from a dynamic team (no context).

Arguments:

  • team: DynamicTeam

Example: disassignRoles(team)

source
disassignRoles(context::Union{Context, Nothing}, teamType::Type, id)

Removes all role assignments from a dynamic team by type and id within a context.

Arguments:

  • context: Context or nothing
  • teamType: Team type
  • id: Team id

Example: disassignRoles(ctx, TeamType, 1)

source
disassignRoles(teamType::Type, id)

Removes all role assignments from a dynamic team by type and id (no context).

Arguments:

  • teamType: Team type
  • id: Team id

Example: disassignRoles(TeamType, 1)

source
Contexts.@changeRolesMacro
@changeRoles(context, team, id, attrs)

Macro to change role assignments and disassignments in a dynamic team within a context.

Arguments:

  • context: Context
  • team: DynamicTeam type
  • id: Team id
  • attrs: Block of assignments (object >> Role, object << Role)

Example: @changeRoles(ctx, MyDynTeam, 1, begin obj1 >> RoleA obj2 << RoleB end)

source
@changeRoles(team, id, attrs)

Macro to change role assignments and disassignments in a dynamic team (no context).

Arguments:

  • team: DynamicTeam type
  • id: Team id
  • attrs: Block of assignments (object >> Role, object << Role)

Example: @changeRoles(MyDynTeam, 1, begin obj1 >> RoleA obj2 << RoleB end)

source
Contexts.changeRolesFunction
changeRoles(context::Union{Context, Nothing}, team::DynamicTeam, roleAssignment::Vector{Any}, roleDisassignment::Vector{Pair{T, DataType}})

Changes role assignments and disassignments in a dynamic team within a context.

Arguments:

  • context: Context or nothing
  • team: DynamicTeam
  • roleAssignment: Vector of assignments (object, Role)
  • roleDisassignment: Vector of disassignments (object, Role type)

Example: changeRoles(ctx, team, [(obj1, RoleA)], [(obj2, RoleB)])

source
changeRoles(context::Union{Context, Nothing}, team::DynamicTeam, roleAssignment::Vector{Pair{T, R}}, roleDisassignment::Vector{Any}) where T where R <: Role

Changes role assignments in a dynamic team within a context.

Arguments:

  • context: Context or nothing
  • team: DynamicTeam
  • roleAssignment: Vector of assignments (object, Role)
  • roleDisassignment: Vector of objects to disassign

Example: changeRoles(ctx, team, [(obj1, RoleA)], [obj2])

source
changeRoles(context::Union{Context, Nothing}, team::DynamicTeam, roleAssignment::Vector{Pair{T1, R}}, roleDisassignment::Vector{Pair{T2, DataType}}) where T1 where T2 where R <: Role

Changes role assignments and disassignments in a dynamic team within a context.

Arguments:

  • context: Context or nothing
  • team: DynamicTeam
  • roleAssignment: Vector of assignments (object, Role)
  • roleDisassignment: Vector of disassignments (object, Role type)

Example: changeRoles(ctx, team, [(obj1, RoleA)], [(obj2, RoleB)])

source
Contexts.getDynamicTeamFunction
getDynamicTeam(context::Union{Context, Nothing}, role::Role)

Returns the dynamic team in a context that has a specific role.

Arguments:

  • context: Context or nothing
  • role: Role type

Example: getDynamicTeam(MyContext, Manager)

source
getDynamicTeam(role::Role)

Convenience function to getDynamicTeam with no context.

Arguments:

  • role: Role type

Example: getDynamicTeam(Manager)

source
getDynamicTeam(context::Union{Context, Nothing}, teamType::DataType, id::T) where T

Returns a dynamic team by id in a context.

Arguments:

  • context: Context or nothing
  • teamType: Team type
  • id: Id value

Example: getDynamicTeam(MyContext, MyDynTeam, :teamid, 123)

source
getDynamicTeam(teamType::DataType, id::T) where T

Convenience function to getDynamicTeam with no context.

Arguments:

  • teamType: Team type
  • id: Id value

Example: getDynamicTeam(MyDynTeam, 123)

source
Contexts.getDynamicTeamsFunction
getDynamicTeams(context::Union{Context, Nothing}, teamType::Type)

Returns all dynamic teams of a given type in a context.

Arguments:

  • context: Context or nothing
  • teamType: Team type

Example: getDynamicTeams(MyContext, MyDynTeam)

source
getDynamicTeams(teamType::Type)

Convenience function to getDynamicTeams with no context.

Arguments:

  • teamType: Team type

Example: getDynamicTeams(MyDynTeam)

source
Contexts.getDynamicTeamIDFunction
getDynamicTeamID(context::Union{Context, Nothing}, team::DynamicTeam)

Returns the properties of a dynamic team in a context.

Arguments:

  • context: Context or nothing
  • team: DynamicTeam type

Example: getDynamicTeamID(MyContext, MyDynTeam)

source
getDynamicTeamID(team::DynamicTeam)

Convenience function to getDynamicTeamID with no context.

Arguments:

  • team: DynamicTeam type

Example: getDynamicTeamID(MyDynTeam)

source
Contexts.getObjectsOfRoleFunction
getObjectsOfRole(context::Union{Context, Nothing}, team::DynamicTeam, role::Type)

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

Arguments:

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

Example: getObjectsOfRole(MyContext, MyDynTeam, Manager)

source
getObjectsOfRole(team::DynamicTeam, role::Type)

Convenience function to getObjectsOfRole with no context.

Arguments:

  • team: DynamicTeam type
  • role: Role type

Example: getObjectsOfRole(MyDynTeam, Manager)

source
Contexts.getRolesOfTeamFunction
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
getRolesOfTeam(team::Team)

Convenience function to getRolesOfTeam with no context.

Arguments:

  • team: Team type

Example: getRolesOfTeam(MyTeam)

source
getRolesOfTeam(context::Union{Context, Nothing}, team::DynamicTeam)

Returns all roles in a dynamic team in a context.

Arguments:

  • context: Context or nothing
  • team: DynamicTeam type

Example: getRolesOfTeam(MyContext, MyDynTeam)

source
getRolesOfTeam(team::DynamicTeam)

Convenience function to getRolesOfTeam with no context.

Arguments:

  • team: DynamicTeam type

Example: getRolesOfTeam(MyDynTeam)

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

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

Arguments:

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

Returns true or false.

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

source

Dynamic teams allow runtime changes in team composition and cardinality. Use @newDynamicTeam to define dynamic teams, and assignRoles, disassignRoles, and changeRoles to manage role assignments. Query dynamic teams and their roles with the provided functions.

See also: assignRoles, changeRoles