/*
* Copyright Massimiliano Dess� (desmax74@yahoo.it)
*
* Licensed under Apache License Version 2.0
* (http://www.apache.org/licenses/LICENSE-2.0),
*
* for commercial use, under
* GNU General Public License Version 2 or later (the "GPL")
* http://www.gnu.org/licenses/gpl.html
*/
package org.magicbox.service;
import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.Map;
import javolution.util.FastList;
import org.apache.log4j.Logger;
import org.magicbox.admin.bind.Binder;
import org.magicbox.controller.UploadController;
import org.magicbox.domain.Utente;
import org.magicbox.util.Constant;
import org.springframework.util.FileCopyUtils;
/**
* Implementazione Interfaccia per bind file uploadato e per successivo recupero utenti
*
* @author Massimiliano Dess� (desmax74@yahoo.it)
* @since jdk 1.6.0
* @version 3.0
*/
public class BindDataServiceImpl implements BindDataService {
@SuppressWarnings("unchecked")
public List<Utente> getUtenti(Map params, byte[] bytes) {
File temp = (File) params.get(Constant.TEMP);
String pathToFile;
try {
File upload = File.createTempFile(params.get(Constant.ID).toString(), params.get(Constant.EXT).toString(), temp);
FileCopyUtils.copy(bytes, upload);
StringBuilder sb = new StringBuilder(temp.getCanonicalPath()).append("//").append(upload.getName());
pathToFile = sb.toString();
} catch (IOException e) {
Logger.getLogger(UploadController.class).error("exception:" + e.getMessage());
return new FastList(0);
}
bytes = null;
return bind((Long) params.get(Constant.ID_CENTRO), pathToFile);
}
private List<Utente> bind(Long idCentro, String pathToFile) {
return pathToFile.endsWith(Constant.CSV_EXT) ? _binder.loadDataFromCsv(pathToFile, idCentro) : _binder.loadDataFromXsl(pathToFile);
}
public void setBinder(Binder bind) {
_binder = bind;
}
private Binder _binder;
}