Search in sources :

Example 31 with FieldDTO

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

Example 32 with FieldDTO

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

the class ImportDDIServiceBean method processSumDscr.

private void processSumDscr(XMLStreamReader xmlr, DatasetVersionDTO dvDTO) throws XMLStreamException {
    List<String> geoUnit = new ArrayList<>();
    List<String> unitOfAnalysis = new ArrayList<>();
    List<String> universe = new ArrayList<>();
    List<String> kindOfData = new ArrayList<>();
    List<HashSet<FieldDTO>> geoBoundBox = new ArrayList<>();
    List<HashSet<FieldDTO>> geoCoverages = new ArrayList<>();
    FieldDTO timePeriodStart = null;
    FieldDTO timePeriodEnd = null;
    FieldDTO dateOfCollectionStart = null;
    FieldDTO dateOfCollectionEnd = null;
    for (int event = xmlr.next(); event != XMLStreamConstants.END_DOCUMENT; event = xmlr.next()) {
        if (event == XMLStreamConstants.START_ELEMENT) {
            if (xmlr.getLocalName().equals("timePrd")) {
                String eventAttr = xmlr.getAttributeValue(null, "event");
                if (eventAttr == null || EVENT_SINGLE.equalsIgnoreCase(eventAttr) || EVENT_START.equalsIgnoreCase(eventAttr)) {
                    timePeriodStart = FieldDTO.createPrimitiveFieldDTO("timePeriodCoveredStart", parseDate(xmlr, "timePrd"));
                } else if (EVENT_END.equals(eventAttr)) {
                    timePeriodEnd = FieldDTO.createPrimitiveFieldDTO("timePeriodCoveredEnd", parseDate(xmlr, "timePrd"));
                }
            } else if (xmlr.getLocalName().equals("collDate")) {
                String eventAttr = xmlr.getAttributeValue(null, "event");
                if (eventAttr == null || EVENT_SINGLE.equalsIgnoreCase(eventAttr) || EVENT_START.equalsIgnoreCase(eventAttr)) {
                    dateOfCollectionStart = FieldDTO.createPrimitiveFieldDTO("dateOfCollectionStart", parseDate(xmlr, "collDate"));
                } else if (EVENT_END.equals(eventAttr)) {
                    dateOfCollectionEnd = FieldDTO.createPrimitiveFieldDTO("dateOfCollectionEnd", parseDate(xmlr, "collDate"));
                }
            } else if (xmlr.getLocalName().equals("nation")) {
                HashSet<FieldDTO> set = new HashSet<>();
                set.add(FieldDTO.createVocabFieldDTO("country", parseText(xmlr)));
                geoCoverages.add(set);
            } else if (xmlr.getLocalName().equals("geogCover")) {
                HashSet<FieldDTO> set = new HashSet<>();
                set.add(FieldDTO.createPrimitiveFieldDTO("otherGeographicCoverage", parseText(xmlr)));
                geoCoverages.add(set);
            } else if (xmlr.getLocalName().equals("geogUnit")) {
                geoUnit.add(parseText(xmlr));
            } else if (xmlr.getLocalName().equals("geoBndBox")) {
                geoBoundBox.add(processGeoBndBox(xmlr));
            } else if (xmlr.getLocalName().equals("anlyUnit")) {
                unitOfAnalysis.add(parseText(xmlr, "anlyUnit"));
            } else if (xmlr.getLocalName().equals("universe")) {
                universe.add(parseText(xmlr, "universe"));
            } else if (xmlr.getLocalName().equals("dataKind")) {
                kindOfData.add(parseText(xmlr));
            }
        } else if (event == XMLStreamConstants.END_ELEMENT) {
            if (xmlr.getLocalName().equals("sumDscr")) {
                if (timePeriodStart != null || timePeriodEnd != null) {
                    getCitation(dvDTO).addField(FieldDTO.createMultipleCompoundFieldDTO("timePeriodCovered", timePeriodStart, timePeriodEnd));
                }
                if (dateOfCollectionStart != null || dateOfCollectionEnd != null) {
                    getCitation(dvDTO).addField(FieldDTO.createMultipleCompoundFieldDTO("dateOfCollection", dateOfCollectionStart, dateOfCollectionEnd));
                }
                if (geoUnit.size() > 0) {
                    getGeospatial(dvDTO).addField(FieldDTO.createMultiplePrimitiveFieldDTO("geographicUnit", geoUnit));
                }
                if (unitOfAnalysis.size() > 0) {
                    getSocialScience(dvDTO).addField(FieldDTO.createMultiplePrimitiveFieldDTO("unitOfAnalysis", unitOfAnalysis));
                }
                if (universe.size() > 0) {
                    getSocialScience(dvDTO).addField(FieldDTO.createMultiplePrimitiveFieldDTO("universe", universe));
                }
                if (kindOfData.size() > 0) {
                    getCitation(dvDTO).addField(FieldDTO.createMultiplePrimitiveFieldDTO("kindOfData", kindOfData));
                }
                if (geoCoverages.size() > 0) {
                    getGeospatial(dvDTO).addField(FieldDTO.createMultipleCompoundFieldDTO("geographicCoverage", geoCoverages));
                }
                if (geoBoundBox.size() > 0) {
                    getGeospatial(dvDTO).addField(FieldDTO.createMultipleCompoundFieldDTO("geographicBoundingBox", geoBoundBox));
                }
                return;
            }
        }
    }
}
Also used : 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