@GET
  @Consumes({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
  @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
  @ApiOperation(
      value = "List Representations",
      notes = "Gets a list of representations.",
      response = Representations.class,
      responseContainer = "List")
  @ApiResponses(
      value = {
        @ApiResponse(
            code = 200,
            message = "Successful response",
            response = Representations.class,
            responseContainer = "List"),
        @ApiResponse(code = 404, message = "Not found", response = ApiResponseMessage.class)
      })
  public Response listRepresentations(
      @ApiParam(value = "Index of the first element to return", defaultValue = "0")
          @QueryParam(RodaConstants.API_QUERY_KEY_START)
          String start,
      @ApiParam(
              value = "Maximum number of elements to return",
              defaultValue = RodaConstants.DEFAULT_PAGINATION_STRING_VALUE)
          @QueryParam(RodaConstants.API_QUERY_KEY_LIMIT)
          String limit,
      @ApiParam(
              value = "Choose format in which to get the representation",
              allowableValues = RodaConstants.API_LIST_MEDIA_TYPES,
              defaultValue = RodaConstants.API_QUERY_VALUE_ACCEPT_FORMAT_JSON)
          @QueryParam(RodaConstants.API_QUERY_KEY_ACCEPT_FORMAT)
          String acceptFormat)
      throws RODAException {
    String mediaType = ApiUtils.getMediaType(acceptFormat, request);

    // get user
    User user = UserUtility.getApiUser(request);

    // delegate action to controller
    boolean justActive = false;
    Pair<Integer, Integer> pagingParams = ApiUtils.processPagingParams(start, limit);
    IndexResult<IndexedRepresentation> result =
        Browser.find(
            IndexedRepresentation.class,
            Filter.NULL,
            Sorter.NONE,
            new Sublist(pagingParams.getFirst(), pagingParams.getSecond()),
            null,
            user,
            justActive);
    return Response.ok(
            ApiUtils.indexedResultToRODAObjectList(IndexedRepresentation.class, result), mediaType)
        .build();
  }
Exemple #2
0
  public static Pair<StringContentPayload, Boolean> runVeraPDF(
      Path input, String profile, boolean hasFeatures)
      throws VeraPDFException, IOException, JAXBException {

    PdfBoxFoundryProvider.initialise();
    PDFAFlavour flavour = PDFAFlavour.byFlavourId(profile);

    ValidatorConfig validatorConfig = ValidatorFactory.createConfig(flavour, true, 10);
    FeatureExtractorConfig featureConfig = FeatureFactory.defaultConfig();
    MetadataFixerConfig fixerConfig = FixerFactory.defaultConfig();
    EnumSet<TaskType> tasks = EnumSet.of(TaskType.VALIDATE);

    if (hasFeatures) {
      tasks.add(TaskType.EXTRACT_FEATURES);
    }

    ItemProcessor processor =
        ProcessorFactory.createProcessor(
            ProcessorFactory.fromValues(validatorConfig, featureConfig, fixerConfig, tasks));

    ProcessorResult result = processor.process(input.toFile());
    ByteArrayOutputStream os = new ByteArrayOutputStream();

    boolean prettyPrint = true;
    ProcessorFactory.resultToXml(result, os, prettyPrint);

    IOUtils.closeQuietly(os);
    StringContentPayload s = new StringContentPayload(os.toString(RodaConstants.DEFAULT_ENCODING));
    return Pair.create(s, result.getValidationResult().isCompliant());
  }