Javers and anonymization - javers

We are using javers and using some private datas. We must store the changes (for our business needs) on these datas (that's why we do not exclude them).
We have to be able to make these datas anonym.
Is there a way to anonymize the datas stored in javers ?
Thanks.

Related

Is it recommended to insert data into a database through a DTO or DTO is supposed to be read data from the Database only?

I am confused as to the actual usage of a DTO, and my confusion arises from the fact that most articles say that DTOs are to be used to read data from database and pass it to external clients and then these external clients will then choose to do what they want with it. So I want to know if it is recommended or not to insert Data into the database through DTOs.
I have created a dto that maps to the entity and also then created repository class that has the methods for saving data into the database through the dto, I then created my dtocontroller where I then implemented the actual saving and I was able to save the data into the database.
So my question is: Is it recommended to insert data into a database through a DTO or DTO is supposed to be read data from the Database only?
DTOs are for passing data around, usually as a REST call payload or response (Controller). Also for passing/returning to Service methods.
Entities are for persisting to the DB within a Repository.
Normally a Service calls the DTO/Entity mapping around calls a Repository, which only deals in Entities.
This answer probably explains better.

How to fetch the data from database using spring boot without mapping

I have a database and in that database there are many tables of data. I want to fetch the data from any one of those tables by entering a query from the front-end application. I'm not doing any manipulation to the data, doing just retrieving the data from database.
Also, mapping the data requires writing so many entity or POJO classes, so I don't want to map the data to any object. How can I achieve this?
In this case, assuming the mapping of tables if not relevant, you don't need to use JPA/Hibernate at all.
You can use an old, battle tested jdbc template that can execute a query of your choice (that you'll pass from client), will serialize the response to JSONObject and return it as a response in your controller.
The client side will be responsible to rendering the result.
You might also query the database metadata to obtain the information about column names, types, etc. so that the client side will also get this information and will be able to show the results in a more convenient / "advanced" way.
Beware of security implications, though. Basically it means that the client will be able to delete all the records from the database by a simple query and you won't be able to avoid it :)

Embeded H2 Database for dynamic files

In our application, we need to load large CSV files and fetch some data out of it. For example, getting the distinct values from the CSV file. For this, we decided to go with in-memory DB's like H2, as there is no need to store the data in persistent storage.
However, the file is so dynamic that the columns may not be the same. I need to load the file to the H2 database to a table that is temporary for that session.
Tech Stack is Spring boot and H2.
The examples I see on forums is using a standard entity that knows what fields the table has. However my case the table columns will be dynamic
I tried the below in spring boot
public interface ImportCSVRepository extends JpaRepository<Object, String>
with
#Query(value = "CREATE TABLE TEST AS SELECT * FROM CSVREAD('test.csv');", nativeQuery = true)
But this gives unmanaged entity error. I understand why the error is thrown. However I am not sure how to achieve this. Also please clarify if I should use Spring-batch ?
You can use JdbcTemplate to manually create tables and query/update the data in them.
An example of how to create a table with JdbcTemplate
Dynamically creating tables and defining new entities (or modifying existing ones) is hardly possible with spring-data repositories and #Entity-ies. You probably should also check some NoSQL dbs like MongoDb - it's easier to define documents (or key-value objects - Redis) with dynamic structures in them.

Is there a way to ignore only one field (BLOB) from a entity object during fetch using SPRING JPA Repo

While using Spring JPA and trying to fetch an entity from the DB which contains a blob, it takes a long time to load if the result set is large.
Is there a way I can ignore just only one attribute of the entity, i.e the blob while fetching the data using SPRING JPA? For example, repo.findAll() or
Example<EnityVO> siloQueryExample= Example.of(entityVO);
List<EnityVO> queryResult = imageSiloRepo.findAll(siloQueryExample,sort);
You can anotate your blob column with
#Basic(fetch=FetchType.LAZY)
This way your column is marked to be lazy loaded, which means your blob will only be fetched upon explicitly calling it with getter.
You could use projection to fetch only required columns. Here are some tutorials:
Spring Data JPA Projections
Why, When and How to Use DTO Projections with JPA and Hibernate
Another solution is to map multiple JPA entities to one database table - one with all columns and another without the blob one. Here is another tutorial:
How to Map Multiple Entities to the Same Table

How should I define non-entity repositories with Spring Data MongoDB?

On my domain I have the usual entities (User, Company, etc) and also "entities" that doesn't change, I mean they are fixed values but stored on data base. My backend is Mongo so I make use of MongoRepository. I'm also using Spring Data Rest.
Let's say I have defined Sector as entity, which is nothing more than a String wrapped on a Java object.
So this is how I define the repository.
#RepositoryRestResource
public interface SectorRepo extends MongoRepository<Sector,String>{
}
The thing is that this seems to be inappropriate, as I should not define an object that only wraps an string and treat it as an entity, it isn't. The only purpose for Sector collection is to be loaded on a combo box, nothing more.
The problem gets serious when you have more and more of these non-entities objects.
How I should approach this situation so I can still use MongoRepository + Spring Data Rest?
This is similar to couple of other questions. Please see my answers for both. Hope it helps
Spring Data MongoDB eliminate POJO's
Storing a JSON schema in mongodb with spring

Resources