Class TransformingWriter
java.lang.Object
com.northconcepts.datapipeline.core.DataObject
com.northconcepts.datapipeline.core.Endpoint
com.northconcepts.datapipeline.core.DataEndpoint
com.northconcepts.datapipeline.core.DataWriter
com.northconcepts.datapipeline.core.ProxyWriter
com.northconcepts.datapipeline.transform.TransformingWriter
A proxy that applies transformations to records passing through.
-
Nested Class Summary
Nested classes/interfaces inherited from class com.northconcepts.datapipeline.core.DataEndpoint
DataEndpoint.State -
Field Summary
Fields inherited from class com.northconcepts.datapipeline.core.DataEndpoint
lastRecord, PRODUCT, PRODUCT_VERSION, VENDOR, XML_INPUT_FACTORY_KEYFields inherited from class com.northconcepts.datapipeline.core.Endpoint
BUFFER_SIZE, captureElapsedTime, DEFAULT_READ_BUFFER_SIZEFields inherited from class com.northconcepts.datapipeline.core.DataObject
id, log, name, TIMESTAMP_FORMAT -
Constructor Summary
ConstructorsConstructorDescriptionTransformingWriter(DataWriter writer) Accepts the target DataWriter of the transform.TransformingWriter(DataWriter writer, DataWriter discardWriter) Accepts the target DataWriter of the transform and the DataWriter to send discarded records to (due to exception).TransformingWriter(DataWriter writer, DataWriter discardWriter, String discardReasonFieldName) Accepts the target DataWriter of the transform and the DataWriter to send discarded records to (due to exception). -
Method Summary
Modifier and TypeMethodDescriptionadd(Transformer... transformer) Appends transformers; each record passes through them in the order added.addExceptionProperties(DataException exception) Adds this endpoint's current state to aDataException.voidclose()Indicates that this endpoint has finished reading or writing.get(int index) Returns the transformer at the given 0-based index.Returns the condition under which this transformation applies ornullif it always applies.intgetCount()Returns the number of transformers added.Returns the the field in the record to place the description of the transformation that failed along with the exception message.Returns the discard sink for bad records ornullif one was not assigned.protected RecordinterceptRecord(Record record) Overridden by subclasses to transform, drop, or observe a record on its way through this proxy.booleanIndicates if a transformer that throws or returns false stops processing with an exception (default is true unless a discard writer is set).booleanIndicates if the warning added when a transformer returns false includes a stack trace (default is true).protected voidonFailure(Record record, Transformer transformer, DataException exception, String message, Messages messages) Handles a failed transformation (exceptionisnullif it returned false): sends the record to the discard writer if there is one, otherwise throws or, when exceptionOnFailure is off, adds warnings tomessages.voidopen()Makes this endpoint ready for reading or writing.setCondition(Filter condition) Sets the condition under which this transformation applies ornullif it should always be applied.setExceptionOnFailure(boolean exceptionOnFailure) Sets the flag to stop processing if an exception is thrown (default) or false if they should be ignored.setRecordStackTraceInMessage(boolean recordStackTraceInMessage) Indicates if the warning added when a transformer returns false includes a stack trace (default is true).protected booleantransformRecord(Record record, Transformer transformer, Messages messages) Applies the transformer to the record, passing any failure (an exception or a false result) toonFailure; returns true if the record should continue.Methods inherited from class com.northconcepts.datapipeline.core.ProxyWriter
available, getNestedWriter, map, map, setNestedDataWriter, setNestedDataWriter, writeImplMethods inherited from class com.northconcepts.datapipeline.core.DataWriter
getNestedEndpoint, getRootEndpoint, getRootWriter, getWriter, writeMethods inherited from class com.northconcepts.datapipeline.core.DataEndpoint
decrementRecordCount, enableJmx, getLastRecord, getRecordCount, getRecordCountAsBigInteger, getRecordCountAsString, incrementRecordCount, isRecordCountBigInteger, resetRecordCount, toStringMethods inherited from class com.northconcepts.datapipeline.core.Endpoint
addElapsedtime, assertClosed, assertNotOpened, assertOpened, finalize, getClosedOn, getDescription, getElapsedTime, getElapsedTimeAsString, getOpenedOn, getOpenElapsedTime, getOpenElapsedTimeAsString, getSelfTime, getSelfTimeAsString, getState, isCaptureElapsedTime, isClosed, isOpen, setCaptureElapsedTime, setDescription
-
Constructor Details
-
TransformingWriter
public TransformingWriter(DataWriter writer, DataWriter discardWriter, String discardReasonFieldName) Accepts the target DataWriter of the transform and the DataWriter to send discarded records to (due to exception).- Parameters:
writer- the target writer of the transform.discardWriter- the discard sink for bad records.discardReasonFieldName- the field in the record to place the description of the transformation that failed along with the exception message.
-
TransformingWriter
Accepts the target DataWriter of the transform and the DataWriter to send discarded records to (due to exception).- Parameters:
writer- the target writer of the transform.discardWriter- the discard sink for bad records.
-
TransformingWriter
Accepts the target DataWriter of the transform.- Parameters:
writer- the target writer of the transform.
-
-
Method Details
-
getCondition
Returns the condition under which this transformation applies ornullif it always applies. -
setCondition
Sets the condition under which this transformation applies ornullif it should always be applied. -
isExceptionOnFailure
public boolean isExceptionOnFailure()Indicates if a transformer that throws or returns false stops processing with an exception (default is true unless a discard writer is set). -
setExceptionOnFailure
Sets the flag to stop processing if an exception is thrown (default) or false if they should be ignored. -
isRecordStackTraceInMessage
public boolean isRecordStackTraceInMessage()Indicates if the warning added when a transformer returns false includes a stack trace (default is true). -
setRecordStackTraceInMessage
Indicates if the warning added when a transformer returns false includes a stack trace (default is true). -
add
Appends transformers; each record passes through them in the order added. -
getCount
public int getCount()Returns the number of transformers added. -
get
Returns the transformer at the given 0-based index. -
getDiscardWriter
Returns the discard sink for bad records ornullif one was not assigned. -
getDiscardReasonFieldName
Returns the the field in the record to place the description of the transformation that failed along with the exception message. -
open
Description copied from class:DataEndpointMakes this endpoint ready for reading or writing.- Overrides:
openin classProxyWriter- Throws:
DataException
-
close
Description copied from class:DataEndpointIndicates that this endpoint has finished reading or writing.- Overrides:
closein classProxyWriter- Throws:
DataException
-
interceptRecord
Description copied from class:ProxyWriterOverridden by subclasses to transform, drop, or observe a record on its way through this proxy.Contract for subclasses (see also
docs/authoring/ProxyWriter.md):- Return the record (possibly modified) to forward it to the nested
DataWriter. - Return
nullto drop the record; the framework will not write it downstream. - Throw to fail the pipeline; the framework wraps the throwable in a
DataExceptionwith.setRecord(record). - The nested
DataWriteris opened and closed for you; do not write to it here. - Do not call
DataEndpoint.incrementRecordCount()here.
- Overrides:
interceptRecordin classProxyWriter- Throws:
Throwable
- Return the record (possibly modified) to forward it to the nested
-
transformRecord
Applies the transformer to the record, passing any failure (an exception or a false result) toonFailure; returns true if the record should continue. -
onFailure
protected void onFailure(Record record, Transformer transformer, DataException exception, String message, Messages messages) Handles a failed transformation (exceptionisnullif it returned false): sends the record to the discard writer if there is one, otherwise throws or, when exceptionOnFailure is off, adds warnings tomessages. -
addExceptionProperties
Description copied from class:EndpointAdds this endpoint's current state to aDataException. Since this method is called whenever an exception is thrown, subclasses should override it to add their specific information.- Overrides:
addExceptionPropertiesin classProxyWriter
-