use of org.estatio.module.party.dom.role.IPartyRoleType in project estatio by estatio.
the class StateTransitionRepositoryGeneric method createTaskIfRequired.
protected <DO, ST extends StateTransitionAbstract<DO, ST, STT, S>, STT extends StateTransitionType<DO, ST, STT, S>, S extends State<S>> Task createTaskIfRequired(final IPartyRoleType iRoleAssignTo, final Person personToAssignToIfAny, final String taskDescription, final Class<ST> stateTransitionClass, final DO domainObject) {
if (iRoleAssignTo == null) {
return null;
}
final LocalDateTime createdOn = clockService.nowAsLocalDateTime();
final String transitionObjectType = metaModelService3.toObjectType(stateTransitionClass);
final Person assignToIfAny = personToAssignToIfAny != null ? personToAssignToIfAny : partyRoleTypeService.onlyMemberOfElseNone(iRoleAssignTo, domainObject);
final PartyRoleType roleAssignTo = iRoleAssignTo.findOrCreateUsing(partyRoleTypeRepository);
final Task task = new Task(roleAssignTo, assignToIfAny, taskDescription, createdOn, transitionObjectType);
repositoryService.persist(task);
return task;
}
use of org.estatio.module.party.dom.role.IPartyRoleType in project estatio by estatio.
the class StateTransitionService method pendingTransitionIfPossible.
private <DO, ST extends StateTransition<DO, ST, STT, S>, STT extends StateTransitionType<DO, ST, STT, S>, S extends State<S>> ST pendingTransitionIfPossible(final DO domainObject, final Class<ST> stateTransitionClass, final STT requestedTransitionTypeIfAny, final Person personToAssignNextToIfAny, final String nextTaskDescriptionIfAny) {
// check the override, if any
if (requestedTransitionTypeIfAny != null) {
boolean canTransition = requestedTransitionTypeIfAny.canTransitionFromCurrentStateAndIsMatch(domainObject, serviceRegistry2);
if (!canTransition) {
// what's been requested is a no-go.
return null;
}
}
// determine what previously was determined as the pending (if any)
ST pendingTransitionIfAny = pendingTransitionOf(domainObject, stateTransitionClass);
// what we now think as the pending (if any)
STT nextTransitionType = null;
// current state
final ST mostRecentTransitionIfAny = mostRecentlyCompletedTransitionOf(domainObject, stateTransitionClass);
final S currentStateIfAny = mostRecentTransitionIfAny != null ? mostRecentTransitionIfAny.getTransitionType().getToState() : null;
if (requestedTransitionTypeIfAny != null) {
nextTransitionType = requestedTransitionTypeIfAny;
} else {
if (mostRecentTransitionIfAny != null) {
// use most recent transition to determine the next transition (since one hasn't been requested)
final STT mostRecentTransitionType = mostRecentTransitionIfAny.getTransitionType();
final NextTransitionSearchStrategy<DO, ST, STT, S> transitionStrategy = mostRecentTransitionType.getNextTransitionSearchStrategy();
if (transitionStrategy != null) {
nextTransitionType = transitionStrategy.nextTransitionType(domainObject, mostRecentTransitionType, serviceRegistry2);
}
} else {
// can't proceed because unable to determine current state, and no transition specified
return null;
}
}
// if pending has changed, then reconcile
STT pendingTransitionType = pendingTransitionIfAny != null ? pendingTransitionIfAny.getTransitionType() : null;
if (pendingTransitionType != nextTransitionType) {
if (pendingTransitionType != null) {
if (nextTransitionType != null) {
final Task taskIfAny = pendingTransitionIfAny.getTask();
repositoryService.remove(pendingTransitionIfAny);
if (taskIfAny != null) {
repositoryService.removeAndFlush(taskIfAny);
}
pendingTransitionType = nextTransitionType;
pendingTransitionIfAny = createPendingTransition(domainObject, currentStateIfAny, nextTransitionType, personToAssignNextToIfAny, nextTaskDescriptionIfAny);
} else {
// in this branch the transition strategy for the most recently completed transition
// must have returned null for nextTransitionType, and yet a pending transition does exist
// (pendingTransitionType is not null). This can only have come about if that pending
// transition was created directly (using createPendingTransition(...)).
// We don't want to discard this pending transition, so we use instead update nextTransitionType
// to this existing pending value.
nextTransitionType = pendingTransitionType;
}
} else {
// pendingTransitionType == null, so nextTransitionType != null because of outer if
pendingTransitionIfAny = createPendingTransition(domainObject, currentStateIfAny, nextTransitionType, personToAssignNextToIfAny, nextTaskDescriptionIfAny);
pendingTransitionType = nextTransitionType;
}
}
if (pendingTransitionType == null) {
return null;
}
if (domainObject instanceof Stateful) {
final Stateful stateful = (Stateful) domainObject;
final S currentStateAccordingToDomainObject = stateful.getStateOf(stateTransitionClass);
if (currentStateAccordingToDomainObject == null && mostRecentTransitionIfAny != null) {
// self-healing
stateful.setStateOf(stateTransitionClass, mostRecentTransitionIfAny.getToState());
}
}
final Task taskIfAny = pendingTransitionIfAny.getTask();
if (taskIfAny != null) {
final PartyRoleType roleAssignedTo = taskIfAny.getAssignedTo();
final IPartyRoleType iRoleShouldBeAssignedTo = pendingTransitionType.getTaskAssignmentStrategy().getAssignTo(domainObject, serviceRegistry2);
// always overwrite the role
final PartyRoleType roleShouldBeAssignedTo = partyRoleTypeRepository.findOrCreate(iRoleShouldBeAssignedTo);
if (roleAssignedTo != roleShouldBeAssignedTo) {
taskIfAny.setAssignedTo(roleShouldBeAssignedTo);
}
// only overwrite the person if not actually assigned
final Person personAssignedToIfAny = taskIfAny.getPersonAssignedTo();
if (personAssignedToIfAny == null) {
if (iRoleShouldBeAssignedTo != null) {
Person person = partyRoleTypeService.onlyMemberOfElseNone(iRoleShouldBeAssignedTo, domainObject);
taskIfAny.setPersonAssignedTo(person);
}
}
}
if (!pendingTransitionType.isGuardSatisfied(domainObject, serviceRegistry2)) {
// (there must be a guard prohibiting it for this particular domain object)
return null;
}
// if requestedTransitionTypeIfAny != null, then this is an explicit action, so automatic doesn't apply...
if (requestedTransitionTypeIfAny != null) {
return pendingTransitionIfAny;
}
final AdvancePolicy advancePolicy = nextTransitionType.advancePolicyFor(domainObject, serviceRegistry2);
if (advancePolicy.isAutomatic() && pendingTransitionType.isAutoGuardSatisfied(domainObject, serviceRegistry2)) {
return pendingTransitionIfAny;
}
return null;
}
use of org.estatio.module.party.dom.role.IPartyRoleType in project estatio by estatio.
the class OrganisationMenu method newOrganisation.
@Action(semantics = SemanticsOf.NON_IDEMPOTENT)
@MemberOrder(sequence = "1")
public Organisation newOrganisation(@Parameter(regexPattern = ReferenceType.Meta.REGEX, regexPatternReplacement = ReferenceType.Meta.REGEX_DESCRIPTION, optionality = Optionality.OPTIONAL) final String reference, final String name, final Country country, final List<IPartyRoleType> partyRoleTypes) {
boolean useNumerator = Strings.isNullOrEmpty(reference);
final Organisation organisation = organisationRepository.newOrganisation(reference, useNumerator, name, country);
for (IPartyRoleType partyRoleType : partyRoleTypes) {
partyRoleRepository.findOrCreate(organisation, partyRoleType);
}
return organisation;
}
use of org.estatio.module.party.dom.role.IPartyRoleType in project estatio by estatio.
the class PersonPartyRolesBuilder method execute.
@Override
public void execute(ExecutionContext executionContext) {
checkParam("person", executionContext, Person.class);
for (IPartyRoleType partyRoleType : partyRoleTypes) {
final PartyRole partyRole = partyRoleTypeService.createRole(person, partyRoleType);
object.add(partyRole);
}
}
use of org.estatio.module.party.dom.role.IPartyRoleType in project estatio by estatio.
the class PartyRoleTypeService_Test method setUp.
@Before
public void setUp() throws Exception {
person1 = new Person();
person2 = new Person();
partyRoleTypeService = new PartyRoleTypeService() {
@Override
public List<Person> membersOf(final IPartyRoleType partyRoleType, final Object domainObject) {
return members;
}
};
}
Aggregations