use of edu.harvard.iq.dataverse.ForeignMetadataFormatMapping in project dataverse by IQSS.
the class ForeignMetadataImportServiceBean method importXML.
public void importXML(String xmlToParse, String foreignFormat, DatasetVersion datasetVersion) {
StringReader reader = null;
XMLStreamReader xmlr = null;
ForeignMetadataFormatMapping mappingSupported = findFormatMappingByName(foreignFormat);
if (mappingSupported == null) {
throw new EJBException("Unknown/unsupported foreign metadata format " + foreignFormat);
}
try {
reader = new StringReader(xmlToParse);
XMLInputFactory xmlFactory = javax.xml.stream.XMLInputFactory.newInstance();
xmlr = xmlFactory.createXMLStreamReader(reader);
processXML(xmlr, mappingSupported, datasetVersion);
} catch (XMLStreamException ex) {
// Logger.getLogger("global").log(Level.SEVERE, null, ex);
throw new EJBException("ERROR occurred while parsing XML fragment (" + xmlToParse.substring(0, 64) + "...); ", ex);
} finally {
try {
if (xmlr != null) {
xmlr.close();
}
} catch (XMLStreamException ex) {
}
}
}
use of edu.harvard.iq.dataverse.ForeignMetadataFormatMapping in project dataverse by IQSS.
the class ForeignMetadataImportServiceBean method importXML.
public void importXML(File xmlFile, String foreignFormat, DatasetVersion datasetVersion) {
FileInputStream in = null;
XMLStreamReader xmlr = null;
// look up the foreign metadata mapping for this format:
ForeignMetadataFormatMapping mappingSupported = findFormatMappingByName(foreignFormat);
if (mappingSupported == null) {
throw new EJBException("Unknown/unsupported foreign metadata format " + foreignFormat);
}
try {
in = new FileInputStream(xmlFile);
XMLInputFactory xmlFactory = javax.xml.stream.XMLInputFactory.newInstance();
xmlr = xmlFactory.createXMLStreamReader(in);
processXML(xmlr, mappingSupported, datasetVersion);
} catch (FileNotFoundException ex) {
// Logger.getLogger("global").log(Level.SEVERE, null, ex);
throw new EJBException("ERROR occurred in mapDDI: File Not Found!");
} catch (XMLStreamException ex) {
// Logger.getLogger("global").log(Level.SEVERE, null, ex);
throw new EJBException("ERROR occurred while parsing XML (file " + xmlFile.getAbsolutePath() + "); ", ex);
} finally {
try {
if (xmlr != null) {
xmlr.close();
}
} catch (XMLStreamException ex) {
}
try {
if (in != null) {
in.close();
}
} catch (IOException ex) {
}
}
}
use of edu.harvard.iq.dataverse.ForeignMetadataFormatMapping in project dataverse by IQSS.
the class ImportGenericServiceBean method processOAIDCxml.
// Helper method for importing harvested Dublin Core xml.
// Dublin Core is considered a mandatory, built in metadata format mapping.
// It is distributed as required content, in reference_data.sql.
// Note that arbitrary formatting tags are supported for the outer xml
// wrapper. -- L.A. 4.5
public DatasetDTO processOAIDCxml(String DcXmlToParse) throws XMLStreamException {
// look up DC metadata mapping:
ForeignMetadataFormatMapping dublinCoreMapping = findFormatMappingByName(DCTERMS);
if (dublinCoreMapping == null) {
throw new EJBException("Failed to find metadata mapping for " + DCTERMS);
}
DatasetDTO datasetDTO = this.initializeDataset();
StringReader reader = null;
XMLStreamReader xmlr = null;
try {
reader = new StringReader(DcXmlToParse);
XMLInputFactory xmlFactory = javax.xml.stream.XMLInputFactory.newInstance();
xmlr = xmlFactory.createXMLStreamReader(reader);
// while (xmlr.next() == XMLStreamConstants.COMMENT); // skip pre root comments
xmlr.nextTag();
xmlr.require(XMLStreamConstants.START_ELEMENT, null, OAI_DC_OPENING_TAG);
processXMLElement(xmlr, ":", OAI_DC_OPENING_TAG, dublinCoreMapping, datasetDTO);
} catch (XMLStreamException ex) {
throw new EJBException("ERROR occurred while parsing XML fragment (" + DcXmlToParse.substring(0, 64) + "...); ", ex);
}
datasetDTO.getDatasetVersion().setVersionState(DatasetVersion.VersionState.RELEASED);
// Our DC import handles the contents of the dc:identifier field
// as an "other id". In the context of OAI harvesting, we expect
// the identifier to be a global id, so we need to rearrange that:
String identifier = getOtherIdFromDTO(datasetDTO.getDatasetVersion());
logger.fine("Imported identifier: " + identifier);
String globalIdentifier = reassignIdentifierAsGlobalId(identifier, datasetDTO);
logger.fine("Detected global identifier: " + globalIdentifier);
if (globalIdentifier == null) {
throw new EJBException("Failed to find a global identifier in the OAI_DC XML record.");
}
return datasetDTO;
}
use of edu.harvard.iq.dataverse.ForeignMetadataFormatMapping in project dataverse by IQSS.
the class ImportGenericServiceBean method importXML.
public void importXML(File xmlFile, String foreignFormat, DatasetVersion datasetVersion) {
FileInputStream in = null;
XMLStreamReader xmlr = null;
// look up the foreign metadata mapping for this format:
ForeignMetadataFormatMapping mappingSupported = findFormatMappingByName(foreignFormat);
if (mappingSupported == null) {
throw new EJBException("Unknown/unsupported foreign metadata format " + foreignFormat);
}
try {
in = new FileInputStream(xmlFile);
XMLInputFactory xmlFactory = javax.xml.stream.XMLInputFactory.newInstance();
xmlr = xmlFactory.createXMLStreamReader(in);
DatasetDTO datasetDTO = processXML(xmlr, mappingSupported);
Gson gson = new Gson();
String json = gson.toJson(datasetDTO.getDatasetVersion());
logger.info("Json:\n" + json);
JsonReader jsonReader = Json.createReader(new StringReader(json));
JsonObject obj = jsonReader.readObject();
DatasetVersion dv = new JsonParser(datasetFieldSvc, blockService, settingsService).parseDatasetVersion(obj, datasetVersion);
} catch (FileNotFoundException ex) {
// Logger.getLogger("global").log(Level.SEVERE, null, ex);
throw new EJBException("ERROR occurred in mapDDI: File Not Found!");
} catch (XMLStreamException ex) {
// Logger.getLogger("global").log(Level.SEVERE, null, ex);
throw new EJBException("ERROR occurred while parsing XML (file " + xmlFile.getAbsolutePath() + "); ", ex);
} catch (JsonParseException ex) {
Logger.getLogger(ImportGenericServiceBean.class.getName()).log(Level.SEVERE, null, ex);
} finally {
try {
if (xmlr != null) {
xmlr.close();
}
} catch (XMLStreamException ex) {
}
try {
if (in != null) {
in.close();
}
} catch (IOException ex) {
}
}
}
use of edu.harvard.iq.dataverse.ForeignMetadataFormatMapping in project dataverse by IQSS.
the class ImportGenericServiceBean method importXML.
public void importXML(String xmlToParse, String foreignFormat, DatasetVersion datasetVersion) {
StringReader reader = null;
XMLStreamReader xmlr = null;
ForeignMetadataFormatMapping mappingSupported = findFormatMappingByName(foreignFormat);
if (mappingSupported == null) {
throw new EJBException("Unknown/unsupported foreign metadata format " + foreignFormat);
}
try {
reader = new StringReader(xmlToParse);
XMLInputFactory xmlFactory = javax.xml.stream.XMLInputFactory.newInstance();
xmlr = xmlFactory.createXMLStreamReader(reader);
DatasetDTO datasetDTO = processXML(xmlr, mappingSupported);
Gson gson = new Gson();
String json = gson.toJson(datasetDTO.getDatasetVersion());
logger.fine(json);
JsonReader jsonReader = Json.createReader(new StringReader(json));
JsonObject obj = jsonReader.readObject();
DatasetVersion dv = new JsonParser(datasetFieldSvc, blockService, settingsService).parseDatasetVersion(obj, datasetVersion);
} catch (XMLStreamException ex) {
// Logger.getLogger("global").log(Level.SEVERE, null, ex);
throw new EJBException("ERROR occurred while parsing XML fragment (" + xmlToParse.substring(0, 64) + "...); ", ex);
} catch (JsonParseException ex) {
Logger.getLogger(ImportGenericServiceBean.class.getName()).log(Level.SEVERE, null, ex);
} finally {
try {
if (xmlr != null) {
xmlr.close();
}
} catch (XMLStreamException ex) {
}
}
}
Aggregations