1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.chemistry.opencmis.client.bindings.impl;
20
21 import static org.apache.chemistry.opencmis.commons.impl.CollectionsHelper.isNotEmpty;
22
23 import java.io.Serializable;
24 import java.math.BigInteger;
25 import java.util.List;
26
27 import org.apache.chemistry.opencmis.client.bindings.cache.TypeDefinitionCache;
28 import org.apache.chemistry.opencmis.client.bindings.spi.BindingSession;
29 import org.apache.chemistry.opencmis.client.bindings.spi.CmisSpi;
30 import org.apache.chemistry.opencmis.commons.data.ExtensionsData;
31 import org.apache.chemistry.opencmis.commons.data.RepositoryInfo;
32 import org.apache.chemistry.opencmis.commons.definitions.TypeDefinition;
33 import org.apache.chemistry.opencmis.commons.definitions.TypeDefinitionContainer;
34 import org.apache.chemistry.opencmis.commons.definitions.TypeDefinitionList;
35 import org.apache.chemistry.opencmis.commons.spi.ExtendedRepositoryService;
36 import org.apache.chemistry.opencmis.commons.spi.RepositoryService;
37
38
39
40
41
42
43 public class RepositoryServiceImpl implements RepositoryService, ExtendedRepositoryService, Serializable {
44
45 private static final long serialVersionUID = 1L;
46
47 private final BindingSession session;
48
49
50
51
52 public RepositoryServiceImpl(BindingSession session) {
53 assert session != null;
54
55 this.session = session;
56 }
57
58 @Override
59 public RepositoryInfo getRepositoryInfo(String repositoryId, ExtensionsData extension) {
60 RepositoryInfo result = null;
61 boolean hasExtension = (extension != null) && isNotEmpty(extension.getExtensions());
62
63 RepositoryInfoCache cache = CmisBindingsHelper.getRepositoryInfoCache(session);
64
65
66 if (!hasExtension) {
67 result = cache.get(repositoryId);
68 if (result != null) {
69 return result;
70 }
71 }
72
73
74 CmisSpi spi = CmisBindingsHelper.getSPI(session);
75 result = spi.getRepositoryService().getRepositoryInfo(repositoryId, extension);
76
77
78 if (!hasExtension) {
79 cache.put(result);
80 }
81
82 return result;
83 }
84
85 @Override
86 public List<RepositoryInfo> getRepositoryInfos(ExtensionsData extension) {
87 List<RepositoryInfo> result = null;
88 boolean hasExtension = (extension != null) && isNotEmpty(extension.getExtensions());
89
90
91 CmisSpi spi = CmisBindingsHelper.getSPI(session);
92 result = spi.getRepositoryService().getRepositoryInfos(extension);
93
94
95 if (!hasExtension && (result != null)) {
96 RepositoryInfoCache cache = CmisBindingsHelper.getRepositoryInfoCache(session);
97 for (RepositoryInfo rid : result) {
98 cache.put(rid);
99 }
100 }
101
102 return result;
103 }
104
105 @Override
106 public TypeDefinitionList getTypeChildren(String repositoryId, String typeId, Boolean includePropertyDefinitions,
107 BigInteger maxItems, BigInteger skipCount, ExtensionsData extension) {
108 TypeDefinitionList result = null;
109 boolean hasExtension = (extension != null) && isNotEmpty(extension.getExtensions());
110 boolean propDefs = (includePropertyDefinitions == null ? false : includePropertyDefinitions.booleanValue());
111
112
113 CmisSpi spi = CmisBindingsHelper.getSPI(session);
114 result = spi.getRepositoryService().getTypeChildren(repositoryId, typeId, includePropertyDefinitions, maxItems,
115 skipCount, extension);
116
117
118 if (!hasExtension && propDefs && (result != null)) {
119 TypeDefinitionCache cache = CmisBindingsHelper.getTypeDefinitionCache(session);
120
121 for (TypeDefinition tdd : result.getList()) {
122 cache.put(repositoryId, tdd);
123 }
124 }
125
126 return result;
127 }
128
129 @Override
130 public TypeDefinition getTypeDefinition(String repositoryId, String typeId, ExtensionsData extension) {
131 return getTypeDefinition(repositoryId, typeId, extension, true);
132 }
133
134 @Override
135 public TypeDefinition getTypeDefinition(String repositoryId, String typeId, ExtensionsData extension,
136 boolean useCache) {
137 TypeDefinition result = null;
138 boolean hasExtension = (extension != null) && isNotEmpty(extension.getExtensions());
139
140 TypeDefinitionCache cache = CmisBindingsHelper.getTypeDefinitionCache(session);
141
142
143
144 if (useCache && !hasExtension) {
145 result = cache.get(repositoryId, typeId);
146 if (result != null) {
147 return result;
148 }
149 }
150
151
152 CmisSpi spi = CmisBindingsHelper.getSPI(session);
153 result = spi.getRepositoryService().getTypeDefinition(repositoryId, typeId, extension);
154
155
156 if (!hasExtension && (result != null)) {
157 cache.put(repositoryId, result);
158 }
159
160 return result;
161 }
162
163 @Override
164 public List<TypeDefinitionContainer> getTypeDescendants(String repositoryId, String typeId, BigInteger depth,
165 Boolean includePropertyDefinitions, ExtensionsData extension) {
166 List<TypeDefinitionContainer> result = null;
167 boolean hasExtension = (extension != null) && isNotEmpty(extension.getExtensions());
168 boolean propDefs = includePropertyDefinitions == null ? false : includePropertyDefinitions.booleanValue();
169
170
171 CmisSpi spi = CmisBindingsHelper.getSPI(session);
172 result = spi.getRepositoryService().getTypeDescendants(repositoryId, typeId, depth, includePropertyDefinitions,
173 extension);
174
175
176 if (!hasExtension && propDefs && (result != null)) {
177 TypeDefinitionCache cache = CmisBindingsHelper.getTypeDefinitionCache(session);
178 addToTypeCache(cache, repositoryId, result);
179 }
180
181 return result;
182 }
183
184 private void addToTypeCache(TypeDefinitionCache cache, String repositoryId, List<TypeDefinitionContainer> containers) {
185 if (containers == null) {
186 return;
187 }
188
189 for (TypeDefinitionContainer container : containers) {
190 cache.put(repositoryId, container.getTypeDefinition());
191 addToTypeCache(cache, repositoryId, container.getChildren());
192 }
193 }
194
195 @Override
196 public TypeDefinition createType(String repositoryId, TypeDefinition type, ExtensionsData extension) {
197
198 CmisSpi spi = CmisBindingsHelper.getSPI(session);
199 TypeDefinition result = spi.getRepositoryService().createType(repositoryId, type, extension);
200
201
202 TypeDefinitionCache cache = CmisBindingsHelper.getTypeDefinitionCache(session);
203 cache.put(repositoryId, result);
204
205 return result;
206 }
207
208 @Override
209 public TypeDefinition updateType(String repositoryId, TypeDefinition type, ExtensionsData extension) {
210
211 CmisSpi spi = CmisBindingsHelper.getSPI(session);
212 TypeDefinition result = spi.getRepositoryService().updateType(repositoryId, type, extension);
213
214
215 TypeDefinitionCache cache = CmisBindingsHelper.getTypeDefinitionCache(session);
216 cache.put(repositoryId, result);
217
218 return result;
219 }
220
221 @Override
222 public void deleteType(String repositoryId, String typeId, ExtensionsData extension) {
223
224 CmisSpi spi = CmisBindingsHelper.getSPI(session);
225 spi.getRepositoryService().deleteType(repositoryId, typeId, extension);
226
227
228 TypeDefinitionCache cache = CmisBindingsHelper.getTypeDefinitionCache(session);
229 cache.remove(repositoryId, typeId);
230 }
231
232 }