Creating Assets with Java SDK
When you create a new asset with the JavaSDK, you need to specify the context of another asset that will be the parent. For example, if you create a new Story asset you can specify which Scope (project) it should be created in.
Prior to creating an asset in Digital.ai Agility, you must first instantiate a V1Connector and Services object:
V1Connector connector = V1Connector
.withInstanceUrl("<Server Base URI>")
.withUserAgentHeader("AppName", "1.0")
.withAccessToken("1.rWM8lKLk+PnyFxkEWVX5Kl2u6Jk=")
.build();
IServices services = new Services(connector);
Creating a New Asset
This example shows how to create a Story asset in the context of a Scope with ID 1012:
Oid projectId = services.getOid("Scope:0");
IAssetType storyType = services.getMeta().getAssetType("Story");
Asset newStory = services.createNew(storyType, projectId);
IAttributeDefinition nameAttribute = storyType.getAttributeDefinition("Name");
newStory.setAttributeValue(nameAttribute, "My New Story");
services.save(newStory);
System.out.println(newStory.getOid().getToken());
System.out.println(newStory.getAttribute(storyType.getAttributeDefinition("Scope")).getValue());
System.out.println(newStory.getAttribute(nameAttribute).getValue());
/***** OUTPUT *****
Story:7617:9243
Scope:0
My New Story
******************/