mtconnect / cppagent_dev

Private C++ Agent for Pending Release Development
Apache License 2.0
1 stars 1 forks source link

QIF document addition removes XML nodes #270

Closed MatthewPowley closed 1 year ago

MatthewPowley commented 1 year ago

Need help pointing me to how I can fix this issue. When adding a XML QIF Results document, nodes with the same name in the document are not stored.

In QIF a file multiple child nodes exist with the same name. In the excerpt below, there are multiple 'CircleFeatureDefinition' nodes, each with different child nodes and attributes.

<Features>
  <FeatureDefinitions n="2">
    <CircleFeatureDefinition id="4">
      <Attributes n="4">
        <AttributeQPId name="AP242:PersistentFeature:UUID" value="be620693-2cd7-49b8-998d-e098a46a163a" />
        <AttributeI1 name="Renishaw:DataCollector:FeatureId" value="1" />
        <AttributeI1 name="Renishaw:DataCollector:FeatureType" value="103" />
        <AttributeStr name="Renishaw:DataCollector:FeatureTypeDescription" value="InspectionPlus Bore (3Pt)" />
      </Attributes>
      <InternalExternal>INTERNAL</InternalExternal>
      <Diameter>5.000000</Diameter>
    </CircleFeatureDefinition>
    <CircleFeatureDefinition id="20">
      <Attributes n="4">
        <AttributeQPId name="AP242:PersistentFeature:UUID" value="6f6e0701-e6ad-4c46-afcb-f77084e1d42d" />
        <AttributeI1 name="Renishaw:DataCollector:FeatureId" value="2" />
        <AttributeI1 name="Renishaw:DataCollector:FeatureType" value="103" />
        <AttributeStr name="Renishaw:DataCollector:FeatureTypeDescription" value="InspectionPlus Bore (3Pt)" />
      </Attributes>
      <InternalExternal>INTERNAL</InternalExternal>
      <Diameter>5.000000</Diameter>
     </CircleFeatureDefinition>
  </FeatureDefinitions>
</Features>

When the data is sent to the agent through a multi-line SHDR all data is present. When processing however each of the nodes is turned into a property of the QifDocumentWrapper entity. This property collection is a map and so it can only have 1 child property value with the same name.

So any XML that has the form:

<Parent>
  <Child name="Child1"/>
  <Child name="Child2"/>
  <Child name="Child3"/>
</Parent>

Will end up with only one 'Child' property and will have an attribute 'name' with the value 'Child1'.

How best to modify the data parsing pipeline to retain the structure?

wsobel commented 1 year ago

This should work, it may be something in the parser when it translates it to the internal structure. This was added to provide a json representation instead of a raw xml document. Looks nicer if you request json. I’ll get back soon. At the ROS meeting in Detroit this week, so will be a little slow getting to it. BestW(Sent from mobile)On May 24, 2023, at 05:34, Matt Powley @.***> wrote: Need help pointing me to how I can fix this issue. When adding a XML QIF Results document, nodes with the same name in the document are not stored. In QIF a file multiple child nodes exist with the same name. In the excerpt below, there are multiple 'CircleFeatureDefinition' nodes, each with different child nodes and attributes.

INTERNAL 5.000000 INTERNAL 5.000000

When the data is sent to the agent through a multi-line SHDR all data is present. When processing however each of the nodes is turned into a property of the QifDocumentWrapper entity. This property collection is a map and so it can only have 1 child property value with the same name. So any XML that has the form:

Will end up with only one 'Child' property and will have an attribute 'name' with the value 'Child1'. How best to modify the data parsing pipeline to retain the structure?

—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you are subscribed to this thread.Message ID: @.***>

wsobel commented 1 year ago

Hi Matt,

Do you have the complete QIF document? I'm trying to build a unit test around this and need to have a sample.

I think the parser treats the content like a property set instead of a list. I use a generic entity mapper to create the QIF document; I don't have a complete internal model for QIF–maybe sometime in the future–to do validation. Therefore it is probably makeign some poor assumptions.

There are some other areas this pattern is used, like extended schema, so I need to verify I can differentiate behavior.

A complete example would be very helpful.

Thanks, W

MatthewPowley commented 1 year ago

@wsobel - I will catch up with you in person next week. I understand why it has been implemented this way, to separate the model of the data from its representation (XML, JSON, YAML...). Building a model for QIF might be quite complex but can be done and maybe should be done outside of MTConnect, which the agent can then utilise. We will discuss a plan of what to do next and then I will add a few demonstration documents and build some tests.