This project has retired. For details please refer to its
Attic page.
UnitTestTypeSystemCreator xref
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.chemistry.opencmis.inmemory;
20
21
22
23
24
25
26 import java.util.ArrayList;
27 import java.util.Collections;
28 import java.util.HashMap;
29 import java.util.LinkedList;
30 import java.util.List;
31 import java.util.Map;
32
33 import org.apache.chemistry.opencmis.commons.definitions.Choice;
34 import org.apache.chemistry.opencmis.commons.definitions.PropertyDefinition;
35 import org.apache.chemistry.opencmis.commons.definitions.TypeDefinition;
36 import org.apache.chemistry.opencmis.commons.enums.Updatability;
37 import org.apache.chemistry.opencmis.commons.impl.dataobjects.ChoiceImpl;
38 import org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyDateTimeDefinitionImpl;
39 import org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyDecimalDefinitionImpl;
40 import org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyHtmlDefinitionImpl;
41 import org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyIdDefinitionImpl;
42 import org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyIntegerDefinitionImpl;
43 import org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyStringDefinitionImpl;
44 import org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyUriDefinitionImpl;
45 import org.apache.chemistry.opencmis.inmemory.types.InMemoryDocumentTypeDefinition;
46 import org.apache.chemistry.opencmis.inmemory.types.InMemoryFolderTypeDefinition;
47 import org.apache.chemistry.opencmis.inmemory.types.PropertyCreationHelper;
48
49 public class UnitTestTypeSystemCreator implements TypeCreator {
50 public static final List<TypeDefinition> singletonTypes = buildTypesList();
51 public static final String COMPLEX_TYPE = "ComplexType";
52 public static final String TOPLEVEL_TYPE = "DocumentTopLevel";
53 public static final String LEVEL1_TYPE = "DocumentLevel1";
54 public static final String LEVEL2_TYPE = "DocumentLevel2";
55 public static final String VERSIONED_TYPE = "MyVersionedType";
56 public static final String VERSION_PROPERTY_ID = "StringProp";
57 public static final String FOLDER_TYPE = "FolderType";
58
59 public static final String PROP_ID_BOOLEAN = "BooleanProp";
60 public static final String PROP_ID_DATETIME = "DateTimeProp";
61 public static final String PROP_ID_DECIMAL = "DecimalProp";
62 public static final String PROP_ID_HTML = "HtmlProp";
63 public static final String PROP_ID_ID = "IdProp";
64 public static final String PROP_ID_INT = "IntProp";
65 public static final String PROP_ID_STRING = "StringProp";
66 public static final String PROP_ID_URI = "UriProp";
67 public static final String PROP_ID_BOOLEAN_MULTI_VALUE = "BooleanPropMV";
68 public static final String PROP_ID_DATETIME_MULTI_VALUE = "DateTimePropMV";
69 public static final String PROP_ID_DECIMAL_MULTI_VALUE = "DecimalPropMV";
70 public static final String PROP_ID_HTML_MULTI_VALUE = "HtmlPropMV";
71 public static final String PROP_ID_ID_MULTI_VALUE = "IdPropMV";
72 public static final String PROP_ID_INT_MULTI_VALUE = "IntPropMV";
73 public static final String PROP_ID_STRING_MULTI_VALUE = "StringPropMV";
74 public static final String PROP_ID_URI_MULTI_VALUE = "UriPropMV";
75
76
77
78
79
80 public List<TypeDefinition> createTypesList() {
81 return singletonTypes;
82 }
83
84 public static List<TypeDefinition> getTypesList() {
85 return singletonTypes;
86 }
87
88 public static TypeDefinition getTypeById(String typeId) {
89 for (TypeDefinition typeDef : singletonTypes)
90 if (typeDef.getId().equals(typeId))
91 return typeDef;
92 return null;
93 }
94
95
96
97
98
99
100 private static List<TypeDefinition> buildTypesList() {
101
102 List<TypeDefinition> typesList = new LinkedList<TypeDefinition>();
103
104 InMemoryDocumentTypeDefinition cmisType1 = new InMemoryDocumentTypeDefinition("MyDocType1",
105 "My Type 1 Level 1", InMemoryDocumentTypeDefinition.getRootDocumentType());
106 typesList.add(cmisType1);
107
108 InMemoryDocumentTypeDefinition cmisType2 = new InMemoryDocumentTypeDefinition("MyDocType2",
109 "My Type 2 Level 1", InMemoryDocumentTypeDefinition.getRootDocumentType());
110 typesList.add(cmisType2);
111
112 InMemoryDocumentTypeDefinition cmisType11 = new InMemoryDocumentTypeDefinition("MyDocType1.1",
113 "My Type 3 Level 2", cmisType1);
114 typesList.add(cmisType11);
115
116 InMemoryDocumentTypeDefinition cmisType111 = new InMemoryDocumentTypeDefinition("MyDocType1.1.1",
117 "My Type 4 Level 3", cmisType11);
118 typesList.add(cmisType111);
119
120 InMemoryDocumentTypeDefinition cmisType112 = new InMemoryDocumentTypeDefinition("MyDocType1.1.2",
121 "My Type 5 Level 3", cmisType11);
122 typesList.add(cmisType112);
123
124 InMemoryDocumentTypeDefinition cmisType12 = new InMemoryDocumentTypeDefinition("MyDocType1.2",
125 "My Type 6 Level 2", cmisType1);
126 typesList.add(cmisType12);
127
128 InMemoryDocumentTypeDefinition cmisType21 = new InMemoryDocumentTypeDefinition("MyDocType2.1",
129 "My Type 7 Level 2", cmisType2);
130 typesList.add(cmisType21);
131
132 InMemoryDocumentTypeDefinition cmisType22 = new InMemoryDocumentTypeDefinition("MyDocType2.2",
133 "My Type 8 Level 2", cmisType2);
134 typesList.add(cmisType22);
135 InMemoryDocumentTypeDefinition cmisType23 = new InMemoryDocumentTypeDefinition("MyDocType2.3",
136 "My Type 9 Level 2", cmisType2);
137 typesList.add(cmisType23);
138 InMemoryDocumentTypeDefinition cmisType24 = new InMemoryDocumentTypeDefinition("MyDocType2.4",
139 "My Type 10 Level 2", cmisType2);
140 typesList.add(cmisType24);
141 InMemoryDocumentTypeDefinition cmisType25 = new InMemoryDocumentTypeDefinition("MyDocType2.5",
142 "My Type 11 Level 2", cmisType2);
143 typesList.add(cmisType25);
144
145 InMemoryDocumentTypeDefinition cmisType26 = new InMemoryDocumentTypeDefinition("MyDocType2.6",
146 "My Type 12 Level 2", cmisType2);
147 typesList.add(cmisType26);
148 InMemoryDocumentTypeDefinition cmisType27 = new InMemoryDocumentTypeDefinition("MyDocType2.7",
149 "My Type 13 Level 2", cmisType2);
150 typesList.add(cmisType27);
151 InMemoryDocumentTypeDefinition cmisType28 = new InMemoryDocumentTypeDefinition("MyDocType2.8",
152 "My Type 14 Level 2", cmisType2);
153 typesList.add(cmisType28);
154 InMemoryDocumentTypeDefinition cmisType29 = new InMemoryDocumentTypeDefinition("MyDocType2.9",
155 "My Type 15 Level 2", cmisType2);
156 typesList.add(cmisType29);
157
158
159 InMemoryDocumentTypeDefinition cmisComplexType = new InMemoryDocumentTypeDefinition(COMPLEX_TYPE,
160 "Complex type with properties, Level 1", InMemoryDocumentTypeDefinition.getRootDocumentType());
161
162
163
164 Map<String, PropertyDefinition<?>> propertyDefinitions = new HashMap<String, PropertyDefinition<?>>();
165
166 PropertyDefinition<Boolean> prop = PropertyCreationHelper.createBooleanDefinition(PROP_ID_BOOLEAN,
167 "Sample Boolean Property", Updatability.READONLY);
168 propertyDefinitions.put(prop.getId(), prop);
169
170 prop = PropertyCreationHelper.createBooleanMultiDefinition(PROP_ID_BOOLEAN_MULTI_VALUE,
171 "Sample Boolean multi-value Property", Updatability.READONLY);
172 propertyDefinitions.put(prop.getId(), prop);
173
174 PropertyDateTimeDefinitionImpl prop2 = PropertyCreationHelper.createDateTimeDefinition(PROP_ID_DATETIME,
175 "Sample DateTime Property", Updatability.READONLY);
176 propertyDefinitions.put(prop2.getId(), prop2);
177
178 prop2 = PropertyCreationHelper.createDateTimeMultiDefinition(PROP_ID_DATETIME_MULTI_VALUE,
179 "Sample DateTime multi-value Property", Updatability.READONLY);
180 propertyDefinitions.put(prop2.getId(), prop2);
181
182 PropertyDecimalDefinitionImpl prop3 = PropertyCreationHelper.createDecimalDefinition(PROP_ID_DECIMAL,
183 "Sample Decimal Property", Updatability.READONLY);
184 propertyDefinitions.put(prop3.getId(), prop3);
185
186 prop3 = PropertyCreationHelper.createDecimalMultiDefinition(PROP_ID_DECIMAL_MULTI_VALUE, "Sample Decimal multi-value Property", Updatability.READONLY);
187 propertyDefinitions.put(prop3.getId(), prop3);
188
189 PropertyHtmlDefinitionImpl prop4 = PropertyCreationHelper.createHtmlDefinition(PROP_ID_HTML,
190 "Sample Html Property", Updatability.READONLY);
191 propertyDefinitions.put(prop4.getId(), prop4);
192
193 prop4 = PropertyCreationHelper.createHtmlDefinition(PROP_ID_HTML_MULTI_VALUE, "Sample Html multi-value Property", Updatability.READONLY);
194 propertyDefinitions.put(prop4.getId(), prop4);
195
196 PropertyIdDefinitionImpl prop5 = PropertyCreationHelper.createIdDefinition(PROP_ID_ID, "Sample Id Property", Updatability.READONLY);
197 propertyDefinitions.put(prop5.getId(), prop5);
198
199 prop5 = PropertyCreationHelper.createIdMultiDefinition(PROP_ID_ID_MULTI_VALUE, "Sample Id Html multi-value Property", Updatability.READONLY);
200 propertyDefinitions.put(prop5.getId(), prop5);
201
202 PropertyIntegerDefinitionImpl prop6 = PropertyCreationHelper.createIntegerDefinition(PROP_ID_INT,
203 "Sample Int Property", Updatability.READONLY);
204 propertyDefinitions.put(prop6.getId(), prop6);
205
206 prop6 = PropertyCreationHelper.createIntegerMultiDefinition(PROP_ID_INT_MULTI_VALUE, "Sample Int multi-value Property", Updatability.READONLY);
207 propertyDefinitions.put(prop6.getId(), prop6);
208
209 PropertyStringDefinitionImpl prop7 = PropertyCreationHelper.createStringDefinition(PROP_ID_STRING,
210 "Sample String Property", Updatability.READONLY);
211 propertyDefinitions.put(prop7.getId(), prop7);
212
213 prop7 = PropertyCreationHelper.createStringMultiDefinition(PROP_ID_STRING_MULTI_VALUE,
214 "Sample String multi-value Property", Updatability.READONLY);
215 propertyDefinitions.put(prop7.getId(), prop7);
216
217 PropertyUriDefinitionImpl prop8 = PropertyCreationHelper.createUriDefinition(PROP_ID_URI, "Sample Uri Property", Updatability.READONLY);
218 propertyDefinitions.put(prop8.getId(), prop8);
219
220 prop8 = PropertyCreationHelper.createUriMultiDefinition(PROP_ID_URI_MULTI_VALUE, "Sample Uri multi-value Property", Updatability.READONLY);
221 propertyDefinitions.put(prop8.getId(), prop8);
222
223 PropertyStringDefinitionImpl prop9 = PropertyCreationHelper.createStringDefinition("PickListProp",
224 "Sample Pick List Property", Updatability.READONLY);
225 List<Choice<String>> choiceList = new ArrayList<Choice<String>>();
226 ChoiceImpl<String> elem = new ChoiceImpl<String>();
227 elem.setValue(Collections.singletonList("red"));
228 choiceList.add(elem);
229 elem = new ChoiceImpl<String>();
230 elem.setValue(Collections.singletonList("green"));
231 choiceList.add(elem);
232 elem = new ChoiceImpl<String>();
233 elem.setValue(Collections.singletonList("blue"));
234 choiceList.add(elem);
235 elem = new ChoiceImpl<String>();
236 elem.setValue(Collections.singletonList("black"));
237 choiceList.add(elem);
238 prop9.setChoices(choiceList);
239 prop9.setDefaultValue(Collections.singletonList("blue"));
240 propertyDefinitions.put(prop9.getId(), prop9);
241
242
243
244
245
246
247
248
249
250 cmisComplexType.addCustomPropertyDefinitions(propertyDefinitions);
251
252
253 typesList.add(cmisComplexType);
254
255
256 InMemoryDocumentTypeDefinition cmisDocTypeTopLevel = new InMemoryDocumentTypeDefinition(TOPLEVEL_TYPE,
257 "Document type with properties, Level 1", InMemoryDocumentTypeDefinition.getRootDocumentType());
258
259 InMemoryDocumentTypeDefinition cmisDocTypeLevel1 = new InMemoryDocumentTypeDefinition(LEVEL1_TYPE,
260 "Document type with inherited properties, Level 2", cmisDocTypeTopLevel);
261
262 InMemoryDocumentTypeDefinition cmisDocTypeLevel2 = new InMemoryDocumentTypeDefinition(LEVEL2_TYPE,
263 "Document type with inherited properties, Level 3", cmisDocTypeLevel1);
264
265 propertyDefinitions = new HashMap<String, PropertyDefinition<?>>();
266 PropertyStringDefinitionImpl propTop = PropertyCreationHelper.createStringDefinition("StringPropTopLevel",
267 "Sample String Property", Updatability.READONLY);
268 propertyDefinitions.put(propTop.getId(), propTop);
269 cmisDocTypeTopLevel.addCustomPropertyDefinitions(propertyDefinitions);
270
271 propertyDefinitions = new HashMap<String, PropertyDefinition<?>>();
272 PropertyStringDefinitionImpl propLevel1 = PropertyCreationHelper.createStringDefinition("StringPropLevel1",
273 "String Property Level 1", Updatability.READONLY);
274 propertyDefinitions.put(propLevel1.getId(), propLevel1);
275 cmisDocTypeLevel1.addCustomPropertyDefinitions(propertyDefinitions);
276
277 propertyDefinitions = new HashMap<String, PropertyDefinition<?>>();
278 PropertyStringDefinitionImpl propLevel2 = PropertyCreationHelper.createStringDefinition("StringPropLevel2",
279 "String Property Level 2", Updatability.READONLY);
280 propertyDefinitions.put(propLevel2.getId(), propLevel2);
281 cmisDocTypeLevel2.addCustomPropertyDefinitions(propertyDefinitions);
282
283
284 InMemoryDocumentTypeDefinition cmisVersionedType = new InMemoryDocumentTypeDefinition(VERSIONED_TYPE,
285 "VersionedType", InMemoryDocumentTypeDefinition.getRootDocumentType());
286
287
288
289 propertyDefinitions = new HashMap<String, PropertyDefinition<?>>();
290
291 PropertyStringDefinitionImpl prop1 = PropertyCreationHelper.createStringDefinition(VERSION_PROPERTY_ID,
292 "Sample String Property", Updatability.READONLY);
293 propertyDefinitions.put(prop1.getId(), prop1);
294
295 cmisVersionedType.addCustomPropertyDefinitions(propertyDefinitions);
296 cmisVersionedType.setIsVersionable(true);
297
298
299
300 InMemoryFolderTypeDefinition cmisFolderType = new InMemoryFolderTypeDefinition(FOLDER_TYPE,
301 "Folder type with properties", InMemoryFolderTypeDefinition.getRootFolderType());
302
303
304
305 propertyDefinitions = new HashMap<String, PropertyDefinition<?>>();
306
307 prop6 = PropertyCreationHelper.createIntegerDefinition(PROP_ID_INT, "Sample Folder Int Property", Updatability.READONLY);
308 propertyDefinitions.put(prop6.getId(), prop6);
309
310 prop7 = PropertyCreationHelper.createStringDefinition(PROP_ID_STRING,
311 "Sample Folder String Property", Updatability.READONLY);
312 propertyDefinitions.put(prop7.getId(), prop7);
313 cmisFolderType.addCustomPropertyDefinitions(propertyDefinitions);
314
315
316
317 typesList.add(cmisDocTypeTopLevel);
318 typesList.add(cmisDocTypeLevel1);
319 typesList.add(cmisDocTypeLevel2);
320 typesList.add(cmisVersionedType);
321 typesList.add(cmisFolderType);
322
323 return typesList;
324 }
325
326 }