All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.coodoo.framework.jpa.control.JpaRevisionService Maven / Gradle / Ivy

There is a newer version: 1.2.0
Show newest version
package io.coodoo.framework.jpa.control;

import java.time.LocalDateTime;
import java.time.ZoneId;

import javax.ejb.Stateless;
import javax.enterprise.inject.Instance;
import javax.inject.Inject;

import io.coodoo.framework.jpa.boundary.RevisionUser;
import io.coodoo.framework.jpa.boundary.entity.AbstractRevisionDatesEntity;
import io.coodoo.framework.jpa.boundary.entity.AbstractRevisionDeleteMarkerEntity;
import io.coodoo.framework.jpa.boundary.entity.AbstractRevisionEntity;

/**
 * Fills the entites revision attributes
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
EntityCreation DateCreation UserUpdate DateUpdate UserDelete DateDelete User
AbstractRevisionDatesEntityXX
AbstractRevisionDatesDeleteMarkerEntityXXX
AbstractRevisionEntityXXXX
AbstractRevisionDeleteMarkerEntityXXXXXX
* * * @author coodoo GmbH (coodoo.io) */ @Stateless public class JpaRevisionService { @Inject Instance revisionUserInstance; public void markCreation(AbstractRevisionDatesEntity entity) { entity.setCreatedAt(now()); if (entity instanceof AbstractRevisionEntity) { RevisionUser revisionUser = revisionUserInstance.get(); ((AbstractRevisionEntity) entity).setCreatedBy(revisionUser.getUserId()); } } public void markUpdate(AbstractRevisionDatesEntity entity) { if (entity instanceof AbstractRevisionDeleteMarkerEntity // triggered by a set deletion marker field && (((AbstractRevisionDeleteMarkerEntity) entity).getDeletedAt() != null || ((AbstractRevisionDeleteMarkerEntity) entity).getDeletedBy() != null)) { RevisionUser revisionUser = revisionUserInstance.get(); ((AbstractRevisionDeleteMarkerEntity) entity).setDeletedAt(now()); ((AbstractRevisionDeleteMarkerEntity) entity).setDeletedBy(revisionUser.getUserId()); } entity.setUpdatedAt(now()); if (entity instanceof AbstractRevisionEntity) { RevisionUser revisionUser = revisionUserInstance.get(); ((AbstractRevisionEntity) entity).setUpdatedBy(revisionUser.getUserId()); } } private LocalDateTime now() { return LocalDateTime.now(ZoneId.of("UTC")); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy