TrackLoader loader = new TrackLoader();
Genome curGenome = null;
try {
curGenome = GenomeManager.getInstance().loadGenome(genomeItem.getLocation(), null);
} catch (IOException e) {
recordError(new ResourceLocator(genomeItem.getLocation()), e, failedFiles);
continue;
}
errorWriter.println("Genome: " + curGenome.getId());
try {
nodeURLs = LoadFromServerAction.getNodeURLs(genomeURL);
if (nodeURLs == null) {
errorWriter.println("Warning: No Data found for " + genomeURL);
continue;
}
} catch (Exception e) {
recordError(genomeURL, e, failedFiles);
continue;
}
for (String nodeURL : nodeURLs) {
errorWriter.println("NodeURL: " + nodeURL);
try {
Document xmlDocument = LoadFromServerAction.createMasterDocument(Arrays.asList(nodeURL));
DefaultMutableTreeNode treeNode = new DefaultMutableTreeNode("HostedDataTest");
ResourceTree.buildLocatorTree(treeNode, xmlDocument.getDocumentElement(),
Collections.<ResourceLocator>emptySet(), null);
Enumeration enumeration = treeNode.depthFirstEnumeration();
while (enumeration.hasMoreElements()) {
Object nextEl = enumeration.nextElement();
DefaultMutableTreeNode node = (DefaultMutableTreeNode) nextEl;
Object userObject = node.getUserObject();
//Get resource locator from tree
//don't load resources we've already tried (same file can be listed multiple times)
ResourceTree.CheckableResource checkableResource;
ResourceLocator locator;
if (userObject instanceof ResourceTree.CheckableResource) {
checkableResource = (ResourceTree.CheckableResource) userObject;
locator = checkableResource.getResourceLocator();
if (locator.getPath() == null || loadedResources.contains(locator)) {
continue;
} else {
loadedResources.add(locator);
}
} else {
continue;
}
// int childCount = node.getChildCount();
// if(childCount > 0){
// System.out.println(node.getUserObject() + " Children: " + childCount);
// if(childCount > maxChildCount){
// maxChildCount = childCount;
// maxNode = node;
// }
// }
FeatureDB.clearFeatures();
try {
// if(locator.getServerURL() != null){
// //System.out.println("server url " + locator.getServerURL());
// //System.out.println("path " + locator.getPath());
// }else{
// continue;
// }
// errorWriter.println("Loading " + locator);
loader.load(locator, curGenome);
} catch (Exception e) {
recordError(locator, e, failedFiles);
}
counter = (counter + 1) % clearInterval;
}
} catch (Exception e) {
recordError(nodeURL, e, failedFiles);
}
}
}
//System.out.println("Max Node: " + maxNode + ". Children: " + maxChildCount);
for (Map.Entry<ResourceLocator, Exception> entry : failedFiles.entrySet()) {
ResourceLocator item = entry.getKey();
errorWriter.println(formatLocator(item) + "\terror: " + entry.getValue().getMessage());
}
errorWriter.flush();
errorWriter.close();