def setUp(self):
        self.app = create_app('TESTING_CONFIG')
        self.app_context = self.app.app_context()
        self.app_context.push()
        self.client = self.app.test_client()
        self.basedir = os.path.abspath(os.path.dirname(__file__))
        db.create_all()
        test_password = '******'
        Organization.insert_org()
        UserScope.insert_scopes()
        User.insert_user(password=test_password)

        self.client = self.app.test_client(use_cookies=False)

        # set the vars for the connection
        self.cmisUrl =  \
            'https://alfresco.oceanobservatories.org/alfresco/s/api/cmis'
        self.cmisUsername = '******'
        self.cmisPassword = '******'
        self.cmisId = 'c161bc66-4f7e-4a4f-b5f2-aac9fbf1d3cd'

        # cmis is tested elsewhere

        from cmislib.model import CmisClient
        client = CmisClient(self.cmisUrl, self.cmisUsername, self.cmisPassword)
        repo = client.getRepository(self.cmisId)
Exemple #2
0
class DmsAdapter(CRUDAdapter):
    def auth(self):
        backend_record = self.backend_record
        self.client = CmisClient(backend_record.location,
                                 backend_record.username,
                                 backend_record.password)

    def get_repositories(self):
        return {
            r['repositoryId']: r['repositoryName']
            for r in self.client.getRepositories()
        }

    def get_repository(self, repository_id):
        return self.client.getRepository(repository_id)

    def read_document_from_path(self, repository_id, path):
        repo = self.client.getRepository(repository_id)
        if isinstance(path, unicode):
            path = path.encode('utf-8')
        doc = repo.getObjectByPath(path)
        output = StringIO()
        output.write(doc.getContentStream().read())
        data = output.getvalue()
        version = doc.getProperties()['cmis:versionLabel']
        return data, version
 def testGetRepositoryBadId(self):
     """Try to get a repository with a bad repo ID"""
     cmisClient = CmisClient(self.url,
                             self.user,
                             self.pwd,
                             binding=self.binding,
                             **self.ext_args)
     with pytest.raises(ObjectNotFoundException):
         cmisClient.getRepository('123FOO')
    def test_alfresco_bp(self):
        from cmislib.model import CmisClient
        client = CmisClient(self.cmisUrl, self.cmisUsername, self.cmisPassword)
        repo = client.getRepository(self.cmisId)

        from ooiservices.app import alfresco

        # test unauth
        print '\n\ttesting authenication . . .'
        response = self.client.get('/alfresco/', content_type = 'application/json')
        self.assertTrue(response.status_code == 401)

        # lets auth on the services
        headers = self.get_api_headers('admin', 'test')

        # test redirect (if no trailing slash is provided, will get redirect)
        print '\ttesting redirect . . .'
        response = self.client.get('/alfresco', headers = headers,  content_type = 'application/json')
        self.assertTrue(response.status_code == 301)

        # test redirect (if no trailing slash is provided, will get redirect)
        print '\ttesting not found . . .'
        response = self.client.get('/alfresco/notfound', headers = headers,  content_type = 'application/json')
        self.assertTrue(response.status_code == 404)

        # test root (should respond with alfresco repo informatioN)
        print '\ttesting root . . .'
        response = self.client.get('/alfresco/', headers = headers, content_type = 'application/json')
        self.assertTrue(response.status_code == 200)
    def test_cmislib_CRD(self):
        from cmislib.model import CmisClient
        client = CmisClient(self.cmisUrl, self.cmisUsername, self.cmisPassword)
        repo = client.getRepository(self.cmisId)

        # for tests, lets make sure the test folder isn't still there
        try:
            print ". . ."
            someObject = repo.getObjectByPath('/testFolder')
            someObject.deleteTree()
        except:
            print "\tno existing folders..."

        # create a new dir in the root folder
        print "\ttesting folder creation..."
        root = repo.rootFolder
        someFolder = root.createFolder('testFolder')

        # create a test file and drop it in the test folder.
        print "\ttesting file creation..."
        someFile = open(self.basedir + '/mock_data/test.txt', 'r')
        someFolder.createDocument('Test Document', contentFile=someFile)

        # test read by using a full-text search.
        print "\ttesting full-text search (read)..."
        repo.query("select * from cmis:document where contains('test')")

        # Then obliterate the folder and all it's children, mercilessly.
        print "\ttesting delete..."
        someFolder.deleteTree()
 def _repository(self):
     client = CmisClient(
         self._repository_url,
         self.repository_user,
         self.repository_password)
     repositories = client.getRepositories()
     assert len(repositories) == 1
     identifier = repositories[0]['repositoryId']
     return client.getRepository(identifier)
Exemple #7
0
    def make_alfresco_conn(self):
        # create the cmis client
        client = CmisClient(
            self.ALFRESCO_URL, self.ALFRESCO_UN, self.ALFRESCO_PW)

        # connect to the alfresco server and return the repo object
        repo = client.getRepository(self.ALFRESCO_ID)

        # this will be what we work with primarily
        # returns a repo object
        return repo
    def test_cmislib_connection(self):
        from cmislib.model import CmisClient

        # create the connection object
        client = CmisClient(self.cmisUrl, self.cmisUsername, self.cmisPassword)
        # check to make sure the object was created with the correct url
        self.assertEquals(client.repositoryUrl, self.cmisUrl)

        # use the client to connect to the repository
        repo = client.getRepository(self.cmisId)
        # make sure the repo information is referencing the correct repository
        self.assertEqual(repo.info['repositoryId'], self.cmisId)
 def testGetRepository(self):
     """Get a repository by repository ID"""
     cmisClient = CmisClient(self.url,
                             self.user,
                             self.pwd,
                             binding=self.binding,
                             **self.ext_args)
     repo = cmisClient.getDefaultRepository()
     defaultRepoId = repo.getRepositoryId()
     defaultRepoName = repo.getRepositoryName()
     repo = cmisClient.getRepository(defaultRepoId)
     assert defaultRepoId == repo.getRepositoryId()
     assert defaultRepoName == repo.getRepositoryName()
Exemple #10
0
    def make_alfresco_query(self, query):
        '''
        query the alfresco server for all documents matching the search param.
        **CAUTION: THIS MAY TAKE A WHILE TO RESPOND**
        '''
        # create the cmis client
        client = CmisClient(
            self.ALFRESCO_URL, self.ALFRESCO_UN, self.ALFRESCO_PW)

        # connect to the alfresco server and return the repo object
        repo = client.getRepository(self.ALFRESCO_ID)
        # use this files connection method

        # issue the query
        results = repo.query("select * from cmis:document where contains('\"%s\"')" % query)

        return results
    def badSetUp(self):
        self.app = create_app('TESTING_CONFIG')
        self.app_context = self.app.app_context()
        self.app_context.push()
        self.client = self.app.test_client()
        self.basedir = os.path.abspath(os.path.dirname(__file__))

        # set the vars for the connection
        self.cmisUrl = 'http://localhost/alfresco/badsetup'
        self.cmisUsername = '******'
        self.cmisPassword = '******'
        self.cmisId = 'not-correct-code'

        # cmis is tested elsewhere

        from cmislib.model import CmisClient
        client = CmisClient(self.cmisUrl, self.cmisUsername, self.cmisPassword)
        repo = client.getRepository(self.cmisId)
    def start(self):
        if self._repository is not None:
            return self._root

        options = {}
        if self._settings.proxy:
            options['proxy'] = {
                'http': self._settings.proxy,
                'https': self._settings.proxy}

        client = CmisClient(
            self._settings.repository_url,
            self._settings.repository_user,
            self._settings.repository_password,
            **options)

        repositories = client.getRepositories()
        if self._settings.repository_name:
            for repository in repositories:
                if self._settings.repository_name == repository['repositoryName']:
                    break
            else:
                raise RESTConnectorError(
                    u'Unknown repository: %s' % (
                        self._settings.repository_name))
        elif len(repositories) == 1:
            repository = repositories[0]
        else:
            raise RESTConnectorError(
                u'Multiple repository available. Please select one.')
        self._repository_id = repository['repositoryId']
        self._repository = client.getRepository(self._repository_id)

        # Find root
        if self._settings.repository_path:
            self._root = self.get_object_by_path(
                self._settings.repository_path,
                root=True)
        else:
            self._root = cmis_object_to_dict(
                self._repository.getRootFolder(),
                root=True)
        return self._root
Exemple #13
0
    def make_alfresco_cruise_query(self, array,cruise):
        '''
        query the alfresco server for all documents relating to a cruise
        '''
        # create the cmis client
        client = CmisClient(self.ALFRESCO_URL, self.ALFRESCO_UN, self.ALFRESCO_PW)

        # connect to the alfresco server and return the repo object
        repo = client.getRepository(self.ALFRESCO_ID)
        # use this files connection method

        doc = repo.getObjectByPath("/OOI/"+array+" Array/Cruise Data")
        folder_query = "IN_FOLDER('"+doc.id+"')"

        array_cruises = repo.query("select * FROM cmis:folder  WHERE "+folder_query)

        #setup the cruise information
        results = []
        cruise_id = None
        if len(cruise) > 0:
            cruise_split = re.split('\s|-|;|,|\*|\n',cruise)
            cruise = "-".join(cruise_split)
            #unique case...
            if cruise == "Scarlett-Isabella":
                cruise = "SI"

            for r in array_cruises:
                cruise_str = r.getName().split("_")[1]
                if cruise in cruise_str:
                    cruise_id = r
                    break

            #only should the cruise information if its availablep
            if cruise_id is not None:
                cruise_results = repo.query("select * FROM cmis:document where IN_FOLDER('"+cruise_id.id+"')")
                for c in cruise_results:
                    c.type = "cruise"
                #add the cruise link
                cruise_id.type = "link"
                return cruise_results,cruise_id

        #return the defaults if not available
        return results,cruise_id