Search in sources :

Example 6 with PartyRoleType

use of org.estatio.module.party.dom.role.PartyRoleType in project estatio by estatio.

the class IncomingInvoiceApprovalState_IntegTest method complete_works_when_having_appropriate_role_type_test.

@Test
public void complete_works_when_having_appropriate_role_type_test() {
    Exception error = new Exception();
    // given
    Person personEmma = (Person) partyRepository.findPartyByReference(Person_enum.EmmaTreasurerGb.getRef());
    PartyRoleType roleAsPropertyManager = partyRoleTypeRepository.findByKey("PROPERTY_MANAGER");
    personEmma.addRole(roleAsPropertyManager);
    transactionService.nextTransaction();
    SortedSet<PartyRole> rolesforEmma = personEmma.getRoles();
    assertThat(rolesforEmma.size()).isEqualTo(2);
    assertThat(rolesforEmma.first().getRoleType()).isEqualTo(partyRoleTypeRepository.findByKey("PROPERTY_MANAGER"));
    // when
    try {
        // workaround: clear MeService#me cache
        queryResultsCache.resetForNextTransaction();
        sudoService.sudo(Person_enum.EmmaTreasurerGb.getRef().toLowerCase(), (Runnable) () -> wrap(mixin(IncomingInvoice_complete.class, incomingInvoice)).act("PROPERTY_MANAGER", null, null));
    } catch (DisabledException e) {
        error = e;
    }
    assertThat(error.getMessage()).isNull();
    assertThat(incomingInvoice.getApprovalState()).isEqualTo(IncomingInvoiceApprovalState.COMPLETED);
}
Also used : PartyRole(org.estatio.module.party.dom.role.PartyRole) DisabledException(org.apache.isis.applib.services.wrapper.DisabledException) PartyRoleType(org.estatio.module.party.dom.role.PartyRoleType) Person(org.estatio.module.party.dom.Person) DisabledException(org.apache.isis.applib.services.wrapper.DisabledException) Test(org.junit.Test)

Example 7 with PartyRoleType

use of org.estatio.module.party.dom.role.PartyRoleType in project estatio by estatio.

the class EnforceTaskAssignmentPolicySubscriber_applyPolicy_Test method setUp.

@Before
public void setUp() throws Exception {
    subscriber = new EnforceTaskAssignmentPolicySubscriber();
    subscriber.stateTransitionService = mockStateTransitionService;
    subscriber.personRepository = mockPersonRepository;
    subscriber.metaModelService3 = mockMetaModelService3;
    domainObject = new BankAccount();
    stateTransitionClass = BankAccountVerificationStateTransition.class;
    pendingTransition = new BankAccountVerificationStateTransition();
    personTaskAssignedTo = new Person();
    personTaskAssignedTo.setReference("JBLOGGS");
    roleTaskAssignedTo = new PartyRoleType();
    roleTaskAssignedTo.setKey("Treasurer");
    pendingTask = new Task(roleTaskAssignedTo, personTaskAssignedTo, "some description", LocalDateTime.now(), // objectType of transition class
    "bankAccount.BankAccountVerificationStateTransition");
    pendingTransition.setTask(pendingTask);
    personForMe = new Person();
    personForMe.getRoles().add(new PartyRole(personForMe, roleTaskAssignedTo));
    assertThat(pendingTransition.getTask()).isNotNull();
    assertThat(personForMe.getRoles()).isNotEmpty();
    assertThat(Lists.newArrayList(personForMe.getRoles()).stream().map(PartyRole::getRoleType)).contains(roleTaskAssignedTo);
}
Also used : PartyRole(org.estatio.module.party.dom.role.PartyRole) Task(org.estatio.module.capex.dom.task.Task) PartyRoleType(org.estatio.module.party.dom.role.PartyRoleType) BankAccount(org.estatio.module.financial.dom.BankAccount) Person(org.estatio.module.party.dom.Person) BankAccountVerificationStateTransition(org.estatio.module.capex.dom.bankaccount.verification.BankAccountVerificationStateTransition) Before(org.junit.Before)

Example 8 with PartyRoleType

use of org.estatio.module.party.dom.role.PartyRoleType in project estatio by estatio.

the class TaskRepository method findIncompleteForMyRolesAndUnassignedAndCreatedOnBefore.

/**
 * Those tasks which are assigned to no-one, but for which I have the (party) roles to perform before {@param createdOn}
 * @param createdOn
 * @return
 */
@Programmatic
public List<Task> findIncompleteForMyRolesAndUnassignedAndCreatedOnBefore(final LocalDateTime createdOn) {
    final Person meAsPerson = meAsPerson();
    if (meAsPerson == null) {
        return Lists.newArrayList();
    }
    final List<PartyRoleType> myRoleTypes = partyRoleTypesFor(meAsPerson);
    return findIncompleteByUnassignedForRolesAndCreatedOnBefore(myRoleTypes, createdOn);
}
Also used : PartyRoleType(org.estatio.module.party.dom.role.PartyRoleType) Person(org.estatio.module.party.dom.Person) Programmatic(org.apache.isis.applib.annotation.Programmatic)

Example 9 with PartyRoleType

use of org.estatio.module.party.dom.role.PartyRoleType in project estatio by estatio.

the class TaskRepository method findIncompleteForMyRolesAndUnassignedAndCreatedOnAfter.

/**
 * Those tasks which are assigned to no-one, but for which I have the (party) roles to perform after {@param createdOn}
 * @param createdOn
 * @return
 */
@Programmatic
public List<Task> findIncompleteForMyRolesAndUnassignedAndCreatedOnAfter(final LocalDateTime createdOn) {
    final Person meAsPerson = meAsPerson();
    if (meAsPerson == null) {
        return Lists.newArrayList();
    }
    final List<PartyRoleType> myRoleTypes = partyRoleTypesFor(meAsPerson);
    return findIncompleteByUnassignedForRolesAndCreatedOnAfter(myRoleTypes, createdOn);
}
Also used : PartyRoleType(org.estatio.module.party.dom.role.PartyRoleType) Person(org.estatio.module.party.dom.Person) Programmatic(org.apache.isis.applib.annotation.Programmatic)

Example 10 with PartyRoleType

use of org.estatio.module.party.dom.role.PartyRoleType in project estatio by estatio.

the class EnforceTaskAssignmentPolicySubscriber method applyPolicy.

<DO, ST extends StateTransition<DO, ST, STT, S>, STT extends StateTransitionType<DO, ST, STT, S>, S extends State<S>> Optional<String> applyPolicy(final Class<ST> stateTransitionClass, final DO entityOrViewModel) {
    if (EstatioTogglzFeature.ApproveByProxy.isActive()) {
        return Optional.empty();
    }
    final DO entity = unwrapIfRequired(entityOrViewModel);
    final ST pendingTransition = stateTransitionService.pendingTransitionOf(entity, stateTransitionClass);
    if (pendingTransition == null) {
        return Optional.empty();
    }
    final Task task = pendingTransition.getTask();
    if (task == null) {
        return Optional.empty();
    }
    final Person meAsPerson = personRepository.me();
    if (meAsPerson == null) {
        return Optional.of("Could not locate Person for current user");
    }
    // first guard: meAsPerson always needs the PartyRoleType the task is assigned to
    List<PartyRoleType> meAsPersonRoleTypes = Lists.newArrayList(meAsPerson.getRoles()).stream().map(PartyRole::getRoleType).collect(Collectors.toList());
    if (!meAsPersonRoleTypes.contains(task.getAssignedTo())) {
        return Optional.of(String.format("Task assigned to '%s' role", task.getAssignedTo().getKey()));
    }
    // second guard: if the task is assigned to a specific person it needs to be meAsPerson
    final Person taskAssignedTo = task.getPersonAssignedTo();
    if (taskAssignedTo == null || taskAssignedTo == meAsPerson) {
        return Optional.empty();
    } else {
        return Optional.of(String.format("Task assigned to %s", taskAssignedTo.getReference()));
    }
}
Also used : Task(org.estatio.module.capex.dom.task.Task) PartyRoleType(org.estatio.module.party.dom.role.PartyRoleType) Person(org.estatio.module.party.dom.Person)

Aggregations

PartyRoleType (org.estatio.module.party.dom.role.PartyRoleType)13 Person (org.estatio.module.party.dom.Person)9 Task (org.estatio.module.capex.dom.task.Task)6 Test (org.junit.Test)5 Programmatic (org.apache.isis.applib.annotation.Programmatic)4 BankAccountVerificationStateTransition (org.estatio.module.capex.dom.bankaccount.verification.BankAccountVerificationStateTransition)3 BankAccount (org.estatio.module.financial.dom.BankAccount)3 IPartyRoleType (org.estatio.module.party.dom.role.IPartyRoleType)3 PartyRole (org.estatio.module.party.dom.role.PartyRole)3 BankAccountVerificationState (org.estatio.module.capex.dom.bankaccount.verification.BankAccountVerificationState)2 IncomingInvoiceApprovalStateTransition (org.estatio.module.capex.dom.invoice.approval.IncomingInvoiceApprovalStateTransition)2 DisabledException (org.apache.isis.applib.services.wrapper.DisabledException)1 AbstractBeanPropertiesTest (org.incode.module.unittestsupport.dom.bean.AbstractBeanPropertiesTest)1 Expectations (org.jmock.Expectations)1 LocalDateTime (org.joda.time.LocalDateTime)1 Before (org.junit.Before)1