/**
   * @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();
  }
Example #2
0
  /**
   * Tests creating a new {@link Record}.
   *
   * @throws Exception
   */
  @Test
  public void testCreateRecord() throws Exception {
    MarcFactory factory = MarcFactory.newInstance();
    Record record = factory.newRecord("00000cam a2200000 a 4500");
    assertEquals("00000cam a2200000 a 4500", record.getLeader().marshal());

    record.addVariableField(factory.newControlField("001", "12883376"));

    DataField df = factory.newDataField("245", '1', '0');
    df.addSubfield(factory.newSubfield('a', "Summerland /"));
    df.addSubfield(factory.newSubfield('c', "Michael Chabon."));
    record.addVariableField(df);
  }
Example #3
0
 /**
  * Creates a new data field with the given tag and indicators and subfields and returns the
  * instance.
  *
  * @return DataField
  */
 @Override
 public DataField newDataField(
     final String tag, final char ind1, final char ind2, final String... subfieldCodesAndData) {
   final DataField df = new DataFieldImpl(tag, ind1, ind2);
   if (subfieldCodesAndData.length % 2 == 1) {
     throw new MarcException(
         "Error: must provide even number of parameters for subfields: code, data, code, data, ...");
   }
   for (int i = 0; i < subfieldCodesAndData.length; i += 2) {
     if (subfieldCodesAndData[i].length() != 1) {
       throw new MarcException("Error: subfieldCode must be a single character");
     }
     final Subfield sf =
         newSubfield(subfieldCodesAndData[i].charAt(0), subfieldCodesAndData[i + 1]);
     df.addSubfield(sf);
   }
   return (df);
 }