예제 #1
0
    def update_document(self, document):
        """Update Document"""

        try:
            return self.collection.replace(document)
        except exceptions.DocumentReplaceError as err:
            if err.error_code == 1202:
                msg = 'There no document with key {}'.format(document['_key'])
                app.logger.warning(msg)
                raise gmap_exceptions.DocumentNotExist(msg)
            elif err.error_code == 1210:
                msg = 'Unique constraint violated in index primary with key {}'.format(
                    document['_key'])
                app.logger.warning(msg)
            else:
                app.logger.error(err.message)
                raise gmap_exceptions.DocumentException(
                    doc_err.get(0).format(document['_key'], err.message))

        except Exception as err:
            if err.error_code == 1200:
                msg = 'There is a conflict in document update with key {}'.format(
                    document['_key'])
                app.logger.warning(msg)
            else:
                app.logger.error(err)
                raise gmap_exceptions.DocumentException(
                    doc_err.get(0).format(document['_key'], str(err)))
예제 #2
0
    def create_document(self, document):
        """Create Document"""

        try:
            return self.collection.insert(document)
        except exceptions.DocumentInsertError as err:

            if doc_err.get(err.error_code):
                if err.error_code == 1210:
                    app.logger.warning(err.message)
                    raise gmap_exceptions.DocumentAlreadyExist(
                        doc_err.get(err.error_code).format(document['_key']))
                else:
                    app.logger.error(err.message)
                    raise gmap_exceptions.DocumentException(
                        doc_err.get(err.error_code).format(document['_key']))

            else:
                raise gmap_exceptions.DocumentException(
                    doc_err.get(0).format(document['_key'], err.message))

        except Exception as err:
            if err.error_code == 1200:
                msg = 'There is a conflict in document create with key {}'.format(
                    document['_key'])
                app.logger.warning(msg)
            else:
                app.logger.error(err)
                raise gmap_exceptions.DocumentException(
                    doc_err.get(0).format(document['_key'], str(err)))
예제 #3
0
    def update_document(self, document):
        """Update Document"""

        try:
            return self.collection.update(document)
        except exceptions.DocumentInsertError as err:

            if err.error_code == 1202:
                msg = 'There no document with key {}'.format(document['_key'])
                raise gmap_exceptions.DocumentNotExist(msg)

            else:
                raise gmap_exceptions.DocumentException(
                    doc_err.get(0).format(document['_key'], err.message))

        except Exception as err:
            raise gmap_exceptions.DocumentException(
                doc_err.get(0).format(document['_key'], err.message))
예제 #4
0
    def create_document(self, document):
        """Create Document"""

        try:
            return self.collection.insert(document)
        except exceptions.DocumentInsertError as err:

            if doc_err.get(err.error_code):
                raise gmap_exceptions.DocumentException(
                    doc_err.get(err.error_code).format(document['_key']))

            else:
                raise gmap_exceptions.DocumentException(
                    doc_err.get(0).format(document['_key'], err.message))

        except Exception as err:
            raise gmap_exceptions.DocumentException(
                doc_err.get(0).format(document['_key'], err.message))
예제 #5
0
    def update_document(self, document):
        """Update Document"""

        try:
            return self.collection.update(document)
        except exceptions.DocumentInsertError as err:

            if err.error_code == 1202:
                msg = 'There no document with key {}'.format(document['_key'])
                raise gmap_exceptions.DocumentNotExist(msg)

            else:
                raise gmap_exceptions.DocumentException(
                    doc_err.get(0).format(document['_key'], err.message))

        except Exception as err:
            raise gmap_exceptions.DocumentException(
                doc_err.get(0).format(document['_key'], err.message))
예제 #6
0
    def create_document(self, document):
        """Create Document"""

        try:
            return self.collection.insert(document)
        except exceptions.DocumentInsertError as err:

            if doc_err.get(err.error_code):
                raise gmap_exceptions.DocumentException(
                    doc_err.get(err.error_code).format(document['_key']))

            else:
                raise gmap_exceptions.DocumentException(
                    doc_err.get(0).format(document['_key'], err.message))

        except Exception as err:
            raise gmap_exceptions.DocumentException(
                doc_err.get(0).format(document['_key'], err.message))
예제 #7
0
    def delete_document(self, key):
        """Delete Document"""

        try:
            self.collection.delete(key)
        except exceptions.DocumentDeleteError as err:

            if err.error_code == 1202:
                msg = 'There no document with key {}'.format(key)
                raise gmap_exceptions.DocumentNotExist(msg)

            else:
                raise gmap_exceptions.DocumentException(
                    doc_err.get(0).format(key, err.message))

        except Exception as err:
            raise gmap_exceptions.DocumentException(
                doc_err.get(0).format(key, err.message))
        else:
            return True
예제 #8
0
    def delete_document(self, key):
        """Delete Document"""

        try:
            self.collection.delete(key)
        except exceptions.DocumentDeleteError as err:

            if err.error_code == 1202:
                msg = 'There no document with key {}'.format(key)
                raise gmap_exceptions.DocumentNotExist(msg)

            else:
                raise gmap_exceptions.DocumentException(
                    doc_err.get(0).format(key, err.message))

        except Exception as err:
            raise gmap_exceptions.DocumentException(
                doc_err.get(0).format(key, err.message))
        else:
            return True
예제 #9
0
    def get_document(self, key):
        """Get Document"""

        try:
            document = self.collection.get(key)

        except Exception as err:
            raise gmap_exceptions.DocumentException(
                doc_err.get(0).format(key, err.message))
        else:
            if document is None:
                msg = 'There no document with key {}'.format(key)
                raise gmap_exceptions.DocumentNotExist(msg)

            return document
예제 #10
0
    def get_document(self, key):
        """Get Document"""

        try:
            document = self.collection.get(key)

        except Exception as err:
            raise gmap_exceptions.DocumentException(
                doc_err.get(0).format(key, err.message))
        else:
            if document is None:
                msg = 'There no document with key {}'.format(key)
                raise gmap_exceptions.DocumentNotExist(msg)

            return document
예제 #11
0
    def get_document(self, key):
        """Get Document"""

        try:
            document = self.collection.get(key)

        except Exception as err:
            app.logger.error(err)
            raise gmap_exceptions.DocumentException(
                doc_err.get(0).format(key, str(err)))
        else:
            if document is None:
                msg = 'There no document with key {}'.format(key)
                app.logger.warning(msg)
                raise gmap_exceptions.DocumentNotExist(msg)

            return document