Example #1
0
  public String create() {

    //    Long selectedgroup  = this.getSelectedGroup();
    String dtype = 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();

    boolean success = true;
    if (validateClassificationCheckBoxes()) {
      vdcService.create(userId, name, alias, dtype);
      VDC createdVDC = vdcService.findByAlias(alias);
      saveClassifications(createdVDC);
      createdVDC.setDtype(dataverseType);
      createdVDC.setDisplayNetworkAnnouncements(
          getVDCRequestBean().getCurrentVdcNetwork().isDisplayAnnouncements());
      createdVDC.setDisplayAnnouncements(
          getVDCRequestBean().getCurrentVdcNetwork().isDisplayVDCAnnouncements());
      createdVDC.setDisplayNewStudies(
          getVDCRequestBean().getCurrentVdcNetwork().isDisplayVDCRecentStudies());
      createdVDC.setAboutThisDataverse(
          getVDCRequestBean().getCurrentVdcNetwork().getDefaultVDCAboutText());
      createdVDC.setContactEmail(getVDCSessionBean().getLoginBean().getUser().getEmail());
      createdVDC.setAffiliation(strAffiliation);
      createdVDC.setDvnDescription(strShortDescription);
      createdVDC.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);
        createdVDC.setVdcNetwork(vdcNetwork);
      } else {
        vdcNetwork = vdcNetworkService.findRootNetwork();
        createdVDC.setVdcNetwork(vdcNetwork);
      }
      // Set template to the network's default template
      Template template = vdcNetwork.getDefaultTemplate();
      createdVDC.setDefaultTemplate(template);

      // on create if description is blank uncheck display flag
      if (strShortDescription.isEmpty()) {
        createdVDC.setDisplayAnnouncements(false);
      }
      vdcService.edit(createdVDC);

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

      logger.fine("created dataverse; site address: " + siteAddress);

      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=" + createdVDC.getId();
    } else {
      success = false;
      return null;
    }
  }