#4932 Remove autowired members, Use serliaised cdm model map
[taxeditor.git] / eu.etaxonomy.taxeditor.cdmlib / src / main / java / eu / etaxonomy / taxeditor / service / CachedCommonServiceImpl.java
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 // if(cacheEnabled) {
47 CdmBase cdmEntity = CdmApplicationState.getCurrentAppConfig().getCommonService().find(clazz, id, getPropertyPaths(clazz));
48 if(cdmEntity == null) {
49 throw new NullPointerException("CDM Entity of type " + clazz.getName() + " with id " + id + " is null.");
50 }
51 return cdmEntity;
52 //return cdmEntitySessionManager.load(cdmEntity, false);
53 // } else {
54 // return CdmBase.deproxy(commonService.find(clazz, id),clazz);
55 // }
56 }
57
58
59 private List<String> getPropertyPaths(Object obj) {
60 List<String> propertyPaths = null;
61 ICdmEntitySession cdmEntitySession =
62 ((CdmApplicationRemoteController)CdmApplicationState.getCurrentAppConfig()).getCdmEntitySessionManager().getActiveSession();
63 if(cdmEntitySession != null) {
64 propertyPaths = cdmEntitySession.getPropertyPaths(obj);
65 }
66 return propertyPaths;
67 }
68
69 /* (non-Javadoc)
70 * @see eu.etaxonomy.taxeditor.service.ICachedCommonService#initializeCollection(java.util.UUID, java.lang.String)
71 */
72 @Override
73 public Object initializeCollection(UUID ownerUuid, String fieldName) {
74 return CdmApplicationState.getCurrentAppConfig().getCommonService().initializeCollection(ownerUuid, fieldName, getPropertyPaths(fieldName));
75 }
76
77
78 /* (non-Javadoc)
79 * @see eu.etaxonomy.taxeditor.remoting.service.ICachedCommonService#isEmpty(org.hibernate.collection.spi.PersistentCollection)
80 */
81 @Override
82 public boolean isEmpty(UUID ownerUuid, String fieldName) {
83 return CdmApplicationState.getCurrentAppConfig().getCommonService().isEmpty(ownerUuid, fieldName);
84
85 }
86
87
88 /* (non-Javadoc)
89 * @see eu.etaxonomy.taxeditor.remoting.service.ICachedCommonService#size(org.hibernate.collection.spi.PersistentCollection)
90 */
91 @Override
92 public int size(UUID ownerUuid, String fieldName) {
93 return CdmApplicationState.getCurrentAppConfig().getCommonService().size(ownerUuid, fieldName);
94 }
95
96
97
98 /* (non-Javadoc)
99 * @see eu.etaxonomy.taxeditor.remoting.service.ICachedCommonService#contains(org.hibernate.collection.spi.PersistentCollection, java.lang.Object)
100 */
101 @Override
102 public boolean contains(UUID ownerUuid, String fieldName, Object element) {
103 return CdmApplicationState.getCurrentAppConfig().getCommonService().contains(ownerUuid, fieldName, element);
104 }
105
106
107 /* (non-Javadoc)
108 * @see eu.etaxonomy.taxeditor.remoting.service.ICachedCommonService#containsKey(org.hibernate.collection.spi.PersistentCollection, java.lang.Object)
109 */
110 @Override
111 public boolean containsKey(UUID ownerUuid, String fieldName, Object key) {
112 return CdmApplicationState.getCurrentAppConfig().getCommonService().containsKey(ownerUuid, fieldName, key);
113 }
114
115
116 /* (non-Javadoc)
117 * @see eu.etaxonomy.taxeditor.remoting.service.ICachedCommonService#containsValue(org.hibernate.collection.spi.PersistentCollection, java.lang.Object)
118 */
119 @Override
120 public boolean containsValue(UUID ownerUuid, String fieldName, Object element) {
121 return CdmApplicationState.getCurrentAppConfig().getCommonService().containsValue(ownerUuid, fieldName, element);
122 }
123
124
125
126
127
128
129 }