use of com.salesmanager.core.model.common.audit.Auditable in project shopizer by shopizer-ecommerce.
the class PersistableAuditAspect method afterReturning.
@AfterReturning(value = "execution(* populate(..))", returning = "result")
public void afterReturning(JoinPoint joinPoint, Object result) {
try {
if (result instanceof Auditable) {
Auditable entity = (Auditable) result;
AuditSection audit = entity.getAuditSection();
if (entity.getAuditSection() == null) {
audit = new AuditSection();
}
audit.setDateModified(new Date());
Authentication auth = SecurityContextHolder.getContext().getAuthentication();
if (auth != null) {
if (auth instanceof UsernamePasswordAuthenticationToken) {
// api only is captured
com.salesmanager.shop.store.security.user.JWTUser user = (com.salesmanager.shop.store.security.user.JWTUser) auth.getPrincipal();
audit.setModifiedBy(user.getUsername());
}
}
// TODO put in log audit log trail
entity.setAuditSection(audit);
}
} catch (Throwable e) {
LOGGER.error("Error while setting audit values" + e.getMessage());
}
}
Aggregations