grapefruit 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bcb692f301d7d33fbec2f8bff1cc82ba310a8525
4
- data.tar.gz: 786bafee98285b1b38918995d5ef61dde59a9913
3
+ metadata.gz: 56440bfc747e9db9fb39b37a0be2ef717f6d04bd
4
+ data.tar.gz: 713c3cda200b0166fc8a10a6fd1870c141d4c6bd
5
5
  SHA512:
6
- metadata.gz: 9c95753a5a34320aa79bbf6790e6d7c0448fc2964923342566351908f7e700c42a7ce67d9384f2ebe647860fecd596ed2fe6b71505a899530c1adff40f3d3cb5
7
- data.tar.gz: 44ad9d285f21060465588f4fcdf1136e4d413877f384f963629e5b707119b47fa2f6e4cdaea92dec7965f3fdf64bcdeecdf7058126286b4ec65789f85c75ef9a
6
+ metadata.gz: 0bab8545b7d17474beed41988cba1409f8c20eee02a439b225ec5534123985d622e8cf066a19635cad55a795c28f97991890fe718513f2210254f889004fd39d
7
+ data.tar.gz: 3082d4ac47a4a135c948096d50fa5d3a910994762780ee601fda512f5b264d8a66afce95275d28911c9c165355b1d92460fb5e1ac4f22eb50208255eefdea312
@@ -2,6 +2,7 @@ require 'dotenv'
2
2
  Dotenv.load
3
3
  require "grapefruit/version"
4
4
  require "grapefruit/cmis_client"
5
+ require "grapefruit/folder"
5
6
 
6
7
  module Grapefruit
7
8
  # Your code goes here...
@@ -12,9 +12,9 @@ module Grapefruit
12
12
  @password = password
13
13
  fetch_ticket
14
14
  #Loading Alfresco repository using active_cmis client
15
- @repository = ActiveCMIS.load_config('alfresco_config', File.expand_path(ENV["CMIS_YML"]))
16
- @root = repository.root_folder
17
- @sites = fetch_sites
15
+ self.repository = ActiveCMIS.load_config('alfresco_config', File.expand_path(ENV["CMIS_YML"]))
16
+ self.root = repository.root_folder
17
+ self.sites = fetch_sites
18
18
  end
19
19
 
20
20
  def fetch_ticket
@@ -24,10 +24,9 @@ module Grapefruit
24
24
  end
25
25
 
26
26
  def fetch_sites
27
- @sites = @root.items.select { |i| i.name == "Sites" }[0]
27
+ sites = root.items.select { |i| i.name == "Sites" }[0]
28
28
  end
29
29
 
30
-
31
30
  def ticket_url
32
31
  "#{@url}/alfresco/service/api/login?u=#{@username}&pw=#{@password}"
33
32
  end
@@ -36,23 +35,14 @@ module Grapefruit
36
35
  "#{ENV['CMIS_HOST']}/alfresco/s/cmis/s/workspace:SpacesStore/i/51ccddc0-d1e6-43fe-b75e-87675659977e/tree"
37
36
  end
38
37
 
39
- def getRoot
40
- @root
41
- end
42
-
43
- #path ex: pearson/
44
- def getFolder(path)
45
- curr_folder = @sites
46
- path.slice!(0) if path[0]== "/"
47
- path.split("/").map!{ |s| s.downcase }.each do |name|
48
- folder = curr_folder.items.select { |i| i.name.downcase == name }[0]
49
- if folder
50
- curr_folder = folder
51
- else
52
- raise 'Dumb ? you have passed a wrong path'
53
- end
54
- end
55
- curr_folder
38
+ def create_folder(folder)
39
+ xml = folder.to_xml
40
+ response = RestClient.post("#{ENV['CMIS_HOST']}/alfresco/s/cmis/p/children?alf_ticket=#{ticket}", xml.strip, :content_type => :atom)
41
+ doc = Nokogiri::XML.parse(response)
42
+ ns = doc.collect_namespaces
43
+ folder.cmis_object_id = doc.xpath("//cmis:propertyId[@propertyDefinitionId='cmis:objectId']", ns).text().strip
44
+ # Handle errors
45
+ folder
56
46
  end
57
47
 
58
48
  end
@@ -0,0 +1,31 @@
1
+ module Grapefruit
2
+ class Folder
3
+ attr_accessor :client, :title, :cmis_object_id
4
+
5
+ def initialize(client=Grapefruit::CmisClient)
6
+ self.client = client
7
+ end
8
+
9
+ def save
10
+ client.create_folder(self)
11
+ end
12
+
13
+ def to_xml
14
+ <<-eoxml
15
+ <?xml version="1.0" encoding="utf-8"?>
16
+ <entry xmlns="http://www.w3.org/2005/Atom"
17
+ xmlns:cmisra="http://docs.oasis-open.org/ns/cmis/restatom/200908/"
18
+ xmlns:cmis="http://docs.oasis-open.org/ns/cmis/core/200908/">
19
+ <title>#{title}</title>
20
+ <cmisra:object>
21
+ <cmis:properties>
22
+ <cmis:propertyId propertyDefinitionId="cmis:objectTypeId">
23
+ <cmis:value>cmis:folder</cmis:value>
24
+ </cmis:propertyId>
25
+ </cmis:properties>
26
+ </cmisra:object>
27
+ </entry>
28
+ eoxml
29
+ end
30
+ end
31
+ end
@@ -1,3 +1,3 @@
1
1
  module Grapefruit
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
@@ -31,17 +31,23 @@ describe "cmis client", :contract => true do
31
31
  expect(@sut.sites).to be_true
32
32
  end
33
33
 
34
- it "Verify the correct folder path" do
35
- expect(@sut.getFolder("Pearson/documentLibrary")).to be_true
36
-
34
+ context "Creating Folders" do
35
+ it "should make a request to the CMIS host to create a folder" do
36
+ sut = Grapefruit::CmisClient.new(ENV["CMIS_HOST"], ENV["CMIS_USER"], ENV["CMIS_PASS"])
37
+ folder = sut.create_folder(FakeFolder.new)
38
+ expect(folder.cmis_object_id).to be
39
+ end
40
+ it "should be able to create a folder under another given folder" do
41
+ pending "Not Yet Implemented"
42
+ end
43
+ it "should optionally behave like mkdir -p" do
44
+ pending "Not Yet"
45
+ end
46
+ it "should not try to create folders that already exist" do
47
+ pending "Not Yet"
48
+ end
37
49
  end
38
50
 
39
- it "Verfiy the slash in front of path should pass" do
40
- expect(@sut.getFolder("/Pearson/documentLibrary")).to be_true
41
- end
42
51
 
43
- it "Verfiy we are able to retrieve Reading folder" do
44
- expect(@sut.getFolder("/pearson/documentLibrary/SuccessMaker UK/Reading").name).to eq('Reading')
45
- end
46
52
 
47
53
  end
@@ -0,0 +1,89 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <entry xmlns="http://www.w3.org/2005/Atom" xmlns:alf="http://www.alfresco.org" xmlns:app="http://www.w3.org/2007/app" xmlns:cmis="http://docs.oasis-open.org/ns/cmis/core/200908/" xmlns:cmisra="http://docs.oasis-open.org/ns/cmis/restatom/200908/">
3
+ <author>
4
+ <name>claytonlz</name>
5
+ </author>
6
+ <content src="http://cmsstg.smdemo.info:80/alfresco/s/cmis/s/workspace:SpacesStore/i/9e9087a5-0ece-42c8-84b6-6940eb6b28fa/content" />
7
+ <id>urn:uuid:9e9087a5-0ece-42c8-84b6-6940eb6b28fa</id>
8
+ <link rel="self" href="http://cmsstg.smdemo.info:80/alfresco/s/cmis/s/workspace:SpacesStore/i/9e9087a5-0ece-42c8-84b6-6940eb6b28fa" />
9
+ <link rel="edit" href="http://cmsstg.smdemo.info:80/alfresco/s/cmis/s/workspace:SpacesStore/i/9e9087a5-0ece-42c8-84b6-6940eb6b28fa" />
10
+ <link rel="http://docs.oasis-open.org/ns/cmis/link/200908/allowableactions" href="http://cmsstg.smdemo.info:80/alfresco/s/cmis/s/workspace:SpacesStore/i/9e9087a5-0ece-42c8-84b6-6940eb6b28fa/allowableactions" />
11
+ <link rel="http://docs.oasis-open.org/ns/cmis/link/200908/relationships" href="http://cmsstg.smdemo.info:80/alfresco/s/cmis/s/workspace:SpacesStore/i/9e9087a5-0ece-42c8-84b6-6940eb6b28fa/rels" />
12
+ <link rel="http://docs.oasis-open.org/ns/cmis/link/200908/policies" href="http://cmsstg.smdemo.info:80/alfresco/s/cmis/s/workspace:SpacesStore/i/9e9087a5-0ece-42c8-84b6-6940eb6b28fa/pols" />
13
+ <link rel="http://docs.oasis-open.org/ns/cmis/link/200908/acl" href="http://cmsstg.smdemo.info:80/alfresco/s/cmis/s/workspace:SpacesStore/i/9e9087a5-0ece-42c8-84b6-6940eb6b28fa/acl" />
14
+ <link rel="up" href="http://cmsstg.smdemo.info:80/alfresco/s/cmis/s/workspace:SpacesStore/i/ec50a0b7-fa2d-473a-8057-c2907aef7023" type="application/atom+xml;type=entry" />
15
+ <link rel="down" href="http://cmsstg.smdemo.info:80/alfresco/s/cmis/s/workspace:SpacesStore/i/9e9087a5-0ece-42c8-84b6-6940eb6b28fa/children" type="application/atom+xml;type=feed" />
16
+ <link rel="down" href="http://cmsstg.smdemo.info:80/alfresco/s/cmis/s/workspace:SpacesStore/i/9e9087a5-0ece-42c8-84b6-6940eb6b28fa/descendants" type="application/cmistree+xml" />
17
+ <link rel="http://docs.oasis-open.org/ns/cmis/link/200908/foldertree" href="http://cmsstg.smdemo.info:80/alfresco/s/cmis/s/workspace:SpacesStore/i/9e9087a5-0ece-42c8-84b6-6940eb6b28fa/tree" type="application/atom+xml;type=feed" />
18
+ <link rel="describedby" href="http://cmsstg.smdemo.info:80/alfresco/s/cmis/type/cmis:folder" />
19
+ <link rel="service" href="http://cmsstg.smdemo.info:80/alfresco/s/cmis" />
20
+ <published>2013-12-03T14:51:53.168-07:00</published>
21
+ <summary>Team Exception</summary>
22
+ <title>Team Exception</title>
23
+ <updated>2013-12-03T14:51:53.168-07:00</updated>
24
+ <app:edited>2013-12-03T14:51:53.168-07:00</app:edited>
25
+ <alf:icon>http://cmsstg.smdemo.info:80/alfresco/images/icons/space-icon-default-16.gif</alf:icon>
26
+ <cmisra:object>
27
+ <cmis:properties>
28
+ <cmis:propertyId propertyDefinitionId="cmis:allowedChildObjectTypeIds" displayName="Allowed Child Object Types Ids" queryName="cmis:allowedChildObjectTypeIds" />
29
+ <cmis:propertyId propertyDefinitionId="cmis:objectTypeId" displayName="Object Type Id" queryName="cmis:objectTypeId">
30
+ <cmis:value>cmis:folder</cmis:value>
31
+ </cmis:propertyId>
32
+ <cmis:propertyString propertyDefinitionId="cmis:path" displayName="Path" queryName="cmis:path">
33
+ <cmis:value>/Team Exception</cmis:value>
34
+ </cmis:propertyString>
35
+ <cmis:propertyString propertyDefinitionId="cmis:name" displayName="Name" queryName="cmis:name">
36
+ <cmis:value>Team Exception</cmis:value>
37
+ </cmis:propertyString>
38
+ <cmis:propertyDateTime propertyDefinitionId="cmis:creationDate" displayName="Creation Date" queryName="cmis:creationDate">
39
+ <cmis:value>2013-12-03T14:51:53.168-07:00</cmis:value>
40
+ </cmis:propertyDateTime>
41
+ <cmis:propertyString propertyDefinitionId="cmis:changeToken" displayName="Change token" queryName="cmis:changeToken" />
42
+ <cmis:propertyString propertyDefinitionId="cmis:lastModifiedBy" displayName="Last Modified By" queryName="cmis:lastModifiedBy">
43
+ <cmis:value>claytonlz</cmis:value>
44
+ </cmis:propertyString>
45
+ <cmis:propertyString propertyDefinitionId="cmis:createdBy" displayName="Created by" queryName="cmis:createdBy">
46
+ <cmis:value>claytonlz</cmis:value>
47
+ </cmis:propertyString>
48
+ <cmis:propertyId propertyDefinitionId="cmis:objectId" displayName="Object Id" queryName="cmis:objectId">
49
+ <cmis:value>workspace://SpacesStore/9e9087a5-0ece-42c8-84b6-6940eb6b28fa</cmis:value>
50
+ </cmis:propertyId>
51
+ <cmis:propertyId propertyDefinitionId="alfcmis:nodeRef" displayName="Alfresco Node Ref" queryName="alfcmis:nodeRef" />
52
+ <cmis:propertyId propertyDefinitionId="cmis:baseTypeId" displayName="Base Type Id" queryName="cmis:baseTypeId">
53
+ <cmis:value>cmis:folder</cmis:value>
54
+ </cmis:propertyId>
55
+ <cmis:propertyDateTime propertyDefinitionId="cmis:lastModificationDate" displayName="Last Modified Date" queryName="cmis:lastModificationDate">
56
+ <cmis:value>2013-12-03T14:51:53.168-07:00</cmis:value>
57
+ </cmis:propertyDateTime>
58
+ <cmis:propertyId propertyDefinitionId="cmis:parentId" displayName="Parent Id" queryName="cmis:parentId">
59
+ <cmis:value>workspace://SpacesStore/ec50a0b7-fa2d-473a-8057-c2907aef7023</cmis:value>
60
+ </cmis:propertyId>
61
+ <alf:aspects>
62
+ <alf:appliedAspects>P:sys:localized</alf:appliedAspects>
63
+ <alf:properties />
64
+ </alf:aspects>
65
+ </cmis:properties>
66
+ <cmis:allowableActions>
67
+ <cmis:canDeleteObject>true</cmis:canDeleteObject>
68
+ <cmis:canUpdateProperties>true</cmis:canUpdateProperties>
69
+ <cmis:canGetFolderTree>true</cmis:canGetFolderTree>
70
+ <cmis:canGetProperties>true</cmis:canGetProperties>
71
+ <cmis:canGetObjectRelationships>true</cmis:canGetObjectRelationships>
72
+ <cmis:canGetObjectParents>true</cmis:canGetObjectParents>
73
+ <cmis:canGetFolderParent>true</cmis:canGetFolderParent>
74
+ <cmis:canGetDescendants>true</cmis:canGetDescendants>
75
+ <cmis:canMoveObject>true</cmis:canMoveObject>
76
+ <cmis:canApplyPolicy>false</cmis:canApplyPolicy>
77
+ <cmis:canGetAppliedPolicies>true</cmis:canGetAppliedPolicies>
78
+ <cmis:canRemovePolicy>false</cmis:canRemovePolicy>
79
+ <cmis:canGetChildren>true</cmis:canGetChildren>
80
+ <cmis:canCreateDocument>true</cmis:canCreateDocument>
81
+ <cmis:canCreateFolder>true</cmis:canCreateFolder>
82
+ <cmis:canCreateRelationship>true</cmis:canCreateRelationship>
83
+ <cmis:canDeleteTree>true</cmis:canDeleteTree>
84
+ <cmis:canGetACL>true</cmis:canGetACL>
85
+ <cmis:canApplyACL>true</cmis:canApplyACL>
86
+ </cmis:allowableActions>
87
+ </cmisra:object>
88
+ <cmisra:pathSegment>Team Exception</cmisra:pathSegment>
89
+ </entry>
@@ -0,0 +1,59 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Folders" do
4
+ it "should have a default client" do
5
+ sut = Grapefruit::Folder.new
6
+ expect(sut.client).to be
7
+ end
8
+ it "should be able to take a custom client" do
9
+ fake = FakeCMISClient.new
10
+ sut = Grapefruit::Folder.new(fake)
11
+ expect(sut.client).to eq(fake)
12
+ end
13
+ it "should have a title" do
14
+ sut = Grapefruit::Folder.new(FakeCMISClient)
15
+ sut.title = "Title"
16
+ expect(sut.title).to eq("Title")
17
+ end
18
+
19
+ it "should have a cmis object id" do
20
+ sut = Grapefruit::Folder.new(FakeCMISClient)
21
+ sut.cmis_object_id = 123
22
+ expect(sut.cmis_object_id).to eq(123)
23
+ end
24
+
25
+ context "Persisting Folders" do
26
+ it "should be able to persist a folder using the client" do
27
+ mock = double(Grapefruit::CmisClient, :create_folder => true)
28
+ sut = Grapefruit::Folder.new(mock)
29
+ mock.should_receive(:create_folder).with(sut)
30
+ sut.save
31
+ end
32
+ end
33
+
34
+ context "Viewing as XML" do
35
+ it "should be able to represent itself as an CMIS XML document" do
36
+ sut = Grapefruit::Folder.new(FakeCMISClient.new)
37
+ sut.title = "Cats are Cool"
38
+
39
+ xml_string = <<-eoxml
40
+ <?xml version="1.0" encoding="utf-8"?>
41
+ <entry xmlns="http://www.w3.org/2005/Atom"
42
+ xmlns:cmisra="http://docs.oasis-open.org/ns/cmis/restatom/200908/"
43
+ xmlns:cmis="http://docs.oasis-open.org/ns/cmis/core/200908/">
44
+ <title>Cats are Cool</title>
45
+ <cmisra:object>
46
+ <cmis:properties>
47
+ <cmis:propertyId propertyDefinitionId="cmis:objectTypeId">
48
+ <cmis:value>cmis:folder</cmis:value>
49
+ </cmis:propertyId>
50
+ </cmis:properties>
51
+ </cmisra:object>
52
+ </entry>
53
+ eoxml
54
+
55
+ expect(sut.to_xml).to eq(xml_string)
56
+ end
57
+ end
58
+ end
59
+
@@ -1 +1,24 @@
1
1
  require File.join(File.expand_path(File.dirname(__FILE__)),"..","lib","grapefruit")
2
+
3
+ class FakeCMISClient
4
+ end
5
+
6
+ class FakeFolder < Grapefruit::Folder
7
+ def to_xml
8
+ <<-eoxml
9
+ <?xml version="1.0" encoding="utf-8"?>
10
+ <entry xmlns="http://www.w3.org/2005/Atom"
11
+ xmlns:cmisra="http://docs.oasis-open.org/ns/cmis/restatom/200908/"
12
+ xmlns:cmis="http://docs.oasis-open.org/ns/cmis/core/200908/">
13
+ <title>Test Folder #{Time.now.to_f}</title>
14
+ <cmisra:object>
15
+ <cmis:properties>
16
+ <cmis:propertyId propertyDefinitionId="cmis:objectTypeId">
17
+ <cmis:value>cmis:folder</cmis:value>
18
+ </cmis:propertyId>
19
+ </cmis:properties>
20
+ </cmisra:object>
21
+ </entry>
22
+ eoxml
23
+ end
24
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: grapefruit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Team Exception
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-12-02 00:00:00.000000000 Z
11
+ date: 2013-12-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -129,10 +129,13 @@ files:
129
129
  - grapefruit.gemspec
130
130
  - lib/grapefruit.rb
131
131
  - lib/grapefruit/cmis_client.rb
132
+ - lib/grapefruit/folder.rb
132
133
  - lib/grapefruit/interface.rb
133
134
  - lib/grapefruit/module Grapefruit
134
135
  - lib/grapefruit/version.rb
135
136
  - spec/cmis_client_spec.rb
137
+ - spec/fixtures/create_folder_response.xml
138
+ - spec/folder_spec.rb
136
139
  - spec/spec_helper.rb
137
140
  homepage: ''
138
141
  licenses:
@@ -154,10 +157,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
154
157
  version: '0'
155
158
  requirements: []
156
159
  rubyforge_project:
157
- rubygems_version: 2.1.11
160
+ rubygems_version: 2.0.3
158
161
  signing_key:
159
162
  specification_version: 4
160
163
  summary: A sane library for interacting with Alfresco
161
164
  test_files:
162
165
  - spec/cmis_client_spec.rb
166
+ - spec/fixtures/create_folder_response.xml
167
+ - spec/folder_spec.rb
163
168
  - spec/spec_helper.rb