// $Id$
/**
* Copyright (C) 2007 EDIT
-* European Distributed Institute of Taxonomy
+* European Distributed Institute of Taxonomy
* http://www.e-taxonomy.eu
-*
+*
* The contents of this file are subject to the Mozilla Public License Version 1.1
* See LICENSE.TXT at the top of this package for the full license terms.
*/
import eu.etaxonomy.cdm.api.service.pager.Pager;
import eu.etaxonomy.cdm.api.service.pager.impl.DefaultPagerImpl;
import eu.etaxonomy.cdm.common.monitor.IProgressMonitor;
-import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
import eu.etaxonomy.cdm.model.common.CdmBase;
import eu.etaxonomy.cdm.model.common.DefinedTermBase;
import eu.etaxonomy.cdm.model.common.Language;
import eu.etaxonomy.cdm.model.common.LanguageString;
import eu.etaxonomy.cdm.model.common.LanguageStringBase;
import eu.etaxonomy.cdm.model.common.Representation;
+import eu.etaxonomy.cdm.model.common.TermType;
import eu.etaxonomy.cdm.model.common.TermVocabulary;
import eu.etaxonomy.cdm.model.location.NamedArea;
import eu.etaxonomy.cdm.model.location.NamedAreaLevel;
import eu.etaxonomy.cdm.model.location.NamedAreaType;
import eu.etaxonomy.cdm.model.media.Media;
-import eu.etaxonomy.cdm.model.taxon.Synonym;
import eu.etaxonomy.cdm.persistence.dao.common.IDefinedTermDao;
import eu.etaxonomy.cdm.persistence.dao.common.ILanguageStringBaseDao;
import eu.etaxonomy.cdm.persistence.dao.common.ILanguageStringDao;
public class TermServiceImpl extends IdentifiableServiceBase<DefinedTermBase,IDefinedTermDao> implements ITermService{
@SuppressWarnings("unused")
private static final Logger logger = Logger.getLogger(TermServiceImpl.class);
-
+
private ILanguageStringDao languageStringDao;
-
+
@Autowired
@Qualifier("langStrBaseDao")
private ILanguageStringBaseDao languageStringBaseDao;
private IRepresentationDao representationDao;
-
+
@Autowired
public void setLanguageStringDao(ILanguageStringDao languageStringDao) {
this.languageStringDao = languageStringDao;
- }
-
+ }
+
@Autowired
public void setRepresentationDao(IRepresentationDao representationDao) {
this.representationDao = representationDao;
}
-
- @Autowired
+
+ @Override
+ @Autowired
protected void setDao(IDefinedTermDao dao) {
this.dao = dao;
}
-
+ /* (non-Javadoc)
+ * @see eu.etaxonomy.cdm.api.service.ITermService#listByTermType(eu.etaxonomy.cdm.model.common.TermType, java.lang.Integer, java.lang.Integer, java.util.List, java.util.List)
+ */
@Override
- public <TERM extends DefinedTermBase> List<TERM> listByTermClass(Class<TERM> clazz, Integer limit, Integer start, List<OrderHint> orderHints, List<String> propertyPaths) {
- return dao.listByTermClass(clazz, limit, start, orderHints, propertyPaths);
- }
-
+ public List<DefinedTermBase<?>> listByTermType(TermType termType, Integer limit, Integer start,
+ List<OrderHint> orderHints, List<String> propertyPaths) {
+ return dao.listByTermType(termType, limit, start, orderHints, propertyPaths);
+ }
+
@Override
public DefinedTermBase getByUri(URI uri) {
return dao.findByUri(uri);
}
-
+
@Override
public Language getLanguageByIso(String iso639) {
return dao.getLanguageByIso(iso639);
}
-
+
@Override
public List<Language> getLanguagesByLocale(Enumeration<Locale> locales){
return dao.getLanguagesByLocale(locales);
}
@Override
- public <TERM extends DefinedTermBase> TERM getDefinedTermByIdInVocabulary(String id, UUID vocabularyUuid, Class<TERM> clazz, Integer pageSize, Integer pageNumber) {
- List<TERM> list = dao.getDefinedTermByIdInVocabulary(id, vocabularyUuid, clazz, pageSize, pageNumber);
+ public <TERM extends DefinedTermBase> TERM findByIdInVocabulary(String id, UUID vocabularyUuid, Class<TERM> clazz) throws IllegalArgumentException {
+ List<TERM> list = dao.getDefinedTermByIdInVocabulary(id, vocabularyUuid, clazz, null, null);
if (list.isEmpty()){
return null;
}else if (list.size() == 1){
throw new IllegalStateException(String.format(message, list.size()));
}
}
-
+
@Override
public NamedArea getAreaByTdwgAbbreviation(String tdwgAbbreviation) {
String message = "There is more then 1 (%d) TDWG area with the same abbreviated label. This is forbidden. Check the state of your database.";
throw new IllegalStateException(String.format(message, list.size()));
}
-
+
}
@Override
public <T extends DefinedTermBase> Pager<T> getGeneralizationOf(T definedTerm, Integer pageSize, Integer pageNumber) {
Integer numberOfResults = dao.countGeneralizationOf(definedTerm);
-
+
List<T> results = new ArrayList<T>();
if(numberOfResults > 0) { // no point checking again //TODO use AbstractPagerImpl.hasResultsInRange(numberOfResults, pageNumber, pageSize)
- results = dao.getGeneralizationOf(definedTerm, pageSize, pageNumber);
+ results = dao.getGeneralizationOf(definedTerm, pageSize, pageNumber);
}
-
+
return new DefaultPagerImpl<T>(pageNumber, numberOfResults, pageSize, results);
}
@Override
public <T extends DefinedTermBase> Pager<T> getIncludes(Collection<T> definedTerms, Integer pageSize, Integer pageNumber, List<String> propertyPaths) {
Integer numberOfResults = dao.countIncludes(definedTerms);
-
+
List<T> results = new ArrayList<T>();
if(numberOfResults > 0) { // no point checking again //TODO use AbstractPagerImpl.hasResultsInRange(numberOfResults, pageNumber, pageSize)
- results = dao.getIncludes(definedTerms, pageSize, pageNumber,propertyPaths);
+ results = dao.getIncludes(definedTerms, pageSize, pageNumber,propertyPaths);
}
-
+
return new DefaultPagerImpl<T>(pageNumber, numberOfResults, pageSize, results);
}
@Override
public Pager<Media> getMedia(DefinedTermBase definedTerm, Integer pageSize, Integer pageNumber) {
Integer numberOfResults = dao.countMedia(definedTerm);
-
+
List<Media> results = new ArrayList<Media>();
if(numberOfResults > 0) { // no point checking again //TODO use AbstractPagerImpl.hasResultsInRange(numberOfResults, pageNumber, pageSize)
- results = dao.getMedia(definedTerm, pageSize, pageNumber);
+ results = dao.getMedia(definedTerm, pageSize, pageNumber);
}
-
+
return new DefaultPagerImpl<Media>(pageNumber, numberOfResults, pageSize, results);
}
@Override
public <T extends DefinedTermBase> Pager<T> getPartOf(Set<T> definedTerms,Integer pageSize, Integer pageNumber, List<String> propertyPaths) {
Integer numberOfResults = dao.countPartOf(definedTerms);
-
+
List<T> results = new ArrayList<T>();
if(numberOfResults > 0) { // no point checking again //TODO use AbstractPagerImpl.hasResultsInRange(numberOfResults, pageNumber, pageSize)
- results = dao.getPartOf(definedTerms, pageSize, pageNumber, propertyPaths);
+ results = dao.getPartOf(definedTerms, pageSize, pageNumber, propertyPaths);
}
-
+
return new DefaultPagerImpl<T>(pageNumber, numberOfResults, pageSize, results);
}
@Override
public <T extends DefinedTermBase> Pager<T> findByRepresentationText(String label, Class<T> clazz, Integer pageSize, Integer pageNumber) {
Integer numberOfResults = dao.countDefinedTermByRepresentationText(label,clazz);
-
+
List<T> results = new ArrayList<T>();
if(numberOfResults > 0) { // no point checking again //TODO use AbstractPagerImpl.hasResultsInRange(numberOfResults, pageNumber, pageSize)
results = dao.getDefinedTermByRepresentationText(label, clazz, pageSize, pageNumber);
}
-
+
return new DefaultPagerImpl<T>(pageNumber, numberOfResults, pageSize, results);
}
-
+
@Override
public <T extends DefinedTermBase> Pager<T> findByRepresentationAbbreviation(String abbrev, Class<T> clazz, Integer pageSize, Integer pageNumber) {
Integer numberOfResults = dao.countDefinedTermByRepresentationAbbrev(abbrev,clazz);
-
+
List<T> results = new ArrayList<T>();
if(numberOfResults > 0) { // no point checking again //TODO use AbstractPagerImpl.hasResultsInRange(numberOfResults, pageNumber, pageSize)
results = dao.getDefinedTermByRepresentationAbbrev(abbrev, clazz, pageSize, pageNumber);
}
-
+
return new DefaultPagerImpl<T>(pageNumber, numberOfResults, pageSize, results);
}
public UUID saveLanguageData(LanguageStringBase languageData) {
return languageStringBaseDao.save(languageData);
}
-
+
/* (non-Javadoc)
* @see eu.etaxonomy.cdm.api.service.ServiceBase#delete(eu.etaxonomy.cdm.model.common.CdmBase)
*/
* to allow DeleteResult return type*/
@Override
@Deprecated
- public String delete(DefinedTermBase term){
- String result = term.getUuid().toString();
-
+ public DeleteResult delete(DefinedTermBase term){
+ DeleteResult result = new DeleteResult();
+
TermDeletionConfigurator defaultConfig = new TermDeletionConfigurator();
- delete(term, defaultConfig);
+ result = delete(term, defaultConfig);
return result;
}
DeleteResult result = new DeleteResult();
Set<DefinedTermBase> termsToSave = new HashSet<DefinedTermBase>();
CdmBase.deproxy(dao.merge(term), DefinedTermBase.class);
-
+
try {
//generalization of
Set<DefinedTermBase> specificTerms = term.getGeneralizationOf();
DataChangeNoRollbackException ex = new DataChangeNoRollbackException(message);
result.addException(ex);
}
- }
+ }
+
-
//included in
Set<DefinedTermBase> includedTerms = term.getIncludes();
if (includedTerms.size()> 0){
//// config.setCheck(isCheck);
// result.includeResult(includedResult);
// }
-// }else
+// }else
if (config.isDeleteIncludedRelations()){
DefinedTermBase parent = term.getPartOf();
for (DefinedTermBase includedTerm: includedTerms){
//handelede before "included in"
}
}
-
+
// relatedObjects;
-
-
+
+
if (result.isOk()){
TermVocabulary voc = term.getVocabulary();
if (voc!= null){
for (DeleteResult.PersistPair persistPair : result.getObjectsToSave()){
persistPair.dao.saveOrUpdate(persistPair.objectToPersist);
}
-
+
}
}
} catch (DataChangeNoRollbackException e) {