This project has retired. For details please refer to its Attic page.
VersionTestTypeSystemCreator 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 java.util.HashMap;
22  import java.util.LinkedList;
23  import java.util.List;
24  import java.util.Map;
25  
26  import org.apache.chemistry.opencmis.commons.definitions.PropertyDefinition;
27  import org.apache.chemistry.opencmis.commons.definitions.TypeDefinition;
28  import org.apache.chemistry.opencmis.commons.enums.Updatability;
29  import org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyStringDefinitionImpl;
30  import org.apache.chemistry.opencmis.inmemory.types.InMemoryDocumentTypeDefinition;
31  import org.apache.chemistry.opencmis.inmemory.types.PropertyCreationHelper;
32  
33  public class VersionTestTypeSystemCreator implements TypeCreator {
34      public static final String VERSION_TEST_DOCUMENT_TYPE_ID = "MyVersionedType";
35      public static final String PROPERTY_ID = "StringProp";
36      public static final List<TypeDefinition> singletonTypes = buildTypesList();
37  
38      /**
39       * in the public interface of this class we return the singleton containing
40       * the required types for testing
41       */
42      public List<TypeDefinition> createTypesList() {
43          return singletonTypes;
44      }
45  
46      public static List<TypeDefinition> getTypesList() {
47          return singletonTypes;
48      }
49  
50      public static TypeDefinition getTypeById(String typeId) {
51          for (TypeDefinition typeDef : singletonTypes) {
52              if (typeDef.getId().equals(typeId)) {
53                  return typeDef;
54              }
55          }
56          return null;
57      }
58  
59      /**
60       * create root types and a collection of sample types
61       *
62       * @return typesMap map filled with created types
63       */
64      private static List<TypeDefinition> buildTypesList() {
65          // always add CMIS default types
66          List<TypeDefinition> typesList = new LinkedList<TypeDefinition>();
67  
68          // create a complex type with properties
69          InMemoryDocumentTypeDefinition cmisComplexType = new InMemoryDocumentTypeDefinition(
70                  VERSION_TEST_DOCUMENT_TYPE_ID, "VersionedType", InMemoryDocumentTypeDefinition.getRootDocumentType());
71  
72          // create a boolean property definition
73  
74          Map<String, PropertyDefinition<?>> propertyDefinitions = new HashMap<String, PropertyDefinition<?>>();
75  
76          PropertyStringDefinitionImpl prop1 = PropertyCreationHelper.createStringDefinition(PROPERTY_ID,
77                  "Sample String Property", Updatability.WHENCHECKEDOUT);
78          propertyDefinitions.put(prop1.getId(), prop1);
79  
80          cmisComplexType.addCustomPropertyDefinitions(propertyDefinitions);
81          cmisComplexType.setIsVersionable(true); // make it a versionable type;
82  
83          // add type to types collection
84          typesList.add(cmisComplexType);
85  
86          return typesList;
87      }
88  
89  }