示例#1
0
  public static final void process(IData pipeline) throws ServiceException {
    // --- <<IS-START(process)>> ---
    // @subtype unknown
    // @sigtype java 3.5
    // [i] field:0:required $file
    // [i] field:0:optional $mode {&quot;read&quot;,&quot;append&quot;,&quot;write&quot;}
    // [i] field:0:required $service
    // [i] record:0:optional $pipeline
    // [i] field:0:optional $service.input
    // [o] record:0:optional $pipeline
    IDataCursor cursor = pipeline.getCursor();

    try {
      String file = IDataUtil.getString(cursor, "$file");
      String mode = IDataUtil.getString(cursor, "$mode");
      String service = IDataUtil.getString(cursor, "$service");
      String input = IDataUtil.getString(cursor, "$service.input");
      IData scope = IDataUtil.getIData(cursor, "$pipeline");
      boolean scoped = scope != null;

      scope = process(file, mode, service, input, scoped ? scope : pipeline);

      if (scoped) IDataUtil.put(cursor, "$pipeline", scope);
    } finally {
      cursor.destroy();
    }
    // --- <<IS-END>> ---

  }
示例#2
0
  public static final void format(IData pipeline) throws ServiceException {
    // --- <<IS-START(format)>> ---
    // @sigtype java 3.5
    // [i] field:0:optional $datetime
    // [i] field:0:optional $pattern.input
    // {&quot;datetime&quot;,&quot;date&quot;,&quot;time&quot;,&quot;milliseconds&quot;}
    // [i] field:0:optional $pattern.output
    // {&quot;datetime&quot;,&quot;date&quot;,&quot;time&quot;,&quot;milliseconds&quot;}
    // [o] field:0:optional $datetime
    IDataCursor cursor = pipeline.getCursor();

    try {
      String datetime = IDataUtil.getString(cursor, "$datetime");
      String inPattern = IDataUtil.getString(cursor, "$pattern.input");
      String outPattern = IDataUtil.getString(cursor, "$pattern.output");

      datetime = format(datetime, inPattern, outPattern);

      if (datetime != null) IDataUtil.put(cursor, "$datetime", datetime);
    } finally {
      cursor.destroy();
    }
    // --- <<IS-END>> ---

  }
示例#3
0
  public static final void write(IData pipeline) throws ServiceException {
    // --- <<IS-START(write)>> ---
    // @subtype unknown
    // @sigtype java 3.5
    // [i] field:0:optional $file
    // [i] field:0:optional $mode {&quot;append&quot;,&quot;write&quot;}
    // [i] object:0:optional $content
    // [i] field:0:optional $encoding
    // [o] field:0:optional $file
    IDataCursor cursor = pipeline.getCursor();

    try {
      String file = IDataUtil.getString(cursor, "$file");
      String mode = IDataUtil.getString(cursor, "$mode");
      Object content = IDataUtil.get(cursor, "$content");
      String encoding = IDataUtil.getString(cursor, "$encoding");

      file = write(file, mode, content, encoding);

      IDataUtil.put(cursor, "$file", file);
    } finally {
      cursor.destroy();
    }
    // --- <<IS-END>> ---

  }
示例#4
0
  public static final void validate(IData pipeline) throws ServiceException {
    // --- <<IS-START(validate)>> ---
    // @sigtype java 3.5
    // [i] field:0:required $datetime
    // [i] field:0:optional $pattern
    // {&quot;date.jdbc&quot;,&quot;date.xml&quot;,&quot;datetime.jdbc&quot;,&quot;datetime.xml&quot;,&quot;datetime.xcbl&quot;,&quot;datetime.sapiens&quot;,&quot;datetime.epoch.milliseconds&quot;,&quot;time.jdbc&quot;,&quot;time.xml&quot;}
    // [i] field:0:optional $raise? {&quot;false&quot;,&quot;true&quot;}
    // [o] field:0:required $valid?
    IDataCursor cursor = pipeline.getCursor();

    boolean valid = true, raise = false;
    try {
      String datetime = IDataUtil.getString(cursor, "$datetime");
      String pattern = IDataUtil.getString(cursor, "$pattern");
      raise = Boolean.parseBoolean(IDataUtil.getString(cursor, "$raise?"));

      // attempt to parse the datetime string, if no exception is thrown then the string is valid
      parse(datetime, pattern);
    } catch (IllegalArgumentException ex) {
      if (raise) tundra.exception.raise(ex);
      valid = false;
    } finally {
      IDataUtil.put(cursor, "$valid?", "" + valid);
      cursor.destroy();
    }
    // --- <<IS-END>> ---

  }
示例#5
0
  public static final void compare(IData pipeline) throws ServiceException {
    // --- <<IS-START(compare)>> ---
    // @sigtype java 3.5
    // [i] field:0:optional $datetime.x
    // [i] field:0:optional $datetime.y
    // [o] field:0:required $before?
    // [o] field:0:required $equal?
    // [o] field:0:required $after?
    IDataCursor cursor = pipeline.getCursor();

    try {
      String dx = IDataUtil.getString(cursor, "$datetime.x");
      String dy = IDataUtil.getString(cursor, "$datetime.y");

      int comparison = compare(dx, dy);

      IDataUtil.put(cursor, "$before?", "" + (comparison < 0));
      IDataUtil.put(cursor, "$equal?", "" + (comparison == 0));
      IDataUtil.put(cursor, "$after?", "" + (comparison > 0));
    } finally {
      cursor.destroy();
    }
    // --- <<IS-END>> ---

  }
示例#6
0
  public static final void decompress(IData pipeline) throws ServiceException {
    // --- <<IS-START(decompress)>> ---
    // @subtype unknown
    // @sigtype java 3.5
    // [i] object:0:optional $content.gzip
    // [i] field:0:optional $encoding
    // [i] field:0:optional $mode
    // {&quot;stream&quot;,&quot;bytes&quot;,&quot;string&quot;,&quot;base64&quot;}
    // [o] object:0:optional $content
    IDataCursor cursor = pipeline.getCursor();

    try {
      Object input = IDataUtil.get(cursor, "$content.gzip");
      Charset charset = CharsetHelper.normalize(IDataUtil.getString(cursor, "$encoding"));
      ObjectConvertMode mode = ObjectConvertMode.normalize(IDataUtil.getString(cursor, "$mode"));

      Object output =
          ObjectHelper.convert(
              GzipHelper.decompress(InputStreamHelper.normalize(input, charset)), charset, mode);

      if (output != null) IDataUtil.put(cursor, "$content", output);
    } catch (IOException ex) {
      ExceptionHelper.raise(ex);
    } finally {
      cursor.destroy();
    }
    // --- <<IS-END>> ---

  }
示例#7
0
  public static final void get(IData pipeline) throws ServiceException {
    // --- <<IS-START(get)>> ---
    // @subtype unknown
    // @sigtype java 3.5
    // [i] record:0:optional $bizdoc
    // [i] - field:0:required InternalID
    // [i] field:0:optional $part
    // [o] object:0:optional $content
    // [o] field:0:optional $content.type
    IDataCursor cursor = pipeline.getCursor();

    try {
      IData bizdoc = IDataUtil.getIData(cursor, "$bizdoc");
      String partName = IDataUtil.getString(cursor, "$part");

      if (bizdoc != null) {
        ContentPart part = new ContentPart(bizdoc, partName);
        java.io.InputStream content = part.getContent();

        if (content != null) {
          IDataUtil.put(cursor, "$content", content);
          IDataUtil.put(cursor, "$content.type", part.getMimeType());
        }
      }
    } finally {
      cursor.destroy();
    }
    // --- <<IS-END>> ---

  }
示例#8
0
  public static final void getTimeZoneOffsetFromGMT(IData pipeline) throws ServiceException {
    // --- <<IS-START(getTimeZoneOffsetFromGMT)>> ---
    // @subtype unknown
    // @sigtype java 3.5
    // [i] field:0:required inTimeZone
    // [o] field:0:required outOffset

    // pipeline
    IDataCursor pipelineCursor = pipeline.getCursor();
    String inTimeZone = IDataUtil.getString(pipelineCursor, "inTimeZone");
    pipelineCursor.destroy();

    java.util.TimeZone inTZ = java.util.TimeZone.getTimeZone(inTimeZone);
    java.util.Calendar inCalendar = new java.util.GregorianCalendar(inTZ);
    int offset =
        inCalendar.get(java.util.Calendar.ZONE_OFFSET)
            + inCalendar.get(java.util.Calendar.DST_OFFSET);

    // pipeline
    IDataCursor pipelineCursor_1 = pipeline.getCursor();
    IDataUtil.put(pipelineCursor_1, "outOffset", String.valueOf(offset));
    pipelineCursor_1.destroy();
    // --- <<IS-END>> ---

  }
示例#9
0
  public static final void add(IData pipeline) throws ServiceException {
    // --- <<IS-START(add)>> ---
    // @sigtype java 3.5
    // [i] field:0:optional $datetime
    // [i] field:0:optional $duration
    // [o] field:0:optional $datetime
    IDataCursor cursor = pipeline.getCursor();

    try {
      String datetime = IDataUtil.getString(cursor, "$datetime");
      String duration = IDataUtil.getString(cursor, "$duration");
      IDataUtil.put(cursor, "$datetime", add(datetime, duration));
    } finally {
      cursor.destroy();
    }
    // --- <<IS-END>> ---

  }
示例#10
0
  public static final void rename(IData pipeline) throws ServiceException {
    // --- <<IS-START(rename)>> ---
    // @subtype unknown
    // @sigtype java 3.5
    // [i] field:0:required $file.source
    // [i] field:0:required $file.target
    IDataCursor cursor = pipeline.getCursor();

    try {
      String source = IDataUtil.getString(cursor, "$file.source");
      String target = IDataUtil.getString(cursor, "$file.target");
      rename(source, target);
    } finally {
      cursor.destroy();
    }
    // --- <<IS-END>> ---

  }
示例#11
0
  public static final void copy(IData pipeline) throws ServiceException {
    // --- <<IS-START(copy)>> ---
    // @subtype unknown
    // @sigtype java 3.5
    // [i] field:0:required $key.source
    // [i] field:0:required $key.target
    IDataCursor cursor = pipeline.getCursor();

    try {
      String source = IDataUtil.getString(cursor, "$key.source");
      String target = IDataUtil.getString(cursor, "$key.target");
      tundra.document.copy(pipeline, source, target);
    } finally {
      cursor.destroy();
    }
    // --- <<IS-END>> ---

  }
示例#12
0
  public static final void duration(IData pipeline) throws ServiceException {
    // --- <<IS-START(duration)>> ---
    // @subtype unknown
    // @sigtype java 3.5
    // [i] field:0:optional $datetime.start
    // [i] field:0:optional $datetime.end
    // [o] field:0:optional $duration
    IDataCursor cursor = pipeline.getCursor();

    try {
      String start = IDataUtil.getString(cursor, "$datetime.start");
      String end = IDataUtil.getString(cursor, "$datetime.end");

      IDataUtil.put(cursor, "$duration", duration(start, end));
    } finally {
      cursor.destroy();
    }
    // --- <<IS-END>> ---

  }
示例#13
0
  public static final void concatenate(IData pipeline) throws ServiceException {
    // --- <<IS-START(concatenate)>> ---
    // @subtype unknown
    // @sigtype java 3.5
    // [i] field:0:optional $date
    // [i] field:0:optional $time
    // [o] field:0:optional $datetime
    IDataCursor cursor = pipeline.getCursor();

    try {
      String date = IDataUtil.getString(cursor, "$date");
      String time = IDataUtil.getString(cursor, "$time");

      if (date != null && time != null) IDataUtil.put(cursor, "$datetime", concatenate(date, time));
    } finally {
      cursor.destroy();
    }
    // --- <<IS-END>> ---

  }
示例#14
0
  public static final void read(IData pipeline) throws ServiceException {
    // --- <<IS-START(read)>> ---
    // @subtype unknown
    // @sigtype java 3.5
    // [i] field:0:required $file
    // [i] field:0:required $mode {&quot;bytes&quot;,&quot;string&quot;}
    // [i] field:0:optional $encoding
    // [o] object:0:required $content
    IDataCursor cursor = pipeline.getCursor();

    try {
      String file = IDataUtil.getString(cursor, "$file");
      String mode = IDataUtil.getString(cursor, "$mode");
      String encoding = IDataUtil.getString(cursor, "$encoding");

      IDataUtil.put(cursor, "$content", read(file, mode, encoding));
    } finally {
      cursor.destroy();
    }
    // --- <<IS-END>> ---

  }
示例#15
0
  public static final void match(IData pipeline) throws ServiceException {
    // --- <<IS-START(match)>> ---
    // @subtype unknown
    // @sigtype java 3.5
    // [i] field:0:required $file
    // [i] field:0:required $pattern
    // [i] field:0:optional $mode {&quot;regex&quot;,&quot;wildcard&quot;}
    // [o] field:0:required $match?
    IDataCursor cursor = pipeline.getCursor();

    try {
      String file = IDataUtil.getString(cursor, "$file");
      String pattern = IDataUtil.getString(cursor, "$pattern");
      String mode = IDataUtil.getString(cursor, "$mode");
      boolean regex = (mode == null || mode.equalsIgnoreCase("regex"));

      IDataUtil.put(cursor, "$match?", "" + tundra.support.file.match(file, pattern, regex));
    } finally {
      cursor.destroy();
    }
    // --- <<IS-END>> ---

  }
示例#16
0
  public static final void create(IData pipeline) throws ServiceException {
    // --- <<IS-START(create)>> ---
    // @subtype unknown
    // @sigtype java 3.5
    // [i] field:0:required $file
    IDataCursor cursor = pipeline.getCursor();

    try {
      create(IDataUtil.getString(cursor, "$file"));
    } finally {
      cursor.destroy();
    }
    // --- <<IS-END>> ---

  }
示例#17
0
  public static final void unreached(IData pipeline) throws ServiceException {
    // --- <<IS-START(unreached)>> ---
    // @subtype unknown
    // @sigtype java 3.5
    // [i] field:0:optional $message
    IDataCursor cursor = pipeline.getCursor();
    try {
      String message = IDataUtil.getString(cursor, "$message");
      unreached(message);
    } finally {
      cursor.destroy();
    }
    // --- <<IS-END>> ---

  }
示例#18
0
  public static final void drop(IData pipeline) throws ServiceException {
    // --- <<IS-START(drop)>> ---
    // @subtype unknown
    // @sigtype java 3.5
    // [i] field:0:optional $key
    IDataCursor cursor = pipeline.getCursor();

    try {
      String key = IDataUtil.getString(cursor, "$key");
      tundra.document.drop(pipeline, key);
    } finally {
      cursor.destroy();
    }
    // --- <<IS-END>> ---

  }
示例#19
0
  public static final void get(IData pipeline) throws ServiceException {
    // --- <<IS-START(get)>> ---
    // @subtype unknown
    // @sigtype java 3.5
    // [i] field:0:optional $key
    // [o] object:0:optional $value
    IDataCursor cursor = pipeline.getCursor();

    try {
      String key = IDataUtil.getString(cursor, "$key");
      IDataUtil.put(cursor, "$value", tundra.support.document.get(pipeline, key));
    } finally {
      cursor.destroy();
    }
    // --- <<IS-END>> ---

  }
示例#20
0
  public static final void length(IData pipeline) throws ServiceException {
    // --- <<IS-START(length)>> ---
    // @subtype unknown
    // @sigtype java 3.5
    // [i] field:0:required $file
    // [o] field:0:required $length
    IDataCursor cursor = pipeline.getCursor();

    try {
      String file = IDataUtil.getString(cursor, "$file");
      IDataUtil.put(cursor, "$length", "" + length(file));
    } finally {
      cursor.destroy();
    }
    // --- <<IS-END>> ---

  }
示例#21
0
  public static final void normalize(IData pipeline) throws ServiceException {
    // --- <<IS-START(normalize)>> ---
    // @subtype unknown
    // @sigtype java 3.5
    // [i] field:0:required $file
    // [o] field:0:required $file
    IDataCursor cursor = pipeline.getCursor();

    try {
      IDataUtil.put(
          cursor, "$file", tundra.support.file.normalize(IDataUtil.getString(cursor, "$file")));
    } finally {
      cursor.destroy();
    }
    // --- <<IS-END>> ---

  }
示例#22
0
  public static final void remove(IData pipeline) throws ServiceException {
    // --- <<IS-START(remove)>> ---
    // @subtype unknown
    // @sigtype java 3.5
    // [i] record:0:optional $bizdoc
    // [i] - field:0:required InternalID
    // [i] field:0:optional $part
    IDataCursor cursor = pipeline.getCursor();

    try {
      IData bizdoc = IDataUtil.getIData(cursor, "$bizdoc");
      String partName = IDataUtil.getString(cursor, "$part");

      remove(bizdoc, partName);
    } finally {
      cursor.destroy();
    }
    // --- <<IS-END>> ---

  }
示例#23
0
  public static final void getCurrentDateString(IData pipeline) throws ServiceException {
    // --- <<IS-START(getCurrentDateString)>> ---
    // @subtype unknown
    // @sigtype java 3.5
    // [i] field:0:required pattern
    // [i] field:0:optional timezone
    // [i] field:0:optional locale
    // [o] field:0:required value
    IDataCursor idcPipeline = pipeline.getCursor();
    try {
      String inPattern = "";
      if (idcPipeline.first("pattern")) {
        inPattern = (String) idcPipeline.getValue();
      } else {
        throw new ServiceException("Input parameter 'pattern' was not found.");
      }

      IData output = Service.doInvoke("pub.date", "getCurrentDateString", pipeline);
      IDataCursor outCur = output.getCursor();

      String stDate = IDataUtil.getString(outCur, "value");
      IDataUtil.remove(outCur, "value");

      outCur.destroy();

      if (inPattern.endsWith("Z")) {
        Matcher matcher = specialTimezonePattern.matcher(stDate);
        if (matcher.find()) {
          stDate = matcher.replaceAll(":" + matcher.group(1));
        }
      }

      idcPipeline.insertAfter("value", stDate);
    } catch (Exception e) {
      throw new ServiceException(e.getMessage());
    }

    idcPipeline.destroy();
    // --- <<IS-END>> ---

  }