Esempio n. 1
0
  /** Get Process Definition Forms */
  public static Map<String, List<FormElement>> getProcessDefinitionForms(long processDefinitionId)
      throws ParseException {
    log.debug("getProcessDefinitionForms({})", processDefinitionId);
    JbpmContext jbpmContext = JBPMUtils.getConfig().createJbpmContext();
    Map<String, List<FormElement>> forms = new HashMap<String, List<FormElement>>();
    InputStream is = null;

    try {
      GraphSession graphSession = jbpmContext.getGraphSession();
      org.jbpm.graph.def.ProcessDefinition pd =
          graphSession.getProcessDefinition(processDefinitionId);
      FileDefinition fileDef = pd.getFileDefinition();
      is = fileDef.getInputStream("forms.xml");

      if (is != null) {
        forms = FormUtils.parseWorkflowForms(is);
      } else {
        log.warn("Process definition '{}' has no forms.xml file", processDefinitionId);
      }
    } finally {
      IOUtils.closeQuietly(is);
      jbpmContext.close();
    }

    log.debug("getProcessDefinitionForms: {}", forms);
    return forms;
  }
Esempio n. 2
0
  /** Register Process Definition */
  public static void registerProcessDefinition(InputStream is)
      throws WorkflowException, ParseException, IOException {
    log.debug("registerProcessDefinition({})", is);
    JbpmContext jbpmContext = JBPMUtils.getConfig().createJbpmContext();
    InputStream isForms = null;
    ZipInputStream zis = null;

    if (Config.SYSTEM_READONLY) {
      throw new WorkflowException("System is in read-only mode");
    }

    try {
      zis = new ZipInputStream(is);
      org.jbpm.graph.def.ProcessDefinition processDefinition =
          org.jbpm.graph.def.ProcessDefinition.parseParZipInputStream(zis);

      // Check xml form definition
      FileDefinition fileDef = processDefinition.getFileDefinition();
      isForms = fileDef.getInputStream("forms.xml");
      FormUtils.parseWorkflowForms(isForms);

      // If it is ok, deploy it
      jbpmContext.deployProcessDefinition(processDefinition);
    } catch (JbpmException e) {
      throw new WorkflowException(e.getMessage(), e);
    } finally {
      IOUtils.closeQuietly(isForms);
      IOUtils.closeQuietly(zis);
      jbpmContext.close();
    }

    log.debug("registerProcessDefinition: void");
  }
Esempio n. 3
0
  /** Create XPath related to property groups. */
  private Object preparePropertyGroups(QueryParams params) throws IOException, ParseException {
    StringBuilder sb = new StringBuilder();

    if (!params.getProperties().isEmpty()) {
      Map<PropertyGroup, List<FormElement>> formsElements =
          FormUtils.parsePropertyGroupsForms(Config.PROPERTY_GROUPS_XML);

      for (Iterator<Entry<String, String>> it = params.getProperties().entrySet().iterator();
          it.hasNext(); ) {
        Entry<String, String> ent = it.next();
        FormElement fe = FormUtils.getFormElement(formsElements, ent.getKey());

        if (fe != null && ent.getValue() != null) {
          String valueTrimmed = ent.getValue().trim();

          if (!valueTrimmed.equals("")) {
            sb.append(" " + params.getOperator() + " ");

            if (fe instanceof Select) {
              sb.append("@" + ent.getKey() + "='" + escapeXPath(valueTrimmed) + "'");
            } else if (fe instanceof Input && ((Input) fe).getType().equals(Input.TYPE_DATE)) {
              String[] date = valueTrimmed.split(",");

              if (date.length == 2) {
                sb.append("@" + ent.getKey() + " >= '" + date[0] + "'");
                sb.append(" and ");
                sb.append("@" + ent.getKey() + " <= '" + date[1] + "'");
              }
            } else {
              sb.append(
                  "jcr:contains(@" + ent.getKey() + ",'" + escapeContains(valueTrimmed) + "')");
            }
          }
        }
      }
    }

    return sb.toString();
  }
  @Override
  public void init() throws ServletException {
    super.init();
    ServletContext sc = getServletContext();

    // Read configuration file
    Properties config = Config.load(sc);

    // Call only once during initialization time of your application
    // @see http://issues.openkm.com/view.php?id=1577
    SLF4JBridgeHandler.install();

    // Get OpenKM version
    WarUtils.readAppVersion(sc);
    log.info("*** Application version: {} ***", WarUtils.getAppVersion());

    // Database initialize
    log.info("*** Hibernate initialize ***");
    HibernateUtil.getSessionFactory();

    // Create missing directories
    // NOTE: Should be executed AFTER Hibernate initialization because if in created mode
    // initialization will drop these directories
    createMissingDirs();

    try {
      // Initialize property groups
      log.info("*** Initialize property groups... ***");
      FormUtils.parsePropertyGroupsForms(Config.PROPERTY_GROUPS_XML);
    } catch (Exception e) {
      log.error(e.getMessage(), e);
    }

    // Initialize language detection engine
    try {
      log.info("*** Initialize language detection engine... ***");
      DetectorFactory.loadProfile(Config.LANG_PROFILES_BASE);
    } catch (LangDetectException e) {
      log.error(e.getMessage(), e);
    }

    // Load database configuration
    Config.reload(sc, config);

    // Invoke start
    start();

    // Activity log
    UserActivity.log(Config.SYSTEM_USER, "MISC_OPENKM_START", null, null, null);
  }