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.
Unique capability identifier
The party who has this capability
scopes
List<OperatingScope>
required
Operating scopes that constrain this capability
When this capability is valid
Builder Pattern
forParty
static Builder forParty(PartyId partyId)
Creates a builder for a specific party.
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
Returns the capability identifier.
partyId
Returns the party identifier.
The party who has this capability
type
Returns the capability type.
scopes
List<OperatingScope> scopes()
Returns the operating scopes.
Immutable list of operating scopes
validity
Returns the validity period.
When this capability is valid
Validation Methods
isCurrentlyValid
boolean isCurrentlyValid()
Checks if the capability is currently valid.
true if valid at current time, false otherwise
isValidAt
boolean isValidAt(Instant instant)
Checks if the capability is valid at a specific instant.
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.
The scope class to search for
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
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
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
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.
This builder for chaining
Builder type(String typeName)
Sets the capability type by name.
This builder for chaining
withScope
Builder withScope(OperatingScope scope)
Adds an operating scope.
This builder for chaining
validUntil
Builder validUntil(Instant validTo)
Sets validity from now until specified time.
This builder for chaining
validFrom
Builder validFrom(Instant validFrom)
Sets validity from specified time indefinitely.
This builder for chaining
validBetween
Builder validBetween(Instant validFrom, Instant validTo)
Sets validity for a specific time range.
This builder for chaining
validity
Builder validity(Validity validity)
Sets the validity directly.
This builder for chaining
build
Builds the Capability instance.
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());
}