| 1 | |
package org.jtheque.films.services.impl; |
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
|
| 18 | |
|
| 19 | |
import org.jtheque.core.managers.Managers; |
| 20 | |
import org.jtheque.core.managers.language.ILanguageManager; |
| 21 | |
import org.jtheque.core.managers.persistence.able.DataListener; |
| 22 | |
import org.jtheque.films.persistence.dao.able.IDaoFilms; |
| 23 | |
import org.jtheque.films.persistence.od.able.Film; |
| 24 | |
import org.jtheque.films.services.able.IFilmsService; |
| 25 | |
import org.jtheque.films.services.able.INotesService; |
| 26 | |
import org.jtheque.films.services.able.IRealizersService; |
| 27 | |
import org.jtheque.films.services.impl.utils.VideoFile; |
| 28 | |
import org.jtheque.primary.od.able.Kind; |
| 29 | |
import org.jtheque.primary.od.able.Person; |
| 30 | |
import org.jtheque.primary.services.able.IKindsService; |
| 31 | |
import org.jtheque.primary.services.able.ILanguagesService; |
| 32 | |
import org.jtheque.primary.services.able.ITypesService; |
| 33 | |
import org.jtheque.utils.StringUtils; |
| 34 | |
import org.jtheque.utils.print.PrintUtils; |
| 35 | |
import org.springframework.transaction.annotation.Transactional; |
| 36 | |
|
| 37 | |
import javax.annotation.Resource; |
| 38 | |
import java.util.ArrayList; |
| 39 | |
import java.util.Collection; |
| 40 | |
|
| 41 | |
|
| 42 | |
|
| 43 | |
|
| 44 | |
|
| 45 | |
|
| 46 | 0 | public final class FilmsService implements IFilmsService { |
| 47 | |
@Resource |
| 48 | |
private IDaoFilms daoFilms; |
| 49 | |
|
| 50 | |
@Resource |
| 51 | |
private INotesService notesService; |
| 52 | |
|
| 53 | |
@Resource |
| 54 | |
private IRealizersService realizersService; |
| 55 | |
|
| 56 | |
@Resource |
| 57 | |
private IKindsService kindsService; |
| 58 | |
|
| 59 | |
@Resource |
| 60 | |
private ITypesService typesService; |
| 61 | |
|
| 62 | |
@Resource |
| 63 | |
private ILanguagesService languagesService; |
| 64 | |
|
| 65 | |
@Override |
| 66 | |
@Transactional |
| 67 | |
public void create(Film film) { |
| 68 | 0 | daoFilms.create(film); |
| 69 | 0 | } |
| 70 | |
|
| 71 | |
@Override |
| 72 | |
@Transactional |
| 73 | |
public void save(Film film) { |
| 74 | 0 | daoFilms.save(film); |
| 75 | 0 | } |
| 76 | |
|
| 77 | |
@Override |
| 78 | |
@Transactional |
| 79 | |
public boolean delete(Film film) { |
| 80 | 0 | return daoFilms.delete(film); |
| 81 | |
} |
| 82 | |
|
| 83 | |
@Override |
| 84 | |
@Transactional |
| 85 | |
public void createAll(Collection<Film> films) { |
| 86 | 0 | daoFilms.createAll(films); |
| 87 | 0 | } |
| 88 | |
|
| 89 | |
@Override |
| 90 | |
public boolean isNoFilms() { |
| 91 | 0 | return daoFilms.getFilms().size() <= 0; |
| 92 | |
} |
| 93 | |
|
| 94 | |
@Override |
| 95 | |
public Collection<Film> getFilms() { |
| 96 | 0 | return daoFilms.getFilms(); |
| 97 | |
} |
| 98 | |
|
| 99 | |
@Override |
| 100 | |
public void addDataListener(DataListener listener) { |
| 101 | 0 | daoFilms.addDataListener(listener); |
| 102 | 0 | } |
| 103 | |
|
| 104 | |
@Override |
| 105 | |
public Collection<Film> getDatas() { |
| 106 | 0 | return daoFilms.getFilms(); |
| 107 | |
} |
| 108 | |
|
| 109 | |
@Override |
| 110 | |
public Film getDefaultFilm() { |
| 111 | 0 | Film emptyFilm = getEmptyFilm(); |
| 112 | |
|
| 113 | 0 | emptyFilm.setTitle(Managers.getManager(ILanguageManager.class).getMessage("generic.view.actions.new")); |
| 114 | 0 | emptyFilm.setNote(notesService.getDefaultNote()); |
| 115 | 0 | emptyFilm.setTheRealizer(realizersService.getDefaultRealizer()); |
| 116 | 0 | emptyFilm.addKind(kindsService.getDefaultKind()); |
| 117 | 0 | emptyFilm.setTheType(typesService.getDefaultType()); |
| 118 | 0 | emptyFilm.setTheLanguage(languagesService.getDefaultLanguage()); |
| 119 | |
|
| 120 | 0 | return emptyFilm; |
| 121 | |
} |
| 122 | |
|
| 123 | |
@Override |
| 124 | |
public void printListOfFilms() { |
| 125 | 0 | Collection<String> list = new ArrayList<String>(25); |
| 126 | |
|
| 127 | 0 | list.add("List of films"); |
| 128 | |
|
| 129 | 0 | for (Film f : daoFilms.getFilms()) { |
| 130 | 0 | list.add(f.getDisplayableText()); |
| 131 | |
} |
| 132 | |
|
| 133 | 0 | PrintUtils.printArrayString(list); |
| 134 | 0 | } |
| 135 | |
|
| 136 | |
@Override |
| 137 | |
public String generateEmail(Film film) { |
| 138 | 0 | return generateFilmDescription(film); |
| 139 | |
} |
| 140 | |
|
| 141 | |
|
| 142 | |
|
| 143 | |
|
| 144 | |
|
| 145 | |
|
| 146 | |
|
| 147 | |
private static String generateFilmDescription(Film film) { |
| 148 | 0 | StringBuilder builder = new StringBuilder(250); |
| 149 | |
|
| 150 | 0 | builder.append("Hi, \n\n i'm sending the informations about a film that can interest you : \n"); |
| 151 | 0 | builder.append("Title : ").append(film.getTitle()); |
| 152 | 0 | builder.append("\nKind : "); |
| 153 | |
|
| 154 | 0 | for (Kind kind : film.getKinds()) { |
| 155 | 0 | builder.append("\n - ").append(kind.getDisplayableText()); |
| 156 | |
} |
| 157 | |
|
| 158 | 0 | builder.append("\nRealizer : ").append(film.getTheRealizer()); |
| 159 | 0 | builder.append("\nYear : ").append(film.getYear()); |
| 160 | 0 | builder.append("\nActors : "); |
| 161 | |
|
| 162 | 0 | for (Person actor : film.getActors()) { |
| 163 | 0 | builder.append("\n - ").append(actor.getDisplayableText()); |
| 164 | |
} |
| 165 | |
|
| 166 | 0 | return builder.toString(); |
| 167 | |
} |
| 168 | |
|
| 169 | |
@Override |
| 170 | |
public String generateFilmDescriptionForPrinting(Film film) { |
| 171 | 0 | return generateFilmDescription(film); |
| 172 | |
} |
| 173 | |
|
| 174 | |
@Override |
| 175 | |
public Collection<VideoFile> getVideoFiles() { |
| 176 | 0 | Collection<VideoFile> videoFiles = new ArrayList<VideoFile>(10); |
| 177 | |
|
| 178 | 0 | for (Film film : daoFilms.getFilms()) { |
| 179 | 0 | if (!StringUtils.isEmpty(film.getFilePath())) { |
| 180 | |
String path; |
| 181 | |
|
| 182 | 0 | if (film.getFilePath().contains("/")) { |
| 183 | 0 | path = film.getFilePath().substring(film.getFilePath().lastIndexOf('/') + 1); |
| 184 | 0 | } else if (film.getFilePath().contains("\\")) { |
| 185 | 0 | path = film.getFilePath().substring(film.getFilePath().lastIndexOf('\\') + 1); |
| 186 | |
} else { |
| 187 | 0 | path = film.getFilePath(); |
| 188 | |
} |
| 189 | |
|
| 190 | 0 | videoFiles.add(new VideoFile(path, film)); |
| 191 | 0 | } |
| 192 | |
} |
| 193 | |
|
| 194 | 0 | return videoFiles; |
| 195 | |
} |
| 196 | |
|
| 197 | |
@Override |
| 198 | |
@Transactional |
| 199 | |
public void clearAll() { |
| 200 | 0 | daoFilms.clearAll(); |
| 201 | 0 | } |
| 202 | |
|
| 203 | |
@Override |
| 204 | |
public String getDataType() { |
| 205 | 0 | return DATA_TYPE; |
| 206 | |
} |
| 207 | |
|
| 208 | |
@Override |
| 209 | |
public Film getEmptyFilm() { |
| 210 | 0 | return daoFilms.createFilm(); |
| 211 | |
} |
| 212 | |
} |