# Path: monasca_api/common/repositories/notifications_repository.py
# class NotificationsRepository(object):
#     def create_notification(self, tenant_id, name, notification_type,
#                             address, period):
#     def list_notifications(self, tenant_id, sort_by, offset, limit):
#     def delete_notification(self, tenant_id, notification_id):
#     def list_notification(self, tenant_id, notification_id):
#     def update_notification(self, notification_id, tenant_id, name, notification_type,
#                             address, period):
# 
# Path: monasca_api/common/repositories/sqla/models.py
# def get_all_metadata():
# def create_a_model(metadata=None):
# def create_sadd_model(metadata=None):
# def create_aa_model(metadata=None):
# def create_md_model(metadata=None):
# def create_mde_model(metadata=None):
# def create_nm_model(metadata=None):
# def create_nmt_model(metadata=None):
# def create_mdd_model(metadata=None):
# def create_am_model(metadata=None):
# def create_ad_model(metadata=None):
# def create_sa_model(metadata=None):
# def create_sad_model(metadata=None):
#     def __init__(self, columns, separator=',', order_by=None):
# def _group_concat_oracle(element, compiler_, **kw):
# def _group_concat_postgresql(element, compiler_, **kw):
# def _group_concat_sybase(element, compiler_, **kw):
# def _group_concat_mysql(element, compiler_, **kw):
# def _group_concat_default(element, compiler_, **kw):
#     def __init__(self, column, fields):
# def _field_sort_mysql(element, compiler_, **kw):
# def _field_sort_general(element, compiler_, **kw):
# class group_concat(expression.ColumnElement):
# class field_sort(expression.ColumnElement):


import datetime
import six
from oslo_utils import uuidutils
from monasca_api.common.repositories import exceptions
from monasca_api.common.repositories import notifications_repository as nr
from monasca_api.common.repositories.sqla import models
from monasca_api.common.repositories.sqla import sql_repository
from sqlalchemy import MetaData, update, insert, delete
from sqlalchemy import select, bindparam, func, and_, literal_column
                    order_columns.append(nm.c.id)
            else:
                order_columns = [nm.c.id]

            select_nm_query = select_nm_query.order_by(*order_columns)

            select_nm_query = (select_nm_query
                               .order_by(nm.c.id)
                               .limit(bindparam('b_limit')))

            parms['b_limit'] = limit + 1

            if offset:
                select_nm_query = select_nm_query.offset(bindparam('b_offset'))
                parms['b_offset'] = offset

            rows = conn.execute(select_nm_query, parms).fetchall()

        return [dict(row) for row in rows]

    @sql_repository.sql_try_catch_block
    def delete_notification(self, tenant_id, _id):

        with self._db_engine.connect() as conn:

            row = conn.execute(self._select_nm_count_id_query,
                               b_tenant_id=tenant_id,
                               b_id=_id).fetchone()

            if int(row[0]) < 1:

# Path: monasca_api/common/repositories/notifications_repository.py
# class NotificationsRepository(object):
#     def create_notification(self, tenant_id, name, notification_type,
#                             address, period):
#     def list_notifications(self, tenant_id, sort_by, offset, limit):
#     def delete_notification(self, tenant_id, notification_id):
#     def list_notification(self, tenant_id, notification_id):
#     def update_notification(self, notification_id, tenant_id, name, notification_type,
#                             address, period):
# 
# Path: monasca_api/common/repositories/sqla/models.py
# def get_all_metadata():
# def create_a_model(metadata=None):
# def create_sadd_model(metadata=None):
# def create_aa_model(metadata=None):
# def create_md_model(metadata=None):
# def create_mde_model(metadata=None):
# def create_nm_model(metadata=None):
# def create_nmt_model(metadata=None):
# def create_mdd_model(metadata=None):
# def create_am_model(metadata=None):
# def create_ad_model(metadata=None):
# def create_sa_model(metadata=None):
# def create_sad_model(metadata=None):
#     def __init__(self, columns, separator=',', order_by=None):
# def _group_concat_oracle(element, compiler_, **kw):
# def _group_concat_postgresql(element, compiler_, **kw):
# def _group_concat_sybase(element, compiler_, **kw):
# def _group_concat_mysql(element, compiler_, **kw):
# def _group_concat_default(element, compiler_, **kw):
#     def __init__(self, column, fields):
# def _field_sort_mysql(element, compiler_, **kw):
# def _field_sort_general(element, compiler_, **kw):
# class group_concat(expression.ColumnElement):
# class field_sort(expression.ColumnElement):


# Path: monasca_api/common/repositories/sqla/notifications_repository.py
import datetime
import six
from oslo_utils import uuidutils
from monasca_api.common.repositories import exceptions
from monasca_api.common.repositories import notifications_repository as nr
from monasca_api.common.repositories.sqla import models
from monasca_api.common.repositories.sqla import sql_repository
from sqlalchemy import MetaData, update, insert, delete
from sqlalchemy import select, bindparam, func, and_, literal_column

                    order_columns.append(nm.c.id)
            else:
                order_columns = [nm.c.id]

            select_nm_query = select_nm_query.order_by(*order_columns)

            select_nm_query = (select_nm_query
                               .order_by(nm.c.id)
                               .limit(bindparam('b_limit')))

            parms['b_limit'] = limit + 1

            if offset:
                select_nm_query = select_nm_query.offset(bindparam('b_offset'))
                parms['b_offset'] = offset

            rows = conn.execute(select_nm_query, parms).fetchall()

        return [dict(row) for row in rows]

    @sql_repository.sql_try_catch_block
    def delete_notification(self, tenant_id, _id):

        with self._db_engine.connect() as conn:

            row = conn.execute(self._select_nm_count_id_query,
                               b_tenant_id=tenant_id,
                               b_id=_id).fetchone()

            if int(row[0]) < 1:

                raise exceptions.DoesNotExistException