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.IPreferencePredicate;
|
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(IPreferencePredicate<?> 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(IPreferencePredicate<?> predicate){
|
65
|
PrefKey key = CdmPreference.NewKey(PreferenceSubject.NewVaadinInstance(), predicate);
|
66
|
return find(key);
|
67
|
}
|
68
|
|
69
|
@Override
|
70
|
public CdmPreference findTaxEditor(IPreferencePredicate<?> predicate){
|
71
|
PrefKey key = CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), predicate);
|
72
|
return find(key);
|
73
|
}
|
74
|
|
75
|
|
76
|
@Override
|
77
|
@Transactional(readOnly = false)
|
78
|
public void set(CdmPreference preference) {
|
79
|
dao.set(preference);
|
80
|
}
|
81
|
|
82
|
@Override
|
83
|
public long count() {
|
84
|
return dao.count();
|
85
|
}
|
86
|
|
87
|
@Override
|
88
|
public List<CdmPreference> list() {
|
89
|
return dao.list();
|
90
|
}
|
91
|
|
92
|
@Override
|
93
|
public Object find(TaxonNode taxonNode, String predicate) {
|
94
|
return dao.find(taxonNode, predicate);
|
95
|
}
|
96
|
|
97
|
@Override
|
98
|
public CdmPreference find(TaxonNode taxonNode, IPreferencePredicate<?> predicate){
|
99
|
return dao.find(taxonNode, predicate.getKey());
|
100
|
}
|
101
|
|
102
|
|
103
|
// ********************** NOT YET HANDLED *******************/
|
104
|
|
105
|
|
106
|
@Override
|
107
|
public List<CdmPreference> list(String subject, String predicate) {
|
108
|
//FIXME
|
109
|
throw new RuntimeException("list(String, String) not yet implemented" );
|
110
|
}
|
111
|
|
112
|
@Override
|
113
|
//this method is only partly implemented
|
114
|
public CdmPreference find(CdmBase taxonNodeRelatedCdmBase, String predicate) {
|
115
|
TaxonNode taxonNode = mapToTaxonNode(taxonNodeRelatedCdmBase);
|
116
|
return dao.find(taxonNode, predicate);
|
117
|
}
|
118
|
|
119
|
/**
|
120
|
* @param taxonNodeRelatedCdmBase
|
121
|
* @return
|
122
|
*/
|
123
|
private TaxonNode mapToTaxonNode(CdmBase taxonNodeRelatedCdmBase) {
|
124
|
if (taxonNodeRelatedCdmBase == null){
|
125
|
return null;
|
126
|
}else if (taxonNodeRelatedCdmBase.isInstanceOf(TaxonNode.class)){
|
127
|
return CdmBase.deproxy(taxonNodeRelatedCdmBase, TaxonNode.class);
|
128
|
}else{
|
129
|
throw new RuntimeException("mapToTaxonNode not yet implemented for " + taxonNodeRelatedCdmBase.getClass().getSimpleName());
|
130
|
}
|
131
|
}
|
132
|
|
133
|
|
134
|
// @Override
|
135
|
// public String setCdmPrefs(CdmBase cdmBase, String predicate, String value) {
|
136
|
// // TODO Auto-generated method stub
|
137
|
// return null;
|
138
|
// }
|
139
|
|
140
|
|
141
|
}
|