Changes for issues pertaining to file upload (correction of date for uploadDateTime), file replacement (changing label, etc.), and file deletion.
This commit is contained in:
parent
fd2676da55
commit
fa143a168b
6 changed files with 318 additions and 55 deletions
|
@ -8,6 +8,7 @@ import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
import java.security.MessageDigest;
|
import java.security.MessageDigest;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
@ -20,6 +21,7 @@ import javax.servlet.ServletContext;
|
||||||
import javax.servlet.ServletException;
|
import javax.servlet.ServletException;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import javax.servlet.http.HttpSession;
|
||||||
|
|
||||||
import org.apache.commons.fileupload.FileItem;
|
import org.apache.commons.fileupload.FileItem;
|
||||||
import org.apache.commons.fileupload.FileUploadException;
|
import org.apache.commons.fileupload.FileUploadException;
|
||||||
|
@ -27,8 +29,21 @@ import org.apache.commons.fileupload.disk.DiskFileItemFactory;
|
||||||
import org.apache.commons.fileupload.servlet.ServletFileUpload;
|
import org.apache.commons.fileupload.servlet.ServletFileUpload;
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
import org.joda.time.DateTime;
|
||||||
|
|
||||||
|
import com.hp.hpl.jena.datatypes.BaseDatatype;
|
||||||
|
import com.hp.hpl.jena.datatypes.xsd.XSDDatatype;
|
||||||
|
import com.hp.hpl.jena.datatypes.xsd.XSDDateTime;
|
||||||
|
import com.hp.hpl.jena.ontology.DatatypeProperty;
|
||||||
|
import com.hp.hpl.jena.ontology.ObjectProperty;
|
||||||
import com.hp.hpl.jena.ontology.OntModel;
|
import com.hp.hpl.jena.ontology.OntModel;
|
||||||
|
import com.hp.hpl.jena.vocabulary.RDF;
|
||||||
|
import com.hp.hpl.jena.vocabulary.RDFS;
|
||||||
|
import com.hp.hpl.jena.vocabulary.XSD;
|
||||||
|
import com.hp.hpl.jena.rdf.model.Statement;
|
||||||
|
import com.hp.hpl.jena.rdf.model.Model;
|
||||||
|
import com.hp.hpl.jena.rdf.model.Resource;
|
||||||
|
import com.ibm.icu.util.Calendar;
|
||||||
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.ConfigurationProperties;
|
import edu.cornell.mannlib.vitro.webapp.ConfigurationProperties;
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.DataProperty;
|
import edu.cornell.mannlib.vitro.webapp.beans.DataProperty;
|
||||||
|
@ -42,6 +57,9 @@ import fedora.client.FedoraClient;
|
||||||
import fedora.common.Constants;
|
import fedora.common.Constants;
|
||||||
import fedora.server.management.FedoraAPIM;
|
import fedora.server.management.FedoraAPIM;
|
||||||
import fedora.server.types.gen.Datastream;
|
import fedora.server.types.gen.Datastream;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.beans.ObjectPropertyStatement;
|
||||||
|
import edu.cornell.mannlib.vedit.beans.LoginFormBean;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles a request to change a datastream in a fedora repository.
|
* Handles a request to change a datastream in a fedora repository.
|
||||||
|
@ -62,13 +80,28 @@ public class FedoraDatastreamController extends VitroHttpServlet implements Cons
|
||||||
private boolean configured = false;
|
private boolean configured = false;
|
||||||
private boolean connected = false;
|
private boolean connected = false;
|
||||||
|
|
||||||
private static final int DEFAULT_MAX_SIZE = 1024 * 1024 * 50;
|
private static final int DEFAULT_MAX_SIZE = 1024 * 1024 * 50;//Shoudl this be changed to 1 GB to be consistent
|
||||||
private static final String DEFAULT_FILE_URI_PREFIX = "http://vivo.library.cornell.edu/ns/0.1#individual";
|
private static final String DEFAULT_FILE_URI_PREFIX = "http://vivo.library.cornell.edu/ns/0.1#individual";
|
||||||
private static final String DEFAULT_BASE_DIR = "/usr/local/vitrofiles";
|
private static final String DEFAULT_BASE_DIR = "/usr/local/vitrofiles";
|
||||||
private static String fileUriPrefix = DEFAULT_FILE_URI_PREFIX;
|
private static String fileUriPrefix = DEFAULT_FILE_URI_PREFIX;
|
||||||
private static String baseDirectoryForFiles = DEFAULT_BASE_DIR;
|
private static String baseDirectoryForFiles = DEFAULT_BASE_DIR;
|
||||||
private static int maxFileSize = DEFAULT_MAX_SIZE;
|
private static int maxFileSize = DEFAULT_MAX_SIZE;
|
||||||
|
|
||||||
|
protected String contentTypeProperty = VitroVocabulary.CONTENT_TYPE;
|
||||||
|
protected String fileSizeProperty = VitroVocabulary.FILE_SIZE;
|
||||||
|
protected String fileNameProperty = VitroVocabulary.FILE_NAME;
|
||||||
|
protected String fileLocationProperty = VitroVocabulary.FILE_LOCATION;
|
||||||
|
protected String fileLabelProperty = RDFS.label.getURI();
|
||||||
|
protected String checksumNodeProperty = "";//Object property linking file to check sum node object
|
||||||
|
protected String checksumNodeDateTimeProperty = "";
|
||||||
|
protected String checksumNodeValueProperty = "";
|
||||||
|
protected String checksumDataProperty = ""; //is there a vitro equivalent?
|
||||||
|
|
||||||
|
protected String deleteNs = "";
|
||||||
|
protected String individualPrefix = "";
|
||||||
|
protected String fedoraNs = VitroVocabulary.VITRO_FEDORA;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The get will present a form to the user.
|
* The get will present a form to the user.
|
||||||
*/
|
*/
|
||||||
|
@ -111,16 +144,18 @@ public class FedoraDatastreamController extends VitroHttpServlet implements Cons
|
||||||
if( req.getParameter("uri") == null || "".equals(req.getParameter("uri")))
|
if( req.getParameter("uri") == null || "".equals(req.getParameter("uri")))
|
||||||
throw new FdcException("No file uri specified in request");
|
throw new FdcException("No file uri specified in request");
|
||||||
|
|
||||||
String fileUri = req.getParameter("uri");
|
boolean isDelete = (req.getParameter("delete") != null && "true".equals(req.getParameter("delete")));
|
||||||
|
|
||||||
|
String fileUri = req.getParameter("uri");
|
||||||
//check if file individual has a fedora:PID for a data stream
|
//check if file individual has a fedora:PID for a data stream
|
||||||
IndividualDao iwDao = vreq.getWebappDaoFactory().getIndividualDao();
|
IndividualDao iwDao = vreq.getWebappDaoFactory().getIndividualDao();
|
||||||
Individual entity = iwDao.getIndividualByURI(fileUri);
|
Individual entity = iwDao.getIndividualByURI(fileUri);
|
||||||
|
|
||||||
if( entity == null )
|
if( entity == null )
|
||||||
throw new FdcException( "No entity found in system for file uri " + fileUri);
|
throw new FdcException( "No entity found in system for file uri " + fileUri);
|
||||||
|
//System.out.println("Entity == null:" + (entity == null));
|
||||||
//get the fedora PID
|
//get the fedora PID
|
||||||
|
//System.out.println("entity data property " + entity.getDataPropertyMap().get(VitroVocabulary.FEDORA_PID));
|
||||||
if( entity.getDataPropertyMap().get(VitroVocabulary.FEDORA_PID ) == null )
|
if( entity.getDataPropertyMap().get(VitroVocabulary.FEDORA_PID ) == null )
|
||||||
throw new FdcException( "No fedora:pid found in system for file uri " + fileUri);
|
throw new FdcException( "No fedora:pid found in system for file uri " + fileUri);
|
||||||
List<DataPropertyStatement> stmts = entity.getDataPropertyMap().get(VitroVocabulary.FEDORA_PID).getDataPropertyStatements();
|
List<DataPropertyStatement> stmts = entity.getDataPropertyMap().get(VitroVocabulary.FEDORA_PID).getDataPropertyStatements();
|
||||||
|
@ -133,11 +168,43 @@ public class FedoraDatastreamController extends VitroHttpServlet implements Cons
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
//System.out.println("pid is " + pid + " and comparison is " + (pid == null));
|
||||||
if( pid == null )
|
if( pid == null )
|
||||||
throw new FdcException( "No fedora:pid found in system for file uri " + fileUri);
|
throw new FdcException( "No fedora:pid found in system for file uri " + fileUri);
|
||||||
req.setAttribute("pid", pid);
|
req.setAttribute("pid", pid);
|
||||||
req.setAttribute("fileUri", fileUri);
|
req.setAttribute("fileUri", fileUri);
|
||||||
|
//get current file name to use on form
|
||||||
|
req.setAttribute("fileName", entity.getName());
|
||||||
|
|
||||||
|
if(isDelete)
|
||||||
|
{
|
||||||
|
//Execute a 'deletion', i.e. unlink dataset and file, without removing file
|
||||||
|
//Also save deletion as a deleteEvent entity which can later be queried
|
||||||
|
|
||||||
|
String datasetUri = null;
|
||||||
|
//Get dataset uri by getting the fromDataSet property
|
||||||
|
edu.cornell.mannlib.vitro.webapp.beans.ObjectProperty fromDataSet = entity.getObjectPropertyMap().get(fedoraNs + "fromDataSet");
|
||||||
|
if(fromDataSet != null)
|
||||||
|
{
|
||||||
|
List<ObjectPropertyStatement> fromDsStmts = fromDataSet.getObjectPropertyStatements();
|
||||||
|
if(fromDsStmts.size() > 0) {
|
||||||
|
datasetUri = fromDsStmts.get(0).getObjectURI();
|
||||||
|
//System.out.println("object uri should be " + datasetUri);
|
||||||
|
} else {
|
||||||
|
//System.out.println("No matching dataset uri could be found");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
//System.out.println("From dataset is null");
|
||||||
|
}
|
||||||
|
|
||||||
|
req.setAttribute("dataseturi", datasetUri);
|
||||||
|
boolean success = deleteFile(req, entity, iwDao, sessionOntModel);
|
||||||
|
req.setAttribute("deletesuccess", (success)?"success":"error");
|
||||||
|
req.setAttribute("bodyJsp", "/edit/fileDeleteConfirm.jsp");
|
||||||
|
RequestDispatcher rd = req.getRequestDispatcher(Controllers.BASIC_JSP);
|
||||||
|
rd.forward(req, res);
|
||||||
|
}
|
||||||
|
else{
|
||||||
//check if the data stream exists in the fedora repository
|
//check if the data stream exists in the fedora repository
|
||||||
Datastream ds = apim.getDatastream(pid,DEFAULT_DSID,null);
|
Datastream ds = apim.getDatastream(pid,DEFAULT_DSID,null);
|
||||||
if( ds == null )
|
if( ds == null )
|
||||||
|
@ -145,13 +212,13 @@ public class FedoraDatastreamController extends VitroHttpServlet implements Cons
|
||||||
"repository for " + pid + " " + DEFAULT_DSID);
|
"repository for " + pid + " " + DEFAULT_DSID);
|
||||||
req.setAttribute("dsid", DEFAULT_DSID);
|
req.setAttribute("dsid", DEFAULT_DSID);
|
||||||
|
|
||||||
//get current file name to use on form
|
|
||||||
req.setAttribute("fileName", entity.getName());
|
|
||||||
|
|
||||||
//forward to form
|
//forward to form
|
||||||
req.setAttribute("bodyJsp","/fileupload/datastreamModification.jsp");
|
req.setAttribute("bodyJsp","/fileupload/datastreamModification.jsp");
|
||||||
RequestDispatcher rd = req.getRequestDispatcher(Controllers.BASIC_JSP);
|
RequestDispatcher rd = req.getRequestDispatcher(Controllers.BASIC_JSP);
|
||||||
rd.forward(req, res);
|
rd.forward(req, res);
|
||||||
|
}
|
||||||
}catch(FdcException ex){
|
}catch(FdcException ex){
|
||||||
req.setAttribute("errors", ex.getMessage());
|
req.setAttribute("errors", ex.getMessage());
|
||||||
RequestDispatcher rd = req.getRequestDispatcher("/edit/fileUploadError.jsp");
|
RequestDispatcher rd = req.getRequestDispatcher("/edit/fileUploadError.jsp");
|
||||||
|
@ -249,7 +316,7 @@ public class FedoraDatastreamController extends VitroHttpServlet implements Cons
|
||||||
fileUri = queryParameters.get("fileUri").get(0);
|
fileUri = queryParameters.get("fileUri").get(0);
|
||||||
}
|
}
|
||||||
boolean useNewName=false;
|
boolean useNewName=false;
|
||||||
if( "true".equals(queryParameters.get("useNewName"))){
|
if( "true".equals(queryParameters.get("useNewName"))){System.out.println("Use new name parameter is true");
|
||||||
useNewName = true;
|
useNewName = true;
|
||||||
}
|
}
|
||||||
if( pId == null || pId.length() == 0 )
|
if( pId == null || pId.length() == 0 )
|
||||||
|
@ -308,6 +375,9 @@ public class FedoraDatastreamController extends VitroHttpServlet implements Cons
|
||||||
}
|
}
|
||||||
|
|
||||||
File uploadedFile = new File(saveLocation);
|
File uploadedFile = new File(saveLocation);
|
||||||
|
//System.out.println("Uploaded file path " + uploadedFile.getPath() + " - get file?" + uploadedFile.getName());
|
||||||
|
String uploadedFileLocation = uploadedFile.getAbsolutePath();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
fileRes.write(uploadedFile);
|
fileRes.write(uploadedFile);
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
|
@ -319,7 +389,7 @@ public class FedoraDatastreamController extends VitroHttpServlet implements Cons
|
||||||
//upload to temp area on fedora
|
//upload to temp area on fedora
|
||||||
File file = new File(saveLocation);
|
File file = new File(saveLocation);
|
||||||
String uploadFileUri = fedora.uploadFile( file );
|
String uploadFileUri = fedora.uploadFile( file );
|
||||||
|
// System.out.println("Fedora upload temp = upload file uri is " + uploadFileUri);
|
||||||
String md5 = md5hashForFile( file );
|
String md5 = md5hashForFile( file );
|
||||||
md5 = md5.toLowerCase();
|
md5 = md5.toLowerCase();
|
||||||
|
|
||||||
|
@ -337,36 +407,126 @@ public class FedoraDatastreamController extends VitroHttpServlet implements Cons
|
||||||
//update properties like checksum, file size, and content type
|
//update properties like checksum, file size, and content type
|
||||||
|
|
||||||
WebappDaoFactory wdf = vreq.getWebappDaoFactory();
|
WebappDaoFactory wdf = vreq.getWebappDaoFactory();
|
||||||
|
DataPropertyStatement dps = null;
|
||||||
DataProperty contentType = wdf.getDataPropertyDao().getDataPropertyByURI(VitroVocabulary.CONTENT_TYPE);
|
DataProperty contentType = wdf.getDataPropertyDao().getDataPropertyByURI(this.contentTypeProperty);
|
||||||
|
if(contentType != null)
|
||||||
|
{
|
||||||
|
System.out.println("Setting content type to " + fileRes.getContentType());
|
||||||
wdf.getDataPropertyStatementDao().deleteDataPropertyStatementsForIndividualByDataProperty(fileEntity, contentType);
|
wdf.getDataPropertyStatementDao().deleteDataPropertyStatementsForIndividualByDataProperty(fileEntity, contentType);
|
||||||
DataPropertyStatement dps = new DataPropertyStatementImpl();
|
dps = new DataPropertyStatementImpl();
|
||||||
dps.setIndividualURI(fileEntity.getURI());
|
dps.setIndividualURI(fileEntity.getURI());
|
||||||
dps.setDatapropURI(VitroVocabulary.CONTENT_TYPE);
|
dps.setDatapropURI(VitroVocabulary.CONTENT_TYPE);
|
||||||
dps.setData(fileRes.getContentType());
|
dps.setData(fileRes.getContentType());
|
||||||
wdf.getDataPropertyStatementDao().insertNewDataPropertyStatement(dps);
|
wdf.getDataPropertyStatementDao().insertNewDataPropertyStatement(dps);
|
||||||
|
}
|
||||||
|
|
||||||
DataProperty fileSize = wdf.getDataPropertyDao().getDataPropertyByURI(VitroVocabulary.FILE_SIZE);
|
DataProperty fileSize = wdf.getDataPropertyDao().getDataPropertyByURI(this.fileSizeProperty);
|
||||||
|
if(fileSize != null)
|
||||||
|
{
|
||||||
wdf.getDataPropertyStatementDao().deleteDataPropertyStatementsForIndividualByDataProperty(fileEntity, fileSize);
|
wdf.getDataPropertyStatementDao().deleteDataPropertyStatementsForIndividualByDataProperty(fileEntity, fileSize);
|
||||||
dps = new DataPropertyStatementImpl();
|
dps = new DataPropertyStatementImpl();
|
||||||
dps.setIndividualURI(fileEntity.getURI());
|
dps.setIndividualURI(fileEntity.getURI());
|
||||||
dps.setDatapropURI(VitroVocabulary.FILE_SIZE);
|
dps.setDatapropURI(VitroVocabulary.FILE_SIZE);
|
||||||
dps.setData(Long.toString(fileRes.getSize()));
|
dps.setData(Long.toString(fileRes.getSize()));
|
||||||
wdf.getDataPropertyStatementDao().insertNewDataPropertyStatement(dps);
|
wdf.getDataPropertyStatementDao().insertNewDataPropertyStatement(dps);
|
||||||
|
//System.out.println("Updated file size with " + fileRes.getSize());
|
||||||
|
}
|
||||||
|
|
||||||
DataProperty checksumDp = wdf.getDataPropertyDao().getDataPropertyByURI("http://datastar.mannlib.cornell.edu/ns/core/0.1#checksum");
|
DataProperty checksumDp = wdf.getDataPropertyDao().getDataPropertyByURI(this.checksumDataProperty);
|
||||||
//DataProperty checksumDp = wdf.getDataPropertyDao().getDataPropertyByURI(DataStarVocabulary.CHECSUM);
|
if(checksumDp != null)
|
||||||
|
{
|
||||||
|
//System.out.println("Checksum data property is also not null");
|
||||||
wdf.getDataPropertyStatementDao().deleteDataPropertyStatementsForIndividualByDataProperty(fileEntity, checksumDp);
|
wdf.getDataPropertyStatementDao().deleteDataPropertyStatementsForIndividualByDataProperty(fileEntity, checksumDp);
|
||||||
dps = new DataPropertyStatementImpl();
|
dps = new DataPropertyStatementImpl();
|
||||||
dps.setIndividualURI(fileEntity.getURI());
|
dps.setIndividualURI(fileEntity.getURI());
|
||||||
dps.setDatapropURI(checksumDp.getURI());
|
dps.setDatapropURI(checksumDp.getURI());
|
||||||
dps.setData(checksum);
|
dps.setData(checksum);
|
||||||
wdf.getDataPropertyStatementDao().insertNewDataPropertyStatement(dps);
|
wdf.getDataPropertyStatementDao().insertNewDataPropertyStatement(dps);
|
||||||
|
}
|
||||||
|
|
||||||
// entDao().insertNewDataPropertyStatement(dps);
|
//I'm leaving if statement out for now as the above properties are obviously being replaced as well
|
||||||
//if user checked "use name of new file" and maybe change the rdfs:label
|
//if( "true".equals(useNewName)){
|
||||||
|
//Do we need to encapuslate in this if OR is this path always for replacing a file
|
||||||
|
//TODO: Put in check to see if file name has changed and only execute these statements if file name has changed
|
||||||
|
DataProperty fileNameProperty = wdf.getDataPropertyDao().getDataPropertyByURI(this.fileNameProperty);
|
||||||
|
if(fileNameProperty != null) {
|
||||||
|
wdf.getDataPropertyStatementDao().deleteDataPropertyStatementsForIndividualByDataProperty(fileEntity, fileNameProperty);
|
||||||
|
dps = new DataPropertyStatementImpl();
|
||||||
|
dps.setIndividualURI(fileEntity.getURI());
|
||||||
|
dps.setDatapropURI(fileNameProperty.getURI());
|
||||||
|
dps.setData(originalName); //This follows the pattern of the original file upload - the name returned from the uploaded file object
|
||||||
|
wdf.getDataPropertyStatementDao().insertNewDataPropertyStatement(dps);
|
||||||
|
//System.out.println("File name property is not null = " + fileNameProperty.getURI() + " updating to " + originalName);
|
||||||
|
} else {
|
||||||
|
//System.out.println("file name property is null");
|
||||||
|
}
|
||||||
|
|
||||||
|
//This doesn't seem to be settable as a data property - how else could we set this?
|
||||||
|
/*
|
||||||
|
DataProperty fileLocationProperty = wdf.getDataPropertyDao().getDataPropertyByURI(this.fileLocationProperty);
|
||||||
|
if(fileLocationProperty != null) {
|
||||||
|
wdf.getDataPropertyStatementDao().deleteDataPropertyStatementsForIndividualByDataProperty(fileEntity, fileLocationProperty);
|
||||||
|
dps = new DataPropertyStatementImpl();
|
||||||
|
dps.setIndividualURI(fileEntity.getURI());
|
||||||
|
dps.setDatapropURI(fileLocationProperty.getURI());
|
||||||
|
dps.setData(saveLocation); //This follows the pattern of the original file upload - the name returned from the uploaded file object
|
||||||
|
wdf.getDataPropertyStatementDao().insertNewDataPropertyStatement(dps);
|
||||||
|
} else {
|
||||||
|
System.out.println("File location property is null");
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
//Need to also update the check sum node - how would we do that
|
||||||
|
//Find checksum node related to this particular file uri, then go ahead and update two specific fields
|
||||||
|
//ObjectProperty checksumNode = wdf.getObjectPropertyDao().getObjectPropertyByURI(this.checksumNodeProperty);
|
||||||
|
//if(checksumNode != null) {
|
||||||
|
// System.out.println("Check sum node is not equal to null");
|
||||||
|
// fileEntity.
|
||||||
|
//}
|
||||||
|
List<ObjectPropertyStatement >csNodeStatements = fileEntity.getObjectPropertyMap().get(this.checksumNodeProperty).getObjectPropertyStatements();
|
||||||
|
if(csNodeStatements.size() == 0) {
|
||||||
|
System.out.println("No object property statements correspond to this property");
|
||||||
|
} else {
|
||||||
|
ObjectPropertyStatement cnodeStatement = csNodeStatements.get(0);
|
||||||
|
String cnodeUri = cnodeStatement.getObjectURI();
|
||||||
|
//System.out.println("Checksum node uri is " + cnodeUri);
|
||||||
|
|
||||||
|
Individual checksumNodeObject = iwDao.getIndividualByURI(cnodeUri);
|
||||||
|
|
||||||
|
DataProperty checksumDateTime = wdf.getDataPropertyDao().getDataPropertyByURI(this.checksumNodeDateTimeProperty);
|
||||||
|
if(checksumDateTime != null) {
|
||||||
|
String newDatetime = sessionOntModel.createTypedLiteral(new DateTime()).getString();
|
||||||
|
//Review how to update date time
|
||||||
|
wdf.getDataPropertyStatementDao().deleteDataPropertyStatementsForIndividualByDataProperty(checksumNodeObject, checksumDateTime);
|
||||||
|
dps = new DataPropertyStatementImpl();
|
||||||
|
dps.setIndividualURI(checksumNodeObject.getURI());
|
||||||
|
dps.setDatapropURI(checksumDateTime.getURI());
|
||||||
|
dps.setData(newDatetime);
|
||||||
|
wdf.getDataPropertyStatementDao().insertNewDataPropertyStatement(dps);
|
||||||
|
|
||||||
|
}
|
||||||
|
DataProperty checksumNodeValue = wdf.getDataPropertyDao().getDataPropertyByURI(this.checksumDataProperty);
|
||||||
|
if(checksumNodeValue != null) {
|
||||||
|
wdf.getDataPropertyStatementDao().deleteDataPropertyStatementsForIndividualByDataProperty(checksumNodeObject, checksumNodeValue);
|
||||||
|
dps = new DataPropertyStatementImpl();
|
||||||
|
dps.setIndividualURI(checksumNodeObject.getURI());
|
||||||
|
dps.setDatapropURI(checksumNodeValue.getURI());
|
||||||
|
dps.setData(checksum); //Same as fileName above - change if needed
|
||||||
|
wdf.getDataPropertyStatementDao().insertNewDataPropertyStatement(dps);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//Assumes original entity name is equal to the location - as occurs with regular file upload
|
||||||
|
String originalEntityName = fileEntity.getName();
|
||||||
|
if(originalEntityName != originalName) {
|
||||||
|
//System.out.println("Setting file entity to name of uploaded file");
|
||||||
|
fileEntity.setName(originalName);
|
||||||
|
} else {
|
||||||
|
//System.out.println("Conditional for file entity name and uploaded name is saying same");
|
||||||
|
}
|
||||||
|
iwDao.updateIndividual(fileEntity);
|
||||||
|
//}
|
||||||
|
|
||||||
req.setAttribute("fileUri", fileUri);
|
req.setAttribute("fileUri", fileUri);
|
||||||
req.setAttribute("originalFileName", fileEntity.getName());
|
req.setAttribute("originalFileName", fileEntity.getName());
|
||||||
|
@ -390,6 +550,86 @@ public class FedoraDatastreamController extends VitroHttpServlet implements Cons
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Delete method
|
||||||
|
public boolean deleteFile(HttpServletRequest req, Individual entity, IndividualDao iwDao, OntModel sessionOntModel) {
|
||||||
|
boolean success = false;
|
||||||
|
String fileUri = entity.getURI();
|
||||||
|
//Create uri based on milliseconds etc.?
|
||||||
|
Calendar c = Calendar.getInstance();
|
||||||
|
long timeMs = c.getTimeInMillis();
|
||||||
|
//Cuirrent date
|
||||||
|
SimpleDateFormat dateTime = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS");
|
||||||
|
String formattedDeleteDate = dateTime.format(c.getTime());
|
||||||
|
String deleteEventName = "deleteEvent" + timeMs;
|
||||||
|
//System.out.println("Delete event name is " +deleteEventName + " - delete time is " + formattedDeleteDate);
|
||||||
|
|
||||||
|
//Get current user
|
||||||
|
HttpSession session = req.getSession(true);
|
||||||
|
LoginFormBean loginBean = (LoginFormBean) session.getAttribute("loginHandler");
|
||||||
|
String userURI = loginBean.getUserURI();
|
||||||
|
//System.out.println("Current logged in user uri is " + userURI);
|
||||||
|
|
||||||
|
//Update model
|
||||||
|
sessionOntModel.enterCriticalSection(true);
|
||||||
|
|
||||||
|
try {
|
||||||
|
|
||||||
|
//Dataset Uri
|
||||||
|
String datasetUri = (String) req.getAttribute("dataseturi");
|
||||||
|
//System.out.println("Dataset uri is " + datasetUri);
|
||||||
|
//Remove the actual relationships: dsr:hasFile and fedora:fromDataSet
|
||||||
|
ObjectProperty hasFileProperty = sessionOntModel.getObjectProperty(fedoraNs + "hasFile");
|
||||||
|
|
||||||
|
ObjectProperty fromDatasetProperty = sessionOntModel.getObjectProperty(fedoraNs + "fromDataSet");
|
||||||
|
if(hasFileProperty != null) {
|
||||||
|
//System.out.println("Has file property does exist");
|
||||||
|
sessionOntModel.remove(sessionOntModel.createStatement(sessionOntModel.getResource(datasetUri), hasFileProperty, sessionOntModel.getResource(fileUri)));
|
||||||
|
} else{
|
||||||
|
//System.out.println("Has file property does not exist");
|
||||||
|
}
|
||||||
|
|
||||||
|
if(fromDatasetProperty != null) {
|
||||||
|
//System.out.println("From dataset property exists ");
|
||||||
|
sessionOntModel.remove(sessionOntModel.createStatement(sessionOntModel.getResource(fileUri), fromDatasetProperty, sessionOntModel.getResource(datasetUri)));
|
||||||
|
} else{
|
||||||
|
//System.out.println("From dataset property does not exist");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//Create delete event entity and update with the correct information
|
||||||
|
//Type of Event
|
||||||
|
Resource deleteEventType = sessionOntModel.createResource(deleteNs + "DeleteEvent");
|
||||||
|
//Individual event
|
||||||
|
Resource eventIndividual = sessionOntModel.createResource(individualPrefix + deleteEventName);
|
||||||
|
//Event is of type DeleteEvent
|
||||||
|
Statement rType = sessionOntModel.createStatement(eventIndividual, com.hp.hpl.jena.vocabulary.RDF.type, deleteEventType);
|
||||||
|
sessionOntModel.add(rType);
|
||||||
|
//Add properties to individual - deleteDateTime, deletedBy, forDataSet, forFile
|
||||||
|
DatatypeProperty dateTimeProp = sessionOntModel.createDatatypeProperty(deleteNs + "deleteDateTime");
|
||||||
|
dateTimeProp.setRange(XSD.dateTime);
|
||||||
|
|
||||||
|
ObjectProperty deletedByProp = sessionOntModel.createObjectProperty(deleteNs + "deletedBy");
|
||||||
|
ObjectProperty forDatasetProp = sessionOntModel.createObjectProperty(deleteNs + "forDataset");
|
||||||
|
ObjectProperty forFileProp = sessionOntModel.createObjectProperty(deleteNs + "forFile");
|
||||||
|
//Need to make sure date time property is set to correct xsd:DateTime
|
||||||
|
//XSDDateTime now = new XSDDateTime(c);
|
||||||
|
//XSDDateTime now = new XSDDateTime(java.util.Calendar.getInstance());
|
||||||
|
eventIndividual.addProperty(dateTimeProp, sessionOntModel.createTypedLiteral(formattedDeleteDate, XSDDatatype.XSDdateTime));
|
||||||
|
//eventIndividual.addProperty(dateTimeProp, sessionOntModel.createTypedLiteral(now, XSDDatatype.XSDdateTime));
|
||||||
|
eventIndividual.addProperty(deletedByProp, sessionOntModel.getResource(userURI));
|
||||||
|
if(datasetUri != null){
|
||||||
|
//System.out.println("Dataset uri is " + datasetUri);
|
||||||
|
eventIndividual.addProperty(forDatasetProp, sessionOntModel.getResource(datasetUri));
|
||||||
|
}
|
||||||
|
eventIndividual.addProperty(forFileProp, sessionOntModel.getResource(fileUri));
|
||||||
|
success = true;
|
||||||
|
|
||||||
|
} finally {
|
||||||
|
sessionOntModel.leaveCriticalSection();
|
||||||
|
}
|
||||||
|
return success;
|
||||||
|
}
|
||||||
|
|
||||||
public void init() throws ServletException {
|
public void init() throws ServletException {
|
||||||
super.init();
|
super.init();
|
||||||
|
|
||||||
|
|
|
@ -224,7 +224,7 @@ public class N3MultiPartUpload extends VitroHttpServlet {
|
||||||
: "request is for a new file object");
|
: "request is for a new file object");
|
||||||
/** *************************************************** */
|
/** *************************************************** */
|
||||||
String uploadFileName = "";
|
String uploadFileName = "";
|
||||||
if (requestIsAnUpdate) {System.out.println("Currently existing file resource edit not supported");
|
if (requestIsAnUpdate) {
|
||||||
log.error("Editing an existing file resource is not supported by N3MultiPartUpload.java ");
|
log.error("Editing an existing file resource is not supported by N3MultiPartUpload.java ");
|
||||||
request.setAttribute("errors", "Editing an existing file resource is not supported.");
|
request.setAttribute("errors", "Editing an existing file resource is not supported.");
|
||||||
RequestDispatcher rd = request
|
RequestDispatcher rd = request
|
||||||
|
@ -260,6 +260,11 @@ public class N3MultiPartUpload extends VitroHttpServlet {
|
||||||
+ requiredFieldAssertions.get(fileItemKey));
|
+ requiredFieldAssertions.get(fileItemKey));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
//DEBUG
|
||||||
|
System.out.println("build assertions for field "
|
||||||
|
+ fileItemKey + " and file "
|
||||||
|
+ fileItem.getName() + "\n"
|
||||||
|
+ requiredFieldAssertions.get(fileItemKey));
|
||||||
//Save upload file name for use in email confirmation
|
//Save upload file name for use in email confirmation
|
||||||
uploadFileName = fileItem.getName();
|
uploadFileName = fileItem.getName();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
@ -296,6 +301,12 @@ public class N3MultiPartUpload extends VitroHttpServlet {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//DEBUG to see what statements are being added
|
||||||
|
StmtIterator it = assertionModel.listStatements();
|
||||||
|
while(it.hasNext()){
|
||||||
|
System.out.println("NEXT Statement:" + it.nextStatement().toString() );
|
||||||
|
}
|
||||||
|
|
||||||
/* ****** do PostUpload if there is one ******* */
|
/* ****** do PostUpload if there is one ******* */
|
||||||
boolean postUploadSuccess = false;
|
boolean postUploadSuccess = false;
|
||||||
if (postUpload != null) {
|
if (postUpload != null) {
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||||
|
|
||||||
package edu.cornell.mannlib.vitro.webapp.edit.n3editing;
|
package edu.cornell.mannlib.vitro.webapp.edit.n3editing;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
@ -8,6 +9,7 @@ import java.util.Iterator;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Calendar;
|
||||||
|
|
||||||
import javax.servlet.ServletContext;
|
import javax.servlet.ServletContext;
|
||||||
import javax.servlet.ServletRequest;
|
import javax.servlet.ServletRequest;
|
||||||
|
@ -32,6 +34,9 @@ import edu.cornell.mannlib.vitro.webapp.auth.identifier.UserToIndIdentifierFacto
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.DataPropertyStatement;
|
import edu.cornell.mannlib.vitro.webapp.beans.DataPropertyStatement;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
|
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
|
||||||
import edu.cornell.mannlib.vitro.webapp.edit.EditLiteral;
|
import edu.cornell.mannlib.vitro.webapp.edit.EditLiteral;
|
||||||
|
import com.hp.hpl.jena.datatypes.xsd.XSDDatatype;
|
||||||
|
import com.hp.hpl.jena.datatypes.xsd.XSDDateTime;
|
||||||
|
import com.hp.hpl.jena.datatypes.BaseDatatype;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a set of fields on a form and how parameters from a from
|
* Represents a set of fields on a form and how parameters from a from
|
||||||
|
@ -224,7 +229,12 @@ public class EditConfiguration {
|
||||||
if( getSparqlForAdditionalLiteralsInScope() != null &&
|
if( getSparqlForAdditionalLiteralsInScope() != null &&
|
||||||
getSparqlForAdditionalLiteralsInScope().containsKey("currentTime") &&
|
getSparqlForAdditionalLiteralsInScope().containsKey("currentTime") &&
|
||||||
USE_SYSTEM_VALUE.equals(getSparqlForAdditionalLiteralsInScope().get("currentTime"))){
|
USE_SYSTEM_VALUE.equals(getSparqlForAdditionalLiteralsInScope().get("currentTime"))){
|
||||||
getLiteralsInScope().put("currentTime", ResourceFactory.createTypedLiteral(new Date()));
|
//Updating so that this is represented as an XSD Date Time literal - to allow for comparison later
|
||||||
|
//Currently it appears that this is only used for file upload
|
||||||
|
//getLiteralsInScope().put("currentTime", ResourceFactory.createTypedLiteral(new Date()));
|
||||||
|
SimpleDateFormat dateTime = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
|
||||||
|
String formattedDate = dateTime.format(Calendar.getInstance().getTime());
|
||||||
|
getLiteralsInScope().put("currentTime", ResourceFactory.createTypedLiteral(formattedDate, XSDDatatype.XSDdateTime));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* editing user */
|
/* editing user */
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
<input type="hidden" name="fileUri" value="${fileUri}"/>
|
<input type="hidden" name="fileUri" value="${fileUri}"/>
|
||||||
<input type="hidden" name="pid" value="${pid}"/>
|
<input type="hidden" name="pid" value="${pid}"/>
|
||||||
<input type="hidden" name="dsid" value="${dsid}"/>
|
<input type="hidden" name="dsid" value="${dsid}"/>
|
||||||
|
<!--Adding use new name set to true so that it is overwritten correctly-->
|
||||||
|
<input type="hidden" name="useNewName" value="true"/>
|
||||||
<input type="submit" id="submit" value="submit" />
|
<input type="submit" id="submit" value="submit" />
|
||||||
</form>
|
</form>
|
||||||
|
|
|
@ -6,7 +6,8 @@
|
||||||
<h3>Reports</h3>
|
<h3>Reports</h3>
|
||||||
|
|
||||||
<ul>
|
<ul>
|
||||||
<li><a href="customsparql">Custom Report: File Publication Date < 1 YEAR AGO</a></li>
|
<li><a href="customsparql?queryType=fileupload">Custom Report: File Publication Date > 1 YEAR AGO</a></li>
|
||||||
|
<li><a href="customsparql?queryType=filedelete">Custom Report: File Deleted > 1 YEAR AGO</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
<% } %>
|
<% } %>
|
||||||
|
|
Loading…
Add table
Reference in a new issue