---
id: executing-operations-java-sdk
slug: /sdk/java/executing-operations-java-sdk
title: 'Executing Operations using Java SDK'
description: 'This topic explains how to execute operations against assets in Agility'
sidebar_label: 'Executing Operations'
sidebar_position: 9
tags: ['meta-api', 'v1connector', 'services']
---

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("YOUR_ACCESS_TOKEN")
            .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 the**MetaModel**object. However, starting with the 15.0.0.0 release, that is no longer necessary. The**MetaModel**object is now available from the**getMeta**method of the**Services**object. For more advanced**Services**constructor 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 **Services**object. Note the use of the **getOperation**method 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 **Services**object:

```
                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 **Services**object:

```
                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.
