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