Created
August 8, 2014 18:45
-
-
Save dilnei/91cab38a98e898f4aaf3 to your computer and use it in GitHub Desktop.
Listener para popular campo com o usuario do JAAS.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package br.com.app.model.entity.listener; | |
| import javax.ejb.EJB; | |
| import javax.persistence.PrePersist; | |
| import javax.persistence.PreUpdate; | |
| import org.slf4j.Logger; | |
| import org.slf4j.LoggerFactory; | |
| import net.vidageek.mirror.dsl.Mirror; | |
| import net.vidageek.mirror.exception.MirrorException; | |
| /** | |
| * listener para popular campo com o usuario do JAAS. | |
| * | |
| * @author Dilnei Cunha | |
| */ | |
| public class CurrentUserListener { | |
| private transient final Logger logger = LoggerFactory.getLogger(getClass()); | |
| @EJB | |
| private CurrentUserBean currentUserBean; | |
| @PrePersist | |
| @PreUpdate | |
| public void load(Object object) { | |
| if (object != null) { | |
| try { | |
| String usuario = currentUserBean.getCurrentUser(); | |
| new Mirror().on(object).invoke().method("setUsuario").withArgs(usuario); | |
| } catch (MirrorException e) { | |
| logger.warn("Object {} não tem um método setUsuario", object.getClass()); | |
| } | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment