/**
   * @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
  public String createScholarDataverse() {
    String dataversetype = dataverseType;

    String name = (String) dataverseName.getValue();
    String alias = (String) dataverseAlias.getValue();
    String strAffiliation = (String) affiliation.getValue();
    String strShortDescription = (String) shortDescription.getValue();
    Long userId = getVDCSessionBean().getLoginBean().getUser().getId();

    if (validateClassificationCheckBoxes()) {
      vdcService.createScholarDataverse(
          userId, firstName, lastName, name, strAffiliation, alias, dataversetype);
      VDC createdScholarDataverse = vdcService.findScholarDataverseByAlias(alias);
      saveClassifications(createdScholarDataverse);

      //  add default values to the VDC table and commit/set the vdc bean props
      createdScholarDataverse.setDisplayNetworkAnnouncements(
          getVDCRequestBean().getCurrentVdcNetwork().isDisplayAnnouncements());
      createdScholarDataverse.setDisplayAnnouncements(
          getVDCRequestBean().getCurrentVdcNetwork().isDisplayVDCAnnouncements());
      // on create if description is blank uncheck display flag
      if (strShortDescription.isEmpty()) {
        createdScholarDataverse.setDisplayAnnouncements(false);
      }
      createdScholarDataverse.setAnnouncements(
          getVDCRequestBean().getCurrentVdcNetwork().getDefaultVDCAnnouncements());
      createdScholarDataverse.setDisplayNewStudies(
          getVDCRequestBean().getCurrentVdcNetwork().isDisplayVDCRecentStudies());
      createdScholarDataverse.setAboutThisDataverse(
          getVDCRequestBean().getCurrentVdcNetwork().getDefaultVDCAboutText());
      createdScholarDataverse.setContactEmail(
          getVDCSessionBean().getLoginBean().getUser().getEmail());
      createdScholarDataverse.setDvnDescription(strShortDescription);
      createdScholarDataverse.setAnnouncements(
          strShortDescription); // also set default dv home page description from the the DVN home
                                // page short description
      VDCNetwork vdcNetwork;
      if (selectSubNetworkId != null && selectSubNetworkId > 0) {
        vdcNetwork = vdcNetworkService.findById(selectSubNetworkId);
        createdScholarDataverse.setVdcNetwork(vdcNetwork);
      } else {
        vdcNetwork = vdcNetworkService.findRootNetwork();
        createdScholarDataverse.setVdcNetwork(vdcNetwork);
      }
      // Set default template to subnet's default template
      Template template = vdcNetwork.getDefaultTemplate();
      createdScholarDataverse.setDefaultTemplate(template);

      vdcService.edit(createdScholarDataverse);

      String hostUrl = PropertyUtil.getHostUrl();
      VDCUser creator =
          userService.findByUserName(getVDCSessionBean().getLoginBean().getUser().getUserName());
      String toMailAddress = getVDCSessionBean().getLoginBean().getUser().getEmail();
      String siteAddress = hostUrl + "/dvn/dv/" + createdScholarDataverse.getAlias();

      mailService.sendAddSiteNotification(toMailAddress, name, siteAddress);

      // Refresh User object in LoginBean so it contains the user's new role of VDC administrator.
      getVDCSessionBean().getLoginBean().setUser(creator);
      getVDCRenderBean().getFlash().put("successMessage", "Your new dataverse has been created!");
      return "/site/AddSiteSuccessPage?faces-redirect=true&vdcId="
          + createdScholarDataverse.getId();
    } else {
      return null;
    }
  }