31.01.09 21:57 Age: 2 yrs
System Comparison Tool - Advanced Samples for BOInterface
This is a small series of publications around a tool that I develop based on the BOInterface library. This tool, called System Comparison Tool, allows you to compare two Business Objects Enterprise systems in order to find out whether there are any inconsistencies within one system or differences between the two systems.
The motivation for this work is that customers may be unsure whether two systems are "identical", so whether a migration from, e.g. XIR2 to XI3.1 was giving the same result on the new system as they had on the old system.
Business Objects Enterprise has an excellent metadata repository, and BOInterface provides you with an easy to use SDK so that you can evaluate that metadata. The System Comparison Tool leverages the Program Object Framework of BOInterface and in the end provides you with a valid Business Objects Enterprise session and a command line and properties file parser so that you can implement code based on BOInterface without having to worry about creating a session or parsing command line parameters.
This article will show you a very simple, yet powerful application of the System Comparison tool - we are not comparing two systems; in fact we are working out whether on one given system, there are instances referenced in the metadata repository for which the actual files on the file system are missing. This scenario may happen due to inconsistencies while migrating the filestore, or due to the CMS never updating the repository about an instance that had disappeared.
Here is the tool:
public class FindMissingFiles {
@SuppressWarnings("unchecked")
public void run(Run run) throws Exception {
final BOReport boReport = run.getBOReport();
final boolean instances = "true".equals(run.getAttribute("instances"));
final String installdir = run.getAttribute("filestore");
|
The run method is called by the Program Object Framework and provides us with a valid session expressed by the BOReport object. It also gives us access to command line parameters or properties kept in a properties file using the getAttribute method. We thus define whether we want to work on instances (outgoing file repository server) or not (incoming file repository server). Installdir is a directory local to the JVM that executes this class which obviously needs to look up the files in the file system. If your filestore is on another system, you need to mount that file location or you need to run this class on that other system.
String query = run.getAttribute("query");
if (query == null) {
query = "SELECT top 100000 SI_ID, SI_NAME, SI_FILES FROM CI_INFOOBJECTS WHERE SI_PARENT_FOLDER != 49 AND SI_INSTANCE=" +
(instances ? 1 : 0) +
" and ( SI_KIND='CrystalReport' or SI_KIND='FullClient' or SI_KIND='Webi')";
}
final Document dReports = CERepositoryQuery.queryInfoStoreXML(boReport.getCESession(), query);
|
We are able to override the query we're executing against the repository using our properties file. The standard query is shown above. Also, you see that BOInterface's CERepositoryQuery.querInfoStoreXML function takes that query and returns a JDom document.
The following code will be given in one chunk so that you can study the elegance of working with XPath expressions to parse the returned XML document using CERepositoryQuery.queryXPath. We first find out the number of documents, then iterate over the documents and evaluate the XML model to find out which files map to the metadata record in the file store.
final List lReports = (List) CERepositoryQuery.queryXPath(dReports, "/results/result", -1);
final int nReports = lReports.size();
Integer docId = -1;
String docName = null;
String fileName = null;
String filePath = null;
int missingFiles = 0;
System.out.println("---------------------------------------------------------------");
System.out.println((instances ? "Instances" : "Reports") +
" that are missing files on the file repository for " + run.getAttribute("cms") + ":");
System.out.println("---------------------------------------------------------------");
for (int i = 0; i < nReports; i++) {
docId = (Integer) CERepositoryQuery.queryXPath(dReports, "/results/result[" + (i + 1) + "]/SI_ID/text()", 0);
docName = (String) CERepositoryQuery.queryXPath(dReports, "/results/result[" + (i + 1) + "]/SI_NAME/text()", 0);
fileName = (String) CERepositoryQuery.queryXPath(dReports, "/results/result[" + (i + 1) + "]/SI_FILES/SI_FILE1/text()", 0);
filePath = (String) CERepositoryQuery.queryXPath(dReports, "/results/result[" + (i + 1) + "]/SI_FILES/SI_PATH/text()", 0);
if ((filePath == null) || (fileName == null)) {
continue;
}
|
With this file path, we are now going to look up the file in the filestore using standard methods.
filePath = filePath.substring(5);
try {
final FileInputStream = fstream new FileInputStream(installdir + filePath + fileName);
} catch (FileNotFoundException e) {
try {
if ("Output".equals(filePath.substring(1, 7))) {
final FileInputStream fstream2 = new FileInputStream(installdir + "frsoutput" +
filePath.substring(7) + fileName);
} else {
final FileInputStream fstream2 = new FileInputStream(installdir + "frsinput" +
filePath.substring(6) + fileName);
}
} catch (FileNotFoundException e2) {
String path = "";
try {
path = CERepositoryQuery.getReportPath(run.getCeSession(), docId);
} catch (Exception e3) {}
System.out.println("Not found: (" + docId + ") " + path + "/" + docName + " \t \t " + StringUtility.replace(installdir +
filePath + fileName, "/", "\\", true));
missingFiles++;
}
}
}
System.out.println("---------------------------------------------------------------");
System.out.println("Total missing files: " + missingFiles);
System.out.println("---------------------------------------------------------------");
}
}
|
Finally we had the class print out the files that were missing.
As you've seen, BOInterface allows you to pretty easily look up information from the metadata repository, to parse that information in a pretty elegant way and to finally comine that information with other information like the existence of a file in the filestore.
The user of this program can then evaluate whether the reported missing files, if any, are relevant, and design a plan of action.
M