by

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
Remo
@remmeier
@nature32 rather than IllegalArgumentException we should throw a BadRequestException.
added it to the ticket
Rehab Reda
@rehab-reda0
Thanks Remo. so is there a workaround I can translate the filter in the request to a filter that can be accepted by crnk and repo
I mean something that is called at the beggining ( before going to the deserialization) I can override it and change the request filters ?
Remo
@remmeier
depends on what kind of filter you would like to apply. If you can map it to the other operators, you can do that in your repository. If not, we should do that little change in crnk-data-jpa. It is not really much effort and should be of use to other people as well.
4 replies
nature32
@nature32
hi. I need to change the exception from 500(coming from crnk) to 400(in my code) .I have written one custom filter by implementing DocumentFilter so that I can change the response before sending it to client. but I am not able to find where should I set this custom filter class. can someone help me please?
Remo
@remmeier
let's fix it directly in crnk-core. It is a minor commit and you don't have to work around it.
11 replies
(the alternative approach would be to implement a custom ExceptionMapper, but in general IllegalStatEexception should not be used here)
Mahmoud Hatem
@mahmoud-hatem

Hi, I was trying to implement cursor based pagination by creating my own paging spec. I noticed that JpaExecutor trying to convert it to an offsetPagingSpec.

Does that mean every new paging spec should be converted to offsetPagingSpec ?

4 replies
image.png
Paulo Nascimento
@paulopaesnascimento
Hi, I am using Crnk with Spring Boot, I am configuring two datasources., but I only can get to work with Crnk the one datasource I set as Primary, I get the following error for the other entities: io.crnk.core.exception.InternalServerErrorException: Not an entity. I am new to Crnk, can someone give some directions what I need to do to have multiple datasources in Crnk. Thanks
9 replies
whgibbo
@whgibbo

Hi,
New to the group.. Was just looking crnk and was wondering if there was any support for NOSQL databases ?
In particular I was looking for DynamoDB .. Any examples ?

Thanks

Mahmoud Hatem
@mahmoud-hatem
image.png
Why is it explicity set the offset pagination even if I override it in model definition ?
1 reply
image.png
Rehab Reda
@rehab-reda0
Hi, if I the repo extends JpaEntityRepositoryBase, what if I want to override the find all to get sum(order) grouped by client and having sum(order)>100 how can i do so ?
1 reply
Mahmoud Hatem
@mahmoud-hatem

@remmeier can you respond for this thread pls? We need it to go on with our implementations.

Hi, I was trying to implement cursor based pagination by creating my own paging spec. I noticed that JpaExecutor trying to convert it to an offsetPagingSpec.

Does that mean every new paging spec should be converted to offsetPagingSpec ?

2 replies
Arun Bitla
@abitla
hey guys! What's the best way to validate "request headers" for REST api using Crnk. We have requirement to validate mandatory and values of request headers. Right now, I have a custom method that validates the request headers before the database call. There must be a simpler way to validate request headers similar to request body validation using crnk validation.
Remo
@remmeier
Hi @abitla , depends on what you are doing with that request header. Often request headers are used for security and related concern. Those span over all repositories and maybe other non-crnk endpoints. For this reason the best place might be the underlying HTTP engine (like a servlet filter).
Steve Brush
@brushs
Is there a blog post somewhere containing an example of how to map a @ManyToOne unidirectional relationship (e.g. Product -> ProductType) in the latest version? I have a ProductType property in my Product class, annotated with @ManyToOne, @JoinColumn and @JsonApiReleation, with nothing related to this relation currently in ProductType. When trying to execute a GET request I receive "Couldn't find a relationship repository for resourceType=product and field=productType, hasIdField=false, repositoryBehavior=DEFAULT"
Remo
@remmeier
do you have the entire exception? server or client side?
Steve Brush
@brushs
I was able to answer my own question -- it was in docs after all, just did not jump out as the right scenario, must have read too fast. I removed the @JsonApiRelation annotation, added a separate productTypeId property with the @JsonApiRelationId annotation and it worked as expected
whgibbo
@whgibbo
Are there any examples of generating the Swagger./OpenAPI using Maven ?
Remo
@remmeier
not as of yet,we only have a Gradle plugin. If you search for Maven in this chat, you should find some anwers to the topic. To summarize, the generator is independent from Gradle. So if you replicate what Gradle is doing, you can do it equally well with any Java main class or Maven. Personally I don't use Maven anymore. But if somebody like to contribute a Maven plugin, would be very welcomed. In the meantime maybe this approach should be documented somewhere of doing it one byitself without Maven plugin.
nature32
@nature32

Hi. we are sending an attribute "is-enabled" from the front end code but its not there in resource class. I have updated crnk to 3.2 . now its giving the below exception.before updating crnk it was working fine.

{"exception":"io.crnk.core.exception.BadRequestException: attribute is-enabled not found\n\tat io.crnk.core.engine.internal.dispatcher.controller.ResourceUpsert.setAttribute(ResourceUpsert.java:191)\n\tat io.crnk.core.engine.internal.dispatcher.controller.ResourceUpsert.setAttributes(ResourceUpsert.java:148)\n\tat io.crnk.core.engine.internal.dispatcher.controller.ResourcePostController.handleAsync(ResourcePostController.java:64)\n\tat io.crnk.core.engine.internal.dispatcher.controller.BaseController.handle(BaseController.java:56)\n\tat io.crnk.core.engine.internal.http.DocumentFilterChainImpl.doFilter(DocumentFilterChainImpl.java:28)\n\tat io.crnk.core.engine.internal.http.JsonApiRequestProcessor.processAsync(JsonApiRequestProcessor.java:167)\n\tat io.crnk.core.engine.internal.http.JsonApiRequestProcessor.processAsync(JsonApiRequestProcessor.java:131)\n\tat io.crnk.core.engine.internal.http.HttpRequestDispatcherImpl.process(HttpRequestDispatcherImpl.java:73)\n\tat io.crnk.rs.CrnkFilter.filter(CrnkFilter.java:55)\n\tat

I tried using some annotations like @JsonIgnoreProperties . but still this error is coming. how can I fix this?

I have also tried "crnkBoot.setAllowUnknownAttributes();"
Remo
@remmeier
Hi @nature32 why are you sending an attribute that does not exist? What version have you been running before? Because I'm kind of suprised for it to have worked in the past. setAllowUnknownAttributes as of yet only handles url parameter, not as of yet in the body.
but naming is not quite clear in that regard, as it would imply to ignore it everywhere
nature32
@nature32
@remmeier we were using 3.0.20190714142556. now I have updated it to 3.2.20200419165537. is there any way to fix for this scenario?
Remo
@remmeier
how many times to do you have that pattern? is it desired or can the client be fixed? the flag could be extended to also ignore the attributes in the body. Or a DocumentFilter might be able to remove it in advancet.
8 replies
Percy Hatcherson
@primitive-type
How can I do a bulk DELETE request after overriding the delete method in the BulkResourceRepository like:
@Override
public void delete(List<Integer> list) {
    for (Integer i : list) {
        super.delete(i);
    }
}
what should my DELETE request body look like? do I need to do something special in the query parameters?
Tikaro
@0-Tikaro
Hey mates, I was wondering if anybody was solving a problem of single-resource endpoints? Something like a "singleton" resource which exists as a single instance. This could, for example, be a /version endpoint which serves information about the server's version. The problem is, Crnk inherently works with collections and as far as I see there isn't a way to create an endpoint which links directly to a single resource.
Tikaro
@0-Tikaro
Of course there are routes of implementing this through Spring's controllers or filters and manually constructing a response which adheres to json:api, but that's more effortful to maintain and fragile in the future.
Remo
@remmeier
@primitive-type both comma seperation in the url like tasks/1,2 or in the body following JSON:API convetions should work. CrnkClient uses:
final ObjectMapper objectMapper = client.getObjectMapper();
        Document document = new Document();
        ArrayList<ResourceIdentifier> resourceIdentifiers = new ArrayList<>();
        for (Object id : ids) {
            resourceIdentifiers.add(resourceInformation.toResourceIdentifier(id));
        }
        document.setData(Nullable.of(resourceIdentifiers));
        Document transportDocument = client.getFormat().toTransportDocument(document);
        String requestBodyValue = ExceptionUtil.wrapCatchedExceptions(new Callable<String>() {
            @Override
            public String call() throws Exception {
                return objectMapper.writeValueAsString(transportDocument);
            }
        });
        executeDelete(url, requestBodyValue);

@0-Tikaro one of the most common use cases is getting the current uses. I create a repository returning a single element, like /whoami/me where me is the current version. There is a bid of a trade-off between having it a truely singleton and adhering to the json:api specification. I prefer the later for the sake of consistency. Another angle could be to question whether a singleton is really a good idea. More often than not, one may end-up with more than one of those some time in the future...

But it would be perfectly possible to using the crnk serialization things like the Document class and DocumentMapper/ResourceMapper to create that singleton e ndpoint.

Alexander Matthiesen
@alexander-matthiesen
Hey @remmeier , is there a way to serialize a string (JSON:API) to a crnk resource without using the client or something like that?
Remo
@remmeier
what you would do is to first map the string to the crnk Document object. You can use Jackson for that. Like CrnkBoot.getObjectMapper(). But it may work with any kind of ObjectMapper instance (not 100% sure). That you can feed into the DocumentMapper/ResourceMapper. Also available from CrnkBoot, it will translate the generic Document class into concrete objects.
Alexander Matthiesen
@alexander-matthiesen
What would the call in the documentMapper look like? I managed it to convert my string to a document, but I'm missing the conversion to my actual resource class. If it is important, I'm receiving a list of resources and not only a resource but that may be manageable over a type reference.
Do you have any code examples or method names for me?
Remo
@remmeier
oh, I'm sorry. My answer was not entirely correct. Just now there is also a ClientDocumentMapper. It offers a public Object fromDocument(Document document, boolean getList, QueryContext queryContext) { method to do what you are looking for. The class sits next to CrnkClient. But actually it would be worthwhile to merge that functionality with DocumentMapper to have the implementation at both ways in same location.
the class is used by ClientStubBase.execute, so it should be a good example. If you think it is worthwile, we could merge to implementation to have it available in crnk-core. Might not be too hard to do.
Alexander Matthiesen
@alexander-matthiesen
Thanks for the heads up! Would be nice to have that in DocumentMapper. :)
Alexander Matthiesen
@alexander-matthiesen
Unfortunately the ProxyFactory in the DocumentMapper is null and I don't have a client context.
This is my example code:
val document: Document = crnkBoot.objectMapper.readValue(content, Document::class.java)
val mapper = ClientDocumentMapper(crnkBoot.moduleRegistry, crnkBoot.objectMapper, crnkBoot.propertiesProvider)
val tests = mapper.fromDocument(document, true) as List<TestDocument>
Remo
@remmeier
seems that the is a setProxyFactory method which passes along, e.g. BasicProxyFactory. You can open up a ticket. In case you have time to move it, feel free. Otherwise I should have time the coming days.
1 reply
nature32
@nature32
@remmeier As I mentioned earlier, we get InternalServerError (caused by IllegalArgumentException) when we provide String value for UUID (id) to path param. (findOne method/patch api). for other exceptions I have written exception mapper classes and I have changed it to 400. it worked. but for this exception I am not able to do anything since its not coming to exception mappers(java.lang.exception) . Is there any way to fix this ? (crnk-project/crnk-framework#753)
Steve Brush
@brushs
does CRNK support transactions spanning multiple requests?
Remo
@remmeier
@nature32 yes should be fixed for sure. if somebody has time for a PR, that is welcome. Otherwise I will start to have a bit more time towards the end of the week for the coming weeks. Has been a few busy months :-(
2 replies
@brushs depends on what you intend to do. In general I would try to avoid this kind of things as things become rather complicated with the services stop being state-less. There is one exception tough: http://www.crnk.io/releases/stable/documentation/#_bulk_updates_with_operations_module to send multiple changes in a single request. Are you looking for that?
3 replies
Arun Bitla
@abitla
Is there a way to maintain or set order of attributes in a resource? Product Owner wants response attributes in rest api to have a specific order.
Atreyu79
@Atreyu79
@abitla Did your product owner give you a reason? If not, he should. I can't think of a good reason an API would need this, as you expose yourself to backwards compatibility issues. If the need is to have something presented in a particular order you might consider a single collection attribute, with the collection elements sorted in the order you wish. I'd document the details of the sorting and probably name the attribute something descriptive, like maintenanceYearsDesc, for example. That way the API is self documenting and it's clear what to expect of that attribute.
Goran Jovicic
@goran.jovicic_gitlab
How do you guys handle OPTIONS requests with Spring Security+CRNK? My options requests just come to CrnkFilter and CrnkFilter throws "JsonApiRequestProcessor : method not allowed: OPTIONS". Do I need to add some filter or interceptor before CrnkFilter to handle OPTIONS request or to modify CRNK somehow?