Get List of Schema (Form)
From ARSWiki
Using AR Remedy java API is simple, but finding how to do it isn't. All I done to learn Java API is come from looking into Remedy Java Driver program, tirelessly read Java DOC API, and a little head bashing to the wall. Ok enough with complaining, now to the code.
First, create instance of Proxy object, since with this object we can access many of the function we need. Then connect to ARS server using ARServer object.
//Connect to server
Proxy arsProxy = new Proxy();
ARServerUser arsUser = new ARServerUser("Demo", "", "", "arsserver");
- NOTE: The Proxy object is not generally needed for most ARS Java API operations. Maybe it should be left out of the "basic" examples?
The method signature for the ARServerUser object constructors are
- v6.3
- ARServerUser()
- ARServerUser(java.lang.String user, java.lang.String password, java.lang.String locale, java.lang.String server)
- ARServerUser(java.lang.String user, java.lang.String password, java.lang.String locale, java.lang.String serverName, int serverPort)
- ARServerUser(java.lang.String user, java.lang.String password, java.lang.String locale, java.lang.String server, long cacheId)
- ARServerUser(java.lang.String user, java.lang.String password, java.lang.String authentication, java.lang.String locale, java.lang.String server, long cacheId)
- ARServerUser(java.lang.String user, java.lang.String password, java.lang.String authentication, java.lang.String locale, java.lang.String timeZone, java.lang.String customDateFormat, java.lang.String customTimeFormat, java.lang.String server, long cacheId)
If your connection to your ARS server needs to be on a specific TCP port, then you can set an environment variable ARTCPPORT, use the ARServerUser.setPort() method, or use the Util.ARSetServerPort() method to control that attribute of your connection with the ARS server(s).
After you have configured your connection to the ARS server of interest. You next need to define criteria for specific form/schema to retrieve. For this purpose, use SchemaListCriteria object to define which form(s) you want. Form is one of ARS object, which is in Java API, all objects in ARS are representing by NameID object. Since we want to grab all forms, we will set it to null. To retrieve form use Proxy.ARGetListSchema function.
Timestamp timeStamp=null; NameID nameID= null; //Grab all type of schema SchemaListCriteria arSchema = new SchemaListCriteria(SchemaType.ALL,true,timeStamp,nameID); SchemaKey schemaKey[] = arsProxy.ARGetListSchema(arsUser,arSchema);
The result will be an array of SchemaKey, which provides a unique identifier for each schema objects. Now, our last task is showing all Schema/Form name using iteration.
int sizeSchema = schemaKey.length;
for (int i=0;i < sizeSchema;i++){
System.out.println(schemaKey[i].getValue());
}
Here is the full java code for get a list of schema using Remedy ARS 6.3.
//Connect to server
Proxy arsProxy = new Proxy();
ARServerUser arsUser = new ARServerUser("Demo", "", "", "arsserver");
Timestamp timeStamp=null;
NameID nameID= null;
//Grab all type of schema
SchemaListCriteria arSchema = new SchemaListCriteria(SchemaType.ALL,true,timeStamp,nameID);
SchemaKey schemaKey[] = arsProxy.ARGetListSchema(arsUser,arSchema);
int sizeSchema = schemaKey.length;
for (int i=0;i < sizeSchema;i++){
System.out.println(schemaKey[i].getValue());
}
Or you can use the Factory design pattern and get your list of schema objects this way:
//Connect to server
ARServerUser arsUser = new ARServerUser("Demo", "", "", "arsserver");
SchemaFactory schemaFactory = SchemaFactory.getFactory( );
SchemaListCriteria listcriteria = new SchemaListCriteria();
// get all schemas modified since epoch (the start of time)
listcriteria.setModifiedAfter(new Timestamp(0));
SchemaCriteria criteria = new SchemaCriteria( );
// get all schemas
criteria.setRetrieveAll( true );
Schema[] schemas = schemaFactory.findObjects( arsUser, listcriteria, criteria );
// now output the names of the schemas that were found
int sizeSchema = schemas.length;
for (int i=0;i < sizeSchema;i++){
System.out.println(schemas[i].getName().getValue());
}
I hope it is enough for the introduction to ARS Java API programming.
Issotyo P.B.S http://jroller.com/page/issotyo

