0

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?
2
  • Is the handler known before the data is loaded? Given file1 and file2, will your code use load(file1);load(file2) or load1(file1);load2(file2);?
    – Brian
    Commented Oct 21, 2015 at 14:54
  • I receive the files loaded and have allready determined the required handler to parse them
    – JMan
    Commented Oct 22, 2015 at 5:09

1 Answer 1

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.
  • 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.
  • CommonDataCollection

    • Between the equality-comparer implementations and RecordType property we can find, match, etc. records for each file type.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.