Enable sub resource levels spring data rest? - spring

I have an entity called Document and inside that I have a list of dispatchDetails. I have only created a repository for documents.When I make a GET request for a document by documentID, I get below result
{
"docType": "SAP_ACCOUNTS_PAYABLE",
"docStoreId": 456651,
"qualityChecked": true,
"format": "pdf",
"bookingId": -1,
"dispatchDetails": [
{
"dispatchQueId": 207443,
"dispatchStatus": "S",
"recipient": "fldcvisla12678.wdw.disney.com|#|/opt/apps/shared/shuttle/SAP/OUT/|#|f-tbxshuttlenp|#|D1$NeY984|#|SFTP|#|22|#|null",
"description": "Upload :FileUploadDispatcher; FTP:null/null;\n2d89df3d-ca51-4d35-9528-439923fa48d4..",
"dispatcher": "AD",
"_links": {
"generatedDocument": {
"href": "http://localhost:7070/booking-documents-service/docs/5999571"
}
}
}
],
"_links": {
"self": {
"href": "http://localhost:7070/booking-documents-service/docs/5999571"
},
"generatedDocument": {
"href": "http://localhost:7070/booking-documents-service/docs/5999571"
}
}
}
In dispatchDetails, I can't see a link for self. i.e. actions on sub resource level is not activated. Is there any way to generate that and enable sub resource level calls by adding anything to the existing repository without creating a separate repository for dispatchDetails? or with 2 repositories?
Simply what I want is to see both hateoas link and attributes loading inline.

Set dispatchDetails fetch policy for LAZY.

Related

FHIR - Contained Resources and Referencing

I am still new to FHIR and trying to connect the dots.
If I have a resource that I want to contain other resources, can I refer to it by element name (#myElementName) or do I need to use the contained resource id? (#myDeviceId).
I've included sample code below. What I would like to accomplish is to have a Basic resource that has two extensions: TestConfiguration(Device) and DigitalSample(ImagingStudy). I would like for both of these resources to be contained.
PS: I generated the code below using custom classes and the .net API.
Thank you much!
{
"resourceType": "TestInput",
"contained": [
{
"resourceType": "TestConfiguration",
"id": "TestConfigurationId",
"contained": [
{
"resourceType": "DeviceDefinition",
"modelNumber": "ABC123"
}
],
"definition": {
"reference": "#definition"
}
},
{
"resourceType": "DigitalSample",
"id": "DigitalSampleId"
}
],
"extension": [
{
"url": "http://MyOrganization.com/fhir/R4/StructureDefinition/Basic-TestConfiguration",
"valueReference": {
"reference": "#testConfiguration"
}
},
{
"url": "http://MyOrganization.com/fhir/R4/StructureDefinition/Basic-DigitalSample",
"valueReference": {
"reference": "#digitalSampleId"
}
}
]
}
Every local reference must point to an id of a contained resource.
In your case it should be:
"reference": "#TestConfigurationId"
"reference":"#DigitalSampleId"
Always check https://www.hl7.org/fhir/ for what you need to do. Always check the FHIR version

Microsoft Flow fails when trigger event is Create a File on OneDrive for Business

I am triggering a flow when a new file is added to a folder (/Flows/InvoicesToXero/) in OneDrive for business.
However, it sees to think that the folder is a file and this causes issues:
{
"status": 400,
"message": "The file id '/Flows/InvoicesToXero/' is not valid.",
"source": "api.connectorp.svc.ms"
}
This is probably the simplest flow you could have:
Full error here:
This is the json for the trigger: (I have tried with and without a trailing slash)
{
"inputs": {
"host": {
"connection": {
"name": "#parameters('$connections')['shared_onedriveforbusiness']['connectionId']"
}
},
"method": "get",
"path": "/datasets/default/triggers/batch/onnewfile",
"queries": {
"folderId": "/Flows/InvoicesToXero",
"maxFileCount": 10
},
"authentication": "#parameters('$authentication')"
},
"recurrence": {
"interval": 5,
"frequency": "Minute"
},
"metadata": {
"b!caGb33cRrkC_foNq9zd0FIdP_xtQDcZEmqyeYyKvO6dYQu456-3vQaC_VKHi8b5w.014XBLOOWVAVAWSVA2QNELELS5LQI3SOJN": "/Flows/InvoicesToXero",
"flowSystemMetadata": {
"swaggerOperationId": "OnNewFiles"
}
},
"splitOn": "#triggerBody()"
}
How can I trigger a flow when a new file is added to OneDrive for Business in a subfolder?
You can try to create another connector also named "When a file is created (properties only)", please refer to this tutorial and the screenshot below:
According to the screenshot above, we can see there are two triggers named "When a file is created (properties only)" and the second include sub folders.
Hope it would be helpful to your problem~

Visit HATEOAS links of optional entities [duplicate]

This question already has an answer here:
Spring Data ReST ref link omission when null or empty
(1 answer)
Closed 5 years ago.
I developed a Spring Boot, Spring Data REST, Hibernate application that exposes REST endpoints.
A typical response is something like this:
{
"sid": "f6dddaaa-2713-4b92-844b-6f0d3cefad3f",
"createdBy": "admin",
"createdDate": "2018-01-30T15:56:38.417Z",
"lastModifiedDate": "2018-01-30T15:57:53.963Z",
"lastModifiedBy": "admin",
"status": "Annullato",
"number": "51",
"dailyCode": "VS",
"entryDate": "2018-01-30T15:56:00Z",
"exitDate": "2018-01-31T15:56:00Z",
"totalDays": 1,
"standard": true,
"minibus": false,
"schoolTrip": false,
"price": 400,
"fareRow": "Standard",
"fareColumn": "Euro 0 3",
"extSyncCode": null,
"payments": [],
"passengers": 44,
"agency": null,
"paperBlock": null,
"paperReceipt": null,
"payer": null,
"checkedMedia": false,
"checkedLicensePlate": false,
"_links": {
"self": {
"href": "http://localhost:8080/api/v1/tickets/1"
},
"ticket": {
"href": "http://localhost:8080/api/v1/tickets/1{?projection}",
"templated": true
},
"area": {
"href": "http://localhost:8080/api/v1/tickets/1/area"
},
"fareException": {
"href": "http://localhost:8080/api/v1/tickets/1/fareException"
},
"block": {
"href": "http://localhost:8080/api/v1/tickets/1/block"
},
"customer": {
"href": "http://localhost:8080/api/v1/tickets/1/customer"
},
"transitCertificate": {
"href": "http://localhost:8080/api/v1/tickets/1/transitCertificate"
},
"passengersCountry": {
"href": "http://localhost:8080/api/v1/tickets/1/passengersCountry"
},
"refund": {
"href": "http://localhost:8080/api/v1/tickets/1/refund"
},
"fine": {
"href": "http://localhost:8080/api/v1/tickets/1/fine"
},
"hotel": {
"href": "http://localhost:8080/api/v1/tickets/1/hotel"
},
"workShift": {
"href": "http://localhost:8080/api/v1/tickets/1/workShift"
}
}
}
As you can see this entity has a lot of links. These links represent bound entities. Unfortunately some of these entities are optional.
I created a Angular 5 application that consumes my server side API. When I want to display data (let's say the entity shown in the example) I need to get related entities and I've to visit all links. Because not all related entities are mandatories, some of these links return HTTP 404 and the browser display these calls as errors (see the picture).
Is my approach right? Should I visit all these links and consider the 404 response perfectly fine (I think so) even if the browser consided that as an error? Is there a better approach otherwise?
That’s a lot of work to discover a related entity doesn’t exist. HTTP requests are slow. Admittedly they will run in parallel but it still seems inefficient.
Instead, when you load the parent entity, can you check at that time which children entities will be valid? If the child will not be valid then, instead of a link, return null. Or don’t return the value at all.

How to add templated selfrel to Spring HATEOAS PagedResourcesAssembler?

I'm currently building an API using spring hateoas. Most of my controllers provide a list method which returns a PagedResources<>. For some reason the selfrel does not contain the {?page,size,sort} template which is found in all examples. Instead I only get the base URI.
So my e.g. my ProjectContoller looks like
#GetMapping
public PagedResources<ProjectResource> list(Pageable pageable, PagedResourcesAssembler<Project> pagedResourcesAssembler){
Page<Project> projects = service.findAll(pageable);
return pagedResourcesAssembler.toResource(projects, assembler);
}
and returns
{"_embedded":{
"projectResourceList":[
{
"begin":1462053600000,
"end":1469829600000,
"name":"Cool Big Project",
"_links":{"self":{"href":"http://localhost/projects/1"}}
}
]
},
"_links":{"self":{"href":"http://localhost/projects"}},
"page":{
"size":20,
"totalElements":1,
"totalPages":1,
"number":0
}
}
I guess I'm missing something trivial but can't find out what :-/
After reading how HAL should behave in Spring Data Rest it seems there could be some bug.
This is the standard Spring Data Rest links output for a tasks collection resource:
"_links": {
"first": {
"href": "http://localhost:8080/tasks?page=0&size=20"
},
"self": {
"href": "http://localhost:8080/tasks"
},
"next": {
"href": "http://localhost:8080/tasks?page=1&size=20"
},
"last": {
"href": "http://localhost:8080/tasks?page=2&size=20"
},
"profile": {
"href": "http://localhost:8080/profile/tasks"
},
"search": {
"href": "http://localhost:8080/tasks/search"
}
No link is being templated in out of the box HAL responses rendered by Spring Data Rest, contrary to what is shown in docs.
If I follow next link, the self link is not correct:
"_links": {
"first": {
"href": "http://localhost:8080/tasks?page=0&size=20"
},
"prev": {
"href": "http://localhost:8080/tasks?page=0&size=20"
},
"self": {
"href": "http://localhost:8080/tasks"
},
"next": {
"href": "http://localhost:8080/tasks?page=2&size=20"
},
"last": {
"href": "http://localhost:8080/tasks?page=2&size=20"
},
"profile": {
"href": "http://localhost:8080/profile/tasks"
},
"search": {
"href": "http://localhost:8080/tasks/search"
}
}
If I override the Controller:
#RequestMapping(method = RequestMethod.GET, path = "/tasks")
public ResponseEntity<Page<Task>> read(Pageable pageRequest, PersistentEntityResourceAssembler assembler) {
Page<Task> pendingTasks = taskService.read(pageRequest);
return new ResponseEntity(pageAssembler.toResource(pendingTasks, (ResourceAssembler) assembler),
HttpStatus.OK);
}
And add a service between the controller and repository that initializes a Pageable instance to default values even if none is specified:
public Page<Task> read(Pageable pageRequest) {
Pageable effectivePageRequest = pageRequest;
if (effectivePageRequest == null) {
effectivePageRequest = new PageRequest(0, 20, DEFAULT_SORT);
}
if (effectivePageRequest.getSort() == null) {
//override Sort
effectivePageRequest = new PageRequest(effectivePageRequest.getPageNumber(),
effectivePageRequest.getPageSize(), DEFAULT_SORT);
}
return taskRepository.findByStatus(Task.Status.PENDING, effectivePageRequest);
}
I can overcome the problem with the self link. But have seen no way of generating the templlated URIs. These are the links for the second page:
"_links": {
"first": {
"href": "http://localhost:8080/tasks?page=0&size=20&sort=created,desc"
},
"prev": {
"href": "http://localhost:8080/tasks?page=0&size=20&sort=created,desc"
},
"self": {
"href": "http://localhost:8080/tasks?page=1&size=20&sort=created,desc"
},
"next": {
"href": "http://localhost:8080/tasks?page=2&size=20&sort=created,desc"
},
"last": {
"href": "http://localhost:8080/tasks?page=2&size=20&sort=created,desc"
}
Hope this helps discarding possibilities, but default behavior shown here suggests that there may be some problem with Spring HATEOAS/Spring Data Rest when generating collection links.
I'm using org.springframework.boot:spring-boot-starter-data-rest:jar:1.4.0.RELEASE, org.springframework.data:spring-data-rest-webmvc:jar:2.5.2.RELEASE, org.springframework.hateoas:spring-hateoas:jar:0.20.0.RELEASE

Dojox/app keeping models synchronized with store

I am currently using dojox/app to create a SPA, and I am starting now to add stores and models. I have been able to create a store from a json object, to create a model from the store, and to bind fields to the model using dojox mvc. However, I have something that I have not yet been able to do: update a 2nd model that is binded to the same store as the 1st one.
I will give an example. I have this store:
win.global.modelApp = {};
modelApp.names = {
identifier: "id",
items: [{
"id": 1,
"First": "John",
"Last": "Doe",
},{
"id": 2,
"First": "John2",
"Last": "Doe",
}]
}
and then I create two models using this store in the config.json file:
"stores": {
"namesStore":{
"type": "dojo/store/Memory",
"params": {
"data": "modelApp.names"
}
}
},
"models": {
"namesXUnused": {
"modelLoader": "dojox/app/utils/mvcModel",
"type": "dojox/mvc/EditStoreRefListController",
"params":{
"store": {"$ref":"#stores.namesStore"}
}
},
"namesXUnused2": {
"modelLoader": "dojox/app/utils/mvcModel",
"type": "dojox/mvc/EditStoreRefListController",
"params":{
"store": {"$ref":"#stores.namesStore"}
}
}
}
Then, in my HTML file, I have a field binded to namesXUnused (property First), and another binded to namesXUnused2 (property First). When I edit the first field, I then have a button that commits these changes to the store. I can see via debugger that the store data has been correctly updated. However, I cannot get the second field to reflect the changes. Is there a way to refresh or recreate the model from the store?
Thank you,
I think you need to set "observable": true, on the store to use an Observable store since you want to have updates to the store be reflected back to the models. There are examples in the dojox/app/tests (and the dojox/mvc/tests) if you have problems, but just adding:
"observable": true, to your namesStore should do it.
"stores": {
"namesStore":{
"type": "dojo/store/Memory",
"observable": true,
"params": {
"data": "modelApp.names"
}
}
},
Regards,
Ed

Resources