protected DocumentMetadata getMetaFromVersionKey(String versionDocPath) {
   String metaData = metaStore.get(versionDocPath);
   if (metaData != null) {
     return JacksonUtil.objectFromJson(metaData, DocumentMetadata.class);
   }
   return null;
 }
Exemplo n.º 2
0
 public EmailAlerter(String templateName) {
   String templateJson =
       Kernel.getSys()
           .retrieveSystemConfig(
               ContextFactory.getKernelUser(), "CONFIG", TEMPLATE_URI + templateName);
   this.emailTemplate = JacksonUtil.objectFromJson(templateJson, EmailTemplate.class);
 }
Exemplo n.º 3
0
 public static EmailTemplate getEmailTemplate(CallingContext context, String templateName) {
   String templateJson =
       Kernel.getSys().retrieveSystemConfig(context, "CONFIG", EMAIL_TEMPLATE_DIR + templateName);
   if (StringUtils.isBlank(templateJson)) {
     throw RaptureExceptionFactory.create("Email template " + templateName + " does not exist");
   }
   return JacksonUtil.objectFromJson(templateJson, EmailTemplate.class);
 }
 @Override
 public ReflexValue readContent(ReflexStreamValue file, IReflexIOHandler ioHandler) {
   // The file is one big JSON document, and in fact is an array, so
   // convert it to an array
   ReflexValue content = ioHandler.getContent(file);
   List<?> ret = JacksonUtil.objectFromJson(content.toString(), List.class);
   return new ReflexValue(ret);
 }
Exemplo n.º 5
0
 public static SMTPConfig getSMTPConfig() {
   String configString =
       Kernel.getSys()
           .retrieveSystemConfig(ContextFactory.getKernelUser(), "CONFIG", SMTP_CONFIG_URL);
   if (StringUtils.isBlank(configString)) {
     throw RaptureExceptionFactory.create("No SMTP configured");
   }
   return JacksonUtil.objectFromJson(configString, SMTPConfig.class);
 }
 /**
  * Insert values into the array, preserving the original order of the request
  *
  * @param docsWithMeta - array to set values in with the correct order
  * @param positions - the original ordering
  * @param contents - the document contents
  * @param metaContents - the meta document contents
  */
 protected void constructDocumentWithMetaList(
     DocumentWithMeta[] docsWithMeta,
     List<RaptureURI> uris,
     List<Integer> positions,
     List<String> contents,
     List<String> metaContents) {
   if (contents.size() != metaContents.size()) {
     log.error("Batch getDocAndMetas failed due to different size of content vs metaContent");
     return;
   }
   for (int i = 0; i < contents.size(); i++) {
     DocumentWithMeta dwm = new DocumentWithMeta();
     String meta = metaContents.get(i);
     if (meta != null) {
       dwm.setMetaData(JacksonUtil.objectFromJson(meta, DocumentMetadata.class));
     }
     dwm.setContent(contents.get(i));
     dwm.setDisplayName(uris.get(positions.get(i)).getDocPath());
     docsWithMeta[positions.get(i)] = dwm;
   }
 }
Exemplo n.º 7
0
 HooksConfig readFromFile() {
   String json = ConfigLoader.getConf().DefaultApiHooks;
   return JacksonUtil.objectFromJson(json, HooksConfig.class);
 }
  @Override
  public String invoke(CallingContext ctx) {
    DecisionApi decision = Kernel.getDecision();
    String workOrderUri = new RaptureURI(getWorkerURI(), Scheme.WORKORDER).toShortString();
    String config =
        StringUtils.stripToNull(decision.getContextValue(ctx, workOrderUri, "CONFIGURATION"));

    try {
      decision.setContextLiteral(ctx, getWorkerURI(), "STEPNAME", getStepName());

      String docPath = new RaptureURI(workOrderUri).getDocPath();
      int lio = docPath.lastIndexOf('/');
      if (lio < 0) lio = 0;

      StringBuilder externalUrl = new StringBuilder();
      String host = System.getenv("HOST");
      String port = System.getenv("PORT");
      externalUrl
          .append("http://")
          .append((host != null) ? host : LOCALHOST)
          .append(":")
          .append((port != null) ? port : DEFAULT_RIM_PORT)
          .append("/process/")
          .append(docPath.substring(0, lio))
          .append(WORKORDER_DELIMETER)
          .append(docPath.substring(lio + 1));
      decision.setContextLiteral(
          ctx, workOrderUri, EXTERNAL_RIM_WORKORDER_URL, externalUrl.toString());

      Map<String, String> view = new HashMap<>();
      DocApi docApi = Kernel.getDoc();

      if (config == null) {
        decision.writeWorkflowAuditEntry(
            ctx, getWorkerURI(), "No configuration document specified", false);
        return this.getNextTransition();
      }
      List<String> configs;
      try {
        // Could be a list or a single entry.
        configs = JacksonUtil.objectFromJson(config, ArrayList.class);
      } catch (Exception e) {
        configs = ImmutableList.of(config);
      }

      for (String conf : configs) {
        if (docApi.docExists(ctx, conf)) {
          String doc = docApi.getDoc(ctx, conf);
          Map<String, Object> map = JacksonUtil.getMapFromJson(doc);
          for (Entry<String, Object> entry : map.entrySet()) {
            String key = entry.getKey();
            String value = StringUtils.stripToNull(entry.getValue().toString());
            ContextValueType type = ContextValueType.getContextValueType(value.charAt(0));
            if (type == ContextValueType.NULL) {
              type = ContextValueType.LITERAL;
            } else value = value.substring(1);
            ExecutionContextUtil.setValueECF(ctx, workOrderUri, view, key, type, value);
            decision.writeWorkflowAuditEntry(
                ctx,
                getWorkerURI(),
                getStepName() + ": Read configuration data from " + conf,
                false);
          }
        } else {
          decision.writeWorkflowAuditEntry(
              ctx,
              getWorkerURI(),
              getStepName() + ": Cannot locate configuration document " + conf,
              true);
        }
      }
      return Steps.NEXT.toString();
    } catch (Exception e) {
      decision.setContextLiteral(
          ctx, getWorkerURI(), getStepName(), "Exception in workflow : " + e.getLocalizedMessage());
      decision.setContextLiteral(ctx, getWorkerURI(), getErrName(), ExceptionToString.summary(e));
      log.error(ExceptionToString.format(ExceptionToString.getRootCause(e)));
      decision.writeWorkflowAuditEntry(
          ctx,
          getWorkerURI(),
          "Problem in " + getStepName() + ": unable to read the configuration document " + config,
          true);
      decision.writeWorkflowAuditEntry(
          ctx,
          getWorkerURI(),
          ": " + ExceptionToString.getRootCause(e).getLocalizedMessage(),
          true);

      return getErrorTransition();
    }
  }
Exemplo n.º 9
0
 public static ReflexValue deserialize(String json) throws ClassNotFoundException {
   Object x = JacksonUtil.objectFromJson(json, Object.class);
   return KernelExecutor.reconstructFromObject(x);
 }
Exemplo n.º 10
0
 private static SMTPConfig getEmailConfig() {
   String configString =
       Kernel.getSys().retrieveSystemConfig(ContextFactory.getKernelUser(), "CONFIG", CONFIG_URI);
   return JacksonUtil.objectFromJson(configString, SMTPConfig.class);
 }