|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object atg.rest.client.RestRepositoryHelper
public class RestRepositoryHelper
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 |
---|
public static java.lang.String CLASS_VERSION
Constructor Detail |
---|
public RestRepositoryHelper()
Method Detail |
---|
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
pRepositoryPath
- the path of the desired repositorypItemDescriptorName
- the name of the item descriptorpItemId
- the item idpParams
- a map of parameters to include in the request or null if no parameters are neededpSession
- the session object representing the current session
RestClientException
- if an error occurs issuing the requestpublic 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
pRepositoryPath
- the path of the desired repositorypItemDescriptorName
- the name of the item descriptorpParams
- a map of parameters to include in the request or null if no parameters are neededpSession
- the session object representing the current session
RestClientException
- if an error occurs issuing the requestpublic 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
pRepositoryPath
- the path of the desired repositorypItemDescriptorName
- the name of the item descriptorpRQL
- the RQL query stringpParams
- a map of parameters to include in the request or null if no parameters are neededpSession
- the session object representing the current session
RestClientException
- if an error occurs issuing the requestpublic 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
pRepositoryPath
- the path of the desired repositorypItemDescriptorName
- the name of the item descriptorpItemId
- the item idpProperty
- 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 neededpSession
- the session object representing the current session
RestClientException
- if an error occurs issuing the requestpublic 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
pRepositoryPath
- the path of the desired repositorypItemDescriptorName
- the name of the item descriptorpItemId
- the item idpProperty
- the name of the desired property or sub-property to get formatted as follows: "property/sub-property/sub-property"pValue
- the value to setpParams
- a map of parameters to include in the request or null if no parameters are neededpSession
- the session object representing the current session
RestClientException
- if an error occurs issuing the requestpublic 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
pRepositoryPath
- the path of the desired repositorypItemDescriptorName
- the name of the item descriptorpParams
- a map of parameters to include in the request or null if no parameters are neededpSession
- the session object representing the current session
RestClientException
- if an error occurs issuing the requestpublic 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
pRepositoryPath
- the path of the desired repositorypItemDescriptorName
- the name of the item descriptorpItemId
- an optional parameter to specify the id to use when creating the itempParams
- a map of parameters to include in the request or null if no parameters are neededpSession
- the session object representing the current session
RestClientException
- if an error occurs issuing the requestpublic 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
pRepositoryPath
- the path of the desired repositorypItemDescriptorName
- the name of the item descriptorpItemId
- the item idpParams
- a map of parameters to include in the request or null if no parameters are neededpSession
- the session object representing the current session
RestClientException
- if an error occurs issuing the request
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |