/**
   * @param study - study that we are exporting
   * @param out
   * @throws IOException
   */
  @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
  public void exportStudy(Study study, OutputStream out) throws IOException {
    if (study.getReleasedVersion() == null) {
      throw new IllegalArgumentException(
          "Study does not have released version, study.id = " + study.getId());
    }
    Metadata metadata = study.getReleasedVersion().getMetadata();

    MarcFactory factory = MarcFactory.newInstance();
    Record record = factory.newRecord();

    DataField title = factory.newDataField("245", '0', ' ');
    title.addSubfield(factory.newSubfield('a', metadata.getTitle()));
    if (!StringUtil.isEmpty(metadata.getAuthorsStr())) {
      title.addSubfield(factory.newSubfield('c', metadata.getAuthorsStr()));
    }
    if (!StringUtil.isEmpty(metadata.getDistributionDate())) {
      title.addSubfield(factory.newSubfield('s', metadata.getDistributionDate()));
    }
    record.addVariableField(title);

    DataField globalId = factory.newDataField("440", ' ', ' ');
    globalId.addSubfield(factory.newSubfield('v', study.getGlobalId()));
    record.addVariableField(globalId);

    for (StudyOtherId studyOtherId : metadata.getStudyOtherIds()) {
      DataField otherId = factory.newDataField("440", ' ', ' ');
      otherId.addSubfield(factory.newSubfield('v', studyOtherId.getOtherId()));
      record.addVariableField(otherId);
    }
    for (StudyAbstract studyAbstract : metadata.getStudyAbstracts()) {
      DataField abstractField = factory.newDataField("520", ' ', ' ');
      abstractField.addSubfield(factory.newSubfield('a', studyAbstract.getText()));
      record.addVariableField(abstractField);
    }

    DataField handle = factory.newDataField("856", ' ', ' ');
    handle.addSubfield(factory.newSubfield('u', study.getHandleURL()));
    record.addVariableField(handle);

    DataField dataverseUrl = factory.newDataField("535", ' ', ' ');
    dataverseUrl.addSubfield(
        factory.newSubfield(
            'd',
            "http://" + PropertyUtil.getHostUrl() + "/dvn/study?globalId=" + study.getGlobalId()));
    record.addVariableField(dataverseUrl);

    for (StudyTopicClass studyTopicClass : metadata.getStudyTopicClasses()) {
      DataField topicClass = factory.newDataField("650", ' ', ' ');
      topicClass.addSubfield(factory.newSubfield('a', studyTopicClass.getValue()));
      record.addVariableField(topicClass);
    }
    MarcStreamWriter writer = new MarcStreamWriter(out);

    writer.write(record);

    out.flush();
  }
Beispiel #2
0
  /**
   * @param xmlw - stream to write DublinCore XML for the study
   * @param study - get metadata from released version of the study.
   * @throws XMLStreamException
   * @throws IllegalArgumentException - if study does not have a released version.
   */
  public void createDC(XMLStreamWriter xmlw, Study study) throws XMLStreamException {
    if (study.getReleasedVersion() == null) {
      throw new IllegalArgumentException(
          "Study does not have released version, study.id = " + study.getId());
    }
    Metadata metadata = study.getReleasedVersion().getMetadata();

    xmlw.writeStartElement("oai_dc:dc");
    xmlw.writeAttribute("xmlns:oai_dc", "http://www.openarchives.org/OAI/2.0/oai_dc/");
    xmlw.writeAttribute("xmlns:dc", "http://purl.org/dc/elements/1.1/");
    xmlw.writeAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
    xmlw.writeAttribute(
        "xsi:schemaLocation",
        "http://www.openarchives.org/OAI/2.0/oai_dc/    http://www.openarchives.org/OAI/2.0/oai_dc.xsd");

    // Title
    xmlw.writeStartElement("dc:title");
    xmlw.writeCharacters(metadata.getTitle());
    xmlw.writeEndElement();

    // Identifier
    xmlw.writeStartElement("dc:identifier");
    xmlw.writeCharacters(study.getPersistentURL());
    xmlw.writeEndElement();

    // Creator
    for (StudyAuthor author : metadata.getStudyAuthors()) {
      xmlw.writeStartElement("dc:creator");
      xmlw.writeCharacters(author.getName());
      xmlw.writeEndElement();
    }

    // Publisher
    for (StudyProducer producer : metadata.getStudyProducers()) {
      xmlw.writeStartElement("dc:publisher");
      xmlw.writeCharacters(producer.getName());
      xmlw.writeEndElement();
    }

    // Date
    if (!StringUtil.isEmpty(metadata.getProductionDate())) {
      xmlw.writeStartElement("dc:date");
      xmlw.writeCharacters(metadata.getProductionDate());
      xmlw.writeEndElement();
    }

    // Relation
    for (StudyRelPublication rp : metadata.getStudyRelPublications()) {
      xmlw.writeStartElement("dc:relation");
      xmlw.writeCharacters(rp.getText());
      xmlw.writeEndElement();
    }
    for (StudyRelMaterial rm : metadata.getStudyRelMaterials()) {
      xmlw.writeStartElement("dc:relation");
      xmlw.writeCharacters(rm.getText());
      xmlw.writeEndElement();
    }
    for (StudyRelStudy rs : metadata.getStudyRelStudies()) {
      xmlw.writeStartElement("dc:relation");
      xmlw.writeCharacters(rs.getText());
      xmlw.writeEndElement();
    }
    for (StudyOtherRef or : metadata.getStudyOtherRefs()) {
      xmlw.writeStartElement("dc:relation");
      xmlw.writeCharacters(or.getText());
      xmlw.writeEndElement();
    }

    // Subject
    for (StudyKeyword keyword : metadata.getStudyKeywords()) {
      xmlw.writeStartElement("dc:subject");
      xmlw.writeCharacters(keyword.getValue());
      xmlw.writeEndElement();
    }
    for (StudyTopicClass topicClass : metadata.getStudyTopicClasses()) {
      xmlw.writeStartElement("dc:subject");
      xmlw.writeCharacters(topicClass.getValue());
      xmlw.writeEndElement();
    }

    // Description
    for (StudyAbstract studyAbstract : metadata.getStudyAbstracts()) {
      xmlw.writeStartElement("dc:description");
      xmlw.writeCharacters(studyAbstract.getText());
      xmlw.writeEndElement();
    }
    xmlw.writeStartElement("dc:description");
    xmlw.writeCharacters("Citation: " + metadata.getTextCitation());
    xmlw.writeEndElement();

    // Coverage
    writeCoverage(xmlw, metadata);

    // Type
    if (!StringUtil.isEmpty(metadata.getKindOfData())) {
      xmlw.writeStartElement("dc:type");
      xmlw.writeCharacters(metadata.getKindOfData());
      xmlw.writeEndElement();
    }

    // Source
    if (!StringUtil.isEmpty(metadata.getDataSources())) {
      xmlw.writeStartElement("dc:source");
      xmlw.writeCharacters(metadata.getDataSources());
      xmlw.writeEndElement();
    }

    // Rights
    writeRights(xmlw, metadata);

    // End root element
    xmlw.writeEndElement();
  }