| 1 | |
package org.jtheque.films.services.impl; |
| 2 | |
|
| 3 | |
import org.jtheque.core.managers.Managers; |
| 4 | |
import org.jtheque.core.managers.view.able.IViewManager; |
| 5 | |
import org.jtheque.core.utils.Response; |
| 6 | |
import org.jtheque.core.utils.SystemProperty; |
| 7 | |
import org.jtheque.films.persistence.od.able.Film; |
| 8 | |
import org.jtheque.films.services.able.IFilmsService; |
| 9 | |
import org.jtheque.films.services.able.IPublicationService; |
| 10 | |
import org.jtheque.films.services.impl.utils.file.FTPConnectionInfos; |
| 11 | |
import org.jtheque.films.services.impl.utils.file.FTPManager; |
| 12 | |
import org.jtheque.films.services.impl.utils.file.exports.Exporter; |
| 13 | |
import org.jtheque.films.services.impl.utils.file.exports.ExporterFactory; |
| 14 | |
import org.jtheque.films.utils.Constants; |
| 15 | |
|
| 16 | |
import javax.annotation.Resource; |
| 17 | |
|
| 18 | |
|
| 19 | |
|
| 20 | |
|
| 21 | |
|
| 22 | |
|
| 23 | |
|
| 24 | |
|
| 25 | |
|
| 26 | |
|
| 27 | |
|
| 28 | |
|
| 29 | |
|
| 30 | |
|
| 31 | |
|
| 32 | |
|
| 33 | |
|
| 34 | |
|
| 35 | |
|
| 36 | |
|
| 37 | 0 | public final class PublicationService implements IPublicationService { |
| 38 | |
@Resource |
| 39 | |
private IFilmsService filmsService; |
| 40 | |
|
| 41 | |
@Override |
| 42 | |
public void uploadListOfFilms(FTPConnectionInfos infos) { |
| 43 | 0 | String local = SystemProperty.JAVA_IO_TMP_DIR.get() + "/index.html"; |
| 44 | |
|
| 45 | 0 | Exporter<Film> exporter = ExporterFactory.getExporter(Constants.Files.FileType.HTML); |
| 46 | |
|
| 47 | 0 | exporter.setDatas(filmsService.getFilms()); |
| 48 | |
|
| 49 | 0 | exporter.export(local); |
| 50 | |
|
| 51 | 0 | String remote = infos.getPath() + "index.html"; |
| 52 | |
|
| 53 | 0 | FTPManager ftp = new FTPManager(infos); |
| 54 | |
|
| 55 | 0 | Response connection = ftp.connect(); |
| 56 | |
|
| 57 | 0 | if (connection.isOk()) { |
| 58 | 0 | Response store = ftp.upload(local, remote); |
| 59 | |
|
| 60 | 0 | Managers.getManager(IViewManager.class).displayText(store.getMessage()); |
| 61 | 0 | } else { |
| 62 | 0 | Managers.getManager(IViewManager.class).displayText(connection.getMessage()); |
| 63 | |
} |
| 64 | |
|
| 65 | 0 | ftp.disconnect(); |
| 66 | 0 | } |
| 67 | |
} |