yaccl 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,4 @@
1
+ Gemfile.lock
2
+
3
+ .idea
4
+ *.iml
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source :rubygems
2
+
3
+ gemspec
4
+
5
+ gem 'rake'
6
+ gem 'rspec'
@@ -0,0 +1,7 @@
1
+ require 'rspec/core/rake_task'
2
+
3
+ RSpec::Core::RakeTask.new(:spec) do |spec|
4
+ spec.rspec_opts = ['--colour']
5
+ end
6
+
7
+ task default: [:spec]
@@ -0,0 +1,40 @@
1
+ require 'yaccl'
2
+
3
+ repository = YACCL::Model::Server.repository('blueprint')
4
+
5
+ type = YACCL::Model::Type.new
6
+ type.id = 'apple'
7
+ type.local_name = 'apple'
8
+ type.query_name = 'apple'
9
+ type.display_name = 'Apple'
10
+ type.parent_id = 'cmis:document'
11
+ type.base_id = 'cmis:document'
12
+ type.description = 'The apple fruit.'
13
+ type.creatable = true
14
+ type.fileable = true
15
+ type.queryable = true
16
+ type.controllable_policy = true
17
+ type.controllable_acl = true
18
+ type.fulltext_indexed = true
19
+ type.included_in_supertype_query = true
20
+ type.content_stream_allowed = 'allowed'
21
+ type.versionable = false
22
+
23
+ type.add_property_definition(
24
+ id: 'color',
25
+ localName: 'color',
26
+ queryName: 'color',
27
+ displayName: 'Color',
28
+ description: 'The color.',
29
+ propertyType: 'string',
30
+ cardinality: 'single',
31
+ updatability: 'readwrite',
32
+ inherited: false,
33
+ required: false,
34
+ queryable: true,
35
+ orderable: true
36
+ )
37
+
38
+ full_type = repository.create_type(type)
39
+ puts full_type.to_hash
40
+ repository.delete_type(type.id)
@@ -0,0 +1,10 @@
1
+ module YACCL
2
+ VERSION = '0.0.1'
3
+
4
+ def self.init(url)
5
+ YACCL.const_set('SERVICE_URL', url)
6
+ end
7
+ end
8
+
9
+ require 'yaccl/model'
10
+ require 'yaccl/services'
@@ -0,0 +1,10 @@
1
+ require 'yaccl/model/object'
2
+ require 'yaccl/model/object_factory'
3
+ require 'yaccl/model/document'
4
+ require 'yaccl/model/folder'
5
+ require 'yaccl/model/item'
6
+ require 'yaccl/model/policy'
7
+ require 'yaccl/model/relationship'
8
+ require 'yaccl/model/repository'
9
+ require 'yaccl/model/type'
10
+ require 'yaccl/model/server'
@@ -0,0 +1,63 @@
1
+ module YACCL
2
+ module Model
3
+ class Document < Object
4
+ attr_reader :is_immutable
5
+ attr_reader :is_latest_version
6
+ attr_reader :is_major_version
7
+ attr_reader :is_latest_major_version
8
+ attr_reader :is_private_working_copy
9
+ attr_reader :version_label
10
+ attr_reader :version_series_id
11
+ attr_reader :version_series_checked_out
12
+ attr_reader :version_series_checked_out_by
13
+ attr_reader :version_series_checked_out_id
14
+ attr_reader :checkin_comment
15
+ attr_reader :content_stream_length
16
+ attr_reader :content_stream_mime_type
17
+ attr_reader :content_stream_file_name
18
+ attr_reader :content_stream_id
19
+
20
+ def initialize(repository_id, raw={})
21
+ super
22
+ @is_immutable = @properties[:'cmis:isImmutable']
23
+ @is_latest_version = @properties[:'cmis:isLatestVersion']
24
+ @is_major_version = @properties[:'cmis:isMajorVersion']
25
+ @is_lastest_major_version = @properties[:'cmis:isLatestMajorVersion']
26
+ @is_private_working_copy = @properties[:'cmis:isPrivateWorkingCopy']
27
+ @version_label = @properties[:'cmis:versionLabel']
28
+ @version_series_id = @properties[:'cmis:versionSeriesId']
29
+ @version_series_checked_out = @properties[:'cmis:isVersionSeriesCheckedOut']
30
+ @version_series_checked_out_by = @properties[:'cmis:versionSeriesCheckedOutBy']
31
+ @version_series_checked_out_id = @properties[:'cmis:versionSeriesCheckedOutId']
32
+ @checkin_comment = @properties[:'cmis:checkinComment']
33
+ @content_stream_length = @properties[:'cmis:contentStreamLength']
34
+ @content_stream_mime_type = @properties[:'cmis:contentStreamMimeType']
35
+ @content_stream_file_name = @properties[:'cmis:contentStreamFileName']
36
+ @content_stream_id = @properties[:'cmis:contentStreamId']
37
+ end
38
+
39
+ def copy_in_folder(folder)
40
+ new_object_id = Services.create_document_from_source(repository_id, object_id, nil, folder.object_id, nil, nil, nil, nil)
41
+ repository.object(new_object_id)
42
+ end
43
+
44
+ def content
45
+ Services.get_content_stream(repository_id, object_id, nil, nil, nil)
46
+ end
47
+
48
+ def set_content(stream, mime_type, filename)
49
+ content = {stream: stream, mime_type: mime_type, filename: filename}
50
+ if detached?
51
+ @local_content = content
52
+ else
53
+ Services.set_content_stream(repository_id, object_id, nil, nil, content)
54
+ end
55
+ end
56
+
57
+ def create_in_folder(folder_id)
58
+ hash = Services.create_document(repository_id, create_properties, folder_id, @local_content, nil, nil, nil, nil)
59
+ ObjectFactory.create(repository_id, hash)
60
+ end
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,66 @@
1
+ module YACCL
2
+ module Model
3
+ class Folder < Object
4
+ attr_reader :parent_id
5
+ attr_reader :path
6
+ attr_reader :allowed_child_object_type_ids
7
+
8
+ def initialize(repository_id, raw={})
9
+ super
10
+ @parent_id = @properties[:'cmis:parentId']
11
+ @path = @properties[:'cmis:path']
12
+ @allowed_child_object_type_ids = @properties[:'cmis:allowedChildObjectTypeIds']
13
+ end
14
+
15
+ def parent
16
+ repository.object(parent_id) unless parent_id.nil?
17
+ end
18
+
19
+ def allowed_child_object_types
20
+ return nil if allowed_child_object_type_ids.nil?
21
+ allowed_child_object_type_ids.map do |type_id|
22
+ repository.type(type_id)
23
+ end
24
+ end
25
+
26
+ def children
27
+ Services.navigation.get_children(repository_id, object_id, nil, nil, nil, nil, nil, nil, nil, nil).map do |o|
28
+ ObjectFactory.create(repository_id, o)
29
+ end
30
+ end
31
+
32
+ def tree(depth)
33
+ end
34
+
35
+ def create(object)
36
+ properties = object.create_properties
37
+ if object.is_a? Folder
38
+ o = Services.create_folder(repository_id, properties, object_id, nil, nil, nil)
39
+ elsif object.is_a? Document
40
+ return object.create_in_folder(object_id)
41
+ elsif object.is_a? Relationship
42
+ raise 'relationship is not fileable'
43
+ elsif object.is_a? Policy
44
+ o = Services.create_policy(repository_id, properties, object_id, nil, nil, nil)
45
+ elsif object.is_a? Item
46
+ o = Services.create_item(repository_id, properties, object_id, nil, nil, nil)
47
+ else
48
+ raise "Unexpected base_type_id: #{object.base_type_id}"
49
+ end
50
+ ObjectFactory.create(repository_id, o)
51
+ end
52
+
53
+ def delete_tree
54
+ Services.delete_tree(repository_id, object_id, true, false, false)
55
+ end
56
+
57
+ def add(object)
58
+ Services.add_object_to_folder(repository_id, object.object_id, object_id, nil)
59
+ end
60
+
61
+ def remove(object)
62
+ Services.remove_object_from_folder(repository_id, object.object_id, object_id)
63
+ end
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,9 @@
1
+ module YACCL
2
+ module Model
3
+ class Item < Object
4
+ def initialize(repository_id, raw={})
5
+ super
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,98 @@
1
+ module YACCL
2
+ module Model
3
+ class Object
4
+ attr_reader :repository_id
5
+ attr_reader :object_id
6
+ attr_reader :base_type_id
7
+ attr_accessor :object_type_id
8
+ attr_reader :secondary_object_type_ids
9
+ attr_accessor :name
10
+ attr_reader :description
11
+ attr_reader :created_by
12
+ attr_reader :creation_date
13
+ attr_reader :last_modified_by
14
+ attr_reader :last_modification_date
15
+ attr_reader :change_token
16
+ attr_reader :properties
17
+
18
+ def initialize(repository_id, raw={})
19
+ @repository_id = repository_id
20
+ @properties = get_properties_map(raw)
21
+ @object_id = @properties[:'cmis:objectId']
22
+ @base_type_id = @properties[:'cmis:baseTypeId']
23
+ @object_type_id = @properties[:'cmis:objectTypeId']
24
+ @secondary_object_type_ids = @properties[:'cmis:secondaryObjectTypeId']
25
+ @name = @properties[:'cmis:name']
26
+ @description = @properties[:'cmis:description']
27
+ @created_by = @properties[:'cmis:createdBy']
28
+ @creation_date = @properties[:'cmis:creationDate']
29
+ @last_modified_by = @properties[:'cmis:lastModifiedBy']
30
+ @last_modification_date = @properties[:'cmis:lastModificationDate']
31
+ @change_token = @properties[:'cmis:changeToken']
32
+ end
33
+
34
+ def repository
35
+ Server.repository(repository_id)
36
+ end
37
+
38
+ def object_type
39
+ repository.type(object_type_id)
40
+ end
41
+
42
+ def delete
43
+ Services.delete_object(repository_id, object_id, true)
44
+ end
45
+
46
+ def allowable_actions
47
+ Services.get_allowable_actions(repository_id, object_id)
48
+ end
49
+
50
+ def relationships(direction='either')
51
+ result = Services.get_object_relationships(repository_id, object_id, nil, direction, nil, nil, false, nil, nil)
52
+ result[:objects] = result[:objects].map { |r| Relationship.create(repository_id, r) }
53
+ result
54
+ end
55
+
56
+ def policies
57
+ Services.get_applied_policies(repository_id, object_id, nil).map do |policy|
58
+ Policy.create(repository_id, policy)
59
+ end
60
+ end
61
+
62
+ # remove from all folders
63
+ def unfile
64
+ Services.remove_object_from_folder(repository_id, object_id, nil)
65
+ end
66
+
67
+ def acls
68
+ Services.get_acl(repository_id, object_id, nil)
69
+ end
70
+
71
+ def add_aces(aces)
72
+ Services.apply_acl(repository_id, object_id, aces, nil, nil)
73
+ end
74
+
75
+ def remove_aces(aces)
76
+ Services.apply_acl(repository_id, object_id, nil, aces, nil)
77
+ end
78
+
79
+ protected
80
+
81
+ def create_properties
82
+ {'cmis:name' => name, 'cmis:objectTypeId' => object_type_id}.merge(properties)
83
+ end
84
+
85
+ def detached?
86
+ object_id.nil?
87
+ end
88
+
89
+ private
90
+
91
+ def get_properties_map(raw)
92
+ raw_properties = raw[:properties]
93
+ return {} if raw_properties.nil?
94
+ raw_properties.reduce({}) { |h, (k, v)| h.merge(k => v[:value]) }
95
+ end
96
+ end
97
+ end
98
+ end
@@ -0,0 +1,18 @@
1
+ module YACCL
2
+ module Model
3
+ class ObjectFactory
4
+ def self.create(repository_id, raw)
5
+ properties = raw[:properties]
6
+ base_type_id = properties[:'cmis:baseTypeId'][:value]
7
+ case base_type_id
8
+ when 'cmis:folder' then Folder.new(repository_id, raw)
9
+ when 'cmis:document' then Document.new(repository_id, raw)
10
+ when 'cmis:relationship' then Relationship.new(repository_id, raw)
11
+ when 'cmis:policy' then Policy.new(repository_id, raw)
12
+ when 'cmis:item' then Item.new(repository_id, raw)
13
+ else raise "Unexpected baseTypeId: #{base_type_id}."
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,20 @@
1
+ module YACCL
2
+ module Model
3
+ class Policy < Object
4
+ attr_reader :policy_text
5
+
6
+ def initialize(repository_id, raw={})
7
+ super
8
+ @policy_text = @properties[:'cmis:policyText']
9
+ end
10
+
11
+ def apply_to(object)
12
+ Services.apply_policy(repository_id, object_id, object.object_id)
13
+ end
14
+
15
+ def remove_from(object)
16
+ Services.remove_policy(repository_id, object_id, object.object_id)
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,22 @@
1
+ module YACCL
2
+ module Model
3
+ class Relationship < Object
4
+ attr_reader :source_id
5
+ attr_reader :target_id
6
+
7
+ def initialize(repository_id, raw={})
8
+ super
9
+ @source_id = @properties['cmis:sourceId']
10
+ @target_id = @properties['cmis:targetId']
11
+ end
12
+
13
+ def source
14
+ Object.create(Services.get_object(repository_id, source_id, nil, false, false, nil, false, false))
15
+ end
16
+
17
+ def target
18
+ Object.create(Services.get_object(repository_id, target_id, nil, false, false, nil, false, false))
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,106 @@
1
+ module YACCL
2
+ module Model
3
+ class Repository
4
+ attr_reader :id
5
+ attr_reader :name
6
+ attr_reader :description
7
+ attr_reader :root_folder_id
8
+ attr_reader :capabilities
9
+ attr_reader :url
10
+ attr_reader :latest_change_log_token
11
+ attr_reader :vendor_name
12
+ attr_reader :cmis_version_supported
13
+ attr_reader :acl_capabilities
14
+ attr_reader :product_name
15
+ attr_reader :product_version
16
+ attr_reader :thin_client_uri
17
+ attr_reader :changes_on_type
18
+ attr_reader :root_folder_url
19
+
20
+ def self.create(raw_repository)
21
+ Repository.new(raw_repository)
22
+ end
23
+
24
+ def initialize(raw)
25
+ @id = raw[:repositoryId]
26
+ @name = raw[:repositoryName]
27
+ @description = raw[:repositoryDescription]
28
+ @root_folder_id = raw[:rootFolderId]
29
+ @capabilities = raw[:capabilities]
30
+ @url = raw[:repositoryUrl]
31
+ @latest_change_log_token = raw[:latestChangeLogToken]
32
+ @vendor_name = raw[:vendorName]
33
+ @cmis_version_supported = raw[:cmisVersionSupported]
34
+ @acl_capabilities = raw[:aclCapabilities]
35
+ @product_name = raw[:productName]
36
+ @product_version = raw[:productVersion]
37
+ @thin_client_uri = raw[:thinClientUri]
38
+ @changes_on_type = raw[:changesOnType]
39
+ @root_folder_url = raw[:rootFolderUrl]
40
+ end
41
+
42
+ def new_folder
43
+ Folder.new(id)
44
+ end
45
+
46
+ def new_document
47
+ Document.new(id)
48
+ end
49
+
50
+ def new_relationship
51
+ Relationship.new(id)
52
+ end
53
+
54
+ def new_policy
55
+ Policy.new(id)
56
+ end
57
+
58
+ def new_item
59
+ Item.new(id)
60
+ end
61
+
62
+ # object
63
+
64
+ def root
65
+ ObjectFactory.create(id, Services.get_object(id, root_folder_id, nil, false, nil, nil, false, false))
66
+ end
67
+
68
+ def object(object_id)
69
+ ObjectFactory.create(id, Services.get_object(id, object_id, nil, false, nil, nil, false, false))
70
+ end
71
+
72
+ # type
73
+
74
+ def type(type_id)
75
+ Type.create(Services.get_type_definition(id, type_id))
76
+ end
77
+
78
+ def type_tree
79
+ end
80
+
81
+ def create_type(type)
82
+ Type.create(Services.create_type(id, type.to_hash))
83
+ end
84
+
85
+ def update_type(type)
86
+ Type.create(Services.update_type(id, type.to_hash))
87
+ end
88
+
89
+ def delete_type(type_id)
90
+ Services.delete_type(id, type_id)
91
+ end
92
+
93
+ # discovery
94
+
95
+ def query(statement)
96
+ Services.query(id, statement, false, nil, nil, nil, nil, nil).map do |o|
97
+ ObjectFactory.create(id, o)
98
+ end
99
+ end
100
+
101
+ def content_changes(change_log_token)
102
+ Services.get_content_changes(id, change_log_token, nil, nil, nil, nil)
103
+ end
104
+ end
105
+ end
106
+ end