-// $Id$\r
/**\r
* Copyright (C) 2007 EDIT\r
* European Distributed Institute of Taxonomy\r
import eu.etaxonomy.cdm.model.common.ISourceable;\r
import eu.etaxonomy.cdm.model.common.IdentifiableEntity;\r
import eu.etaxonomy.cdm.model.metadata.CdmMetaData;\r
-import eu.etaxonomy.cdm.model.metadata.CdmMetaData.MetaDataPropertyName;\r
+import eu.etaxonomy.cdm.model.metadata.CdmMetaDataPropertyName;\r
import eu.etaxonomy.cdm.persistence.dao.common.ICdmGenericDao;\r
import eu.etaxonomy.cdm.persistence.dao.common.IOriginalSourceDao;\r
import eu.etaxonomy.cdm.persistence.query.OrderHint;\r
public class CommonServiceImpl /*extends ServiceBase<OriginalSourceBase,IOriginalSourceDao>*/ implements ICommonService {\r
@SuppressWarnings("unused")\r
private static final Logger logger = Logger.getLogger(CommonServiceImpl.class);\r
-
+\r
\r
@Autowired\r
private IOriginalSourceDao originalSourceDao;\r
\r
-
+\r
@Autowired\r
private ICdmGenericDao genericDao;\r
-
+\r
+\r
+ @Override\r
+ public <T extends CdmBase> T findWithUpdate(Class<T> clazz, int id){\r
+ return genericDao.find(clazz, id);\r
+ }\r
\r
@Override\r
- public CdmBase find(Class<? extends CdmBase> clazz, int id){\r
+ public <T extends CdmBase> T find(Class<T> clazz, int id){\r
return genericDao.find(clazz, id);\r
}\r
\r
+ @Override\r
+ public <T extends CdmBase> T find(Class<T> clazz, int id, List<String> propertyPaths){\r
+ return genericDao.find(clazz, id, propertyPaths);\r
+ }\r
+\r
+ @Override\r
+ public <T extends CdmBase> T find(Class<T> clazz, UUID uuid) {\r
+ return uuid == null ? null : genericDao.find(clazz, uuid);\r
+ }\r
+\r
+ @Override\r
+ public <T extends CdmBase> T find(Class<T> clazz, UUID uuid, List<String> propertyPaths) {\r
+ return uuid == null ? null : genericDao.find(clazz, uuid, propertyPaths);\r
+ }\r
\r
@Override\r
public Map<String, ? extends ISourceable> getSourcedObjectsByIdInSource(Class clazz, Set<String> idInSourceSet, String idNamespace) {\r
\r
@Override\r
public ISourceable getSourcedObjectByIdInSource(Class clazz, String idInSource, String idNamespace) {\r
- ISourceable result = null;\r
+ ISourceable<?> result = null;\r
List<IdentifiableEntity> list = originalSourceDao.findOriginalSourceByIdInSource(clazz, idInSource, idNamespace);\r
if (! list.isEmpty()){\r
result = list.get(0);\r
return this.genericDao.getReferencingObjects(referencedCdmBase);\r
}\r
\r
+ @Override\r
+ public Integer getReferencingObjectsCount(CdmBase referencedCdmBase){\r
+ return this.genericDao.getReferencingObjectsCount(referencedCdmBase);\r
+ }\r
\r
@Override\r
public Set<CdmBase> getReferencingObjectsForDeletion(CdmBase referencedCdmBase){\r
//\r
// referencedCdmBase = (CdmBase)HibernateProxyHelper.deproxy(referencedCdmBase);\r
// Class referencedClass = referencedCdmBase.getClass();\r
- // Set<CdmBase> result = new HashSet<CdmBase>();\r
+ // Set<CdmBase> result = new HashSet<>();\r
// logger.debug("Referenced Class: " + referencedClass.getName());\r
//\r
// for (Class<? extends CdmBase> cdmClass : allCdmClasses){\r
// }\r
//\r
// private Set<Field> getFields(Class clazz){\r
- // Set<Field> result = new HashSet<Field>();\r
+ // Set<Field> result = new HashSet<>();\r
// for (Field field: clazz.getDeclaredFields()){\r
// if (!Modifier.isStatic(field.getModifiers())){\r
// result.add(field);\r
// }\r
//\r
// private Set<CdmBase> getCdmBasesByFieldAndClass(Field field, Class itemClass, Class otherClazz, CdmBase item, boolean isCollection){\r
- // Set<CdmBase> result = new HashSet<CdmBase>();\r
+ // Set<CdmBase> result = new HashSet<>();\r
// if (isCollection){\r
// result.addAll(genericDao.getCdmBasesWithItemInCollection(itemClass, otherClazz, field.getName(), item));\r
// }else{\r
merge(mergeFirst, mergeSecond, mergeStrategy);\r
}\r
\r
+ @Override\r
+ @Transactional(readOnly = false)\r
+ @Deprecated\r
+ public <T extends IMergable> void merge(int mergeFirstId, int mergeSecondId, Class<? extends CdmBase> clazz) throws MergeException {\r
+ IMergeStrategy mergeStrategy;\r
+ T mergeFirst = (T) genericDao.find(clazz, mergeFirstId);\r
+ T mergeSecond = (T) genericDao.find(clazz, mergeSecondId);\r
+ mergeStrategy = DefaultMergeStrategy.NewInstance(clazz);\r
+ merge(mergeFirst, mergeSecond, mergeStrategy);\r
+ }\r
+\r
+ @Override\r
+ @Transactional(readOnly = false)\r
+ public <T extends IMergable> void merge(UUID mergeFirstUuid, UUID mergeSecondUuid, Class<? extends CdmBase> clazz) throws MergeException {\r
+ IMergeStrategy mergeStrategy;\r
+ T mergeFirst = (T) genericDao.find(clazz, mergeFirstUuid);\r
+ T mergeSecond = (T) genericDao.find(clazz, mergeSecondUuid);\r
+ if (mergeFirst == null){\r
+ throw new MergeException("The merge target is not available anymore.");\r
+ }\r
+ if (mergeSecond == null){\r
+ throw new MergeException("The merge candidate is not available anymore.");\r
+ }\r
+ mergeStrategy = DefaultMergeStrategy.NewInstance(clazz);\r
+ merge(mergeFirst, mergeSecond, mergeStrategy);\r
+ }\r
+\r
@Override\r
public <T extends IMergable> void merge(T mergeFirst, T mergeSecond) throws MergeException {\r
IMergeStrategy mergeStrategy = DefaultMergeStrategy.NewInstance(((CdmBase)mergeFirst).getClass());\r
return genericDao.findMatching(objectToMatch, matchStrategy);\r
}\r
\r
-
+\r
\r
/* (non-Javadoc)\r
* @see eu.etaxonomy.cdm.api.service.ICommonService#findMatching(eu.etaxonomy.cdm.strategy.match.IMatchable, eu.etaxonomy.cdm.strategy.match.MatchStrategyConfigurator.MatchStrategy)\r
// logger.warn("Not yet implemented");\r
// return null;\r
// }\r
-
+\r
\r
@Transactional(readOnly = false)\r
@Override\r
}\r
\r
@Override\r
- public Map<MetaDataPropertyName, CdmMetaData> getCdmMetaData() {\r
- Map<MetaDataPropertyName, CdmMetaData> result = new HashMap<MetaDataPropertyName, CdmMetaData>();\r
+ public Map<CdmMetaDataPropertyName, CdmMetaData> getCdmMetaData() {\r
+ Map<CdmMetaDataPropertyName, CdmMetaData> result = new HashMap<>();\r
List<CdmMetaData> metaDataList = genericDao.getMetaData();\r
for (CdmMetaData metaData : metaDataList){\r
- MetaDataPropertyName propertyName = metaData.getPropertyName();\r
+ CdmMetaDataPropertyName propertyName = metaData.getPropertyName();\r
result.put(propertyName, metaData);\r
}\r
return result;\r
\r
}\r
\r
+ @Override\r
+ public Object initializeCollection(UUID ownerUuid, String fieldName, List<String> propertyPaths) {\r
+ return genericDao.initializeCollection(ownerUuid, fieldName, propertyPaths);\r
+\r
+ }\r
+\r
@Override\r
public boolean isEmpty(UUID ownerUuid, String fieldName) {\r
return genericDao.isEmpty(ownerUuid, fieldName);\r
genericDao.createFullSampleData();\r
}\r
\r
-
+\r
\r
@Override\r
public <S extends CdmBase> List<S> list(Class<S> type, Integer limit, Integer start, List<OrderHint> orderHints, List<String> propertyPaths){\r
\r
@Override\r
@Transactional(readOnly = false)\r
- public UUID save(CdmBase newInstance) {\r
+ public CdmBase save(CdmBase newInstance) {\r
return genericDao.save(newInstance);\r
}\r
\r
+ @Override\r
+ @Transactional(readOnly = false)\r
+ public UUID delete(CdmBase instance) {\r
+ return genericDao.delete(instance);\r
+ }\r
+\r
+ @Override\r
+ @Transactional(readOnly = false)\r
+ public UUID saveOrUpdate(CdmBase newInstance) {\r
+ return genericDao.saveOrUpdate(newInstance);\r
+ }\r
+\r
\r
@Override\r
@Transactional(readOnly = false)\r
return (Map)originalSourceDao.saveAll((Collection)newInstances);\r
}\r
\r
+ @Override\r
+ @Transactional(readOnly = false)\r
+ public <T extends CdmBase> Map<UUID,T> saveOrUpdate(Collection<T> newInstances) {\r
+ //this is very ugly, I know, but for now I do not want to copy the saveAll method from CdmEntityDaoBase to genericDao\r
+ //and generally the saveAll method should work for other CdmBase types with generics removed\r
+ return (Map)originalSourceDao.saveOrUpdateAll((Collection)newInstances);\r
+ }\r
+\r
\r
@Override\r
public <T extends CdmBase> boolean isMergeable(T cdmBase1, T cdmBase2, IMergeStrategy mergeStrategy) throws MergeException {\r
return genericDao.isMergeable(cdmBase1, cdmBase2, mergeStrategy);\r
}\r
-
+\r
}\r