Posts Tagged ‘JAVA’

ARSocial, a Java Plugin for Twitter – BMC Remedy AR System integration

March 29th, 2010

Credits – Sebastiaan de Mann

Twitter – @sebas

ARSocial is a Twitter – BMC Remedy AR System integration that allows you to publish tweets, replies, direct messages as well as have an overview of your friends timeline, a search option and mentions. Because it is based on the AR System it can be fully integrated into the ITSM Suite as well as custom built applications. The plugin and application are open source and released on with a BSD style license. Please be aware this is only a ‘preview’ release and is not quite ready for production use.

Here are some pics of the wonderful app

Detailed information in author’s words:

Architecture

The ARSocial application consists of several parts:

  • ARDBC Plugin for listing tweets, mentions, direct messages and search

The ARDBC Plugin treats the twitter feeds (friends, direct messages, search) as a database source. Because of the speed of the Twitter API we can do fast searches and show all relevant information, mentions and direct messages. It also allows for the creation of tweets, replies and direct messages.

  • ARSocial Console form, for an overview of all twitter related items

This will be the main form for the users of the application. It is meant to keep an overview of all tweets that are sent by friends, mentions of the twitter account and searches (for example tweets that mention your company name)

  • Vendor and Regular forms

Vendor Forms are built from the ARDBC Data sources to show the information in the Tables of the console. Regular forms are used to store sent Tweets and Direct Messages.

All items and source code can be found in the download package.

What you will need

  • BMC Remedy AR System 7.5 server
  • Midter 7.5
  • Remedy Developer know-how
  • Plugin Server know-how
  • Java know-how
  • A twitter account
  • An AR Server that you can break without getting people angry at you (really, I’m serious)

You can download a ‘developer preview’ of the application here: arsocialpreview

at the moment there’s only standard twitter client functionality implemented, and there is no direct integration into the ITSM Suite, however because of the architecture including Vendor Forms it is quite easy to integrate into any itsm and custom built applications. Over the next few weeks I will expand the plugin and the application.

For now please be aware there are several open issues, including ordering of tweets in the table fields and missing functionality in the stand-alone application.

Please provide feedback on BMCDN communities, contact Sebas on twitter or send an email.

Create, Modify and Query Records in Remedy using Remedy Java API

December 16th, 2009

Use of Remedy Java API to Create, Modify and Query Records (Amar Dadhi)

Remedy Java API is most tight synchronous way of integrating AR System with legacy applications. It is most sophisticated way of integrating remedy applications. The sample source code given below will describe how to use java api. Refer AR System integration document for details. Sample code shows Create, modify and querying records with java API. Before compiling the source code you need verify that PATH, CLASSPATH are set correctly and alldll’s and jar files mentioned in integration document are in the same directory where source file is stored.

// include section
import java.io.*;
import java.util.*;
import java.text.*;
import com.remedy.arsys.api.*;
// public class RemedyRecord
//main method accepts server user password schema, operation etc values.
public class RemedyRecord
{
ARServerUser userInfo;
Entry entry;
public static void main (String[] args)
{
// Declaration of variables.
String[] fvPairs = new String[1];
String clvalues[] = {“Server”,”User”,”Password”,”Schema”,”Operation”, “EntryID”, “Criteria”};
String vServer;
String vUser;
String vPassword;
String vSchema;
String eID = null;
String vCriteria = null;
String fileLog = null;
FileOutputStream fout;
Date today = new Date();
SimpleDateFormat formatter = new SimpleDateFormat(“yyyyMMdd”);
String datenewformat = formatter.format(today);
String nameFile = “remedyAPI”+datenewformat+”.log”;
RemedyRecord cRemedyRecord = new RemedyRecord();
File f = new File( nameFile);
if (!(f.exists()))
{
try
{
fout = new FileOutputStream (nameFile); // Open an output stream
fout.close(); // Close our output stream
}
catch (IOException e) // Catches any error conditions
{
System.err.println (“Unable to write to file”);
}
}
if (args.length<6)
{
System.out.println(“Usage of program requires minimum 6 arguments.”);
System.out.println(“Program accepets an arguments with the below sequence.”);
Remedy Action Request System Server

http://myadminteam.com

Powered by Joomla!
Generated: 25 February, 2009, 17:02
Page 2
System.out.println(“Remedy Server – <remserver>”);
System.out.println(“User – <user>”);
System.out.println(“Pasword – <password>”);
System.out.println(“Schema- <schema>”);
System.out.println(“Operation – Submit <S>, Modify <M>, Search <Q>”);
System.out.println(“For modify entry id is required – <entry id>”);
System.out.println(“Field id – value pair <field id1> <value1> <field id2> <value2> <field id3> <value3>…….”);
System.out.println(“Syntax for submit – RemedyRecord ” +’”‘+”<server>”+’”‘ + ” “+’”‘+”<user>”+’”‘+”
“+’”‘+”<password>”+’”‘+” “+’”‘+”<schema>”+’”‘+” “+’”‘+”S”+’”‘+” “+’”‘+”<field id1>”+’”‘+” “+’”‘+”<value1>”+’”‘+” “+’”‘+”<field
id2>”+’”‘+” “+’”‘+”<value2>”+’”‘+” “+’”‘+”<field id3>”+’”‘+” “+’”‘+”<value3>”+’”‘+”…….”);
System.out.println(“Syntax for modify – RemedyRecord ” +’”‘+”<server>”+’”‘ + ” “+’”‘+”<user>”+’”‘+”
“+’”‘+”<password>”+’”‘+” “+’”‘+”<schema>”+’”‘+” “+’”‘+”M”+’”‘+” “+’”‘+”<entry id>”+’”‘+” “+’”‘+”<field id1>”+’”‘+”
“+’”‘+”<value1>”+’”‘+” “+’”‘+”<field id2>”+’”‘+” “+’”‘+”<value2>”+’”‘+” “+’”‘+”<field id3>”+’”‘+” “+’”‘+”<value3>”+’”‘+”…….”);
System.out.println(“Syntax for search – RemedyRecord ” +’”‘+”<server>”+’”‘ + ” “+’”‘+”<user>”+’”‘+”
“+’”‘+”<password>”+’”‘+” “+’”‘+”<schema>”+’”‘+” “+’”‘+”Q”+’”‘+” “+’”‘+”<criteria>”+’”‘);
System.exit(1);
}
fileLog = “Operation – ” + args[4] + ” #Arguments – ” + args.length;
cRemedyRecord.writeLogFile(nameFile, fileLog);
if (args[4].equals (“S”) && args.length<11)
{
System.out.println(“To submit the record at least 3 fieldid-value pairs are required.”);
System.out.println(“Syntax for submit – RemedyRecord ” +’”‘+”<server>”+’”‘ + ” “+’”‘+”<user>”+’”‘+”
“+’”‘+”<password>”+’”‘+” “+’”‘+”<schema>”+’”‘+” “+’”‘+”S”+’”‘+” “+’”‘+”<field id1>”+’”‘+” “+’”‘+”<value1>”+’”‘+” “+’”‘+”<field
id2>”+’”‘+” “+’”‘+”<value2>”+’”‘+” “+’”‘+”<field id3>”+’”‘+” “+’”‘+”<value3>”+’”‘+”…….”);
System.exit(1);
}
if (args[4].equals (“M”) && args.length<8)
{
System.out.println(“To modify the record at least 1 fieldid-value pair is required.”);
System.out.println(“Syntax for modify – RemedyRecord ” +’”‘+”<server>”+’”‘ + ” “+’”‘+”<user>”+’”‘+”
“+’”‘+”<password>”+’”‘+” “+’”‘+”<schema>”+’”‘+” “+’”‘+”M”+’”‘+” “+’”‘+”<entry id>”+’”‘+” “+’”‘+”<field id1>”+’”‘+”
“+’”‘+”<value1>”+’”‘+” “+’”‘+”<field id2>”+’”‘+” “+’”‘+”<value2>”+’”‘+” “+’”‘+”<field id3>”+’”‘+” “+’”‘+”<value3>”+’”‘+”…….”);
System.exit(1);
}
if (args[4].equals (“Q”) && args.length<6)
{
System.out.println(“To search the record search criteria is required is required.”);
System.out.println(“Syntax for search – RemedyRecord ” +’”‘+”<server>”+’”‘ + ” “+’”‘+”<user>”+’”‘+”
“+’”‘+”<password>”+’”‘+” “+’”‘+”<schema>”+’”‘+” “+’”‘+”Q”+’”‘+” “+’”‘+”<criteria>”+’”‘);
System.exit(1);
}
if (args[4].equals (“S”))
{
fileLog = “\n”;
fvPairs = (String[])resizeArray(fvPairs, (args.length-5));
for (int i = 0, j=0; i < args.length; i++)
{
if ( i<5)
{
System.out.println(clvalues[i] + ” — ” +args[i]);
fileLog = fileLog + clvalues[i] + ” — ” +args[i]+”\n”;
}
else
{
System.out.println(“FieldID” + ” — ” + args[i]+ ” Value” + ” — ” +args[i+1]);
fvPairs[j] = args[i];
fileLog = fileLog + “FieldID” + ” — ” + fvPairs[j] + ” — “;
j++;
fvPairs[j] = args[i+1];
fileLog = fileLog + “Value” + ” — ” + fvPairs[j] + “\n”;
j++;
i++;
}
}
}
if (args[4].equals (“M”))
{
fileLog = “\n”;
fvPairs = (String[])resizeArray(fvPairs, (args.length-6));
for (int i = 0, j=0; i < args.length; i++)
{
if ( i<6)
{
System.out.println(clvalues[i] + ” — ” +args[i]);
if(i==5) eID = args[5];
fileLog = fileLog + clvalues[i] + ” — ” +args[i]+”\n”;
}
else
{
System.out.println(“FieldID” + ” — ” + args[i]+ ” Value” + ” — ” +args[i+1]);
fvPairs[j] = args[i];
fileLog = fileLog + “FieldID” + ” — ” + fvPairs[j] + ” — “;
j++;
fvPairs[j] = args[i+1];
fileLog = fileLog + “Value” + ” — ” + fvPairs[j] + “\n”;
j++;
i++;
}
}
}
if (args[4].equals (“Q”))
{
fileLog = “\n”;
for (int i = 0; i < args.length; i++)
{
if ( i<5)
{
System.out.println(clvalues[i] + ” — ” +args[i]);
fileLog = fileLog + clvalues[i] + ” — ” +args[i]+”\n”;
}
else
{
System.out.println(“Criteria” + ” — ” + args[i]);
vCriteria = args[i];
fileLog = fileLog + “Criteria” + ” — ” + vCriteria + “\n”;
}
}
}
System.out.println(“—————————————————–”);
fileLog = fileLog + “————————————————————————————-\n”;
System.out.println(“Total values — ” + fvPairs.length);
fileLog = fileLog + “Total values — ” + fvPairs.length + “\n”;
cRemedyRecord.writeLogFile(nameFile, fileLog);
// for (int i = 0; i < fvPairs.length; i++)
// System.out.println(fvPairs[i]);
vServer= args[0];
vUser = args[1];
vPassword = args[2];
vSchema = args[3];
cRemedyRecord.connect(vServer, vUser , vPassword, nameFile);
cRemedyRecord.init(vSchema, nameFile);
if (args[4].equals (“S”) && ((fvPairs.length % 2)==0))
{
System.out.println(“Creating entry …..”);
String entryID = cRemedyRecord.createRecord(fvPairs, vSchema, nameFile);
System.out.println(“Entry created Id# ” + entryID);
}
else if (args[4].equals (“M”) && ((fvPairs.length % 2)==0))
{
System.out.println(“Modifying record….”);
cRemedyRecord.modifyRecord(eID, fvPairs, vSchema, nameFile);
System.out.println(“Modified record id ” + eID);
}
else if (args[4].equals (“Q”))
{
System.out.println(“Searching Criteria – ” + vCriteria);
cRemedyRecord.queryRecordsByQual(vCriteria, vSchema, nameFile);
}
else
{
System.out.println(“Error in Arguments”);
System.exit(1);
}
cRemedyRecord.cleanup(nameFile);
}
public void connect(String server, String user, String password, String sNameFile)
{
String sFileLog = null;
RemedyRecord cpRemedyRecord = new RemedyRecord();
System.out.println(“Connecting to AR Server…”);
sFileLog = “Connecting to AR Server…\n”;
userInfo = new ARServerUser();
userInfo.setServer(server);
userInfo.setUser(new AccessNameID(user));
userInfo.setPassword(new AccessNameID(password));
try
{
userInfo.verifyUser(new VerifyUserCriteria());
}
catch (ARException e)
{
//This exception is triggered by a bad server, password or, if guest access is turned off, by an unknown username.
System.out.println(“Error verifying user: “+e);
sFileLog = sFileLog + “Error verifying user: “+e +”\n”;
cpRemedyRecord.writeLogFile(sNameFile, sFileLog);
//Clear memory used by our user context object
userInfo.clear();
System.exit(1);
}
System.out.println(“Connected to AR Server.”);
sFileLog = sFileLog + “Connected to AR Server.\n”;
cpRemedyRecord.writeLogFile(sNameFile, sFileLog);
}
public void init(String schemaName, String sNameFile)
{
String sFileLog = null;
RemedyRecord cpRemedyRecord = new RemedyRecord();
NameID formName = new NameID(schemaName);
EntryFactory entryFactory = EntryFactory.getFactory();
entry = (Entry)entryFactory.newInstance();
entry.setContext(userInfo);
entry.setSchemaID(formName);
System.out.println(“Initialized.”);
sFileLog = “Initialized….\n”;
cpRemedyRecord.writeLogFile(sNameFile, sFileLog);
}
public String createRecord (String[] fldValPair, String schemaName, String sNameFile)
{
String entryIdOut= “”;
String sFileLog = null;
RemedyRecord cpRemedyRecord = new RemedyRecord();
try
{
EntryFactory entryFactory = EntryFactory.getFactory();
Entry entryr = (Entry)entryFactory.newInstance();
entryr.setContext(userInfo);
entryr.setSchemaID(new NameID(schemaName));
FieldID[] fields = new FieldID[(fldValPair.length)/2];
Value[] values = new Value[(fldValPair.length)/2];
for (int i = 0, j=0; i < (fldValPair.length); i++)
{
long fId = Long.parseLong(fldValPair[i]);
String fValue = fldValPair[i+1];
fields[j] = new FieldID( fId );
values[j] = new Value( fValue );
System.out.println(” Field ID -” + fields[j] + ” Value – ” + values[j]);
j++;
i++;
}
EntryItem[] entryItems= new EntryItem[(fldValPair.length)/2];
for (int i = 0; i < (fldValPair.length/2); i++)
{
entryItems[i] = new EntryItem(fields[i], values[i]);
}
entryr.setEntryItems(entryItems);
entryr.create();
entryIdOut = entryr.getEntryID().toString();
System.out.println(“Entry created, id #”+entryIdOut);
sFileLog = “Entry created, id #”+ entryIdOut +”\n”;
cpRemedyRecord.writeLogFile(sNameFile, sFileLog);
}
catch (ARException e)
{
ARExceptionHandler(e,”Problem while creating entry: “);
sFileLog = e + ” Problem while creating entry: ” +”\n”;
cpRemedyRecord.writeLogFile(sNameFile, sFileLog);
cpRemedyRecord.cleanup(sNameFile);
}
return entryIdOut;
}
void modifyRecord(String eidStr, String[] fldValPair, String schemaName, String sNameFile)
{
String sFileLog = null;
RemedyRecord cpRemedyRecord = new RemedyRecord();
NameID formName = new NameID(schemaName);
try
{
EntryID entryID = new EntryID(eidStr);
EntryKey entryKey = new EntryKey(formName, entryID);
entry = EntryFactory.findByKey(userInfo, entryKey, null);
FieldID[] fields = new FieldID[(fldValPair.length)/2];
Value[] values = new Value[(fldValPair.length)/2];
for (int i = 0, j=0; i < (fldValPair.length); i++)
{
long fId = Long.parseLong(fldValPair[i]);
String fValue = fldValPair[i+1];
fields[j] = new FieldID( fId );
values[j] = new Value( fValue );
j++;
i++;
}
EntryItem[] entryItems= new EntryItem[(fldValPair.length)/2];
for (int i = 0; i < (fldValPair.length/2); i++)
{
entryItems[i] = new EntryItem(fields[i],values[i]);
}
entry.setEntryItems(entryItems);
entry.store();
System.out.println(“Record #”+eidStr+” modified successfully.”);
sFileLog = “Record #”+eidStr+” modified successfully.\n”;
cpRemedyRecord.writeLogFile(sNameFile, sFileLog);
}
catch(ARException e)
{
ARExceptionHandler(e,”Problem while modifying record: “);
sFileLog = e + ” Problem while modifying record: ” +”\n”;
cpRemedyRecord.writeLogFile(sNameFile, sFileLog);
cpRemedyRecord.cleanup(sNameFile);
}
}
void queryRecordsByQual(String qualStr, String schemaName, String sNameFile)
{
String sFileLog = null;
RemedyRecord cpRemedyRecord = new RemedyRecord();
System.out.println(“Retrieving records with qualification “+qualStr);
sFileLog = “Retrieving records with qualification ” + qualStr + “\n”;
NameID formName = new NameID(schemaName);
try
{
// Set the field criteria to retrieve all field info
FieldCriteria fCrit = new FieldCriteria( );
fCrit.setRetrieveAll(true);
// Retrieve all types of fields
FieldListCriteria fListCrit = new FieldListCriteria(formName, new Timestamp(0), FieldType.AR_ALL_FIELD);
// Load the field array with all fields in the test form
Field[] formFields = FieldFactory.findObjects(userInfo, fListCrit, fCrit);
// Create the search qualifier.
QualifierInfo myQual = Util.ARGetQualifier(userInfo, qualStr, formFields, null,
Constants.AR_QUALCONTEXT_DEFAULT);
FieldFactory.getFactory().releaseInstance( formFields );
// Set the EntryListCriteria
EntryListCriteria listCriteria = new EntryListCriteria( );
listCriteria.setSchemaID( formName );
listCriteria.setQualifier( myQual );
// Define which fields to retrieve in the results list Note that the total width including separators must be
// <256 characters Here the total width=15+15+25+3*1=58, 3*1 is three separators of 1 character each
EntryListFieldInfo[] entryListFieldList = new EntryListFieldInfo[ 3 ];
// Submitter(2)
entryListFieldList[0] = new EntryListFieldInfo(new FieldID(2), 15, ” ” );
// Status(7)
entryListFieldList[1] = new EntryListFieldInfo(new FieldID(7), 15, ” ” );
// Short Description(8)
entryListFieldList[2] = new EntryListFieldInfo(new FieldID(8), 25, ” ” );
// Set the entry criteria
EntryCriteria criteria = new EntryCriteria( );
criteria.setEntryListFieldInfo( entryListFieldList );
// Make the call to retreive the query results list
Integer nMatches = new Integer(0);
// AR Java API 6.0 syntax adds the boolean useLocale flag. Set it to false to return all entries regardless of locale.
EntryListInfo[] entryInfo = EntryFactory.findEntryListInfos (userInfo, listCriteria, criteria, false, nMatches );
System.out.println (“Query returned “+ nMatches +” matches.”);
sFileLog = sFileLog + ” Query returned “+ nMatches +” matches.” +”\n”;
cpRemedyRecord.writeLogFile(sNameFile, sFileLog);
if( nMatches.intValue() > 0)
{
// Print out the matches
System.out.println(“Request Id Submitter”+” Status Short Description” );
for( int i = 0; i < entryInfo.length; i++ )
System.out.println(entryInfo[i].getEntryID().toString( ) +” ” + new String(entryInfo[i].getDescription( )));
}
EntryFactory.getFactory().releaseInstance( entryInfo );
}
catch( ARException e )
{
ARExceptionHandler (e,”Problem while querying by qualifier: “);
sFileLog = sFileLog + e+ ” Problem while querying by qualifier: ” +”\n”;
cpRemedyRecord.writeLogFile(sNameFile, sFileLog);
cpRemedyRecord.cleanup(sNameFile);
}
}
public void ARExceptionHandler(ARException e, String errMessage)
{
System.out.println(errMessage);
printStatusList(userInfo.getLastStatus());
System.out.print(“Stack Trace:”);
e.printStackTrace();
}
public void printStatusList(StatusInfo[] statusList)
{
if (statusList == null || statusList.length==0)
{
System.out.println(“Status List is empty.”);
return;
}
System.out.print(“Message type: “);
switch(statusList[0].getMessageType())
{
case Constants.AR_RETURN_OK:
System.out.println(“Note”);
break;
case Constants.AR_RETURN_WARNING:
System.out.println(“Warning”);
break;
case Constants.AR_RETURN_ERROR:
System.out.println(“Error”);
break;
case Constants.AR_RETURN_FATAL:
System.out.println(“Fatal Error”);
break;
default:
System.out.println(“Unknown (“+
statusList[0].getMessageType()+”)”);
break;
}
System.out.println(“Status List:”);
for (int i=0; i<statusList.length; i++)
{
System.out.println(statusList[i].getMessageText());
System.out.println(statusList[i].getAppendedText());
}
}
public void cleanup(String sNameFile)
{
String sFileLog = null;
RemedyRecord cpRemedyRecord = new RemedyRecord();
//Clear memory held by our entry object
//Similar cleanup should be done for all objects created by a factory
EntryFactory.getFactory().releaseInstance(entry);
//Clear memory used by our user context object
userInfo.clear();
System.out.println(“AR System objects cleaned up.”);
sFileLog = ” AR System objects cleaned up.\n”;
cpRemedyRecord.writeLogFile(sNameFile, sFileLog);
}
private static Object resizeArray (Object oldArray, int newSize)
{
int oldSize = java.lang.reflect.Array.getLength(oldArray);
Class elementType = oldArray.getClass().getComponentType();
Object newArray = java.lang.reflect.Array.newInstance(elementType,newSize);
int preserveLength = Math.min(oldSize,newSize);
if (preserveLength > 0)
System.arraycopy (oldArray,0,newArray,0,preserveLength);
return newArray;
}
public void writeLogFile(String logFileName, String fileLog)
{
try
{
BufferedWriter out = new BufferedWriter(new FileWriter(logFileName, true)); // Append log file
out.write(fileLog + “\n”); // Write to log
out.close(); // close the file
}
catch (IOException e) // Catches any error conditions
{
System.err.println (“Unable to write to file”);
//System.exit(-1);
}
}
}

Originally posted here