コード例 #1
0
  @RolesAllowed(SecurityRoles.CONFIGURATION_EDITOR)
  @RequestMapping(method = RequestMethod.GET, produces = MediaType.APPLICATION_XML_VALUE)
  @ResponseBody
  public HttpEntity<byte[]> downloadConfigurationFile(@PathVariable("tenant") final String tenant) {

    final TenantContext context = _contextFactory.getContext(tenant);
    final RepositoryFile configurationFile = context.getConfigurationFile();

    if (configurationFile == null) {
      throw new IllegalStateException("Configuration file not found!");
    }

    final byte[] documentBody =
        configurationFile.readFile(
            new Func<InputStream, byte[]>() {
              @Override
              public byte[] eval(InputStream in) {
                return FileHelper.readAsBytes(in);
              }
            });

    final HttpHeaders header = new HttpHeaders();
    header.setContentType(MediaType.APPLICATION_XML);
    header.setContentLength(documentBody.length);
    return new HttpEntity<byte[]>(documentBody, header);
  }
コード例 #2
0
  @RequestMapping(method = RequestMethod.POST, produces = "application/json")
  @ResponseBody
  @RolesAllowed({SecurityRoles.CONFIGURATION_EDITOR})
  public Map<String, String> removeDatastore(
      @PathVariable("tenant") final String tenant,
      @PathVariable("datastore") String datastoreName) {

    logger.info("Request payload: {} - {}", tenant, datastoreName);

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

    final Map<String, String> response = new TreeMap<String, String>();
    response.put("datastore", datastoreName);
    response.put("action", "remove");

    final TenantContext tenantContext = _contextFactory.getContext(tenant);
    if (tenantContext.getConfiguration().getDatastoreCatalog().getDatastore(datastoreName)
        == null) {
      response.put("status", "FAILURE");
      response.put("message", "No such datastore: " + datastoreName);
      return response;
    }

    try {
      datastoreDao.removeDatastore(tenantContext, datastoreName);
    } catch (Exception e) {
      logger.error(
          "Removing datastore '"
              + datastoreName
              + "' from tenant '"
              + tenant
              + "'s configuration failed",
          e);
      response.put("status", "FAILURE");
      response.put("message", e.getMessage());
      return response;
    }

    response.put("status", "SUCCESS");
    response.put("message", "Datastore was removed succesfully");

    logger.debug("Response payload: {}", response);
    return response;
  }
コード例 #3
0
  @RolesAllowed(SecurityRoles.CONFIGURATION_EDITOR)
  @RequestMapping(
      method = RequestMethod.POST,
      produces = MediaType.APPLICATION_JSON_VALUE,
      consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
  @ResponseBody
  public Map<String, String> uploadConfigurationFileJson(
      @PathVariable("tenant") final String tenant, @RequestParam("file") final MultipartFile file)
      throws Exception {
    if (file == null) {
      logger.warn("No upload file provided, throwing IllegalArgumentException");
      throw new IllegalArgumentException(
          "No file upload provided. Please provide a multipart file using the 'file' HTTP parameter.");
    }

    logger.info("Upload of new configuration file beginning");

    try {
      final TenantContext context = _contextFactory.getContext(tenant);
      final RepositoryFile configurationFile = context.getConfigurationFile();

      final InputStream inputStream = file.getInputStream();
      final WriteUpdatedConfigurationFileAction writeAction =
          new WriteUpdatedConfigurationFileAction(inputStream, configurationFile);

      try {
        configurationFile.writeFile(writeAction);
      } finally {
        FileHelper.safeClose(inputStream);
      }

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

      return result;
    } catch (Exception e) {
      logger.warn(
          "An error occurred while uploading new configuration file for tenant " + tenant, e);
      throw e;
    }
  }