cmis 0.2.0-java → 0.2.1-java
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +31 -1
- data/lib/cmis.rb +19 -5
- data/lib/cmis/version.rb +1 -1
- data/spec/cmis_spec.rb +24 -3
- metadata +2 -2
data/README.md
CHANGED
@@ -31,6 +31,12 @@ Or install it yourself as:
|
|
31
31
|
|
32
32
|
$ gem install cmis
|
33
33
|
|
34
|
+
|
35
|
+
## Notes about JRuby and OpenCMIS
|
36
|
+
Every call you do in this library that returns an object actually returns a real Java object from OpenCMIS so you have access to all the functionality that OpenCMIS provides.
|
37
|
+
|
38
|
+
If you want to do something that is not described in the documentation below you can read the [OpenCMIS JavaDoc](http://chemistry.apache.org/java/0.8.0/maven/apidocs/) and you should figure out how to do it.
|
39
|
+
|
34
40
|
## Usage
|
35
41
|
|
36
42
|
This guide is for JRuby developers who want to access CMIS-compliant content repositories from JRuby. The examples has been tested with Alfresco Community Edition 4.2.c which is one of the most feature complete CMIS content repository.
|
@@ -66,6 +72,8 @@ puts "Trying to connect to a repository with id #{available_repos[0].id}"
|
|
66
72
|
|
67
73
|
```
|
68
74
|
|
75
|
+
Note: The create_session method returns a real [Session](http://chemistry.apache.org/java/0.8.0/maven/apidocs/org/apache/chemistry/opencmis/client/api/Session.html) object that is used in OpenCMIS so you have access to every functionality that the Session object provides.
|
76
|
+
|
69
77
|
## Working with folders and documents
|
70
78
|
|
71
79
|
Finding the contents of the root folder:
|
@@ -93,8 +101,11 @@ Create a folder the hard way:
|
|
93
101
|
```ruby
|
94
102
|
folder_props = { CMIS::PropertyIds::OBJECT_TYPE_ID => "cmis:folder", CMIS::PropertyIds::NAME => "Another folder" }
|
95
103
|
root.create_folder(folder_props)
|
104
|
+
puts folder.name
|
96
105
|
```
|
97
106
|
|
107
|
+
Note: When you create a folder it will return an actual Java OpenCMIS Folder object. That means you have access to everything it provides. [More information can be found in the JavaDoc for the Folder interface](http://chemistry.apache.org/java/0.8.0/maven/apidocs/org/apache/chemistry/opencmis/client/api/Folder.html)
|
108
|
+
|
98
109
|
### Creating/Uploading documents
|
99
110
|
|
100
111
|
The create_cmis_document method is a convenient method implemented in the JRuby CMIS Library.
|
@@ -113,9 +124,12 @@ content_stream = CMIS::create_content_stream("/Users/ricn/cmis_logo.png", @sessi
|
|
113
124
|
props = { CMIS::PropertyIds::OBJECT_TYPE_ID => "cmis:document", CMIS::PropertyIds::NAME => "cmis_logo.png" }
|
114
125
|
id = root.create_document(props, content_stream, CMIS::VersioningState::MAJOR)
|
115
126
|
doc = @session.get_object(id)
|
127
|
+
puts doc.name
|
116
128
|
```
|
117
129
|
|
118
|
-
|
130
|
+
Note: When you create a document it will return an actual Java OpenCMIS Document object. That means you have access to everything it provides. [More information can be found in the JavaDoc for the Document interface](http://chemistry.apache.org/java/0.8.0/maven/apidocs/org/apache/chemistry/opencmis/client/api/Document.html)
|
131
|
+
|
132
|
+
#### Download a document to your local disc
|
119
133
|
|
120
134
|
```ruby
|
121
135
|
doc = @session.get_object(id)
|
@@ -438,6 +452,22 @@ puts rel.source.id
|
|
438
452
|
puts rel.target.id
|
439
453
|
```
|
440
454
|
|
455
|
+
## Exceptions
|
456
|
+
If something goes wrong in an OpenCMIS method, an exception will be thrown. All OpenCMIS exceptions extend [CmisBaseException](http://chemistry.apache.org/java/0.8.0/maven/apidocs/org/apache/chemistry/opencmis/commons/exceptions/package-tree.html) which is a Java runtime exception. Because all exceptions are runtime, you do not have to catch or specify the exceptions in your own code.
|
457
|
+
|
458
|
+
When you are using the ATOMPUB binding, [CmisBaseException](http://chemistry.apache.org/java/0.8.0/maven/apidocs/org/apache/chemistry/opencmis/commons/exceptions/package-tree.html) provides a error_content method which returns the content of the error page returned from the server, if there is one. This can be very useful when debugging, as the server side is normally able to provide far more information that the client.
|
459
|
+
In the following example, a CMISInvalidArgumentException exception is forced by trying to create a folder with an invalid type. The rescue block prints the server's error page:
|
460
|
+
|
461
|
+
```ruby
|
462
|
+
begin
|
463
|
+
folder_props = { CMIS::PropertyIds::OBJECT_TYPE_ID => "INVALIDOBJECTTYPEID", CMIS::PropertyIds::NAME => "folder name" }
|
464
|
+
folder = @session.root_folder.create_folder(folder_props)
|
465
|
+
rescue StandardError => e
|
466
|
+
puts e.message
|
467
|
+
puts e.error_content
|
468
|
+
end
|
469
|
+
```
|
470
|
+
|
441
471
|
## Contributing
|
442
472
|
|
443
473
|
1. Fork it
|
data/lib/cmis.rb
CHANGED
@@ -71,7 +71,7 @@ module CMIS
|
|
71
71
|
content = session.object_factory.create_content_stream(file.name, file.length, CMIS::MimeTypes.getMIMEType(file), stream)
|
72
72
|
doc_props = { CMIS::PropertyIds::OBJECT_TYPE_ID => "cmis:document", CMIS::PropertyIds::NAME => name }
|
73
73
|
doc_props.merge!(props) if props != nil && props.is_a?(Hash)
|
74
|
-
self.create_document(doc_props, content, CMIS::VersioningState::MAJOR)
|
74
|
+
self.create_document(java.util.HashMap.new(doc_props), content, CMIS::VersioningState::MAJOR)
|
75
75
|
end
|
76
76
|
end
|
77
77
|
|
@@ -88,7 +88,7 @@ module CMIS
|
|
88
88
|
session_factory = SessionFactoryImpl.new_instance
|
89
89
|
repo_id = self.repositories(url, user, password)[0].id if repo_id == nil
|
90
90
|
|
91
|
-
|
91
|
+
params = {
|
92
92
|
SessionParameter::ATOMPUB_URL => url,
|
93
93
|
SessionParameter::BINDING_TYPE => BindingType::ATOMPUB.value,
|
94
94
|
SessionParameter::USER => user,
|
@@ -96,19 +96,33 @@ module CMIS
|
|
96
96
|
SessionParameter::REPOSITORY_ID => repo_id
|
97
97
|
}
|
98
98
|
|
99
|
-
session_factory.create_session(
|
99
|
+
session_factory.create_session(java.util.HashMap.new(params))
|
100
|
+
end
|
101
|
+
|
102
|
+
def self.create_session_with_soap(user, password, web_services, repo_id = nil)
|
103
|
+
session_factory = SessionFactoryImpl.new_instance
|
104
|
+
repo_id = self.repositories(url, user, password)[0].id if repo_id == nil
|
105
|
+
|
106
|
+
params = {
|
107
|
+
SessionParameter::BINDING_TYPE => BindingType::WEBSERVICES.value,
|
108
|
+
SessionParameter::USER => user,
|
109
|
+
SessionParameter::PASSWORD => password,
|
110
|
+
SessionParameter::REPOSITORY_ID => repo_id
|
111
|
+
}.merge!(web_services)
|
112
|
+
|
113
|
+
session_factory.create_session(java.util.HashMap.new(params))
|
100
114
|
end
|
101
115
|
|
102
116
|
def self.repositories(url, user, password)
|
103
117
|
session_factory = SessionFactoryImpl.new_instance
|
104
|
-
|
118
|
+
params = {
|
105
119
|
SessionParameter::ATOMPUB_URL => url,
|
106
120
|
SessionParameter::BINDING_TYPE => BindingType::ATOMPUB.value,
|
107
121
|
SessionParameter::USER => user,
|
108
122
|
SessionParameter::PASSWORD => password
|
109
123
|
}
|
110
124
|
|
111
|
-
session_factory.get_repositories(
|
125
|
+
session_factory.get_repositories(java.util.HashMap.new(params))
|
112
126
|
end
|
113
127
|
|
114
128
|
def self.create_content_stream(filename, session)
|
data/lib/cmis/version.rb
CHANGED
data/spec/cmis_spec.rb
CHANGED
@@ -18,6 +18,7 @@ describe "CMIS" do
|
|
18
18
|
end
|
19
19
|
|
20
20
|
describe "Repository functionality" do
|
21
|
+
|
21
22
|
it "should create a session" do
|
22
23
|
@session.is_a?(Java::OrgApacheChemistryOpencmisClientRuntime::SessionImpl).should be_true
|
23
24
|
end
|
@@ -306,11 +307,31 @@ describe "CMIS" do
|
|
306
307
|
end
|
307
308
|
|
308
309
|
describe "Local Alfresco" do
|
310
|
+
# Basic test for web service binding
|
311
|
+
it "should be possible to use web services" do
|
312
|
+
repo_id = CMIS::repositories("http://localhost:8181/alfresco/service/cmis", "admin", "admin")[0].id
|
313
|
+
ws_url = "http://localhost:8181/alfresco/cmis/"
|
314
|
+
ws_urls = {
|
315
|
+
CMIS::SessionParameter::WEBSERVICES_ACL_SERVICE => "#{ws_url}ACLService?wsdl",
|
316
|
+
CMIS::SessionParameter::WEBSERVICES_DISCOVERY_SERVICE => "#{ws_url}DiscoveryService?wsdl",
|
317
|
+
CMIS::SessionParameter::WEBSERVICES_MULTIFILING_SERVICE => "#{ws_url}MultiFilingService?wsdl",
|
318
|
+
CMIS::SessionParameter::WEBSERVICES_NAVIGATION_SERVICE => "#{ws_url}NavigationService?wsdl",
|
319
|
+
CMIS::SessionParameter::WEBSERVICES_OBJECT_SERVICE => "#{ws_url}ObjectService?wsdl",
|
320
|
+
CMIS::SessionParameter::WEBSERVICES_POLICY_SERVICE => "#{ws_url}PolicyService?wsdl",
|
321
|
+
CMIS::SessionParameter::WEBSERVICES_RELATIONSHIP_SERVICE => "#{ws_url}RelationshipService?wsdl",
|
322
|
+
CMIS::SessionParameter::WEBSERVICES_REPOSITORY_SERVICE => "#{ws_url}RepositoryService?wsdl",
|
323
|
+
CMIS::SessionParameter::WEBSERVICES_VERSIONING_SERVICE => "#{ws_url}VersioningService?wsdl"
|
324
|
+
}
|
325
|
+
|
326
|
+
@ws_session = CMIS::create_session_with_soap("admin", "admin", ws_urls, repo_id)
|
327
|
+
@ws_session.locale.should_not be_nil
|
328
|
+
end
|
329
|
+
|
309
330
|
atom_url = "http://localhost:8181/alfresco/service/cmis"
|
310
331
|
user = "admin"
|
311
332
|
password = "admin"
|
312
333
|
|
313
|
-
|
334
|
+
it_behaves_like "a CMIS repository", atom_url, user, password
|
314
335
|
end
|
315
336
|
|
316
337
|
describe "Alfresco" do
|
@@ -318,7 +339,7 @@ describe "CMIS" do
|
|
318
339
|
user = "admin"
|
319
340
|
password = "admin"
|
320
341
|
|
321
|
-
it_behaves_like "a CMIS repository", atom_url, user, password
|
342
|
+
#it_behaves_like "a CMIS repository", atom_url, user, password
|
322
343
|
end
|
323
344
|
|
324
345
|
describe "Nuxeo" do
|
@@ -326,6 +347,6 @@ describe "CMIS" do
|
|
326
347
|
user = "Administrator"
|
327
348
|
password = "Administrator"
|
328
349
|
|
329
|
-
it_behaves_like "a CMIS repository", atom_url, user, password
|
350
|
+
#it_behaves_like "a CMIS repository", atom_url, user, password
|
330
351
|
end
|
331
352
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cmis
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
prerelease:
|
6
6
|
platform: java
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-02-15 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|