* @param action
* text for action entry
* @return new Provenance entry for ArchiveWriter created docs.
+ * TODO: Verify and move to SimpleClient class for provenance handling
*/
public static Entry newProvenanceEntry(String user, String action) {
log.debug("Adding ProvenanceEntry("+user+","+action+")");
list.addEntry(newProvenanceEntry("ArchiveWriter", "Created new Vamsas Document"));
return list;
}
+
private static void mergeVecs(Object[] destvec, Object[] svec1, Object[] svec2) {
int i;
for (i=0; i<svec1.length; i++)
}
return ht;
}
+ /**
+ * safely copies an appData from one archive to another.
+ * @param darc destination archive
+ * @param dest destination document object
+ * @param sarc source archive reader
+ * @param entry application data to be copied from source archive
+ */
public static void addAppDataEntry(VamsasArchive darc, VamsasDocument dest, VamsasArchiveReader sarc, ApplicationData entry) {
// check uniqueness of entry.urn amongst dest.ApplicationData[].urn
//
}
}
+ /**
+ * Copy new datasets and appdatas from one vamsas document to another.
+ * @param darc
+ * @param dest
+ * @param sarc
+ * @param source
+ * @return true if merge was successful.
+ */
public static boolean mergeDocs(VamsasArchive darc, VamsasDocument dest, VamsasArchiveReader sarc, VamsasDocument source) {
log.debug("mergeDocs entered.");
// search for appDatas in cdoc
VAMSAS[] newr = new VAMSAS[dest.getVAMSASCount()+source.getVAMSASCount()];
mergeVecs(newr, dest.getVAMSAS(), source.getVAMSAS());
dest.setVAMSAS(newr);
- // TODO: should verify that all ids really are unique in newly merged document. If not then what ?
-
+ /** TODO: LATER: should verify that all ids really are unique in newly merged document. If not then what ?
+ * investigate possibility of having an id translation between appDatas and the core document -
+ * the mapping is stored when an external application performs a merge, but when the owning
+ * Application accesses the object, the vorba_id is updated to the new one when it writes its
+ * references in to its appdata again
+ */
if (source.getApplicationDataCount()>0) {
ApplicationData[] newdat = new ApplicationData[source.getApplicationDataCount()+dest.getApplicationDataCount()];
ApplicationData[] sappd = source.getApplicationData();
public static void main(String argv[]) {
+ /**
+ * TODO: switches for setting user identities for writing to vamsas document
+ */
if (argv.length<1) {
log.fatal("Usage : <archive to create> [(commands)]");
return;
docroot.setProvenance(newProvenance());
while (++argpos<argv.length) {
File archive = new File(argv[argpos]);
+ InputStream istream;
if (archive.exists()) {
VamsasArchiveReader vdoc = new VamsasArchiveReader(archive);
if (vdoc.isValid()) {
- InputStream istream = vdoc.getVamsasDocumentStream();
+ istream = vdoc.getVamsasDocumentStream();
if (istream!=null) {
VamsasDocument cdocroot = VamsasDocument.unmarshal(new InputStreamReader(istream));
if (cdocroot!=null)
mergeDocs(varc, docroot, vdoc, cdocroot);
- } else {
+ } else
+ log.warn("Unexpectedly null document stream from existing document "+archive);
+ } else {
+ // updating an oldformat stream ?
if ((istream = vdoc.getVamsasXmlStream())!=null) {
// make a new vamsas document from the vamsas.xml entry
- VAMSAS root = VAMSAS.unmarshal(new InputStreamReader(istream));
+ VAMSAS root = VAMSAS.unmarshal(new InputStreamReader(istream)); // TODO: verify only one VAMSAS element per vamsas.xml entry.
docroot.getProvenance().addEntry(newProvenanceEntry("user", "added vamsas.xml from "+argv[argpos-1]));
docroot.addVAMSAS(root);
}
- }
-
}
- // Write a dummy vamsas document
-
+ } else {
+ // Begin a new vamsas document
PrintWriter docwriter = varc.getDocumentOutputStream();
}
}