Search in sources :

Example 1 with TermsOfUseAndAccess

use of edu.harvard.iq.dataverse.TermsOfUseAndAccess in project dataverse by IQSS.

the class FileUtilTest method testIsDownloadPopupRequiredHasTermsOfUseAndNoneLicense.

@Test
public void testIsDownloadPopupRequiredHasTermsOfUseAndNoneLicense() {
    DatasetVersion dsv1 = new DatasetVersion();
    dsv1.setVersionState(DatasetVersion.VersionState.RELEASED);
    TermsOfUseAndAccess termsOfUseAndAccess = new TermsOfUseAndAccess();
    termsOfUseAndAccess.setLicense(TermsOfUseAndAccess.License.NONE);
    termsOfUseAndAccess.setTermsOfUse("be excellent to each other");
    dsv1.setTermsOfUseAndAccess(termsOfUseAndAccess);
    assertEquals(true, FileUtil.isDownloadPopupRequired(dsv1));
}
Also used : DatasetVersion(edu.harvard.iq.dataverse.DatasetVersion) TermsOfUseAndAccess(edu.harvard.iq.dataverse.TermsOfUseAndAccess) Test(org.junit.Test)

Example 2 with TermsOfUseAndAccess

use of edu.harvard.iq.dataverse.TermsOfUseAndAccess in project dataverse by IQSS.

the class FileUtilTest method testIsDownloadPopupRequiredHasTermsOfAccess.

@Test
public void testIsDownloadPopupRequiredHasTermsOfAccess() {
    DatasetVersion dsv1 = new DatasetVersion();
    dsv1.setVersionState(DatasetVersion.VersionState.RELEASED);
    TermsOfUseAndAccess termsOfUseAndAccess = new TermsOfUseAndAccess();
    termsOfUseAndAccess.setTermsOfAccess("Terms of *Access* is different than Terms of Use");
    dsv1.setTermsOfUseAndAccess(termsOfUseAndAccess);
    assertEquals(true, FileUtil.isDownloadPopupRequired(dsv1));
}
Also used : DatasetVersion(edu.harvard.iq.dataverse.DatasetVersion) TermsOfUseAndAccess(edu.harvard.iq.dataverse.TermsOfUseAndAccess) Test(org.junit.Test)

Example 3 with TermsOfUseAndAccess

use of edu.harvard.iq.dataverse.TermsOfUseAndAccess in project dataverse by IQSS.

the class FileUtilTest method testIsDownloadPopupRequiredLicenseCC0.

@Test
public void testIsDownloadPopupRequiredLicenseCC0() {
    DatasetVersion dsv1 = new DatasetVersion();
    dsv1.setVersionState(DatasetVersion.VersionState.RELEASED);
    TermsOfUseAndAccess termsOfUseAndAccess = new TermsOfUseAndAccess();
    termsOfUseAndAccess.setLicense(TermsOfUseAndAccess.License.CC0);
    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 4 with TermsOfUseAndAccess

use of edu.harvard.iq.dataverse.TermsOfUseAndAccess in project dataverse by IQSS.

the class JsonParser method parseDatasetVersion.

public DatasetVersion parseDatasetVersion(JsonObject obj, DatasetVersion dsv) throws JsonParseException {
    try {
        String archiveNote = obj.getString("archiveNote", null);
        if (archiveNote != null) {
            dsv.setArchiveNote(archiveNote);
        }
        dsv.setDeaccessionLink(obj.getString("deaccessionLink", null));
        int versionNumberInt = obj.getInt("versionNumber", -1);
        Long versionNumber = null;
        if (versionNumberInt != -1) {
            versionNumber = new Long(versionNumberInt);
        }
        dsv.setVersionNumber(versionNumber);
        dsv.setMinorVersionNumber(parseLong(obj.getString("minorVersionNumber", null)));
        // use the id from the json object.
        if (dsv.getId() == null) {
            dsv.setId(parseLong(obj.getString("id", null)));
        }
        String versionStateStr = obj.getString("versionState", null);
        if (versionStateStr != null) {
            dsv.setVersionState(DatasetVersion.VersionState.valueOf(versionStateStr));
        }
        dsv.setReleaseTime(parseDate(obj.getString("releaseDate", null)));
        dsv.setLastUpdateTime(parseTime(obj.getString("lastUpdateTime", null)));
        dsv.setCreateTime(parseTime(obj.getString("createTime", null)));
        dsv.setArchiveTime(parseTime(obj.getString("archiveTime", null)));
        dsv.setUNF(obj.getString("UNF", null));
        // Terms of Use related fields
        TermsOfUseAndAccess terms = new TermsOfUseAndAccess();
        terms.setTermsOfUse(obj.getString("termsOfUse", null));
        terms.setTermsOfAccess(obj.getString("termsOfAccess", null));
        terms.setConfidentialityDeclaration(obj.getString("confidentialityDeclaration", null));
        terms.setSpecialPermissions(obj.getString("specialPermissions", null));
        terms.setRestrictions(obj.getString("restrictions", null));
        terms.setCitationRequirements(obj.getString("citationRequirements", null));
        terms.setDepositorRequirements(obj.getString("depositorRequirements", null));
        terms.setConditions(obj.getString("conditions", null));
        terms.setDisclaimer(obj.getString("disclaimer", null));
        terms.setDataAccessPlace(obj.getString("dataAccessPlace", null));
        terms.setOriginalArchive(obj.getString("originalArchive", null));
        terms.setAvailabilityStatus(obj.getString("availabilityStatus", null));
        terms.setContactForAccess(obj.getString("contactForAccess", null));
        terms.setSizeOfCollection(obj.getString("sizeOfCollection", null));
        terms.setStudyCompletion(obj.getString("studyCompletion", null));
        terms.setLicense(parseLicense(obj.getString("license", null)));
        dsv.setTermsOfUseAndAccess(terms);
        dsv.setDatasetFields(parseMetadataBlocks(obj.getJsonObject("metadataBlocks")));
        JsonArray filesJson = obj.getJsonArray("files");
        if (filesJson == null) {
            filesJson = obj.getJsonArray("fileMetadatas");
        }
        if (filesJson != null) {
            dsv.setFileMetadatas(parseFiles(filesJson, dsv));
        }
        return dsv;
    } catch (ParseException ex) {
        throw new JsonParseException("Error parsing date:" + ex.getMessage(), ex);
    } catch (NumberFormatException ex) {
        throw new JsonParseException("Error parsing number:" + ex.getMessage(), ex);
    }
}
Also used : JsonArray(javax.json.JsonArray) JsonString(javax.json.JsonString) ParseException(java.text.ParseException) TermsOfUseAndAccess(edu.harvard.iq.dataverse.TermsOfUseAndAccess)

Example 5 with TermsOfUseAndAccess

use of edu.harvard.iq.dataverse.TermsOfUseAndAccess in project dataverse by IQSS.

the class SwordServiceBean method setDatasetLicenseAndTermsOfUse.

/**
 * The rules (from https://github.com/IQSS/dataverse/issues/805 ) are below.
 *
 * If you don't provide `<dcterms:license>` the license should be set to
 * "CC0" on dataset creation.
 *
 * If you don't provide `<dcterms:license>` the license on dataset
 * modification, the license should not change.
 *
 * To provide `<dcterms:rights>` you much either omit `<dcterms:license>`
 * (for backwards compatibility since `<dcterms:license>` was not a required
 * field for SWORD in DVN 3.6) or set `<dcterms:license>` to "NONE".
 *
 * It is invalid to provide "CC0" under `<dcterms:license>` in combination
 * with any value under `<dcterms:rights>`.
 *
 * It is invalid to attempt to change the license to "CC0" if Terms of Use
 * (`<dcterms:rights>`) is already on file.
 *
 * Both `<dcterms:rights>` and `<dcterms:license>` can only be specified
 * once. Multiples are not allowed.
 *
 * Blank values are not allowed for `<dcterms:license>` (since it's new) but
 * for backwards compatibility, blank values are allowed for
 * `<dcterms:rights>` per
 * https://github.com/IQSS/dataverse/issues/805#issuecomment-71670396
 *
 * @todo What about the "native" API? Are similar rules enforced? See also
 * https://github.com/IQSS/dataverse/issues/1385
 */
public void setDatasetLicenseAndTermsOfUse(DatasetVersion datasetVersionToMutate, SwordEntry swordEntry) throws SwordError {
    Map<String, List<String>> dcterms = swordEntry.getDublinCore();
    List<String> listOfLicensesProvided = dcterms.get("license");
    TermsOfUseAndAccess terms = new TermsOfUseAndAccess();
    datasetVersionToMutate.setTermsOfUseAndAccess(terms);
    if (listOfLicensesProvided == null) {
        TermsOfUseAndAccess.License existingLicense = datasetVersionToMutate.getTermsOfUseAndAccess().getLicense();
        if (existingLicense != null) {
            // leave the license alone but set terms of use
            setTermsOfUse(datasetVersionToMutate, dcterms, existingLicense);
        } else {
            TermsOfUseAndAccess.License unspecifiedLicense = TermsOfUseAndAccess.defaultLicense;
            List<String> listOfRights = dcterms.get("rights");
            if (listOfRights != null) {
                int numRightsProvided = listOfRights.size();
                if (numRightsProvided != 1) {
                    throw new SwordError("Only one Terms of Use (dcterms:rights) can be provided per dataset, not " + numRightsProvided);
                } else {
                    // Set to NONE for backwards combatibility. We didn't require a license for SWORD in DVN 3.x.
                    unspecifiedLicense = TermsOfUseAndAccess.License.NONE;
                }
            }
            terms.setLicense(existingLicense);
            terms.setLicense(unspecifiedLicense);
            setTermsOfUse(datasetVersionToMutate, dcterms, unspecifiedLicense);
        }
        return;
    }
    int numLicensesProvided = listOfLicensesProvided.size();
    if (numLicensesProvided != 1) {
        throw new SwordError("Only one license can be provided per dataset, not " + numLicensesProvided + ".");
    }
    String licenseProvided = listOfLicensesProvided.get(0);
    if (StringUtils.isBlank(licenseProvided)) {
        throw new SwordError("License provided was blank.");
    }
    TermsOfUseAndAccess.License licenseToSet;
    try {
        licenseToSet = TermsOfUseAndAccess.License.valueOf(licenseProvided);
    } catch (IllegalArgumentException ex) {
        throw new SwordError("License provided was \"" + licenseProvided + "\" but one " + Arrays.toString(DatasetVersion.License.values()) + " was expected.");
    }
    terms.setLicense(licenseToSet);
    setTermsOfUse(datasetVersionToMutate, dcterms, licenseToSet);
}
Also used : SwordError(org.swordapp.server.SwordError) List(java.util.List) TermsOfUseAndAccess(edu.harvard.iq.dataverse.TermsOfUseAndAccess)

Aggregations

TermsOfUseAndAccess (edu.harvard.iq.dataverse.TermsOfUseAndAccess)7 DatasetVersion (edu.harvard.iq.dataverse.DatasetVersion)5 Test (org.junit.Test)5 Dataset (edu.harvard.iq.dataverse.Dataset)1 FileMetadata (edu.harvard.iq.dataverse.FileMetadata)1 ParseException (java.text.ParseException)1 List (java.util.List)1 JsonArray (javax.json.JsonArray)1 JsonString (javax.json.JsonString)1 SwordError (org.swordapp.server.SwordError)1