/**
   * @override @see
   *     org.springframework.web.servlet.mvc.SimpleFormController#onSubmit(javax.servlet.http.HttpServletRequest,
   *     javax.servlet.http.HttpServletResponse, java.lang.Object,
   *     org.springframework.validation.BindException)
   */
  @Override
  protected ModelAndView onSubmit(
      HttpServletRequest request,
      HttpServletResponse response,
      Object command,
      BindException errors) {
    OtmlFileUpload bean = (OtmlFileUpload) command;
    MultipartFile file = bean.getFile();

    if (file == null) {
      ModelAndView modelAndView = new ModelAndView(new RedirectView(getSuccessView()));
      return modelAndView;
    } else {
      CreateOtmlModuleParameters params = new CreateOtmlModuleParameters();
      params.setName(bean.getName());
      params.setUrl(RooloOtmlModuleDao.defaultOtrunkCurnitUrl);
      params.setRetrieveotmlurl(
          Util.getPortalUrl(request) + "/repository/retrieveotml.html?otmlModuleId=");
      try {
        params.setOtml(file.getBytes());
      } catch (IOException e) {
        e.printStackTrace();
        return null;
      }
      curnitService.createCurnit(params);
    }
    return null;
  }
  /**
   * @see
   *     org.springframework.web.servlet.mvc.AbstractController#handleRequestInternal(javax.servlet.http.HttpServletRequest,
   *     javax.servlet.http.HttpServletResponse)
   */
  @Override
  protected ModelAndView handleRequestInternal(
      HttpServletRequest request, HttpServletResponse response) throws Exception {

    String outResponse = "";
    User user = ControllerUtil.getSignedInUser();
    Set<User> owners = new TreeSet<User>();
    owners.add(user);

    Project project = projectService.getById(Long.parseLong(request.getParameter(PROJECTID)));

    CreateOtmlModuleParameters params = new CreateOtmlModuleParameters();
    params.setName(project.getCurnit().getSdsCurnit().getName());
    params.setUrl(RooloOtmlModuleDao.defaultOtrunkCurnitUrl);
    params.setRetrieveotmlurl(
        Util.getPortalUrl(request) + "/repository/retrieveotml.html?otmlModuleId=");
    byte[] otmlbytes = (byte[]) project.getCurnit().accept(new CurnitGetOtmlVisitor());
    if (otmlbytes != null) {
      params.setOtml(otmlbytes);
      Curnit copiedCurnit = curnitService.createCurnit(params);

      ProjectParameters projParams = new ProjectParameters();

      projParams.setCurnitId(copiedCurnit.getId());
      projParams.setJnlpId(project.getJnlp().getId());
      projParams.setOwners(owners);
      projParams.setProjectname(project.getName());
      projParams.setProjectType(project.getProjectType());

      projectService.createProject(projParams);

      outResponse =
          "Project "
              + project.getName()
              + " has been successfully "
              + "copied and can be found in My Customized Projects.";
    } else {
      outResponse = "This project is not of a type that can be copied.";
    }

    ModelAndView modelAndView = new ModelAndView();
    modelAndView.addObject(RESPONSE, outResponse);
    return modelAndView;
  }