Javers demo project broken? - javers

I just started evaluating Javers and downloaded the organization-structure demo provided on the Javers homepage. The organization-structure-sql project does not seem to correct identify changes.
git clone https://github.com/javers/organization-structure.git
Imported project into Intellij
An SqlApplication as Spring Boot project
The project starts up several rest endpoints to make updates to an H2 database and to test the Javers API with those changes
a) localhost:8080/view/person/0
{
"id": 0,
"firstName": "Frodo",
"lastName": "Baggins",
"sex": "MALE",
"salary": 9000,
"position": "DEVELOPER"
}
b) localhost:8080/audit/test
makes changes to Person/0 above
c) localhost:8080/view/person/0
shows the audit/test endpoint updated salary from 9000->1234:
{
"id": 0,
"firstName": "Frodo",
"lastName": "Baggins",
"sex": "MALE",
"salary": 1234,
"position": "DEVELOPER"
}
d) localhost:8080/audit/person/0
[]
expected: output that would show the update made to person/0
Also, the PUT endpoint doesn't seem to work:
e) PUT localhost:8080/audit/person/0
{
"id": 0,
"firstName": "Frodo",
"lastName": "Baggins",
"sex": "MALE",
"salary": 10000,
"position": "DEVELOPER"
}
f) localhost:8080/view/person/0
{
"id": 0,
"firstName": "Frodo",
"lastName": "Baggins",
"sex": "MALE",
"salary": 1234,
"position": "DEVELOPER"
}
This simple demo not working doesn't inspire much confidence with using Javers.
Does anyone how to get this demo working?

I did some fixes and now it should work better, but please note that organization-structure is just a toy project and not a part of official Javers documentation.

Related

Apollo cache error on deleted "child" table

NOTE: the __typename Client below refers to a person (like a customer) - not client/server.
Getting the following error:
Cache data may be lost when replacing the clientServices field of a Client object.
To address this problem (which is not a bug in Apollo Client), define a custom merge function for the Client.clientServices field, so InMemoryCache can safely merge these objects:
existing: [{"__ref":"ClientService:46"}]
incoming: []
What's happening is that I've deleted a "child" record - so there's no data.
First time I get this returned. Note: there's info associated with field clientServices
{
"client": {
"id": "41",
"companyId": "3",
"firstName": "Lew",
"lastName": "Terry",
"email": "lewterry#diamond.com",
"clientServices": [
{
"id": "46",
"serviceId": "13",
"description": "Individual psychotherapy - 45 minutes",
"sessionFee": 90,
"cptCode": "90834",
"__typename": "ClientService"
}
],
"__typename": "Client"
}
}
And here's the results on a refetch after the client record is saved and the clientServices "child" data has been deleted so it's an empty array.
{
"client": {
"id": "41",
"companyId": "3",
"firstName": "Lew",
"lastName": "Terry",
"email": "lewterry#diamond.com",
clientServices: []
"__typename": "Client"
}
}
Do I really need a custom merge? Or is there another solution?

How to get data from ManyToOne Entity in Java Spring Boot with id decrease after update field

When I updated an entity in Spring with id, my entity always displayed at the last of list. How can I do format this to a list with id decrease. Below is my example after updating
"educations": [
{
"id": 17,
"name": "NEU",
"major": "QTKD",
"fromDate": "12/11/2019",
"toDate": "12/11/2023",
"description": "123456"
},
{
"id": 5,
"name": "PTIT",
"major": "IT",
"fromDate": "12/11/2019",
"toDate": "12/11/2023",
"description": "123456"
}
],

JMETER - response assertion -> Response was null

I have checked several options how to validate response and it still not works in my case.
As you can see (Debug sampler), for last_name regex works and I receive some values, but if I want to reuse this response as "Response assertion", test failed, because I receive "Response was null".
JSON Extractor for last_name
Response assertion
Test failed
Also, I would like to count objects in "data", so I used http://jsonpath.herokuapp.com/?path=$..book[0,1] to make sure, the JSON file is correct. But "Debug sampler" shows me nothing :( so test failed again
Count of objects
Result
Any idea how to solve this problem please ?
JSON:
{
"page": 2,
"per_page": 6,
"total": 12,
"total_pages": 2,
"data": [
{
"id": 7,
"email": "michael.lawson#reqres.in",
"first_name": "Michael",
"last_name": "Lawson",
"avatar": "https://reqres.in/img/faces/7-image.jpg"
},
{
"id": 8,
"email": "lindsay.ferguson#reqres.in",
"first_name": "Lindsay",
"last_name": "Ferguson",
"avatar": "https://reqres.in/img/faces/8-image.jpg"
},
{
"id": 9,
"email": "tobias.funke#reqres.in",
"first_name": "Tobias",
"last_name": "Funke",
"avatar": "https://reqres.in/img/faces/9-image.jpg"
},
{
"id": 10,
"email": "byron.fields#reqres.in",
"first_name": "Byron",
"last_name": "Fields",
"avatar": "https://reqres.in/img/faces/10-image.jpg"
},
{
"id": 11,
"email": "george.edwards#reqres.in",
"first_name": "George",
"last_name": "Edwards",
"avatar": "https://reqres.in/img/faces/11-image.jpg"
},
{
"id": 12,
"email": "rachel.howell#reqres.in",
"first_name": "Rachel",
"last_name": "Howell",
"avatar": "https://reqres.in/img/faces/12-image.jpg"
}
],
You need to tick Compute concatenation var in JSON Extractor, otherwise you will get 2 separate JMeter Variables:
lastName_1=Lawson
lastName_2=Ferguson
In addition to point 1 you need to use lastName_ALL in the Response Assertion
You need to switch from Matches to Substring in "Pattern Matching Rules" of the Response assertion
Demo:
More information: How to Use the JSON Extractor For Testing

Indexing In ElasticSearch For Auditing

There is a microservice-based architecture wherein each service has a different type of entity. For example:
Service-1:
{
"entity_type": "SKU",
"sku": "123",
"ext_sku": "201",
"store": "1",
"product": "abc",
"timestamp": 1564484862000
}
Service-2:
{
"entity_type": "PRODUCT",
"product": "abc",
"parent": "xyz",
"description": "curd",
"unit_of_measure": "gm",
"quantity": "200",
"timestamp": 1564484863000
}
Service-3:
{
"entity_type": "PRICE",
"meta": {
"store": "1",
"sku": "123"
},
"price": "200",
"currency": "INR",
"timestamp": 1564484962000
}
Service-4:
{
"entity_type": "INVENTORY",
"meta": {
"store": "1",
"sku": "123"
},
"in_stock": true,
"inventory": 10,
"timestamp": 1564484864000
}
I want to write an Audit Service backed by elasticsearch, which will ingest all these entities and it will index based on entity_type, store, sku, timestamp.
Will elasticsearch be a good choice here? Also, how will the indexing work? So, for example, if I search for store=1, it should return all the different entities that have store as 1. Secondly, will I be able to get all the entities between 2 timestamps?
Will ES and Kibana (to visualize) be good choices here?
Yes. Your use case is pretty much exactly what is described in the docs under filter context:
In filter context, a query clause answers the question “Does this
document match this query clause?” The answer is a simple Yes or
No — no scores are calculated. Filter context is mostly used for
filtering structured data, e.g.
Does this timestamp fall into the range 2015 to 2016?
Is the status field set to published?

Access control at property level (hiding/showing properties in api response based on the role)

I have a spring-boot based micro-service generated using JHipster.
I am using keycloak as my Auth Server. I could enable Role-based & scope based authorization on my resources(apis).
Now the requirement is: based on the role of the client, I need to restrict the information to send in the response (either mask the attributes or nullify them).
eg:
consider the following api to get the person's profile
/api/person/{id}
{
"name": {
"firstName": "Jack",
"lastName": "Sparrow"
},
"gender": "MALE",
"emails": {
"details": [
{
"emailId": "jack.sparrow#gmail.com"
}
]
},
"phones": {
"details": [
{
"phoneNumber": "1234567890",
"countryCode": "+1"
}
]
},
"addresses": {
"details": [
{
"addressLine1": "aaaaaaaa",
"addressLine2": "bbbbbbb",
"city": "cccccc",
"state": "ddddd",
"country": "South Africa",
"postalCode": "987654"
}
]
},
"photo": "string",
"nationality": "South Africa",
"countryOfResidence": "string",
"active": true,
"createdAt": 1537431339569,
"modifiedAt": 1537436600693,
"createdBy": "admin",
"modifiedBy": "admin"
}
Now, when a person with BASIC role calls this API, the requirement is to show only basic information like:
- name, gender
If he has INTERMEDIATE role then we can send something more than basic but not full information. eg: name, gender, photo, nationality
If he has ADMIN role then we can send the complete information.
Can anyone please let me know What is the best approach to achieve this.
-- Thanks in advance :)

Resources