Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved archivematica logging #199

Merged
merged 1 commit into from
Jul 31, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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