1
|
// $Id$
|
2
|
/**
|
3
|
* Copyright (C) 2007 EDIT
|
4
|
* European Distributed Institute of Taxonomy
|
5
|
* http://www.e-taxonomy.eu
|
6
|
*
|
7
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
8
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
9
|
*/
|
10
|
|
11
|
package eu.etaxonomy.cdm.api.service;
|
12
|
|
13
|
import java.util.ArrayList;
|
14
|
import java.util.List;
|
15
|
|
16
|
import org.apache.log4j.Logger;
|
17
|
import org.springframework.beans.factory.annotation.Autowired;
|
18
|
import org.springframework.stereotype.Service;
|
19
|
import org.springframework.transaction.annotation.Transactional;
|
20
|
|
21
|
import eu.etaxonomy.cdm.model.common.CdmBase;
|
22
|
import eu.etaxonomy.cdm.model.metadata.CdmPreference;
|
23
|
import eu.etaxonomy.cdm.model.metadata.CdmPreference.PrefKey;
|
24
|
import eu.etaxonomy.cdm.model.metadata.PreferencePredicate;
|
25
|
import eu.etaxonomy.cdm.model.metadata.PreferenceSubject;
|
26
|
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
|
27
|
import eu.etaxonomy.cdm.persistence.dao.common.IPreferenceDao;
|
28
|
|
29
|
/**
|
30
|
* @author a.mueller
|
31
|
* @created 2013-09-09
|
32
|
*/
|
33
|
@Service
|
34
|
@Transactional(readOnly = true)
|
35
|
public class PreferenceServiceImpl implements IPreferenceService {
|
36
|
|
37
|
@SuppressWarnings("unused")
|
38
|
private static final Logger logger = Logger.getLogger(PreferenceServiceImpl.class);
|
39
|
|
40
|
@Autowired
|
41
|
private IPreferenceDao dao;
|
42
|
|
43
|
@Override
|
44
|
public CdmPreference find(PrefKey key) {
|
45
|
List<PrefKey> keys = new ArrayList<>();
|
46
|
keys.add(key);
|
47
|
// while(key.) TODO
|
48
|
|
49
|
return dao.get(key);
|
50
|
}
|
51
|
|
52
|
/**
|
53
|
* Retrieve the database wide preference for the given predicate.
|
54
|
* @param key
|
55
|
* @return
|
56
|
*/
|
57
|
@Override
|
58
|
public CdmPreference findDatabase(PreferencePredicate predicate){
|
59
|
PrefKey key = CdmPreference.NewKey(PreferenceSubject.NewDatabaseInstance(), predicate);
|
60
|
return find(key);
|
61
|
}
|
62
|
|
63
|
|
64
|
@Override
|
65
|
@Transactional(readOnly = false)
|
66
|
public void set(CdmPreference preference) {
|
67
|
dao.set(preference);
|
68
|
}
|
69
|
|
70
|
@Override
|
71
|
public int count() {
|
72
|
return dao.count();
|
73
|
}
|
74
|
|
75
|
@Override
|
76
|
public List<CdmPreference> list() {
|
77
|
return dao.list();
|
78
|
}
|
79
|
|
80
|
@Override
|
81
|
public Object find(TaxonNode taxonNode, String predicate) {
|
82
|
return dao.find(taxonNode, predicate);
|
83
|
}
|
84
|
|
85
|
@Override
|
86
|
public CdmPreference find(TaxonNode taxonNode, PreferencePredicate predicate){
|
87
|
return dao.find(taxonNode, predicate.getKey());
|
88
|
}
|
89
|
|
90
|
|
91
|
// ********************** NOT YET HANDLED *******************/
|
92
|
|
93
|
|
94
|
@Override
|
95
|
public List<CdmPreference> list(String subject, String predicate) {
|
96
|
//FIXME
|
97
|
throw new RuntimeException("list(String, String) not yet implemented" );
|
98
|
}
|
99
|
|
100
|
@Override
|
101
|
//this method is only partly implemented
|
102
|
public CdmPreference find(CdmBase taxonNodeRelatedCdmBase, String predicate) {
|
103
|
TaxonNode taxonNode = mapToTaxonNode(taxonNodeRelatedCdmBase);
|
104
|
return dao.find(taxonNode, predicate);
|
105
|
}
|
106
|
|
107
|
/**
|
108
|
* @param taxonNodeRelatedCdmBase
|
109
|
* @return
|
110
|
*/
|
111
|
private TaxonNode mapToTaxonNode(CdmBase taxonNodeRelatedCdmBase) {
|
112
|
if (taxonNodeRelatedCdmBase == null){
|
113
|
return null;
|
114
|
}else if (taxonNodeRelatedCdmBase.isInstanceOf(TaxonNode.class)){
|
115
|
return CdmBase.deproxy(taxonNodeRelatedCdmBase, TaxonNode.class);
|
116
|
}else{
|
117
|
throw new RuntimeException("mapToTaxonNode not yet implemented for " + taxonNodeRelatedCdmBase.getClass().getSimpleName());
|
118
|
}
|
119
|
}
|
120
|
|
121
|
|
122
|
// @Override
|
123
|
// public String setCdmPrefs(CdmBase cdmBase, String predicate, String value) {
|
124
|
// // TODO Auto-generated method stub
|
125
|
// return null;
|
126
|
// }
|
127
|
|
128
|
|
129
|
}
|