Пример #1
0
    def put(self, ):
        print "Update operation of resource: Heat"
        json_struct = request.get_json() #json parser.
        try:
            existing_object = HvacHeatImpl.get()
        except KeyError as inst:
            if inst.args[0] != '':
                return NotFoundError(inst.args[0] + " not found")

            new_object = create_instance(Heat, json_struct)
            if isinstance(new_object, BadRequestError):
                return new_object
            elif isinstance(new_object, NotFoundError):
                return new_object
            else:
                try:
                    HvacHeatImpl.put(new_object)
                    js=new_object.json_serializer()
                except KeyError as inst:
                    return NotFoundError(inst.args[0] + " not found")
        else:
            existing_object = modify_instance(existing_object, json_struct)
            if isinstance(existing_object, BadRequestError):
                return existing_object
            elif isinstance(existing_object, NotFoundError):
                return existing_object
            else:
                try:
                    HvacHeatImpl.put(existing_object)
                    js=existing_object.json_serializer()
                except KeyError as inst:
                    return NotFoundError(inst.args[0] + " not found")

        return Successful("Successful operation",json_dumps(js))
Пример #2
0
 def delete(self, ):
     print "Delete operation of resource: Heat"
     try:
         response=HvacHeatImpl.delete()
     except KeyError as inst:
         return NotFoundError(inst.args[0] + " not found")
     else:
         return Successful('Successful operation')
Пример #3
0
 def get(self, ):
     print "Retrieve operation of resource: Heat"
     try:
         response = HvacHeatImpl.get()
     except KeyError as inst:
         return NotFoundError(inst.args[0] + " not found")
     else:
         js = response.json_serializer()
         return Successful("Successful operation",json_dumps(js))
Пример #4
0
    def post(self, ):
        print "Create operation of resource: Heat"
        try:
            response = HvacHeatImpl.get()
        except KeyError as inst:
            if inst.args[0] != '':
                return NotFoundError(inst.args[0] + " not found")

            json_struct = request.get_json() #json parser.
            new_object = create_instance(Heat, json_struct)
            if isinstance(new_object, BadRequestError):
                return new_object
            elif isinstance(new_object, NotFoundError):
                return new_object
            else:
                try:
                    HvacHeatImpl.post(new_object)
                    js=new_object.json_serializer()
                except KeyError as inst:
                    return NotFoundError(inst.args[0] + " not found")
        else:
            return BadRequestError("Object already exists. For updates use PUT.")
        return Successful("Successful operation",json_dumps(js))