This project has retired. For details please refer to its Attic page.
RepositoryServiceTest xref

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   * http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.chemistry.opencmis.inmemory;
20  
21  import static org.junit.Assert.assertEquals;
22  import static org.junit.Assert.assertFalse;
23  import static org.junit.Assert.assertNotNull;
24  import static org.junit.Assert.assertNull;
25  import static org.junit.Assert.assertTrue;
26  import static org.junit.Assert.fail;
27  
28  import java.math.BigInteger;
29  import java.util.ArrayList;
30  import java.util.List;
31  import java.util.Map;
32  
33  import org.apache.chemistry.opencmis.commons.PropertyIds;
34  import org.apache.chemistry.opencmis.commons.data.RepositoryInfo;
35  import org.apache.chemistry.opencmis.commons.definitions.PropertyDefinition;
36  import org.apache.chemistry.opencmis.commons.definitions.TypeDefinition;
37  import org.apache.chemistry.opencmis.commons.definitions.TypeDefinitionContainer;
38  import org.apache.chemistry.opencmis.commons.definitions.TypeDefinitionList;
39  import org.apache.chemistry.opencmis.commons.enums.BaseTypeId;
40  import org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException;
41  import org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException;
42  import org.apache.chemistry.opencmis.inmemory.types.DocumentTypeCreationHelper;
43  import org.apache.commons.logging.Log;
44  import org.apache.commons.logging.LogFactory;
45  import org.junit.After;
46  import org.junit.Before;
47  import org.junit.Test;
48  
49  /**
50   * @author Jens
51   */
52  public class RepositoryServiceTest extends AbstractServiceTest {
53  
54      // private CmisProvider fProvider;
55  
56      private static final Log log = LogFactory.getLog(RepositoryServiceTest.class);
57      private static final String REPOSITORY_ID = "UnitTestRepository";
58      private static final String TYPE_ID_MUTABILITY = "BookTypeAddedLater";
59  
60  
61      @Override
62      @Before
63      public void setUp() {
64          super.setTypeCreatorClass(UnitTestTypeSystemCreator.class.getName());
65          super.setUp();
66      }
67  
68      @Override
69      @After
70      public void tearDown() {
71          super.tearDown();
72      }
73  
74      @Test
75      public void testRepositoryInfo() {
76          log.info("starting testRepositoryInfo() ...");
77          List<RepositoryInfo> repositories = fRepSvc.getRepositoryInfos(null);
78          assertNotNull(repositories);
79          assertFalse(repositories.isEmpty());
80  
81          log.info("geRepositoryInfo(), found " + repositories.size() + " repository/repositories).");
82  
83          for (RepositoryInfo repository : repositories) {
84              RepositoryInfo repository2 = fRepSvc.getRepositoryInfo(repository.getId(), null);
85              assertNotNull(repository2);
86              assertEquals(repository.getId(), repository2.getId());
87              log.info("found repository" + repository2.getId());
88          }
89  
90          log.info("... testRepositoryInfo() finished.");
91      }
92  
93      @Test
94      public void testTypeDefinition() {
95          log.info("");
96          log.info("starting testTypeDefinition() ...");
97          String repositoryId = getRepositoryId();
98          String typeId = "MyDocType1";
99          TypeDefinition ref = UnitTestTypeSystemCreator.getTypeById(typeId);
100         TypeDefinition type = fRepSvc.getTypeDefinition(repositoryId, typeId, null);
101         assertEquals(ref.getId(), type.getId());
102         assertEquals(ref.getDescription(), type.getDescription());
103         assertEquals(ref.getDisplayName(), type.getDisplayName());
104         assertEquals(ref.getLocalName(), type.getLocalName());
105         assertEquals(ref.getLocalNamespace(), type.getLocalNamespace());
106         containsAllBasePropertyDefinitions(type);
107         log.info("... testTypeDefinition() finished.");
108     }
109 
110     @Test
111     public void testGetAllTypesUnlimitedDepth() {
112         log.info("");
113         log.info("starting testGetAllTypesUnlimitedDepth()...");
114         String repositoryId = getRepositoryId();
115 
116         // get types
117         List<TypeDefinitionContainer> types = fRepSvc.getTypeDescendants(repositoryId, null/*
118                                                                                             * all
119                                                                                             * types
120                                                                                             */, BigInteger.valueOf(-1),
121                 Boolean.TRUE, null);
122         assertNotNull(types);
123 
124         // check that we got all types
125         int expectedSize = UnitTestTypeSystemCreator.getTypesList().size()
126                 + DocumentTypeCreationHelper.getDefaultTypes().size();
127         int totalSize = getRecursiveSize(types);
128 
129         assertEquals(expectedSize, totalSize);
130         assertEquals(2, types.size());
131 
132         for (TypeDefinitionContainer type : types) {
133             assertNotNull(type);
134             TypeDefinition typeDef = type.getTypeDefinition();
135             assertNotNull(typeDef);
136             assertNotNull(typeDef.getId());
137             assertNotNull(typeDef.getBaseTypeId());
138             log.info("Found type: " + typeDef.getId() + ", display name is: " + typeDef.getDisplayName());
139             log.info("  Base type is: " + typeDef.getBaseTypeId());
140             log.info("  Number of children types is: " + type.getChildren().size());
141             Map<String, PropertyDefinition<?>> propDefs = type.getTypeDefinition().getPropertyDefinitions();
142             log.info("  Number of properties is: " + (propDefs == null ? 0 : propDefs.size()));
143             containsAllBasePropertyDefinitions(typeDef);
144         }
145 
146         log.info("... testGetAllTypesUnlimitedDepth() finished.");
147     }
148 
149     @Test
150     public void testGetTypesWihtoutPropDefs() {
151         log.info("");
152         log.info("starting testGetTypesWihtoutPropDefs()...");
153         String repositoryId = getRepositoryId();
154 
155         // get types
156         List<TypeDefinitionContainer> types = fRepSvc.getTypeDescendants(repositoryId, BaseTypeId.CMIS_DOCUMENT.value(), BigInteger.valueOf(-1),
157                 Boolean.FALSE, null);
158 //        List<TypeDefinitionContainer> types = fRepSvc.getTypeDescendants(repositoryId, "MyDocType1", BigInteger.valueOf(-1),
159 //                Boolean.FALSE, null);
160         assertNotNull(types);
161 
162         int totalSize = getRecursiveSize(types);
163         log.info("Found " + totalSize + " number of type definitions. ");
164 
165         List<TypeDefinition> descendants = getTypeDefsFlattened(types);
166         for (TypeDefinition typeDef : descendants) {
167             assertNotNull(typeDef);
168             assertNotNull(typeDef.getId());
169             assertNotNull(typeDef.getBaseTypeId());
170             assertEquals(BaseTypeId.CMIS_DOCUMENT, typeDef.getBaseTypeId());
171             log.info("Found type: " + typeDef.getId() + ", display name is: " + typeDef.getDisplayName());
172             log.info("  Base type is: " + typeDef.getBaseTypeId());
173             Map<String, PropertyDefinition<?>> propDefs = typeDef.getPropertyDefinitions();
174             log.info("  Property definitions (must be null): " + propDefs);
175             assertNull(propDefs);
176         }
177 
178         log.info("... testGetTypesWihtoutPropDefs() finished.");
179     }
180 
181     @Test
182     public void testGetAllTypesLimitedDepth() {
183         log.info("");
184         log.info("starting testGetAllTypesLimitedDepth()...");
185         String repositoryId = getRepositoryId();
186 
187         // get types
188         int depth = 1;
189         List<TypeDefinitionContainer> types = fRepSvc.getTypeDescendants(repositoryId,
190                 BaseTypeId.CMIS_DOCUMENT.value(), BigInteger.valueOf(depth), Boolean.TRUE, null);
191         assertNotNull(types);
192         log.info("Found in repository " + repositoryId + " " + types.size() + " type(s) with depth " + depth + ".");
193 
194         for (TypeDefinitionContainer type : types) {
195             TypeDefinition typeDef = type.getTypeDefinition();
196             log.info("Found type: " + typeDef.getId() + ", display name is: " + typeDef.getDisplayName());
197             log.info("  Base type is: " + typeDef.getBaseTypeId());
198             log.info("  Number of children types is: " + type.getChildren().size());
199             containsAllBasePropertyDefinitions(typeDef);
200         }
201 
202         int totalSize = getRecursiveSize(types);
203         assertEquals(5, totalSize); // all RepositoryTestTypeSystemCreator types
204         // minus one in level two plus cmis.docment
205         assertFalse(containsTypeByIdRecursive(BaseTypeId.CMIS_DOCUMENT.value(), types));
206         assertFalse(containsTypeByIdRecursive(BaseTypeId.CMIS_FOLDER.value(), types));
207 
208         assertTrue(containsTypeByIdRecursive("MyDocType1", types));
209         assertTrue(containsTypeByIdRecursive("MyDocType2", types));
210 
211         assertFalse(containsTypeByIdRecursive(UnitTestTypeSystemCreator.LEVEL2_TYPE, types));
212 
213         for (TypeDefinitionContainer type : types) {
214             assertNotNull(type);
215             TypeDefinition typeDef = type.getTypeDefinition();
216             assertNotNull(typeDef);
217             assertNotNull(typeDef.getId());
218             assertNotNull(typeDef.getBaseTypeId());
219         }
220 
221         log.info("... testGetAllTypesLimitedDepth() finished.");
222     }
223 
224     @Test
225     public void testGetSpecificTypeLimitedDepth() {
226         log.info("");
227         log.info("starting testGetSpecificTypeLimitedDepth()...");
228         String repositoryId = getRepositoryId();
229 
230         // get types
231         int depth = 2;
232         String typeId = "MyDocType1";
233         List<TypeDefinitionContainer> types = fRepSvc.getTypeDescendants(repositoryId, typeId, BigInteger
234                 .valueOf(depth), Boolean.TRUE, null);
235         assertNotNull(types);
236         log.info("Found in repository " + repositoryId + " for type " + typeId + ", " + types.size()
237                 + " type(s) with depth " + depth + ".");
238 
239         assertEquals(4, getRecursiveSize(types));
240         assertTrue(containsTypeByIdRecursive("MyDocType1.1", types));
241         assertTrue(containsTypeByIdRecursive("MyDocType1.2", types));
242         assertTrue(containsTypeByIdRecursive("MyDocType1.1.1", types));
243         assertTrue(containsTypeByIdRecursive("MyDocType1.1.2", types));
244         for (TypeDefinitionContainer type : types) {
245             assertNotNull(type);
246             TypeDefinition typeDef = type.getTypeDefinition();
247             assertNotNull(typeDef);
248             assertNotNull(typeDef.getId());
249             assertNotNull(typeDef.getBaseTypeId());
250             log.info("Found type: " + typeDef.getId() + ", display name is: " + typeDef.getDisplayName());
251             log.info("  Base type is: " + typeDef.getBaseTypeId());
252             log.info("  Number of children types is: " + type.getChildren().size());
253             containsAllBasePropertyDefinitions(typeDef);
254         }
255 
256         log.info("... testGetSpecificTypeLimitedDepth() finished.");
257     }
258 
259     @Test
260     public void testGetTypeChildren() {
261         log.info("");
262         log.info("starting testGetTypeChildren()...");
263         String repositoryId = getRepositoryId();
264         String typeId = "MyDocType2";
265 
266         // get all children
267         BigInteger maxItems = BigInteger.valueOf(1000);
268         BigInteger skipCount = BigInteger.valueOf(0);
269         TypeDefinitionList children = fRepSvc.getTypeChildren(repositoryId, typeId, true, maxItems, skipCount, null);
270 
271         for (TypeDefinition type : children.getList()) {
272             log.info("Found type: " + type.getId() + ", display name is: " + type.getDisplayName());
273             containsAllBasePropertyDefinitions(type);
274         }
275         assertEquals(9, children.getList().size());
276         assertEquals(9, children.getNumItems().intValue());
277         assertFalse(children.hasMoreItems());
278 
279         // get a chunk
280         maxItems = BigInteger.valueOf(5);
281         skipCount = BigInteger.valueOf(3);
282         children = fRepSvc.getTypeChildren(repositoryId, typeId, true, maxItems, skipCount, null);
283 
284         for (TypeDefinition type : children.getList()) {
285             log.info("Found type: " + type.getId() + ", display name is: " + type.getDisplayName());
286             containsAllBasePropertyDefinitions(type);
287         }
288         assertEquals(5, children.getList().size());
289         assertEquals(9, children.getNumItems().intValue());
290         assertTrue(children.hasMoreItems());
291 
292         log.info("... testGetTypeChildren() finished.");
293     }
294 
295     @Test
296     public void testGetTypeChildrenNoProperties() {
297         log.info("");
298         log.info("starting testGetTypeChildrenNoProperties()...");
299         String repositoryId = getRepositoryId();
300         String typeId = "cmis:document";
301 
302         // get all children
303         BigInteger maxItems = BigInteger.valueOf(1000);
304         BigInteger skipCount = BigInteger.valueOf(0);
305         TypeDefinitionList children = fRepSvc.getTypeChildren(repositoryId, typeId, null, maxItems, skipCount, null);
306 
307         children = fRepSvc.getTypeChildren(repositoryId, typeId, null, maxItems, null, null);
308 
309         for (TypeDefinition type : children.getList()) {
310             assertNull(type.getPropertyDefinitions());
311         }
312 
313         log.info("... testGetTypeChildrenNoProperties() finished.");
314     }
315 
316     @Test
317     public void testGetWrongParameters() {
318         log.info("");
319         log.info("starting testGetWrongParameters()...");
320         String repositoryId = getRepositoryId();
321         String wrongRepositoryId = "NonExistantRepository";
322 
323         // get types
324         int depth = -1;
325         String wrongTypeId = "UnknownType";
326 
327         try {
328             RepositoryInfo repInf = fRepSvc.getRepositoryInfo(wrongRepositoryId, null);
329             log.debug("getRepositoryInfo(): " + repInf);
330             fail("getRepositoryInfo() with illegal repository id should throw InvalidArgumentException.");
331         } catch (CmisInvalidArgumentException e) {
332             log.info("getRepositoryInfo() with depth==0 raised expected exception: " + e);
333         }
334 
335         try {
336             List<TypeDefinitionContainer> types = fRepSvc.getTypeDescendants(repositoryId, "CMISDocument", BigInteger
337                     .valueOf(0), Boolean.TRUE, null);
338             log.debug("getTypeDescendants(): " + types);
339             fail("getTypeDescendants() with depth 0 should throw InvalidArgumentException.");
340         } catch (CmisInvalidArgumentException e) {
341             log.info("getTypeDescendants() with depth==0 raised expected exception: " + e);
342         }
343 
344         try {
345             List<TypeDefinitionContainer> types = fRepSvc.getTypeDescendants(repositoryId, wrongTypeId, BigInteger
346                     .valueOf(depth), Boolean.TRUE, null);
347             log.debug("getTypeDescendants(): " + types);
348             fail("getTypeDescendants() with unknown type should throw exception.");
349         } catch (CmisInvalidArgumentException e) {
350             log.info("getTypeDescendants() with unknown type raised expected exception: " + e);
351         }
352 
353         try {
354             TypeDefinition type = fRepSvc.getTypeDefinition(wrongRepositoryId, "CMISDocument", null);
355             log.debug("getTypeDefinition(): " + type);
356             fail("getTypeDefinition() with unknown repository id should throw exception.");
357         } catch (CmisInvalidArgumentException e) {
358             log.info("getTypeDefinition() with unknown repository id raised expected exception: " + e);
359         }
360 
361         try {
362             TypeDefinition type = fRepSvc.getTypeDefinition(repositoryId, wrongTypeId, null);
363             log.debug("getTypeDefinition(): " + type);
364             fail("getTypeDefinition() with unknown type should throw exception.");
365         } catch (CmisObjectNotFoundException e) {
366             log.info("getTypeDefinition() with unknown type raised expected exception: " + e);
367         }
368 
369         try {
370             TypeDefinitionList types = fRepSvc.getTypeChildren(wrongRepositoryId, "CMISDocument", Boolean.TRUE,
371                     BigInteger.valueOf(100), BigInteger.ZERO, null);
372             log.debug("getTypeChildren(): " + types);
373             fail("getTypeDescendants() with unknown type should throw InvalidArgumentException.");
374         } catch (CmisInvalidArgumentException e) {
375             log.info("getTypeDescendants() with unknown repository id raised expected exception: " + e);
376         }
377 
378         try {
379             TypeDefinitionList types = fRepSvc.getTypeChildren(repositoryId, wrongTypeId, Boolean.TRUE, BigInteger
380                     .valueOf(100), BigInteger.ZERO, null);
381             log.debug("getTypeChildren(): " + types);
382             fail("getTypeDescendants() with unknown type should throw exception.");
383         } catch (CmisInvalidArgumentException e) {
384             log.info("getTypeDescendants() with unknown type raised expected exception: " + e);
385         }
386 
387         log.info("... testGetUnknownType() testGetWrongParameters.");
388 
389     }
390 
391     @Test
392     public void testInheritedProperties() {
393         log.info("");
394         log.info("starting testInheritedProperties()...");
395         String repositoryId = getRepositoryId();
396         String typeId = UnitTestTypeSystemCreator.TOPLEVEL_TYPE;
397 
398         // get top level type
399         TypeDefinition typeContainer = fRepSvc.getTypeDefinition(repositoryId, typeId, null);
400         assertNotNull(typeContainer);
401         Map<String, PropertyDefinition<?>> propDefMap = typeContainer.getPropertyDefinitions();
402         assertTrue(propDefMap.containsKey("StringPropTopLevel"));
403         assertFalse(propDefMap.get("StringPropTopLevel").isInherited());
404         assertFalse(propDefMap.containsKey("StringPropLevel1"));
405         assertFalse(propDefMap.containsKey("StringPropLevel2"));
406         containsAllBasePropertyDefinitions(typeContainer);
407 
408         // get level 1 type
409         typeId = UnitTestTypeSystemCreator.LEVEL1_TYPE;
410         typeContainer = fRepSvc.getTypeDefinition(repositoryId, typeId, null);
411         assertNotNull(typeContainer);
412         propDefMap = typeContainer.getPropertyDefinitions();
413         assertTrue(propDefMap.containsKey("StringPropTopLevel"));
414         assertTrue(propDefMap.get("StringPropTopLevel").isInherited());
415         assertTrue(propDefMap.containsKey("StringPropLevel1"));
416         assertFalse(propDefMap.get("StringPropLevel1").isInherited());
417         assertFalse(propDefMap.containsKey("StringPropLevel2"));
418         containsAllBasePropertyDefinitions(typeContainer);
419 
420         // get level 2 type
421         typeId = UnitTestTypeSystemCreator.LEVEL2_TYPE;
422         typeContainer = fRepSvc.getTypeDefinition(repositoryId, typeId, null);
423         assertNotNull(typeContainer);
424         propDefMap = typeContainer.getPropertyDefinitions();
425         assertTrue(propDefMap.containsKey("StringPropTopLevel"));
426         assertTrue(propDefMap.get("StringPropTopLevel").isInherited());
427         assertTrue(propDefMap.containsKey("StringPropLevel1"));
428         assertTrue(propDefMap.get("StringPropLevel1").isInherited());
429         assertTrue(propDefMap.containsKey("StringPropLevel2"));
430         assertFalse(propDefMap.get("StringPropLevel2").isInherited());
431         containsAllBasePropertyDefinitions(typeContainer);
432 
433         log.info("... testInheritedProperties() finished.");
434     }
435 
436 
437     private String getRepositoryId() {
438         List<RepositoryInfo> repositories = fRepSvc.getRepositoryInfos(null);
439         RepositoryInfo repository = repositories.get(0);
440         assertNotNull(repository);
441         return repository.getId();
442     }
443 
444     private boolean containsTypeByIdRecursive(String typeId, List<TypeDefinitionContainer> types) {
445         for (TypeDefinitionContainer type : types) {
446             if (containsTypeByIdRecursive(typeId, type)) {
447                 return true;
448             }
449         }
450         return false;
451     }
452 
453     private boolean containsTypeByIdRecursive(String typeId, TypeDefinitionContainer typeContainer) {
454         if (typeId.equals(typeContainer.getTypeDefinition().getId())) {
455             return true;
456         }
457 
458         for (TypeDefinitionContainer type : typeContainer.getChildren()) {
459             if (containsTypeByIdRecursive(typeId, type)) {
460                 return true;
461             }
462         }
463         return false;
464     }
465 
466     static void containsAllBasePropertyDefinitions(TypeDefinition typeDef) {
467         Map<String, PropertyDefinition<?>> propDefs = typeDef.getPropertyDefinitions();
468         String baseTypeId = typeDef.getBaseTypeId().value();
469 
470         assertTrue(propDefs.containsKey(PropertyIds.NAME));
471         assertTrue(propDefs.containsKey(PropertyIds.OBJECT_ID));
472         assertTrue(propDefs.containsKey(PropertyIds.OBJECT_TYPE_ID));
473         assertTrue(propDefs.containsKey(PropertyIds.BASE_TYPE_ID));
474         assertTrue(propDefs.containsKey(PropertyIds.CREATED_BY));
475         assertTrue(propDefs.containsKey(PropertyIds.CREATION_DATE));
476         assertTrue(propDefs.containsKey(PropertyIds.LAST_MODIFIED_BY));
477         assertTrue(propDefs.containsKey(PropertyIds.LAST_MODIFICATION_DATE));
478         assertTrue(propDefs.containsKey(PropertyIds.CHANGE_TOKEN));
479 
480         if (baseTypeId.equals(BaseTypeId.CMIS_DOCUMENT.value())) {
481             assertTrue(propDefs.containsKey(PropertyIds.IS_IMMUTABLE));
482             assertTrue(propDefs.containsKey(PropertyIds.IS_LATEST_VERSION));
483             assertTrue(propDefs.containsKey(PropertyIds.IS_MAJOR_VERSION));
484             assertTrue(propDefs.containsKey(PropertyIds.IS_LATEST_MAJOR_VERSION));
485             assertTrue(propDefs.containsKey(PropertyIds.VERSION_LABEL));
486             assertTrue(propDefs.containsKey(PropertyIds.VERSION_SERIES_ID));
487             assertTrue(propDefs.containsKey(PropertyIds.IS_VERSION_SERIES_CHECKED_OUT));
488             assertTrue(propDefs.containsKey(PropertyIds.VERSION_SERIES_CHECKED_OUT_BY));
489             assertTrue(propDefs.containsKey(PropertyIds.VERSION_SERIES_CHECKED_OUT_ID));
490             assertTrue(propDefs.containsKey(PropertyIds.CHECKIN_COMMENT));
491             assertTrue(propDefs.containsKey(PropertyIds.CONTENT_STREAM_LENGTH));
492             assertTrue(propDefs.containsKey(PropertyIds.CONTENT_STREAM_MIME_TYPE));
493             assertTrue(propDefs.containsKey(PropertyIds.CONTENT_STREAM_FILE_NAME));
494             assertTrue(propDefs.containsKey(PropertyIds.CONTENT_STREAM_ID));
495             assertTrue(propDefs.containsKey(PropertyIds.CHANGE_TOKEN));
496         } else if (baseTypeId.equals(BaseTypeId.CMIS_FOLDER.value())) {
497             assertTrue(propDefs.containsKey(PropertyIds.PARENT_ID));
498             assertTrue(propDefs.containsKey(PropertyIds.ALLOWED_CHILD_OBJECT_TYPE_IDS));
499             assertTrue(propDefs.containsKey(PropertyIds.PATH));
500         } else if (baseTypeId.equals(BaseTypeId.CMIS_POLICY.value())) {
501             assertTrue(propDefs.containsKey(PropertyIds.POLICY_TEXT));
502         } else if (baseTypeId.equals(BaseTypeId.CMIS_RELATIONSHIP.value())) {
503             assertTrue(propDefs.containsKey(PropertyIds.SOURCE_ID));
504             assertTrue(propDefs.containsKey(PropertyIds.TARGET_ID));
505         } else {
506             fail("Unknown base type id in type definition");
507         }
508     }
509 
510     private int getRecursiveSize(List<TypeDefinitionContainer> types) {
511         if (null == types) {
512             return 0;
513         }
514 
515         int size = types.size();
516         for (TypeDefinitionContainer type : types) {
517             size += getRecursiveSize(type.getChildren());
518         }
519 
520         return size;
521     }
522 
523     private List<TypeDefinition> getTypeDefsFlattened(List<TypeDefinitionContainer> types) {
524         List<TypeDefinition> flattened = new ArrayList<TypeDefinition>();
525         
526         for (TypeDefinitionContainer type : types) {
527             flattened.add(type.getTypeDefinition());
528             if (null != type.getChildren()) {
529                 List<TypeDefinition> children = getTypeDefsFlattened(type.getChildren());
530                 flattened.addAll(children);
531             }
532         }
533 
534         return flattened;
535     }
536     
537 }