Пример #1
0
    def delete(self, id, file_set_id, file_id):
    
        # Retrieve repository
        repository_dao = RepositoryDao(self.db_session())
        repository = repository_dao.retrieve(id=id)
        if repository is None:
            return self.error_response('Repository {} not found'.format(id), http.NOT_FOUND_404)
    
        # Get file set and check its part of repository
        file_set_dao = FileSetDao(self.db_session())
        file_set = file_set_dao.retrieve(id=file_set_id)
        if file_set is None:
            return self.error_response('File set {} not found'.format(file_set_id), http.NOT_FOUND_404)

        # Get file and check it's also part of repository
        f_dao = FileDao(self.db_session())
        f = f_dao.retrieve(id=file_id)
        if f is None:
            return self.error_response('File {} not found'.format(file_id), http.NOT_FOUND_404)
        if f.repository != repository:
            return self.error_response('File {} not in repository {}'.format(file_id, id), http.BAD_REQUEST_400)

        # Remove file from file set
        if f in file_set.files:
            file_set.remove(f)
            file_set_dao.save(file_set)

        return self.response(file_set.to_dict())
Пример #2
0
    def put(self, id, file_set_id):

        parser = reqparse.RequestParser()
        parser.add_argument('name', type=str, required=True, location='json')
        args = parser.parse_args()

        # Retrieve repository
        repository_dao = RepositoryDao(self.db_session())
        repository = repository_dao.retrieve(id=id)
        if repository is None:
            return self.error_response('Repository {} not found'.format(id), http.NOT_FOUND_404)
        
        # Retrieve file set and check it belongs to repository
        file_set_dao = FileSetDao(self.db_session())
        file_set = file_set_dao.retrieve(id=file_set_id)
        if file_set is None:
            return self.error_response('File set {} not found'.format(file_set_id), http.NOT_FOUND_404)
        if file_set.repository != repository:
            return self.error_response('File set {} not in repository {}'.format(file_set_id, id), http.BAD_REQUEST_400)
        
        # Update file set
        file_set.name = args['name']
        file_set_dao.save(file_set)

        return self.response(file_set.to_dict())
Пример #3
0
    def get(self, id, file_set_id):
        
        # Retrieve repository
        repository_dao = RepositoryDao(self.db_session())
        repository = repository_dao.retrieve(id=id)
        if repository is None:
            return self.error_response('Repository {} not found'.format(id), http.NOT_FOUND_404)
        
        # Retrieve file set and check it's a member of repository
        file_set_dao = FileSetDao(self.db_session())
        file_set = file_set_dao.retrieve(id=file_set_id)
        if file_set is None:
            return self.error_response('File set {} not found'.format(id), http.NOT_FOUND_404)
        if file_set.repository != repository:
            return self.error_response('File set {} not in repository {}'.format(file_set_id, id), http.BAD_REQUEST_400)

        return self.response(file_set.to_dict())
Пример #4
0
    def post(self):

        parser = reqparse.RequestParser()
        parser.add_argument('name', type=str, required=True, location='json')
        args = parser.parse_args()

        # Retrieve repository
        repository_dao = RepositoryDao(self.db_session())
        repository = repository_dao.retrieve(id=id)
        if repository is None:
            return self.error_response('Repository {} not found'.format(id), http.NOT_FOUND_404)
        args['repository'] = repository

        # Create file set
        file_set_dao = FileSetDao(self.db_session())
        file_set = file_set_dao.create(**args)

        return self.response(file_set.to_dict(), http.CREATED_201)
Пример #5
0
    def delete(self, id, file_set_id):
    
        # Retrieve repository
        repository_dao = RepositoryDao(self.db_session())
        repository = repository_dao.retrieve(id=id)
        if repository is None:
            return self.error_response('Repository {} not found'.format(id), http.NOT_FOUND_404)
    
        # Retrieve file set and check it belongs to repository
        file_set_dao = FileSetDao(self.db_session())
        file_set = file_set_dao.retrieve(id=file_set_id)
        if file_set is None:
            return self.error_response('File set {} not found'.format(file_set_id), http.NOT_FOUND_404)
        if file_set.repository != repository:
            return self.error_response('File set {} not in repository {}'.format(file_set_id, id), http.BAD_REQUEST_400)
        
        # Delete file set
        file_set_dao.delete(file_set)

        return self.response({}, http.NO_CONTENT_204)
Пример #6
0
    def put(self, id, file_set_id, file_id):
    
        # Retrieve repository
        repository_dao = RepositoryDao(self.db_session())
        repository = repository_dao.retrieve(id=id)
        if repository is None:
            return self.error_response('Repository {} not found'.format(id), http.NOT_FOUND_404)
    
        # Get file set and check its part of repository
        file_set_dao = FileSetDao(self.db_session())
        file_set = file_set_dao.retrieve(id=file_set_id)
        if file_set is None:
            return self.error_response('File set {} not found'.format(file_set_id), http.NOT_FOUND_404)
        if file_set.repository != repository:
            return self.error_response('File set {} not in repository {}'.format(file_set_id, id), http.BAD_REQUEST_400)
        
        # Get file and check it's also part of repository
        f_dao = FileDao(self.db_session())
        f = f_dao.retrieve(id=file_id)
        if f is None:
            return self.error_response('File {} not found'.format(file_id), http.NOT_FOUND_404)
        if f.repository != repository:
            return self.error_response('File {} not in repository {}'.format(file_id, id), http.BAD_REQUEST_400)

        # Add file to file set
        if f not in file_set.files:
            # Verify that given file complies with file set schema. This requires that
            # schema validation is enabled on the file set. The schema specification
            # specifies which additional arguments should be provided for each file, e.g.,
            # subject ID, session ID, etc.
            # TODO: Implement file set schemas or something similar...
            if file_set.schema_enabled:
                pass

            # Schema seems to be satisfied so add the file to the set and save.
            file_set.files.append(f)
            file_set_dao.save(file_set)

        return self.response(file_set.to_dict())