Search in sources :

Example 1 with AbstractEntity

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());
    }
}
Also used : AuditSearchable(eu.bcvsolutions.idm.core.api.domain.AuditSearchable) Codeable(eu.bcvsolutions.idm.core.api.domain.Codeable) AbstractEntity(eu.bcvsolutions.idm.core.api.entity.AbstractEntity) AbstractAuthentication(eu.bcvsolutions.idm.core.security.api.domain.AbstractAuthentication) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)

Example 2 with AbstractEntity

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);
    }
}
Also used : IdmAudit(eu.bcvsolutions.idm.core.audit.entity.IdmAudit) AbstractEntity(eu.bcvsolutions.idm.core.api.entity.AbstractEntity) IdmAuditDto(eu.bcvsolutions.idm.core.api.audit.dto.IdmAuditDto)

Example 3 with AbstractEntity

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());
    }
}
Also used : AuditSearchable(eu.bcvsolutions.idm.core.api.domain.AuditSearchable) Codeable(eu.bcvsolutions.idm.core.api.domain.Codeable) AbstractEntity(eu.bcvsolutions.idm.core.api.entity.AbstractEntity) AbstractAuthentication(eu.bcvsolutions.idm.core.security.api.domain.AbstractAuthentication) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)

Aggregations

AbstractEntity (eu.bcvsolutions.idm.core.api.entity.AbstractEntity)3 AuditSearchable (eu.bcvsolutions.idm.core.api.domain.AuditSearchable)2 Codeable (eu.bcvsolutions.idm.core.api.domain.Codeable)2 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)2 AbstractAuthentication (eu.bcvsolutions.idm.core.security.api.domain.AbstractAuthentication)2 IdmAuditDto (eu.bcvsolutions.idm.core.api.audit.dto.IdmAuditDto)1 IdmAudit (eu.bcvsolutions.idm.core.audit.entity.IdmAudit)1