Beispiel #1
0
    def modify_user(ctx, user):
        global user_database

        if not (user.userid in user_database):
            raise ResourceNotFoundError(user.userid)

        user_database[user.userid] = user
Beispiel #2
0
    def delete_user(ctx, userid):
        global user_database

        if not (userid in user_database):
            raise ResourceNotFoundError(userid)

        del user_database[userid]
 def OrderPayment(ctx, PaymentInput: OrderPaymentRequest):
     message_url = ctx.udc.message_url
     message_name = ctx.udc.message_name
     auth_key = ctx.udc.token
     # Get user_id, order_id, instance_id, and callback
     user_id = PaymentInput.user_id
     order_id = PaymentInput.order_id
     instance_id = PaymentInput.instance_id
     callback = PaymentInput.callback
     callback_type = PaymentInput.callback_type
     payment_method = PaymentInput.payment_method
     if (payment_method != 'ovo' and payment_method != 'go_pay'
             and payment_method != 'bank' and payment_method != 'bank_va'):
         raise ArgumentError("Payment method not available")
     # Create payload
     payload = create_request(user_id, order_id, instance_id, callback,
                              callback_type, payment_method, auth_key,
                              message_name)
     print(payload)
     camunda_resp = requests.post(message_url, json=payload)
     if camunda_resp.status_code == 404:
         raise ResourceNotFoundError(camunda_resp)
     elif not camunda_resp.ok:
         raise InternalError(Exception("Spyne Server Error"))
     return OrderPaymentResp(
         200,
         "Processing your input. Detail will be given to your callback URL")
Beispiel #4
0
    def add_recommendation(self, activity_id, recommendation):
        try:
            activity = Activity.objects.get(pk=activity_id)
            if type(activity.is_violated) == bytes:
                activity.is_violated = bool.from_bytes(activity.is_violated,
                                                       "big")

            if type(activity.is_normal) == bytes:
                activity.is_normal = bool.from_bytes(activity.is_normal, "big")

            if activity.is_normal:
                raise Exception("Activity is labeled as normal")

            latest_activity = ActivityRecommendation.objects.latest('id')

            latest_id = latest_activity.id + 1

            activity_recommendation = ActivityRecommendation()
            activity_recommendation.id = latest_id
            activity_recommendation.activity_id = activity.id
            activity_recommendation.recommendation = recommendation
            activity_recommendation.save(force_insert=True)
        except ObjectDoesNotExist as ex:
            raise ResourceNotFoundError('Activity %s not found' % activity_id)
        except Exception as ex:
            raise Fault(faultstring=str(ex))
Beispiel #5
0
        def put(ctx, obj):
            if obj.id is None:
                ctx.udc.session.add(obj)
                ctx.udc.session.flush()

            else:
                if ctx.udc.session.query(T).get(obj.id) is None:
                    raise ResourceNotFoundError('%s.id=%d' % (T_name, obj.id))

                else:
                    ctx.udc.session.merge(obj)

            return obj.id
Beispiel #6
0
    def call_wrapper(self, ctx):
        try:
            return ctx.service_class.call_wrapper(ctx)

        except NoResultFound:
            raise ResourceNotFoundError(ctx.in_object)

        except Fault as e:
            logging.error(e)
            raise

        except Exception as e:
            logging.exception(e)
            raise InternalError(e)
Beispiel #7
0
    def get_user(ctx, userid):
        global user_database

        # If you rely on dict lookup raising KeyError here, you'll return an
        # internal error to the client, which tells the client that there's
        # something wrong in the server. However in this case, KeyError means
        # invalid request, so it's best to return a client error.

        # For the HttpRpc case, internal error is 500 whereas
        # ResourceNotFoundError is 404.
        if not (userid in user_database):
            raise ResourceNotFoundError(userid)

        return user_database[userid]
Beispiel #8
0
    def annotate_activity(self, activity_id, label):
        try:
            print(activity_id, label)
            activity = Activity.objects.get(pk=activity_id)

            if type(activity.is_violated) == bytes:
                activity.is_violated = bool.from_bytes(activity.is_violated,
                                                       "big")

            activity.is_normal = label
            activity.save()
            return activity
        except Exception as ex:
            raise ResourceNotFoundError('Activity %s not found' % activity_id)
Beispiel #9
0
    def put_user(ctx, user):
        if user.id is None:
            ctx.udc.session.add(user)
            ctx.udc.session.flush()  # so that we get the user.id value

        else:
            if ctx.udc.session.query(User).get(user.id) is None:
                # this is to prevent the client from setting the primary key
                # of a new object instead of the database's own primary-key
                # generator.
                # Instead of raising an exception, you can also choose to
                # ignore the primary key set by the client by silently doing
                # user.id = None
                raise ResourceNotFoundError('user.id=%d' % user.id)

            else:
                ctx.udc.session.merge(user)

        return user.id
Beispiel #10
0
        def put(ctx, obj):
            if obj.id is None:
                ctx.udc.session.add(obj)
                ctx.udc.session.flush()  # so that we get the obj.id value

            else:
                if ctx.udc.session.query(T).get(obj.id) is None:
                    # this is to prevent the client from setting the primary key
                    # of a new object instead of the database's own primary-key
                    # generator.
                    # Instead of raising an exception, you can also choose to
                    # ignore the primary key set by the client by silently doing
                    # obj.id = None in order to have the database assign the
                    # primary key the traditional way.
                    raise ResourceNotFoundError('%s.id=%d' % (T_name, obj.id))

                else:
                    ctx.udc.session.merge(obj)

            return obj.id
 def BookEvent(ctx, BookEventInput: BookEventRequest):
     book_event_url = ctx.udc.book_event_url
     auth_key = ctx.udc.token
     # Get section_list, user_id, and callback
     section_list = BookEventInput.section_list
     user_id = BookEventInput.user_id
     callback = BookEventInput.callback
     callback_type = BookEventInput.callback_type
     # Create payload and post to request
     payload = create_request(user_id, section_list, callback,
                              callback_type, auth_key)
     print(payload)
     camunda_resp = requests.post(book_event_url, json=payload)
     if camunda_resp.status_code == 404:
         raise ResourceNotFoundError(camunda_resp)
     elif not camunda_resp.ok:
         raise InternalError(Exception("Spyne Server Error"))
     json_response = camunda_resp.json()
     return BookEventResp(
         json_response["id"], 200,
         "Processing your input. Detail will be given to your callback URL")
Beispiel #12
0
 def CancelOrder(ctx, CancelOrderInput: CancelOrderRequest):
     cancel_order_url = ctx.udc.cancel_order_url
     auth_key = ctx.udc.token
     order_id = CancelOrderInput.order_id
     callback = CancelOrderInput.callback
     callback_type = CancelOrderInput.callback_type
     payment_method = PaymentInput.payment_method
     if (payment_method != 'ovo' and payment_method != 'go_pay'
             and payment_method != 'bank' and payment_method != 'bank_va'):
         raise ArgumentError("Payment method not available")
     # Create payload and request to create_event_url
     payload = create_request(order_id, payment_method, callback,
                              callback_type, auth_key)
     camunda_resp = requests.post(cancel_order_url, json=payload)
     print(camunda_resp.json())
     if camunda_resp.status_code == 404:
         raise ResourceNotFoundError(camunda_resp)
     elif not camunda_resp.ok:
         raise InternalError(Exception("Spyne Server Error"))
     return CancelOrderResp(
         200,
         "Processing your input. Detail will be given to your callback URL")
Beispiel #13
0
        def del_(ctx, obj_id):
            count = ctx.udc.session.query(T).filter_by(id=obj_id).count()
            if count == 0:
                raise ResourceNotFoundError(obj_id)

            ctx.udc.session.query(T).filter_by(id=obj_id).delete()
Beispiel #14
0
    def del_user(ctx, user_id):
        count = ctx.udc.session.query(User).filter_by(id=user_id).count()
        if count == 0:
            raise ResourceNotFoundError(user_id)

        ctx.udc.session.query(User).filter_by(id=user_id).delete()
Beispiel #15
0
 def put_not_found(obj):
     raise ResourceNotFoundError('%s.id=%d' % (T_name, obj.id))
Beispiel #16
0
 def get_container(ctx, pk):
     # return "kont1"
     try:
         return IllnessItem.objects.get(pk=pk)
     except IllnessItem.DoesNotExist:
         raise ResourceNotFoundError('IllnessItem')