Skip to content

Compatible issue on httpRequestPayload with Support collections of entities as parameters #2350

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

Closed
venkat125 opened this issue Aug 10, 2021 · 9 comments
Labels
status: invalid An issue that we don't feel is valid

Comments

@venkat125
Copy link

I was trying to use the collection support on custom repository queries. That works fine when we build the collection locally as in the testcase. But, when i post the data through httpPayload, it throws error on parsing / object construction.

Since, this seems to be the http payload and collect support compatibility, thought of creating a new issue. If this seems to be not an issue, requesting to please suggest a workaround to get this.

Thanks SDN Team.

Referring the comments link here
Originally posted by @venkat125 in #2292 (comment)

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Aug 10, 2021
@venkat125 venkat125 changed the title Compatible issue with httpRequestPayload and Support collections of entities as parameters Compatible issue on httpRequestPayload with Support collections of entities as parameters Aug 10, 2021
@michael-simons
Copy link
Collaborator

SDN does not have any thoughts about HTTP Payloads.
It is the duty of Spring-WebMVC and most likely Jackson to deserialize your payload into Java objects that fit your definition. I can't do anything with the information above and I am not gonna reopen the other ticket.

In the other ticket Jackson is complaining about no default constructor present (a constructor taking no arguments). This can be solved with Jacksons @JsonCreator which needs to be added via that Lombok Annotation, something like this: @AllArgsConstructor(onConstructor_ = { @JsonCreator }).

Or you add also add @NoArgsConstructor, also from Lombok.

Sorry, as much as we love to help you, this is not an SDN issue. Please read up on Jackson and or Lombok.
Personal opinion: Lombok is helpful, so is Jackson.
But especially with Lombok you must be aware what you are doing by sprinkling annotations around, especially together with mapping frameworks like ours or Jackson.

https://github.com/FasterXML/jackson
https://projectlombok.org
This might be helpful
https://projectlombok.org/features/experimental/Jacksonized
https://medium.com/consulner/lombok-tricks-and-common-mistakes-fbf0ed044c3c
https://www.thecuriousdev.org/lombok-builder-with-jackson/
https://gist.github.com/michael-simons/72c17cb1cbb0ad9eb673ab2b18bf4272

@michael-simons michael-simons added status: invalid An issue that we don't feel is valid and removed status: waiting-for-triage An issue we've not yet triaged labels Aug 11, 2021
@venkat125
Copy link
Author

Just got workaround to get this worked. Will post the link shortly. Thanks Team

@venkat125
Copy link
Author

venkat125 commented Aug 16, 2021

Hi, @michael-simons i've accepted ur answer as it is resolved in SDN stackoverflow url But, the workaround is on the spring mvc side i hope as you mentioned. For the same i commented which works fine in updating simple collection of relationships with the desired output.

@RelationshipProperties @Data
public class KnowsEntity {

    @JsonView(Views.Public.class) // it might not be needed
    @Id
    @GeneratedValue
    private Long id;
    @JsonView(Views.Public.class) @Property
    private Boolean read;
    @JsonView(Views.Public.class) @Property
    private Boolean write;
    @JsonView(Views.Public.class) @TargetNode
    private Language language;

}

@Node(primaryLabel = "LANGUAGE")
public class Language {

    @JsonView(Views.Public.class) @Id
    private String name;

}

public class Views {
    public static class Public {
    }
}
@Query("UNWIND $relations As rel WITH rel " +
            "MATCH (f:PERSON {nid: $from}) - [r:KNOWS] -> (t:LANGUAGE {name: rel.__properties__.__target__.__id__}) " +
            "SET r.read = rel.__properties__.read " +
            "RETURN f, collect(r), collect(t)")
PersonEntity testR(@Param("from") String from,
                            @Param("relations") Set<KnowsEntity> relations);

Thanks

Further, when i tried to accommodate apoc.do.when for conditional querying on neo4j relationships like delete / upsert by boolean field, which works fine in neo4j browser after installing apoc library with below query.

MATCH (m:MALE {name: 'Max'}) WITH m
UNWIND [{id:54,read:false,write:false,is_delete:true,language:{name:"xxxx"}},{read:false,write:false,is_delete:false,language:{name:"yyyy"}}] as obj
CALL apoc.do.when(obj.is_delete,
    'MATCH (m)-[dr:KNOWS]->(:LANGUAGE {name: o.language.name}) delete dr',
    'MATCH (l:LANGUAGE {name: o.language.name}) MERGE (m)-[cr:KNOWS]->(l) ON MATCH SET cr.read = o.read, cr.write = o.write ON CREATE SET cr.read = o.read RETURN m,cr,l',
    {m:m, o:obj}
) YIELD value
RETURN value.m as m, value.cr AS cr, value.l AS l

But, when i used the same in @query i'm facing the same null on result (not updating / changing the data in DB)

@Query("MATCH (m:PERSON {name: $from}) WITH m " +
            "UNWIND $relations AS obj " +
            "CALL apoc.do.when(obj.__properties__.is_delete," +
                "'MATCH (m)-[dr:KNOWS]->(:LANGUAGE {name: o.__properties__.__target__.__id__}) DELETE dr RETURN m, dr as cr, l'," +
                "'MATCH (l:LANGUAGE {name: o.__properties__.__target__.__id__}) " +
                    "MERGE (m)-[cr:KNOWS]->(l) " +
                    "ON MATCH SET cr.read = o.__properties__.read, cr.write = o.__properties__.write " +
                    "ON CREATE SET cr.read = o.__properties__.read RETURN m,cr,l'," +
                "{m:m, o:obj}" +
            ") YIELD value " +
            "RETURN m, collect(value.cr), collect(value.l)")
    PersonEntity testR(@Param("from") String from,
                            @Param("relations") Set<KnowsEntity> relations);

Is there any issue in the above apoc implementation in @Query Or something happening with the apoc.do.when support in SDN 6.x

@michael-simons
Copy link
Collaborator

Thanks for your feedback.

SDN makes no assumptions about any procedures you call, being it APOC or built-in ones.
Check what kind of variable is actually passed to apoc with obj.__properties__.is_delete.

@venkat125
Copy link
Author

can you please suggest a way to look the passing value in apoc? as of now i could see the query debug log as below

[nio-8080-exec-1] org.springframework.data.neo4j.cypher : Executing:
MATCH (m:PERSON {name: $from}) WITH m UNWIND [{id:54,read:false,write:false,is_delete:false,language:{name:"xxxx"}},{read:false,write:false,is_delete:true,language:{name:"yyyy"}}] AS obj CALL apoc.do.when(obj.properties.is_delete,'MATCH (m)-[dr:KNOWS]->(:LANGUAGE {name: o.properties.target.id}) DELETE dr RETURN m, dr as cr, l','MATCH (l:LANGUAGE {name: o.properties.target.id}) MERGE (m)-[cr:KNOWS]->(l) ON MATCH SET cr.read = o.properties.read, cr.write = o.properties.write ON CREATE SET cr.read = o.properties.read RETURN m,cr,l',{m:m, o:obj}) YIELD value RETURN m, collect(value.cr), collect(value.l)

Please suggest a way to debug the passing values in the apoc query. It might be really helpful. Thanks

@michael-simons
Copy link
Collaborator

@fbiville Can you help here? This issue and the one linked in the first post has been reiterated multiple times, I am not too keen of debugging APOC. Thanks.

@venkat125
Copy link
Author

venkat125 commented Aug 17, 2021

Sorry, i had an issue (passing values) in the query variable in apoc and solved.
nvm
Note: query is fine
Thanks @michael-simons @fbiville

@Bhavinpanchal20
Copy link

@venkat125 can you tell me how you resolved that issue? because I get the same error to occur.

@venkat125
Copy link
Author

venkat125 commented Oct 7, 2022

This is just a workaround link to get this resolved. @Bhavinpanchal20

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: invalid An issue that we don't feel is valid
Projects
None yet
Development

No branches or pull requests

4 participants