From b347e6c5106ea464e0baf81b00b26144201e826c Mon Sep 17 00:00:00 2001 From: EL HADJI DEM Date: Fri, 21 Mar 2014 18:35:36 -0400 Subject: [PATCH 01/14] [ADD] add cmis module: It allows to configure a CMIS backend in OpenERP --- cmis/__init__.py | 26 +++++++++ cmis/__openerp__.py | 62 ++++++++++++++++++++ cmis/backend.py | 32 +++++++++++ cmis/cmis_menu.xml | 17 ++++++ cmis/cmis_model.py | 121 +++++++++++++++++++++++++++++++++++++++ cmis/cmis_model_view.xml | 67 ++++++++++++++++++++++ cmis/connector.py | 39 +++++++++++++ 7 files changed, 364 insertions(+) create mode 100644 cmis/__init__.py create mode 100644 cmis/__openerp__.py create mode 100644 cmis/backend.py create mode 100644 cmis/cmis_menu.xml create mode 100644 cmis/cmis_model.py create mode 100644 cmis/cmis_model_view.xml create mode 100644 cmis/connector.py diff --git a/cmis/__init__.py b/cmis/__init__.py new file mode 100644 index 00000000..b6b1b965 --- /dev/null +++ b/cmis/__init__.py @@ -0,0 +1,26 @@ +# -*- encoding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# This module copyright (C) 2014 Savoir-faire Linux +# (). +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## + +from . import cmis_model +from . import backend + +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/cmis/__openerp__.py b/cmis/__openerp__.py new file mode 100644 index 00000000..d0336961 --- /dev/null +++ b/cmis/__openerp__.py @@ -0,0 +1,62 @@ +# -*- encoding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# This module copyright (C) 2014 Savoir-faire Linux +# (). +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## + +{ + 'name': 'CMIS', + 'version': '0.1', + 'category': 'Connector', + 'summary': 'Cmis Connector', + 'description': """ +Cmis Connector +============== + +This module is the base for OpenERP modules implementing different integration scenario with a CMIS server. +It allows you to configure a CMIS backend in OpenERP. + +Configuration +============= + +Create a new CMIS backend with the host, login and password. + +Contributors +------------ +* El Hadji Dem (elhadji.dem@savoirfairelinux.com) +""", + 'author': 'Savoir-faire Linux', + 'website': 'www.savoirfairelinux.com', + 'license': 'AGPL-3', + 'depends': [ + 'connector', + ], + 'data': [ + 'cmis_model_view.xml', + 'cmis_menu.xml', + ], + 'js': [], + 'qweb': [], + 'test': [], + 'demo': [], + 'installable': True, + 'auto_install': False, +} + +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/cmis/backend.py b/cmis/backend.py new file mode 100644 index 00000000..8ac85895 --- /dev/null +++ b/cmis/backend.py @@ -0,0 +1,32 @@ +# -*- encoding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# This module copyright (C) 2014 Savoir-faire Linux +# (). +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## + +import openerp.addons.connector.backend as backend + + +cmis = backend.Backend('cmis') +""" Generic CMIS Backend """ + +cmis1700 = backend.Backend(parent=cmis, version='1.7') +""" CMIS Backend for version 1.7 """ + +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/cmis/cmis_menu.xml b/cmis/cmis_menu.xml new file mode 100644 index 00000000..9613d0d7 --- /dev/null +++ b/cmis/cmis_menu.xml @@ -0,0 +1,17 @@ + + + + + + + + + + diff --git a/cmis/cmis_model.py b/cmis/cmis_model.py new file mode 100644 index 00000000..dc0c1d1d --- /dev/null +++ b/cmis/cmis_model.py @@ -0,0 +1,121 @@ +# -*- encoding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# This module copyright (C) 2014 Savoir-faire Linux +# (). +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## + +from openerp.osv import orm, fields, osv +from openerp.tools.translate import _ +from openerp.addons.connector.queue.job import job +from cmislib.model import CmisClient +import openerp.addons.connector as connector +from openerp.addons.connector.session import ConnectorSession + + +class cmis_backend(orm.Model): + _name = 'cmis.backend' + _description = 'CMIS Backend' + _inherit = 'connector.backend' + + _backend_type = 'cmis' + + def _select_versions(self, cr, uid, context=None): + return [('1.7', '1.7')] + + # Test connection with GED + def _auth(self, cr, uid, context=None): + if context is None: + context = {} + # Get the url, user and password for GED + ids = self.search(cr, uid, []) + res = self.read(cr, uid, ids, + ['location', + 'username', + 'password'], context=context)[0] + url = res['location'] + user_name = res['username'] + user_password = res['password'] + client = CmisClient(url, user_name, user_password) + if not client: + raise osv.except_osv(_('Cmis connection Error!'), + _("Check your cmis account configuration.")) + return client + + def test_directory_of_write(self, cr, uid, ids, context=None): + if context is None: + context = {} + cmis_backend_obj = self.pool.get('cmis.backend') + #login with the cmis account + client = cmis_backend_obj._auth(cr, uid, context=context) + repo = client.defaultRepository + folder_path_write = cmis_backend_obj.read(cr, uid, ids, ['initial_directory_write'], + context=context)[0]['initial_directory_write'] + # Testing the path + rs = repo.query("SELECT cmis:path FROM cmis:folder ") + bool_path_write = self.test_existing_path(rs, folder_path_write) + self.get_error_for_path(bool_path_write, folder_path_write) + + def test_directory_of_read(self, cr, uid, ids, context=None): + if context is None: + context = {} + cmis_backend_obj = self.pool.get('cmis.backend') + #login with the cmis account + client = cmis_backend_obj._auth(cr, uid, context=context) + repo = client.defaultRepository + folder_path_read = cmis_backend_obj.read(cr, uid, ids, ['initial_directory_read'], + context=context)[0]['initial_directory_read'] + # Testing the path + rs = repo.query("SELECT cmis:path FROM cmis:folder ") + bool_path_read = self.test_existing_path(rs, folder_path_read) + self.get_error_for_path(bool_path_read, folder_path_read) + + def test_existing_path(self, rs, folder_path): + for one_rs in rs: + # Print name of files + props = one_rs.getProperties() + if props['cmis:path'] != folder_path: + bool = False + else: + bool = True + break + return bool + + def get_error_for_path(self, bool, path): + if bool: + raise osv.except_osv(_('Cmis Message'), + _("Path is correct for : " + path)) + else: + raise osv.except_osv(_('Cmis Error!'), + _("Error path for : " + path)) + + _columns = { + 'version': fields.selection( + _select_versions, + string='Version', + required=True), + 'location': fields.char('Location', size=128, help="Location."), + 'username': fields.char('Username', size=64, help="Username."), + 'password': fields.char('Password', size=64, help="Password."), + 'initial_directory_read': fields.char('Initial directory of read', + size=128, help="Initial directory of read."), + 'initial_directory_write': fields.char('Initial directory of write', + size=128, help="Initial directory of write."), + } + +# vim:expandtab:smartindent:toabstop=4:softtabstop=4:shiftwidth=4: diff --git a/cmis/cmis_model_view.xml b/cmis/cmis_model_view.xml new file mode 100644 index 00000000..8a73e488 --- /dev/null +++ b/cmis/cmis_model_view.xml @@ -0,0 +1,67 @@ + + + + + + cmis.backend.form + cmis.backend + +
+ + +
+
+
+ + + cmis.backend.tree + cmis.backend + + + + + + + + + + + CMIS Backends + cmis.backend + form + tree,form + + +
+
diff --git a/cmis/connector.py b/cmis/connector.py new file mode 100644 index 00000000..044d8a2f --- /dev/null +++ b/cmis/connector.py @@ -0,0 +1,39 @@ +# -*- encoding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# This module copyright (C) 2014 Savoir-faire Linux +# (). +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## + +from openerp.osv import orm, fields +from openerp.addons.connector.connector import (Environment, + install_in_connector) + +install_in_connector() + + +def get_environment(session, model_name, backend_id): + """ Create an environment to work with. """ + backend_record = session.browse('cmis.backend', backend_id) + env = Environment(backend_record, session, model_name) + lang = backend_record.default_lang_id + lang_code = lang.code if lang else 'en_US' + env.set_lang(code=lang_code) + return env + +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: From 43af0f0f669a0c603e3011669a1b8ef1ace44069 Mon Sep 17 00:00:00 2001 From: EL HADJI DEM Date: Tue, 1 Apr 2014 10:24:56 -0400 Subject: [PATCH 02/14] [IMP] add the good version for cmislib and add the external_dependencies --- cmis/__openerp__.py | 3 +++ cmis/cmis_model.py | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/cmis/__openerp__.py b/cmis/__openerp__.py index d0336961..c083cc60 100644 --- a/cmis/__openerp__.py +++ b/cmis/__openerp__.py @@ -47,6 +47,9 @@ Contributors 'depends': [ 'connector', ], + 'external_dependencies': { + 'python': ['cmislib'], + }, 'data': [ 'cmis_model_view.xml', 'cmis_menu.xml', diff --git a/cmis/cmis_model.py b/cmis/cmis_model.py index dc0c1d1d..efe57df9 100644 --- a/cmis/cmis_model.py +++ b/cmis/cmis_model.py @@ -36,7 +36,7 @@ class cmis_backend(orm.Model): _backend_type = 'cmis' def _select_versions(self, cr, uid, context=None): - return [('1.7', '1.7')] + return [('1.0', '1.0')] # Test connection with GED def _auth(self, cr, uid, context=None): From fe8b214132f887b487d3233b36b2f82833cea6c9 Mon Sep 17 00:00:00 2001 From: EL HADJI DEM Date: Tue, 1 Apr 2014 17:39:37 -0400 Subject: [PATCH 03/14] [IMP] add the good version --- cmis/backend.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cmis/backend.py b/cmis/backend.py index 8ac85895..a6590cb8 100644 --- a/cmis/backend.py +++ b/cmis/backend.py @@ -26,7 +26,7 @@ import openerp.addons.connector.backend as backend cmis = backend.Backend('cmis') """ Generic CMIS Backend """ -cmis1700 = backend.Backend(parent=cmis, version='1.7') -""" CMIS Backend for version 1.7 """ +cmis1000 = backend.Backend(parent=cmis, version='1.0') +""" CMIS Backend for version 1.0 """ # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: From 856406bcd7c91723766b930a7af64a4ec9bd17b0 Mon Sep 17 00:00:00 2001 From: EL HADJI DEM Date: Wed, 16 Apr 2014 17:02:22 -0400 Subject: [PATCH 04/14] [IMP] Check the permission when reading or writing doc --- cmis/cmis_model.py | 65 ++++++++++++++++++++++++++++++---------- cmis/cmis_model_view.xml | 4 +-- 2 files changed, 52 insertions(+), 17 deletions(-) diff --git a/cmis/cmis_model.py b/cmis/cmis_model.py index efe57df9..5a4f3772 100644 --- a/cmis/cmis_model.py +++ b/cmis/cmis_model.py @@ -26,6 +26,7 @@ from openerp.addons.connector.queue.job import job from cmislib.model import CmisClient import openerp.addons.connector as connector from openerp.addons.connector.session import ConnectorSession +import base64 class cmis_backend(orm.Model): @@ -36,7 +37,7 @@ class cmis_backend(orm.Model): _backend_type = 'cmis' def _select_versions(self, cr, uid, context=None): - return [('1.0', '1.0')] + return [('1.7', '1.7')] # Test connection with GED def _auth(self, cr, uid, context=None): @@ -57,35 +58,65 @@ class cmis_backend(orm.Model): _("Check your cmis account configuration.")) return client - def test_directory_of_write(self, cr, uid, ids, context=None): + def check_directory_of_write(self, cr, uid, ids, context=None): if context is None: context = {} cmis_backend_obj = self.pool.get('cmis.backend') + datas_fname = 'testdoc' #login with the cmis account client = cmis_backend_obj._auth(cr, uid, context=context) repo = client.defaultRepository - folder_path_write = cmis_backend_obj.read(cr, uid, ids, ['initial_directory_write'], - context=context)[0]['initial_directory_write'] + folder_path_write = cmis_backend_obj.read( + cr, uid, ids, ['initial_directory_write'], + context=context)[0]['initial_directory_write'] # Testing the path - rs = repo.query("SELECT cmis:path FROM cmis:folder ") - bool_path_write = self.test_existing_path(rs, folder_path_write) + rs = repo.query("SELECT cmis:path FROM cmis:folder") + bool_path_write = self.check_existing_path(rs, folder_path_write) + # Check if we can create a doc from OE to EDM + # Document properties + if bool_path_write: + sub = repo.getObjectByPath(folder_path_write) + someDoc = sub.createDocumentFromString( + datas_fname, + contentString='hello, world', + contentType='text/plain') self.get_error_for_path(bool_path_write, folder_path_write) - def test_directory_of_read(self, cr, uid, ids, context=None): + def check_directory_of_read(self, cr, uid, ids, context=None): + ir_attach_obj = self.pool.get('ir.attachment') + ir_attach_dms_obj = self.pool.get('ir.attachment.dms') if context is None: context = {} cmis_backend_obj = self.pool.get('cmis.backend') #login with the cmis account client = cmis_backend_obj._auth(cr, uid, context=context) repo = client.defaultRepository - folder_path_read = cmis_backend_obj.read(cr, uid, ids, ['initial_directory_read'], - context=context)[0]['initial_directory_read'] + folder_path_read = cmis_backend_obj.read( + cr, uid, ids, ['initial_directory_read'], + context=context)[0]['initial_directory_read'] # Testing the path rs = repo.query("SELECT cmis:path FROM cmis:folder ") - bool_path_read = self.test_existing_path(rs, folder_path_read) + bool_path_read = self.check_existing_path(rs, folder_path_read) + file_name = 'testdoc' + # Add testdoc in the context just to check if it is as test + context['bool_testdoc'] = True + if bool_path_read: + # Get results from name of document + results = repo.query(" SELECT * FROM cmis:document \ + WHERE cmis:name LIKE '%" + file_name + "%'") + for result in results: + info = result.getProperties() + data_attach = { + 'name': info['cmis:name'], + 'datas_fname': info['cmis:name'], + 'type': 'binary', + 'datas': result.getContentStream().read().encode('base64'), + } + res = ir_attach_obj.create(cr, uid, data_attach, + context=context) self.get_error_for_path(bool_path_read, folder_path_read) - def test_existing_path(self, rs, folder_path): + def check_existing_path(self, rs, folder_path): for one_rs in rs: # Print name of files props = one_rs.getProperties() @@ -112,10 +143,14 @@ class cmis_backend(orm.Model): 'location': fields.char('Location', size=128, help="Location."), 'username': fields.char('Username', size=64, help="Username."), 'password': fields.char('Password', size=64, help="Password."), - 'initial_directory_read': fields.char('Initial directory of read', - size=128, help="Initial directory of read."), - 'initial_directory_write': fields.char('Initial directory of write', - size=128, help="Initial directory of write."), + 'initial_directory_read': fields.char( + 'Initial directory of read', + size=128, + help="Initial directory of read."), + 'initial_directory_write': fields.char( + 'Initial directory of write', + size=128, + help="Initial directory of write."), } # vim:expandtab:smartindent:toabstop=4:softtabstop=4:shiftwidth=4: diff --git a/cmis/cmis_model_view.xml b/cmis/cmis_model_view.xml index 8a73e488..49c1080f 100644 --- a/cmis/cmis_model_view.xml +++ b/cmis/cmis_model_view.xml @@ -29,11 +29,11 @@
-
+