Skip to content
This repository was archived by the owner on Feb 27, 2023. It is now read-only.

Insert a fragment into an existing document #295#297

Open
Chunyuwilson wants to merge 2 commits intomarklogic-community:devfrom
Chunyuwilson:dev
Open

Insert a fragment into an existing document #295#297
Chunyuwilson wants to merge 2 commits intomarklogic-community:devfrom
Chunyuwilson:dev

Conversation

@Chunyuwilson
Copy link
Copy Markdown
Contributor

No description provided.

import java.io.IOException;
import java.util.List;

public class MarkLogicPatchItemWriter implements ItemWriter<String[]> {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, Created the parameters.

for (String[] item : items) {
String uri = item[0];
String xmlPatch = item[1];
String itemPatch = item[1];
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@Chunyuwilson
Copy link
Copy Markdown
Contributor Author

Please check my update for your review.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants