NIHVIVO-3005 NIHVIVO-3007 Merged r3374 from maint-rel-1.3 branch.
This commit is contained in:
parent
48b4ded3af
commit
eb567572bd
4 changed files with 337 additions and 217 deletions
|
@ -162,7 +162,7 @@ visualization.temporal = enabled
|
|||
# Absolute path on the server of the Harvester root directory.
|
||||
# You must include the final slash.
|
||||
#
|
||||
harvester.location = /usr/local/vivo/harvester/
|
||||
# harvester.location = /usr/local/vivo/harvester/
|
||||
|
||||
#
|
||||
# Default type(s) for Google Refine Reconciliation Service
|
||||
|
|
|
@ -33,3 +33,13 @@ a.help {
|
|||
#harvestButton {
|
||||
margin-right: 10px;
|
||||
}
|
||||
#fileHarvestErrorHelp ol {
|
||||
margin: 0 0 1.3em 2em;
|
||||
list-style-type: decimal;
|
||||
font-size: .9em;
|
||||
}
|
||||
#fileHarvestErrorHelp em {
|
||||
font-family:"Courier New",Courier,mono;
|
||||
font-style: normal;
|
||||
color:#666;
|
||||
}
|
|
@ -1,5 +1,7 @@
|
|||
<#-- $This file is distributed under the terms of the license in /doc/license.txt$ -->
|
||||
|
||||
<#-- <@dump var="harvesterLocation" /> -->
|
||||
|
||||
<#if !(user.loggedIn && user.hasSiteAdminAccess)>
|
||||
|
||||
<p>You must be an administrator to use this tool.</p>
|
||||
|
@ -14,223 +16,264 @@
|
|||
|
||||
<#else>
|
||||
|
||||
<script type="text/javascript">
|
||||
<h2><a class="ingestMenu" href="${urls.base}/ingest" title="Return to the Data Ingest Tools menu">Ingest Menu</a> > ${jobSpecificHeader}</h2>
|
||||
|
||||
var harvestProgressResponse;
|
||||
<#-- check to ensure harvester.location is set in deploy.properties -->
|
||||
<#if harvesterLocation?has_content>
|
||||
|
||||
function doHarvest()
|
||||
{
|
||||
document.getElementById("harvestButton").disabled = true;
|
||||
document.getElementById("harvestButtonHelpText").innerHTML = "Please wait while your data is harvested.";
|
||||
<script type="text/javascript">
|
||||
|
||||
var request = createRequest();
|
||||
request.onreadystatechange=function() {
|
||||
if(request.readyState == 4 && request.status == 200) {
|
||||
harvestProgressResponse = request.responseText;
|
||||
var harvestProgressResponse;
|
||||
|
||||
var json = eval("(" + harvestProgressResponse + ")");
|
||||
var scriptTextArea = document.getElementById("scriptTextArea");
|
||||
scriptTextArea.innerHTML = json.scriptText;
|
||||
function doHarvest() {
|
||||
document.getElementById("harvestButton").disabled = true;
|
||||
document.getElementById("harvestButtonHelpText").innerHTML = "Please wait while your data is harvested.";
|
||||
|
||||
window.setTimeout(continueHarvest, 1000);
|
||||
}
|
||||
}
|
||||
request.open("POST", "${postTo}", true);
|
||||
request.setRequestHeader("content-type","application/x-www-form-urlencoded");
|
||||
//request.send("${paramMode}=${modeHarvest}&${paramJob}=${job}");
|
||||
request.send("${paramMode}=${modeHarvest}");
|
||||
}
|
||||
|
||||
|
||||
function continueHarvest()
|
||||
{
|
||||
var response = harvestProgressResponse;
|
||||
var json = eval("(" + response + ")");
|
||||
|
||||
var logAppend = json.progressSinceLastCheck;
|
||||
var progressTextArea = document.getElementById("progressTextArea");
|
||||
progressTextArea.innerHTML = progressTextArea.innerHTML + logAppend;
|
||||
progressTextArea.scrollTop = progressTextArea.scrollHeight;
|
||||
|
||||
if(!json.finished) {
|
||||
var request = createRequest();
|
||||
request.onreadystatechange=function() {
|
||||
if(request.readyState == 4 && request.status == 200) {
|
||||
harvestProgressResponse = request.responseText;
|
||||
|
||||
var json = eval("(" + harvestProgressResponse + ")");
|
||||
if(checkForFatalError(json))
|
||||
return;
|
||||
|
||||
var scriptTextArea = document.getElementById("scriptTextArea");
|
||||
scriptTextArea.innerHTML = json.scriptText;
|
||||
|
||||
window.setTimeout(continueHarvest, 1000);
|
||||
}
|
||||
}
|
||||
request.open("POST", "${postTo}", true);
|
||||
request.setRequestHeader("Content-type","application/x-www-form-urlencoded");
|
||||
//request.send("${paramMode}=${modeCheckStatus}&${paramJob}=${job}");
|
||||
request.send("${paramMode}=${modeCheckStatus}");
|
||||
} else {
|
||||
request.setRequestHeader("content-type","application/x-www-form-urlencoded");
|
||||
//request.send("${paramMode}=${modeHarvest}&${paramJob}=${job}");
|
||||
request.send("${paramMode}=${modeHarvest}");
|
||||
}
|
||||
|
||||
// var linkHeader = document.getElementById("linkHeader");
|
||||
// linkHeader.style.display = "inline";
|
||||
$('#linkHeader').removeClass('hidden');
|
||||
|
||||
var importedItems = document.getElementById("importedItems")
|
||||
|
||||
if(json.newlyAddedUrls.length > 0) {
|
||||
for(var i = 0; i < json.newlyAddedUrls.length; i++) {
|
||||
|
||||
var newLi = document.createElement("li");
|
||||
newLi.innerHTML = "<a href=\"" + json.newlyAddedUrls[i] + "\" target=\"_blank\">" + json.newlyAddedUris[i] + "</a>";
|
||||
importedItems.appendChild(newLi);
|
||||
}
|
||||
} else {
|
||||
|
||||
var newLi = document.createElement("li");
|
||||
newLi.innerHTML = "${jobSpecificNoNewDataMessage}";
|
||||
importedItems.appendChild(newLi);
|
||||
function continueHarvest() {
|
||||
var response = harvestProgressResponse;
|
||||
var json = eval("(" + response + ")");
|
||||
if(checkForFatalError(json)) {
|
||||
return;
|
||||
}
|
||||
|
||||
document.getElementById("harvestButtonHelpText").innerHTML = "Harvest complete. For another, please refresh the page.";
|
||||
var logAppend = json.progressSinceLastCheck;
|
||||
var progressTextArea = document.getElementById("progressTextArea");
|
||||
progressTextArea.innerHTML = progressTextArea.innerHTML + logAppend;
|
||||
progressTextArea.scrollTop = progressTextArea.scrollHeight;
|
||||
|
||||
if(!json.finished) {
|
||||
var request = createRequest();
|
||||
request.onreadystatechange=function() {
|
||||
if(request.readyState == 4 && request.status == 200) {
|
||||
harvestProgressResponse = request.responseText;
|
||||
window.setTimeout(continueHarvest, 1000);
|
||||
}
|
||||
}
|
||||
request.open("POST", "${postTo}", true);
|
||||
request.setRequestHeader("Content-type","application/x-www-form-urlencoded");
|
||||
//request.send("${paramMode}=${modeCheckStatus}&${paramJob}=${job}");
|
||||
request.send("${paramMode}=${modeCheckStatus}");
|
||||
} else {
|
||||
// var linkHeader = document.getElementById("linkHeader");
|
||||
// linkHeader.style.display = "inline";
|
||||
$('#linkHeader').removeClass('hidden');
|
||||
|
||||
var importedItems = document.getElementById("importedItems")
|
||||
|
||||
if(json.newlyAddedUrls.length > 0) {
|
||||
for(var i = 0; i < json.newlyAddedUrls.length; i++) {
|
||||
|
||||
var newLi = document.createElement("li");
|
||||
newLi.innerHTML = "<a href=\"" + json.newlyAddedUrls[i] + "\" target=\"_blank\">" + json.newlyAddedUris[i] + "</a>";
|
||||
importedItems.appendChild(newLi);
|
||||
}
|
||||
} else {
|
||||
var newLi = document.createElement("li");
|
||||
newLi.innerHTML = "${jobSpecificNoNewDataMessage}";
|
||||
importedItems.appendChild(newLi);
|
||||
}
|
||||
|
||||
document.getElementById("harvestButtonHelpText").innerHTML = "Harvest complete. For another, please refresh the page.";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
function createRequest() {
|
||||
var request;
|
||||
if (window.XMLHttpRequest) {
|
||||
request = new XMLHttpRequest();
|
||||
} else {
|
||||
request = new ActiveXObject("Microsoft.XMLHTTP");
|
||||
function createRequest() {
|
||||
var request;
|
||||
if (window.XMLHttpRequest) {
|
||||
request = new XMLHttpRequest();
|
||||
} else {
|
||||
request = new ActiveXObject("Microsoft.XMLHTTP");
|
||||
}
|
||||
return request;
|
||||
}
|
||||
return request;
|
||||
}
|
||||
|
||||
function fileResponse()
|
||||
{
|
||||
var response = frames["uploadTarget"].document.getElementsByTagName("body")[0].innerHTML;
|
||||
var json = eval("(" + response + ")");
|
||||
function fileResponse() {
|
||||
var response = frames["uploadTarget"].document.getElementsByTagName("body")[0].innerHTML;
|
||||
var json = eval("(" + response + ")");
|
||||
if(checkForFatalError(json)) {
|
||||
return;
|
||||
}
|
||||
|
||||
var fileListing = document.getElementById("fileListing")
|
||||
var newLi = document.createElement("li");
|
||||
var fileListing = document.getElementById("fileListing")
|
||||
var newLi = document.createElement("li");
|
||||
|
||||
if(json.success)
|
||||
newLi.innerHTML = json.fileName + " <span style=\"color:green\">" + json.errorMessage + "</span>";
|
||||
else
|
||||
newLi.innerHTML = json.fileName + " <span style=\"color:red\">upload failed: " + json.errorMessage + "</span>";
|
||||
fileListing.appendChild(newLi);
|
||||
if (json.success) {
|
||||
newLi.innerHTML = json.fileName + " <span style=\"color:green\">" + json.errorMessage + "</span>";
|
||||
} else {
|
||||
newLi.innerHTML = json.fileName + " <span style=\"color:red\">upload failed: " + json.errorMessage + "</span>";
|
||||
}
|
||||
|
||||
document.getElementById("${paramFirstUpload}").value = "false";
|
||||
fileListing.appendChild(newLi);
|
||||
|
||||
//document.getElementById("responseArea").innerHTML = response;
|
||||
}
|
||||
document.getElementById("${paramFirstUpload}").value = "false";
|
||||
|
||||
function init()
|
||||
{
|
||||
document.getElementById("harvestButton").disabled = false;
|
||||
|
||||
document.getElementById("${paramFirstUpload}").value = "true";
|
||||
document.getElementById("fileUploadForm").onsubmit = function()
|
||||
{
|
||||
document.getElementById("fileUploadForm").target = "uploadTarget";
|
||||
document.getElementById("uploadTarget").onload = fileResponse;
|
||||
//document.getElementById("responseArea").innerHTML = response;
|
||||
}
|
||||
document.getElementById("downloadTemplateForm").onsubmit = function()
|
||||
{
|
||||
document.getElementById("downloadTemplateForm").target = "uploadTarget";
|
||||
|
||||
function init() {
|
||||
document.getElementById("harvestButton").disabled = false;
|
||||
|
||||
document.getElementById("${paramFirstUpload}").value = "true";
|
||||
document.getElementById("fileUploadForm").onsubmit = function()
|
||||
{
|
||||
document.getElementById("fileUploadForm").target = "uploadTarget";
|
||||
document.getElementById("uploadTarget").onload = fileResponse;
|
||||
}
|
||||
document.getElementById("downloadTemplateForm").onsubmit = function()
|
||||
{
|
||||
document.getElementById("downloadTemplateForm").target = "uploadTarget";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
window.onload = init;
|
||||
function checkForFatalError(json) {
|
||||
if(json.fatalError) {
|
||||
handleFatalError();
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
$(document).ready(function() {
|
||||
$('a.help').click(function() {
|
||||
$('#csvHelp-collapsible').toggleClass('hidden');
|
||||
return false;
|
||||
function handleFatalError() {
|
||||
$('#fileHarvestErrorHelp').removeClass('hidden');
|
||||
$('#fileHarvestForm').addClass('hidden');
|
||||
}
|
||||
|
||||
window.onload = init;
|
||||
|
||||
$(document).ready(function() {
|
||||
$('a.help').click(function() {
|
||||
$('#csvHelp-collapsible').toggleClass('hidden');
|
||||
return false;
|
||||
});
|
||||
|
||||
$('#harvestButton').click(function() {
|
||||
doHarvest();
|
||||
return false;
|
||||
});
|
||||
});
|
||||
|
||||
$('#harvestButton').click(function() {
|
||||
doHarvest();
|
||||
return false;
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
</script>
|
||||
<div id="fileHarvestErrorHelp" class="hidden">
|
||||
<p>An error has occurred and the file harvest cannot continue.</p>
|
||||
|
||||
<h2><a class="ingestMenu" href="${urls.base}/ingest">Ingest Menu</a> > ${jobSpecificHeader}</h2>
|
||||
<p>This is most likely due to an improper Harvester configuration. Please ensure the following:</p>
|
||||
|
||||
<div id="step1" class="testfile-step">
|
||||
<h3 class="testfile-step-header">Step 1</h3>
|
||||
<div id="step1-inner" class="testfile-step-body">
|
||||
<h4 class="testfile-step-subheader">Download template</h4>
|
||||
<form id="downloadTemplateForm" method="post" action=${postTo}>
|
||||
<input type="hidden" id="${paramMode}" name="${paramMode}" value="${modeDownloadTemplate}" />
|
||||
<p><input id="submit" type="submit" name="submit" value="Download" /> ${jobSpecificDownloadHelp}</p>
|
||||
</form>
|
||||
<ol>
|
||||
<li>VIVO Harvester is installed.</li>
|
||||
<li>The <em>harvester.location</em> property in deploy.properties is pointed to the Harvester installation directory.</li>
|
||||
<li>In VIVO Harvester, the web server user (typically tomcat6) has read and write access to the <em>vivo/</em> directory and all of its children.</li>
|
||||
<li>In VIVO Harvester, the <em>logs/</em> directory exists and the web server user has read and write access to it.</li>
|
||||
<li>In VIVO Harvester, the file <em>vivo/config/vivo.xml</em> is properly configured with your database information and namespace.</li>
|
||||
</ol>
|
||||
</div>
|
||||
<div class="clearBothDiv" />
|
||||
</div>
|
||||
|
||||
<div id="step2" class="testfile-step">
|
||||
<h3 class="testfile-step-header">Step 2</h3>
|
||||
<div id="step2-inner" class="testfile-step-body">
|
||||
<h4 class="testfile-step-subheader">Fill in data <a class="help" href="#">Help</a></h4>
|
||||
<div id="csvHelp-collapsible" class="hidden">
|
||||
<div id="csvHelp-indented">
|
||||
${jobSpecificFillInHelp}
|
||||
<div id="fileHarvestForm">
|
||||
<div id="step1" class="testfile-step">
|
||||
<h3 class="testfile-step-header">Step 1</h3>
|
||||
<div id="step1-inner" class="testfile-step-body">
|
||||
<h4 class="testfile-step-subheader">Download template</h4>
|
||||
<form id="downloadTemplateForm" method="post" action=${postTo}>
|
||||
<input type="hidden" id="${paramMode}" name="${paramMode}" value="${modeDownloadTemplate}" />
|
||||
<p><input id="submit" type="submit" name="submit" value="Download" /> ${jobSpecificDownloadHelp}</p>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
<p>Fill in the template with your data. You may fill in multiple templates if you wish to harvest multiple files at once.</p>
|
||||
<div id="csvHelp">
|
||||
</div>
|
||||
</div>
|
||||
<div class="clearBothDiv" />
|
||||
</div>
|
||||
|
||||
<div id="step3" class="testfile-step">
|
||||
<h3 class="testfile-step-header">Step 3</h3>
|
||||
<div id="step3-inner" class="testfile-step-body">
|
||||
<h4 class="testfile-step-subheader">Upload file(s)</h4>
|
||||
<p>Upload your filled-in template(s).</p>
|
||||
<form id="fileUploadForm" method="post" enctype="multipart/form-data" action=${postTo}>
|
||||
<input type="hidden" id="${paramFirstUpload}" name="${paramFirstUpload}" value="true" />
|
||||
<!--<input type="hidden" id="${paramJob}" name="${paramJob}" value="${job}" /> -->
|
||||
<input type="file" name="${paramUploadedFile}" />
|
||||
<input type="submit" name="submit" value="Upload" />
|
||||
<iframe id="uploadTarget" name="uploadTarget" src=""></iframe>
|
||||
</form>
|
||||
<h5>Uploaded files</h5>
|
||||
<ul id="fileListing">
|
||||
</ul>
|
||||
</div>
|
||||
<div class="clearBothDiv" />
|
||||
</div>
|
||||
<div id="step2" class="testfile-step">
|
||||
<h3 class="testfile-step-header">Step 2</h3>
|
||||
<div id="step2-inner" class="testfile-step-body">
|
||||
<h4 class="testfile-step-subheader">Fill in data <a class="help" href="#">Help</a></h4>
|
||||
<div id="csvHelp-collapsible" class="hidden">
|
||||
<div id="csvHelp-indented">
|
||||
${jobSpecificFillInHelp}
|
||||
</div>
|
||||
</div>
|
||||
<p>Fill in the template with your data. You may fill in multiple templates if you wish to harvest multiple files at once.</p>
|
||||
<div id="csvHelp">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="step4" class="testfile-step">
|
||||
<h3 class="testfile-step-header">Step 4</h3>
|
||||
<div id="step4-inner" class="testfile-step-body">
|
||||
<h4 class="testfile-step-subheader">Harvest</h4>
|
||||
<p><input type="button" name="harvestButton" id="harvestButton" class="green button" value="Harvest" /><span id="harvestButtonHelpText">Click the button to harvest your file(s).</span></p>
|
||||
</div>
|
||||
<div class="clearBothDiv" />
|
||||
</div>
|
||||
<div id="step3" class="testfile-step">
|
||||
<h3 class="testfile-step-header">Step 3</h3>
|
||||
<div id="step3-inner" class="testfile-step-body">
|
||||
<h4 class="testfile-step-subheader">Upload file(s)</h4>
|
||||
<p>Upload your filled-in template(s).</p>
|
||||
<form id="fileUploadForm" method="post" enctype="multipart/form-data" action=${postTo}>
|
||||
<input type="hidden" id="${paramFirstUpload}" name="${paramFirstUpload}" value="true" />
|
||||
<!--<input type="hidden" id="${paramJob}" name="${paramJob}" value="${job}" /> -->
|
||||
<input type="file" name="${paramUploadedFile}" />
|
||||
<input type="submit" name="submit" value="Upload" />
|
||||
<iframe id="uploadTarget" name="uploadTarget" src=""></iframe>
|
||||
</form>
|
||||
<h5>Uploaded files</h5>
|
||||
<ul id="fileListing">
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="step5" class="testfile-step">
|
||||
<h3 class="testfile-step-header">Step 5</h3>
|
||||
<div id="step5-inner" class="testfile-step-body">
|
||||
<h4 class="testfile-step-subheader">View results</h4>
|
||||
<div id="script">
|
||||
<h5>Script being executed</h5>
|
||||
<textarea cols="100" rows="20" readonly="readonly" id="scriptTextArea"></textarea>
|
||||
<div id="step4" class="testfile-step">
|
||||
<h3 class="testfile-step-header">Step 4</h3>
|
||||
<div id="step4-inner" class="testfile-step-body">
|
||||
<h4 class="testfile-step-subheader">Harvest</h4>
|
||||
<p><input type="button" name="harvestButton" id="harvestButton" class="green button" value="Harvest" /><span id="harvestButtonHelpText">Click the button to harvest your file(s).</span></p>
|
||||
</div>
|
||||
</div>
|
||||
<div id="progress">
|
||||
<h5>Progress</h5>
|
||||
<textarea cols="100" rows="20" readonly="readonly" id="progressTextArea"></textarea>
|
||||
</div>
|
||||
<div id="summary">
|
||||
<h5 id="linkHeader" class="hidden">${jobSpecificLinkHeader}</h5>
|
||||
<ul id="importedItems">
|
||||
</ul>
|
||||
|
||||
<div id="step5" class="testfile-step">
|
||||
<h3 class="testfile-step-header">Step 5</h3>
|
||||
<div id="step5-inner" class="testfile-step-body">
|
||||
<h4 class="testfile-step-subheader">View results</h4>
|
||||
<div id="script">
|
||||
<h5>Script being executed</h5>
|
||||
<textarea cols="100" rows="20" readonly="readonly" id="scriptTextArea"></textarea>
|
||||
</div>
|
||||
<div id="progress">
|
||||
<h5>Progress</h5>
|
||||
<textarea cols="100" rows="20" readonly="readonly" id="progressTextArea"></textarea>
|
||||
</div>
|
||||
<div id="summary">
|
||||
<h5 id="linkHeader" class="hidden">${jobSpecificLinkHeader}</h5>
|
||||
<ul id="importedItems">
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="clearBothDiv" />
|
||||
</div>
|
||||
|
||||
<#else>
|
||||
|
||||
<div id="fileHarvestErrorHelp">
|
||||
<p>The <em>harvester.location</em> property in deploy.properties is undefined.</p>
|
||||
|
||||
<p>In order to use this feature, please define a value for this property that points to the Harvester installation directory before redeploying and restarting the application.</p>
|
||||
</div>
|
||||
|
||||
<#-- if harvester.location is defined -->
|
||||
</#if>
|
||||
|
||||
${stylesheets.add('<link rel="stylesheet" href="${urls.base}/css/harvester/fileharvest.css" />')}
|
||||
|
||||
|
|
|
@ -52,6 +52,8 @@ public class FileHarvestController extends FreemarkerHttpServlet {
|
|||
private static final Log log = LogFactory.getLog(FileHarvestController.class);
|
||||
private static final String TEMPLATE_DEFAULT = "fileharvest.ftl";
|
||||
|
||||
private static final String NORMAL_TERMINATION_LAST_OUTPUT = "File Harvest completed successfully";
|
||||
|
||||
private static final String PARAMETER_FIRST_UPLOAD = "firstUpload";
|
||||
private static final String PARAMETER_UPLOADED_FILE = "uploadedFile";
|
||||
private static final String PARAMETER_MODE = "mode";
|
||||
|
@ -140,6 +142,7 @@ public class FileHarvestController extends FreemarkerHttpServlet {
|
|||
FileHarvestJob jobObject = getJob(vreq, job);
|
||||
|
||||
Map<String, Object> body = new HashMap<String, Object>();
|
||||
String harvesterPath = getHarvesterPath(vreq);
|
||||
//body.put("uploadPostback", "false");
|
||||
body.put("paramFirstUpload", PARAMETER_FIRST_UPLOAD);
|
||||
body.put("paramUploadedFile", PARAMETER_UPLOADED_FILE);
|
||||
|
@ -150,6 +153,7 @@ public class FileHarvestController extends FreemarkerHttpServlet {
|
|||
body.put("modeDownloadTemplate", MODE_DOWNLOAD_TEMPLATE);
|
||||
body.put("job", job);
|
||||
body.put("jobKnown", jobKnown);
|
||||
body.put("harvesterLocation", harvesterPath);
|
||||
body.put("postTo", POST_TO + "?" + PARAMETER_JOB + "=" + job);
|
||||
body.put("jobSpecificHeader", (jobObject != null) ? jobObject.getPageHeader() : "");
|
||||
body.put("jobSpecificLinkHeader", (jobObject != null) ? jobObject.getLinkHeader() : "");
|
||||
|
@ -284,7 +288,7 @@ public class FileHarvestController extends FreemarkerHttpServlet {
|
|||
private void doFileUploadPost(HttpServletRequest request, HttpServletResponse response)
|
||||
throws IOException, ServletException {
|
||||
|
||||
JSONObject json = new JSONObject();
|
||||
JSONObject json = generateJson(false);
|
||||
try {
|
||||
VitroRequest vreq = new VitroRequest(request);
|
||||
|
||||
|
@ -392,7 +396,7 @@ public class FileHarvestController extends FreemarkerHttpServlet {
|
|||
}
|
||||
} catch(Exception e) {
|
||||
log.error(e, e);
|
||||
return;
|
||||
json = generateJson(true);
|
||||
}
|
||||
|
||||
//write the prepared response
|
||||
|
@ -407,6 +411,7 @@ public class FileHarvestController extends FreemarkerHttpServlet {
|
|||
*/
|
||||
private void doHarvestPost(HttpServletRequest request, HttpServletResponse response) {
|
||||
|
||||
JSONObject json;
|
||||
try {
|
||||
VitroRequest vreq = new VitroRequest(request);
|
||||
FileHarvestJob job = getJob(vreq, vreq.getParameter(PARAMETER_JOB));
|
||||
|
@ -416,18 +421,23 @@ public class FileHarvestController extends FreemarkerHttpServlet {
|
|||
String script = job.getScript();
|
||||
String additionsFilePath = job.getAdditionsFilePath();
|
||||
String scriptFileLocation = getScriptFileLocation(vreq);
|
||||
runScript(getSessionId(request), script, additionsFilePath, scriptFileLocation);
|
||||
runScript(getSessionId(request), script, additionsFilePath, scriptFileLocation, job);
|
||||
|
||||
JSONObject json = new JSONObject();
|
||||
json = generateJson(false);
|
||||
json.put("progressSinceLastCheck", "");
|
||||
json.put("scriptText", script);
|
||||
json.put("finished", false);
|
||||
|
||||
response.getWriter().write(json.toString());
|
||||
|
||||
} catch(Exception e) {
|
||||
json = generateJson(true);
|
||||
log.error(e, e);
|
||||
}
|
||||
|
||||
try {
|
||||
response.getWriter().write(json.toString());
|
||||
} catch(IOException e) {
|
||||
log.error(e, e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -439,6 +449,7 @@ public class FileHarvestController extends FreemarkerHttpServlet {
|
|||
*/
|
||||
private void doCheckHarvestStatusPost(HttpServletRequest request, HttpServletResponse response) {
|
||||
|
||||
JSONObject json;
|
||||
try {
|
||||
String newline = "\n";
|
||||
|
||||
|
@ -463,6 +474,7 @@ public class FileHarvestController extends FreemarkerHttpServlet {
|
|||
}
|
||||
|
||||
boolean finished = sessionInfo.isFinished();
|
||||
boolean abnormalTermination = false;
|
||||
|
||||
VitroRequest vreq = new VitroRequest(request);
|
||||
ArrayList<String> newlyAddedUrls = new ArrayList<String>();
|
||||
|
@ -478,21 +490,35 @@ public class FileHarvestController extends FreemarkerHttpServlet {
|
|||
|
||||
//remove all entries in "sessionIdTo..." mappings for this session ID
|
||||
clearSessionInfo(sessionId);
|
||||
|
||||
if(sessionInfo.getAbnormalTermination())
|
||||
abnormalTermination = true;
|
||||
}
|
||||
|
||||
JSONObject json = new JSONObject();
|
||||
json.put("progressSinceLastCheck", progressSinceLastCheck);
|
||||
json.put("finished", finished);
|
||||
json.put("newlyAddedUris", newlyAddedUris);
|
||||
json.put("newlyAddedUrls", newlyAddedUrls);
|
||||
|
||||
response.getWriter().write(json.toString());
|
||||
if(!abnormalTermination) {
|
||||
json = generateJson(false);
|
||||
json.put("progressSinceLastCheck", progressSinceLastCheck);
|
||||
json.put("finished", finished);
|
||||
json.put("newlyAddedUris", newlyAddedUris);
|
||||
json.put("newlyAddedUrls", newlyAddedUrls);
|
||||
} else {
|
||||
json = generateJson(true);
|
||||
log.error("File harvest terminated abnormally.");
|
||||
}
|
||||
} else { //if we have not started a harvest thread, the browser should not have made this request to begin with. Bad browser, very bad browser.
|
||||
json = generateJson(true);
|
||||
log.error("Attempt to check status of a harvest that was never started! (Session ID " + sessionId + ")");
|
||||
}
|
||||
} catch(Exception e) {
|
||||
json = generateJson(true);
|
||||
log.error(e, e);
|
||||
}
|
||||
|
||||
try {
|
||||
response.getWriter().write(json.toString());
|
||||
} catch(IOException e) {
|
||||
log.error(e, e);
|
||||
}
|
||||
}
|
||||
|
||||
private void doDownloadTemplatePost(HttpServletRequest request, HttpServletResponse response) {
|
||||
|
@ -549,10 +575,10 @@ public class FileHarvestController extends FreemarkerHttpServlet {
|
|||
}
|
||||
|
||||
|
||||
private void runScript(String sessionId, String script, String additionsFilePath, String scriptFileLocation) {
|
||||
private void runScript(String sessionId, String script, String additionsFilePath, String scriptFileLocation, FileHarvestJob job) {
|
||||
clearSessionInfo(sessionId);
|
||||
|
||||
ScriptRunner runner = new ScriptRunner(sessionId, script, additionsFilePath, scriptFileLocation);
|
||||
ScriptRunner runner = new ScriptRunner(sessionId, script, additionsFilePath, scriptFileLocation, job);
|
||||
SessionInfo info = new SessionInfo(sessionId, runner);
|
||||
sessionIdToSessionInfo.put(sessionId, info);
|
||||
runner.start();
|
||||
|
@ -604,7 +630,7 @@ public class FileHarvestController extends FreemarkerHttpServlet {
|
|||
* @param additionsFile the file containing the newly-added RDF/XML
|
||||
* @param newlyAddedUris a list in which to place the newly added URIs
|
||||
*/
|
||||
private void extractNewlyAddedUris(File additionsFile, List<String> newlyAddedUris) {
|
||||
private void extractNewlyAddedUris(File additionsFile, List<String> newlyAddedUris, FileHarvestJob job) {
|
||||
|
||||
try {
|
||||
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
|
||||
|
@ -618,7 +644,16 @@ public class FileHarvestController extends FreemarkerHttpServlet {
|
|||
Node node = descriptionNodes.item(i);
|
||||
|
||||
ArrayList<String> types = getRdfTypes(node);
|
||||
if(types.contains("http://vivoweb.org/ontology/core#Grant")) { //todo: generalize
|
||||
|
||||
boolean match = false;
|
||||
String[] validRdfTypesForJob = job.getRdfTypesForLinks();
|
||||
for(String rdfType : validRdfTypesForJob) {
|
||||
if(types.contains(rdfType))
|
||||
match = true;
|
||||
break;
|
||||
}
|
||||
|
||||
if(match) {
|
||||
|
||||
NamedNodeMap attributes = node.getAttributes();
|
||||
Node aboutAttribute = attributes.getNamedItemNS("http://www.w3.org/1999/02/22-rdf-syntax-ns#", "about");
|
||||
|
@ -705,6 +740,21 @@ public class FileHarvestController extends FreemarkerHttpServlet {
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create a new JSON object
|
||||
* @param fatalError whether the fatal error flag should be set on this object
|
||||
* @return the new JSON object
|
||||
*/
|
||||
private JSONObject generateJson(boolean fatalError) {
|
||||
JSONObject json = null;
|
||||
try {
|
||||
json = new JSONObject();
|
||||
json.put("fatalError", fatalError);
|
||||
} catch(JSONException e) {
|
||||
log.error(e.getMessage(), e);
|
||||
}
|
||||
return json;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -743,6 +793,11 @@ public class FileHarvestController extends FreemarkerHttpServlet {
|
|||
*/
|
||||
private boolean finished = false;
|
||||
|
||||
/**
|
||||
* Flag indicating that the thread finished abnormally.
|
||||
*/
|
||||
private boolean abnormalTermination = false;
|
||||
|
||||
|
||||
/**
|
||||
* Newly added entries to VIVO, for this user session.
|
||||
|
@ -757,6 +812,13 @@ public class FileHarvestController extends FreemarkerHttpServlet {
|
|||
this.harvestThread = harvestThread;
|
||||
}
|
||||
|
||||
public void setAbnormalTermination() {
|
||||
abnormalTermination = true;
|
||||
}
|
||||
public boolean getAbnormalTermination() {
|
||||
return abnormalTermination;
|
||||
}
|
||||
|
||||
public void finish() {
|
||||
finished = true;
|
||||
}
|
||||
|
@ -786,14 +848,16 @@ public class FileHarvestController extends FreemarkerHttpServlet {
|
|||
private final String script;
|
||||
private final String additionsFilePath;
|
||||
private final String scriptFileLocation;
|
||||
private final FileHarvestJob job;
|
||||
|
||||
private volatile boolean abort = false;
|
||||
|
||||
public ScriptRunner(String sessionId, String script, String additionsFilePath, String scriptFileLocation) {
|
||||
public ScriptRunner(String sessionId, String script, String additionsFilePath, String scriptFileLocation, FileHarvestJob job) {
|
||||
this.sessionId = sessionId;
|
||||
this.script = script;
|
||||
this.additionsFilePath = additionsFilePath;
|
||||
this.scriptFileLocation = scriptFileLocation;
|
||||
this.job = job;
|
||||
}
|
||||
|
||||
public void abortRun() {
|
||||
|
@ -804,6 +868,7 @@ public class FileHarvestController extends FreemarkerHttpServlet {
|
|||
@Override
|
||||
public void run() {
|
||||
SessionInfo sessionInfo = sessionIdToSessionInfo.get(sessionId);
|
||||
boolean normalTerminationLineFound = false;
|
||||
if(sessionInfo != null) {
|
||||
try {
|
||||
ArrayList<String> unsentLogLines = sessionInfo.unsentLogLines;
|
||||
|
@ -820,6 +885,8 @@ public class FileHarvestController extends FreemarkerHttpServlet {
|
|||
BufferedReader processOutputReader = new BufferedReader(new InputStreamReader(pr.getInputStream()));
|
||||
for(String line = processOutputReader.readLine(); line != null; line = processOutputReader.readLine()) {
|
||||
|
||||
normalTerminationLineFound = line.endsWith(NORMAL_TERMINATION_LAST_OUTPUT); //set every read to ensure it's the last line
|
||||
|
||||
//don't add stuff to this list if the main thread is running a "transaction" of copying out the data to send to client and then clearing the list
|
||||
synchronized(unsentLogLines) {
|
||||
unsentLogLines.add(line);
|
||||
|
@ -857,7 +924,7 @@ public class FileHarvestController extends FreemarkerHttpServlet {
|
|||
|
||||
File additionsFile = new File(this.additionsFilePath);
|
||||
if(additionsFile.exists())
|
||||
extractNewlyAddedUris(additionsFile, sessionInfo.newlyAddedUris);
|
||||
extractNewlyAddedUris(additionsFile, sessionInfo.newlyAddedUris, this.job);
|
||||
else
|
||||
log.error("Additions file not found: " + this.additionsFilePath);
|
||||
}
|
||||
|
@ -867,10 +934,10 @@ public class FileHarvestController extends FreemarkerHttpServlet {
|
|||
log.error(e, e);
|
||||
} finally {
|
||||
sessionInfo.finish();
|
||||
if(!normalTerminationLineFound)
|
||||
sessionInfo.setAbnormalTermination();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue