springfilter icon indicating copy to clipboard operation
springfilter copied to clipboard

Support Search in ElementCollection

Open moiflo033 opened this issue 3 years ago • 7 comments

It would be nice if you could search for Elements in a collection.

moiflo033 avatar Oct 07 '21 09:10 moiflo033

Hey,

Just to give some news, I am going to change a few things as stated in #135 before going on with this issue, since @ElementCollection is basically a @OneToMany.

torshid avatar Oct 12 '21 14:10 torshid

I also wanted to know what kind of search you want to do on those collections.

For example

  • collection in ('x', 'y', 'z') : is one of x, y, z an element of collection?
  • collection : 'x' : is x inside collection?
  • collection ! 'x' : is x not inside collection?

I think that those are what you expect. Correct me if I am wrong please.

torshid avatar Oct 12 '21 14:10 torshid

Hi im sorry it took me so long to Answer.

My thought was:

  • Key exists
  • Key exists with value
  • Value exists

My use case would be for a map.

But your examples certainly do apply for Lists and in some part for maps to.

moiflo033 avatar Oct 14 '21 08:10 moiflo033

I will try to implement that sooner.

torshid avatar Oct 15 '21 05:10 torshid

hi @torshid any update on this case?

wicaksono avatar Aug 31 '22 22:08 wicaksono

Hey @wicaksono @moiflo033

Unfortunately I didn't get the time to focus on this issue. Your contributions are always welcome. You can also sponsor me so that I can give better support.

torshid avatar Sep 02 '22 04:09 torshid

@torshid I think I have a solution for the parsing, but I don't know if that is enough.

I think this code in the class "StringConverter.java" at row 122 would be something to try out:

        if (Map.class.isAssignableFrom(expectedType)) {
            Map<String, String> hashMap = new HashMap<>();
            String keyValues[] = input.split(",");

            for (String keyValue : keyValues) {

                String[] splitKeyValue = keyValue.split(":");

                String key = splitKeyValue[0].trim();
                String value = splitKeyValue[1].trim();

                hashMap.put(key, value);
            }

            if (hashMap.isEmpty()) {
                throw new ClassCastException("The input '" + input + "' could not be parsed to Map");
            }

            return hashMap;
        }

Then you should be able to parse a string like this: 'Aashish:1, Bina:2, Chintu:3'

I cloned the repository and tried to build a jar to test it locally with mvn clean install but I get some error: [ERROR] Failed to execute goal org.apache.maven.plugins:maven-gpg-plugin:3.0.1:sign (sign-artifacts) on project spring-filter: Exit code: 2 -> [Help 1]

Dennis-Nilsson avatar Sep 07 '22 14:09 Dennis-Nilsson

It is now possible to filter @ElementCollection (lists and maps) in version 3.0.0.

Consider map to be a Map<?, ?>, you can query: map.key : 'test' and map.value : 'test'.

torshid avatar Feb 20 '23 12:02 torshid