Ejemplo n.º 1
0
  public String btnView_action() {
    String itemID = (String) hdnSelectedItemID.getValue();
    if (itemID == null) {
      msgPanel.error("No work item selected. Please select a work item to view.");
      return null;
    }

    WorkItemRecord selectedWIR = getSelectedWIR(itemID);

    // maybe the wir isn't started or was part of a cancellation set and now it's gone
    if (selectedWIR == null) {
      msgPanel.error(
          "Cannot view item contents - it appears that the "
              + "selected item may have been removed or cancelled. "
              + "Please see the log files for details.");
      return null;
    }

    _sb.setDynFormType(ApplicationBean.DynFormType.tasklevel);
    DynamicForm df = (DynamicForm) getBean("DynFormFactory");
    String title = "YAWL 3.0 - Edit Work Item";
    String header = "Edit Work Item: " + selectedWIR.getCaseID();
    if (df.makeForm(title, header, _sb.getTaskSchema(selectedWIR), selectedWIR)) {
      _sb.setVisualiserReferred(true);
      _sb.setVisualiserEditedWIR(selectedWIR);
      return "showDynForm";
    } else {
      msgPanel.error(
          "Cannot view item contents - problem initialising "
              + "dynamic form from task specification. "
              + "Please see the log files for details.");
      return null;
    }
  }
  private void ItemPostConstraint(WorkItemRecord wir, String data) {
    AdviceQuery query = new AdviceQuery();

    List<Advice> advs = query.getAdvicesByAdviceJoinPointID(wir.getID());
    if ((advs != null) && (advs.size() > 0)) {
      suspendCase(wir.getCaseID().substring(0, wir.getCaseID().indexOf('.')));
      System.out.println("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@");
      System.out.println(
          "suspended case is " + wir.getCaseID().substring(0, wir.getCaseID().indexOf('.')));
      for (Advice advice : advs) {
        SAXBuilder builder = new SAXBuilder();

        List<org.jdom2.Element> ls = null;
        org.jdom2.Element root = null;
        try {
          org.jdom2.Document document = builder.build(new StringReader(data));
          ls = document.getRootElement().getChildren();
        } catch (Exception e) {
          System.out.println(e);
        }
        String s = "<" + advice.getProceedName() + ">";
        for (org.jdom2.Element l : ls) {
          s = s + "<" + l.getName() + ">" + l.getText() + "</" + l.getName() + ">";
        }
        s = s + "</" + advice.getProceedName() + ">";

        connect();

        advice.setSynched(false);
        this._Persister.beginTransaction();
        this._Persister.update(advice);
        this._Persister.commit();

        System.out.println(
            "*** try to checkin workitem with proceed id of "
                + advice.getProceedID()
                + " - with data: "
                + s);
        try {
          _ibClient.checkInWorkItem(advice.getProceedID(), s, "", _handle);
        } catch (IOException e) {
          System.out.println("************************ problem in checkin");
          e.printStackTrace();
        }
      }
    }
  }
  private void handleProceedPlaceholder(WorkItemRecord enabledWorkItem) {
    connect();
    try {
      WorkItemRecord childWorkItem = checkOut(enabledWorkItem.getID(), _handle);
      AdviceQuery query = new AdviceQuery();

      List<Advice> advs = query.getByAdviceName(enabledWorkItem.getSpecURI());
      System.out.println(">>>> Number of the same advices are " + advs.size());
      if ((advs != null) && (advs.size() > 0)) {
        System.out.println(">>>> Number of the launched advices are " + advs.size());
        do {
          advs = query.getByAdviceCaseID(enabledWorkItem.getCaseID());
        } while ((advs == null) || (advs.size() == 0));
        System.out.println(">>>> Number of the launched advices are " + advs.size());

        Advice advice = (Advice) advs.get(0);
        advice.setSynched(true);
        advice.setProceedName(enabledWorkItem.getTaskName());
        advice.setProceedID(childWorkItem.getID());

        this._Persister.beginTransaction();
        this._Persister.update(advice);
        this._Persister.commit();

        System.out.println(">>>> Proceed Name is " + advice.getProceedName());
        System.out.println(">>>> Proceed ID is " + advice.getProceedID());

        org.jdom2.Element d =
            getDataforCase(
                advice.getParentSpecName(),
                advice.getParentCaseID(),
                _ibClient.getCaseData(enabledWorkItem.getCaseID(), _handle));

        this._ixClient.updateCaseData(advice.getParentCaseID(), d, _handle);

        weaving(advice.getParentCaseID(), advice.getAdjpID(), false);
      }
    } catch (IOException | YAWLException e) {
      e.printStackTrace();
    }
  }
  private void ItemPreConstraint(WorkItemRecord wir, String data) {
    Collection<String> advices = evaluateRule(wir.getSpecURI(), wir.getTaskName(), data);
    if (advices.size() > 0) {
      suspendCase(wir.getCaseID().substring(0, wir.getCaseID().indexOf('.')));
      for (String s : advices) {
        try {
          uploadAdvice(s);

          String res = mapItemParamsToAdviceCaseParams(s, getInputParams(getAdviceID(s)), data);

          Advice advice = new Advice();
          advice.setParentSpecID(wir.getSpecIdentifier());
          advice.setParentSpecName(wir.getSpecURI());
          advice.setParentCaseID(wir.getCaseID().substring(0, wir.getCaseID().indexOf('.')));

          advice.setAdjpID(wir.getID());
          advice.setAdjpDataString(data);
          advice.setAdviceName(s);

          advice.setSynched(false);

          this._Persister.beginTransaction();
          this._Persister.insert(advice);
          this._Persister.commit();

          String adviceCaseID = launchAdvice(getAdviceID(s), res);

          advice.setAdviceCaseID(adviceCaseID);

          this._Persister.beginTransaction();
          this._Persister.update(advice);
          this._Persister.commit();
        } catch (IOException e) {
          e.printStackTrace();
        }
      }
    }
  }
 private String getNetParamValue(WorkItemRecord wir, String name) {
   String result = null;
   try {
     result = _rm.getNetParamValue(wir.getCaseID(), _name);
     if (result == null)
       _log.error(
           "Unable to retrieve value from net parameter '"
               + name
               + "' for deferred allocation of workitem '"
               + wir.getID()
               + "'.");
   } catch (IOException ioe) {
     _log.error(
         "Caught exception attempting to retrieve value from net parameter '"
             + name
             + "' for deferred allocation of workitem '"
             + wir.getID()
             + "'.");
   }
   return result;
 }
Ejemplo n.º 6
0
  public static final void main(final String[] args) throws Exception {

    // This simulates the method:
    // public YParameter[] describeRequiredParams()

    // NOTE: with the addition of Ehcache, RabbitMQ use is required for end
    // of life cycle tasks; e.g., writing data to Gate, to a Neo4J Db, or
    // to a file, etc.
    // The YAWL engine startup and a YawlGatewayObserver class MessagingLoader
    // will load this when in a Yawl server environment, we load here, for
    // testing. BUT, a RabbitMQ server SHALL be running someplace as referenced in the
    // RabbitMqConnection.properties config file.
    LOGGER.info("------------------------------ STARTUP ---------------------------------");
    LOGGER.info("------------------------------------------------------------------------");
    LOGGER.info(
        "Like sands through the hourglass, so are the days of our lives: {}",
        StringUtil.dateAsRfc822(false));
    LOGGER.info("------------------------------------------------------------------------");

    LOGGER.info("----------------------------  EHCACHE   --------------------------------");
    // This gives the system a chance to load the Ehcache properties file
    // and to set up the BootstrapPropertiesFetcher and BootstrapConfigFinder
    // classes, again to bootstrap - individual web apps will
    // need to create their own instances.
    //		BootstrapPropertiesFetcher bspf = new BootstrapPropertiesFetcher();
    //		LOGGER.info("BootstrapPropertiesFetcher: using this server: {}",
    //				bspf.getProperties().getProperty("ehcache.client.serviceurl"));

    LOGGER.info("------------------------------  GATE   ---------------------------------");

    if (null == GateDataStore.getInstance()) {
      LOGGER.info("Gate: Failure on GateDataStore.getInstance(): Gate not available.");
    }

    LOGGER.info("------------------------------  NEO4J  ---------------------------------");

    LOGGER.info("----------------  Using the server instance of Neo4J.  -----------------");

    // Using the Neo4J server instead of embedded due to issues with single instance
    // within this environment.
    // See the PersistenceConnection.properties file.

    LOGGER.info("-------------------------  CAMEL FILEMOVER  ----------------------------");

    FileMover fm = new FileMover("FileMover.properties");
    fm.prepareCamelContext();

    LOGGER.info("----------------------  CAMEL FILEPROCESSOR  ---------------------------");

    FileProcessor fp = new FileProcessor("FileProcessor.properties");
    fp.prepareCamelContext();

    LOGGER.info("----------------------  CAMEL IMAPPROCESSOR  ---------------------------");

    ImapProcessor imp = new ImapProcessor("ImapProcessor.properties");
    imp.prepareCamelContext();

    LOGGER.info("----------------------  CAMEL GATEPROCESSOR  ---------------------------");

    GateProcessor gp = new GateProcessor("GateFileProcessor.properties");
    gp.prepareCamelContext();

    LOGGER.info("--------------------  CAMEL TIKAFILEPROCESSOR  -------------------------");

    TikaFileProcessor tfp = new TikaFileProcessor("TikaFileProcessor.properties");
    tfp.prepareCamelContext();

    LOGGER.info("----------------------  CAMEL TIKAPROCESSOR  ---------------------------");

    // TikaProcessor is currently using a singleton due to issues writing to
    // Lucene index - one writer per index - always ...
    if (null == TikaLuceneProcessor.getInstance()) {
      LOGGER.info(
          "TikaProcessor: Failure on TikaProcessor.getInstance(): TikaProcessor not available.");
    }

    LOGGER.info("----------------------  CAMEL CMISPROCESSOR  ---------------------------");

    CmisProcessor cp = new CmisProcessor("CmisFileProcessor.properties");
    cp.prepareCamelContext();

    LOGGER.info("------------------------------ RabbitMq --------------------------------");
    LOGGER.info("MessagingLoader: announceEngineInitialised: IS using RabbitMQ listener.");

    if (ProcessKonstants.YDS_MESSAGE_QUEUE_AVAILABLE.equalsIgnoreCase("true")) {
      LOGGER.info("MessagingLoader: announceEngineInitialised: Starting YDS message listener.");
      // Spin off the Receiver instance.
      new Thread(
              new Runnable() {
                public void run() {
                  Receiver.getInstance().receiver(null);
                }
              })
          .start();
    }

    LOGGER.info("------------  PAUSING TO ALLOW ABOVE INSTANCES TO SPIN UP  -------------\n");
    try {
      LOGGER.info("I'm so sleepy, I'll take a quick nap ... {}\n", StringUtil.dateAsRfc822(false));
      Thread.sleep(20000);

    } catch (InterruptedException e) {
      LOGGER.error("Startup Pause: Error in Thread.sleep(20000): ", e.getLocalizedMessage());
    }
    LOGGER.info(
        "Wow, great nap - you've been busy already - let's play! {}\n",
        StringUtil.dateAsRfc822(false));
    LOGGER.info("---------------------------- END STARTUP -------------------------------\n");

    // SNIPPET START: Replace form here down to the last SNIPPET END ...
    LOGGER.info("----------------------------- START TEST -------------------------------");
    LOGGER.info(
        SERVICE_NAME + " TEST: describeRequiredParams: {}", SERVICE_NAME + ProcessKonstants.AVRO);
    LOGGER.info("------------------------------------------------------------------------\n");

    final YParameter[] params =
        SchemaToInputElement.loadRequiredYawlParams(
            SERVICE_NAME + ProcessKonstants.AVRO, ProcessKonstants.RETURN_DATA_SCHEMA);

    // Use the first params element to store documentation
    if (null != params) {
      params[0].setDocumentation("Add a documentation string here.");
    }

    // ----------------------------------------------------------------------
    // This simulates the method:
    // prepareToExecuteCommand()

    String result = SERVICE_NAME + " TEST: Cannot instantiate service: " + CoreKonstants.YDS_FAILED;

    UuidServiceWrapper uuid = new UuidServiceWrapper();

    if (null != uuid) {

      result =
          uuid.updateStatus(
              uuid.getRdm().getResultId(),
              CoreKonstants.YDS_UNKNOWN,
              "Initializing with parameters.",
              SERVICE_NAME);

      //			 {
      //			      "namespace": "org.imsys.naiche.yds.avro",
      //			      "name": "UuidService",
      //			      "type": "record",
      //			      "fields": [
      //			          {"name": "Guid", "type": "string" }
      //			          ]
      //			}

      // Manually create a data element based on corresponding Avro schema.
      Element data = new Element("data");
      Element guid = new Element("Guid");
      guid.setText("yes");
      data.addContent(guid);

      LOGGER.info(SERVICE_NAME + " TEST: data element: {}", data.toString());
      LOGGER.info("---------------------------------------------------------\n");

      Reflection.yawlElementToObject(SERVICE_NAME, data, uuid);

      // Need to build a YawlWorkitemModel object
      WorkItemRecord wir = new WorkItemRecord();

      wir.setCaseID("CaseId50");
      wir.setTaskID(SERVICE_NAME + "-taskId");
      wir.setTaskName(SERVICE_NAME + "-taskName");
      wir.setDataList(data);

      // SNIPPET START
      // Get a json formatted text of the service object.
      ObjectMapper mapper = new ObjectMapper();
      String yawlInputEleAsJson = null;
      try {

        yawlInputEleAsJson = mapper.writeValueAsString(uuid);

        LOGGER.info(SERVICE_NAME + ": prepareToExecuteCommand: Json: {}", yawlInputEleAsJson);

      } catch (JsonParseException e) {
        LOGGER.error(
            SERVICE_NAME
                + ": prepareToExecuteCommand: JsonParseException: {} "
                + e.getLocalizedMessage());
      } catch (JsonMappingException e) {
        LOGGER.error(
            SERVICE_NAME
                + ": prepareToExecuteCommand: JsonMappingException: {} "
                + e.getLocalizedMessage());
      } catch (IOException e) {
        LOGGER.error(
            SERVICE_NAME + ": prepareToExecuteCommand: IOException: {} " + e.getLocalizedMessage());
      }

      // This creates and inputs a YawlWorkitemModel object into a map for later
      // retrieval.
      YawlWorkitemModel ywim =
          new YawlWorkitemModel(
              "serviceRequestId",
              "dataXmlString",
              "serviceName",
              ENGINEUSER,
              ENGINEPASSWORD,
              "wkitemId",
              // inputData will be created when the service object is instantiated
              null,
              // outputData will be created when the service object is instantiated
              null,
              "wkitemTaskName",
              "wkitemTaskId",
              "wkitemCaseId",
              "wkitemSpecUri",
              "wkitemSpecVersion",
              "wkitemSpecIdentifier",
              SERVICE_NAME + ProcessKonstants.AVRO,
              ProcessKonstants.RETURN_DATA_SCHEMA);

      // Optional, will use in graphDB.
      ywim.setTaskId(wir.getTaskID());
      ywim.setCaseId(wir.getCaseID());
      ywim.setSpecUri(SERVICE_NAME + "SPECIFICATION-NAME");
      ywim.setSpecVersion(SERVICE_NAME + "SPECIFCATION-VERSION");
      ywim.setSpecId(SERVICE_NAME + "SPECIFICATION-GUID");

      ywim.setInputSchemaName(SERVICE_NAME + ProcessKonstants.AVRO);
      ywim.setOutputSchemaName(ProcessKonstants.RETURN_DATA_SCHEMA);

      // ywim.putWorkitemToMap(uuid.getRdm().getResultId() , ywim);
      // SNIPPET END.

      // This realizes the goal of the service.
      result = uuid.performService();

      LOGGER.info(SERVICE_NAME + " TEST: result: {}", result);
      LOGGER.info("-----------------------END OF TEST--------------------------\n");

      // SNIPPET END: To here with a service class to test. Leave the other external
      // services running to better test some level of integration prior to doing a
      // full build and running in the container.

      LOGGER.info("CAMEL PROCCESES MAY CONTINUE TO RUN - WATCH FOLDERS AND EMAIL FOR OUTPUT");
      LOGGER.info("-------------------------------- END -----------------------------------\n");
    }

    // Give the running services some time to catch up ...
    try {
      Thread.sleep(10000);
    } catch (InterruptedException e) {
      LOGGER.error("Test: Error in Thread.sleep(10000): ", e.getLocalizedMessage());
    }

    BufferedReader ir = new BufferedReader(new InputStreamReader(System.in));
    String s = null;
    System.out.print("\nshutdown prompt:>>> ");
    while ((s = ir.readLine()).length() > 0) {
      if (s.equals("shutdown")) {
        System.out.println("\nSending shutdown request ...");

        System.out.println("Shutdown successful. Quitting console.\n");

        System.exit(0);
      }
      System.out.print("\nshutdown prompt:>>> ");
    }
  }