2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
10 package eu
.etaxonomy
.cdm
.api
.service
;
12 import java
.util
.ArrayList
;
13 import java
.util
.List
;
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
;
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
;
33 @Transactional(readOnly
= true)
34 public class PreferenceServiceImpl
implements IPreferenceService
{
36 @SuppressWarnings("unused")
37 private static final Logger logger
= Logger
.getLogger(PreferenceServiceImpl
.class);
40 private IPreferenceDao dao
;
43 public CdmPreference
find(PrefKey key
) {
44 List
<PrefKey
> keys
= new ArrayList
<>();
55 public CdmPreference
findDatabase(PreferencePredicate predicate
){
56 PrefKey key
= CdmPreference
.NewKey(PreferenceSubject
.NewDatabaseInstance(), predicate
);
64 public CdmPreference
findVaadin(PreferencePredicate predicate
){
65 PrefKey key
= CdmPreference
.NewKey(PreferenceSubject
.NewVaadinInstance(), predicate
);
71 @Transactional(readOnly
= false)
72 public void set(CdmPreference preference
) {
82 public List
<CdmPreference
> list() {
87 public Object
find(TaxonNode taxonNode
, String predicate
) {
88 return dao
.find(taxonNode
, predicate
);
92 public CdmPreference
find(TaxonNode taxonNode
, PreferencePredicate predicate
){
93 return dao
.find(taxonNode
, predicate
.getKey());
97 // ********************** NOT YET HANDLED *******************/
101 public List
<CdmPreference
> list(String subject
, String predicate
) {
103 throw new RuntimeException("list(String, String) not yet implemented" );
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
);
114 * @param taxonNodeRelatedCdmBase
117 private TaxonNode
mapToTaxonNode(CdmBase taxonNodeRelatedCdmBase
) {
118 if (taxonNodeRelatedCdmBase
== null){
120 }else if (taxonNodeRelatedCdmBase
.isInstanceOf(TaxonNode
.class)){
121 return CdmBase
.deproxy(taxonNodeRelatedCdmBase
, TaxonNode
.class);
123 throw new RuntimeException("mapToTaxonNode not yet implemented for " + taxonNodeRelatedCdmBase
.getClass().getSimpleName());
129 // public String setCdmPrefs(CdmBase cdmBase, String predicate, String value) {
130 // // TODO Auto-generated method stub