Skip to main content
Version: ADONIS 15/ADOIT 16/ADOGRC 12

Update a risk's data

This article shows how to use the ADOXX API to update data in an existing object.

The Java snippet below will change the frequency of the risk assessment in a risk whose ID we already know (e.g. retrieved via a search query).

note

The Java snippet below uses Basic Authentication.

Replace the values in angle brackets with values that fit your setup, e.g. instead of <HOST> use the host at which you access your ADOXX instance.

Click to view the code!

Source Code

public class UpdateRisk
{
public static void main (final String [] args) throws ClientProtocolException, IOException
{
final CloseableHttpClient aClient = HttpClients.createDefault ();

final String sUser = "<USER>";
final String sPass = "<PASSWORD>";
final String sRepoID = "<REPO_ID>";
final String sRiskID = "<RISK_ID>";
final String sPath = "http://<HOST>:<PORT>/ADOGRC/rest/2.0/repos/" +
sRepoID +
"/objects/" +
sRiskID;

final HttpPatch aMethod = new HttpPatch (sPath);

final StringBuilder aUpdateParams = new StringBuilder ();
aUpdateParams.append ("{");
aUpdateParams.append ("\"attributes\":");
aUpdateParams.append ("[");
aUpdateParams.append ("{");
// Replace A_STRING_ATTR with the name of your attribute
aUpdateParams.append ("\"metaName\":\"A_ARTIFACT_SPEC\",");
aUpdateParams.append ("\"value\":\"v1\"");
aUpdateParams.append ("}");
aUpdateParams.append ("]");
aUpdateParams.append ("}");

final StringEntity aJSON = new StringEntity (aUpdateParams.toString (),
ContentType.APPLICATION_JSON);
aMethod.setEntity (aJSON);

// The headers controlling the return type and the language do not have to be considered for
// token generation
aMethod.addHeader ("Accept", "application/json");
aMethod.addHeader ("Accept-Language", "en");

// Construction of the header to pass the basic authentication information
aMethod.addHeader ("Authorization",
"Basic " +
DatatypeConverter.printBase64Binary ((sUser + ":" + sPass).getBytes ()));

final CloseableHttpResponse aResponse = aClient.execute (aMethod);

try
{
final String sResult = EntityUtils.toString (aResponse.getEntity (), "UTF-8");
final StatusLine aStatusLine = aResponse.getStatusLine ();
System.out.println ("Status Code: " + aStatusLine.getStatusCode ());
System.out.println ("Result: \n" + sResult);
}
catch (final Exception aEx)
{
aEx.printStackTrace ();
}
finally
{
aResponse.close ();
}
}
}

The result should look similar to the following:

Status Code: 200
Result:
{
"locale": "en",
"item": {
"rest_links": [ ... ],
"id": " ... ",
"name": " ... ",
"type": " ... ",
"artefactType": " ... ",
"metaName": " ... ",
"link": { ... },
"icon": { ... },
"attributes": [ ... ],
"relations": [ ... ]
}
}