Search in sources :

Example 1 with FileMetadataIngest

use of edu.harvard.iq.dataverse.ingest.metadataextraction.FileMetadataIngest 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;
}
Also used : Set(java.util.Set) LinkedHashSet(java.util.LinkedHashSet) FileMetadataIngest(edu.harvard.iq.dataverse.ingest.metadataextraction.FileMetadataIngest) FileNotFoundException(java.io.FileNotFoundException) FileMetadata(edu.harvard.iq.dataverse.FileMetadata) FileMetadataExtractor(edu.harvard.iq.dataverse.ingest.metadataextraction.FileMetadataExtractor) FITSFileMetadataExtractor(edu.harvard.iq.dataverse.ingest.metadataextraction.impl.plugins.fits.FITSFileMetadataExtractor) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) FITSFileMetadataExtractor(edu.harvard.iq.dataverse.ingest.metadataextraction.impl.plugins.fits.FITSFileMetadataExtractor) BufferedInputStream(java.io.BufferedInputStream) DataFile(edu.harvard.iq.dataverse.DataFile) File(java.io.File)

Aggregations

DataFile (edu.harvard.iq.dataverse.DataFile)1 FileMetadata (edu.harvard.iq.dataverse.FileMetadata)1 FileMetadataExtractor (edu.harvard.iq.dataverse.ingest.metadataextraction.FileMetadataExtractor)1 FileMetadataIngest (edu.harvard.iq.dataverse.ingest.metadataextraction.FileMetadataIngest)1 FITSFileMetadataExtractor (edu.harvard.iq.dataverse.ingest.metadataextraction.impl.plugins.fits.FITSFileMetadataExtractor)1 BufferedInputStream (java.io.BufferedInputStream)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 LinkedHashSet (java.util.LinkedHashSet)1 Set (java.util.Set)1