Search in sources :

Example 46 with DatasetVersion

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) {
        }
    }
}
Also used : XMLStreamReader(javax.xml.stream.XMLStreamReader) ForeignMetadataFormatMapping(edu.harvard.iq.dataverse.ForeignMetadataFormatMapping) FileNotFoundException(java.io.FileNotFoundException) Gson(com.google.gson.Gson) JsonObject(javax.json.JsonObject) DatasetVersion(edu.harvard.iq.dataverse.DatasetVersion) IOException(java.io.IOException) JsonParseException(edu.harvard.iq.dataverse.util.json.JsonParseException) FileInputStream(java.io.FileInputStream) XMLStreamException(javax.xml.stream.XMLStreamException) StringReader(java.io.StringReader) JsonReader(javax.json.JsonReader) EJBException(javax.ejb.EJBException) XMLInputFactory(javax.xml.stream.XMLInputFactory) JsonParser(edu.harvard.iq.dataverse.util.json.JsonParser)

Example 47 with DatasetVersion

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) {
        }
    }
}
Also used : XMLStreamReader(javax.xml.stream.XMLStreamReader) ForeignMetadataFormatMapping(edu.harvard.iq.dataverse.ForeignMetadataFormatMapping) Gson(com.google.gson.Gson) JsonObject(javax.json.JsonObject) DatasetVersion(edu.harvard.iq.dataverse.DatasetVersion) JsonParseException(edu.harvard.iq.dataverse.util.json.JsonParseException) XMLStreamException(javax.xml.stream.XMLStreamException) StringReader(java.io.StringReader) JsonReader(javax.json.JsonReader) EJBException(javax.ejb.EJBException) XMLInputFactory(javax.xml.stream.XMLInputFactory) JsonParser(edu.harvard.iq.dataverse.util.json.JsonParser)

Example 48 with DatasetVersion

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));
}
Also used : DatasetVersion(edu.harvard.iq.dataverse.DatasetVersion) TermsOfUseAndAccess(edu.harvard.iq.dataverse.TermsOfUseAndAccess) Test(org.junit.Test)

Example 49 with DatasetVersion

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));
}
Also used : Dataset(edu.harvard.iq.dataverse.Dataset) DatasetVersion(edu.harvard.iq.dataverse.DatasetVersion) Test(org.junit.Test)

Example 50 with DatasetVersion

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));
}
Also used : Dataset(edu.harvard.iq.dataverse.Dataset) FileMetadata(edu.harvard.iq.dataverse.FileMetadata) DatasetVersion(edu.harvard.iq.dataverse.DatasetVersion) TermsOfUseAndAccess(edu.harvard.iq.dataverse.TermsOfUseAndAccess) Test(org.junit.Test)

Aggregations

DatasetVersion (edu.harvard.iq.dataverse.DatasetVersion)85 Dataset (edu.harvard.iq.dataverse.Dataset)43 Test (org.junit.Test)36 FileMetadata (edu.harvard.iq.dataverse.FileMetadata)25 ArrayList (java.util.ArrayList)24 DataFile (edu.harvard.iq.dataverse.DataFile)19 JsonObject (javax.json.JsonObject)15 Date (java.util.Date)13 StringReader (java.io.StringReader)11 IOException (java.io.IOException)10 AuthenticatedUser (edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser)9 Timestamp (java.sql.Timestamp)9 EJBException (javax.ejb.EJBException)9 JsonParser (edu.harvard.iq.dataverse.util.json.JsonParser)8 JsonObjectBuilder (javax.json.JsonObjectBuilder)8 JsonReader (javax.json.JsonReader)8 DatasetField (edu.harvard.iq.dataverse.DatasetField)7 Dataverse (edu.harvard.iq.dataverse.Dataverse)7 RoleAssignment (edu.harvard.iq.dataverse.RoleAssignment)7 DataverseRequest (edu.harvard.iq.dataverse.engine.command.DataverseRequest)7