<commit_before>package cz.cuni.mff.xrg.odalic.api.rest.resources;

import java.io.IOException;
import java.util.concurrent.CancellationException;
import java.util.concurrent.ExecutionException;

import javax.ws.rs.GET;
import javax.ws.rs.NotFoundException;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Response;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.google.common.base.Preconditions;

import cz.cuni.mff.xrg.odalic.outputs.rdfexport.RdfExportService;

/**
 * Definition of the resource providing the result as serialized RDF data.
 * 
 * @author <NAME>
 *
 */
@Component
@Path("/tasks/{id}/result/rdf-export")
public final class RdfExportResource {

  public static final String TURTLE_MIME_TYPE = "text/turtle";
  public static final String JSON_LD_MIME_TYPE = "application/ld+json";

  private final RdfExportService rdfExportService;

  @Autowired
  public RdfExportResource(RdfExportService RdfExportService) {
    Preconditions.checkNotNull(RdfExportService);

    this.rdfExportService = RdfExportService;
  }

  @GET
  @Produces(TURTLE_MIME_TYPE)
  public Response getTurtleExport(@PathParam("id") String taskId)
      throws CancellationException, InterruptedException, ExecutionException, IOException {
    final String rdfContent;
    try {
      rdfContent = rdfExportService.exportToTurtle(taskId);
    } catch (final CancellationException | ExecutionException e) {
      throw new NotFoundException(
          "RDF export is not available, because the processing did not finish. Check the result first!");
    } catch (final IllegalArgumentException e) {
      throw new NotFoundException("The task has not been scheduled or does not exist!");
    }

    return Response.ok(rdfContent).build();
  }

  @GET
  @Produces(JSON_LD_MIME_TYPE)
  public Response getJsonLdExport(@PathParam("id") String taskId)
      throws CancellationException, InterruptedException, ExecutionException, IOException {
    final String rdfContent;
    try {
      rdfContent = rdfExportService.exportToJsonLd(taskId);
    } catch (final CancellationException | ExecutionException e) {
      throw new NotFoundException(
          "RDF export is not available, because the processing did not finish. Check the result first!");
    } catch (final IllegalArgumentException e) {
      throw new NotFoundException("The task has not been scheduled or does not exist!");
    }

    return Response.ok(rdfContent).build();
  }
}<commit_msg>Added alternative export paths when client cannot provide Accept header.<commit_after>package cz.cuni.mff.xrg.odalic.api.rest.resources;

import java.io.IOException;
import java.util.concurrent.CancellationException;
import java.util.concurrent.ExecutionException;

import javax.ws.rs.GET;
import javax.ws.rs.NotFoundException;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Response;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.google.common.base.Preconditions;

import cz.cuni.mff.xrg.odalic.outputs.rdfexport.RdfExportService;

/**
 * Definition of the resource providing the result as serialized RDF data.
 * 
 * @author <NAME>
 *
 */
@Component
@Path("/tasks/{id}/result/rdf-export")
public final class RdfExportResource {

  public static final String TURTLE_MIME_TYPE = "text/turtle";
  public static final String JSON_LD_MIME_TYPE = "application/ld+json";

  private final RdfExportService rdfExportService;

  @Autowired
  public RdfExportResource(RdfExportService RdfExportService) {
    Preconditions.checkNotNull(RdfExportService);

    this.rdfExportService = RdfExportService;
  }

  @GET
  @Produces(TURTLE_MIME_TYPE)
  public Response getTurtleExport(@PathParam("id") String taskId)
      throws CancellationException, InterruptedException, ExecutionException, IOException {
    final String rdfContent;
    try {
      rdfContent = rdfExportService.exportToTurtle(taskId);
    } catch (final CancellationException | ExecutionException e) {
      throw new NotFoundException(
          "RDF export is not available, because the processing did not finish. Check the result first!");
    } catch (final IllegalArgumentException e) {
      throw new NotFoundException("The task has not been scheduled or does not exist!");
    }

    return Response.ok(rdfContent).build();
  }

  @GET
  @Produces(JSON_LD_MIME_TYPE)
  public Response getJsonLdExport(@PathParam("id") String taskId)
      throws CancellationException, InterruptedException, ExecutionException, IOException {
    final String rdfContent;
    try {
      rdfContent = rdfExportService.exportToJsonLd(taskId);
    } catch (final CancellationException | ExecutionException e) {
      throw new NotFoundException(
          "RDF export is not available, because the processing did not finish. Check the result first!");
    } catch (final IllegalArgumentException e) {
      throw new NotFoundException("The task has not been scheduled or does not exist!");
    }

    return Response.ok(rdfContent).build();
  }

  /**
   * Alternative method for client that are unable to provide Accept headers.
   */
  @GET
  @Path("turtle")
  @Produces(TURTLE_MIME_TYPE)
  public Response getTurtleAlternativeExport(@PathParam("id") String taskId)
      throws CancellationException, InterruptedException, ExecutionException, IOException {
    return getTurtleExport(taskId);
  }

  /**
   * Alternative method for client that are unable to provide Accept headers.
   */
  @GET
  @Path("json-ld")
  @Produces(JSON_LD_MIME_TYPE)
  public Response getJsonLdAlternativeExport(@PathParam("id") String taskId)
      throws CancellationException, InterruptedException, ExecutionException, IOException {
    return getJsonLdExport(taskId);
  }
}
{'fraction_non_alphanumeric': 0.08858833474218089, 'fraction_numerical': 0.0, 'mean_word_length': 4.53932584269663, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5281648', 'n_tokens_mistral': 1717, 'n_tokens_neox': 1696, 'n_words': 438}