Skip to main content
Version: ADONIS 12/ADOIT 13/ADOGRC 11

Create a new artifact

This article shows how to use the ADOXX API to create new objects.

The snippet below will create a new ArchiMate artifact object in the repository.

note

The 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 CreateArtifact
{
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 sPath = "http://<HOST>:<PORT>/ADOIT/rest/2.0/repos/" + sRepoID + "/objects";

final HttpPost aMethod = new HttpPost (sPath);

final StringBuilder aCreationParams = new StringBuilder ();
aCreationParams.append ("{");
aCreationParams.append ("\"name\":\"MyArtifact\",");
// Replace C_CLASSNAME with the name of your class
aCreationParams.append ("\"metaName\":\"C_ARTIFACT\",");
aCreationParams.append ("\"attributes\":");
aCreationParams.append ("[");
aCreationParams.append ("{");
// Replace A_STRING_ATTR with the name of your attribute
aCreationParams.append ("\"metaName\":\"A_DESCRIPTION\",");
aCreationParams.append ("\"value\":\"This is my artifact created via the API\"");
aCreationParams.append ("}");
aCreationParams.append ("]");
aCreationParams.append ("}");

final StringEntity aJSON = new StringEntity (aCreationParams.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: 201
Result:
{
"locale": "en",
"item": {
"rest_links": [ ... ],
"id": " ... ",
"name": "MyArtifact",
"type": "Artifact",
"artefactType": " ... ",
"metaName": "C_ARTIFACT",
"link": { ... },
"icon": { ... },
"attributes": [ ... ],
"relations": [ ... ]
}
}