Spring Data Mongo: IllegalArgumentException trying to use field reference for minus() - spring

I'm trying to use the $subtract operator to project the difference between two fields as a separate third field using this line of code:
pipeline.add(Aggregation.project("createdTime","modResult").andExpression("createdTime").minus("modResult").as("bucketedTime"));
However, when I try to perform the aggregation, I get the following exception:
org.springframework.web.util.NestedServletException: Request processing failed; nested exception is java.lang.IllegalArgumentException: can't serialize class org.springframework.data.mongodb.core.aggregation.Fields$AggregationField
What am I doing wrong here? I've noticed that if I provide an integer instead of a field name, there is no issue. Thanks for your help.

As per my question here, it turns out I should have been using and() instead of andExpression(). The latter tries to interpret the argument as an expression, such as field1 + field2 as a more convenient way of doing .and("field1").plus("field2").

Related

NiFi putelasticsearch5 error - Content type is missing

I am using PutElasticsearch5 processor to index documents into ES.My workflow has couple of other processors before PutElasticsearch5 which converts avro to json.
I am getting the below given error when I run the workflow.
java.lang.IllegalArgumentException: Validation Failed: 1: content type is missing;2: content type is missing;
I coudlnt find any other relvant information to troubleshoot this. There is no setting for "Content Type" under Putelasticsearch5 configuration
I'm also having this issue, like user2297083 said if you are sending a batched JSON file into the PutElasticsearch5 then it will throw this exception and move the file into the FAILED relationship. The processor seems like it only handles one JSON object written into a file at a time that cannot be surrounded by array brackets. So if you have a file with content such as:
[{"key":"value"}]
then the processor will fail however if you send the same document as:
{"key":"value"}
then the processor will index successfully, considering your other configurations are correct.
One solution can be such that if you don't want to send everything through a splitter before coming to the PutElasticsearch5 processor, then use a splitter processor that works off of the FAILURE relationship to the PutElasticsearch5 and sends data back into the same PutElasticsearch5. More FlowFiles means more IO in your node, so I'm actively looking for a way to have the PutElasticsearch5 processor handle a batched JSON document. I feel like there's got to be a way without writing a custom iteration of it or creating a ton of new FlowFiles.
EDIT:
Actually, it does answer the question. His question is:
I am using PutElasticsearch5 processor to index documents into ES.My workflow has couple of other processors before PutElasticsearch5 which converts avro to json.
I am getting the below given error when I run the workflow.
java.lang.IllegalArgumentException: Validation Failed: 1: content type is missing;2: content type is missing;
which is exactly the exception message that is given by the PutElasticsearch5 processor when passing a JSON file that is not formatted correctly. His question is why this is happening.
My answer states why it's happening (one possible use case) and how to work around it by giving a solution that does work.
In this case, correctly formatted JSON means a FlowFile that has a single JSON object as it's content as I have shown above.
Further looking into this though, it makes sense that the processor only takes a single JSON document FlowFile at a time because you can use FlowFile attributes to specify the "id" of the indexed document. If the uuid of the FlowFile is used and it was a batched JSON i.e.
[{"one":1},{"two":2},{"three":3}]
then each JSON object would be indexed in elasticsearch using the same "index","type", and "id" (id being the FlowFile uuid), and this would not be desired.

Spring MVC- Joda datetime error message for invalid date

I have a joda datetime attribute in my request object and I have used #DateTimeFormat for the date formatting.
But when I enter an invalid date(say day as 55), it displays the whole message
Failed to convert property value of type java.lang.String to required type org.joda.time.DateTime for property request.myDate; nested exception is org.springframework.core.convert.ConversionFailedException: Unable to convert value "55/12/2014" from type java.lang.String to type org.joda.time.DateTime; nested exception is org.joda.time.IllegalFieldValueException: Cannot parse "55/12/2014": Value 55 for dayOfMonth must be in the range [1,31]
How can I change it to a custom message as the present message is generated by Spring.
In another SO question
Spring mvc Joda Datetime converter fail if invalid date
it is asked to make entry in message.properties.
But I'm not able to understand how will it pick the message from property file as I am not doing any error.rejectValue type of thing, So how will the message be identified.
The approach you linked to in your question should work. But the message key you should use is for instance typeMismatch.org.joda.time.DateTime.
Even though you are not manually rejecting the value anywhere Spring will automatically know where to look for the message based on the rules described in the JavaDoc of DefaultMessageCodesResolver.
In the situation you describe Spring will look for following codes specifically:
typeMismatch.request.myDate - Conversion message for attribute named "myDate" on an object named "request"
typeMismatch.myDate - Conversion message for attribute named myDate
typeMismatch.org.joda.time.DateTime - Conversion message for DateTime type
typeMismatch - General conversion error message
So you can define some general typeMismatch message like Incorrect format and then define more specific messages as needed. The more specific error codes have higher priority than those below it. So if you have both typeMismatch and typeMismatch.org.joda.time.DateTime messages defined, the latter will be used.

Cannot convert value of type [org.springframework.web.multipart.commons.CommonsMultipartFile] to required type [java.sql.Blob]

when i used without validation the deatails successfully inserted into DB,But when i applied validation using spring above exception occurr.
java.lang.IllegalStateException:
Cannot convert value of type [org.springframework.web.multipart.commons.CommonsMultipartFile]
to required type [java.sql.Blob] for property 'employee_Uploadphoto'
could anybody please rectify this one?

How to get MessageBuilder status in Protocol Buffers?

When using Message.Builder.build() an exception is thrown when a required field is not set. Is there way to find out if the exception will be thrown? i.e. something like an iSReadyToBuild? There is a buildPartial method but it does not say whether the build was complete or partial.
The method you are looking for is called "isInitialized()".

Usage of #RequestParam throws error in Spring 3

I am using the #RequestParam annotation to get the request parameters , and using the same to insert the values into the DB.
I have setup the controller to re-direct to the same page which contains the text fields for the user to enter the values, which are being read using the #RequestParam annotation.
But after I enter the values into the text fields , and click submit , it throws this error
Request processing failed; nested exception is java.lang.IllegalArgumentException: Name for argument type [java.lang.String] not available, and parameter name information not found in class file either.
I am a newbie to Spring 3 , and unable to understand the error. Can anybody please shed light on the same.
Thanks in advance,
Vivek
In order to inject the value of request parameter into your handler method parameter, either one of the following should be satisfied
The name of the request parameter must match the name of the method parameter.
e.g.
Following will inject the request parameter named "studentName" into the method parameter studentName
public String goToStep(#RequestParam String studentName)
The request parameter name must be explicitly specified if it does not match the method parameter. The following will inject "nameOfStudent" request parameter into studentName:
public String goToStep(#RequestParam("nameOfStudent") String studentName)
Please post your handler method code if your issue continues to persist.
I asked for the version you are using because I ran with a similar problem a few days ago. I was using Spring 3.1.0.M2 and the same exception appeared when I was using #PathVariable in proxied #Controller.
It was caused by a resolved known bug. You just have to switch to 3.0.6 or try the nightly build 3.1.0.BUILD-SNAPSHOT. Of course, the latter option is not recommended for production environment.

Resources