use of eu.bcvsolutions.idm.core.api.entity.AbstractEntity in project CzechIdMng by bcvsolutions.
the class IdmAuditListener method changeRevisionDto.
private void changeRevisionDto(Class<AbstractEntity> entityClass, String entityName, UUID entityId, IdmAuditDto revisionEntity, RevisionType revisionType) {
// List<String> changedColumns;
// name of entity class - full name.
revisionEntity.setType(entityName);
// revision type - MOD, DEL, ADD
revisionEntity.setModification(revisionType.name());
// action executer identity
AbstractAuthentication authentication = securityService.getAuthentication();
IdmIdentityDto currentModifierIdentity = authentication == null ? null : authentication.getCurrentIdentity();
IdmIdentityDto originalModifierIdentity = authentication == null ? null : authentication.getOriginalIdentity();
//
revisionEntity.setModifier(securityService.getUsername());
revisionEntity.setModifierId(currentModifierIdentity == null ? null : currentModifierIdentity.getId());
// original action executer identity (before switch)
revisionEntity.setOriginalModifier(securityService.getOriginalUsername());
revisionEntity.setOriginalModifierId(originalModifierIdentity == null ? null : originalModifierIdentity.getId());
// entity id
revisionEntity.setEntityId((UUID) entityId);
//
// get entity in new transaction if revision type is delete
AbstractEntity currentEntity = null;
if (revisionType == RevisionType.DEL) {
currentEntity = auditService.getActualRemovedEntity(entityClass, entityId);
} else {
currentEntity = (AbstractEntity) entityManger.find(entityClass, entityId);
}
//
if (currentEntity instanceof AuditSearchable) {
AuditSearchable searchableEntity = ((AuditSearchable) currentEntity);
revisionEntity.setOwnerCode(searchableEntity.getOwnerCode());
revisionEntity.setOwnerId(searchableEntity.getOwnerId());
revisionEntity.setOwnerType(searchableEntity.getOwnerType());
revisionEntity.setSubOwnerCode(searchableEntity.getSubOwnerCode());
revisionEntity.setSubOwnerId(searchableEntity.getSubOwnerId());
revisionEntity.setSubOwnerType(searchableEntity.getSubOwnerType());
} else if (currentEntity instanceof Codeable) {
revisionEntity.setOwnerCode(((Codeable) currentEntity).getCode());
}
}
use of eu.bcvsolutions.idm.core.api.entity.AbstractEntity in project CzechIdMng by bcvsolutions.
the class IdmAuditListener method entityChanged.
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public void entityChanged(Class entityClass, String entityName, Serializable entityId, RevisionType revisionType, Object revisionEntity) {
// autowire services
autowireServices();
IdmAudit auditEntity = (IdmAudit) revisionEntity;
if (auditEntity.getEntityId() != null) {
// child revision
IdmAuditDto childRevision = new IdmAuditDto();
childRevision.setChangedAttributes(auditEntity.getTemporaryChangedColumns());
childRevision.setTimestamp(((IdmAudit) revisionEntity).getTimestamp());
this.changeRevisionDto((Class<AbstractEntity>) entityClass, entityName, (UUID) entityId, childRevision, revisionType);
this.auditService.save(childRevision);
} else {
// parent revision
this.changeRevisionEntity((Class<AbstractEntity>) entityClass, entityName, (UUID) entityId, auditEntity, revisionType);
}
}
use of eu.bcvsolutions.idm.core.api.entity.AbstractEntity in project CzechIdMng by bcvsolutions.
the class IdmAuditListener method changeRevisionEntity.
private void changeRevisionEntity(Class<AbstractEntity> entityClass, String entityName, UUID entityId, IdmAudit revisionEntity, RevisionType revisionType) {
// name of entity class - full name.
revisionEntity.setType(entityName);
// revision type - MOD, DEL, ADD
revisionEntity.setModification(revisionType.name());
// action executer identity
AbstractAuthentication authentication = securityService.getAuthentication();
IdmIdentityDto currentIdentity = authentication == null ? null : authentication.getCurrentIdentity();
IdmIdentityDto originalIdentity = authentication == null ? null : authentication.getOriginalIdentity();
//
revisionEntity.setModifier(securityService.getUsername());
revisionEntity.setModifierId(currentIdentity == null ? null : currentIdentity.getId());
// original action executer identity (before switch)
revisionEntity.setOriginalModifier(securityService.getOriginalUsername());
revisionEntity.setOriginalModifierId(originalIdentity == null ? null : originalIdentity.getId());
// entity id
revisionEntity.setEntityId((UUID) entityId);
//
AbstractEntity currentEntity = null;
if (revisionType == RevisionType.DEL) {
currentEntity = auditService.getActualRemovedEntity(entityClass, entityId);
} else {
currentEntity = (AbstractEntity) entityManger.find(entityClass, entityId);
}
if (currentEntity instanceof AuditSearchable) {
AuditSearchable searchableEntity = ((AuditSearchable) currentEntity);
revisionEntity.setOwnerCode(searchableEntity.getOwnerCode());
revisionEntity.setOwnerId(searchableEntity.getOwnerId());
revisionEntity.setOwnerType(searchableEntity.getOwnerType());
revisionEntity.setSubOwnerCode(searchableEntity.getSubOwnerCode());
revisionEntity.setSubOwnerId(searchableEntity.getSubOwnerId());
revisionEntity.setSubOwnerType(searchableEntity.getSubOwnerType());
} else if (currentEntity instanceof Codeable) {
revisionEntity.setOwnerCode(((Codeable) currentEntity).getCode());
}
}
Aggregations