use of edu.harvard.iq.dataverse.DatasetVersion 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.DatasetVersion 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) {
}
}
}
use of edu.harvard.iq.dataverse.DatasetVersion in project dataverse by IQSS.
the class FileUtilTest method testIsDownloadPopupRequiredHasTermsOfUseAndCc0License.
@Test
public void testIsDownloadPopupRequiredHasTermsOfUseAndCc0License() {
DatasetVersion dsv1 = new DatasetVersion();
dsv1.setVersionState(DatasetVersion.VersionState.RELEASED);
TermsOfUseAndAccess termsOfUseAndAccess = new TermsOfUseAndAccess();
/**
* @todo Ask if setting the license to CC0 should be enough to not show
* the popup when the are Terms of Use. This feels like a bug since the
* Terms of Use should probably be shown.
*/
termsOfUseAndAccess.setLicense(TermsOfUseAndAccess.License.CC0);
termsOfUseAndAccess.setTermsOfUse("be excellent to each other");
dsv1.setTermsOfUseAndAccess(termsOfUseAndAccess);
assertEquals(false, FileUtil.isDownloadPopupRequired(dsv1));
}
use of edu.harvard.iq.dataverse.DatasetVersion in project dataverse by IQSS.
the class FileUtilTest method testIsDownloadPopupRequiredDraft.
@Test
public void testIsDownloadPopupRequiredDraft() {
Dataset dataset = new Dataset();
DatasetVersion dsv1 = dataset.getEditVersion();
assertEquals(DatasetVersion.VersionState.DRAFT, dsv1.getVersionState());
assertEquals(false, FileUtil.isDownloadPopupRequired(dsv1));
}
use of edu.harvard.iq.dataverse.DatasetVersion in project dataverse by IQSS.
the class FileUtilTest method testIsPubliclyDownloadable2.
@Test
public void testIsPubliclyDownloadable2() {
FileMetadata nonRestrictedFileMetadata = new FileMetadata();
DatasetVersion dsv = new DatasetVersion();
TermsOfUseAndAccess termsOfUseAndAccess = new TermsOfUseAndAccess();
termsOfUseAndAccess.setTermsOfUse("be excellent to each other");
dsv.setTermsOfUseAndAccess(termsOfUseAndAccess);
dsv.setVersionState(DatasetVersion.VersionState.RELEASED);
nonRestrictedFileMetadata.setDatasetVersion(dsv);
Dataset dataset = new Dataset();
dsv.setDataset(dataset);
nonRestrictedFileMetadata.setRestricted(false);
assertEquals(false, FileUtil.isPubliclyDownloadable(nonRestrictedFileMetadata));
}
Aggregations