kumuluz / kumuluzee-rest

KumuluzEE REST extension for implementation of common, advanced and flexible REST API functionalities and patterns as microservices.
https://ee.kumuluz.com
Other
8 stars 4 forks source link

Issue with filering fields of type Time and Timestamp #22

Open raaj31sharma opened 2 years ago

raaj31sharma commented 2 years ago

I have Entity class A which has this timestamp type field say "startTime". I want to filter records on the basis of "startTime".

I tried this way : filter=startTime:GTE:ts'2021-12-10T10:00:00:000Z' - Here startTime corresponds to Timestamp field in MY SQL filter=startTime:GTE:ts'10:00:00' - Here startTime corresponds to Time field in MY SQL Although I am not getting any error as such but looks like this filter is getting ignored while fetching the data.

Kindly help me to understand how to pass the time and timestamp fields in the request query

cen1 commented 2 years ago

Have you tried without the ts prefix?

raaj31sharma commented 2 years ago

With or without ts, I am not able to get the response in the second case (Time) filter=startTime:GTE:ts'10:00:00'

It is not able to pick the query, giving the error as either "ts" or "10:00:00" is not a text type.

Is there any other way to pass the Time type filter?

cen1 commented 2 years ago

I took a quick look at the code and I think there is currently no support for Time fields, only dates, datetimes and timestamps. Can you share your JPA entity class (or at least a subset with the time field)?

raaj31sharma commented 2 years ago

@Temporal( TemporalType.TIME ) @Column( name = "start_time" ) private Date startTime;

This is the way I am using the field in my entity class. I also feel that type Time is not handled in the code.

NOTE : There is one more issue I am facing that is regarding getting the count of the records using the utils method. When I am using the nested structure, say, passing (filter=entries.userId:EQ:user1) where one record can have multiple entries.

In this case the util method is giving me the count of entries rather than the count of records. While record.class is being passed as the method parameter. I was expecting the method to return the count of records.

Although if the search filter is applied on the main class fields it works fine.

cen1 commented 2 years ago

Code checks the class in the model directly, ignoring any JPA annotations such as @Temporal so the end solution would probably look at LocalTime instead. If you are using JPA 2.2 and Java 8+ that should not be an issue. But it looks like it doesn't check for LocalTime either right now. I will try to prepare a repro and a fix in the following days.

If you need an immediate workaround you can have a separate query parameter and pass it as a custom filter into JPAUtils.

Although if the search filter is applied on the main class fields it works fine.

Not sure I quite grasped what you were saying here. Can you give me an example of the JPAUtils call in each case?

raaj31sharma commented 2 years ago

queryEntitiesCount(EntityManager em, Class entity, QueryParameters q) This is the method I am using to get the count of the records. There are 2 scenarios: 1: When I am searching using fields of Class passed in the parameter. eg: filter=color:EQ:red This is working fine and giving the correct count.

2: When I am searching using fields of a nested class. Eg: filter=entries.userId:EQ:user1 where a list of entry is the field of Class. This is not giving me the count of the Class instead giving me the count of entries which should not happen.

In laymen's term if I say, A record have multiple entries, and if the search criteria is applied on the field of entry class, In the result it is returning the count of entries instead of the records. Although it should always be the count of records.

osbeorn commented 2 years ago

I have added filtering support for LocalTime and OffsetTime fields. Use these types instead of Date with @Temporal annotation.

I have also fixed the queryEntitiesCount method, which was applying DISTINCT in a wrong way.

raaj31sharma commented 2 years ago

Can you please merge the code and release the latest version so that I will be able to use and test the scenario.

Thanks

MBJuric commented 2 years ago

Hi, we will include this in the next regular release in a few weeks. In the meantime you can use the snapshot repository to use the latest unreleased version. Best regards

raaj31sharma commented 2 years ago

I used the below mentioned snapshot version:

com.kumuluz.ee.rest
<artifactId>kumuluzee-rest</artifactId>
<version>1.6.0-SNAPSHOT</version>

But it is giving me the below error:

"The POM for com.kumuluz.ee.rest:kumuluzee-rest:jar:1.6.0-SNAPSHOT is missing, no dependency information available"

Is it the right way to use? If not, please let me know how to use it.

Thanks

osbeorn commented 2 years ago

@raaj31sharma please check again. Version 1.6.0-SNAPSHOT should now be available.

raaj31sharma commented 2 years ago

@osbeorn It is still not working, getting error as not able to download jar from proximity. Pls let me know if its to be used in a different way. As of now I am using in the same way as mentioned above.

raaj31sharma commented 2 years ago

I am using the following dependency to use the snapshot version:

com.kumuluz.ee.rest kumuluzee-rest 1.6.0-SNAPSHOT

Getting the following error: Could not find artifact com.kumuluz.ee.rest:kumuluzee-rest:pom:1.6.0-SNAPSHOT in proximity (https://repository.abc.com/content/groups/public/)

Please let me know if there is a different way to use this.

Also, exactly when are you planning to release the next version of the library.