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

            new_object = create_instance(HVAC, json_struct)
            if isinstance(new_object, BadRequestError):
                return new_object
            elif isinstance(new_object, NotFoundError):
                return new_object
            else:
                try:
                    HvacImpl.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:
                    HvacImpl.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))
Example #2
0
 def delete(self, ):
     print "Delete operation of resource: HVAC"
     try:
         response=HvacImpl.delete()
     except KeyError as inst:
         return NotFoundError(inst.args[0] + " not found")
     else:
         return Successful('Successful operation')
Example #3
0
 def get(self, ):
     print "Retrieve operation of resource: HVAC"
     try:
         response = HvacImpl.get()
     except KeyError as inst:
         return NotFoundError(inst.args[0] + " not found")
     else:
         js = response.json_serializer()
         return Successful("Successful operation",json_dumps(js))
Example #4
0
    def post(self, ):
        print "Create operation of resource: HVAC"
        try:
            response = HvacImpl.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(HVAC, json_struct)
            if isinstance(new_object, BadRequestError):
                return new_object
            elif isinstance(new_object, NotFoundError):
                return new_object
            else:
                try:
                    HvacImpl.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))