Project

General

Profile

Download (4.23 KB) Statistics
| Branch: | Tag: | Revision:
1
// $Id$
2
/**
3
* Copyright (C) 2014 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
package eu.etaxonomy.taxeditor.service;
11

    
12
import java.util.List;
13
import java.util.UUID;
14

    
15
import org.springframework.stereotype.Component;
16

    
17
import eu.etaxonomy.cdm.api.application.CdmApplicationRemoteController;
18
import eu.etaxonomy.cdm.api.application.CdmApplicationState;
19
import eu.etaxonomy.cdm.model.common.CdmBase;
20
import eu.etaxonomy.taxeditor.session.ICdmEntitySession;
21

    
22
/**
23
 * @author cmathew
24
 * @date 14 Oct 2014
25
 *
26
 */
27
@Component
28
public class CachedCommonServiceImpl implements ICachedCommonService {
29

    
30

    
31
    private static boolean cacheEnabled = true;
32

    
33
    public static boolean isCacheEnabled() {
34
        return cacheEnabled;
35
    }
36

    
37
    public static void setCacheEnabled(boolean cacheEnabled) {
38
        CachedCommonServiceImpl.cacheEnabled = cacheEnabled;
39
    }
40

    
41
    /* (non-Javadoc)
42
     * @see eu.etaxonomy.taxeditor.remoting.service.ICachedCommonService#find(java.lang.Class, int)
43
     */
44
    @Override
45
    public CdmBase find(Class<? extends CdmBase> clazz, int id) {
46
        CdmBase cdmEntity = CdmApplicationState.getCurrentAppConfig().getCommonService().find(clazz, id, getPropertyPaths(clazz));
47
        if(cdmEntity == null) {
48
            throw new NullPointerException("CDM Entity of type " + clazz.getName() + " with id " + id  + " is null.");
49
        }
50
        return cdmEntity;
51

    
52
    }
53

    
54

    
55
    private List<String> getPropertyPaths(Object obj) {
56
        List<String> propertyPaths = null;
57
        ICdmEntitySession cdmEntitySession =
58
                ((CdmApplicationRemoteController)CdmApplicationState.getCurrentAppConfig()).getCdmEntitySessionManager().getActiveSession();
59
        if(cdmEntitySession != null) {
60
            propertyPaths = cdmEntitySession.getPropertyPaths(obj);
61
        }
62
        return propertyPaths;
63
    }
64

    
65
    /* (non-Javadoc)
66
     * @see eu.etaxonomy.taxeditor.service.ICachedCommonService#initializeCollection(java.util.UUID, java.lang.String)
67
     */
68
    @Override
69
    public Object initializeCollection(UUID ownerUuid, String fieldName) {
70
        return  CdmApplicationState.getCurrentAppConfig().getCommonService().initializeCollection(ownerUuid, fieldName, getPropertyPaths(fieldName));
71
    }
72

    
73

    
74
    /* (non-Javadoc)
75
     * @see eu.etaxonomy.taxeditor.remoting.service.ICachedCommonService#isEmpty(org.hibernate.collection.spi.PersistentCollection)
76
     */
77
    @Override
78
    public boolean isEmpty(UUID ownerUuid, String fieldName) {
79
            return  CdmApplicationState.getCurrentAppConfig().getCommonService().isEmpty(ownerUuid, fieldName);
80

    
81
    }
82

    
83

    
84
    /* (non-Javadoc)
85
     * @see eu.etaxonomy.taxeditor.remoting.service.ICachedCommonService#size(org.hibernate.collection.spi.PersistentCollection)
86
     */
87
    @Override
88
    public int size(UUID ownerUuid, String fieldName) {
89
        return  CdmApplicationState.getCurrentAppConfig().getCommonService().size(ownerUuid, fieldName);
90
    }
91

    
92

    
93

    
94
    /* (non-Javadoc)
95
     * @see eu.etaxonomy.taxeditor.remoting.service.ICachedCommonService#contains(org.hibernate.collection.spi.PersistentCollection, java.lang.Object)
96
     */
97
    @Override
98
    public boolean contains(UUID ownerUuid, String fieldName, Object element) {
99
        return  CdmApplicationState.getCurrentAppConfig().getCommonService().contains(ownerUuid, fieldName, element);
100
    }
101

    
102

    
103
    /* (non-Javadoc)
104
     * @see eu.etaxonomy.taxeditor.remoting.service.ICachedCommonService#containsKey(org.hibernate.collection.spi.PersistentCollection, java.lang.Object)
105
     */
106
    @Override
107
    public boolean containsKey(UUID ownerUuid, String fieldName, Object key) {
108
        return  CdmApplicationState.getCurrentAppConfig().getCommonService().containsKey(ownerUuid, fieldName, key);
109
    }
110

    
111

    
112
    /* (non-Javadoc)
113
     * @see eu.etaxonomy.taxeditor.remoting.service.ICachedCommonService#containsValue(org.hibernate.collection.spi.PersistentCollection, java.lang.Object)
114
     */
115
    @Override
116
    public boolean containsValue(UUID ownerUuid, String fieldName, Object element) {
117
        return  CdmApplicationState.getCurrentAppConfig().getCommonService().containsValue(ownerUuid, fieldName, element);
118
    }
119

    
120

    
121

    
122

    
123

    
124

    
125
}
(1-1/6)