@Override
  public Boolean doWork() throws Exception {
    if (tracer.isDebugEnabled()) tracer.debug("DocumentAcquiring action.doWork, execution init");

    try {
      // calculating DOCUMENT_ACQUIRING properties values
      Map<QName, Serializable> properties = new HashMap<QName, Serializable>();
      properties.put(
          SinekartaModel.PROP_QNAME_TIMESTAMP_PROCESS_START, new Date(System.currentTimeMillis()));
      properties.put(
          SinekartaModel.PROP_QNAME_REFERENCE_ID,
          (String) this.nodeService.getProperty(actionedUponNodeRef, ContentModel.PROP_NODE_UUID));

      // have we received info about the document type?
      if (documentType != null) {
        // if yes the document is moving from another space
        properties.put(SinekartaModel.PROP_QNAME_DOCUMENT_MOVED, true);
        properties.put(SinekartaModel.PROP_QNAME_DOCUMENT_DATE, documentDate);
        properties.put(SinekartaModel.PROP_QNAME_DOCUMENT_TYPE, "" + documentType.getId());
        properties.put(SinekartaModel.PROP_QNAME_LANGUAGE, documentLanguage);
      }

      // adding DOCUMENT_ACQUIRING aspect to document
      nodeService.addAspect(
          actionedUponNodeRef, SinekartaModel.ASPECT_QNAME_DOCUMENT_ACQUIRING, properties);

      if (documentType != null) {

        if (tracer.isDebugEnabled())
          tracer.debug("DocumentAcquiring doWork : let's go to reorganize the archive");

        // invoking archive organization action
        Action documentOrganize =
            actionService.createAction(DocumentOrganize.ACTION_NAME_DOCUMENT_ORGANIZE);
        try {
          actionService.executeAction(documentOrganize, actionedUponNodeRef, false, false);
        } catch (Throwable t) {
          tracer.error("Unable to reorganize archive", t);
          throw new DocumentAcquiringException("Unable to reorganize archive", t);
        }
      }
    } catch (Throwable e) {
      tracer.error("DocumentAcquiring action.doWork, unable to acquire document", e);
      koReason = "DocumentAcquiring action.doWork, unable to acquire document : " + e.getMessage();
      return false;
    }

    if (tracer.isDebugEnabled()) tracer.debug("DocumentAcquiring action.doWork, finished ok");

    return true;
  }
Example #2
0
 /**
  * Sends an invitation email.
  *
  * @param properties A Map containing the properties needed to send the email.
  */
 public void sendMail(Map<String, String> properties) {
   checkProperties(properties);
   ParameterCheck.mandatory("Properties", properties);
   NodeRef inviter = personService.getPerson(properties.get(wfVarInviterUserName));
   String inviteeName = properties.get(wfVarInviteeUserName);
   NodeRef invitee = personService.getPerson(inviteeName);
   Action mail = actionService.createAction(MailActionExecuter.NAME);
   mail.setParameterValue(MailActionExecuter.PARAM_FROM, getEmail(inviter));
   mail.setParameterValue(MailActionExecuter.PARAM_TO, getEmail(invitee));
   mail.setParameterValue(MailActionExecuter.PARAM_SUBJECT, buildSubject(properties));
   mail.setParameterValue(MailActionExecuter.PARAM_TEMPLATE, getEmailTemplateNodeRef());
   mail.setParameterValue(
       MailActionExecuter.PARAM_TEMPLATE_MODEL,
       (Serializable) buildMailTextModel(properties, inviter, invitee));
   mail.setParameterValue(MailActionExecuter.PARAM_IGNORE_SEND_FAILURE, true);
   actionService.executeAction(mail, getWorkflowPackage(properties));
 }
  /** This is where the action is. */
  @Override
  protected void executeImpl(Action action, NodeRef someRef) {

    if (logger.isDebugEnabled()) logger.debug("enter executeImpl");

    // ReportingRoot reportingRoot = new ReportingRoot(someRef);
    // reportingHelper.initializeReportingRoot(reportingRoot);

    // get the frequency value (hourly, daily, weekly, monthly)
    String executionFrequency = (String) action.getParameterValue(EXECUTION_FREQUENCY);

    if (executionFrequency == null) executionFrequency = "hourly";

    // build a query to find all reportingContainer folders
    // having the executionFrequency, AND executionEnabled
    String query =
        "+@reporting\\:executionFrequency:\""
            + executionFrequency
            + "\" "
            + "+@reporting\\:executionEnabled:true";
    if (logger.isDebugEnabled()) logger.debug("executeImpl query=" + query);

    // build the query and execute. Find all relevant reportingContainers

    ResultSet results =
        searchService.query(
            StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, Constants.QUERYLANGUAGE, query);

    // cycle the resultset
    for (ResultSetRow resultRow : results) {
      NodeRef containerRef = resultRow.getChildAssocRef().getChildRef();

      ReportingContainer reportingContainer = new ReportingContainer(containerRef);
      reportingHelper.initializeReportingContainer(reportingContainer);

      logger.debug("Found container: " + reportingContainer.getName());

      // get its related ReportingRoot
      ReportingRoot reportingRoot =
          new ReportingRoot(reportingHelper.getReportingRoot(containerRef));
      reportingHelper.initializeReportingRoot(reportingRoot);

      // determine if execution of this container is allowed considering
      // the parent ReportingRoot
      if (reportingRoot.isGlobalExecutionEnabled()) {

        // Start a reportingContainerExecuter for the given noderef.
        // Pass the NodeRef of the ReportingRoot since we know who that is.
        Action customAction = actionService.createAction(ReportContainerExecutor.NAME);
        // action.setParameterValue(
        //		ReportContainerExecutor.REPORTING_CONTAINER_NODEREF, containerRef);

        actionService.executeAction(customAction, containerRef);
      } // end if reportingExecturinEnabled()
      {
        logger.warn(
            "Container execution of "
                + reportingContainer.getName()
                + " veto'd by ReportingRoot "
                + reportingRoot.getName());
      }
    } // end for ResultSetRow

    if (logger.isDebugEnabled()) logger.debug("exit executeImpl");
  }