Insert a fragment into an existing document #295#297
Insert a fragment into an existing document #295#297Chunyuwilson wants to merge 2 commits intomarklogic-community:devfrom
Conversation
| import java.io.IOException; | ||
| import java.util.List; | ||
|
|
||
| public class MarkLogicPatchItemWriter implements ItemWriter<String[]> { |
There was a problem hiding this comment.
I advise splitting this class up into two separate classes to adhere to the single responsibility principle. Classes should only have one reason to change.
Recommend a XmlFragmentItemWriter and a JsonNodeItemWriter.
There was a problem hiding this comment.
Yes, I have updated here according to your comments
|
|
||
| if (isXml) { | ||
| //note the root element is referenced in the first parameter of this call, you may need to change based on your xml document | ||
| DocumentPatchHandle patchHandle = xmlPatchBldr.insertFragment("/doc", DocumentPatchBuilder.Position.LAST_CHILD, itemPatch).build(); |
There was a problem hiding this comment.
The parameters for the insertFragment method on the DocumentPatchBuilder should not be hard coded. My recommendation is to pass the contextPath and position as constructor parameters
There was a problem hiding this comment.
Yes, Created the parameters.
| for (String[] item : items) { | ||
| String uri = item[0]; | ||
| String xmlPatch = item[1]; | ||
| String itemPatch = item[1]; |
There was a problem hiding this comment.
What is your opinion on this data structure. Passing in an array of strings of size 2 is kind of hacky. I think a map might be cleaner, what do you think?
There was a problem hiding this comment.
Yes, I agree with you. It is not very clear to use List for the Uri and the patch.
I have changed it to Map type in the list. The key of the Map is the uri of the document. The value is the patch content.
|
Please check my update for your review. |
No description provided.