package org.vamsas.test.simpleclient;
import java.io.InputStream;
+import java.io.PrintStream;
+import java.io.PrintWriter;
import org.vamsas.client.object;
import org.vamsas.client.simpleclient.VamsasArchiveReader;
public class ArchiveReports {
/**
* print an informative summary on a VamsasDocument
+ * @param outstr TODO
* @param document - the document itself
* @param archive - document source archive for resolving any appData refs
* @return
*/
- public static boolean reportProvenance(Provenance p) {
+ public static boolean reportProvenance(Provenance p, PrintStream outstr) {
if (p==null) {
- System.out.println("No Provenance");
+ outstr.println("No Provenance");
return false;
}
Entry[] pe = p.getEntry();
for (int i=0; i<pe.length; i++)
- System.out.println(pe[i].getDate()+"\t'"+pe[i].getUser()+"'\t"+pe[i].getAction());
+ outstr.println(pe[i].getDate()+"\t'"+pe[i].getUser()+"'\t"+pe[i].getAction());
return true;
}
- public static boolean appDataEntryReport(AppData appD, VamsasArchiveReader archive, boolean cascade) {
+ public static boolean appDataEntryReport(AppData appD, VamsasArchiveReader archive, boolean cascade, PrintStream outstr) {
if (appD!=null) {
boolean nulldata=false;
if (appD.getDataReference()!=null) {
String appData=appD.getDataReference();
- if (appData==null) { System.out.println("Empty DataReference - not valid ?"); }
+ if (appData==null) { outstr.println("Empty DataReference - not valid ?"); }
else
if (appData.length()>1) {
- System.out.print("a reference ("+appData+")");
+ outstr.print("a reference ("+appData+")");
InputStream jstrm;
if ((jstrm=archive.getAppdataStream(appData))!=null)
- System.out.println(" which resolves to a JarEntry.");
+ outstr.println(" which resolves to a JarEntry.");
else {
- System.out.println(" which does not resolve to a JarEntry.");
- System.err.println("Unresolved appdata reference '"+appData+"'");
+ outstr.println(" which does not resolve to a JarEntry.");
+ outstr.println("Unresolved appdata reference '"+appData+"'");
}
} else {
nulldata=true;
if (appD.getData()==null)
nulldata &= true;
else
- System.out.println("an embedded chunk of "+appD.getData().length+" bytes.");
+ outstr.println("an embedded chunk of "+appD.getData().length+" bytes.");
}
if (nulldata)
- System.out.println("Null AppData reference/data chunk.");
+ outstr.println("Null AppData reference/data chunk.");
}
return true;
}
- public static boolean appDataReport(ApplicationData appD, VamsasArchiveReader archive, boolean cascade) {
+ public static boolean appDataReport(ApplicationData appD, VamsasArchiveReader archive, boolean cascade, PrintStream outstr) {
if (appD!=null) {
// Report on root appData
- appDataEntryReport(appD, archive, cascade);
+ appDataEntryReport(appD, archive, cascade, outstr);
if (appD.getUserCount()>0) {
User users[] = appD.getUser();
for (int i=0,j=users.length; i<j; i++) {
- System.out.println("Data for User '"+users[i].getFullname()+"' of '"+users[i].getOrganization()+"'");
- appDataEntryReport(users[i], archive, cascade);
+ outstr.println("Data for User '"+users[i].getFullname()+"' of '"+users[i].getOrganization()+"'");
+ appDataEntryReport(users[i], archive, cascade, outstr);
}
}
}
return true;
}
- public static boolean reportDocument(VamsasDocument document, VamsasArchiveReader archive, boolean cascade) {
+ public static boolean reportDocument(VamsasDocument document, VamsasArchiveReader archive, boolean cascade, PrintStream outstr) {
if (document!=null) {
- System.out.println("Vamsas Document version '"+document.getVersion()+"'");
- reportProvenance(document.getProvenance());
- System.out.print("Document contains "+document.getVAMSASCount()+" VAMSAS Elements and "+document.getApplicationDataCount()+" Application data elements.\n");
+ outstr.println("Vamsas Document version '"+document.getVersion()+"'");
+ reportProvenance(document.getProvenance(), outstr);
+ outstr.print("Document contains "+document.getVAMSASCount()+" VAMSAS Elements and "+document.getApplicationDataCount()+" Application data elements.\n");
if (document.getVAMSASCount()>0 && cascade)
- rootReport(document.getVAMSAS(), true);
+ rootReport(document.getVAMSAS(), true, outstr);
if (document.getApplicationDataCount()>0) {
- System.out.print("There are "+document.getApplicationDataCount()+" ApplicationData references.\n");
+ outstr.print("There are "+document.getApplicationDataCount()+" ApplicationData references.\n");
ApplicationData appd[] = document.getApplicationData();
for (int i=0,j=appd.length; i<j; i++) {
- System.out.print("Application "+i+": '"+appd[i].getName()+"'\nVersion '"+appd[i].getVersion()+"'\nURN: '"+appd[i].getUrn()+"'\n");
- System.out.print("AppData is :");
- appDataReport(appd[i], archive, cascade);
+ outstr.print("Application "+i+": '"+appd[i].getName()+"'\nVersion '"+appd[i].getVersion()+"'\nURN: '"+appd[i].getUrn()+"'\n");
+ outstr.print("AppData is :");
+ appDataReport(appd[i], archive, cascade, outstr);
}
}
return true;
} else {
- System.out.print("Document Object is null");
+ outstr.print("Document Object is null");
}
return false;
}
* summarises all the datasets in a vamsas document.
* @param roots
* @param cascade TODO
+ * @param outstr TODO
* @return
*/
- public static boolean rootReport(VAMSAS[] roots, boolean cascade) {
+ public static boolean rootReport(VAMSAS[] roots, boolean cascade, PrintStream outstr) {
if (roots!=null) {
for (int i=0; i<roots.length; i++) {
VAMSAS r = roots[i];
int ds, tr;
- System.out.print("Vamsas Root "+i+" (id="
+ outstr.print("Vamsas Root "+i+" (id="
+((r.getId()!=null) ? r.getId():"<none>")
+") contains "+(ds=r.getDataSetCount())+" DataSets, "
+ (tr=r.getTreeCount())+" Global trees\n");
if (cascade) {
for (int j=0; j<ds; j++) {
- System.out.println("Dataset "+j);
- cascade = datasetReport(r.getDataSet(j), true) && cascade ;
+ outstr.println("Dataset "+j);
+ cascade = datasetReport(r.getDataSet(j), true, outstr) && cascade ;
}
for (int j=0; j<tr; j++) {
- System.out.println("Global tree "+j);
- cascade = treeReport(r.getTree(j), true) && cascade;
+ outstr.println("Global tree "+j);
+ cascade = treeReport(r.getTree(j), true, outstr) && cascade;
}
}
}
}
return false;
}
- public static boolean datasetReport(DataSet ds, boolean cascade) {
+ public static boolean datasetReport(DataSet ds, boolean cascade, PrintStream outstr) {
if (cascade)
- reportProvenance(ds.getProvenance());
- System.out.println("Dataset contains : "+ds.getSequenceCount()
+ reportProvenance(ds.getProvenance(), outstr);
+ outstr.println("Dataset contains : "+ds.getSequenceCount()
+" sequences, "+ds.getAlignmentCount()+" alignments and "+ds.getTreeCount()+" trees.");
if (cascade)
- alignmentReport(ds.getAlignment(), true);
+ alignmentReport(ds.getAlignment(), true, outstr);
return true;
}
- public static boolean alignmentReport(Alignment[] al, boolean cascade) {
+ public static boolean alignmentReport(Alignment[] al, boolean cascade, PrintStream outstr) {
boolean val=true;
if (al!=null && al.length>0) {
for (int i=0; i<al.length; i++) {
- System.out.println("Alignment "+i);
+ outstr.println("Alignment "+i);
if (cascade)
- reportProvenance(al[i].getProvenance());
- System.out.println("Involves "+al[i].getAlignmentSequenceCount()+" sequences, has "
+ reportProvenance(al[i].getProvenance(), outstr);
+ outstr.println("Involves "+al[i].getAlignmentSequenceCount()+" sequences, has "
+al[i].getAlignmentAnnotationsCount()+" annotations and "+al[i].getTreeCount()+" trees.");
if (cascade) {
for (int t=0; t<al[i].getTreeCount(); t++)
- treeReport(al[i].getTree(t), true);
+ treeReport(al[i].getTree(t), true, outstr);
}
}
}
return val;
}
- public static boolean treeReport(Tree t, boolean cascade) {
- System.out.println("Tree: '"+t.getTitle()+"'");
- return !cascade || reportProvenance(t.getProvenance());
+ public static boolean treeReport(Tree t, boolean cascade, PrintStream outstr) {
+ outstr.println("Tree: '"+t.getTitle()+"'");
+ return !cascade || reportProvenance(t.getProvenance(), outstr);
}
}
orignalnew = sdoc.getVamsasDocument(vread);
log.info("*** Dump follows ***");
- ArchiveReports.reportDocument(orignalnew, vread, false);
+ ArchiveReports.reportDocument(orignalnew, vread, false, System.out);
log.info("*** Dump precedes ***");
} catch (Exception e) {
log.info("makeDemoAppdata: Problems accessing original document");
if (roots!=null) {
log.info("Report on Original roots in archive:");
- ArchiveReports.rootReport(roots, true);
+ ArchiveReports.rootReport(roots, true, System.out);
}
log.info("Getting current vamsas document.");
VamsasDocument doc = varchive.getVamsasDocument();
- ArchiveReports.reportDocument(doc, varchive.getOriginalArchiveReader(), true); // not modified document so references will still be valid
+ ArchiveReports.reportDocument(doc, varchive.getOriginalArchiveReader(), true, System.out); // not modified document so references will still be valid
// do some stuff
log.info("Retrieving backup");
File backup = varchive.backupFile();
log.info("Testing update: ");
VamsasArchiveReader vreader = new VamsasArchiveReader(newf);
SimpleDocument sdoc = new SimpleDocument("testing new vamsas write");
- ArchiveReports.reportDocument(sdoc.getVamsasDocument(vreader), vreader, true);
+ ArchiveReports.reportDocument(sdoc.getVamsasDocument(vreader), vreader, true, System.out);
// backup.delete(); // tidy up
log.info("Testing update: ");
vreader = new VamsasArchiveReader(newf);
sdoc = new SimpleDocument("testing vamsas update");
- ArchiveReports.reportDocument(sdoc.getVamsasDocument(vreader), vreader, true);
+ ArchiveReports.reportDocument(sdoc.getVamsasDocument(vreader), vreader, true, System.out);
} catch (Exception e) {
e.printStackTrace(System.err);
}