Search in sources :

Example 1 with DatasetVersionDTO

use of edu.harvard.iq.dataverse.api.dto.DatasetVersionDTO in project dataverse by IQSS.

the class DatasetVersionDTOTest method testReadDataSet.

@Test
public void testReadDataSet() {
    try {
        File file = new File("src/test/java/edu/harvard/iq/dataverse/util/json/JsonDatasetVersion.txt");
        String text = new Scanner(file).useDelimiter("\\Z").next();
        Gson gson = new Gson();
        DatasetVersionDTO dto = gson.fromJson(text, DatasetVersionDTO.class);
        HashSet<FieldDTO> author1Fields = new HashSet<>();
        author1Fields.add(FieldDTO.createPrimitiveFieldDTO("authorAffiliation", "Top"));
        author1Fields.add(FieldDTO.createPrimitiveFieldDTO("authorIdentifier", "ellenid"));
        author1Fields.add(FieldDTO.createVocabFieldDTO("authorIdentifierScheme", "ORCID"));
        author1Fields.add(FieldDTO.createPrimitiveFieldDTO("authorName", "Privileged, Pete"));
        HashSet<FieldDTO> author2Fields = new HashSet<>();
        author2Fields.add(FieldDTO.createPrimitiveFieldDTO("authorAffiliation", "Bottom"));
        author2Fields.add(FieldDTO.createPrimitiveFieldDTO("authorIdentifier", "audreyId"));
        author2Fields.add(FieldDTO.createVocabFieldDTO("authorIdentifierScheme", "DAISY"));
        author2Fields.add(FieldDTO.createPrimitiveFieldDTO("authorName", "Awesome, Audrey"));
        List<HashSet<FieldDTO>> authorList = new ArrayList<>();
        authorList.add(author1Fields);
        authorList.add(author2Fields);
        FieldDTO expectedDTO = new FieldDTO();
        expectedDTO.setTypeName("author");
        expectedDTO.setMultipleCompound(authorList);
        FieldDTO authorDTO = dto.getMetadataBlocks().get("citation").getFields().get(1);
        // write both dto's to json to compare them with gson parser
        JsonElement expected = gson.toJsonTree(expectedDTO, FieldDTO.class);
        JsonElement result = gson.toJsonTree(authorDTO);
        Assert.assertEquals(expected, result);
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Also used : Scanner(java.util.Scanner) JsonElement(com.google.gson.JsonElement) DatasetVersionDTO(edu.harvard.iq.dataverse.api.dto.DatasetVersionDTO) ArrayList(java.util.ArrayList) Gson(com.google.gson.Gson) IOException(java.io.IOException) File(java.io.File) FieldDTO(edu.harvard.iq.dataverse.api.dto.FieldDTO) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 2 with DatasetVersionDTO

use of edu.harvard.iq.dataverse.api.dto.DatasetVersionDTO in project dataverse by IQSS.

the class DdiExportUtil method writeDocDescElement.

private static void writeDocDescElement(XMLStreamWriter xmlw, DatasetDTO datasetDto) throws XMLStreamException {
    DatasetVersionDTO version = datasetDto.getDatasetVersion();
    String persistentProtocol = datasetDto.getProtocol();
    String persistentAgency = persistentProtocol;
    // compatibility, we should probably stick with these labels: (-- L.A. 4.5)
    if ("hdl".equals(persistentAgency)) {
        persistentAgency = "handle";
    } else if ("doi".equals(persistentAgency)) {
        persistentAgency = "DOI";
    }
    String persistentAuthority = datasetDto.getAuthority();
    String persistentId = datasetDto.getIdentifier();
    xmlw.writeStartElement("docDscr");
    xmlw.writeStartElement("citation");
    xmlw.writeStartElement("titlStmt");
    writeFullElement(xmlw, "titl", dto2Primitive(version, DatasetFieldConstant.title));
    xmlw.writeStartElement("IDNo");
    writeAttribute(xmlw, "agency", persistentAgency);
    xmlw.writeCharacters(persistentProtocol + ":" + persistentAuthority + "/" + persistentId);
    // IDNo
    xmlw.writeEndElement();
    // titlStmt
    xmlw.writeEndElement();
    xmlw.writeStartElement("distStmt");
    writeFullElement(xmlw, "distrbtr", datasetDto.getPublisher());
    writeFullElement(xmlw, "distDate", datasetDto.getPublicationDate());
    // diststmt
    xmlw.writeEndElement();
    writeVersionStatement(xmlw, version);
    xmlw.writeStartElement("biblCit");
    xmlw.writeCharacters(version.getCitation());
    // biblCit
    xmlw.writeEndElement();
    // citation
    xmlw.writeEndElement();
    // docDscr
    xmlw.writeEndElement();
}
Also used : DatasetVersionDTO(edu.harvard.iq.dataverse.api.dto.DatasetVersionDTO)

Example 3 with DatasetVersionDTO

use of edu.harvard.iq.dataverse.api.dto.DatasetVersionDTO 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 4 with DatasetVersionDTO

use of edu.harvard.iq.dataverse.api.dto.DatasetVersionDTO 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 5 with DatasetVersionDTO

use of edu.harvard.iq.dataverse.api.dto.DatasetVersionDTO in project dataverse by IQSS.

the class DdiExportUtil method createStdyDscr.

/**
 * @todo This is just a stub, copied from DDIExportServiceBean. It should
 * produce valid DDI based on
 * http://guides.dataverse.org/en/latest/developers/tools.html#msv but it is
 * incomplete and will be worked on as part of
 * https://github.com/IQSS/dataverse/issues/2579 . We'll want to reference
 * the DVN 3.x code for creating a complete DDI.
 *
 * @todo Rename this from "study" to "dataset".
 */
private static void createStdyDscr(XMLStreamWriter xmlw, DatasetDTO datasetDto) throws XMLStreamException {
    DatasetVersionDTO version = datasetDto.getDatasetVersion();
    String persistentProtocol = datasetDto.getProtocol();
    String persistentAgency = persistentProtocol;
    // compatibility, we should probably stick with these labels: (-- L.A. 4.5)
    if ("hdl".equals(persistentAgency)) {
        persistentAgency = "handle";
    } else if ("doi".equals(persistentAgency)) {
        persistentAgency = "DOI";
    }
    String persistentAuthority = datasetDto.getAuthority();
    String persistentId = datasetDto.getIdentifier();
    // docDesc Block
    writeDocDescElement(xmlw, datasetDto);
    // stdyDesc Block
    xmlw.writeStartElement("stdyDscr");
    xmlw.writeStartElement("citation");
    xmlw.writeStartElement("titlStmt");
    writeFullElement(xmlw, "titl", dto2Primitive(version, DatasetFieldConstant.title));
    writeFullElement(xmlw, "subTitl", dto2Primitive(version, DatasetFieldConstant.subTitle));
    writeFullElement(xmlw, "altTitl", dto2Primitive(version, DatasetFieldConstant.alternativeTitle));
    xmlw.writeStartElement("IDNo");
    writeAttribute(xmlw, "agency", persistentAgency);
    xmlw.writeCharacters(persistentProtocol + ":" + persistentAuthority + "/" + persistentId);
    // IDNo
    xmlw.writeEndElement();
    // titlStmt
    xmlw.writeEndElement();
    writeAuthorsElement(xmlw, version);
    writeProducersElement(xmlw, version);
    xmlw.writeStartElement("distStmt");
    writeFullElement(xmlw, "distrbtr", datasetDto.getPublisher());
    writeFullElement(xmlw, "distDate", datasetDto.getPublicationDate());
    // diststmt
    xmlw.writeEndElement();
    // citation
    xmlw.writeEndElement();
    // End Citation Block
    // Start Study Info Block
    // Study Info
    xmlw.writeStartElement("stdyInfo");
    // Subject and Keywords
    writeSubjectElement(xmlw, version);
    // Description
    writeAbstractElement(xmlw, version);
    writeFullElement(xmlw, "notes", dto2Primitive(version, DatasetFieldConstant.notesText));
    writeSummaryDescriptionElement(xmlw, version);
    writeRelPublElement(xmlw, version);
    writeOtherIdElement(xmlw, version);
    writeDistributorsElement(xmlw, version);
    writeContactsElement(xmlw, version);
    writeFullElement(xmlw, "depositr", dto2Primitive(version, DatasetFieldConstant.depositor));
    writeFullElement(xmlw, "depDate", dto2Primitive(version, DatasetFieldConstant.dateOfDeposit));
    writeFullElementList(xmlw, "relMat", dto2PrimitiveList(version, DatasetFieldConstant.relatedMaterial));
    writeFullElementList(xmlw, "relStdy", dto2PrimitiveList(version, DatasetFieldConstant.relatedDatasets));
    writeFullElementList(xmlw, "othRefs", dto2PrimitiveList(version, DatasetFieldConstant.otherReferences));
    writeSeriesElement(xmlw, version);
    writeSoftwareElement(xmlw, version);
    writeFullElementList(xmlw, "dataSrc", dto2PrimitiveList(version, DatasetFieldConstant.dataSources));
    writeFullElement(xmlw, "srcOrig", dto2Primitive(version, DatasetFieldConstant.originOfSources));
    writeFullElement(xmlw, "srcChar", dto2Primitive(version, DatasetFieldConstant.characteristicOfSources));
    writeFullElement(xmlw, "srcDocu", dto2Primitive(version, DatasetFieldConstant.accessToSources));
    // stdyInfo
    xmlw.writeEndElement();
    // End Info Block
    // Social Science Metadata block
    writeMethodElement(xmlw, version);
    // Terms of Use and Access
    writeFullElement(xmlw, "useStmt", version.getTermsOfUse());
    writeFullElement(xmlw, "confDec", version.getConfidentialityDeclaration());
    writeFullElement(xmlw, "specPerm", version.getSpecialPermissions());
    writeFullElement(xmlw, "restrctn", version.getRestrictions());
    writeFullElement(xmlw, "citeReq", version.getCitationRequirements());
    writeFullElement(xmlw, "deposReq", version.getDepositorRequirements());
    writeFullElement(xmlw, "dataAccs", version.getTermsOfAccess());
    writeFullElement(xmlw, "accsPlac", version.getDataAccessPlace());
    writeFullElement(xmlw, "conditions", version.getConditions());
    writeFullElement(xmlw, "disclaimer", version.getDisclaimer());
    writeFullElement(xmlw, "origArch", version.getOriginalArchive());
    writeFullElement(xmlw, "avlStatus", version.getAvailabilityStatus());
    writeFullElement(xmlw, "contact", version.getContactForAccess());
    writeFullElement(xmlw, "collSize", version.getSizeOfCollection());
    writeFullElement(xmlw, "complete", version.getStudyCompletion());
    // stdyDscr
    xmlw.writeEndElement();
}
Also used : DatasetVersionDTO(edu.harvard.iq.dataverse.api.dto.DatasetVersionDTO)

Aggregations

DatasetVersionDTO (edu.harvard.iq.dataverse.api.dto.DatasetVersionDTO)5 GlobalId (edu.harvard.iq.dataverse.GlobalId)2 Gson (com.google.gson.Gson)1 JsonElement (com.google.gson.JsonElement)1 FieldDTO (edu.harvard.iq.dataverse.api.dto.FieldDTO)1 File (java.io.File)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 Scanner (java.util.Scanner)1 Test (org.junit.Test)1