Search in sources :

Example 26 with FieldDTO

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

the class DdiExportUtil method writeSubjectElement.

private static void writeSubjectElement(XMLStreamWriter xmlw, DatasetVersionDTO datasetVersionDTO) throws XMLStreamException {
    // Key Words and Topic Classification
    xmlw.writeStartElement("subject");
    for (Map.Entry<String, MetadataBlockDTO> entry : datasetVersionDTO.getMetadataBlocks().entrySet()) {
        String key = entry.getKey();
        MetadataBlockDTO value = entry.getValue();
        if ("citation".equals(key)) {
            for (FieldDTO fieldDTO : value.getFields()) {
                if (DatasetFieldConstant.subject.equals(fieldDTO.getTypeName())) {
                    for (String subject : fieldDTO.getMultipleVocab()) {
                        xmlw.writeStartElement("keyword");
                        xmlw.writeCharacters(subject);
                        // Keyword
                        xmlw.writeEndElement();
                    }
                }
                if (DatasetFieldConstant.keyword.equals(fieldDTO.getTypeName())) {
                    for (HashSet<FieldDTO> foo : fieldDTO.getMultipleCompound()) {
                        String keywordValue = "";
                        String keywordVocab = "";
                        String keywordURI = "";
                        for (Iterator<FieldDTO> iterator = foo.iterator(); iterator.hasNext(); ) {
                            FieldDTO next = iterator.next();
                            if (DatasetFieldConstant.keywordValue.equals(next.getTypeName())) {
                                keywordValue = next.getSinglePrimitive();
                            }
                            if (DatasetFieldConstant.keywordVocab.equals(next.getTypeName())) {
                                keywordVocab = next.getSinglePrimitive();
                            }
                            if (DatasetFieldConstant.keywordVocabURI.equals(next.getTypeName())) {
                                keywordURI = next.getSinglePrimitive();
                            }
                        }
                        if (!keywordValue.isEmpty()) {
                            xmlw.writeStartElement("keyword");
                            if (!keywordVocab.isEmpty()) {
                                writeAttribute(xmlw, "vocab", keywordVocab);
                            }
                            if (!keywordURI.isEmpty()) {
                                writeAttribute(xmlw, "URI", keywordURI);
                            }
                            xmlw.writeCharacters(keywordValue);
                            // Keyword
                            xmlw.writeEndElement();
                        }
                    }
                }
                if (DatasetFieldConstant.topicClassification.equals(fieldDTO.getTypeName())) {
                    for (HashSet<FieldDTO> foo : fieldDTO.getMultipleCompound()) {
                        String topicClassificationValue = "";
                        String topicClassificationVocab = "";
                        String topicClassificationURI = "";
                        for (Iterator<FieldDTO> iterator = foo.iterator(); iterator.hasNext(); ) {
                            FieldDTO next = iterator.next();
                            if (DatasetFieldConstant.topicClassValue.equals(next.getTypeName())) {
                                topicClassificationValue = next.getSinglePrimitive();
                            }
                            if (DatasetFieldConstant.topicClassVocab.equals(next.getTypeName())) {
                                topicClassificationVocab = next.getSinglePrimitive();
                            }
                            if (DatasetFieldConstant.topicClassVocabURI.equals(next.getTypeName())) {
                                topicClassificationURI = next.getSinglePrimitive();
                            }
                        }
                        if (!topicClassificationValue.isEmpty()) {
                            xmlw.writeStartElement("topcClas");
                            if (!topicClassificationVocab.isEmpty()) {
                                writeAttribute(xmlw, "vocab", topicClassificationVocab);
                            }
                            if (!topicClassificationURI.isEmpty()) {
                                writeAttribute(xmlw, "URI", topicClassificationURI);
                            }
                            xmlw.writeCharacters(topicClassificationValue);
                            // topcClas
                            xmlw.writeEndElement();
                        }
                    }
                }
            }
        }
    }
    // subject
    xmlw.writeEndElement();
}
Also used : MetadataBlockDTO(edu.harvard.iq.dataverse.api.dto.MetadataBlockDTO) Map(java.util.Map) FieldDTO(edu.harvard.iq.dataverse.api.dto.FieldDTO)

Example 27 with FieldDTO

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

the class ImportGenericServiceBean method getOtherIdFromDTO.

private String getOtherIdFromDTO(DatasetVersionDTO datasetVersionDTO) {
    for (Map.Entry<String, MetadataBlockDTO> entry : datasetVersionDTO.getMetadataBlocks().entrySet()) {
        String key = entry.getKey();
        MetadataBlockDTO value = entry.getValue();
        if ("citation".equals(key)) {
            for (FieldDTO fieldDTO : value.getFields()) {
                if (DatasetFieldConstant.otherId.equals(fieldDTO.getTypeName())) {
                    String otherId = "";
                    for (HashSet<FieldDTO> foo : fieldDTO.getMultipleCompound()) {
                        for (FieldDTO next : foo) {
                            if (DatasetFieldConstant.otherIdValue.equals(next.getTypeName())) {
                                otherId = next.getSinglePrimitive();
                            }
                        }
                        if (!otherId.isEmpty()) {
                            return otherId;
                        }
                    }
                }
            }
        }
    }
    return null;
}
Also used : MetadataBlockDTO(edu.harvard.iq.dataverse.api.dto.MetadataBlockDTO) Map(java.util.Map) FieldDTO(edu.harvard.iq.dataverse.api.dto.FieldDTO)

Example 28 with FieldDTO

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

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

the class ImportDDIServiceBean method processSerStmt.

private void processSerStmt(XMLStreamReader xmlr, MetadataBlockDTO citation) throws XMLStreamException {
    FieldDTO seriesName = null;
    FieldDTO seriesInformation = null;
    for (int event = xmlr.next(); event != XMLStreamConstants.END_DOCUMENT; event = xmlr.next()) {
        if (event == XMLStreamConstants.START_ELEMENT) {
            if (xmlr.getLocalName().equals("serName")) {
                seriesName = FieldDTO.createPrimitiveFieldDTO("seriesName", parseText(xmlr));
            } else if (xmlr.getLocalName().equals("serInfo")) {
                seriesInformation = FieldDTO.createPrimitiveFieldDTO("seriesInformation", parseText(xmlr));
            }
        } else if (event == XMLStreamConstants.END_ELEMENT) {
            if (xmlr.getLocalName().equals("serStmt")) {
                citation.getFields().add(FieldDTO.createCompoundFieldDTO("series", seriesName, seriesInformation));
                return;
            }
        }
    }
}
Also used : FieldDTO(edu.harvard.iq.dataverse.api.dto.FieldDTO)

Example 30 with FieldDTO

use of edu.harvard.iq.dataverse.api.dto.FieldDTO 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)

Aggregations

FieldDTO (edu.harvard.iq.dataverse.api.dto.FieldDTO)32 MetadataBlockDTO (edu.harvard.iq.dataverse.api.dto.MetadataBlockDTO)26 Map (java.util.Map)22 Gson (com.google.gson.Gson)2 DatasetFieldCompoundValue (edu.harvard.iq.dataverse.DatasetFieldCompoundValue)2 DatasetFieldType (edu.harvard.iq.dataverse.DatasetFieldType)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 JsonElement (com.google.gson.JsonElement)1 DatasetField (edu.harvard.iq.dataverse.DatasetField)1 ForeignMetadataFieldMapping (edu.harvard.iq.dataverse.ForeignMetadataFieldMapping)1 DatasetVersionDTO (edu.harvard.iq.dataverse.api.dto.DatasetVersionDTO)1 JsonParseException (edu.harvard.iq.dataverse.util.json.JsonParseException)1 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 StringReader (java.io.StringReader)1 Scanner (java.util.Scanner)1 EJBException (javax.ejb.EJBException)1 JsonObject (javax.json.JsonObject)1