Ejemplo n.º 1
0
  public SimpleResult process(RouteContext context, RouteHelper helper) throws Exception {

    LOG.debug("processing FYIByUniversityId node");
    Element rootElement =
        getRootElement(new StandardDocumentContent(context.getDocument().getDocContent()));
    Collection<Element> fieldElements = XmlHelper.findElements(rootElement, "field");
    Iterator<Element> elementIter = fieldElements.iterator();
    while (elementIter.hasNext()) {
      Element field = (Element) elementIter.next();
      Element version = field.getParentElement();
      if (version.getAttribute("current").getValue().equals("true")) {
        LOG.debug("Looking for studentUid field:  " + field.getAttributeValue("name"));
        if (field.getAttribute("name") != null
            && field.getAttributeValue("name").equals("studentUid")) {
          String employeeId = field.getChildText("value");
          LOG.debug("Should send an FYI to employee ID:  " + employeeId);
          if (!StringUtils.isBlank(employeeId)) {
            Person person = KimApiServiceLocator.getPersonService().getPerson(employeeId);

            if (person == null) {
              throw new WorkflowRuntimeException(
                  "Failed to locate a Person with the given employee ID: " + employeeId);
            }
            if (!context.isSimulation()) {
              KEWServiceLocator.getWorkflowDocumentService()
                  .adHocRouteDocumentToPrincipal(
                      person.getPrincipalId(),
                      context.getDocument(),
                      KewApiConstants.ACTION_REQUEST_FYI_REQ,
                      null,
                      null,
                      "Notification Request",
                      person.getPrincipalId(),
                      "Notification Request",
                      true,
                      null);
            }
            // wfDoc.adHocRouteDocumentToPrincipal(KewApiConstants.ACTION_REQUEST_FYI_REQ,
            // "Notification Request", new EmplIdVO(field.getChildText("value")), "Notification
            // Request", true);
            LOG.debug(
                "Sent FYI using the adHocRouteDocumentToPrincipal function to UniversityID:  "
                    + person.getEmployeeId());
            break;
          }
        }
      }
    }
    return super.process(context, helper);
  }
 public SplitResult process(RouteContext context, RouteHelper helper) throws Exception {
   DocumentContent docContent = context.getDocumentContent();
   Document xmlDocument = docContent.getDocument();
   NodeList branchNumberElements = xmlDocument.getElementsByTagName(BRANCH_NUMBER_ELEMENT);
   if (branchNumberElements != null && branchNumberElements.getLength() != 0) {
     Element branchNumberElement = (Element) branchNumberElements.item(0);
     String branchNumber = branchNumberElement.getTextContent();
     if (branchNumber != null && !branchNumber.trim().equals("")) {
       List<String> branchNames = new ArrayList<String>();
       branchNames.add("Branch" + branchNumber);
       return new SplitResult(branchNames);
     }
   }
   // if they didn't submit xml that helps us identify the branch number, just take all branches
   return super.process(context, helper);
 }
  public void recordAction() throws InvalidActionTakenException {
    MDC.put("docId", getRouteHeader().getDocumentId());
    updateSearchableAttributesIfPossible();
    LOG.debug(
        "Moving document "
            + getRouteHeader().getDocumentId()
            + " to point: "
            + displayMovePoint(movePoint)
            + ", annotation: "
            + annotation);

    List actionRequests =
        getActionRequestService()
            .findAllValidRequests(
                getPrincipal().getPrincipalId(),
                getDocumentId(),
                KewApiConstants.ACTION_REQUEST_COMPLETE_REQ);
    Collection activeNodes =
        KEWServiceLocator.getRouteNodeService()
            .getActiveNodeInstances(getRouteHeader().getDocumentId());
    String errorMessage = validateActionRules(actionRequests, activeNodes);
    if (!org.apache.commons.lang.StringUtils.isEmpty(errorMessage)) {
      throw new InvalidActionTakenException(errorMessage);
    }

    RouteNodeInstance startNodeInstance = determineStartNode(activeNodes, movePoint);

    LOG.debug("Record the move action");
    Recipient delegator = findDelegatorForActionRequests(actionRequests);
    ActionTakenValue actionTaken = saveActionTaken(delegator);
    getActionRequestService().deactivateRequests(actionTaken, actionRequests);
    notifyActionTaken(actionTaken);

    // TODO this whole bit is a bit hacky at the moment
    if (movePoint.getStepsToMove() > 0) {
      Set<String> targetNodeNames = new HashSet<String>();
      targetNodeNames.add(determineFutureNodeName(startNodeInstance, movePoint));

      final boolean shouldIndex =
          getRouteHeader().getDocumentType().hasSearchableAttributes()
              && RouteContext.getCurrentRouteContext().isSearchIndexingRequestedForContext();
      String applicationId = routeHeader.getDocumentType().getApplicationId();
      DocumentOrchestrationQueue orchestrationQueue =
          KewApiServiceLocator.getDocumentOrchestrationQueue(
              routeHeader.getDocumentId(), applicationId);
      org.kuali.rice.kew.api.document.OrchestrationConfig orchestrationConfig =
          org.kuali.rice.kew.api.document.OrchestrationConfig.create(
              actionTaken.getActionTakenId(), targetNodeNames);
      DocumentProcessingOptions options =
          DocumentProcessingOptions.create(true, shouldIndex, false);
      orchestrationQueue.orchestrateDocument(
          routeHeader.getDocumentId(),
          getPrincipal().getPrincipalId(),
          orchestrationConfig,
          options);
    } else {
      String targetNodeName = determineReturnNodeName(startNodeInstance, movePoint);
      ReturnToPreviousNodeAction returnAction =
          new ReturnToPreviousNodeAction(
              KewApiConstants.ACTION_TAKEN_MOVE_CD,
              getRouteHeader(),
              getPrincipal(),
              annotation,
              targetNodeName,
              false);

      returnAction.recordAction();
    }
  }