Class AbstractFieldMapping
java.lang.Object
com.northconcepts.datapipeline.foundations.core.Bean
com.northconcepts.datapipeline.foundations.core.FoundationObject
com.northconcepts.datapipeline.foundations.datamapping.DataMappingObject
com.northconcepts.datapipeline.foundations.datamapping.DataMappingPart
com.northconcepts.datapipeline.foundations.datamapping.AbstractFieldMapping
- All Implemented Interfaces:
DataExceptionContributor,JsonSerializable,RecordSerializable,XmlSerializable,DataMappingProblemsSupplier,IFieldMapping,Serializable
- Direct Known Subclasses:
FieldMapping
public abstract class AbstractFieldMapping
extends DataMappingPart
implements IFieldMapping, DataMappingProblemsSupplier
Base class for field mappings that set one target field, with an optional condition, default value expression and
type conversion.
- See Also:
-
Field Summary
Fields inherited from class com.northconcepts.datapipeline.foundations.core.FoundationObject
internalId, internalName, log, TIMESTAMP_FORMATFields inherited from interface com.northconcepts.datapipeline.core.RecordSerializable
SERIALIZED_CLASS_NAME, TYPEFields inherited from interface com.northconcepts.datapipeline.core.XmlSerializable
XML_SERIALIZED_CLASS_NAME -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionaddExceptionProperties(DataException exception) Adds this object's current state to aDataException.fromRecord(Record source) Loads this instance's state from a record and returnsthis(for fluid API call chaining).fromXmlElement(Element fieldMappingElement) LogicalExpressionReturns the condition for computing the field's value; when it is false the field gets the default value or null.Returns the name identifying this part: the data mapping's name or a field mapping's target field name.voidgetDataMappingProblems(List<DataMappingProblem> problems, boolean includeChildren) Adds this element's problems to the list, plus those of its children whenincludeChildrenis true; the default adds none.ExpressionReturns the expression that supplies the field's value when the mapped value is null or the condition is false.getType()Returns the type the field's value is converted to, or null to keep the mapped value as is.mapField(ExpressionContext expressionContext, DataMappingResult result) Sets this mapping's field in the target record held byresult; called byDataMappingfor each record.protected abstract ObjectmapFieldImpl(ExpressionContext expressionContext, DataMappingResult result) Computes the target field's value in the mapping context; called only when there is no condition or it is true.setCondition(LogicalExpression condition) Sets the condition for computing the field's value; when it is false the field gets the default value or null.setDefaultValueExpression(Expression defaultValueExpression) Sets the expression that supplies the field's value when the mapped value is null or the condition is false.setTargetFieldName(String targetFieldName) Sets the type the field's value is converted to, or null to keep the mapped value as is.toRecord()Converts this object's state to a record thatRecordSerializable.fromRecord(Record)can load.toXmlElement(Document document) Returns an element, created withdocument, describing this object; the default implementation throws aDataException.protected voidThrows an exception if the target field name is not set; called before each field is mapped.Methods inherited from class com.northconcepts.datapipeline.foundations.datamapping.DataMappingPart
getDataMapping, getDataMappingName, getDataMappingPartContainer, getDataMappingPartContainerName, getDataMappingPartContainerType, getDataMappingPartTypeMethods inherited from class com.northconcepts.datapipeline.foundations.core.FoundationObject
assertValid, assertValid, clone, exception, exception, exception, getInternalId, getInternalName, resetInternalIdMethods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface com.northconcepts.datapipeline.core.DataExceptionContributor
addExceptionPropertiesMethods inherited from interface com.northconcepts.datapipeline.foundations.datamapping.DataMappingProblemsSupplier
getDataMappingProblems, getDataMappingProblems
-
Constructor Details
-
AbstractFieldMapping
public AbstractFieldMapping()
-
-
Method Details
-
getDataMappingProblems
Description copied from interface:DataMappingProblemsSupplierAdds this element's problems to the list, plus those of its children whenincludeChildrenis true; the default adds none.- Specified by:
getDataMappingProblemsin interfaceDataMappingProblemsSupplier
-
getDataMappingPartName
Description copied from class:DataMappingPartReturns the name identifying this part: the data mapping's name or a field mapping's target field name.- Specified by:
getDataMappingPartNamein classDataMappingPart
-
getTargetFieldName
-
setTargetFieldName
-
getCondition
public LogicalExpression getCondition()Returns the condition for computing the field's value; when it is false the field gets the default value or null. -
setCondition
Sets the condition for computing the field's value; when it is false the field gets the default value or null. -
getConditionAsString
-
getDefaultValueExpression
public Expression getDefaultValueExpression()Returns the expression that supplies the field's value when the mapped value is null or the condition is false. -
getDefaultValueExpressionAsString
-
setDefaultValueExpression
Sets the expression that supplies the field's value when the mapped value is null or the condition is false. -
getType
Returns the type the field's value is converted to, or null to keep the mapped value as is. -
setType
Sets the type the field's value is converted to, or null to keep the mapped value as is. -
mapField
Description copied from interface:IFieldMappingSets this mapping's field in the target record held byresult; called byDataMappingfor each record.- Specified by:
mapFieldin interfaceIFieldMapping
-
mapFieldImpl
protected abstract Object mapFieldImpl(ExpressionContext expressionContext, DataMappingResult result) Computes the target field's value in the mapping context; called only when there is no condition or it is true. A null result falls back to the default value expression. -
validateName
protected void validateName()Throws an exception if the target field name is not set; called before each field is mapped. -
toRecord
Description copied from interface:RecordSerializableConverts this object's state to a record thatRecordSerializable.fromRecord(Record)can load.- Specified by:
toRecordin interfaceRecordSerializable- Overrides:
toRecordin classBean
-
fromRecord
Description copied from interface:RecordSerializableLoads this instance's state from a record and returnsthis(for fluid API call chaining). For fluid API call chaining, the overridden method should change the declared return type to its class.- Specified by:
fromRecordin interfaceRecordSerializable- Overrides:
fromRecordin classBean- Parameters:
source-- Returns:
- this instance.
-
addExceptionProperties
Description copied from class:FoundationObjectAdds this object's current state to aDataException. Since this method is called whenever an exception is thrown, subclasses should override it to add their specific information.- Specified by:
addExceptionPropertiesin interfaceDataExceptionContributor- Overrides:
addExceptionPropertiesin classFoundationObject
-
toXmlElement
Description copied from interface:XmlSerializableReturns an element, created withdocument, describing this object; the default implementation throws aDataException.- Specified by:
toXmlElementin interfaceXmlSerializable
-
fromXmlElement
- Specified by:
fromXmlElementin interfaceXmlSerializable
-