1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.chemistry.opencmis.inmemory.types;
21
22 import java.util.HashMap;
23 import java.util.Map;
24
25 import org.apache.chemistry.opencmis.commons.definitions.PropertyDefinition;
26 import org.apache.chemistry.opencmis.commons.enums.BaseTypeId;
27 import org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException;
28 import org.apache.chemistry.opencmis.commons.impl.dataobjects.RelationshipTypeDefinitionImpl;
29 import org.apache.chemistry.opencmis.inmemory.NameValidator;
30
31 public class InMemoryRelationshipTypeDefinition extends RelationshipTypeDefinitionImpl {
32
33 private static final long serialVersionUID = 1L;
34 private static final InMemoryRelationshipTypeDefinition RELATIONSHIP_TYPE = new InMemoryRelationshipTypeDefinition();
35
36 public static InMemoryRelationshipTypeDefinition getRootRelationshipType() {
37 return RELATIONSHIP_TYPE;
38 }
39
40
41 public InMemoryRelationshipTypeDefinition() {
42 init(BaseTypeId.CMIS_RELATIONSHIP.value(), "CMIS Relation");
43 setParentTypeId(null);
44
45 Map<String, PropertyDefinition<?>> props = getPropertyDefinitions();
46 DocumentTypeCreationHelper.setBasicRelationshipPropertyDefinitions(props);
47 }
48
49 public InMemoryRelationshipTypeDefinition(String id, String displayName) {
50 init(id, displayName);
51 setParentTypeId(RELATIONSHIP_TYPE.getId());
52 }
53
54 public InMemoryRelationshipTypeDefinition(String id, String displayName,
55 InMemoryRelationshipTypeDefinition parentType) {
56
57 init(id, displayName);
58 if (parentType != null) {
59 setBaseTypeId(parentType.getBaseTypeId());
60 } else {
61 throw new IllegalArgumentException("Must provide a parent type when creating a relationship definition");
62 }
63 setParentTypeId(parentType.getId());
64 }
65
66
67
68
69
70
71
72
73
74 public void addCustomPropertyDefinitions(Map<String, PropertyDefinition<?>> propertyDefinitions) {
75 DocumentTypeCreationHelper.mergePropertyDefinitions(getPropertyDefinitions(), propertyDefinitions);
76 }
77
78 private void init(String id, String displayName) {
79 if (!NameValidator.isValidId(id)) {
80 throw new CmisInvalidArgumentException(NameValidator.ERROR_ILLEGAL_NAME);
81 }
82
83 setBaseTypeId(BaseTypeId.CMIS_RELATIONSHIP);
84 setId(id);
85 if (displayName == null) {
86 displayName = id;
87 }
88 setDisplayName(displayName);
89
90 setDescription("Description of " + getDisplayName() + " Type");
91 setLocalName(id);
92 setLocalNamespace("local");
93 setQueryName(id);
94 setIsControllableAcl(false);
95 setIsControllablePolicy(false);
96 setIsCreatable(true);
97 setIsFileable(true);
98 setIsFulltextIndexed(false);
99 setIsIncludedInSupertypeQuery(true);
100 setIsQueryable(false);
101
102
103
104
105
106
107
108
109
110 setAllowedSourceTypes(null);
111 setAllowedTargetTypes(null);
112
113
114 Map<String, PropertyDefinition<?>> props = new HashMap<String, PropertyDefinition<?>>();
115 setPropertyDefinitions(props);
116 }
117
118 }