I receive zip files and they have as content 8 different files, each with it's own metadata inside.
I have to combine these files into 1 object containing certain metadata. The big issue here is that there will not always be 8 files and the metadata i want to retrieve could be in any of these files stored in there own way.
for now i have created a factory method that initiates the correct parser for each file type and the parser returns the object with the metadata it was able to parse.
Now when this is done i have 8 object's i have to merge into 1 result object with the metadata gathered from these results.
so i could have something like this
object Meta1 Meta2 Meta3 Meta4 Meta5
1 A - 15 RT -
2 - - 15 - HIGH
3 A - 15 RT HIGH
4 - 65 - RT HIGH
This needs to have only 1 object as output:
Meta1 Meta2 Meta3 Meta4 Meta5
A 65 15 RT HIGH
Now i'm wondering what would be the best strategy to solve this issue
- Have my parsers accept my Object as parameter, try to map the data and override if present and then return the Object to be passed again in the next Parser
- Parse all the Object and try to merge them somehow in the end
- Another strategy?
1 Answer 1
Here I describe some similar work I did. Perhaps it will work for you. I had 7 different file formats across 2 different files.
What I must assume is that your meta-data is effectively keys. Otherwise how can one possibly know which records to merge?
Create a
CommonData
class- A single class to hold any record from any file.
- A property for each possible meta-field from any incoming file
- A property to hold the entire record
- As you clearly illustrate - Where meta-fields are the same, there is only one. I.E. only 1 "Meta1", "Meta2"
- Populate only the appropriate meta fields for a given file/record format.
- An
enum
identifing the record type - what file it comes from essentially; or for me, the file format. - Has an
IEqualityComparer
CommonDataEqualityComparer
- Implements
IEqualityComparer
- In my solution your "meta data" were my keys that defined equality for each given record type (file).
- The equality-comparer object is passed into the
CommonData
constructor.
- Implements
An
enum
to identify each source file or unique file format.The Factory
- takes the raw record and it's type -
enum
value - Factory passes to appropriate parser based on the
enum
value - Factory returns new CommonData object, with it's record-type-specific
CommonDataEqualityComparer
implementation.
- takes the raw record and it's type -
CommonDataCollection
- Between the equality-comparer implementations and
RecordType
property we can find, match, etc. records for each file type.
- Between the equality-comparer implementations and
Explore related questions
See similar questions with these tags.
load(file1);load(file2)
orload1(file1);load2(file2);
?