diff --git a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/controller/FedoraDatastreamController.java b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/controller/FedoraDatastreamController.java deleted file mode 100644 index 110f6f873..000000000 --- a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/controller/FedoraDatastreamController.java +++ /dev/null @@ -1,713 +0,0 @@ -/* $This file is distributed under the terms of the license in /doc/license.txt$ */ - -package edu.cornell.mannlib.vitro.webapp.controller; - -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.io.InputStream; -import java.net.MalformedURLException; -import java.security.MessageDigest; -import java.text.SimpleDateFormat; -import java.util.List; -import java.util.Properties; - -import javax.servlet.ServletContext; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -import edu.cornell.mannlib.vitro.webapp.utils.JSPPageHandler; -import org.apache.commons.fileupload.FileItem; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.joda.time.DateTime; - -import org.apache.jena.datatypes.xsd.XSDDatatype; -import org.apache.jena.ontology.DatatypeProperty; -import org.apache.jena.ontology.ObjectProperty; -import org.apache.jena.ontology.OntModel; -import org.apache.jena.rdf.model.Resource; -import org.apache.jena.rdf.model.Statement; -import org.apache.jena.vocabulary.RDFS; -import org.apache.jena.vocabulary.XSD; -import com.ibm.icu.util.Calendar; - -import edu.cornell.mannlib.vedit.beans.LoginStatusBean; -import edu.cornell.mannlib.vitro.webapp.beans.DataProperty; -import edu.cornell.mannlib.vitro.webapp.beans.DataPropertyStatement; -import edu.cornell.mannlib.vitro.webapp.beans.DataPropertyStatementImpl; -import edu.cornell.mannlib.vitro.webapp.beans.Individual; -import edu.cornell.mannlib.vitro.webapp.beans.ObjectPropertyStatement; -import edu.cornell.mannlib.vitro.webapp.config.ConfigurationProperties; -import edu.cornell.mannlib.vitro.webapp.dao.IndividualDao; -import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary; -import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory; -import edu.cornell.mannlib.vitro.webapp.modelaccess.ModelAccess; -import fedora.client.FedoraClient; -import fedora.common.Constants; -import fedora.server.management.FedoraAPIM; -import fedora.server.types.gen.Datastream; - - -/** - * Handles a request to change a datastream in a fedora repository. - * Some of this code is copied from N3MultiPartUpload.java - * - * @author bdc34 - * - */ -public class FedoraDatastreamController extends VitroHttpServlet implements Constants{ - private static String FEDORA_PROPERTIES = "/WEB-INF/fedora.properties"; - private static String DEFAULT_DSID = "DS1"; - - private String fedoraUrl = null; - private String adminUser = null; - private String adminPassword = null; - private String pidNamespace = null; - private String configurationStatus = "

Fedora configuration not yet loaded

"; - private boolean configured = false; - private boolean connected = false; - - 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_BASE_DIR = "/usr/local/vitrofiles"; - private static String baseDirectoryForFiles = DEFAULT_BASE_DIR; - 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. - */ - @Override - public void doGet(HttpServletRequest req, HttpServletResponse res) - throws IOException, ServletException { - try { - super.doGet(req, res); - log.debug("In doGet"); - - VitroRequest vreq = new VitroRequest(req); - OntModel sessionOntModel = ModelAccess.on(getServletContext()).getOntModel(); - - synchronized (FedoraDatastreamController.class) { - if( fedoraUrl == null ){ - setup( sessionOntModel, getServletContext() ); - if( fedoraUrl == null ) - throw new FdcException("Connection to the file repository is " + - "not setup correctly. Could not read fedora.properties file"); - }else{ - if( !canConnectToFedoraServer() ){ - fedoraUrl = null; - throw new FdcException("Could not connect to Fedora."); - } - } - } - FedoraClient fedora; - try { fedora = new FedoraClient(fedoraUrl,adminUser,adminPassword); } - catch (MalformedURLException e) { - throw new FdcException("Malformed URL for fedora Repository location: " + fedoraUrl); - } - - FedoraAPIM apim; - try { apim = fedora.getAPIM(); } catch (Exception e) { - throw new FdcException("could not create fedora APIM:" + e.getMessage()); - } - - //check if logged in - - //get URI for file individual - if( req.getParameter("uri") == null || "".equals(req.getParameter("uri"))) - throw new FdcException("No file uri specified in request"); - - 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 - IndividualDao iwDao = vreq.getWebappDaoFactory().getIndividualDao(); - Individual entity = iwDao.getIndividualByURI(fileUri); - - - - if( entity == null ) - throw new FdcException( "No entity found in system for file uri " + fileUri); - //System.out.println("Entity == null:" + (entity == null)); - //get the fedora PID - //System.out.println("entity data property " + entity.getDataPropertyMap().get(VitroVocabulary.FEDORA_PID)); - if( entity.getDataPropertyMap().get(VitroVocabulary.FEDORA_PID ) == null ) - throw new FdcException( "No fedora:pid found in system for file uri " + fileUri); - List stmts = entity.getDataPropertyMap().get(VitroVocabulary.FEDORA_PID).getDataPropertyStatements(); - if( stmts == null || stmts.size() == 0) - throw new FdcException( "No fedora:pid found in system for file uri " + fileUri); - String pid = null; - for(DataPropertyStatement stmt : stmts){ - if( stmt.getData() != null && stmt.getData().length() > 0){ - pid = stmt.getData(); - break; - } - } - //System.out.println("pid is " + pid + " and comparison is " + (pid == null)); - if( pid == null ) - throw new FdcException( "No fedora:pid found in system for file uri " + fileUri); - req.setAttribute("pid", pid); - 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 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"); - JSPPageHandler.renderBasicPage(req, res, "/edit/fileDeleteConfirm.jsp"); - } - else{ - //check if the data stream exists in the fedora repository - Datastream ds = apim.getDatastream(pid,DEFAULT_DSID,null); - if( ds == null ) - throw new FdcException("There was no datastream in the " + - "repository for " + pid + " " + DEFAULT_DSID); - req.setAttribute("dsid", DEFAULT_DSID); - - - - //forward to form - JSPPageHandler.renderBasicPage(req, res, "/fileupload/datastreamModification.jsp"); - } - }catch(FdcException ex){ - req.setAttribute("errors", ex.getMessage()); - JSPPageHandler.renderPlainPage(req, res, "/edit/fileUploadError.jsp"); - return; - } - } - - @Override - public long maximumMultipartFileSize() { - return maxFileSize; - } - - @Override - public boolean stashFileSizeException() { - return true; - } - - @Override - public void doPost(HttpServletRequest rawRequest, HttpServletResponse res) - throws ServletException, IOException { - try{ - VitroRequest req = new VitroRequest(rawRequest); - if (req.hasFileSizeException()) { - throw new FdcException("Size limit exceeded: " + req.getFileSizeException().getLocalizedMessage()); - } - if (!req.isMultipart()) { - throw new FdcException("Must POST a multipart encoded request"); - } - - //check if fedora is on line - OntModel sessionOntModel = ModelAccess.on(getServletContext()).getOntModel(); - synchronized (FedoraDatastreamController.class) { - if( fedoraUrl == null ){ - setup( sessionOntModel, getServletContext() ); - if( fedoraUrl == null ) - throw new FdcException("Connection to the file repository is " + - "not setup correctly. Could not read fedora.properties file"); - }else{ - if( !canConnectToFedoraServer() ){ - fedoraUrl = null; - throw new FdcException("Could not connect to Fedora."); - } - } - } - FedoraClient fedora; - try { fedora = new FedoraClient(fedoraUrl,adminUser,adminPassword); } - catch (MalformedURLException e) { - throw new FdcException("Malformed URL for fedora Repository location: " + fedoraUrl); - } - FedoraAPIM apim; - try { apim = fedora.getAPIM(); } catch (Exception e) { - throw new FdcException("could not create fedora APIM:" + e.getMessage()); - } - - //get the parameters from the request - String pId=req.getParameter("pid"); - String dsId=req.getParameter("dsid"); - String fileUri=req.getParameter("fileUri"); - - boolean useNewName=false; - if( "true".equals(req.getParameter("useNewName"))){ - useNewName = true; - } - if( pId == null || pId.length() == 0 ) - throw new FdcException("Your form submission did not contain " + - "enough information to complete your request.(Missing pid parameter)"); - if( dsId == null || dsId.length() == 0 ) - throw new FdcException("Your form submission did not contain " + - "enough information to complete your request.(Missing dsid parameter)"); - if( fileUri == null || fileUri.length() == 0 ) - throw new FdcException("Your form submission did not contain " + - "enough information to complete your request.(Missing fileUri parameter)"); - - FileItem fileRes = req.getFileItem("fileRes"); - if( fileRes == null ) - throw new FdcException("Your form submission did not contain " + - "enough information to complete your request.(Missing fileRes)"); - - //check if file individual has a fedora:PID for a data stream - VitroRequest vreq = new VitroRequest(rawRequest); - IndividualDao iwDao = vreq.getWebappDaoFactory().getIndividualDao(); - Individual fileEntity = iwDao.getIndividualByURI(fileUri); - - //check if logged in - //TODO: check if logged in - - //check if user is allowed to edit datastream - //TODO:check if can edit datastream - - //check if digital object and data stream exist in fedora - Datastream ds = apim.getDatastream(pId,dsId,null); - if( ds == null ) - throw new FdcException("There was no datastream in the " + - "repository for " + pId + " " + DEFAULT_DSID); - - //upload to temp holding area - String originalName = fileRes.getName(); - String name = originalName.replaceAll("[,+\\\\/$%^&*#@!<>'\"~;]", "_"); - name = name.replace("..", "_"); - name = name.trim().toLowerCase(); - - String saveLocation = baseDirectoryForFiles + File.separator + name; - String savedName = name; - int next = 0; - boolean foundUnusedName = false; - while (!foundUnusedName) { - File test = new File(saveLocation); - if (test.exists()) { - next++; - savedName = name + '(' + next + ')'; - saveLocation = baseDirectoryForFiles + File.separator + savedName; - } else { - foundUnusedName = true; - } - } - - File uploadedFile = new File(saveLocation); - - try { - fileRes.write(uploadedFile); - } catch (Exception ex) { - log.error("Unable to save POSTed file. " + ex.getMessage()); - throw new FdcException("Unable to save file to the disk. " - + ex.getMessage()); - } - - //upload to temp area on fedora - File file = new File(saveLocation); - String uploadFileUri = fedora.uploadFile( file ); - // System.out.println("Fedora upload temp = upload file uri is " + uploadFileUri); - String md5 = md5hashForFile( file ); - md5 = md5.toLowerCase(); - - //make change to data stream on fedora - apim.modifyDatastreamByReference(pId, dsId, - null, null, - fileRes.getContentType(), null, - uploadFileUri, - "MD5", null, - null, false); - - String checksum = - apim.compareDatastreamChecksum(pId,dsId,null); - - //update properties like checksum, file size, and content type - - WebappDaoFactory wdf = vreq.getWebappDaoFactory(); - DataPropertyStatement dps = null; - DataProperty contentType = wdf.getDataPropertyDao().getDataPropertyByURI(this.contentTypeProperty); - if(contentType != null) - { - wdf.getDataPropertyStatementDao().deleteDataPropertyStatementsForIndividualByDataProperty(fileEntity, contentType); - dps = new DataPropertyStatementImpl(); - dps.setIndividualURI(fileEntity.getURI()); - dps.setDatapropURI(contentType.getURI()); - dps.setData(fileRes.getContentType()); - wdf.getDataPropertyStatementDao().insertNewDataPropertyStatement(dps); - } - - DataProperty fileSize = wdf.getDataPropertyDao().getDataPropertyByURI(this.fileSizeProperty); - if(fileSize != null) - { - wdf.getDataPropertyStatementDao().deleteDataPropertyStatementsForIndividualByDataProperty(fileEntity, fileSize); - dps = new DataPropertyStatementImpl(); - dps.setIndividualURI(fileEntity.getURI()); - dps.setDatapropURI(fileSize.getURI()); - dps.setData(Long.toString(fileRes.getSize())); - wdf.getDataPropertyStatementDao().insertNewDataPropertyStatement(dps); - //System.out.println("Updated file size with " + fileRes.getSize()); - } - - DataProperty checksumDp = wdf.getDataPropertyDao().getDataPropertyByURI(this.checksumDataProperty); - if(checksumDp != null) - { - //System.out.println("Checksum data property is also not null"); - wdf.getDataPropertyStatementDao().deleteDataPropertyStatementsForIndividualByDataProperty(fileEntity, checksumDp); - dps = new DataPropertyStatementImpl(); - dps.setIndividualURI(fileEntity.getURI()); - dps.setDatapropURI(checksumDp.getURI()); - dps.setData(checksum); - wdf.getDataPropertyStatementDao().insertNewDataPropertyStatement(dps); - } - - //I'm leaving if statement out for now as the above properties are obviously being replaced as well - //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"); - } - - //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 - - ListcsNodeStatements = 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("originalFileName", fileEntity.getName()); - req.setAttribute("checksum", checksum); - if( "true".equals(useNewName)){ - req.setAttribute("useNewName", "true"); - req.setAttribute("newFileName", originalName); - }else{ - req.setAttribute("newFileName", fileEntity.getName()); - } - - //forward to form - JSPPageHandler.renderBasicPage(req, res, "/fileupload/datastreamModificationSuccess.jsp"); - }catch(FdcException ex){ - rawRequest.setAttribute("errors", ex.getMessage()); - JSPPageHandler.renderPlainPage(rawRequest, res, "/edit/fileUploadError.jsp"); - return; - } - } - - //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 - String userURI = LoginStatusBean.getBean(req).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, org.apache.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; - } - - @Override - public void init() throws ServletException { - super.init(); - - ConfigurationProperties configProperties = ConfigurationProperties - .getBean(getServletContext()); - baseDirectoryForFiles = configProperties.getProperty( - "n3.baseDirectoryForFiles", DEFAULT_BASE_DIR); - - String maxSize = configProperties.getProperty("n3.maxSize", Long - .toString(DEFAULT_MAX_SIZE)); - try { - maxFileSize = Integer.parseInt(maxSize); - } catch (NumberFormatException nfe) { - log.error(nfe); - maxFileSize = DEFAULT_MAX_SIZE; - } - } - - public void setup(OntModel model, ServletContext context) { - this.configurationStatus = ""; - StringBuffer status = new StringBuffer(""); - - if( connected && configured ) - return; - - Properties props = new Properties(); - String path = context.getRealPath(FEDORA_PROPERTIES); - try{ - InputStream in = new FileInputStream(new File( path )); - props.load( in ); - fedoraUrl = props.getProperty("fedoraUrl"); - adminUser = props.getProperty("adminUser"); - adminPassword = props.getProperty("adminPassword"); - pidNamespace = props.getProperty("pidNamespace"); - - if( fedoraUrl == null || adminUser == null || adminPassword == null ){ - if( fedoraUrl == null ){ - log.error("'fedoraUrl' not found in properties file"); - status.append("

'fedoraUrl' not found in properties file.

\n"); - } - if( adminUser == null ) { - log.error("'adminUser' was not found in properties file, the " + - "user name of the fedora admin is needed to access the " + - "fedora API-M services."); - status.append("

'adminUser' was not found in properties file, the " + - "user name of the fedora admin is needed to access the " + - "fedora API-M services.

\n"); - } - if( adminPassword == null ){ - log.error("'adminPassword' was not found in properties file, the " + - "admin password is needed to access the fedora API-M services."); - status.append("

'adminPassword' was not found in properties file, the " + - "admin password is needed to access the fedora API-M services.

\n"); - } - if( pidNamespace == null ){ - log.error("'pidNamespace' was not found in properties file, the " + - "PID namespace indicates which namespace to use when creating " + - "new fedor digital objects."); - status.append("

'pidNamespace' was not found in properties file, the " + - "PID namespace indicates which namespace to use when creating " + - "new fedor digital objects.

\n"); - } - fedoraUrl = null; adminUser = null; adminPassword = null; - configured = false; - } else { - configured = true; - } - }catch(FileNotFoundException e) { - log.error("No fedora.properties file found,"+ - "it should be located at " + path); - status.append("

Fedora configuration failed.

\n"); - status.append("

No fedora.properties file found,"+ - "it should be located at " + path + "

\n"); - configured = false; - return; - }catch(Exception ex){ - status.append("

Fedora configuration failed.

\n"); - status.append("

Exception while loading" + path + "

\n"); - status.append("

" + ex.getMessage() + "

\n"); - log.error("could not load fedora properties", ex); - fedoraUrl = null; adminUser = null; adminPassword = null; - configured = false; - return; - } - - - status.append(RELOAD_MSG); - this.configurationStatus += status.toString(); -// else{ -// status.append("

Fedora configuration file ").append(path).append(" was loaded

"); -// status.append("

fedoraUrl: ").append(fedoraUrl).append("

\n"); -// checkFedoraServer(); -// } - } - - private boolean canConnectToFedoraServer( ){ - try{ - FedoraClient fc = new FedoraClient(fedoraUrl,adminUser, adminPassword); - String fedoraVersion = fc.getServerVersion(); - if( fedoraVersion != null && fedoraVersion.length() > 0 ){ - configurationStatus += "

Fedora server is live and is running " + - "fedora version " + fedoraVersion + "

\n"; - connected = true; - return true; - } else { - configurationStatus += "

Unable to reach fedora server

\n"; - connected = false; - return false; - } - }catch (Exception e) { - configurationStatus += "

There was an error while checking the " + - "fedora server version

\n

"+ e.getMessage() + "

\n"; - connected = false; - return false; - } - } - - public boolean isConfigured(){ return configured; } - public boolean isConnected(){ return connected; } - - private class FdcException extends Exception { - public FdcException(String message) { - super(message); - } - } - - private static final String RELOAD_MSG = - "

The fedora configuartion file will be reloaded if " + - "you edit the properties file and check the status.

\n"; - - public static String md5hashForFile(File file){ - try { - InputStream fin = new FileInputStream(file); - java.security.MessageDigest md5er = - MessageDigest.getInstance("MD5"); - byte[] buffer = new byte[1024]; - int read; - do { - read = fin.read(buffer); - if (read > 0) - md5er.update(buffer, 0, read); - } while (read != -1); - fin.close(); - byte[] digest = md5er.digest(); - if (digest == null) - return null; - String strDigest = "0x"; - for (int i = 0; i < digest.length; i++) { - strDigest += Integer.toString((digest[i] & 0xff) - + 0x100, 16).substring(1); - } - return strDigest; - } catch (Exception e) { - return null; - } - } - - private static final Log log = LogFactory.getLog(FedoraDatastreamController.class.getName()); -} diff --git a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/utils/FedoraConfiguration.java b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/utils/FedoraConfiguration.java deleted file mode 100644 index d014e0688..000000000 --- a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/utils/FedoraConfiguration.java +++ /dev/null @@ -1,198 +0,0 @@ -/* $This file is distributed under the terms of the license in /doc/license.txt$ */ - -package edu.cornell.mannlib.vitro.webapp.utils; - -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.InputStream; -import java.util.Properties; - -import javax.servlet.ServletContext; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.joda.time.format.DateTimeFormatter; -import org.joda.time.format.ISODateTimeFormat; - -import org.apache.jena.rdf.model.Property; -import org.apache.jena.rdf.model.ResourceFactory; - -import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary; -import fedora.client.FedoraClient; - -public class FedoraConfiguration { - - private static String FEDORA_PROPERTIES = "/WEB-INF/fedora.properties"; - - public String fedoraUrl = null; - private String adminUser = null; - private String adminPassword = null; - private String pidNamespace = null; - private String configurationStatus = "

Fedora configuration not yet loaded

"; - private boolean configured = false; - private boolean connected = false; - - public FedoraConfiguration(ServletContext context){ - setup( context ); - } - - public boolean isConfigured(){ return configured; } - public boolean isConnected(){ return connected; } - - public String setup(ServletContext context ){ - internalSetup( context); - if( ! configured ) - return configurationStatus; - canConnectToFedoraServer(); - return configurationStatus; - } - - private void internalSetup(ServletContext context) { - this.configurationStatus = ""; - StringBuffer status = new StringBuffer(""); - - if( connected && configured ) - return; - - Properties props = new Properties(); - String path = context.getRealPath(FEDORA_PROPERTIES); - try{ - InputStream in = new FileInputStream(new File( path )); - props.load( in ); - fedoraUrl = props.getProperty("fedoraUrl"); - adminUser = props.getProperty("adminUser"); - adminPassword = props.getProperty("adminPassword"); - pidNamespace = props.getProperty("pidNamespace"); - if( fedoraUrl == null || adminUser == null || adminPassword == null ){ - if( fedoraUrl == null ){ - log.error("'fedoraUrl' not found in properties file"); - status.append("

'fedoraUrl' not found in properties file.

\n"); - } - if( adminUser == null ) { - log.error("'adminUser' was not found in properties file, the " + - "user name of the fedora admin is needed to access the " + - "fedora API-M services."); - status.append("

'adminUser' was not found in properties file, the " + - "user name of the fedora admin is needed to access the " + - "fedora API-M services.

\n"); - } - if( adminPassword == null ){ - log.error("'adminPassword' was not found in properties file, the " + - "admin password is needed to access the fedora API-M services."); - status.append("

'adminPassword' was not found in properties file, the " + - "admin password is needed to access the fedora API-M services.

\n"); - } - if( pidNamespace == null ){ - log.error("'pidNamespace' was not found in properties file, the " + - "PID namespace indicates which namespace to use when creating " + - "new fedor digital objects."); - status.append("

'pidNamespace' was not found in properties file, the " + - "PID namespace indicates which namespace to use when creating " + - "new fedor digital objects.

\n"); - } - fedoraUrl = null; adminUser = null; adminPassword = null; - configured = false; - } else { - configured = true; - } - }catch(FileNotFoundException e){ - log.error("No fedora.properties file found,"+ - "it should be located at " + path); - status.append("

Fedora configuration failed.

\n"); - status.append("

No fedora.properties file found,"+ - "it should be located at " + path + "

\n"); - configured = false; - return; - }catch(Exception ex){ - status.append("

Fedora configuration failed.

\n"); - status.append("

Exception while loading" + path + "

\n"); - status.append("

" + ex.getMessage() + "

\n"); - log.error("could not load fedora properties", ex); - fedoraUrl = null; adminUser = null; adminPassword = null; - configured = false; - return; - } - - status.append(RELOAD_MSG); - this.configurationStatus += status.toString(); - } - - public boolean canConnectToFedoraServer( ){ - try{ - FedoraClient fc = new FedoraClient(fedoraUrl,adminUser, adminPassword); - String fedoraVersion = fc.getServerVersion(); - if( fedoraVersion != null && fedoraVersion.length() > 0 ){ - configurationStatus += "

Fedora server is live and is running " + - "fedora version " + fedoraVersion + "

\n"; - connected = true; - return true; - } else { - configurationStatus += "

Unable to reach fedora server

\n"; - connected = false; - return false; - } - }catch (Exception e) { - configurationStatus += "

There was an error while checking the " + - "fedora server version

\n

"+ e.getMessage() + "

\n"; - connected = false; - return false; - } - } - - - - public static final Property FILE_NAME = ResourceFactory.createProperty(VitroVocabulary.FILE_NAME); - public static final Property CONTENT_TYPE = ResourceFactory.createProperty(VitroVocabulary.CONTENT_TYPE); - public static final Property FILE_LOCATION = ResourceFactory.createProperty(VitroVocabulary.FILE_LOCATION); - //public static final Property FEDORA_ID = ResourceFactory.createProperty(VitroVocabulary.FEDORA_PID); - - DateTimeFormatter isoFormatter = ISODateTimeFormat.dateTime(); - - private static Log log = LogFactory.getLog(FedoraConfiguration.class); - - private static final String RELOAD_MSG = - "

The fedora configuartion file will be reloaded if " + - "you edit the properties file and check the status.

\n"; - - public String getFedoraUrl() { - return fedoraUrl; - } - - public void setFedoraUrl(String fedoraUrl) { - this.fedoraUrl = fedoraUrl; - } - - public String getAdminUser() { - return adminUser; - } - - public void setAdminUser(String adminUser) { - this.adminUser = adminUser; - } - - public String getAdminPassword() { - return adminPassword; - } - - public void setAdminPassword(String adminPassword) { - this.adminPassword = adminPassword; - } - - public String getPidNamespace() { - return pidNamespace; - } - - public void setPidNamespace(String pidNamespace) { - this.pidNamespace = pidNamespace; - } - - public String getConfigurationStatus() { - return configurationStatus; - } - - public void setConfigurationStatus(String configurationStatus) { - this.configurationStatus = configurationStatus; - } - -} diff --git a/dependencies/pom.xml b/dependencies/pom.xml index 79a9ff0e0..d5717f500 100644 --- a/dependencies/pom.xml +++ b/dependencies/pom.xml @@ -248,11 +248,6 @@ csv 1.0 - - org.vivoweb.dependencies - fedora-client - 1.0 - org.vivoweb.dependencies jai_codec diff --git a/webapp/src/main/webapp/fileupload/datastreamModification.jsp b/webapp/src/main/webapp/fileupload/datastreamModification.jsp deleted file mode 100644 index 0a134f8f8..000000000 --- a/webapp/src/main/webapp/fileupload/datastreamModification.jsp +++ /dev/null @@ -1,24 +0,0 @@ -<%-- $This file is distributed under the terms of the license in /doc/license.txt$ --%> - -<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> - -<%/* this is used by the FedoraDatastreamController and not by the N3 editing system.*/%> - -

Upload a replacement for ${fileName}

-
" - enctype="multipart/form-data" method="POST"> - -

File

- - <%/*

- use existing file name

-

- rename file to name of file being uploaded

*/%> - - - - - - - -
diff --git a/webapp/src/main/webapp/fileupload/datastreamModificationSuccess.jsp b/webapp/src/main/webapp/fileupload/datastreamModificationSuccess.jsp deleted file mode 100644 index 663991cbe..000000000 --- a/webapp/src/main/webapp/fileupload/datastreamModificationSuccess.jsp +++ /dev/null @@ -1,16 +0,0 @@ -<%-- $This file is distributed under the terms of the license in /doc/license.txt$ --%> - -<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> - -
The file ${orginalFileName} was updated. The file received from you had the MD5 checksum ${checksum}.
- - -
The name of the file was also changed to ${newFileName}.
-
- - - - - -
Goto ${newFileName}
- \ No newline at end of file diff --git a/webapp/src/main/webapp/fileupload/md5.jsp b/webapp/src/main/webapp/fileupload/md5.jsp deleted file mode 100644 index 9ace23a43..000000000 --- a/webapp/src/main/webapp/fileupload/md5.jsp +++ /dev/null @@ -1,11 +0,0 @@ -<%-- $This file is distributed under the terms of the license in /doc/license.txt$ --%> - -<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> - -
${checksum} "${fileName}"
- - - - -
return to ${name}
- \ No newline at end of file