Ejemplo n.º 1
0
  /**
   * Servico responsavel por adicionar ativos artifact area de monitoramento do repositorio. Consome
   * XML padronizado (Command) contendo o nome do ativo que se deseja monitorar.
   *
   * @param command
   * @return
   * @throws IOException
   */
  @POST
  @Path("/addasset")
  @Consumes(MediaType.APPLICATION_XML)
  @Produces(MediaType.APPLICATION_XML)
  public Response addAsset(Command command) throws Exception {

    Hidra hidra;
    ResultMessage result = new ResultMessage();
    String path = command.getRepositoryPath();
    String assetName = command.getAssetName();

    if (path.isEmpty() || assetName.isEmpty()) {
      throw new DataNotFoundException(
          "The absolute path of the repository Or Asset Name has not been set");
    }
    if (!new File(path).exists()) {
      throw new IOException("Could not find the informed repository");
    }
    if (!new File(path + separator + assetName).exists()) {
      throw new IOException("Asset informed was not found");
    }

    hidra = new Hidra(path);
    if (hidra.addAsset(assetName)) {
      result.setMessage("The asset: " + assetName + " has been added to the repository");
      result.setStatusMessage(Status.OK);
      return Response.status(Status.OK).entity(result).build();
    }

    throw new Exception("File already monitored. You might want to do \"updateAsset\"");
  }