def on_post(self, req, resp):
        doc = req.context['doc']
        try:
            obj = PatternPhraseManager()
            results = {"message": ""}
            if not obj.add_phrase(doc):
                results[
                    'message'] = "A record with the same name exists in the database"
                resp.status = falcon.HTTP_BAD_REQUEST

            else:
                results['message'] = "Added successfully"
                resp.status = falcon.HTTP_200
            resp.data = results

        except AssertionError as ae:
            logger.exception(ae, exc_info=True)
            logger.error(traceback.format_exc())
            raise falcon.HTTPPreconditionFailed(
                'Service publish condition failed', traceback.format_exc())

        except Exception as ex:
            logger.exception(ex, exc_info=True)
            description = 'Internal Server Error, Please try again later'
            raise falcon.HTTPServiceUnavailable('Service Outage', description,
                                                30)
        resp.set_header('X-Powered-By', 'USTGlobal ICE')
    def on_post(self, req, resp):
        doc = req.context['doc']
        language = get(doc, "language", "EN")
        results = {}
        try:
            obj = PatternPhraseManager()
            if language is not None:
                patterns = self.format_result(
                    obj.fetch_all_patterns_by_language(language))
                phrases = self.format_result(
                    obj.fetch_all_phrases_by_language(language))
                results['patterns'] = patterns
                results['phrases'] = phrases
            else:
                raise Exception("Model Language not specified...")
            resp.data = results
        except AssertionError as ae:
            logger.exception(ae, exc_info=True)
            logger.error(traceback.format_exc())
            raise falcon.HTTPPreconditionFailed(
                'Service publish condition failed', traceback.format_exc())

        except Exception as ex:
            logger.exception(ex, exc_info=True)
            description = 'Internal Server Error, Please try again later'
            raise falcon.HTTPServiceUnavailable('Service Outage', description,
                                                30)

        resp.set_header('X-Powered-By', 'USTGlobal ICE')
        resp.status = falcon.HTTP_200
    def on_post(self, req, resp):
        doc = req.context['doc']
        try:
            obj = PatternPhraseManager()
            obj.remove_phrase(doc)

        except AssertionError as ae:
            logger.exception(ae, exc_info=True)
            logger.error(traceback.format_exc())
            raise falcon.HTTPPreconditionFailed(
                'Service publish condition failed', traceback.format_exc())

        except Exception as ex:
            logger.exception(ex, exc_info=True)
            description = 'Internal Server Error, Please try again later'
            raise falcon.HTTPServiceUnavailable('Service Outage', description,
                                                30)

        resp.set_header('X-Powered-By', 'USTGlobal ICE')
        resp.status = falcon.HTTP_200
    def on_get(self, req, resp):
        phrase = req.get_param(name="name", default=None)
        try:
            obj = PatternPhraseManager()
            if phrase is None:
                results = obj.get_all_phrases()
            else:
                results = obj.get_phrase(phrase)
            resp.data = results

        except AssertionError as ae:
            logger.exception(ae, exc_info=True)
            logger.error(traceback.format_exc())
            raise falcon.HTTPPreconditionFailed(
                'Service publish condition failed', traceback.format_exc())

        except Exception as ex:
            logger.exception(ex, exc_info=True)
            description = 'Internal Server Error, Please try again later'
            raise falcon.HTTPServiceUnavailable('Service Outage', description,
                                                30)

        resp.set_header('X-Powered-By', 'USTGlobal ICE')
        resp.status = falcon.HTTP_200