public static final void current(IData pipeline) throws ServiceException { // --- <<IS-START(current)>> --- // @subtype unknown // @sigtype java 3.5 // [o] field:0:required $thread IDataCursor cursor = pipeline.getCursor(); try { Thread thread = Thread.currentThread(); String description = thread.getClass().getName() + " ID#" + thread.getId() + " " + thread.getName(); IDataUtil.put(cursor, "$thread", description); } finally { cursor.destroy(); } // --- <<IS-END>> --- }
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>> --- }
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>> --- }
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 // {"stream","bytes","string","base64"} // [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>> --- }
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 // {"datetime","date","time","milliseconds"} // [i] field:0:optional $pattern.output // {"datetime","date","time","milliseconds"} // [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>> --- }
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>> --- }
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 // {"date.jdbc","date.xml","datetime.jdbc","datetime.xml","datetime.xcbl","datetime.sapiens","datetime.epoch.milliseconds","time.jdbc","time.xml"} // [i] field:0:optional $raise? {"false","true"} // [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>> --- }
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 {"append","write"} // [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>> --- }
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 {"read","append","write"} // [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>> --- }
public static final void first(IData pipeline) throws ServiceException { // --- <<IS-START(first)>> --- // @subtype unknown // @sigtype java 3.5 // [o] field:0:optional $key // [o] object:0:optional $value IDataCursor cursor = pipeline.getCursor(); try { if (cursor.first()) { String key = cursor.getKey(); Object value = cursor.getValue(); IDataUtil.put(cursor, "$key", key); IDataUtil.put(cursor, "$value", value); } } finally { cursor.destroy(); } // --- <<IS-END>> --- }
public static final void length(IData pipeline) throws ServiceException { // --- <<IS-START(length)>> --- // @subtype unknown // @sigtype java 3.5 // [o] field:0:required $length IDataCursor cursor = pipeline.getCursor(); try { IDataUtil.put(cursor, "$length", "" + tundra.document.size(pipeline)); } finally { cursor.destroy(); } // --- <<IS-END>> --- }
public static final void capture(IData pipeline) throws ServiceException { // --- <<IS-START(capture)>> --- // @subtype unknown // @sigtype java 3.5 // [o] record:0:required $pipeline IDataCursor cursor = pipeline.getCursor(); try { IDataUtil.put(cursor, "$pipeline", IDataUtil.clone(pipeline)); } finally { cursor.destroy(); } // --- <<IS-END>> --- }
public static final void now(IData pipeline) throws ServiceException { // --- <<IS-START(now)>> --- // @subtype unknown // @sigtype java 3.5 // [o] field:0:required $datetime IDataCursor cursor = pipeline.getCursor(); try { IDataUtil.put(cursor, "$datetime", now()); } finally { cursor.destroy(); } // --- <<IS-END>> --- }
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>> --- }
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>> --- }
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>> --- }
public static final void epochToDateString(IData pipeline) throws ServiceException { // --- <<IS-START(epochToDateString)>> --- // @sigtype java 3.5 // [i] object:0:required epochTime // [o] field:0:required dateString IDataCursor pipelineCursor = pipeline.getCursor(); Long myTimeAsLong = (Long) IDataUtil.get(pipelineCursor, "epochTime"); Date date = new Date(myTimeAsLong); DateFormat format = new SimpleDateFormat("dd/MM/yyyy"); String dateString = format.format(date); IDataUtil.put(pipelineCursor, "dateString", dateString); pipelineCursor.destroy(); // --- <<IS-END>> --- }
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>> --- }
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>> --- }
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>> --- }
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 {"bytes","string"} // [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>> --- }
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 {"regex","wildcard"} // [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>> --- }
// opens a file for reading, appending, or writing, and processes it by calling the given service // with the resulting $stream public static IData process( java.io.File file, String mode, String service, String input, IData pipeline) throws ServiceException { if (file != null) { if (input == null) input = "$stream"; Object stream = null; try { if (mode == null || mode.equals("read")) { stream = new java.io.BufferedInputStream( new java.io.FileInputStream(file), tundra.support.constant.DEFAULT_BUFFER_SIZE); } else { if (!exists(file)) create(file); stream = new java.io.BufferedOutputStream( new java.io.FileOutputStream(file, mode.equals("append")), tundra.support.constant.DEFAULT_BUFFER_SIZE); } IDataCursor cursor = pipeline.getCursor(); IDataUtil.put(cursor, input, stream); cursor.destroy(); pipeline = tundra.service.invoke(service, pipeline); } catch (java.io.IOException ex) { tundra.exception.raise(ex); } finally { tundra.stream.close(stream); IDataCursor cursor = pipeline.getCursor(); IDataUtil.remove(cursor, input); cursor.destroy(); } } return pipeline; }