legacy/src/main/java/thredds/catalog/InvDatasetImpl.java
protected void canonicalize() {
    List<InvMetadata> whatsLeft = new ArrayList<>();
    List<InvMetadata> original = new ArrayList<>(tm.metadata); // get copy of metadata
    tm.metadata = new ArrayList<>();

    // transfer all non-inherited thredds metadata to tm
    // transfer all inherited thredds metadata to tmi
    for (InvMetadata m : original) {
      if (m.isThreddsMetadata() && !m.isInherited() && !m.hasXlink()) {
        ThreddsMetadata nested = m.getThreddsMetadata();
        tm.add(nested, false);

      } else if (m.isThreddsMetadata() && m.isInherited() && !m.hasXlink()) {
        ThreddsMetadata nested = m.getThreddsMetadata();
        tmi.add(nested, true);

      } else {
        whatsLeft.add(m);
      }
    }

    // non ThreddsMetadata goes into tm
    tm.metadata.addAll(whatsLeft);
  }
protected void canonicalize() {
    List<InvMetadata> whatsLeft = new ArrayList<>();
    List<InvMetadata> original = new ArrayList<>(tm.metadata); // get copy of metadata
    tm.metadata = new ArrayList<>();

    // transfer all non-inherited thredds metadata to tm
    // transfer all inherited thredds metadata to tmi
    for (InvMetadata m : original) {
      if (m.isThreddsMetadata() && !m.isInherited() && !m.hasXlink()) {
        ThreddsMetadata nested = m.getThreddsMetadata();
        tm.add(nested, false);

      } else if (m.isThreddsMetadata() && m.isInherited() && !m.hasXlink()) {
        ThreddsMetadata nested = m.getThreddsMetadata();
        tmi.add(nested, true);

      } else {
        whatsLeft.add(m);
      }
    }

    // non ThreddsMetadata goes into tm
    tm.metadata.addAll(whatsLeft);
  }
Put metadata into canonical form.
All non-inherited thredds metadata put into single metadata element, pointed to by getLocalMetadata().
All inherited thredds metadata put into single metadata element, pointed to by getLocalMetadataInherited().
This is needed to do reliable editing.