use of org.estatio.module.party.dom.Person in project estatio by estatio.
the class TaskRepository method findIncompleteForMeAndCreatedOnBefore.
/**
* Incomplete, assigned explicitly to me, AND ALSO any tasks not assigned to anyone but for which
* I have the (party) roles to perform them (so should be part of "my tasks") before {@param createdOn}
* @param createdOn
* @return
*/
@Programmatic
public List<Task> findIncompleteForMeAndCreatedOnBefore(final LocalDateTime createdOn) {
final Person meAsPerson = meAsPerson();
if (meAsPerson == null) {
return Lists.newArrayList();
}
final List<Task> tasks = findIncompleteForAndCreatedOnBefore(meAsPerson, createdOn);
final List<Task> myRolesTasksUnassigned = findIncompleteForMyRolesAndUnassignedAndCreatedOnBefore(createdOn);
tasks.addAll(myRolesTasksUnassigned);
tasks.sort(Ordering.natural().nullsLast().reverse().onResultOf(Task::getCreatedOn));
return tasks;
}
use of org.estatio.module.party.dom.Person 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.Person in project estatio by estatio.
the class IncomingInvoice_recategorize method disableAct.
public String disableAct() {
final Document documentIfAny = lookupPdf();
if (documentIfAny == null) {
return "Cannot locate document";
}
if (incomingInvoice.getApprovalState() != IncomingInvoiceApprovalState.NEW) {
return "Only NEW invoices can be recategorized";
}
if (incomingInvoice.isReported()) {
return "This invoice is reported and cannot be recategorized";
}
final Person meAsPerson = personRepository.me();
if (meAsPerson == null)
return "Your login is not linked to a person in Estatio";
if (!(meAsPerson.hasPartyRoleType(FixedAssetRoleTypeEnum.PROPERTY_MANAGER.findUsing(partyRoleTypeRepository)) || meAsPerson.hasPartyRoleType(PartyRoleTypeEnum.OFFICE_ADMINISTRATOR.findUsing(partyRoleTypeRepository)))) {
return String.format("You need role %s or %s to recategorize", FixedAssetRoleTypeEnum.PROPERTY_MANAGER.getKey(), PartyRoleTypeEnum.OFFICE_ADMINISTRATOR);
}
return null;
}
use of org.estatio.module.party.dom.Person in project estatio by estatio.
the class OrderMenu_Test method filterOrFindBySeller_filter_works.
@Test
public void filterOrFindBySeller_filter_works() {
OrderMenu.OrderFinder builder;
// given
builder = new OrderMenu.OrderFinder(mockOrderRepository, mockPartyRepository);
Order order1 = new Order();
Person personToBeFiltered = new Person();
Organisation seller = new Organisation();
order1.setSeller(seller);
Order order2 = new Order();
builder.setResult(Arrays.asList(order1, order2));
Assertions.assertThat(builder.getResult().size()).isEqualTo(2);
// expect
context.checking(new Expectations() {
{
oneOf(mockPartyRepository).findParties("*abc*");
will(returnValue(Arrays.asList(seller, personToBeFiltered)));
}
});
// when
builder.filterOrFindBySeller("abc");
// then
Assertions.assertThat(builder.getResult().size()).isEqualTo(1);
}
use of org.estatio.module.party.dom.Person in project estatio by estatio.
the class IncomingInvoiceApprovalState_IntegTest method complete_should_fail_when_not_having_appropriate_role_type_test.
@Test
public void complete_should_fail_when_not_having_appropriate_role_type_test() {
Exception error = new Exception();
// given
Person personEmmaWithNoRoleAsPropertyManager = (Person) partyRepository.findPartyByReference(Person_enum.EmmaTreasurerGb.getRef());
SortedSet<PartyRole> rolesforEmma = personEmmaWithNoRoleAsPropertyManager.getRoles();
assertThat(rolesforEmma.size()).isEqualTo(1);
assertThat(rolesforEmma.first().getRoleType()).isEqualTo(partyRoleTypeRepository.findByKey(PartyRoleTypeEnum.TREASURER.getKey()));
// 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()).isNotNull();
assertThat(error.getMessage()).contains("Reason: Task assigned to 'PROPERTY_MANAGER' role");
}
Aggregations