Пример #1
0
  @RolesAllowed(SecurityRoles.JOB_EDITOR)
  @RequestMapping(method = RequestMethod.POST, produces = "application/json")
  @ResponseBody
  public Map<String, String> uploadAnalysisJob(
      @PathVariable("tenant") final String tenant,
      @PathVariable("job") String jobName,
      @RequestParam("file") final MultipartFile file) {
    if (file == null) {
      throw new IllegalArgumentException(
          "No file upload provided. Please provide a multipart file using the 'file' HTTP parameter.");
    }

    jobName = jobName.replaceAll("\\+", " ");

    final Action<OutputStream> writeCallback =
        new Action<OutputStream>() {
          @Override
          public void run(OutputStream out) throws Exception {
            final InputStream in = file.getInputStream();
            try {
              FileHelper.copy(in, out);
            } finally {
              FileHelper.safeClose(in);
            }
          }
        };

    final TenantContext context = _contextFactory.getContext(tenant);
    final JobContext existingJob = context.getJob(jobName);
    final RepositoryFile jobFile;
    if (existingJob == null) {
      final RepositoryFolder jobsFolder = context.getJobFolder();

      final String filename;
      if (jobName.endsWith(EXTENSION)) {
        filename = jobName;
      } else {
        filename = jobName + EXTENSION;
      }

      logger.info("Creating new job from uploaded file: {}", filename);
      jobFile = jobsFolder.createFile(filename, writeCallback);
    } else {
      jobFile = existingJob.getJobFile();
      logger.info("Overwriting job from uploaded file: {}", jobFile.getName());
      jobFile.writeFile(writeCallback);
    }

    final Map<String, String> result = new HashMap<String, String>();
    result.put("status", "Success");
    result.put("file_type", jobFile.getType().toString());
    result.put("filename", jobFile.getName());
    result.put("repository_path", jobFile.getQualifiedPath());

    return result;
  }
Пример #2
0
  @RolesAllowed(SecurityRoles.JOB_EDITOR)
  @RequestMapping(method = RequestMethod.GET, produces = "application/xml")
  public void jobXml(
      @PathVariable("tenant") final String tenant,
      @PathVariable("job") String jobName,
      OutputStream out)
      throws IOException {

    jobName = jobName.replaceAll("\\+", " ");

    final TenantContext context = _contextFactory.getContext(tenant);
    final JobContext job = context.getJob(jobName);

    if (!(job instanceof XmlJobContext)) {
      throw new UnsupportedOperationException("Job not compatible with operation: " + job);
    }

    XmlJobContext xmlJob = (XmlJobContext) job;
    xmlJob.toXml(out);
  }