Search in sources :

Example 1 with GlobalId

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

the class DublinCoreExportUtil method createOAIDC.

private static void createOAIDC(XMLStreamWriter xmlw, DatasetDTO datasetDto, String dcFlavor) throws XMLStreamException {
    DatasetVersionDTO version = datasetDto.getDatasetVersion();
    String persistentAgency = datasetDto.getProtocol();
    String persistentAuthority = datasetDto.getAuthority();
    String persistentId = datasetDto.getIdentifier();
    GlobalId globalId = new GlobalId(persistentAgency, persistentAuthority, persistentId);
    writeFullElement(xmlw, dcFlavor + ":" + "title", dto2Primitive(version, DatasetFieldConstant.title));
    xmlw.writeStartElement(dcFlavor + ":" + "identifier");
    xmlw.writeCharacters(globalId.toURL().toString());
    // decterms:identifier
    xmlw.writeEndElement();
    // creator
    writeAuthorsElement(xmlw, version, dcFlavor);
    writeFullElement(xmlw, dcFlavor + ":" + "publisher", datasetDto.getPublisher());
    // Description
    writeAbstractElement(xmlw, version, dcFlavor);
    // Subjects and Key Words
    writeSubjectElement(xmlw, version, dcFlavor);
    writeFullElementList(xmlw, dcFlavor + ":" + "language", dto2PrimitiveList(version, DatasetFieldConstant.language));
    writeFullElement(xmlw, dcFlavor + ":" + "date", dto2Primitive(version, DatasetFieldConstant.productionDate));
    writeFullElement(xmlw, dcFlavor + ":" + "contributor", dto2Primitive(version, DatasetFieldConstant.depositor));
    writeContributorElement(xmlw, version, dcFlavor);
    writeFullElementList(xmlw, dcFlavor + ":" + "relation", dto2PrimitiveList(version, DatasetFieldConstant.relatedDatasets));
    writeFullElementList(xmlw, dcFlavor + ":" + "type", dto2PrimitiveList(version, DatasetFieldConstant.kindOfData));
    writeFullElementList(xmlw, dcFlavor + ":" + "source", dto2PrimitiveList(version, DatasetFieldConstant.dataSources));
}
Also used : DatasetVersionDTO(edu.harvard.iq.dataverse.api.dto.DatasetVersionDTO) GlobalId(edu.harvard.iq.dataverse.GlobalId)

Example 2 with GlobalId

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

the class DublinCoreExportUtil method createDC.

// UPDATED by rmo-cdsp:
// If the requested flavor is "OAI_DC" (the minimal, original 15 field format),
// we shuld NOT be exporting the extended, DCTERMS fields (aka not createDC)
// - such as, for example, "dateSubmitted" ... (4.5.1?)
// -- L.A.
// but use createOAIDC instead (the minimal, original 15 field format)
private static void createDC(XMLStreamWriter xmlw, DatasetDTO datasetDto, String dcFlavor) throws XMLStreamException {
    DatasetVersionDTO version = datasetDto.getDatasetVersion();
    String persistentAgency = datasetDto.getProtocol();
    String persistentAuthority = datasetDto.getAuthority();
    String persistentId = datasetDto.getIdentifier();
    GlobalId globalId = new GlobalId(persistentAgency, persistentAuthority, persistentId);
    writeFullElement(xmlw, dcFlavor + ":" + "title", dto2Primitive(version, DatasetFieldConstant.title));
    xmlw.writeStartElement(dcFlavor + ":" + "identifier");
    xmlw.writeCharacters(globalId.toURL().toString());
    // decterms:identifier
    xmlw.writeEndElement();
    writeAuthorsElement(xmlw, version, dcFlavor);
    writeFullElement(xmlw, dcFlavor + ":" + "publisher", datasetDto.getPublisher());
    writeFullElement(xmlw, dcFlavor + ":" + "issued", datasetDto.getPublicationDate());
    writeFullElement(xmlw, dcFlavor + ":" + "modified", datasetDto.getDatasetVersion().getLastUpdateTime());
    // Description
    writeAbstractElement(xmlw, version, dcFlavor);
    // Subjects and Key Words
    writeSubjectElement(xmlw, version, dcFlavor);
    writeFullElementList(xmlw, dcFlavor + ":" + "language", dto2PrimitiveList(version, DatasetFieldConstant.language));
    writeRelPublElement(xmlw, version, dcFlavor);
    writeFullElement(xmlw, dcFlavor + ":" + "date", dto2Primitive(version, DatasetFieldConstant.productionDate));
    writeFullElement(xmlw, dcFlavor + ":" + "contributor", dto2Primitive(version, DatasetFieldConstant.depositor));
    writeContributorElement(xmlw, version, dcFlavor);
    writeFullElement(xmlw, dcFlavor + ":" + "dateSubmitted", dto2Primitive(version, DatasetFieldConstant.dateOfDeposit));
    writeTimeElements(xmlw, version, dcFlavor);
    writeFullElementList(xmlw, dcFlavor + ":" + "relation", dto2PrimitiveList(version, DatasetFieldConstant.relatedDatasets));
    writeFullElementList(xmlw, dcFlavor + ":" + "type", dto2PrimitiveList(version, DatasetFieldConstant.kindOfData));
    writeFullElementList(xmlw, dcFlavor + ":" + "source", dto2PrimitiveList(version, DatasetFieldConstant.dataSources));
    // Geo Elements
    writeSpatialElements(xmlw, version, dcFlavor);
    // License and Terms
    writeFullElement(xmlw, dcFlavor + ":" + "license", version.getLicense());
    writeFullElement(xmlw, dcFlavor + ":" + "rights", version.getTermsOfUse());
    writeFullElement(xmlw, dcFlavor + ":" + "rights", version.getRestrictions());
}
Also used : DatasetVersionDTO(edu.harvard.iq.dataverse.api.dto.DatasetVersionDTO) GlobalId(edu.harvard.iq.dataverse.GlobalId)

Example 3 with GlobalId

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

the class SwordIT method testCreateAndDeleteDatasetInRoot.

/**
 * This test requires the root dataverse to have been published already. We
 * assume the default, out-of-the-box configuration that the answer to the
 * question "What should be the default role for someone adding datasets to
 * this dataverse?" is "Contributor" rather than "Curator". We are
 * permitting both dataverse and datasets to be created in the root
 * dataverse (:authenticated-users gets fullContributor at root).
 */
@Test
public void testCreateAndDeleteDatasetInRoot() {
    Response createUser = UtilIT.createRandomUser();
    String username = UtilIT.getUsernameFromResponse(createUser);
    String apiTokenContributor = UtilIT.getApiTokenFromResponse(createUser);
    String datasetTitle = "Dataset In Root";
    Response randomUnprivUser = UtilIT.createRandomUser();
    String apiTokenNoPrivs = UtilIT.getApiTokenFromResponse(randomUnprivUser);
    String usernameNoPrivs = UtilIT.getUsernameFromResponse(randomUnprivUser);
    String persistentId = null;
    Integer datasetId = null;
    String protocol;
    String authority;
    String identifier = null;
    Response createDataset = UtilIT.createDatasetViaSwordApi(rootDataverseAlias, datasetTitle, apiTokenContributor);
    createDataset.prettyPrint();
    createDataset.then().assertThat().statusCode(CREATED.getStatusCode()).body("entry.treatment", equalTo("no treatment information available"));
    persistentId = UtilIT.getDatasetPersistentIdFromResponse(createDataset);
    GlobalId globalId = new GlobalId(persistentId);
    protocol = globalId.getProtocol();
    authority = globalId.getAuthority();
    identifier = globalId.getIdentifier();
    Response listDatasetsAtRoot = UtilIT.listDatasetsViaSword(rootDataverseAlias, apiTokenContributor);
    listDatasetsAtRoot.prettyPrint();
    listDatasetsAtRoot.then().assertThat().statusCode(OK.getStatusCode());
    assertTrue(listDatasetsAtRoot.body().asString().contains(identifier));
    Response listDatasetsAtRootNoPrivs = UtilIT.listDatasetsViaSword(rootDataverseAlias, apiTokenNoPrivs);
    listDatasetsAtRootNoPrivs.prettyPrint();
    listDatasetsAtRootNoPrivs.then().assertThat().statusCode(OK.getStatusCode()).body("feed.dataverseHasBeenReleased", equalTo("true"));
    /**
     * ... but not just anyone should be able to see your dataset, only
     * those with edit access.
     */
    assertFalse(listDatasetsAtRootNoPrivs.body().asString().contains(identifier));
    Response atomEntry = UtilIT.getSwordAtomEntry(persistentId, apiTokenContributor);
    atomEntry.prettyPrint();
    atomEntry.then().assertThat().statusCode(OK.getStatusCode()).body("entry.id", endsWith(persistentId));
    Response uploadFile = UtilIT.uploadRandomFile(persistentId, apiTokenContributor);
    uploadFile.prettyPrint();
    uploadFile.then().assertThat().statusCode(CREATED.getStatusCode());
    Response statementContainingFile = UtilIT.getSwordStatement(persistentId, apiTokenContributor);
    statementContainingFile.prettyPrint();
    statementContainingFile.then().assertThat().statusCode(OK.getStatusCode()).body("feed.id", endsWith(persistentId)).body("feed.title", equalTo(datasetTitle)).body("feed.author.name", equalTo("Lastname, Firstname")).body("feed.entry[0].summary", equalTo("Resource Part")).body("feed.entry[0].id", endsWith("trees.png"));
    String firstAndOnlyFileIdAsString = statementContainingFile.getBody().xmlPath().get("feed.entry[0].id").toString().split("/")[10];
    Response deleteFile = UtilIT.deleteFile(Integer.parseInt(firstAndOnlyFileIdAsString), apiTokenContributor);
    deleteFile.prettyPrint();
    deleteFile.then().assertThat().statusCode(NO_CONTENT.getStatusCode());
    Response statementWithNoFiles = UtilIT.getSwordStatement(persistentId, apiTokenContributor);
    statementWithNoFiles.prettyPrint();
    statementWithNoFiles.then().assertThat().statusCode(OK.getStatusCode()).body("feed.title", equalTo(datasetTitle));
    try {
        String attemptToGetFileId = statementWithNoFiles.getBody().xmlPath().get("feed.entry[0].id").toString().split("/")[10];
        System.out.println("attemptToGetFileId: " + attemptToGetFileId);
        assertNull(attemptToGetFileId);
    } catch (Exception ex) {
        System.out.println("We expect an exception here because we can no longer find the file because deleted it: " + ex);
        assertTrue(ex.getClass().getName().equals(ArrayIndexOutOfBoundsException.class.getName()));
    }
    String newTitle = "A New Hope";
    Response updateTitle = UtilIT.updateDatasetTitleViaSword(persistentId, newTitle, apiTokenContributor);
    updateTitle.prettyPrint();
    updateTitle.then().assertThat().statusCode(OK.getStatusCode()).body("entry.treatment", equalTo("no treatment information available"));
    Response statementWithUpdatedTitle = UtilIT.getSwordStatement(persistentId, apiTokenContributor);
    statementWithUpdatedTitle.prettyPrint();
    statementWithUpdatedTitle.then().assertThat().statusCode(OK.getStatusCode()).body("feed.title", equalTo(newTitle));
    Response nativeGetToGetId = UtilIT.nativeGetUsingPersistentId(persistentId, apiTokenContributor);
    nativeGetToGetId.then().assertThat().statusCode(OK.getStatusCode());
    datasetId = JsonPath.from(nativeGetToGetId.body().asString()).getInt("data.id");
    Response listDatasetsAtRootAsSuperuser = UtilIT.listDatasetsViaSword(rootDataverseAlias, apiTokenSuperuser);
    listDatasetsAtRootAsSuperuser.prettyPrint();
    listDatasetsAtRootAsSuperuser.then().assertThat().statusCode(OK.getStatusCode());
    assertTrue(listDatasetsAtRootAsSuperuser.body().asString().contains(identifier));
    Response rootDataverseContents = UtilIT.showDataverseContents(rootDataverseAlias, apiTokenContributor);
    rootDataverseContents.prettyPrint();
    logger.info("We expect to find \"" + identifier + "\" from the persistent ID to be present.");
    assertTrue(rootDataverseContents.body().asString().contains(identifier));
    Response publishShouldFailForContributorViaSword = UtilIT.publishDatasetViaSword(persistentId, apiTokenContributor);
    publishShouldFailForContributorViaSword.prettyPrint();
    publishShouldFailForContributorViaSword.then().assertThat().statusCode(BAD_REQUEST.getStatusCode()).body("error.summary", equalTo("User " + username + " " + username + " is not authorized to modify dataverse " + rootDataverseAlias));
    Response publishShouldFailForContributorViaNative = UtilIT.publishDatasetViaNativeApi(datasetId, "major", apiTokenContributor);
    publishShouldFailForContributorViaNative.prettyPrint();
    publishShouldFailForContributorViaNative.then().assertThat().statusCode(UNAUTHORIZED.getStatusCode()).body("message", equalTo("User @" + username + " is not permitted to perform requested action."));
    Response deleteDatasetResponse = UtilIT.deleteLatestDatasetVersionViaSwordApi(persistentId, apiTokenContributor);
    deleteDatasetResponse.prettyPrint();
    deleteDatasetResponse.then().assertThat().statusCode(NO_CONTENT.getStatusCode());
    UtilIT.deleteUser(username);
    UtilIT.deleteUser(usernameNoPrivs);
// UtilIT.listDatasetsViaSword(rootDataverseAlias, apiTokenSuperuser).prettyPrint();
}
Also used : Response(com.jayway.restassured.response.Response) GlobalId(edu.harvard.iq.dataverse.GlobalId) Test(org.junit.Test)

Aggregations

GlobalId (edu.harvard.iq.dataverse.GlobalId)3 DatasetVersionDTO (edu.harvard.iq.dataverse.api.dto.DatasetVersionDTO)2 Response (com.jayway.restassured.response.Response)1 Test (org.junit.Test)1