This repository was archived by the owner on Oct 13, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathREADME
140 lines (93 loc) · 4.51 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
Alfresco OpenCMIS Extension
===========================
The Alfresco OpenCMIS Extension provides easy access to Alfresco aspects and
aspect properties.
Project page: <http://apache-extras.org/p/alfresco-opencmis-extension>
Using the Alfresco OpenCMIS Extension
-------------------------------------
The Alfresco OpenCMIS Extension requires OpenCMIS 0.2 or higher.
Download it from here: <http://chemistry.apache.org/java/opencmis.html>
Put the Alfresco OpenCMIS Extension Jar into your classpath. When setting up
an OpenCMIS session, set the object factory class to
"org.alfresco.cmis.client.impl.AlfrescoObjectFactoryImpl".
Code sample:
Map<String, String> parameter = new HashMap<String, String>();
// user credentials
parameter.put(SessionParameter.USER, "admin");
parameter.put(SessionParameter.PASSWORD, "admin");
// connection settings
parameter.put(SessionParameter.ATOMPUB_URL,
"http://localhost:8080/alfresco/service/cmis");
parameter.put(SessionParameter.BINDING_TYPE, BindingType.ATOMPUB.value());
// set the object factory
parameter.put(SessionParameter.OBJECT_FACTORY_CLASS,
"org.alfresco.cmis.client.impl.AlfrescoObjectFactoryImpl");
// create session
SessionFactory factory = SessionFactoryImpl.newInstance();
Session session = factory.getRepositories(parameter).get(0).createSession();
Reading aspect properties
-------------------------
Aspect properties automatically appear as CMIS properties.
Updating aspect properties
--------------------------
An aspect property can be updated as any other CMIS property.
Creating documents and folders with aspects
-------------------------------------------
Aspects can be specified at creation of a document or a folder.
In order to create an object, the property "cmis:objectTypeId" must be set to
a valid CMIS object type id. With the Alfresco OpenCMIS Extension installed,
the OpenCMIS library also accepts a comma-separated list of type ids.
The first type id in that list MUST be the object type id. All following
type ids MUST be aspect type ids.
Aspect properties can be set for all aspects in that list.
Code sample:
Map<String, Object> properties = new HashMap<String, Object>();
properties.put(PropertyIds.NAME, "doc1");
properties.put(PropertyIds.OBJECT_TYPE_ID, "cmis:document,P:cm:titled");
properties.put("cm:description", "My document");
Document doc = session.getRootFolder().createDocument(properties, null, null);
Adding, removing and discovering aspects
----------------------------------------
In order to add and remove aspects, cast OpenCMIS Document objects and Folder
objects to AlfrescoDocument respectively AlfrescoFolder.
They provide the following additional methods:
// check for applied aspects
boolean hasAspect(String id);
boolean hasAspect(ObjectType type);
Collection<ObjectType> getAspects();
// find the aspect type for a property id
ObjectType findAspect(String propertyId);
// add and remove aspects
void addAspect(String... id);
void addAspect(ObjectType... type);
void removeAspect(String... id);
void removeAspect(ObjectType... type);
Code sample:
Document doc = (Document) session.getObject(...);
AlfrescoDocument alfDoc = (AlfrescoDocument) doc;
alfDoc.addAspect("P:cm:taggable");
if(alfDoc.hasAspect("P:cm:titled")) {
Map<String, Object> properties = new HashMap<String, Object>();
properties.put("cm:description", "My taggable document");
alfDoc.updateProperties(properties);
}
If the OpenCMIS session is connected to a repository that is not an Alfresco
repository, hasAspect() always returns false, getAspects() returns an empty
collection and addAspect() and removeAspect() calls should be ignored by the
connected repository.
How does it work?
-----------------
The CMIS specification defines several extension points. Alfresco uses these
CMIS extensions to sends and accepts aspect properties. Those extensions are
available to all CMIS clients but most of them ignore extensions.
A vanilla OpenCMIS library can read and set CMIS extensions but that requires
some code and discipline.
The Alfresco OpenCMIS Extension replaces OpenCMIS' internal object factory with
one that understands Alfresco CMIS extensions. The factory creates objects that
are aware of Alfresco aspects and provide appropriate interfaces.
So, the Alfresco OpenCMIS Extension is only a convenience layer on top of CMIS.
License
-------
Apache License, Version 2.0
Please see <http://www.apache.org/licenses/LICENSE-2.0>.
Copyright (C) 2005-2011 Alfresco Software Limited.