Project

General

Profile

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

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

    
14
import org.springframework.stereotype.Component;
15

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

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

    
28

    
29
    private static boolean cacheEnabled = true;
30

    
31
    public static boolean isCacheEnabled() {
32
        return cacheEnabled;
33
    }
34

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

    
39
    @Override
40
    public CdmBase find(Class<? extends CdmBase> clazz, int id) {
41
        CdmBase cdmEntity = CdmApplicationState.getCurrentAppConfig().getCommonService().find(clazz, id, getPropertyPaths(clazz));
42
        if(cdmEntity == null) {
43
            throw new NullPointerException("CDM Entity of type " + clazz.getName() + " with id " + id  + " is null.");
44
        }
45
        return cdmEntity;
46
    }
47

    
48

    
49
    private List<String> getPropertyPaths(Object obj) {
50
        List<String> propertyPaths = null;
51
        ICdmEntitySession cdmEntitySession =
52
                ((CdmApplicationRemoteController)CdmApplicationState.getCurrentAppConfig()).getCdmEntitySessionManager().getActiveSession();
53
        if(cdmEntitySession != null) {
54
            propertyPaths = cdmEntitySession.getPropertyPaths(obj);
55
        }
56
        return propertyPaths;
57
    }
58

    
59
    @Override
60
    public Object initializeCollection(UUID ownerUuid, String fieldName) {
61
        return  CdmApplicationState.getCurrentAppConfig().getCommonService().initializeCollection(ownerUuid, fieldName, getPropertyPaths(fieldName));
62
    }
63

    
64
    @Override
65
    public boolean isEmpty(UUID ownerUuid, String fieldName) {
66
            return  CdmApplicationState.getCurrentAppConfig().getCommonService().isEmpty(ownerUuid, fieldName);
67
    }
68

    
69
    @Override
70
    public int size(UUID ownerUuid, String fieldName) {
71
        return  CdmApplicationState.getCurrentAppConfig().getCommonService().size(ownerUuid, fieldName);
72
    }
73

    
74
    @Override
75
    public boolean contains(UUID ownerUuid, String fieldName, Object element) {
76
        return  CdmApplicationState.getCurrentAppConfig().getCommonService().contains(ownerUuid, fieldName, element);
77
    }
78

    
79
    @Override
80
    public boolean containsKey(UUID ownerUuid, String fieldName, Object key) {
81
        return  CdmApplicationState.getCurrentAppConfig().getCommonService().containsKey(ownerUuid, fieldName, key);
82
    }
83

    
84
    @Override
85
    public boolean containsValue(UUID ownerUuid, String fieldName, Object element) {
86
        return  CdmApplicationState.getCurrentAppConfig().getCommonService().containsValue(ownerUuid, fieldName, element);
87
    }
88

    
89
}
(1-1/6)