Open josegar74 opened 2 months ago
@fxprunayre this change breaks some unit tests, like BatchEditsServiceTest.testUpdateRecordAddAttribute:323 expected:<value> but was:<null>
The test is doing this replacement:
I would expect that in the following code the isCreate
variable would be true
, but that is not the case, so with this change, no longer enters in the condition as createXpathNodeIfNotExist
is false
and the test fails:
isCreate
is false
as doesn't check for the tag gn_add
, but gn_create
.
The difference seems a bit subtle in the documentation, but gn_add
is kind of special case of gn_create
:
I'm afraid changing the code in https://github.com/geonetwork/core-geonetwork/blob/ee23e5430ef839c90ab6d08890e1176481465741/core/src/main/java/org/fao/geonet/kernel/EditLib.java#L505-L507 to check both probably will cause additional unwanted side effects?
gn_add/create
don't have effect on attribute which are always text. So a proper fix could be to change AddElemValue to extract that in a specific property... or we can also check if the target is an attribute and in this case enable creation mode.
The Batch Edit API uses the following setting to add an element in XPATH replace mode, if the XML node doesn't exist:
This doesn't make much sense, since in replacement mode you want to update an element if it exists, otherwise do nothing.
This pull request updates the code to not use that setting and never try to add the element in XPATH replace mode.
Test case:
1) Create an ISO19139 metadata and add a dataset contact with the name
John
and roleowner
2) In the batch edit configure a XPATH replacement:/gmd:MD_Metadata/gmd:identificationInfo/*/gmd:pointOfContact[*/gmd:role/gmd:CI_RoleCode/@codeListValue='owner' and */gmd:individualName/*/text()='John']/*/gmd:individualName/gco:CharacterString
The previous change match the element and changes the individual name to Mary
3) Edit XPATH expression to match another role:
pointOfContact
, that doesn't exist in the metadata:/gmd:MD_Metadata/gmd:identificationInfo/*/gmd:pointOfContact[*/gmd:role/gmd:CI_RoleCode/@codeListValue='pointOfContact' and */gmd:individualName/*/text()='John']/*/gmd:individualName/gco:CharacterString
Without the fix, produces an invalid ISO19139 element:
<gmd:pointOfContact>Mary</gmd:pointOfContact>
With the fix, the individual name is not updated (stays with the value John) as the XPATH expression does not match.
The pull request includes Sonarlint improvements.
For existing installations, a workaround to avoid this problem is to disable the settings listed at the beginning, unde r
Admin console
>Settings
>CSW
Checklist
main
branch, backports managed with labelREADME.md
filespom.xml
dependency management. Update build documentation with intended library use and library tutorials or documentation