Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
  • Jun 26 2017 20:07
    @remmeier banned @hibaymj
Grzegor Ksiazczyk
@gksiazcz_twitter
one may be a bug: I can create resource item with relation to non existing external resource id
one probably wrong config on my side: links to related external resource items are not correct
Grzegor Ksiazczyk
@gksiazcz_twitter
so my question is: Do you have any good / working example of two java services that have relation in model and it validate/include one to another "out of the box" that I can learn how to use it?
Remo
@remmeier
@rehab-reda0 i thin it needs a custom operator, or may equals shouldnreally be equals and there should be an additional contains
@gksiazcz_twitter not quite surr, maybe the ResourcePostController needs to be checked if there is a gap in relationship validation. in the examples there is at least a example with two services
Grzegor Ksiazczyk
@gksiazcz_twitter
thanks @remmeier for you tips, all sorted out now
Shwetank
@c0r3ciph3r_twitter
In Crnk, how can I deny serialization of some properties based on spring security user role?
Remo
@remmeier
there is a security chapter in the docs. all levels are supported, types, individual resources, and fields of a resource.
Sanjin Dumančić
@sdumancic
Hi, I have a one question: Does CRNK work with Quarkus and is there some example how to integrate crnk with quarkus?
Remo
@remmeier
there is no quarkus example yet, but there are many other integration examples. from that perspective it should not be too hard. the decisive factor is probably what foundation of a quarkus integeation will be, servlets, jaxrs or one of the async implementations.
an example would be very welcomed
Stefan Bodewig
@bodewig
Hi, I'm looking for a way to get access to a request's meta, i.e at the level of the Document rather than the resource - i.e. a request that looks somewhat like the meta example in https://jsonapi.org/format/#document-meta . I've been browsing the code for a while and believe there is no easy way to get hold of it inside of a Repository as it is not related to the resource itself. I see I could provide a DocumentFilter. Am I overlooking another alternative?
Remo
@remmeier
it is available on ResourceList, but not for single resources as of yet
Stefan Bodewig
@bodewig
Thanks @remmeier - ResourceList currently only works on the response side of a repository anyway, while I'd want to consume the request's meta data inside of save/create/delete. I understand this is currently not easily done and try a different approach.
Roy
@depzor
Hi all, does CRNK supports read-only jpa transactions? Or is there a way to do so? In my case simply all GET http operations could have been queried in a read-only transaction.
I already checked out this class: io.crnk.spring.jpa.SpringTransactionRunner which runs by default in read-write mode.
Remo
@remmeier
not so far, but in principal easy to add. maybe by reading HttpRequestContext to check the used method.
Roy
@depzor
Thanks! I am wondering how I could read the HttpRequestContext since implementing HttpRequestContextAware into an extended class of SpringTransactionRunner does not allow me to get an instance of HttpRequestContext
Remo
@remmeier
CrnkBoot
not every object is exposed to spring DI just yet. but PRs are welcome, a small change
Andrew Rosenberg
@Iapetus999
Are there any builds past 3.4.20210509072026? There are some fixes I need and was unable to build the project myself.
Martín Battaglia
@mnbattaglia
Hi @remmeier . Is it possible to set headers for a response? I tried almost everything (all types of filters, HttpRequestContextAware, etc.), but at the end of the chain processing the Response object is converted toHttpResponse() and that builds a new HttpResponse(), sets the body, the status and content type. No response headers at all and no control on custom headers for the response. Am I missing something?
Martín Battaglia
@mnbattaglia
I think the problem is that the response is set in the context at the end of processing the chain (HttpRequestDispatcherImpl) so I don't have the chance to set the headers in the recently set response, as filters were already processed. I see that, in the end, headers that are set to the Response object are mapped to the servlet response in the checkabort() method of ServletRequestContext. So, the only thing I need is a way to hook up once the response is set to context so I can set headers to it. Any ideas how to achieve that?
Martín Battaglia
@mnbattaglia
One more question @remmeier (sorry, started recently with Crnk, and I'm love so far). I need to add some filters but I need to set them in a specific order to be processed in the chain. I also need them to be managed, so I can inject other components. As I'm using Spring, by marking them as @Component (to be able to autowire other components) I'm making them discoverable by the default spring discovery service. The discovery service just search for beans (filters in this case) and adds them to the default module in a random order. It would be great to be able to define the order (maybe when the service is listing you could use the spring @Order annotation or the Ordered interface), but I have no control over it. So, decided to build my own module and add filters in order. The problem is, given that those filters needs to be managed (components), they are also added by the spring default discovery service. In this case, I tried to disable that or set an EmptyDiscoveryService without success. The CrnkCoreAutoConfiguration always comes first and sets a SpringServiceDiscovery which cannot be set again later (it fails when trying to do it). Is there any way I can achieve that? (without disabling the whole CrnkCoreAutoConfiguration of course). Thanks!!!
Mishti
@misthi31_twitter
How do I use ResourceModificationFilter in crnk save ? I need to get the attributes of the resource that are changed. I can’t find an example.
10 replies
Mishti
@misthi31_twitter

@remmeier I have the below 2 resouces where Project has relationship with Task ``` @JsonApiResource(type = "project")
public class Project {

@JsonApiRelation(mappedBy="project")
private Task task;

...

}

@JsonApiResource(type = "task")
public class Task {

@JsonApiRelation
private Project project;

...

}
``` I am doing a PATCH as /api/project/{id}/task and I get an exception as io.crnk.core.exception.BadRequestException: project/{id}/ResourceFieldImpl[resourceClass=com.example.Project, name=task,resourceType=project] with method PATCH

2 replies
whgibbo
@whgibbo
Are there any plans to update "io.crnk:crnk-setup-spring-boot2" to upgrade to spring boot 2.6.6?
7 replies
whgibbo
@whgibbo
On another note, has anybody tried using CRNK with a Graph DB?
Weihua Hu
@jameshwh
latest stable version
@remmeier Hi, what's the latest stable version of CRNK? it is 3.4.20210509072026 or 3.3.20200920055408? I know there is a page (https://www.crnk.io/releases/stable/) which we can get the version info but just want to make sure if it up to date.
Miks Miķelsons
@miks

Can anyone throw a hint why "detached entity passed to persist" is happening?

I have single model without any relationships and both public interface ReportRepository extends CrudRepository<Report, Long> and public class ReportRepositoryImpl extends JpaEntityRepositoryBase<Report, Long> repositories.

When creating and updating Report model like this in my tests:
```var report = new Report();
report.setStatus("foo");
reportRepository.save(report);

report.setStatus("bar");
reportRepository.save(report);
```

detached entity passed to persist: com.rimi.socialcards.models.Report; nested exception is org.hibernate.PersistentObjectException: detached entity passed to persist: com.rimi.socialcards.models.Report happens.
From trace I see that while I'm using ReportRepository, it's somehow calls io.crnk.data.jpa.JpaEntityRepositoryBase.save.

Why it's that?

Grzegor Ksiazczyk
@gksiazcz_twitter
var savedReport = reportRepository.save(report);
savedReport.setStatus("bar");
reportRepository.save(savedReport);
when you savr the first time repository returns fresh copy of this object. The object you have in hand is not valid anymore. You can refresh it with entity manager (not recommended) or use the fredh one returned by repository adter saving. It is not crnk related - just regular JPA/hibernate stuff
(sorry for mistakes in words, I’m writing from phone ;) )
Miks Miķelsons
@miks

fresh one - you mean like this?:

    var report = new Report();
    report.setStatus("foo");
    reportRepository.save(report);

    var freshReport = reportRepository.findById(report.getId()).get();

    freshReport.setStatus("bar");
    reportRepository.save(freshReport);

I'm still getting same error

Miks Miķelsons
@miks
Thing is - if I delete ReportRepositoryImpl class, there is no error with that simple save. That's why I asked question why there is io.crnk.data.jpa.JpaEntityRepositoryBase.save in trace if I'm using ReportRepository which extends org.springframework.data.repository.CrudRepository, not crnk.
Grzegor Ksiazczyk
@gksiazcz_twitter
hard to say, can you share somewhere example in github? looks like you have more than one implementation for the same Entity/Resource so for me it doesn't make sense to have both, so it may be random what is really injected or used to handle this Report save action, you think you are using ReportRepository that extends spring....CrudRepository but in real you have two candidates for that and it is not clear which is injected first and which second, which would be selected for save action etc - I would recomend to have only one repository for one type of Entity/Resource. When you have one it works good, when you have two repositories you have conflict and problems - anyway maybe it is nondeterministic which will be finally used
Miks Miķelsons
@miks
Yes, I have two repositories - one is interface extending CrudRepository for all queries and other one is class extending RepositoryImpl. So, your suggestion is to get rid of that interface repository?
Grzegor Ksiazczyk
@gksiazcz_twitter

yeap, I would have only this one:

@Component
public class ReportsRepository extends JpaEntityRepositoryBase<Report, Long> {

public ReportsRepository() {
    super(Report.class);

}

Miks Miķelsons
@miks
Ok, but crnk JpaEntityRepositoryBase doesn't have spring CrudRepository query methods (findBy, existsBy, etc). Is there any similar feature in crnk JpaEntityRepositoryBase that I'm not aware of?
AJ
@aj1x1
Do anyone know how should I should I use sparse field on 2nd level attributes? Someone asked this question on 2018 in crnk-project/crnk-framework#380 . Please help.
5 replies
Lasse Immonen
@turtleman

I noticed an issue with trying to patch a resource with nested attributes when trying to deliberately null one of the nested attributes to make it empty. It looks like that when crnk's ResourcePatchController has done its thing and the resource arrives to the repository's save method, crnk has initialised the to-be-nulled attribute with the current value from the database. There's no way to determine if it should be nulled anymore in that stage. The intent of emptying the attribute got lost.

I wonder if there would be any solutions for this? Something to declare or make differently in the nested attribute class definition for example? I already took a shot to JsonApiEmbeddable annotation but that didn't seem to affect the behaviour. Didn't really look what it does, though.

All tips and tricks appreciated!

Weihua Hu
@jameshwh
image.png
@remmeier Hi, the relationships can only have two links, one for self and the other is related, can we add custom link to it? but it appears impossible since the code in class io.crnk.core.engine.internal.document.mapper.ResourceMapper.java hardcode only self and related links as you see below, so not able to add custom link to it, just want to double check with you:
Remo
@remmeier
@turtleman server logic should be fine. more a question maybe how the request body looks like? if java is used as client, the null/empty annotation properties can control that. or the use of Optional.
@jameshwh for many relations it is possible to change by setting LinksInformation for the ReaourceList. not for one relations, there only filters allow to set it so far.
Mishti
@misthi31_twitter

I am using spring-boot-starter-parent version 2.6.4 with Reactive WebClient.

Below are the dependencies.


<dependency>

            <groupId>org.springframework.boot</groupId>

            <artifactId>spring-boot-starter-oauth2-client</artifactId>

        </dependency>

        <dependency>

            <groupId>org.springframework.boot</groupId>

            <artifactId>spring-boot-starter-web</artifactId>

        </dependency>

        <dependency>

            <groupId>org.springframework.boot</groupId>

            <artifactId>spring-boot-starter-webflux</artifactId></dependency>

I need to use @EnableWebFluxSecurity along with WebClientReactiveClientCredentialsTokenResponseClient from Spring security 5.6.2 version.

I have created a simple REST controller which uses client credentials grant type and integrates with the vendor with Bearer access token through WebClient. When I integrate with the service @GetMapping("/greeting"), the Oauth2 integration with Bearer access token works.

However when I call the CRNK resource url (http://localhost:8080/myResource/someId) I always get 404.


@EnableWebFluxSecurity
@Configuration
@Order(SecurityProperties.BASIC_AUTH_ORDER - 1)
public class SecurityConfig {

    @Bean
    SecurityWebFilterChain apiHttpSecurity(ServerHttpSecurity http) {

        http.cors()             .and().authorizeExchange().pathMatchers(“/greeting/**”,“/myResource/**”).permitAll()
                .anyExchange().denyAll()
                .and().csrf().disable();
        return http.build();

    }

}
Oscar Sandoval
@oscaralvaro
@remmeier Hi, I love the JSON nested filtering, thank you! Quick question, how experimental is? I was introduced in 2018, do you have plans to remove in future versions?
Remo
@remmeier
no, no plans for removal. the main issue is that it not backed by an official spec by json api.
Lucas Jeremías Couchot
@LucasJC

guys I am trying to build the sources from master, when doing gradlew build I get this error:

A problem occurred evaluating root project 'crnk-framework'.
> Receiver class org.ajoberstar.grgit.operation.OpenOp does not define or inherit an implementation of the resolved method abstract setProperty(Ljava/lang/String;Ljava/lang/Object;)V of interface groovy.lang.GroovyObject.

Any ideaS?

martijn
@martijn:mserver.link
[m]

Hi everybody. I am currently implementing a board game backend which has game and player resources. Now I would like a mechanisme to send a move to a game so it can validate and execute the move on the game resource. I don't need to store the moves so a move resource seems over kill. In the docs I've found the following possibility:

A dedicated AddressChangeResource that is in a relationship with the person resource. Then a POST request to /api/addressChange or /api/person/{id}/addressChange (depending on the setup) will trigger a new address change. This is the most elaborate setup and can complement the address relationship from before. It allows not just to trigger a change, but also, for example, to query the current status and get a history of changes. This in turn allows to model more complex workflows where an address change may take a larger mount of time and may involve further manual steps.

But how does this work? Is there a code example of this somewhere?