Search in sources :

Example 1 with ActionTaken

use of org.kuali.rice.kew.api.action.ActionTaken in project cu-kfs by CU-CommunityApps.

the class CuDistributionOfIncomeAndExpenseDocument method doRouteStatusChange.

/**
 * Overridden to interact with the Legacy Travel service
 * @see https://jira.cornell.edu/browse/KFSPTS-2715
 */
@Override
public void doRouteStatusChange(DocumentRouteStatusChange statusChangeEvent) {
    // If the DI is Cancelled or Disapproved, we need to reopen the trip in the Legacy Travel service.
    if (getDocumentHeader().getWorkflowDocument().isCanceled() || getDocumentHeader().getWorkflowDocument().isDisapproved()) {
        boolean tripReOpened = false;
        boolean isTravelDoc = false;
        List<ActionTaken> actionsTaken = this.getDocumentHeader().getWorkflowDocument().getActionsTaken();
        String disapprovalReason = "";
        if (actionsTaken.size() > 0) {
            String annotation = actionsTaken.get(actionsTaken.size() - 1).getAnnotation();
            if (StringUtils.isNotEmpty(annotation)) {
                disapprovalReason = annotation.substring("Disapproval reason - ".length());
            }
        }
        try {
            CULegacyTravelService cuLegacyTravelService = SpringContext.getBean(CULegacyTravelService.class);
            isTravelDoc = cuLegacyTravelService.isCULegacyTravelIntegrationInterfaceAssociatedWithTrip(this);
            if (isTravelDoc) {
                // This means the DI is a Travel DI
                tripReOpened = cuLegacyTravelService.reopenLegacyTrip(this.getDocumentNumber(), disapprovalReason);
                LOG.info("Trip successfully reopened : " + tripReOpened);
            } else {
                LOG.info("DI is not a travel DI");
            }
        } catch (Exception ex) {
            LOG.error("Exception occurred while trying to cancel a trip.", ex);
        }
    }
    super.doRouteStatusChange(statusChangeEvent);
}
Also used : CULegacyTravelService(edu.cornell.kfs.fp.document.service.CULegacyTravelService) ActionTaken(org.kuali.rice.kew.api.action.ActionTaken) WorkflowException(org.kuali.rice.kew.api.exception.WorkflowException)

Example 2 with ActionTaken

use of org.kuali.rice.kew.api.action.ActionTaken in project cu-kfs by CU-CommunityApps.

the class CuAutoDisapproveDocumentsServiceImpl method buildSuccessMessage.

private String buildSuccessMessage(Document document) throws Exception {
    StringBuilder headerBuilder = new StringBuilder();
    headerBuilder.append(document.getDocumentNumber());
    headerBuilder.append(TAB);
    headerBuilder.append(document.getDocumentHeader().getWorkflowDocument().getDocumentTypeName());
    headerBuilder.append(TAB);
    headerBuilder.append(document.getDocumentHeader().getDocumentDescription());
    headerBuilder.append(TAB);
    headerBuilder.append(personService.getPerson(document.getDocumentHeader().getWorkflowDocument().getInitiatorPrincipalId()).getPrincipalName());
    headerBuilder.append(TAB);
    headerBuilder.append(personService.getPerson(document.getDocumentHeader().getWorkflowDocument().getInitiatorPrincipalId()).getName());
    headerBuilder.append(TAB);
    headerBuilder.append(document.getDocumentHeader().getWorkflowDocument().getDateCreated());
    headerBuilder.append(TAB);
    ConfigurationService k = KRADServiceLocator.getKualiConfigurationService();
    StringBuilder routeBuilder = new StringBuilder();
    String url = k.getPropertyValueAsString("workflow.url");
    routeBuilder.append(url);
    routeBuilder.append("/RouteLog.do?routeHeaderId=");
    routeBuilder.append(document.getDocumentNumber());
    routeBuilder.append(TAB);
    headerBuilder.append(routeBuilder);
    List<ActionTaken> actions;
    // try {
    // actions = KEWServiceLocator.getActionTakenService().findByDocumentId(document.getDocumentHeader().getWorkflowDocument().getDocumentId());
    actions = KewApiServiceLocator.getWorkflowDocumentService().getAllActionsTaken(document.getDocumentNumber());
    ActionTaken max = null;
    for (ActionTaken at : actions) {
        if (ObjectUtils.isNull(max)) {
            max = at;
        } else if (at.getActionDate().compareTo(max.getActionDate()) > 0) {
            max = at;
        }
    }
    headerBuilder.append(personService.getPerson(max.getPrincipalId()).getPrincipalName());
    headerBuilder.append(TAB);
    headerBuilder.append(personService.getPerson(max.getPrincipalId()).getName());
    headerBuilder.append(TAB);
    headerBuilder.append(max.getActionDate());
    headerBuilder.append(TAB);
    headerBuilder.append(max.getActionTaken().getLabel());
    headerBuilder.append(TAB);
    // } catch (WorkflowException e) {
    // e.printStackTrace();
    // }
    String headerString = headerBuilder.toString();
    StringBuilder builder = new StringBuilder();
    if (document instanceof AccountingDocumentBase) {
        for (Object o : ((AccountingDocumentBase) document).getSourceAccountingLines()) {
            SourceAccountingLine sal = (SourceAccountingLine) o;
            builder.append(headerString);
            builder.append(sal.getChartOfAccountsCode());
            builder.append(TAB);
            builder.append(sal.getAccountNumber());
            builder.append(TAB);
            builder.append(sal.getAmount());
            builder.append(TAB);
            builder.append(sal.getAccount().getOrganizationCode());
            builder.append(TAB);
            builder.append(KFSConstants.NEWLINE);
        }
        for (Object o : ((AccountingDocumentBase) document).getTargetAccountingLines()) {
            TargetAccountingLine tal = (TargetAccountingLine) o;
            builder.append(headerString);
            builder.append(tal.getChartOfAccountsCode());
            builder.append(TAB);
            builder.append(tal.getAccountNumber());
            builder.append(TAB);
            builder.append(tal.getAmount());
            builder.append(TAB);
            builder.append(tal.getAccount().getOrganizationCode());
            builder.append(TAB);
            builder.append(KFSConstants.NEWLINE);
        }
    }
    return builder.toString();
}
Also used : TargetAccountingLine(org.kuali.kfs.sys.businessobject.TargetAccountingLine) ConfigurationService(org.kuali.rice.core.api.config.property.ConfigurationService) AccountingDocumentBase(org.kuali.kfs.sys.document.AccountingDocumentBase) SourceAccountingLine(org.kuali.kfs.sys.businessobject.SourceAccountingLine) ActionTaken(org.kuali.rice.kew.api.action.ActionTaken)

Example 3 with ActionTaken

use of org.kuali.rice.kew.api.action.ActionTaken in project cu-kfs by CU-CommunityApps.

the class CuDisbursementVoucherDocument method doRouteStatusChange.

/**
 * Overridden to interact with the Legacy Travel service
 * @see <a href="https://jira.cornell.edu/browse/KFSPTS-2715">https://jira.cornell.edu/browse/KFSPTS-2715</a>
 */
@Override
public void doRouteStatusChange(DocumentRouteStatusChange statusChangeEvent) {
    // If the DV is Canceled or Disapproved, we need to reopen the trip in the Legacy Travel service.
    if (getDocumentHeader().getWorkflowDocument().isCanceled() || getDocumentHeader().getWorkflowDocument().isDisapproved()) {
        boolean tripReOpened = false;
        boolean isTravelDoc = false;
        List<ActionTaken> actionsTaken = this.getDocumentHeader().getWorkflowDocument().getActionsTaken();
        String disapprovalReason = findDissapprovalReason(actionsTaken);
        try {
            CULegacyTravelService cuLegacyTravelService = SpringContext.getBean(CULegacyTravelService.class);
            isTravelDoc = cuLegacyTravelService.isCULegacyTravelIntegrationInterfaceAssociatedWithTrip(this);
            if (isTravelDoc) {
                // This means the DV is a Travel DV
                tripReOpened = cuLegacyTravelService.reopenLegacyTrip(this.getDocumentNumber(), disapprovalReason);
                LOG.info("Trip successfully reopened : " + tripReOpened);
            } else {
                LOG.info("DV is not a travel DV");
            }
        } catch (Exception ex) {
            LOG.error("Exception occurred while trying to cancel a trip.", ex);
        }
    }
    super.doRouteStatusChange(statusChangeEvent);
}
Also used : CULegacyTravelService(edu.cornell.kfs.fp.document.service.CULegacyTravelService) ActionTaken(org.kuali.rice.kew.api.action.ActionTaken) WorkflowException(org.kuali.rice.kew.api.exception.WorkflowException)

Example 4 with ActionTaken

use of org.kuali.rice.kew.api.action.ActionTaken in project cu-kfs by CU-CommunityApps.

the class CuPurchaseOrderAmendmentDocument method getAllPriorApprovers.

public Set<Person> getAllPriorApprovers() throws WorkflowException {
    PersonService personService = KimApiServiceLocator.getPersonService();
    List<ActionTaken> actionsTaken = this.getFinancialSystemDocumentHeader().getWorkflowDocument().getActionsTaken();
    Set<String> principalIds = new HashSet<String>();
    Set<Person> persons = new HashSet<Person>();
    for (ActionTaken actionTaken : actionsTaken) {
        if (KewApiConstants.ACTION_TAKEN_APPROVED_CD.equals(actionTaken.getActionTaken().getCode())) {
            String principalId = actionTaken.getPrincipalId();
            if (!principalIds.contains(principalId)) {
                principalIds.add(principalId);
                persons.add(personService.getPerson(principalId));
            }
        }
    }
    return persons;
}
Also used : PersonService(org.kuali.rice.kim.api.identity.PersonService) ActionTaken(org.kuali.rice.kew.api.action.ActionTaken) Person(org.kuali.rice.kim.api.identity.Person) HashSet(java.util.HashSet)

Aggregations

ActionTaken (org.kuali.rice.kew.api.action.ActionTaken)4 CULegacyTravelService (edu.cornell.kfs.fp.document.service.CULegacyTravelService)2 WorkflowException (org.kuali.rice.kew.api.exception.WorkflowException)2 HashSet (java.util.HashSet)1 SourceAccountingLine (org.kuali.kfs.sys.businessobject.SourceAccountingLine)1 TargetAccountingLine (org.kuali.kfs.sys.businessobject.TargetAccountingLine)1 AccountingDocumentBase (org.kuali.kfs.sys.document.AccountingDocumentBase)1 ConfigurationService (org.kuali.rice.core.api.config.property.ConfigurationService)1 Person (org.kuali.rice.kim.api.identity.Person)1 PersonService (org.kuali.rice.kim.api.identity.PersonService)1