atg.rest.client
Class RestRepositoryHelper

java.lang.Object
  extended by atg.rest.client.RestRepositoryHelper

public class RestRepositoryHelper
extends java.lang.Object

A client side helper class which provides useful methods for making calls into the ATG platform using Rest. By default, all methods will return their results in the format that is configured as the default on the server. To override the default, add the atg-rest-output parameter to the pParams argument of the appropriate method with a suitable value, "xml", "json", or the identifier for an appropriate output customizer. To begin a session, first call the login() method. Below is a sample application which demonstrates the basic use of this client library. import atg.rest.client.RestClientException; import atg.rest.client.RestComponentHelper; import atg.rest.client.RestResult; import atg.rest.client.RestSession; import java.io.IOException; public class RestClientSample { private String mUsername = null; private String mPassword = null; private String mHost = "localhost"; private int mPort = 80; private RestSession mSession = null; public RestClientSample() {} protected void parseArguments(String[] pArgs) throws Exception { for (int i = 0; i < pArgs.length; i++) { String arg = pArgs[i]; if (arg.equals("-user")) mUsername = pArgs[i+1]; else if (arg.equals("-password")) mPassword = pArgs[i+1]; else if (arg.equals("-host")) mHost = pArgs[i+1]; else if (arg.equals("-port")) mPort = Integer.parseInt(pArgs[i+1]); } if (isBlank(mUsername)) throw new Exception("Must supply username"); if (isBlank(mPassword)) throw new Exception("Must supply password"); } protected boolean isBlank(String pStr) { return (pStr == null || pStr.length() == 0 || pStr.trim().length() == 0); } protected void println(String s) { System.out.println(s); } protected void println(Throwable t) { t.printStackTrace(System.out); } protected void execute() throws RestClientException { mSession = RestSession.createSession(mHost, mPort, mUsername, mPassword); mSession.setUseHttpsForLogin(false); try { mSession.login(); println("Login Successful"); // add REST requests here } catch (Throwable t) { println(t); } finally { try { mSession.logout(); println("Logout Successful"); } catch (RestClientException e) { println(e); } } } public static void main(String[] args) { RestClientSample sample = new RestClientSample(); try { sample.parseArguments(args); sample.execute(); } catch (Throwable t) { sample.println(t); } } }


Field Summary
static java.lang.String CLASS_VERSION
          Class version string
 
Constructor Summary
RestRepositoryHelper()
           
 
Method Summary
static RestResult createItem(java.lang.String pRepositoryPath, java.lang.String pItemDescriptorName, java.util.Map<java.lang.String,java.lang.Object> pParams, RestSession pSession)
          Creates a repository item.
static RestResult createItem(java.lang.String pRepositoryPath, java.lang.String pItemDescriptorName, java.lang.String pItemId, java.util.Map<java.lang.String,java.lang.Object> pParams, RestSession pSession)
          Creates a repository item with the specified id.
static RestResult executeRQLQuery(java.lang.String pRepositoryPath, java.lang.String pItemDescriptorName, java.lang.String pRQL, java.util.Map<java.lang.String,java.lang.Object> pParams, RestSession pSession)
          Returns references to all the items of the given type that satisfy the RQL query.
static RestResult getItem(java.lang.String pRepositoryPath, java.lang.String pItemDescriptorName, java.lang.String pItemId, java.util.Map<java.lang.String,java.lang.Object> pParams, RestSession pSession)
          Returns a representation of the given repository item.
static RestResult getItems(java.lang.String pRepositoryPath, java.lang.String pItemDescriptorName, java.util.Map<java.lang.String,java.lang.Object> pParams, RestSession pSession)
          Returns references to all the items of the given type.
static RestResult getPropertyValue(java.lang.String pRepositoryPath, java.lang.String pItemDescriptorName, java.lang.String pItemId, java.lang.String pProperty, java.util.Map<java.lang.String,java.lang.Object> pParams, RestSession pSession)
          Gets the specified property or sub-property for the desired repository item.
static RestResult removeItem(java.lang.String pRepositoryPath, java.lang.String pItemDescriptorName, java.lang.String pItemId, java.util.Map<java.lang.String,java.lang.Object> pParams, RestSession pSession)
          Removes the specified repository item
static RestResult setPropertyValue(java.lang.String pRepositoryPath, java.lang.String pItemDescriptorName, java.lang.String pItemId, java.lang.String pProperty, java.lang.Object pValue, java.util.Map<java.lang.String,java.lang.Object> pParams, RestSession pSession)
          Sets the specified value on the given property or sub-property for the desired repository item
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CLASS_VERSION

public static java.lang.String CLASS_VERSION
Class version string

Constructor Detail

RestRepositoryHelper

public RestRepositoryHelper()
Method Detail

getItem

public static RestResult getItem(java.lang.String pRepositoryPath,
                                 java.lang.String pItemDescriptorName,
                                 java.lang.String pItemId,
                                 java.util.Map<java.lang.String,java.lang.Object> pParams,
                                 RestSession pSession)
                          throws RestClientException
Returns a representation of the given repository item.

Parameters:
pRepositoryPath - the path of the desired repository
pItemDescriptorName - the name of the item descriptor
pItemId - the item id
pParams - a map of parameters to include in the request or null if no parameters are needed
pSession - the session object representing the current session
Returns:
the result of the request
Throws:
RestClientException - if an error occurs issuing the request

getItems

public static RestResult getItems(java.lang.String pRepositoryPath,
                                  java.lang.String pItemDescriptorName,
                                  java.util.Map<java.lang.String,java.lang.Object> pParams,
                                  RestSession pSession)
                           throws RestClientException
Returns references to all the items of the given type. To request a range of items, include the atg-rest-index (RestConstants.INDEX) and atg-rest-count (RestConstants.COUNT) parameters in the pParams property with appropriate values.

Parameters:
pRepositoryPath - the path of the desired repository
pItemDescriptorName - the name of the item descriptor
pParams - a map of parameters to include in the request or null if no parameters are needed
pSession - the session object representing the current session
Returns:
the result of the request
Throws:
RestClientException - if an error occurs issuing the request

executeRQLQuery

public static RestResult executeRQLQuery(java.lang.String pRepositoryPath,
                                         java.lang.String pItemDescriptorName,
                                         java.lang.String pRQL,
                                         java.util.Map<java.lang.String,java.lang.Object> pParams,
                                         RestSession pSession)
                                  throws RestClientException
Returns references to all the items of the given type that satisfy the RQL query. To request a range of items, include the atg-rest-index and atg-rest-count parameters in the pParams property with appropriate values.

Parameters:
pRepositoryPath - the path of the desired repository
pItemDescriptorName - the name of the item descriptor
pRQL - the RQL query string
pParams - a map of parameters to include in the request or null if no parameters are needed
pSession - the session object representing the current session
Returns:
the result of the request
Throws:
RestClientException - if an error occurs issuing the request

getPropertyValue

public static RestResult getPropertyValue(java.lang.String pRepositoryPath,
                                          java.lang.String pItemDescriptorName,
                                          java.lang.String pItemId,
                                          java.lang.String pProperty,
                                          java.util.Map<java.lang.String,java.lang.Object> pParams,
                                          RestSession pSession)
                                   throws RestClientException
Gets the specified property or sub-property for the desired repository item.

Parameters:
pRepositoryPath - the path of the desired repository
pItemDescriptorName - the name of the item descriptor
pItemId - the item id
pProperty - the name of the desired property or sub-property to get formatted as follows: "property/sub-property/sub-property"
pParams - a map of parameters to include in the request or null if no parameters are needed
pSession - the session object representing the current session
Returns:
the result of the request
Throws:
RestClientException - if an error occurs issuing the request

setPropertyValue

public static RestResult setPropertyValue(java.lang.String pRepositoryPath,
                                          java.lang.String pItemDescriptorName,
                                          java.lang.String pItemId,
                                          java.lang.String pProperty,
                                          java.lang.Object pValue,
                                          java.util.Map<java.lang.String,java.lang.Object> pParams,
                                          RestSession pSession)
                                   throws RestClientException
Sets the specified value on the given property or sub-property for the desired repository item

Parameters:
pRepositoryPath - the path of the desired repository
pItemDescriptorName - the name of the item descriptor
pItemId - the item id
pProperty - the name of the desired property or sub-property to get formatted as follows: "property/sub-property/sub-property"
pValue - the value to set
pParams - a map of parameters to include in the request or null if no parameters are needed
pSession - the session object representing the current session
Returns:
the result of the request
Throws:
RestClientException - if an error occurs issuing the request

createItem

public static RestResult createItem(java.lang.String pRepositoryPath,
                                    java.lang.String pItemDescriptorName,
                                    java.util.Map<java.lang.String,java.lang.Object> pParams,
                                    RestSession pSession)
                             throws RestClientException
Creates a repository item. To create a transient item, include the atg-rest-transient (RestConstants.TRANSIENT) parameter with a value of true in pParams.

Parameters:
pRepositoryPath - the path of the desired repository
pItemDescriptorName - the name of the item descriptor
pParams - a map of parameters to include in the request or null if no parameters are needed
pSession - the session object representing the current session
Returns:
the result of the request
Throws:
RestClientException - if an error occurs issuing the request

createItem

public static RestResult createItem(java.lang.String pRepositoryPath,
                                    java.lang.String pItemDescriptorName,
                                    java.lang.String pItemId,
                                    java.util.Map<java.lang.String,java.lang.Object> pParams,
                                    RestSession pSession)
                             throws RestClientException
Creates a repository item with the specified id. To create a transient item, include the atg-rest-transient (RestConstants.TRANSIENT) parameter with a value of true in pParams.

Parameters:
pRepositoryPath - the path of the desired repository
pItemDescriptorName - the name of the item descriptor
pItemId - an optional parameter to specify the id to use when creating the item
pParams - a map of parameters to include in the request or null if no parameters are needed
pSession - the session object representing the current session
Returns:
the result of the request
Throws:
RestClientException - if an error occurs issuing the request

removeItem

public static RestResult removeItem(java.lang.String pRepositoryPath,
                                    java.lang.String pItemDescriptorName,
                                    java.lang.String pItemId,
                                    java.util.Map<java.lang.String,java.lang.Object> pParams,
                                    RestSession pSession)
                             throws RestClientException
Removes the specified repository item

Parameters:
pRepositoryPath - the path of the desired repository
pItemDescriptorName - the name of the item descriptor
pItemId - the item id
pParams - a map of parameters to include in the request or null if no parameters are needed
pSession - the session object representing the current session
Returns:
the result of the request
Throws:
RestClientException - if an error occurs issuing the request