Skip to content

Commit

Permalink
Merge pull request #51 from seandenigris/enh_ma-2si-fixer-hooks
Browse files Browse the repository at this point in the history
[Enh]: MA Two Stage Importer - Hooks to Fix Stream & Record...
  • Loading branch information
seandenigris authored Aug 14, 2024
2 parents bd8a52e + 4a03d37 commit 9c24c6c
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions repository/Neo-CSV-Magritte/MACSVTwoStageImporter.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ MACSVTwoStageImporter >> convertToDomainObjects: aCollectionOfDictionaries [
(self selectBlock value: rowDict)
ifTrue: [
result := self domainObjectFromDictionary: rowDict.
self prepareRecord: result.
col add: result ].
col ]
]
Expand All @@ -70,8 +71,9 @@ MACSVTwoStageImporter >> domainObjectFromDictionary: aDictionary [

{ #category : #accessing }
MACSVTwoStageImporter >> importStream: aStream [
| rows |
self configureReaderFor: aStream.
| rows preparedStream |
preparedStream := self prepareStream: aStream.
self configureReaderFor: preparedStream.
rows := self reader upToEnd.
^ self convertToDomainObjects: rows
]
Expand Down Expand Up @@ -136,14 +138,28 @@ MACSVTwoStageImporter >> initializeDomainObject: anObject fromRecord: aDictionar
^ anObject
]

{ #category : #accessing }
MACSVTwoStageImporter >> prepareRecord: aDomainObject [
"Override this to fix input problems which are easier to fix utilizing real accessors and domain objects instead of in the preprocessor where you have dictionary keys and strings"
]

{ #category : #accessing }
MACSVTwoStageImporter >> prepareStream: aStream [
"Override me e.g. if the input is not proper CSV. One might remove a standard number of header or footer lines, handle blank columns, etc"

^ aStream
]

{ #category : #accessing }
MACSVTwoStageImporter >> preprocessor [
^ preprocessor ifNil: [ #yourself ]
]

{ #category : #accessing }
MACSVTwoStageImporter >> preprocessor: anObject [
preprocessor := anObject
MACSVTwoStageImporter >> preprocessor: aValuable [
"Consider #prepareObject: first because it is generally easier to fix the record after initialization because we have real accessors and domain objects e.g. aDate instead of aDateString"

preprocessor := aValuable
]

{ #category : #accessing }
Expand Down

0 comments on commit 9c24c6c

Please sign in to comment.