if (auditable.getCreated() == null) { auditable.setCreated(now); auditable.setUpdated(now); if (auditable.getCreator() == null) { auditable.setCreator( currentUser ); auditable.setUpdator( currentUser );
public boolean onPreInsert( PreInsertEvent preInsertEvent ) { if ( !( preInsertEvent.getEntity() instanceof Auditable ) ) { log.debug( "No auditable object: " + preInsertEvent.getId() ); return false; } log.debug( "Inserting audit info for: " + preInsertEvent.getId() ); Date now = new Date(); Auditable auditable = ( Auditable ) preInsertEvent.getEntity(); auditable.setCreated( now ); auditable.setUpdated( now ); String currentUser = IntactContext.getCurrentInstance().getUserContext().getUserId().toUpperCase(); auditable.setCreator( currentUser ); auditable.setUpdator( currentUser ); String[] names = preInsertEvent.getPersister().getPropertyNames(); Object[] values = preInsertEvent.getState(); for ( int i = 0; i < names.length; i++ ) { if ( names[i].equals( "created" ) || names[i].equals( "updated" ) ) { values[i] = now; continue; } if ( names[i].equals( "creator" ) || names[i].equals( "updator" ) ) { log.debug( "Current user " + currentUser ); values[i] = currentUser; } } return false; }
auditable.setUpdated( now ); auditable.setUpdator( currentUser ); boolean updateCreationInfo = auditable.getCreator() == null; auditable.setCreated( now ); auditable.setUpdated( now ); values[i] = auditable.getCreator(); values[i] = auditable.getCreated();
if (auditable.getCreated() == null) { auditable.setCreated(now); auditable.setUpdated(now); if (auditable.getCreator() == null) { auditable.setCreator( currentUser ); auditable.setUpdator( currentUser );