ADAPT / ISOv4Plugin

Eclipse Public License 1.0
18 stars 33 forks source link

Cannot find native way to add a custom attribute to the output xml nodes. #169

Open kaiverge opened 2 years ago

kaiverge commented 2 years ago

ADAPT https://github.com/ADAPT/ISOv4Plugin

I need to add a custom attribute to the output xml nodes.

I cannot find any extensions/functions to add custom attribute to: ISOCustomer ISOFarm ISOPartField ISOGUidanceGroup

The way that works for me is to extend one of the base classes

public class ISOGuidanceGroupVG : ISOGuidanceGroup
    {
        public string GuidanceGroupType { get; set; }

        public override XmlWriter WriteXML(XmlWriter xmlBuilder)
        {
            xmlBuilder.WriteStartElement("GGP");
            xmlBuilder.WriteXmlAttribute("A", GuidanceGroupId);
            xmlBuilder.WriteXmlAttribute("B", GuidanceGroupDesignator);
            xmlBuilder.WriteXmlAttribute("CUSTOM_ATTRIBUTE", "value"); //adding custom attribute

![Uploading ZKiY0.png…]()
            if (XmlComments != null)
            {
                XmlComments.ForEach(delegate (string s)
                {
                    xmlBuilder.WriteComment(s);
                });
            }

            foreach (ISOGuidancePattern guidancePattern in GuidancePatterns)
            {
                guidancePattern.WriteXML(xmlBuilder);
            }

            foreach (ISOPolygon boundaryPolygon in BoundaryPolygons)
            {
                boundaryPolygon.WriteXML(xmlBuilder);
            }

            xmlBuilder.WriteEndElement();
            return xmlBuilder;
        }
    }

Now the question is, how do I do it in some native way...?

knelson-farmbeltnorth commented 2 years ago

@kaiverge There is not a capability of exporting proprietary schema attributes from within the plugin at this time. In fact, we've only recently supported the import (https://github.com/ADAPT/ISOv4Plugin/commit/ffc2f61e8135b8c3fe31bdaeffb186dd12a28f2c)

If you would like to add this functionality, all are welcome to submit pull requests. While the import logic puts the attributes in the ContextItems collection, current export behavior for ContextItems is to write that to the LinkList. As such, assuming we accomplished the export by means of ContextItems, we would need some logic to determine what to write as proprietary schema attributes and what to write as LinkList items (perhaps a key in the format of P000_?)

tomgruszowski commented 2 years ago

Thanks for response @knelson-farmbeltnorth, to confirm, can this be done without custom extending things and simply using ContextItems (we are not looking to make this proprietary if we can avoid it). If so, will ContextItems automatically read & write those values into XML (are there restrictions there? maybe 255 chars in case it's serialized as an attribute vs XML Element). Ie, we'd like our integration partner to pass in some additional metadata alongside some elements (Farm for example). And we would like to read this metadata somehow (from a ContextItem?). Is this possible or do we and our partner have to extend XML writers/readers and agree on some proprietary tags/attributes?

If the above won't work, what is your suggestion for implementing our scenario.

If context items are an option, is there any reference documentation on this? ie ISOFarm does not have a ContextItem property but ADAPT Farm does.

knelson-farmbeltnorth commented 2 years ago

@tomgruszowski Apologies for the late reply. This repo relates specifically to the ISOXML plugin, but your question appears to relate to ADAPT in general. There are two mechanisms in ADAPT to achieve what you are referring to. 1. ContextItems allow anyone to extend an ADAPT entity with additional contextual information (e.g., a region-specific classification). 2. The CompoundId.UniqueIds property allows for cross-referencing an object in ADAPT with any number of other identifiers for the same object in other systems.

I misunderstood @kaiverge's initial question in the context of manufacturer proprietary attributes in ISOXML, which apply only to equipment manufacturers using that format. In the case of the ISOXML plugin, it will import/export unique ids and context items to and from the LinkList.xml file in ISOXML v.4.

SergeyVBond commented 2 years ago

Hi @knelson-farmbeltnorth, thank you for the reply. We were able to test exporting and importing ISO XML file with some custom properties saved as the ContextItem (in linklist.xml) - thank you for that information. The only thing is only a few properties in the ApplicationDataModel object have the ability to attach ContextItem to them. We can save them against the boundary, grower, farm, crop and field. But we don't see an ability to add any ContextItems to the overall "project" ApplicationDataModel, any guidance groups or any of the guidance lines. Is that by design? If we want to include information such as swath width for some or all the guidance lines or the name of the path plan for the entire "project" - which property would be the best to attach these ContextItems to? Thanks.

knelson-farmbeltnorth commented 1 year ago

@SergeyVBond Guidance Pattern has a SwathWidth property for which the ISO plugin had omitted support by accident. I noticed this a couple months back, and the recent releases should fix this issue. If there are other entities in the ADAPT framework missing Context Items for which you have a use case, please submit a PR against that repo with the addition.

Re setting a ContextItem on the ApplicationDataModel, is your intent to pass something out on the ISO LinkList? If so, what ISOXML element would it reference?

For the path of the source data, I've used Catalog.Description in a couple of plugins. You could also set that as a ProprietaryValue if your desire is to communicate that to consumers of your ADAPT Model. If your intent is to pass that out via the ISO Plugin on the LinkList, it would need to correlate to an ISOXML element.