com.evasion.plugin.geoloc.GeolocModule Maven / Gradle / Ivy
The newest version!
/*
* To change this template, choose Tools | Templates and open the template in
* the editor.
*/
package com.evasion.plugin.geoloc;
import com.evasion.AbstractEJBModule;
import com.evasion.common.TimerInterface;
import com.evasion.ejb.remote.GeolocEJBRemote;
import com.evasion.entity.geolocation.Location;
import com.evasion.exception.EvasionException;
import com.evasion.plugin.geoloc.dao.LocationDAO;
import com.evasion.plugin.geoloc.dataimport.Importer;
import com.evasion.plugin.geoloc.dataimport.Importer.Mode;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import javax.ejb.EJB;
import javax.ejb.Remote;
import javax.ejb.Stateful;
import javax.ejb.TransactionManagement;
import javax.ejb.TransactionManagementType;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.PersistenceContextType;
import javax.transaction.UserTransaction;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
*
* @author glon-56610
*/
@Stateful
@Remote(value = GeolocEJBRemote.class)
@TransactionManagement(TransactionManagementType.BEAN)
public class GeolocModule extends AbstractEJBModule implements GeolocEJBRemote {
/**
* LOGGER.
*/
private static final Logger LOGGER = LoggerFactory.getLogger(
GeolocModule.class);
@EJB(name = "ImportTimerEJB")
private TimerInterface importTimerEJB;
@EJB
private SearchEngine searchEngine;
private LocationDAO locationDAO = new LocationDAO();
@PersistenceContext(unitName = "EvasionPU", type = PersistenceContextType.EXTENDED)
private transient EntityManager em;
@Resource
private UserTransaction utx;
@PostConstruct
public void init() {
locationDAO.setEntityManager(em);
}
@Override
public boolean importData(String file, String format) throws EvasionException {
Importer geo = new Importer(em, utx);
geo.setFile(file);
return geo.importData(format, Mode.UPDATE);
}
@Override
public void updateImportTimer() throws EvasionException {
importTimerEJB.updateImportTimer();
searchEngine.start(); //@TODO a déplacer dans une vrai méthode d'init du plugin.
}
@Override
public Location getLocationByid(long number) {
return locationDAO.findById(number);
}
@Override
public List searchFullTextLocation(String query) throws EvasionException {
try {
return new ArrayList(searchEngine.search("name:" + query + "*", "name"));
} catch (Exception ex) {
throw new EvasionException("Erreur technique:", ex);
}
}
}