Esempio n. 1
0
  /**
   * Get the details of given path.
   *
   * @param user user
   * @param path user
   * @param revision revision. -1 if HEAD
   * @param model model
   * @return script/scriptEditor
   */
  @RequestMapping("/detail/**")
  public String getDetail(
      User user,
      @RemainedPath String path,
      @RequestParam(value = "r", required = false) Long revision,
      ModelMap model) {
    FileEntry script = fileEntryService.getFileEntry(user, path, revision);
    if (script == null || !script.getFileType().isEditable()) {
      LOG.error(
          "Error while getting file detail on {}. the file does not exist or not editable", path);
      model.clear();
      return "redirect:/script/list";
    }
    model.addAttribute("file", script);
    model.addAttribute("ownerId", user.getUserId());

    return "script/scriptEditor";
  }
Esempio n. 2
0
 /**
  * Upload files.
  *
  * @param user current user
  * @param path path
  * @param description description
  * @param file multipart file
  * @param model model
  * @return script/scriptList
  */
 @RequestMapping(value = "/upload/**", method = RequestMethod.POST)
 public String uploadFiles(
     User user,
     @RemainedPath String path,
     @RequestParam("description") String description,
     @RequestParam("uploadFile") MultipartFile file,
     ModelMap model) {
   try {
     FileEntry fileEntry = new FileEntry();
     if (fileEntry.getFileType().isEditable()) {
       fileEntry.setContent(new String(file.getBytes()));
     } else {
       fileEntry.setContentBytes(file.getBytes());
     }
     fileEntry.setDescription(description);
     fileEntry.setPath(
         FilenameUtils.separatorsToUnix(FilenameUtils.concat(path, file.getOriginalFilename())));
     fileEntryService.save(user, fileEntry);
     return "redirect:/script/list/" + path;
   } catch (IOException e) {
     LOG.error("Error while getting file content:" + e.getMessage(), e);
     throw new NGrinderRuntimeException("Error while getting file content:" + e.getMessage(), e);
   }
 }