Package com.evasion.plugin.common

Source Code of com.evasion.plugin.common.EventManager

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package com.evasion.plugin.common;

import com.evasion.ejb.local.EventHandlerLocal;
import com.evasion.ejb.remote.EventHandlerRemote;
import com.evasion.entity.event.EventData;
import com.evasion.entity.security.User;
import com.evasion.plugin.common.dao.EventDataDaoImpl;
import java.util.Date;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.ejb.Local;
import javax.ejb.Remote;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
*
* @author sebastien.glon
*/
@Stateless
@Local(value = EventHandlerLocal.class)
@Remote(value = EventHandlerRemote.class)
public class EventManager implements EventHandlerLocal, EventHandlerRemote {

    /** LOGGER  */
    private static final Logger LOGGER = LoggerFactory.getLogger(
            EventManager.class);

    /** Objet de presistence. */
    @PersistenceContext(unitName = "EvasionPU")
    private EntityManager em;

    private final EventDataDaoImpl eventDao;

    /**
     * Constructeur pour utilisation en test.
     * @param em entity manager.
     */
    protected EventManager(EntityManager em) {
        eventDao = new EventDataDaoImpl();
        eventDao.setEntityManager(em);
    }

    /**
     * Constructeur par défaut pour l'EJB.
     */
    public EventManager() {
        eventDao = new EventDataDaoImpl();
    }

    /**
     * Initialisation post constructeur.
     */
    @SuppressWarnings("PMD.UnusedPrivateMethod")
    @edu.umd.cs.findbugs.annotations.SuppressWarnings("UPM_UNCALLED_PRIVATE_METHOD")
    @PostConstruct
    private void init() {
        eventDao.setEntityManager(em);
    }

    /** {@inheritDoc } */
    @Override
    public List<EventData> getEventSince(Date date, String code) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    /**
     * {@inheritDoc }
     */
    @Override
    public List<EventData> getEventforPluginSince(Date date, String code, String plugin) {
        return eventDao.selectEventSince(date, code, plugin);
    }

    /**
     * {@inheritDoc }
     */
    @Override
    public void addEvent(String plugin, String entityName, String entityId, String code, User auteur) {
        if (StringUtils.isWhitespace(plugin)
                || StringUtils.isWhitespace(entityName)
                || StringUtils.isWhitespace(entityId)
                || StringUtils.isWhitespace(code)) {
            throw new IllegalArgumentException("Au moin une propriété est vide ou null");
        }
        LOGGER.debug("Ajout d'évènement.");
        EventData eventData = new EventData(entityName, entityId, code, plugin, auteur);

        eventDao.persist(eventData);
    }
}
TOP

Related Classes of com.evasion.plugin.common.EventManager

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.