This project has retired. For details please refer to its Attic page.
DocumentTypeCreationHelper 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  
20  package org.apache.chemistry.opencmis.inmemory.types;
21  
22  import java.util.LinkedList;
23  import java.util.List;
24  import java.util.Map;
25  
26  import org.apache.chemistry.opencmis.commons.PropertyIds;
27  import org.apache.chemistry.opencmis.commons.definitions.PropertyDefinition;
28  import org.apache.chemistry.opencmis.commons.definitions.TypeDefinition;
29  import org.apache.chemistry.opencmis.commons.enums.Cardinality;
30  import org.apache.chemistry.opencmis.commons.enums.Updatability;
31  import org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyBooleanDefinitionImpl;
32  import org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyDateTimeDefinitionImpl;
33  import org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyIdDefinitionImpl;
34  import org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyIntegerDefinitionImpl;
35  import org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyStringDefinitionImpl;
36  
37  public class DocumentTypeCreationHelper {
38  
39      private static final List<TypeDefinition> defaultTypes = createCmisDefaultTypes();
40  
41      private DocumentTypeCreationHelper() {
42      }
43  
44      public static List<TypeDefinition> createMapWithDefaultTypes() {
45          List<TypeDefinition> typesList = new LinkedList<TypeDefinition>();
46          typesList.addAll(defaultTypes);
47          return typesList;
48      }
49  
50      public static final List<TypeDefinition> getDefaultTypes() {
51          return defaultTypes;
52      }
53  
54      private static List<TypeDefinition> createCmisDefaultTypes() {
55          List<TypeDefinition> typesList = new LinkedList<TypeDefinition>();
56  
57          // create root types:
58          TypeDefinition cmisType = InMemoryDocumentTypeDefinition.getRootDocumentType();
59          typesList.add(cmisType);
60  
61          cmisType = InMemoryFolderTypeDefinition.getRootFolderType();
62          typesList.add(cmisType);
63  
64          // cmisType = RelationshipTypeDefinition.getRootRelationshipType();
65          // typesList.add(cmisType);
66          //
67          // cmisType = PolicyTypeDefinition.getRootPolicyType();
68          // typesList.add(cmisType);
69  
70          return typesList;
71      }
72  
73      /**
74       * create root types and a collection of sample types
75       *
76       * @return typesMap map filled with created types
77       */
78      public static List<TypeDefinition> createDefaultTypes() {
79          List<TypeDefinition> typesList = createCmisDefaultTypes();
80  
81          return typesList;
82      }
83  
84      public static void setBasicPropertyDefinitions(Map<String, PropertyDefinition<?>> propertyDefinitions) {
85  
86          PropertyStringDefinitionImpl propS = PropertyCreationHelper.createStringDefinition(PropertyIds.NAME,
87                  "Name", Updatability.READWRITE);
88          propS.setIsRequired(true);
89          propertyDefinitions.put(propS.getId(), propS);
90  
91          PropertyIdDefinitionImpl propId = PropertyCreationHelper.createIdDefinition(PropertyIds.OBJECT_ID,
92                  "Object Id", Updatability.READONLY);
93          propertyDefinitions.put(propId.getId(), propId);
94  
95          propId = PropertyCreationHelper.createIdDefinition(PropertyIds.OBJECT_TYPE_ID, "Type-Id", Updatability.ONCREATE);
96          propId.setIsRequired(true);
97          propertyDefinitions.put(propId.getId(), propId);
98  
99          propId = PropertyCreationHelper.createIdDefinition(PropertyIds.BASE_TYPE_ID, "Base-Type-Id", Updatability.READONLY);
100         propertyDefinitions.put(propId.getId(), propId);
101 
102         propS = PropertyCreationHelper.createStringDefinition(PropertyIds.CREATED_BY, "Created By", Updatability.READONLY);
103         propertyDefinitions.put(propS.getId(), propS);
104 
105         PropertyDateTimeDefinitionImpl propD = PropertyCreationHelper.createDateTimeDefinition(
106                 PropertyIds.CREATION_DATE, "Creation Date", Updatability.READONLY);
107         propertyDefinitions.put(propD.getId(), propD);
108 
109         propS = PropertyCreationHelper.createStringDefinition(PropertyIds.LAST_MODIFIED_BY,
110                 "Modified By", Updatability.READONLY);
111         propertyDefinitions.put(propS.getId(), propS);
112 
113         propD = PropertyCreationHelper.createDateTimeDefinition(PropertyIds.LAST_MODIFICATION_DATE,
114                 "Modification Date", Updatability.READONLY);
115         propertyDefinitions.put(propD.getId(), propD);
116 
117         propS = PropertyCreationHelper.createStringDefinition(PropertyIds.CHANGE_TOKEN, "Change Token", Updatability.READONLY);
118         propertyDefinitions.put(propS.getId(), propS);
119     }
120 
121     public static void setBasicDocumentPropertyDefinitions(Map<String, PropertyDefinition<?>> propertyDefinitions) {
122 
123         setBasicPropertyDefinitions(propertyDefinitions);
124         PropertyBooleanDefinitionImpl propB = PropertyCreationHelper.createBooleanDefinition(PropertyIds.IS_IMMUTABLE,
125                 "Immutable", Updatability.READONLY);
126         propertyDefinitions.put(propB.getId(), propB);
127 
128         propB = PropertyCreationHelper.createBooleanDefinition(PropertyIds.IS_LATEST_VERSION,
129                 "Is Latest Version", Updatability.READONLY);
130         propertyDefinitions.put(propB.getId(), propB);
131 
132         propB = PropertyCreationHelper.createBooleanDefinition(PropertyIds.IS_MAJOR_VERSION,
133                 "Is Major Version", Updatability.READONLY);
134         propertyDefinitions.put(propB.getId(), propB);
135 
136         propB = PropertyCreationHelper.createBooleanDefinition(PropertyIds.IS_LATEST_MAJOR_VERSION,
137                 "Is Latest Major Version", Updatability.READONLY);
138         propertyDefinitions.put(propB.getId(), propB);
139 
140         PropertyStringDefinitionImpl propS = PropertyCreationHelper.createStringDefinition(PropertyIds.VERSION_LABEL,
141                 "Version Label", Updatability.READONLY);
142         propertyDefinitions.put(propS.getId(), propS);
143 
144         PropertyIdDefinitionImpl propId = PropertyCreationHelper.createIdDefinition(PropertyIds.VERSION_SERIES_ID,
145                 "Version Series Id", Updatability.READONLY);
146         propertyDefinitions.put(propId.getId(), propId);
147 
148         propB = PropertyCreationHelper.createBooleanDefinition(PropertyIds.IS_VERSION_SERIES_CHECKED_OUT,
149                 "Checked Out", Updatability.READONLY);
150         propertyDefinitions.put(propB.getId(), propB);
151 
152         propS = PropertyCreationHelper.createStringDefinition(PropertyIds.VERSION_SERIES_CHECKED_OUT_BY,
153                 "Checked Out By", Updatability.READONLY);
154         propertyDefinitions.put(propS.getId(), propS);
155 
156         propId = PropertyCreationHelper.createIdDefinition(PropertyIds.VERSION_SERIES_CHECKED_OUT_ID,
157                 "Checked Out Id", Updatability.READONLY);
158         propertyDefinitions.put(propId.getId(), propId);
159 
160         propS = PropertyCreationHelper.createStringDefinition(PropertyIds.CHECKIN_COMMENT,
161                 "Checkin Comment", Updatability.READONLY);
162         // read-only, because
163         // not set as property
164         propertyDefinitions.put(propS.getId(), propS);
165 
166         PropertyIntegerDefinitionImpl propI = PropertyCreationHelper.createIntegerDefinition(
167                 PropertyIds.CONTENT_STREAM_LENGTH, "Content Length", Updatability.READONLY);
168         propertyDefinitions.put(propI.getId(), propI);
169 
170         propS = PropertyCreationHelper.createStringDefinition(PropertyIds.CONTENT_STREAM_MIME_TYPE,
171                 "Mime Type", Updatability.READONLY);
172         propertyDefinitions.put(propS.getId(), propS);
173 
174         propS = PropertyCreationHelper.createStringDefinition(PropertyIds.CONTENT_STREAM_FILE_NAME,
175                 "File Name", Updatability.READONLY);
176         propertyDefinitions.put(propS.getId(), propS);
177 
178         propId = PropertyCreationHelper.createIdDefinition(PropertyIds.CONTENT_STREAM_ID, "Stream Id", Updatability.READONLY);
179         propertyDefinitions.put(propId.getId(), propId);
180 
181     }
182 
183     public static void setBasicFolderPropertyDefinitions(Map<String, PropertyDefinition<?>> propertyDefinitions) {
184 
185         setBasicPropertyDefinitions(propertyDefinitions);
186         PropertyIdDefinitionImpl propId = PropertyCreationHelper.createIdDefinition(PropertyIds.PARENT_ID,
187                 "Parent Id", Updatability.READONLY);
188         propertyDefinitions.put(propId.getId(), propId);
189 
190         propId = PropertyCreationHelper.createIdDefinition(PropertyIds.ALLOWED_CHILD_OBJECT_TYPE_IDS,
191                 "Allowed Child Types", Updatability.READONLY);
192         propId.setCardinality(Cardinality.MULTI);
193         propertyDefinitions.put(propId.getId(), propId);
194 
195         PropertyStringDefinitionImpl propS = PropertyCreationHelper.createStringDefinition(PropertyIds.PATH,
196                 "Path", Updatability.READONLY);
197         propertyDefinitions.put(propS.getId(), propS);
198 
199     }
200 
201     public static void setBasicPolicyPropertyDefinitions(Map<String, PropertyDefinition<?>> propertyDefinitions) {
202 
203         setBasicPropertyDefinitions(propertyDefinitions);
204         PropertyStringDefinitionImpl propS = PropertyCreationHelper.createStringDefinition(PropertyIds.POLICY_TEXT,
205                 "Policy Text", Updatability.READONLY);
206         propS.setIsRequired(true);
207         propertyDefinitions.put(propS.getId(), propS);
208     }
209 
210     public static void setBasicRelationshipPropertyDefinitions(Map<String, PropertyDefinition<?>> propertyDefinitions) {
211 
212         setBasicPropertyDefinitions(propertyDefinitions);
213         PropertyIdDefinitionImpl propId = PropertyCreationHelper.createIdDefinition(PropertyIds.SOURCE_ID,
214                 "Source Id", Updatability.READONLY);
215         propId.setIsRequired(true);
216         propertyDefinitions.put(propId.getId(), propId);
217 
218         propId = PropertyCreationHelper.createIdDefinition(PropertyIds.TARGET_ID, "Target Id", Updatability.READONLY);
219         propId.setIsRequired(true);
220         propertyDefinitions.put(propId.getId(), propId);
221     }
222 
223     public static void mergePropertyDefinitions(Map<String, PropertyDefinition<?>> existingPpropertyDefinitions,
224             Map<String, PropertyDefinition<?>> newPropertyDefinitions) {
225         for (String propId : newPropertyDefinitions.keySet()) {
226             if (existingPpropertyDefinitions.containsKey(propId)) {
227                 throw new RuntimeException("You can't set a property with id " + propId
228                         + ". This property id already exists already or exists in supertype");
229             }
230         }
231         existingPpropertyDefinitions.putAll(newPropertyDefinitions);
232     }
233 
234 }