The Legacy REST Web Services RestRepositoryHelper class exposes methods that perform basic Repository operations.

Getting Repository Items with the Java Client Library

The getItem() method of the RestRepositoryHelper class returns a data stream that contains all the property values of a repository item.

The following code sample returns an array of URLs. Issuing a request using the RestSession.createHttpRequest() method returns the property values of the requested item.

RestResult result = RestRepositoryHelper.getItem("/atg/commerce/catalog/
ProductCatalog", "product", productId, params, session)

The getItems() method retrieves multiple repository items of the same type in a single call. The following code sample returns an array of URLs:

RestResult result = RestRepositoryHelper.getItems("/atg/commerce/catalog/
ProductCatalog", "product", params, session)

When a getItems() call returns many items, you can control the number of items returned with the atg-rest-index and atg-rest-count parameters. The atg-rest-index parameter tells the server which item to return first. The atg-rest-count parameter tells the server how many items past the index item to return.

In the following code sample, the first query, with an index of 0 and a count of 10, retrieves 10 items at a time. The next query has an index of 10 and a count of 10, third, index of 20 and count of 10, and so on.

Map<String,String> params = new HashMap<String,String>();
params.put(RestConstants.COUNT, 10);
params.put(RestConstants.INDEX, 0);
RestResult result = RestRepositoryHelper.getItems("/atg/commerce/catalog/
ProductCatalog", "product", params, session);

params.put(RestConstants.INDEX, 10);

result = RestRepositoryHelper.getItems("/atg/commerce/catalog/ProductCatalog",
"product", params, session);

params.put(RestConstants.INDEX, 20);

result = RestRepositoryHelper.getItems("/atg/commerce/catalog/ProductCatalog",
"product", params, session);
Repository IDs

Each repository item has a unique identifier, called a repository ID. Depending on the repository’s configuration, the repository ID might not be exposed as a property of the repository item. However, when a repository item is returned with a REST RepositoryHelper method, you can reliably retrieve its repositoryID by getting the value of the repositoryId property.

Adding Repository Items

Create a repository item by calling the RestRepositoryHelper.createItem() method. You can supply a repository ID for the newly created item or you can allow the server to generate a repository ID for you.

A createItem() call returns a data stream that contains all the properties of the created item. This is the same data stream that is returned when you call RestRepositoryHelper.getItem().

The following code sample adds a repository item and allows the server to generate the repository ID:

RestResult result = RestRepositoryHelper.createItem("/atg/commerce/catalog/
ProductCatalog", "product", params, session);

The following code sample adds a repository item and specifies the value of myProductId-12345 as the repository ID:

RestResult result = RestRepositoryHelper.createItem("/atg/commerce/catalog/
ProductCatalog", "product", "myProductId-12345", params, session);
Deleting Repository Items

Remove a repository item by calling the RestRepositoryHelper.removeItem() method. A removeItem() call returns a data stream that contains the string true if the item was removed. If the item was not removed, the call throws an exception.

The following sample removes a repository item:

RestResult result = RestRepositoryHelper.removeItem("/atg/commerce/catalog/
ProductCatalog", "product", "myProductId-12345", params, session);
Getting Repository Item Properties with the Java Client

The getPropertyValue() method of the RestRepositoryHelper class returns a data stream that contains the value of the specified property.

The following sample gets the property value displayName from the product repository item.

RestResult result = RestRepositoryHelper.getPropertyValue("/atg/commerce/catalog/
ProductCatalog", "product", "prod12345", "displayName", params, session);
Setting Repository Item Properties with the Java Client

The setPropertyValue() method of the RestRepositoryHelper class sets the value of the specified property.

The following sample sets the property displayName to the string My Modified Display Name.

RestResult result = RestRepositoryHelper.setPropertyValue("/atg/commerce/catalog/
ProductCatalog", "product", "prod12345", "displayName",
"My Modified Display Name", params, session);
Performing Queries for Repository Items

Performing queries for repository items using RQL is similar to retrieving them with getItems(), but querying provides for more control over the items included in the results. Use the RestRepositoryHelper.executeRQLQuery() method to execute and RQL query.

To request a range of items, use the atg-rest-index and atg-rest-count parameters with the executeRQLQuery() method, just as you’d use them with getItems(). See Retrieving a Repository Item in Legacy REST for more information.

In the following example, the INDEX and COUNT keywords in the RQL language are used instead of the “atg-rest-index” and “atg-rest-count” parameters.

Map<String,String> params = new HashMap<String,String>();
params.put(RestConstants.COUNT, 10);
params.put(RestConstants.INDEX, 0);
RestResult result = RestRepositoryHelper.executeRQLQuery("/atg/commerce/catalog/
ProductCatalog", "product", "age >= 30", params, session);
params.put(RestConstants.INDEX, 10);
result = RestRepositoryHelper.executeRQLQuery("/atg/commerce/catalog/
ProductCatalog", "product", "age >= 30", params, session);
params.put(RestConstants.INDEX, 20);
result = RestRepositoryHelper.executeRQLQuery("/atg/commerce/catalog/
ProductCatalog", "product", "age >= 30", params, session);

Copyright © 1997, 2015 Oracle and/or its affiliates. All rights reserved. Legal Notices