Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DATAES-535 - Add mapping annotation @DynamicTemplates #238

Conversation

kukisak
Copy link

@kukisak kukisak commented Jan 17, 2019

  • You have read the Spring Data contribution guidelines.
  • There is a ticket in the bug tracker for the project in our JIRA.
  • You use the code formatters provided here and have them applied to your changes. Don’t submit any formatting related changes.
  • You submit test cases (unit or integration tests) that back your changes.
  • You added yourself as author in the headers of the classes you touched. Amend the date range in the Apache license header if needed. For new types, add the license header (copy from another file and set the current year only).

@kukisak
Copy link
Author

kukisak commented Jan 17, 2019

This pull request is addaptation of #132 to be compatible with spring-data-elasticsearch-3.1.x

@xhaggi
Copy link
Contributor

xhaggi commented Jan 24, 2019

We can't accept your pull request without having a corresponding Jira issue. Please create one for this and adjust your commit message + pull request title according our Spring Data contribution guidelines.

@kukisak kukisak changed the title adapted @DynamicTemplates annotation to spring-data-elasticsearch-3.1.4 DATAES-535 - Add mapping annotation @DynamicTemplates Jan 29, 2019
@kukisak
Copy link
Author

kukisak commented Jan 29, 2019

Hi @xhaggi ,
I added Jira issue, adjusted commit message and pull request title. Is it all correct?

@xhaggi
Copy link
Contributor

xhaggi commented Feb 14, 2019

Please squash your commits into a single one and do a force-push to your branch.


/**
* Elasticsearch dynamic templates mapping.
* This annotation is handy if you prefer apply dynamic templates on fields with annotation e.g. {@link Field} with type = FieldType.Object etc. instead of static mapping on Document via {@link Mapping} annotation.
Copy link
Contributor

Choose a reason for hiding this comment

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

Please break down this comment.

Copy link
Author

Choose a reason for hiding this comment

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

Applied.

*/
private static void addDynamicTemplatesMapping(XContentBuilder builder, String jsonString) throws IOException {
JsonNode jsonNode = new ObjectMapper().readTree(jsonString).get("dynamic_templates");
if (jsonNode != null && isNotBlank(jsonNode.toString()) && jsonNode.isArray()){
Copy link
Contributor

Choose a reason for hiding this comment

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

IMO there is no need to check for isNotBlank(jsonNode.toString()) because jsonNode.isArray() should be enough.

Copy link
Author

Choose a reason for hiding this comment

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

Good one. Applied.

if (iterator.hasNext()){
next = next.concat(",");
}
builder.rawValue(new BytesArray(next.getBytes()), XContentType.JSON);
Copy link
Contributor

@xhaggi xhaggi Feb 14, 2019

Choose a reason for hiding this comment

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

Not sure if we really need to iterate over all node elements. It should be enough to write the jsonNode as raw value.

String json = objectMapper.writeValueAsString(jsonNode);
builder.field(FIELD_DYNAMIC_TEMPLATES);
builder.rawValue(new BytesArray(json.getBytes()), XContentType.JSON);

Copy link
Author

Choose a reason for hiding this comment

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

Nice simplification. Applied.

Copy link
Contributor

@xhaggi xhaggi left a comment

Choose a reason for hiding this comment

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

Please take a look at my comments

@kukisak kukisak force-pushed the dynamic-templates-for-spring-data-3.1.4 branch from 7e3ae93 to 5738006 Compare February 21, 2019 20:48
@kukisak
Copy link
Author

kukisak commented Feb 21, 2019

I applied all your requested changes. Please continue in review.

if (isNotBlank(mappingPath)) {
String jsonString = ElasticsearchTemplate.readFileFromClasspath(mappingPath);
if (isNotBlank(jsonString)) {
addDynamicTemplatesMapping(mapping, jsonString);
Copy link
Contributor

Choose a reason for hiding this comment

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

There's one little thing I'd like to change. I would move all this into addDynamicTemplatesMapping(), so we only have one call to this method and pass the XContentBuilder and class.

private static void addDynamicTemplatesMapping(XContentBuilder xContentBuilder, Class claszz) throws IOException

Copy link
Author

Choose a reason for hiding this comment

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

Good one. Applied refactoring.

@xhaggi
Copy link
Contributor

xhaggi commented Mar 8, 2019

Ok, nice to see you've addressed all my concerns ;) Please squash all your commits into a single one and we are ready to shove it in.

@kukisak kukisak force-pushed the dynamic-templates-for-spring-data-3.1.4 branch from 68ad72d to 7c1dd4b Compare March 12, 2019 20:08
@kukisak
Copy link
Author

kukisak commented Mar 12, 2019

Ok, I squashed all commits to single one. So you can shove it in.
Will you also merge it into the future releases like 3.2 and 4.0?

@xhaggi
Copy link
Contributor

xhaggi commented Mar 13, 2019

Will you also merge it into the future releases like 3.2 and 4.0?

Next time, please do not submit a pull request against a branch other than master. We do the backports when necessary.

Right now it's fine, I'll adjust your changes to be based on the master.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants