Skip to main content
Version: 24.3

Executing Operations

An operation is an action that is executed against a single asset. For example, to delete an asset you must execute the Delete operation on the asset. To close or inactivate a asset, you use the Inactivate operation.

You can use the Meta API to determine the operations that a particular asset supports

Prior to executing an operation against 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);

In versions of the SDK prior to the 15.0.0.0 release, you would also have to instantiate a connector for theMetaModelobject. However, starting with the 15.0.0.0 release, that is no longer necessary. TheMetaModelobject is now available from thegetMetamethod of theServicesobject. For more advancedServicesconstructor overloads, see the Creating a Services Object topic.

Closing an Asset

This example shows how to close an asset using the executeOperation method of the Servicesobject. Note the use of the getOperationmethod to get the operation to execute:

                IOperation closeOperation  = services.getMeta().getOperation("Story.Inactivate");
Oid closeID = services.executeOperation(closeOperation, services.getOid("Story:7618"));

Query query = new Query(closeID.getMomentless());
IAttributeDefinition assetState = services.getMeta().getAttributeDefinition("Story.AssetState");
query.getSelection().add(assetState);
QueryResult result = services.retrieve(query);
Asset closeStory = result.getAssets()[0];
AssetState state = AssetState.valueOf(((Integer) closeStory.getAttribute(assetState).getValue()).intValue());

System.out.println(closeStory.getOid());
System.out.println(state.toString());

/***** OUTPUT *****
Story:7618
Closed
******************/

Reopening an Asset

This example shows how to reopen an asset using the executeOperation method of the Servicesobject:

                IOperation closeOperation  = services.getMeta().getOperation("Story.Reactivate");
Oid closeID = services.executeOperation(closeOperation, services.getOid("Story:7618"));

Query query = new Query(closeID.getMomentless());
IAttributeDefinition assetState = services.getMeta().getAttributeDefinition("Story.AssetState");
query.getSelection().add(assetState);
QueryResult result = services.retrieve(query);
Asset closeStory = result.getAssets()[0];
AssetState state = AssetState.valueOf(((Integer) closeStory.getAttribute(assetState).getValue()).intValue());

System.out.println(closeStory.getOid());
System.out.println(state.toString());

/***** OUTPUT *****
Story:7618
Active
******************/

Deleting an Asset

This example shows how to delete an asset using the executeOperation method of the Servicesobject:

                IOperation deleteOperation = services.getMeta().getOperation("Story.Delete");
Oid deletedOID = services.executeOperation(deleteOperation, services.getOid("Story:7618"));

try {
Query query = new Query(deletedOID.getMomentless());
@SuppressWarnings("unused")
QueryResult result = services.retrieve(query);
} catch (ConnectionException e) {
System.out.println(String.format("%s has been deleted", deletedOID.getMomentless()));
}

/***** OUTPUT *****
Story:7618 has been deleted
******************/

The Delete operation returns the Oid, with the new Moment, of the deleted asset. Future current info queries will automatically exclude deleted assets from results.