Skip to main content

Overview

Capability represents what a specific party can do, constrained by operating scopes and validity period. Each capability is assigned to exactly one party. Package: com.softwarearchetypes.party Source: /party/src/main/java/com/softwarearchetypes/party/Capability.java:20

Use Cases

Medical:
  • Dr. Smith has MedicalImaging capability at Hospital A, working hours, max 20 scans/day, valid until 2025
Logistics:
  • FastLogistics company has GoodsDelivery capability for Warsaw region with ADR certification, valid until 2026
Software:
  • Backend Team has SoftwareDevelopment capability for API Gateway at Senior level, always valid

Constructor

private Capability(CapabilityId id,
                  PartyId partyId,
                  CapabilityType type,
                  List<OperatingScope> scopes,
                  Validity validity)
Use Capability.forParty(partyId) to create instances via builder.
id
CapabilityId
required
Unique capability identifier
partyId
PartyId
required
The party who has this capability
type
CapabilityType
required
Type of capability
scopes
List<OperatingScope>
required
Operating scopes that constrain this capability
validity
Validity
required
When this capability is valid

Builder Pattern

forParty

static Builder forParty(PartyId partyId)
Creates a builder for a specific party.
partyId
PartyId
required
The party identifier
return
Builder
A new Builder instance
Example:
Capability capability = Capability.forParty(doctorId)
    .type(CapabilityType.of("MedicalImaging"))
    .withScope(new LocationScope("Hospital A"))
    .withScope(new TimeScope("09:00-17:00"))
    .withScope(new QuotaScope(20, "scans per day"))
    .validUntil(Instant.parse("2025-12-31T23:59:59Z"))
    .build();

Accessor Methods

id

CapabilityId id()
Returns the capability identifier.
return
CapabilityId
The capability ID

partyId

PartyId partyId()
Returns the party identifier.
return
PartyId
The party who has this capability

type

CapabilityType type()
Returns the capability type.
return
CapabilityType
The capability type

scopes

List<OperatingScope> scopes()
Returns the operating scopes.
return
List<OperatingScope>
Immutable list of operating scopes

validity

Validity validity()
Returns the validity period.
return
Validity
When this capability is valid

Validation Methods

isCurrentlyValid

boolean isCurrentlyValid()
Checks if the capability is currently valid.
return
boolean
true if valid at current time, false otherwise

isValidAt

boolean isValidAt(Instant instant)
Checks if the capability is valid at a specific instant.
instant
Instant
required
The instant to check
return
boolean
true if valid at the given instant, false otherwise

Scope Queries

scope

<T extends OperatingScope> Optional<T> scope(Class<T> scopeClass)
Finds a scope of a specific type.
scopeClass
Class<T>
required
The scope class to search for
return
Optional<T>
The first scope of the given type, or empty if not found
Example:
Optional<LocationScope> location = capability.scope(LocationScope.class);
if (location.isPresent()) {
    System.out.println("Location: " + location.get().getLocation());
}

hasScope

boolean hasScope(Class<? extends OperatingScope> scopeClass)
Checks if the capability has a scope of a specific type.
scopeClass
Class<? extends OperatingScope>
required
The scope class to check
return
boolean
true if has scope of this type, false otherwise

Requirement Checking

satisfies

boolean satisfies(CapabilityRequirement requirement)
Checks if this capability satisfies a requirement. The capability must:
  • Be currently valid
  • Have the same type as required
  • All scopes must satisfy the requirement’s scope requirements
requirement
CapabilityRequirement
required
The requirement to check
return
boolean
true if requirement is satisfied, false otherwise
Example:
CapabilityRequirement requirement = CapabilityRequirement.builder()
    .requiredType(CapabilityType.of("MedicalImaging"))
    .requireScope(new LocationScope("Hospital A"))
    .build();

if (capability.satisfies(requirement)) {
    // Capability meets the requirement
}

satisfiesAt

boolean satisfiesAt(CapabilityRequirement requirement, Instant at)
Checks if this capability satisfies a requirement at a specific instant.
requirement
CapabilityRequirement
required
The requirement to check
at
Instant
required
The instant to check
return
boolean
true if requirement is satisfied at the given instant, false otherwise

Builder Methods

The Builder class provides a fluent interface for constructing Capability instances.

type

Builder type(CapabilityType type)
Sets the capability type.
type
CapabilityType
required
The capability type
return
Builder
This builder for chaining
Builder type(String typeName)
Sets the capability type by name.
typeName
String
required
The capability type name
return
Builder
This builder for chaining

withScope

Builder withScope(OperatingScope scope)
Adds an operating scope.
scope
OperatingScope
required
The scope to add
return
Builder
This builder for chaining

validUntil

Builder validUntil(Instant validTo)
Sets validity from now until specified time.
validTo
Instant
required
The end of validity
return
Builder
This builder for chaining

validFrom

Builder validFrom(Instant validFrom)
Sets validity from specified time indefinitely.
validFrom
Instant
required
The start of validity
return
Builder
This builder for chaining

validBetween

Builder validBetween(Instant validFrom, Instant validTo)
Sets validity for a specific time range.
validFrom
Instant
required
The start of validity
validTo
Instant
required
The end of validity
return
Builder
This builder for chaining

validity

Builder validity(Validity validity)
Sets the validity directly.
validity
Validity
required
The validity period
return
Builder
This builder for chaining

build

Capability build()
Builds the Capability instance.
return
Capability
The constructed Capability
Throws: IllegalArgumentException if capability type is not set.

Complete Usage Example

// Doctor with medical imaging capability
Capability imagingCapability = Capability.forParty(doctorId)
    .type("MedicalImaging")
    .withScope(new LocationScope("Hospital A"))
    .withScope(new TimeScope("09:00-17:00", "Mon-Fri"))
    .withScope(new QuotaScope(20, "scans per day"))
    .validBetween(
        Instant.parse("2024-01-01T00:00:00Z"),
        Instant.parse("2024-12-31T23:59:59Z")
    )
    .build();

// Check validity
assert imagingCapability.isCurrentlyValid();

// Check scopes
assert imagingCapability.hasScope(LocationScope.class);
assert imagingCapability.hasScope(TimeScope.class);

Optional<LocationScope> location = imagingCapability.scope(LocationScope.class);
assert location.isPresent();
assert location.get().getLocation().equals("Hospital A");

// Check if capability satisfies a requirement
CapabilityRequirement requirement = CapabilityRequirement.builder()
    .requiredType(CapabilityType.of("MedicalImaging"))
    .requireScope(new LocationScope("Hospital A"))
    .build();

assert imagingCapability.satisfies(requirement);

// Logistics company with delivery capability
Capability deliveryCapability = Capability.forParty(companyId)
    .type("GoodsDelivery")
    .withScope(new GeographicScope("Warsaw", "Poland"))
    .withScope(new CertificationScope("ADR")) // Hazardous materials
    .withScope(new WeightScope(0, 3500, "kg"))
    .validUntil(Instant.parse("2026-12-31T23:59:59Z"))
    .build();

assert deliveryCapability.isCurrentlyValid();

CapabilitiesFacade

The CapabilitiesFacade provides high-level operations for managing capabilities. Package: com.softwarearchetypes.party Source: /party/src/main/java/com/softwarearchetypes/party/CapabilitiesFacade.java:10

handle (AddCapabilityCommand)

Result<String, CapabilityView> handle(AddCapabilityCommand command)
Adds a capability to a party.
command
AddCapabilityCommand
required
Command containing party ID, capability type, scopes, and validity
return
Result<String, CapabilityView>
Success with capability view, or failure with “PARTY_NOT_FOUND”

handle (RemoveCapabilityCommand)

Result<String, CapabilityId> handle(RemoveCapabilityCommand command)
Removes a capability.
command
RemoveCapabilityCommand
required
Command containing capability ID to remove
return
Result<String, CapabilityId>
Success with capability ID, or failure with “CAPABILITY_NOT_FOUND”
Example:
CapabilitiesFacade facade = // ... injected

AddCapabilityCommand command = new AddCapabilityCommand(
    partyId,
    CapabilityType.of("MedicalImaging"),
    List.of(new LocationScope("Hospital A")),
    Validity.until(Instant.parse("2025-12-31T23:59:59Z"))
);

Result<String, CapabilityView> result = facade.handle(command);

if (result.success()) {
    CapabilityView view = result.getSuccess();
    System.out.println("Added capability: " + view.id());
} else {
    System.out.println("Failed: " + result.getFailure());
}

Build docs developers (and LLMs) love