Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Enh]: MA Two Stage Importer - Hooks to Fix Stream & Record... #51

Merged
merged 1 commit into from
Aug 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading