matgnt / epcis-js

This is a Node.js libary to parse EPCIS documents. We try to translate it into a more useful javascript structure.
MIT License
6 stars 4 forks source link

`bizTransactionList` can have multiple values #2

Open simov opened 8 years ago

simov commented 8 years ago

In 6_ship_order_events.xml:

<bizTransactionList>
  <bizTransaction type="urn:epcglobal:cbv:btt:po">urn:epcglobal:cbv:bt:5012345678900:1234</bizTransaction>
  <bizTransaction type="urn:epcglobal:cbv:btt:inv">urn:epcglobal:cbv:bt:0614141111114:9876</bizTransaction>
</bizTransactionList>

Is parsed as:

bizTransaction: {
  id: 'urn:epcglobal:cbv:bt:5012345678900:1234',
  type: 'urn:epcglobal:fmcg:btt:po'
}

So the second value is lost:

<bizTransaction type="urn:epcglobal:cbv:btt:inv">urn:epcglobal:cbv:bt:0614141111114:9876</bizTransaction>

Isn't that supposed to be parsed as Array, just like the epcList?

matgnt commented 8 years ago
if(bizTransactions.length === 1) {
    event.bizTransaction = bizTransactions[0];
} else if (bizTransactions.length > 1) {
    event.bizTransactionList = bizTransactions;
}

This is the code parsing the bizTransactionList. Yes, it seems to be a bug. But from the code you can see the intention was to use no arrays in the 95% when you only have 1 Transaction. This would make it easier to search (e.g. MongoDB).

epcList is another example where you could transform XML to JSOn 1:1 or you split up the original Events into individual events (which makes it easier to search with EPC again). The only use case which makes sense for the ecpList is the AggregationEvent!

In general you can say this library is not production ready! I'd like to start a discussion on how to use it. Options that come into my mind are:

Iˋm still travelling without my laptop. When I'm back (mid of January), I might have some time to continue with this. But in the meantime, what do you think? I'd love to get more people involved in this project!

Merry Christmas Matthias