Skip to content

Commit

Permalink
Merge a9e0480 into 9726030
Browse files Browse the repository at this point in the history
  • Loading branch information
jcreel committed Jul 16, 2018
2 parents 9726030 + a9e0480 commit 364aa14
Showing 1 changed file with 13 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@

import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.io.FileUtils;
import org.apache.jena.atlas.logging.Log;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.Base64Utils;

Expand All @@ -32,6 +34,7 @@
import edu.tamu.app.model.Document;
import edu.tamu.app.model.ProjectRepository;
import edu.tamu.app.model.repo.DocumentRepo;
import edu.tamu.app.service.DocumentFactory;
import edu.tamu.app.utilities.CsvUtility;

public class ArchivematicaFilesystemRepository implements Repository {
Expand All @@ -45,6 +48,8 @@ public class ArchivematicaFilesystemRepository implements Repository {
private ProjectRepository projectRepository;

private CsvUtility csvUtility;

private static final Logger logger = Logger.getLogger(ArchivematicaFilesystemRepository.class);

public ArchivematicaFilesystemRepository(ProjectRepository projectRepository) {
this.projectRepository = projectRepository;
Expand All @@ -61,7 +66,7 @@ public Document push(Document document) throws IOException {
// make the top level container for the transfer package
File archivematicaPackageDirectory = new File(getArchivematicaTopDirectory() + File.separator + document.getProject().getName() + "_" + document.getName());

System.out.println("Writing Archivematica Transfer Package for Document " + itemDirectoryPath + " to " + archivematicaPackageDirectory.getCanonicalPath());
logger.info("Writing Archivematica Transfer Package for Document " + itemDirectoryPath + " to " + archivematicaPackageDirectory.getCanonicalPath());

if (!archivematicaPackageDirectory.isDirectory())
archivematicaPackageDirectory.mkdir();
Expand Down Expand Up @@ -175,7 +180,7 @@ private boolean startArchivematicaTransfer(Document document, File archivematica
try {
connection.setRequestMethod("POST");
} catch (ProtocolException e) {
ProtocolException pe = new ProtocolException("Failed to set Archivematica request method to GET; that protocol for the request is invalid. {" + e.getMessage() + "}");
ProtocolException pe = new ProtocolException("Failed to set Archivematica request method to POST; that protocol for the request is invalid. {" + e.getMessage() + "}");
pe.setStackTrace(e.getStackTrace());
throw pe;
}
Expand All @@ -184,7 +189,7 @@ private boolean startArchivematicaTransfer(Document document, File archivematica

String itemDirectoryName = document.getProject().getName() + "_" + document.getName();
String pathString = getArchivematicaTransferSourceLocationUUID() + ":" + getArchivematicaTransferLocationDirectoryName() + File.separator + itemDirectoryName;
System.out.println("Transfer package path string: " + pathString);
logger.info("Transfer package path string: " + pathString);
String encodedPath = Base64Utils.encodeToString(pathString.getBytes());

// Write post data by opening an output stream on the connection and
Expand All @@ -201,8 +206,7 @@ private boolean startArchivematicaTransfer(Document document, File archivematica
String params = "";
params += "name=" + document.getProject().getName() + "_" + document.getName() + "&type=standard" + "&paths[]=" + encodedPath;
try {
System.out.println("POST DATA: ");
System.out.println(params);
logger.info("POST request parameters being sent to archivematica: "+ params);

connection.getOutputStream().write(params.getBytes());

Expand All @@ -214,12 +218,13 @@ private boolean startArchivematicaTransfer(Document document, File archivematica

// Read response from item post
StringBuilder response = new StringBuilder();

BufferedReader br = null;
try {
br = new BufferedReader(new InputStreamReader(connection.getInputStream()));

} catch (IOException e) {
IOException ioe = new IOException("Could not get input stream for a response from the connection of the post request. Response message was \"" + connection.getResponseMessage()
IOException ioe = new IOException("Could not get input stream for a response from the connection of the POST request. Response message was \"" + connection.getResponseMessage()
+ "\" with this exception thrown: {" + e.getMessage() + "}");
ioe.setStackTrace(e.getStackTrace());
throw ioe;
Expand All @@ -236,6 +241,8 @@ private boolean startArchivematicaTransfer(Document document, File archivematica
ioe.setStackTrace(e.getStackTrace());
throw ioe;
}

logger.info("POST request to archivematica resulted in response code of " + connection.getResponseCode() + " with response: " + response.toString());

// Close streams
try {
Expand Down

0 comments on commit 364aa14

Please sign in to comment.