Updating entity data

Update the data in an entity by sending a REST API PUT request to the server.

About this task

The PUT request method instructs the server to accept and store the data that is enclosed in the body of the request message. Send a PUT request to the Insight Server to update fields or data in an entity or set of entities. You can send the PUT request by using a script, such as Jython, or from a REST client tool that works with your browser.

Procedure

  1. Make sure you can access the Insight Server by entering the generic REST URL in the browser address field. See Managing entities for an example of the REST URL.
  2. Create the PUT request by using the syntax that is shown in the example.

    Depending on the value of the httpEndpoint setting in the server.xml file on your system, the first part of the request URL is http://hostname:9080 for httpPort connections, or https://hostname:9443 for httpsPort connections.

    .../solutions/solution_name/entity-types/entity_type/entities/entity_id
    where solution_name is the symbolic solution name, for example BankingSolution, and entity_type is a category of entity such as person or customer. The value entity-id must match the ID of an existing entity.
  3. Optional: Add the ETag header to the PUT request to avoid overwriting any modifications to the entity that resulted from event processing. The If-Match ETag header enables optimistic updating of entities. See Updating and retrieving entities by using ETag.

Results

The response to the REST PUT request includes the contents of the previous entity version and the status code 200 OK indicating that the entity is updated. If the entity update is not successful, the status code 400 Bad Request, 404 Not Found, or 412 Precondition Failed appears in the response. The entity update might fail for the following reasons:
  • The entity ID provided in the request does not match the ID of an existing entity (status code 400®).
  • The entity that you tried to update does not exist (status code 404).
  • The ETag header If-Match was included in the request to enable optimistic updating, and the ETag version information did not match. In this situation, ETag prevents entity updating to avoid overwriting changes to the entity that came from event processing (status code 412).

Example

The following example shows how to update the attributes of the Recipient entity by using the test driver API.
public void doPUTUsingTestDriver() throws Exception{

//Create a new instance of TestDriver.
TestDriver driver = new TestDriver();

//Create a SolutionGateway connection to the grid for the passed solution.
driver.connect("hello_world");

/* Create an entity using the generated Java Model.
* In this example a recipient entity is created.
*/
Recipient rep1 = driver.getConceptFactory(ConceptFactory.class).createRecipient("REP001");

//Populate the entity with some attributes.
rep1.setHelloCount(5);

//Use TestDriver to update the entity on the server.
driver.loadEntity(rep1);
}