Package org.ngrinder.script.model

Examples of org.ngrinder.script.model.FileEntry


   * @param path     user
   * @param response response
   */
  @RequestMapping("/download/**")
  public void download(User user, @RemainedPath String path, HttpServletResponse response) {
    FileEntry fileEntry = fileEntryService.getOne(user, path);
    if (fileEntry == null) {
      LOG.error("{} requested to download not existing file entity {}", user.getUserId(), path);
      return;
    }
    response.reset();
    try {
      response.addHeader(
          "Content-Disposition",
          "attachment;filename="
              + java.net.URLEncoder.encode(FilenameUtils.getName(fileEntry.getPath()), "utf8"));
    } catch (UnsupportedEncodingException e1) {
      LOG.error(e1.getMessage(), e1);
    }
    response.setContentType("application/octet-stream; charset=UTF-8");
    response.addHeader("Content-Length", "" + fileEntry.getFileSize());
    byte[] buffer = new byte[4096];
    ByteArrayInputStream fis = null;
    OutputStream toClient = null;
    try {
      fis = new ByteArrayInputStream(fileEntry.getContentBytes());
      toClient = new BufferedOutputStream(response.getOutputStream());
      int readLength;
      while (((readLength = fis.read(buffer)) != -1)) {
        toClient.write(buffer, 0, readLength);
      }
View Full Code Here


      throw processException("Error while getting file content:" + e.getMessage(), e);
    }
  }

  private void upload(User user, String path, String description, MultipartFile file) throws IOException {
    FileEntry fileEntry = new FileEntry();
    fileEntry.setContentBytes(file.getBytes());
    fileEntry.setDescription(description);
    fileEntry.setPath(FilenameUtils.separatorsToUnix(FilenameUtils.concat(path, file.getOriginalFilename())));
    fileEntryService.save(user, fileEntry);
  }
View Full Code Here

   * @return json string
   */
  @RestAPI
  @RequestMapping(value = "/api/**", params = "action=view", method = RequestMethod.GET)
  public HttpEntity<String> viewOne(User user, @RemainedPath String path) {
    FileEntry fileEntry = fileEntryService.getOne(user, path, -1L);
    return toJsonHttpEntity(checkNotNull(fileEntry
        , "%s file is not viewable", path));
  }
View Full Code Here

   * @param path       base path
   * @param comment    comment
   * @param folderName folder name
   */
  public void addFolder(User user, String path, String folderName, String comment) {
    FileEntry entry = new FileEntry();
    entry.setPath(PathUtils.join(path, folderName));
    entry.setFileType(FileType.DIR);
    entry.setDescription(comment);
    fileEntityRepository.save(user, entry, null);
  }
View Full Code Here

    if (scriptHandler instanceof ProjectHandler) {
      scriptHandler.prepareScriptEnv(user, path, fileName, name, url, libAndResource);
      return null;
    }
    path = PathUtils.join(path, fileName);
    FileEntry fileEntry = new FileEntry();
    fileEntry.setPath(path);
    fileEntry.setContent(loadTemplate(user, scriptHandler, url, name));
    if (!"http://please_modify_this.com".equals(url)) {
      fileEntry.setProperties(buildMap("targetHosts", UrlUtils.getHost(url)));
    } else {
      fileEntry.setProperties(new HashMap<String, String>());
    }
    return fileEntry;
  }
View Full Code Here

   * @return created new {@link FileEntry}
   */
  public FileEntry prepareNewEntryForQuickTest(User user, String url, ScriptHandler scriptHandler) {
    String path = getPathFromUrl(url);
    String host = UrlUtils.getHost(url);
    FileEntry quickTestFile = scriptHandler.getDefaultQuickTestFilePath(path);
    if (scriptHandler instanceof ProjectHandler) {
      String[] pathPart = dividePathAndFile(path);
      prepareNewEntry(user, pathPart[0], pathPart[1], host, url, scriptHandler, false);
    } else {
      FileEntry fileEntry = prepareNewEntry(user, path, quickTestFile.getFileName(), host, url, scriptHandler,
          false);
      fileEntry.setDescription("Quick test for " + url);
      save(user, fileEntry);
    }
    return quickTestFile;
  }
View Full Code Here

   * .ngrinder.model.User, org.ngrinder.model.IFileEntry, boolean,
   * java.lang.String)
   */
  @Override
  public String validate(User user, IFileEntry scriptIEntry, boolean useScriptInSVN, String hostString) {
    FileEntry scriptEntry = cast(scriptIEntry);
    try {
      checkNotNull(scriptEntry, "scriptEntity should be not null");
      checkNotEmpty(scriptEntry.getPath(), "scriptEntity path should be provided");
      if (!useScriptInSVN) {
        checkNotEmpty(scriptEntry.getContent(), "scriptEntity content should be provided");
      }
      checkNotNull(user, "user should be provided");
      // String result = checkSyntaxErrors(scriptEntry.getContent());

      ScriptHandler handler = scriptHandlerFactory.getHandler(scriptEntry);
      if (config.getControllerProperties().getPropertyBoolean(PROP_CONTROLLER_VALIDATION_SYNTAX_CHECK)) {
        String result = handler.checkSyntaxErrors(scriptEntry.getPath(), scriptEntry.getContent());
        LOGGER.info("Perform Syntax Check by {} for {}", user.getUserId(), scriptEntry.getPath());
        if (result != null) {
          return result;
        }
      }
      File scriptDirectory = config.getHome().getScriptDirectory(user);
      FileUtils.deleteDirectory(scriptDirectory);
      Preconditions.checkTrue(scriptDirectory.mkdirs(), "Script directory {} creation is failed.");

      ProcessingResultPrintStream processingResult = new ProcessingResultPrintStream(new ByteArrayOutputStream());
      handler.prepareDist(0L, user, scriptEntry, scriptDirectory, config.getControllerProperties(), processingResult);
      if (!processingResult.isSuccess()) {
        return new String(processingResult.getLogByteArray());
      }
      File scriptFile = new File(scriptDirectory, FilenameUtils.getName(scriptEntry.getPath()));

      if (useScriptInSVN) {
        fileEntryService.writeContentTo(user, scriptEntry.getPath(), scriptDirectory);
      } else {
        FileUtils.writeStringToFile(scriptFile, scriptEntry.getContent(),
            StringUtils.defaultIfBlank(scriptEntry.getEncoding(), "UTF-8"));
      }
      File doValidate = localScriptTestDriveService.doValidate(scriptDirectory, scriptFile, new Condition(),
          config.isSecurityEnabled(), hostString, getTimeout());
      List<String> readLines = FileUtils.readLines(doValidate);
      StringBuilder output = new StringBuilder();
View Full Code Here

TOP

Related Classes of org.ngrinder.script.model.FileEntry

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.