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);
}
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);
}
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);
}
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);
}
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()));
}
}
Aggregations