Search in sources :

Example 1 with IPartyRoleType

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;
}
Also used : LocalDateTime(org.joda.time.LocalDateTime) Task(org.estatio.module.capex.dom.task.Task) IPartyRoleType(org.estatio.module.party.dom.role.IPartyRoleType) PartyRoleType(org.estatio.module.party.dom.role.PartyRoleType) Person(org.estatio.module.party.dom.Person)

Example 2 with IPartyRoleType

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;
}
Also used : Task(org.estatio.module.capex.dom.task.Task) IPartyRoleType(org.estatio.module.party.dom.role.IPartyRoleType) IPartyRoleType(org.estatio.module.party.dom.role.IPartyRoleType) PartyRoleType(org.estatio.module.party.dom.role.PartyRoleType) Person(org.estatio.module.party.dom.Person)

Example 3 with IPartyRoleType

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;
}
Also used : IPartyRoleType(org.estatio.module.party.dom.role.IPartyRoleType) Organisation(org.estatio.module.party.dom.Organisation) Action(org.apache.isis.applib.annotation.Action) MemberOrder(org.apache.isis.applib.annotation.MemberOrder)

Example 4 with IPartyRoleType

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);
    }
}
Also used : PartyRole(org.estatio.module.party.dom.role.PartyRole) IPartyRoleType(org.estatio.module.party.dom.role.IPartyRoleType)

Example 5 with IPartyRoleType

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;
        }
    };
}
Also used : IPartyRoleType(org.estatio.module.party.dom.role.IPartyRoleType) PartyRoleTypeService(org.estatio.module.party.dom.role.PartyRoleTypeService) List(java.util.List) Person(org.estatio.module.party.dom.Person) Before(org.junit.Before)

Aggregations

IPartyRoleType (org.estatio.module.party.dom.role.IPartyRoleType)7 Person (org.estatio.module.party.dom.Person)3 PartyRoleType (org.estatio.module.party.dom.role.PartyRoleType)3 Programmatic (org.apache.isis.applib.annotation.Programmatic)2 Task (org.estatio.module.capex.dom.task.Task)2 List (java.util.List)1 Action (org.apache.isis.applib.annotation.Action)1 MemberOrder (org.apache.isis.applib.annotation.MemberOrder)1 Organisation (org.estatio.module.party.dom.Organisation)1 PartyRole (org.estatio.module.party.dom.role.PartyRole)1 PartyRoleTypeService (org.estatio.module.party.dom.role.PartyRoleTypeService)1 LocalDateTime (org.joda.time.LocalDateTime)1 Before (org.junit.Before)1