Skip to content

Commit

Permalink
ePADD+
Browse files Browse the repository at this point in the history
  • Loading branch information
jfarwer committed May 26, 2022
1 parent 841a77d commit ca0b360
Show file tree
Hide file tree
Showing 69 changed files with 20,479 additions and 3,412 deletions.
208 changes: 207 additions & 1 deletion WebContent/WEB-INF/classes/messages.properties

Large diffs are not rendered by default.

204 changes: 203 additions & 1 deletion WebContent/WEB-INF/classes/messages_fr.properties

Large diffs are not rendered by default.

11 changes: 10 additions & 1 deletion WebContent/WEB-INF/web.xml
Expand Up @@ -140,6 +140,15 @@
</servlet-mapping>

<servlet>
<servlet-name>edit-metadata</servlet-name>
<jsp-file>/edit-metadata.jsp</jsp-file>
</servlet>
<servlet-mapping>
<servlet-name>edit-metadata</servlet-name>
<url-pattern>/edit-metadata</url-pattern>
</servlet-mapping>

<!--servlet>
<servlet-name>edit-collection-metadata</servlet-name>
<jsp-file>/edit-collection-metadata.jsp</jsp-file>
</servlet>
Expand All @@ -155,7 +164,7 @@
<servlet-mapping>
<servlet-name>edit-accession-metadata</servlet-name>
<url-pattern>/edit-accession-metadata</url-pattern>
</servlet-mapping>
</servlet-mapping-->

<servlet>
<servlet-name>add-accession</servlet-name>
Expand Down
20 changes: 17 additions & 3 deletions WebContent/add-accession.jsp
Expand Up @@ -117,16 +117,30 @@
</script>

<script type="text/javascript">
function importAccession(e){
epadd.import_accession(e, muse.collect_input_fields());
}
$('#gobutton').click(function(e) {
// this currently just copies the archive into the accession.
// it has to be extended to do a merge if the collection already exists
var accid = $('#accessionID').val();
var accpath = $('#accessionFolder').val();
if (accpath && accpath.length > 0) {
if (accid && accid.length > 0)
epadd.import_accession(e, muse.collect_input_fields());
else
if (accid && accid.length > 0) {
// To support exportable asset, result of success ajax/setExportableAssets should be a call to importAccession which,
// in turn, call to epadd.import_accession
//epadd.import_accession(e, muse.collect_input_fields());
var post_params = '&exportableAssets=exportAccessionProcessing&exportableAssetsFiles=' + accpath;
var page = "ajax/async/setExportableAssets.jsp";
console.log("add-accession.jsp: goButton.click: post_params=" + post_params);
try {
fetch_page_with_progress(page, "status", document.getElementById('status'), document.getElementById('status_text'), post_params, importAccession(e));
} catch(err) { }
} else
epadd.error("Please provide an accession ID for this accession");
}
else
Expand Down
123 changes: 123 additions & 0 deletions WebContent/ajax/async/setExportableAssets.jsp
@@ -0,0 +1,123 @@
<%@page language="java" contentType="application/json;charset=UTF-8"%>
<%@ page import="edu.stanford.muse.webapp.JSPHelper" %>
<%@ page import="edu.stanford.muse.util.Util" %>
<%@ page import="org.json.JSONArray" %><%@ page import="org.json.JSONObject"%><%@ page import="org.json.CDL"%><%@ page import="org.apache.commons.io.FileUtils"%><%@ page import="au.com.bytecode.opencsv.CSVWriter"%><%@ page import="java.util.*"%><%@ page import="edu.stanford.muse.ner.model.NEType"%><%@ page import="edu.stanford.muse.index.*"%><%@ page import="java.io.*"%><%@ page import="java.util.zip.GZIPOutputStream"%><%@ page import="java.util.zip.ZipOutputStream"%><%@ page import="java.util.zip.ZipEntry"%><%@ page import="edu.stanford.muse.util.EmailUtils"%><%@ page import="edu.stanford.muse.webapp.ModeConfig"%><%@ page import="edu.stanford.muse.AddressBookManager.AddressBook"%><%@ page import="edu.stanford.muse.email.StatusProvider"%><%@ page import="com.google.common.collect.Multimap"%><%@ page import="java.util.function.Consumer"%><%@ page import="edu.stanford.epadd.util.OperationInfo"%><%@ page import="edu.stanford.muse.email.StaticStatusProvider"%>
<%
//This api needs to be supported for both types of flows - long running with status bar and normal (without status bar). Theso two invocation types of this jsp will be identified
//by the presence of operation ID (opID field) in the request. If it is being invoked as a long running operation then the front end will use fetch_page_progress_bar method to invoke it
//which in turn will provide it with an operation ID.
Archive archive = ArchiveReaderWriter.prepareAndLoadDefaultArchive(request);
Multimap<String,String> paramMap = JSPHelper.convertRequestToMap(request);
//String appURL = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + request.getContextPath();
String appURL="";
String opID = request.getParameter("opID");
if(opID==null){
//invoke this as normal ajax call without using operation Info object.
JSONObject result = new JSONObject();
setExportableAssets(paramMap,null,session,result, archive);
out.println(result);
}else{
//means it is being invoked as a long running operation using fetch_page_progress api in js. use OperationInfo protocol to invoke it.
//<editor-fold desc="Setting up the operation object to execute this operation asynchronously">
//get the operation ID from the request parameter.
String encoding = request.getCharacterEncoding();
JSPHelper.log.info("request parameter encoding is " + encoding);
String actionName = request.getRequestURI();
//create a new operation object with the information necessary to run this long running async task.
final HttpSession fsession = session;
OperationInfo opinfo = new OperationInfo(actionName,opID,paramMap) {
@Override
public void onStart(JSONObject resultJSON) {
//creating a lambda expression that will be used by functions to set the statusprovider without knowing the
//operationinfo object
Consumer<StatusProvider> setStatusProvider = statusProvider->this.setStatusProvider(statusProvider);
setExportableAssets(this.getParametersMap(),setStatusProvider,fsession,resultJSON, archive);
}@Override
public void onCancel() {
//creating a lambda expression that will be used by functions to set the statusprovider without knowing the
//operationinfo object
Consumer<StatusProvider> setStatusProvider = statusProvider->this.setStatusProvider(statusProvider);
cancelGetNormalizedAsset(setStatusProvider);
}
};
JSPHelper.setOperationInfo(session,opID,opinfo);
opinfo.run();
JSONObject obj = new JSONObject();
out.println(obj);
}
%>

<%!
public void setExportableAssets(Multimap<String,String> params, Consumer<StatusProvider> setStatusProvider, HttpSession session, JSONObject resultJSON, Archive archive){
if(setStatusProvider!=null)
setStatusProvider.accept(new StaticStatusProvider("setting exportable assets..."));
String exportableAssets = JSPHelper.getParam(params,"exportableAssets");
String exportableAssetsFiles = JSPHelper.getParam(params,"exportableAssetsFiles");
//Archive archive = JSPHelper.getArchive(params);
if (archive == null) {
resultJSON.put("-Err-", "No archive in session");
resultJSON.put("status", 0);
// The status should be 1, but in processing mode entering the archive is stopped altogether and the user is stuck
// on the start page.
//out.println (result);
JSPHelper.log.info(resultJSON);
return;
}
String error="";
JSONObject exportResult = new JSONObject();
ArrayList<String> assetsLocation = new ArrayList<String>();
if (!Util.nullOrEmpty(exportableAssetsFiles)){
assetsLocation = new ArrayList(Arrays.asList(exportableAssetsFiles.split("\\^-\\^")));
}
if ("exportAcquisitioned".equals(exportableAssets)){
System.out.println("exportableAssets = exportAcquisitioned");
// Notes: assetsLocation here should be a list of full path filenames
exportResult = archive.setExportableAssets(Archive.Exportable_Assets.EXPORTABLE_APPRAISAL_CANONICAL_ACQUISITIONED, assetsLocation);
exportResult = archive.setExportableAssets(Archive.Exportable_Assets.EXPORTABLE_APPRAISAL_NORMALIZED_ACQUISITIONED, assetsLocation);
} else if ("exportAppraised".equals(exportableAssets)){
System.out.println("exportableAssets = exportAppraised");
exportResult = archive.setExportableAssets(Archive.Exportable_Assets.EXPORTABLE_APPRAISAL_NORMALIZED_APPRAISED);
} else if ("exportProcessing".equals(exportableAssets)){
System.out.println("exportableAssets = exportProcessing");
exportResult = archive.setExportableAssets(Archive.Exportable_Assets.EXPORTABLE_PROCESSING_NORMALIZED);
} else if ("exportAccessionProcessing".equals(exportableAssets)){
System.out.println("exportableAssets = exportAccessionProcessing");
// Notes: assetsLocation here should be a list of folder paths
exportResult = archive.setExportableAssets(Archive.Exportable_Assets.EXPORTABLE_PROCESSING_NORMALIZED, assetsLocation);
} else if ("exportProcessed".equals(exportableAssets)){
System.out.println("exportableAssets = exportProcessed");
exportResult = archive.setExportableAssets(Archive.Exportable_Assets.EXPORTABLE_PROCESSING_NORMALIZED_PROCESSED);
}
if (!Util.nullOrEmpty(error)){
resultJSON.put("status", 1);
resultJSON.put("error", error);
} else {
resultJSON.put("status", 0);
resultJSON.put("responseText","Exportable assets are ready!");
}
}
%>

<%!
public void cancelGetNormalizedAsset(Consumer<StatusProvider> setStatusProvider){
}
%>

2 changes: 1 addition & 1 deletion WebContent/ajax/cancel.jsp
@@ -1,4 +1,4 @@
<!-- runs on server side -->
<%--<!-- runs on server side -->--%>
<%@page language="java" import="edu.stanford.muse.email.*"%>
<%@page language="java" import="edu.stanford.muse.webapp.*"%>
<%@ page import="edu.stanford.epadd.util.OperationInfo" %>
Expand Down
49 changes: 46 additions & 3 deletions WebContent/ajax/importAccession.jsp
Expand Up @@ -6,7 +6,7 @@
<%@page language="java" import="edu.stanford.muse.webapp.*"%>
<%@ page language="java" import="edu.stanford.muse.index.Archive"%>
<%@ page language="java" import="org.apache.commons.io.FileUtils"%>
<%@ page import="java.util.ArrayList"%><%@ page import="org.joda.time.DateTime"%><%@ page import="java.util.Enumeration"%><%@ page import="java.util.Set"%><%@ page import="java.util.LinkedHashSet"%><%@ page import="edu.stanford.muse.index.ArchiveReaderWriter"%>
<%@ page import="org.joda.time.DateTime"%><%@ page import="edu.stanford.muse.index.ArchiveReaderWriter"%><%@ page import="edu.stanford.muse.email.FetchStats"%><%@ page import="java.util.*"%><%@ page import="edu.stanford.muse.email.FolderInfo"%><%@ page import="edu.stanford.muse.util.Pair"%><%@ page import="org.apache.commons.lang.StringUtils"%>
<%
/* copies new accession into REPO_DIR and then loads it from there */
JSONObject result = new JSONObject();
Expand Down Expand Up @@ -60,6 +60,8 @@ if (!collectionDir.equals(baseDir))
//the report when a call to displaymergeReport.jsp is made with archiveID.
String accessionID=request.getParameter("accessionID");
Archive collection;
List<FetchStats> accessionAllStats = new ArrayList<FetchStats>();
if(new File(collectionDir).listFiles().length==0)//means collection directory is empty
{
// delete the existing directory -- Q: should we give user a warning??
Expand All @@ -75,8 +77,11 @@ if (!collectionDir.equals(baseDir))
//This information is present in blobstore so just get it from there.
collection.collectionMetadata.normalizedFiles=collection.getBlobStore().getNormalizedFilesCount();
collection.collectionMetadata.renamedFiles=collection.getBlobStore().getCleanedFilesCount();
accessionAllStats = collection.allStats; // for file metadata creation later
collection.collectionMetadata.fileMetadatas = null; // Erase all existing file metadatas as we will add back them into accession later
//IMP to write collection metadata back..
ArchiveReaderWriter.saveCollectionMetadata(collection.collectionMetadata,collection.baseDir);
ArchiveReaderWriter.saveCollectionMetadata(collection.collectionMetadata,collection.baseDir, null);
//accession id to each doc by saying that this is a baseAccessionID.
result.put("status", 0);
result.put ("message", "Import accession completed.");
Expand All @@ -86,6 +91,9 @@ if (!collectionDir.equals(baseDir))
//read archives present in basedir and collection dir.
collection = ArchiveReaderWriter.readArchiveIfPresent(collectionDir);
Archive accession = ArchiveReaderWriter.readArchiveIfPresent(baseDir);
accessionAllStats = accession.allStats; // Cache accession's allStatus before it is merged for file metadata creation later
//call merge on these archives..
Util.ASSERT(request.getParameter("accessionID")!=null);
//Merge result will be stored in a field of collection archive object. It will be used
Expand Down Expand Up @@ -136,6 +144,41 @@ if (!collectionDir.equals(baseDir))
Archive.CollectionMetadata cm = ArchiveReaderWriter.readCollectionMetadata (collectionDir);
if (cm == null)
cm = new Archive.CollectionMetadata();
Archive accession = ArchiveReaderWriter.readArchiveIfPresent(baseDir);
Archive.CollectionMetadata accession_cm = ArchiveReaderWriter.readCollectionMetadata (baseDir);
List<Archive.FileMetadata> accession_fms = accession_cm.fileMetadatas;
List<Archive.FileMetadata> fms = new ArrayList<Archive.FileMetadata>();
{
// we add the following code to support file metada requirement in epadd+ project
// All file metadatas in accession_fms would be copied into FileMetadatas fms, which is then stored in collection.
Archive.FileMetadata fm = new Archive.FileMetadata();;
int count = 0;
if (accession_fms!=null) {
for (Archive.FileMetadata accessionFM : accession_fms) {
fm = new Archive.FileMetadata();
fm.fileID = "" + am.id + "/File/" + StringUtils.leftPad(""+count, 4, "0");
fm.fileFormat = "MBOX";
fm.notes="";
// if (fm.selectedFolders != null) {
// for (Pair<String, FolderInfo> p : fs.selectedFolders){
// fm.filename = Util.escapeHTML(p.getFirst());
// break;
// }
// }
count ++;
fms.add(fm);
} // end for
} //end if (fetchStats!=null)
}
am.fileMetadatas = fms;
if (cm.accessionMetadatas == null)
cm.accessionMetadatas = new ArrayList<>();
cm.accessionMetadatas.add(am);
Expand All @@ -146,7 +189,7 @@ if (!collectionDir.equals(baseDir))
//the updated metadata on disc will be out of sync. It manifests when saving this archive which
//overwrites the latest on-disc PM data with stale in-memory data.
}
JSPHelper.log.info ("Accession metadata updated");
JSPHelper.log.info ("Accession metadata updated with imported file metadata");
}
} catch (Exception e) {
Expand Down
16 changes: 16 additions & 0 deletions WebContent/ajax/premis.jsp
@@ -0,0 +1,16 @@
<%@ page import="edu.stanford.muse.epaddpremis.EpaddEvent"%>
<%@ page import="edu.stanford.muse.epaddpremis.EpaddPremis"%>
<%@ page import="edu.stanford.muse.index.Archive"%>
<%@ page import="edu.stanford.muse.index.ArchiveReaderWriter"%><%@ page import="org.json.JSONObject"%><%@ page import="com.google.gson.Gson"%>
<%@page language="java" contentType="application/json;charset=UTF-8"%>

<%
String archiveID = request.getParameter("archiveID");
if (archiveID != null && !archiveID.isEmpty())
{
Archive archive = ArchiveReaderWriter.getArchiveForArchiveID(archiveID);
archive.getEpaddPremis().createEvent(new JSONObject(request.getParameter("premisdata")));
}
%>


4 changes: 2 additions & 2 deletions WebContent/ajax/updateAccessionMetadata.jsp
Expand Up @@ -11,7 +11,7 @@
JSONObject result = new JSONObject();
if (!ModeConfig.isProcessingMode()) {
result.put ("status", 1);
result.put ("errorMessage", "Updating collection metadata is allowed only in ePADD's Processing mode.");
result.put ("errorMessage", "Updating accession metadata is allowed only in ePADD's Processing mode.");
out.println (result.toString(4));
return;
}
Expand Down Expand Up @@ -71,7 +71,7 @@ try {
}
else{
//we only need to write the collection metadata without loading the archive. so it's fresh creation.
ArchiveReaderWriter.saveCollectionMetadata(cm, archiveBaseDir);
ArchiveReaderWriter.saveCollectionMetadata(cm, archiveBaseDir, null);
//for updating the checksum we need to first read the bag from the basedir..
Bag archiveBag=Archive.readArchiveBag(archiveBaseDir);
if(archiveBag==null)
Expand Down

0 comments on commit ca0b360

Please sign in to comment.