| 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.persistence.able.DataListener; |
| 20 | |
import org.jtheque.films.services.able.INotesService; |
| 21 | |
import org.jtheque.films.services.able.IRealizersService; |
| 22 | |
import org.jtheque.primary.dao.able.IDaoPersons; |
| 23 | |
import org.jtheque.primary.od.able.Person; |
| 24 | |
import org.jtheque.primary.services.able.ICountriesService; |
| 25 | |
import org.springframework.stereotype.Service; |
| 26 | |
import org.springframework.transaction.annotation.Transactional; |
| 27 | |
|
| 28 | |
import javax.annotation.Resource; |
| 29 | |
import java.util.Collection; |
| 30 | |
|
| 31 | |
|
| 32 | |
|
| 33 | |
|
| 34 | |
|
| 35 | |
|
| 36 | |
@Service |
| 37 | 0 | public final class RealizersService implements IRealizersService { |
| 38 | |
@Resource |
| 39 | |
private IDaoPersons daoPersons; |
| 40 | |
|
| 41 | |
@Resource |
| 42 | |
private INotesService notesService; |
| 43 | |
|
| 44 | |
@Resource |
| 45 | |
private ICountriesService countriesService; |
| 46 | |
|
| 47 | |
private Person defaultRealizer; |
| 48 | |
|
| 49 | |
private static final String DEFAULT_REALIZER = "Unknown"; |
| 50 | |
|
| 51 | |
@Override |
| 52 | |
public Collection<Person> getRealizers() { |
| 53 | 0 | return daoPersons.getPersons(PERSON_TYPE); |
| 54 | |
} |
| 55 | |
|
| 56 | |
@Override |
| 57 | |
@Transactional |
| 58 | |
public boolean delete(Person realizer) { |
| 59 | 0 | return daoPersons.delete(realizer); |
| 60 | |
} |
| 61 | |
|
| 62 | |
@Override |
| 63 | |
public boolean exists(String firstName, String name) { |
| 64 | 0 | return daoPersons.exists(firstName, name, PERSON_TYPE); |
| 65 | |
} |
| 66 | |
|
| 67 | |
@Override |
| 68 | |
public Person getRealizer(String firstName, String name) { |
| 69 | 0 | return daoPersons.getPerson(firstName, name, PERSON_TYPE); |
| 70 | |
} |
| 71 | |
|
| 72 | |
@Override |
| 73 | |
@Transactional |
| 74 | |
public void create(Person realizer) { |
| 75 | 0 | daoPersons.create(realizer); |
| 76 | 0 | } |
| 77 | |
|
| 78 | |
@Override |
| 79 | |
public boolean exists(Person realizer) { |
| 80 | 0 | return daoPersons.exist(realizer); |
| 81 | |
} |
| 82 | |
|
| 83 | |
@Override |
| 84 | |
public boolean hasNoRealizers() { |
| 85 | 0 | return getRealizers().isEmpty(); |
| 86 | |
} |
| 87 | |
|
| 88 | |
@Override |
| 89 | |
@Transactional |
| 90 | |
public void save(Person realizer) { |
| 91 | 0 | daoPersons.save(realizer); |
| 92 | 0 | } |
| 93 | |
|
| 94 | |
@Override |
| 95 | |
public Collection<Person> getDatas() { |
| 96 | 0 | return daoPersons.getPersons(PERSON_TYPE); |
| 97 | |
} |
| 98 | |
|
| 99 | |
@Override |
| 100 | |
public void addDataListener(DataListener listener) { |
| 101 | 0 | daoPersons.addDataListener(listener); |
| 102 | 0 | } |
| 103 | |
|
| 104 | |
@Override |
| 105 | |
public Person getEmptyRealizer() { |
| 106 | 0 | return daoPersons.createPerson(); |
| 107 | |
} |
| 108 | |
|
| 109 | |
@Override |
| 110 | |
@Transactional |
| 111 | |
public Person getDefaultRealizer() { |
| 112 | 0 | if (defaultRealizer == null) { |
| 113 | 0 | defaultRealizer = daoPersons.getPerson(DEFAULT_REALIZER, DEFAULT_REALIZER, PERSON_TYPE); |
| 114 | |
|
| 115 | 0 | if (defaultRealizer == null) { |
| 116 | 0 | defaultRealizer = getEmptyRealizer(); |
| 117 | |
|
| 118 | 0 | defaultRealizer.setName(DEFAULT_REALIZER); |
| 119 | 0 | defaultRealizer.setFirstName(DEFAULT_REALIZER); |
| 120 | 0 | defaultRealizer.setNote(notesService.getDefaultNote()); |
| 121 | 0 | defaultRealizer.setTheCountry(countriesService.getDefaultCountry()); |
| 122 | 0 | daoPersons.create(defaultRealizer); |
| 123 | |
} |
| 124 | |
} |
| 125 | |
|
| 126 | 0 | return defaultRealizer; |
| 127 | |
} |
| 128 | |
|
| 129 | |
@Override |
| 130 | |
@Transactional |
| 131 | |
public void clearAll() { |
| 132 | 0 | daoPersons.clearAll(); |
| 133 | 0 | } |
| 134 | |
|
| 135 | |
@Override |
| 136 | |
public String getDataType() { |
| 137 | 0 | return DATA_TYPE; |
| 138 | |
} |
| 139 | |
} |