I followed this document for implementing Auditing in spring boot.
(https://www.baeldung.com/database-auditing-jpa)
Auditing is working fine but when the object is of type list means we are persisting as multiple entries in db.
I am passing this request object for rest API :-
`
[
{
"name": "reddy"
},
{
"name": "mani"
}
]
`
for each object we are getting one audit log in db.
Is there any way to achieve as single entry in database?
Related
I am working on microservice architecture and I want to aggregate data from two microservices.
For example, Frontend calls the API Gateway and API Gateway calls two microservices Customer and Order microservices. Customer microservice returns customer details and Order microservice returns all ordered products by customer.
This is the format returned by API Gateway after aggregation from two microservice using Ocelot or Azure API Management.
Format 1
{
"Customers":[
{
"customerId":1001,
"customerName":"Tom"
},
{
"customerId":1002,
"customerName":"Jerry"
}
],
"Orders":[
{
"CustomerId":1001,
"Orders":[
{
"ProductId":"PRO1",
"ProductName":"Books"
},
{
"ProductId":"PRO2",
"ProductName":"Pens"
}
]
},
{
"CustomerId":1002,
"Orders":[
{
"ProductId":"PRO3",
"ProductName":"Pencils"
},
{
"ProductId":"PRO4",
"ProductName":"Toys"
}
]
}
]
}
The Format that I want is format 2.
Format 2
{
"OrderDetails":[
{
"customerId":1001,
"customerName":"Tom",
"Orders":[
{
"ProductId":"PRO1",
"ProductName":"Books"
},
{
"ProductId":"PRO2",
"ProductName":"Pens"
}
]
},
{
"customerId":1002,
"customerName":"Jerry",
"Orders":[
{
"ProductId":"PRO3",
"ProductName":"Pencils"
},
{
"ProductId":"PRO4",
"ProductName":"Toys"
}
]
}
]
}
The second format is achievable using Ocelot but the merging of data is based on the ids on Gateway and it requires some processing.
Is it a good practice to aggregate data on Gateway using business logic. If not what practices should be followed for this kind of aggregation?
It would be nice if you can provide some references for achieving this aggregation using the Azure API Management.
This is known as API composition or Backend for Frontend. I would say it is fine to aggregate data using the API Gateway because it allows your API clients to use a simpler API interface. The actual mapping would be done in the API Gateway.
However, when you chain multiple microservices together in one Web API, the failure of one service will cause the entire Web API to fail. An alternative (and more complex) solution is to create a dedicated microservice that aggregates the datasets from the other microservices and expose a single API that shows the joined data. See - CQRS pattern.
A reference for how you might implement this in Azure is API Aggregation Using Azure API Management.
I am writing a JaxRS resource in quarkus with panache and I have noticed that I couldn't get a PUT/PATCH request to work. More specifically I can't seem to update a previously persisted entity in the database. I figured I was doing something wrong, but then I tried the the quarkus-quickstart for panache which can be found here, and I noticed that the PUT doesn't work there either.
What it does is that it gets an entity using the findById method, changes that entity, and then just returns that changed entity. But it doesn't actually change it in the database. For the quickstart I set up the database using docker as it suggests in the README.
What is the recommended way for updating an already persisted Panache entity?
Example Request Flow
These are the requests and responses I got with the quarkus quickstart:
GET localhost:8080/fruits.
Response:[ {"persistent": true, "id": 1, "name": "Cherry"} ]
PUT localhost:8080/fruits/1, body: { "name": "edited name" }
Response: { "persistent": false, "id": 1, "name": "edited name" }
GET localhost:8080/fruits
Response:[ {"persistent": true, "id": 1, "name": "Cherry"} ]
We can close this question with "I confirm that it is a bug in 0.12.0. It's fixed in master and the upcoming 0.13.0 fixes it. " from comment.
Is there any documentation which provides description of all the elements in Spring Cloud Config Server's response
{
"name":"myapp",
"profiles":[
"default"
],
"label":null,
"version":null,
"state":null,
"propertySources":[
{
"name":"vault:myapp",
"source":{
"foo":"myappsbar"
}
},
{
"name":"vault:application",
"source":{
"baz":"bam",
"foo":"bar"
}
}
]
}
Based on source code it's:
Simple plain text serializable encapsulation of a list of property sources. Basically a DTO for {#link org.springframework.core.env.Environment}, but also applicable outside the domain of a Spring application.
See: https://github.com/spring-cloud/spring-cloud-config/blob/master/spring-cloud-config-client/src/main/java/org/springframework/cloud/config/environment/Environment.java
and
https://github.com/spring-cloud/spring-cloud-config/blob/master/spring-cloud-config-client/src/main/java/org/springframework/cloud/config/environment/PropertySource.java
Please refer https://cloud.spring.io/spring-cloud-config/multi/multi__spring_cloud_config_server.html#vault-backend It has a response object which is the same as your question and the documentation can help you understand each and every parameter in that object.
I need to support a MongoDB database originally created by a parse.com installation.
I'm using Spring Boot and Spring Data. The problem is that parse.com and Spring Data have different implementations of DB references:
parse.com
_p_meal_ : { Meal$eh0662S2wn }
_p_FIELD_ : { <REF_CLASS>$<REF_ID> } // generically
Spring Data follows the recommendation
meal: { "$ref" : "meals", "$id" : ObjectId("5126bc054aed4daf9e2ab772"), "$db" : "maindb" }
FIELD: { "$ref": REF_CLASS, "$id": ID, "$db": DATABASE } // generically
I want to configure Spring Data so it knows how to read&write DB references the same way as parse.com.
I suspect it has to do with providing a custom DbRefResolver to MongoTemplate but I'm not sure.
Thanks
Is there a way to perform a REST call to ServiceNow REST API that returns a single column of a table? I would like to query the server table for only the names of the servers and not have the entire record containing some 50 plus fields returned.
The latest REST Table API (as of Eureka, I think) supports the parameter sysparm_fields, which allows you to specify a comma-delimited list of fields to include in the response:
This URL template:
https://YOURINSTANCENAME.service-now.com/api/now/v1/table/incident?sysparm_fields=number,short_description,caller_id.name
Would give you a result with something like:
{
"result": [
{
"caller_id.name": "",
"short_description": "Unable to get to network file shares",
"number": "INC0000002"
}
]
}