Search in sources :

Example 26 with MetadataBlockDTO

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

the class ImportGenericServiceBean method initializeDataset.

// EMK TODO: update unit test so this doesn't have to be public
public DatasetDTO initializeDataset() {
    DatasetDTO datasetDTO = new DatasetDTO();
    DatasetVersionDTO datasetVersionDTO = new DatasetVersionDTO();
    datasetDTO.setDatasetVersion(datasetVersionDTO);
    HashMap<String, MetadataBlockDTO> metadataBlocks = new HashMap<>();
    datasetVersionDTO.setMetadataBlocks(metadataBlocks);
    datasetVersionDTO.getMetadataBlocks().put("citation", new MetadataBlockDTO());
    datasetVersionDTO.getMetadataBlocks().get("citation").setFields(new ArrayList<>());
    datasetVersionDTO.getMetadataBlocks().put("geospatial", new MetadataBlockDTO());
    datasetVersionDTO.getMetadataBlocks().get("geospatial").setFields(new ArrayList<>());
    datasetVersionDTO.getMetadataBlocks().put("social_science", new MetadataBlockDTO());
    datasetVersionDTO.getMetadataBlocks().get("social_science").setFields(new ArrayList<>());
    datasetVersionDTO.getMetadataBlocks().put("astrophysics", new MetadataBlockDTO());
    datasetVersionDTO.getMetadataBlocks().get("astrophysics").setFields(new ArrayList<>());
    return datasetDTO;
}
Also used : MetadataBlockDTO(edu.harvard.iq.dataverse.api.dto.MetadataBlockDTO)

Example 27 with MetadataBlockDTO

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

the class ImportDDIServiceBean method processDDI.

private void processDDI(ImportType importType, XMLStreamReader xmlr, DatasetDTO datasetDTO, Map<String, String> filesMap) throws XMLStreamException, ImportException {
    // make sure we have a codeBook
    // while ( xmlr.next() == XMLStreamConstants.COMMENT ); // skip pre root comments
    xmlr.nextTag();
    xmlr.require(XMLStreamConstants.START_ELEMENT, null, "codeBook");
    // Some DDIs provide an ID in the <codeBook> section.
    // We are going to treat it as just another otherId.
    // (we've seen instances where this ID was the only ID found in
    // in a harvested DDI).
    String codeBookLevelId = xmlr.getAttributeValue(null, "ID");
    // (but first we will parse and process the entire DDI - and only
    // then add this codeBook-level id to the list of identifiers; i.e.,
    // we don't want it to be the first on the list, if one or more
    // ids are available in the studyDscr section - those should take
    // precedence!)
    // In fact, we should only use these IDs when no ID is available down
    // in the study description section!
    processCodeBook(importType, xmlr, datasetDTO, filesMap);
    MetadataBlockDTO citationBlock = datasetDTO.getDatasetVersion().getMetadataBlocks().get("citation");
    if (codeBookLevelId != null && !codeBookLevelId.isEmpty()) {
        if (citationBlock.getField("otherId") == null) {
            // this means no ids were found during the parsing of the
            // study description section. we'll use the one we found in
            // the codeBook entry:
            FieldDTO otherIdValue = FieldDTO.createPrimitiveFieldDTO("otherIdValue", codeBookLevelId);
            FieldDTO otherId = FieldDTO.createCompoundFieldDTO("otherId", otherIdValue);
            citationBlock.getFields().add(otherId);
        }
    }
    if (isHarvestImport(importType)) {
        datasetDTO.getDatasetVersion().setVersionState(VersionState.RELEASED);
    }
}
Also used : MetadataBlockDTO(edu.harvard.iq.dataverse.api.dto.MetadataBlockDTO) FieldDTO(edu.harvard.iq.dataverse.api.dto.FieldDTO)

Example 28 with MetadataBlockDTO

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

the class ImportDDIServiceBean method processTitlStmt.

private void processTitlStmt(XMLStreamReader xmlr, DatasetDTO datasetDTO) throws XMLStreamException, ImportException {
    MetadataBlockDTO citation = datasetDTO.getDatasetVersion().getMetadataBlocks().get("citation");
    List<HashSet<FieldDTO>> otherIds = new ArrayList<>();
    for (int event = xmlr.next(); event != XMLStreamConstants.END_DOCUMENT; event = xmlr.next()) {
        if (event == XMLStreamConstants.START_ELEMENT) {
            if (xmlr.getLocalName().equals("titl")) {
                FieldDTO field = FieldDTO.createPrimitiveFieldDTO("title", parseText(xmlr));
                citation.getFields().add(field);
            } else if (xmlr.getLocalName().equals("subTitl")) {
                FieldDTO field = FieldDTO.createPrimitiveFieldDTO("subtitle", parseText(xmlr));
                citation.getFields().add(field);
            } else if (xmlr.getLocalName().equals("altTitl")) {
                FieldDTO field = FieldDTO.createPrimitiveFieldDTO("alternativeTitle", parseText(xmlr));
                citation.getFields().add(field);
            } else if (xmlr.getLocalName().equals("IDNo")) {
                if (AGENCY_HANDLE.equals(xmlr.getAttributeValue(null, "agency"))) {
                    parseStudyIdHandle(parseText(xmlr), datasetDTO);
                } else if (AGENCY_DOI.equals(xmlr.getAttributeValue(null, "agency"))) {
                    parseStudyIdDOI(parseText(xmlr), datasetDTO);
                } else if (AGENCY_DARA.equals(xmlr.getAttributeValue(null, "agency"))) {
                    /* 
                            da|ra - "Registration agency for social and economic data"
                            (http://www.da-ra.de/en/home/)
                            ICPSR uses da|ra to register their DOIs; so they have agency="dara" 
                            in their IDNo entries. 
                            Also, their DOIs are formatted differently, without the 
                            hdl: prefix. 
                        */
                    parseStudyIdDoiICPSRdara(parseText(xmlr), datasetDTO);
                } else {
                    HashSet<FieldDTO> set = new HashSet<>();
                    addToSet(set, "otherIdAgency", xmlr.getAttributeValue(null, "agency"));
                    addToSet(set, "otherIdValue", parseText(xmlr));
                    if (!set.isEmpty()) {
                        otherIds.add(set);
                    }
                }
            }
        } else if (event == XMLStreamConstants.END_ELEMENT) {
            if (xmlr.getLocalName().equals("titlStmt")) {
                if (otherIds.size() > 0) {
                    citation.addField(FieldDTO.createMultipleCompoundFieldDTO("otherId", otherIds));
                }
                return;
            }
        }
    }
}
Also used : MetadataBlockDTO(edu.harvard.iq.dataverse.api.dto.MetadataBlockDTO) FieldDTO(edu.harvard.iq.dataverse.api.dto.FieldDTO)

Example 29 with MetadataBlockDTO

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

the class ImportDDIServiceBean method processDataColl.

private void processDataColl(XMLStreamReader xmlr, DatasetVersionDTO dvDTO) throws XMLStreamException {
    MetadataBlockDTO socialScience = getSocialScience(dvDTO);
    String collMode = "";
    String timeMeth = "";
    String weight = "";
    for (int event = xmlr.next(); event != XMLStreamConstants.END_DOCUMENT; event = xmlr.next()) {
        if (event == XMLStreamConstants.START_ELEMENT) {
            // timeMethod
            if (xmlr.getLocalName().equals("timeMeth")) {
                String thisValue = parseText(xmlr, "timeMeth");
                if (!StringUtil.isEmpty(thisValue)) {
                    if (!"".equals(timeMeth)) {
                        timeMeth = timeMeth.concat(", ");
                    }
                    timeMeth = timeMeth.concat(thisValue);
                }
            // socialScience.getFields().add(FieldDTO.createPrimitiveFieldDTO("timeMethod", parseText( xmlr, "timeMeth" )));
            } else if (xmlr.getLocalName().equals("dataCollector")) {
                socialScience.getFields().add(FieldDTO.createPrimitiveFieldDTO("dataCollector", parseText(xmlr, "dataCollector")));
            // frequencyOfDataCollection
            } else if (xmlr.getLocalName().equals("frequenc")) {
                socialScience.getFields().add(FieldDTO.createPrimitiveFieldDTO("frequencyOfDataCollection", parseText(xmlr, "frequenc")));
            // samplingProcedure
            } else if (xmlr.getLocalName().equals("sampProc")) {
                socialScience.getFields().add(FieldDTO.createPrimitiveFieldDTO("samplingProcedure", parseText(xmlr, "sampProc")));
            // targetSampleSize
            } else if (xmlr.getLocalName().equals("targetSampleSize")) {
                processTargetSampleSize(xmlr, socialScience);
            // devationsFromSamplingDesign
            } else if (xmlr.getLocalName().equals("deviat")) {
                socialScience.getFields().add(FieldDTO.createPrimitiveFieldDTO("deviationsFromSampleDesign", parseText(xmlr, "deviat")));
            // collectionMode
            } else if (xmlr.getLocalName().equals("collMode")) {
                String thisValue = parseText(xmlr, "collMode");
                if (!StringUtil.isEmpty(thisValue)) {
                    if (!"".equals(collMode)) {
                        collMode = collMode.concat(", ");
                    }
                    collMode = collMode.concat(thisValue);
                }
            // socialScience.getFields().add(FieldDTO.createPrimitiveFieldDTO("collectionMode", parseText( xmlr, "collMode" )));
            // researchInstrument
            } else if (xmlr.getLocalName().equals("resInstru")) {
                socialScience.getFields().add(FieldDTO.createPrimitiveFieldDTO("researchInstrument", parseText(xmlr, "resInstru")));
            } else if (xmlr.getLocalName().equals("sources")) {
                processSources(xmlr, getCitation(dvDTO));
            } else if (xmlr.getLocalName().equals("collSitu")) {
                socialScience.getFields().add(FieldDTO.createPrimitiveFieldDTO("dataCollectionSituation", parseText(xmlr, "collSitu")));
            } else if (xmlr.getLocalName().equals("actMin")) {
                socialScience.getFields().add(FieldDTO.createPrimitiveFieldDTO("actionsToMinimizeLoss", parseText(xmlr, "actMin")));
            } else if (xmlr.getLocalName().equals("ConOps")) {
                socialScience.getFields().add(FieldDTO.createPrimitiveFieldDTO("controlOperations", parseText(xmlr, "ConOps")));
            } else if (xmlr.getLocalName().equals("weight")) {
                String thisValue = parseText(xmlr, "weight");
                if (!StringUtil.isEmpty(thisValue)) {
                    if (!"".equals(weight)) {
                        weight = weight.concat(", ");
                    }
                    weight = weight.concat(thisValue);
                }
            // socialScience.getFields().add(FieldDTO.createPrimitiveFieldDTO("weighting", parseText( xmlr, "weight" )));
            } else if (xmlr.getLocalName().equals("cleanOps")) {
                socialScience.getFields().add(FieldDTO.createPrimitiveFieldDTO("cleaningOperations", parseText(xmlr, "cleanOps")));
            }
        } else if (event == XMLStreamConstants.END_ELEMENT) {
            if (xmlr.getLocalName().equals("dataColl")) {
                if (!StringUtil.isEmpty(timeMeth)) {
                    socialScience.getFields().add(FieldDTO.createPrimitiveFieldDTO("timeMethod", timeMeth));
                }
                if (!StringUtil.isEmpty(collMode)) {
                    socialScience.getFields().add(FieldDTO.createPrimitiveFieldDTO("collectionMode", collMode));
                }
                if (!StringUtil.isEmpty(weight)) {
                    socialScience.getFields().add(FieldDTO.createPrimitiveFieldDTO("weighting", weight));
                }
                return;
            }
        }
    }
}
Also used : MetadataBlockDTO(edu.harvard.iq.dataverse.api.dto.MetadataBlockDTO)

Example 30 with MetadataBlockDTO

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

the class ImportDDIServiceBean method addNote.

private void addNote(String noteText, DatasetVersionDTO dvDTO) {
    MetadataBlockDTO citation = getCitation(dvDTO);
    FieldDTO field = citation.getField("notesText");
    if (field == null) {
        field = FieldDTO.createPrimitiveFieldDTO("notesText", "");
        citation.getFields().add(field);
    }
    String noteValue = field.getSinglePrimitive();
    noteValue += noteText;
    field.setSinglePrimitive(noteValue);
}
Also used : MetadataBlockDTO(edu.harvard.iq.dataverse.api.dto.MetadataBlockDTO) FieldDTO(edu.harvard.iq.dataverse.api.dto.FieldDTO)

Aggregations

MetadataBlockDTO (edu.harvard.iq.dataverse.api.dto.MetadataBlockDTO)32 FieldDTO (edu.harvard.iq.dataverse.api.dto.FieldDTO)26 Map (java.util.Map)22 DatasetFieldType (edu.harvard.iq.dataverse.DatasetFieldType)2 DatasetFieldCompoundValue (edu.harvard.iq.dataverse.DatasetFieldCompoundValue)1 ForeignMetadataFieldMapping (edu.harvard.iq.dataverse.ForeignMetadataFieldMapping)1 JsonParseException (edu.harvard.iq.dataverse.util.json.JsonParseException)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 EJBException (javax.ejb.EJBException)1 NoResultException (javax.persistence.NoResultException)1 XMLStreamException (javax.xml.stream.XMLStreamException)1