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
|
private static boolean cacheEnabled = true;
|
29
|
|
30
|
public static boolean isCacheEnabled() {
|
31
|
return cacheEnabled;
|
32
|
}
|
33
|
|
34
|
public static void setCacheEnabled(boolean cacheEnabled) {
|
35
|
CachedCommonServiceImpl.cacheEnabled = cacheEnabled;
|
36
|
}
|
37
|
|
38
|
@Override
|
39
|
public CdmBase find(Class<? extends CdmBase> clazz, int id) {
|
40
|
CdmBase cdmEntity = CdmApplicationState.getCurrentAppConfig().getCommonService().find(clazz, id, getPropertyPaths(clazz));
|
41
|
if(cdmEntity == null) {
|
42
|
throw new NullPointerException("CDM Entity of type " + clazz.getName() + " with id " + id + " is null.");
|
43
|
}
|
44
|
return cdmEntity;
|
45
|
}
|
46
|
|
47
|
private List<String> getPropertyPaths(Object obj) {
|
48
|
List<String> propertyPaths = null;
|
49
|
ICdmEntitySession cdmEntitySession =
|
50
|
((CdmApplicationRemoteController)CdmApplicationState.getCurrentAppConfig()).getCdmEntitySessionManager().getActiveSession();
|
51
|
if(cdmEntitySession != null) {
|
52
|
propertyPaths = cdmEntitySession.getPropertyPaths(obj);
|
53
|
}
|
54
|
return propertyPaths;
|
55
|
}
|
56
|
|
57
|
@Override
|
58
|
public Object initializeCollection(UUID ownerUuid, String fieldName) {
|
59
|
return CdmApplicationState.getCurrentAppConfig().getCommonService().initializeCollection(ownerUuid, fieldName, getPropertyPaths(fieldName));
|
60
|
}
|
61
|
|
62
|
@Override
|
63
|
public boolean isEmpty(UUID ownerUuid, String fieldName) {
|
64
|
return CdmApplicationState.getCurrentAppConfig().getCommonService().isEmpty(ownerUuid, fieldName);
|
65
|
}
|
66
|
|
67
|
@Override
|
68
|
public int size(UUID ownerUuid, String fieldName) {
|
69
|
return CdmApplicationState.getCurrentAppConfig().getCommonService().size(ownerUuid, fieldName);
|
70
|
}
|
71
|
|
72
|
@Override
|
73
|
public boolean contains(UUID ownerUuid, String fieldName, Object element) {
|
74
|
return CdmApplicationState.getCurrentAppConfig().getCommonService().contains(ownerUuid, fieldName, element);
|
75
|
}
|
76
|
|
77
|
@Override
|
78
|
public boolean containsKey(UUID ownerUuid, String fieldName, Object key) {
|
79
|
return CdmApplicationState.getCurrentAppConfig().getCommonService().containsKey(ownerUuid, fieldName, key);
|
80
|
}
|
81
|
|
82
|
@Override
|
83
|
public boolean containsValue(UUID ownerUuid, String fieldName, Object element) {
|
84
|
return CdmApplicationState.getCurrentAppConfig().getCommonService().containsValue(ownerUuid, fieldName, element);
|
85
|
}
|
86
|
|
87
|
}
|