Search in sources :

Example 1 with AuditSearchable

use of eu.bcvsolutions.idm.core.api.domain.AuditSearchable 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 AuditSearchable

use of eu.bcvsolutions.idm.core.api.domain.AuditSearchable 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

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 AbstractEntity (eu.bcvsolutions.idm.core.api.entity.AbstractEntity)2 AbstractAuthentication (eu.bcvsolutions.idm.core.security.api.domain.AbstractAuthentication)2