use of edu.harvard.iq.dataverse.ingest.metadataextraction.FileMetadataExtractor in project dataverse by IQSS.
the class IngestServiceBean method extractMetadata.
/*
* extractMetadata:
* framework for extracting metadata from uploaded files. The results will
* be used to populate the metadata of the Dataset to which the file belongs.
*/
public boolean extractMetadata(String tempFileLocation, DataFile dataFile, DatasetVersion editVersion) throws IOException {
boolean ingestSuccessful = false;
FileInputStream tempFileInputStream = null;
try {
tempFileInputStream = new FileInputStream(new File(tempFileLocation));
} catch (FileNotFoundException notfoundEx) {
throw new IOException("Could not open temp file " + tempFileLocation);
}
// Locate metadata extraction plugin for the file format by looking
// it up with the Ingest Service Provider Registry:
// FileMetadataExtractor extractorPlugin = IngestSP.getMetadataExtractorByMIMEType(dfile.getContentType());
FileMetadataExtractor extractorPlugin = new FITSFileMetadataExtractor();
FileMetadataIngest extractedMetadata = extractorPlugin.ingest(new BufferedInputStream(tempFileInputStream));
Map<String, Set<String>> extractedMetadataMap = extractedMetadata.getMetadataMap();
// Store the fields and values we've gathered for safe-keeping:
// from 3.6:
// attempt to ingest the extracted metadata into the database;
// TODO: this should throw an exception if anything goes wrong.
FileMetadata fileMetadata = dataFile.getFileMetadata();
if (extractedMetadataMap != null) {
logger.fine("Ingest Service: Processing extracted metadata;");
if (extractedMetadata.getMetadataBlockName() != null) {
logger.fine("Ingest Service: This metadata belongs to the " + extractedMetadata.getMetadataBlockName() + " metadata block.");
processDatasetMetadata(extractedMetadata, editVersion);
}
processFileLevelMetadata(extractedMetadata, fileMetadata);
}
ingestSuccessful = true;
return ingestSuccessful;
}
Aggregations