use of eu.bcvsolutions.idm.core.api.domain.Auditable in project CzechIdMng by bcvsolutions.
the class AuditableListener method onPreInsert.
@Override
public boolean onPreInsert(PreInsertEvent event) {
if (event.getEntity() instanceof Auditable) {
DateTime date = new DateTime();
Auditable entity = (Auditable) event.getEntity();
//
setValue(event.getState(), event, Auditable.PROPERTY_CREATED, date);
entity.setCreated(date);
//
AbstractAuthentication authentication = securityService.getAuthentication();
IdmIdentityDto currentIdentity = authentication == null ? null : authentication.getCurrentIdentity();
IdmIdentityDto originalIdentity = authentication == null ? null : authentication.getOriginalIdentity();
if (entity.getCreator() == null) {
String creator = currentIdentity == null ? securityService.getUsername() : currentIdentity.getUsername();
setValue(event.getState(), event, Auditable.PROPERTY_CREATOR, creator);
entity.setCreator(creator);
//
UUID creatorId = currentIdentity == null ? null : currentIdentity.getId();
setValue(event.getState(), event, Auditable.PROPERTY_CREATOR_ID, creatorId);
entity.setCreatorId(creatorId);
}
// could be filled in wf (applicant) ...
if (entity.getOriginalCreator() == null) {
String originalCreator = originalIdentity == null ? null : originalIdentity.getUsername();
setValue(event.getState(), event, Auditable.PROPERTY_ORIGINAL_CREATOR, originalCreator);
entity.setOriginalCreator(originalCreator);
//
UUID originalCreatorId = originalIdentity == null ? null : originalIdentity.getId();
setValue(event.getState(), event, Auditable.PROPERTY_ORIGINAL_CREATOR_ID, originalCreatorId);
entity.setOriginalCreatorId(originalCreatorId);
}
}
return false;
}
use of eu.bcvsolutions.idm.core.api.domain.Auditable in project CzechIdMng by bcvsolutions.
the class AuditableListener method onPreUpdate.
@Override
public boolean onPreUpdate(PreUpdateEvent event) {
if (event.getEntity() instanceof Auditable) {
DateTime date = new DateTime();
Auditable entity = (Auditable) event.getEntity();
//
setValue(event.getState(), event, Auditable.PROPERTY_MODIFIED, date);
entity.setModified(date);
//
AbstractAuthentication authentication = securityService.getAuthentication();
//
IdmIdentityDto currentIdentity = authentication == null ? null : authentication.getCurrentIdentity();
IdmIdentityDto originalIdentity = authentication == null ? null : authentication.getOriginalIdentity();
//
String modifier = currentIdentity == null ? securityService.getUsername() : currentIdentity.getUsername();
setValue(event.getState(), event, Auditable.PROPERTY_MODIFIER, modifier);
entity.setModifier(modifier);
//
UUID modifierId = currentIdentity == null ? null : currentIdentity.getId();
setValue(event.getState(), event, Auditable.PROPERTY_MODIFIER_ID, modifierId);
entity.setModifierId(modifierId);
// could be filled in wf (applicant) ...
if (entity.getOriginalModifier() == null) {
String originalModifier = originalIdentity == null ? null : originalIdentity.getUsername();
setValue(event.getState(), event, Auditable.PROPERTY_ORIGINAL_MODIFIER, originalModifier);
entity.setOriginalModifier(originalModifier);
//
UUID originalModifierId = originalIdentity == null ? null : originalIdentity.getId();
setValue(event.getState(), event, Auditable.PROPERTY_ORIGINAL_MODIFIER_ID, originalModifierId);
entity.setOriginalModifierId(originalModifierId);
}
}
return false;
}
use of eu.bcvsolutions.idm.core.api.domain.Auditable in project CzechIdMng by bcvsolutions.
the class AuditableEntityListener method touchForUpdate.
/**
* Sets modification date and modifier on the target object in case it implements {@link Auditable} on
* update events.
*
* @param target
*/
@PreUpdate
public void touchForUpdate(Object target) {
if (!(target instanceof Auditable)) {
return;
}
//
AutowireHelper.autowire(this, this.securityService);
//
ZonedDateTime date = ZonedDateTime.now();
Auditable entity = (Auditable) target;
//
entity.setModified(date);
//
AbstractAuthentication authentication = securityService.getAuthentication();
//
IdmIdentityDto currentIdentity = authentication == null ? null : authentication.getCurrentIdentity();
IdmIdentityDto originalIdentity = authentication == null ? null : authentication.getOriginalIdentity();
//
String modifier = currentIdentity == null ? securityService.getUsername() : currentIdentity.getUsername();
entity.setModifier(modifier);
//
UUID modifierId = currentIdentity == null ? null : currentIdentity.getId();
entity.setModifierId(modifierId);
//
String originalModifier = originalIdentity == null ? null : originalIdentity.getUsername();
entity.setOriginalModifier(originalModifier);
UUID originalModifierId = originalIdentity == null ? null : originalIdentity.getId();
entity.setOriginalModifierId(originalModifierId);
//
// set transaction id from context holder
entity.setTransactionId(TransactionContextHolder.getContext().getTransactionId());
}
use of eu.bcvsolutions.idm.core.api.domain.Auditable in project CzechIdMng by bcvsolutions.
the class AuditableEntityListener method touchForCreate.
/**
* Sets creation date and creator on the target object in case it implements {@link Auditable} on
* persist events.
*
* @param target
*/
@PrePersist
public void touchForCreate(Object target) {
if (!(target instanceof Auditable)) {
return;
}
//
AutowireHelper.autowire(this, this.securityService);
//
ZonedDateTime date = ZonedDateTime.now();
Auditable entity = (Auditable) target;
// set created date - can be preset (e.g. preserve created date of original operation moved some where info archive)
if (entity.getCreated() == null) {
entity.setCreated(date);
}
//
AbstractAuthentication authentication = securityService.getAuthentication();
IdmIdentityDto currentIdentity = authentication == null ? null : authentication.getCurrentIdentity();
IdmIdentityDto originalIdentity = authentication == null ? null : authentication.getOriginalIdentity();
if (entity.getCreator() == null) {
String creator = currentIdentity == null ? securityService.getUsername() : currentIdentity.getUsername();
entity.setCreator(creator);
//
UUID creatorId = currentIdentity == null ? null : currentIdentity.getId();
entity.setCreatorId(creatorId);
}
// could be filled in wf (applicant) ...
if (entity.getOriginalCreator() == null) {
String originalCreator = originalIdentity == null ? null : originalIdentity.getUsername();
entity.setOriginalCreator(originalCreator);
//
UUID originalCreatorId = originalIdentity == null ? null : originalIdentity.getId();
entity.setOriginalCreatorId(originalCreatorId);
}
// set transaction id from context holder
entity.setTransactionId(TransactionContextHolder.getContext().getTransactionId());
}
Aggregations