Exemplo n.º 1
0
    def _create_entity(self, entityInstance):
        print "Create Entity"
        statusCode = httplib.OK

        # check maybe to delete:
        if (self._delete_entity(entityInstance)):
            print "error"

        entity = Entity()
        entity.convertObjectToEntity(entityInstance)

        jsonString = JsonConvert.ToJSON(entity)
        print jsonString

        response = requests.post(self._fiwareAddress + "/v2/entities",
                                 data=jsonString,
                                 headers=HEADERS)
        statusCode = response.status_code
        if (isResponseOk(statusCode)):  # everything is fine
            self._published_entities.append(entityInstance)
            print "Status OK"
        elif (statusCode == httplib.BAD_REQUEST):  # everything is NOT fine
            print "httplib.UNPROCESSABLE_ENTITY"
            content = json.loads(response.content)
            print content
        else:
            print statusCode
            print response
Exemplo n.º 2
0
    def delete_entity(self, entityInstance):
        print "Delete Entity - Id: " + str(entityInstance)
        entity = Entity()
        entity.convertObjectToEntity(entityInstance)
        response = requests.delete(self.fiwareAddress + "/v2/entities/" +
                                   str(entity.id))
        statusCode = response.status_code

        if (isResponseOk(statusCode)):  # everything is fine
            print "Status OK"
            return 0
        else:
            content = json.loads(response.content)
            print content
            return statusCode
Exemplo n.º 3
0
 def _update_entity(self, entityInstance):
     print "Update Entity"
     entity = Entity()
     entity.convertObjectToEntity(entityInstance)
     jsonString = JsonConvert.ToJSON(entity)
     jsonString = ContextBrokerHandler._remove_id_and_type(jsonString)
     print jsonString
     response = requests.patch(self._fiwareAddress + "/v2/entities/" +
                               str(entity.id) + "/attrs",
                               data=jsonString,
                               headers=HEADERS)
     statusCode = response.status_code
     if isResponseOk(statusCode):  # everything is fine
         entityInstance.clear_dirty()
         print "Status OK"
     elif statusCode == httplib.BAD_REQUEST:  # everything is NOT fine
         print "httplib.UNPROCESSABLE_ENTITY"
         print statusCode
         print response
         print json.loads(response.content)
     else:
         print statusCode
         print response
         print json.loads(response.content)