@Test public void testSchema() throws Exception { final String source = "header1,header2,header3\n" + "l1r1,l1r2,l1r3\n" + "l2r1,l2r2,l2r3\n" + "l3r1,l3r2,l3r3\n"; InputStream inputStream = new ByteArrayInputStream(source.getBytes()); Response res = csvService.inspect(inputStream, null, ",", true, null, null, null, null, null, null, null, null, null, null); Object entity = res.getEntity(); assertEquals(byte[].class, entity.getClass()); CsvInspectionResponse csvInspectionResponse = Json.mapper().readValue((byte[])entity, CsvInspectionResponse.class); CsvComplexType complexType = (CsvComplexType) csvInspectionResponse.getCsvDocument().getFields().getField().get(0); List<CsvField> fields = complexType.getCsvFields().getCsvField(); assertThat(fields.get(0).getName(), is("header1")); assertThat(fields.get(1).getName(), is("header2")); assertThat(fields.get(2).getName(), is("header3")); }
@POST @Consumes({ MediaType.APPLICATION_JSON }) @Produces({ MediaType.APPLICATION_JSON }) @Path("/inspect") @Operation(summary = "Inspect CSV", description = "Inspect a CSV instance and return a Document object") @RequestBody(description = "Csv", content = @Content(mediaType = "text/csv", schema = @Schema(implementation = String.class))) @ApiResponses(@ApiResponse(responseCode = "200", content = @Content(schema = @Schema(implementation = CsvInspectionResponse.class)), description = "Return a Document object")) public Response inspect(InputStream request, @QueryParam("format") String format, @QueryParam("delimiter") String delimiter, @QueryParam("firstRecordAsHeader") Boolean firstRecordAsHeader, @QueryParam("headers") String headers, @QueryParam("commentMarker") String commentMarker, @QueryParam("escape") String escape, @QueryParam("ignoreEmptyLines") Boolean ignoreEmptyLines, @QueryParam("ignoreHeaderCase") Boolean ignoreHeaderCase, @QueryParam("ignoreSurroundingSpaces") Boolean ignoreSurroundingSpaces, @QueryParam("nullString") String nullString, @QueryParam("quote") String quote, @QueryParam("allowDuplicateHeaderNames") Boolean allowDuplicateHeaderNames, @QueryParam("allowMissingColumnNames") Boolean allowMissingColumnNames) throws IOException { long startTime = System.currentTimeMillis(); CsvInspectionResponse response = new CsvInspectionResponse(); try { CsvConfig csvConfig = new CsvConfig(format); if (delimiter != null) { csvConfig.setDelimiter(delimiter.charAt(0)); } if (firstRecordAsHeader != null) { csvConfig.setFirstRecordAsHeader(firstRecordAsHeader); } csvConfig.setHeaders(headers); if (commentMarker != null) { csvConfig.setCommentMarker(commentMarker.charAt(0)); } if (escape != null) { csvConfig.setEscape(escape.charAt(0)); } csvConfig.setIgnoreEmptyLines(ignoreEmptyLines); csvConfig.setIgnoreHeaderCase(ignoreHeaderCase); csvConfig.setIgnoreSurroundingSpaces(ignoreSurroundingSpaces); csvConfig.setNullString(nullString); if (quote != null) { csvConfig.setQuote(quote.charAt(0)); } csvConfig.setAllowDuplicateHeaderNames(allowDuplicateHeaderNames); csvConfig.setAllowMissingColumnNames(allowMissingColumnNames); CsvFieldReader csvFieldReader = new CsvFieldReader(csvConfig); csvFieldReader.setDocument(request); Document document = csvFieldReader.readSchema(); response.setCsvDocument(document); request.close(); } catch (Exception e) { LOG.error("Error inspecting CSV: " + e.getMessage(), e); response.setErrorMessage(e.getMessage()); } finally { request.close();; response.setExecutionTime(System.currentTimeMillis() - startTime); } return Response.ok().entity(toJson(response)).build(); }
CsvService { @POST @Consumes({ MediaType.APPLICATION_JSON }) @Produces({ MediaType.APPLICATION_JSON }) @Path("/inspect") @Operation(summary = "Inspect CSV", description = "Inspect a CSV instance and return a Document object") @RequestBody(description = "Csv", content = @Content(mediaType = "text/csv", schema = @Schema(implementation = String.class))) @ApiResponses(@ApiResponse(responseCode = "200", content = @Content(schema = @Schema(implementation = CsvInspectionResponse.class)), description = "Return a Document object")) public Response inspect(InputStream request, @QueryParam("format") String format, @QueryParam("delimiter") String delimiter, @QueryParam("firstRecordAsHeader") Boolean firstRecordAsHeader, @QueryParam("headers") String headers, @QueryParam("commentMarker") String commentMarker, @QueryParam("escape") String escape, @QueryParam("ignoreEmptyLines") Boolean ignoreEmptyLines, @QueryParam("ignoreHeaderCase") Boolean ignoreHeaderCase, @QueryParam("ignoreSurroundingSpaces") Boolean ignoreSurroundingSpaces, @QueryParam("nullString") String nullString, @QueryParam("quote") String quote, @QueryParam("allowDuplicateHeaderNames") Boolean allowDuplicateHeaderNames, @QueryParam("allowMissingColumnNames") Boolean allowMissingColumnNames) throws IOException { long startTime = System.currentTimeMillis(); CsvInspectionResponse response = new CsvInspectionResponse(); try { CsvConfig csvConfig = new CsvConfig(format); if (delimiter != null) { csvConfig.setDelimiter(delimiter.charAt(0)); } if (firstRecordAsHeader != null) { csvConfig.setFirstRecordAsHeader(firstRecordAsHeader); } csvConfig.setHeaders(headers); if (commentMarker != null) { csvConfig.setCommentMarker(commentMarker.charAt(0)); } if (escape != null) { csvConfig.setEscape(escape.charAt(0)); } csvConfig.setIgnoreEmptyLines(ignoreEmptyLines); csvConfig.setIgnoreHeaderCase(ignoreHeaderCase); csvConfig.setIgnoreSurroundingSpaces(ignoreSurroundingSpaces); csvConfig.setNullString(nullString); if (quote != null) { csvConfig.setQuote(quote.charAt(0)); } csvConfig.setAllowDuplicateHeaderNames(allowDuplicateHeaderNames); csvConfig.setAllowMissingColumnNames(allowMissingColumnNames); CsvFieldReader csvFieldReader = new CsvFieldReader(csvConfig); csvFieldReader.setDocument(request); Document document = csvFieldReader.readSchema(); response.setCsvDocument(document); request.close(); } catch (Exception e) { LOG.error("Error inspecting CSV: " + e.getMessage(), e); response.setErrorMessage(e.getMessage()); } finally { request.close();; response.setExecutionTime(System.currentTimeMillis() - startTime); } return Response.ok().entity(toJson(response)).build(); } }
CsvService { @POST @Consumes({ MediaType.APPLICATION_JSON }) @Produces({ MediaType.APPLICATION_JSON }) @Path("/inspect") @Operation(summary = "Inspect CSV", description = "Inspect a CSV instance and return a Document object") @RequestBody(description = "Csv", content = @Content(mediaType = "text/csv", schema = @Schema(implementation = String.class))) @ApiResponses(@ApiResponse(responseCode = "200", content = @Content(schema = @Schema(implementation = CsvInspectionResponse.class)), description = "Return a Document object")) public Response inspect(InputStream request, @QueryParam("format") String format, @QueryParam("delimiter") String delimiter, @QueryParam("firstRecordAsHeader") Boolean firstRecordAsHeader, @QueryParam("headers") String headers, @QueryParam("commentMarker") String commentMarker, @QueryParam("escape") String escape, @QueryParam("ignoreEmptyLines") Boolean ignoreEmptyLines, @QueryParam("ignoreHeaderCase") Boolean ignoreHeaderCase, @QueryParam("ignoreSurroundingSpaces") Boolean ignoreSurroundingSpaces, @QueryParam("nullString") String nullString, @QueryParam("quote") String quote, @QueryParam("allowDuplicateHeaderNames") Boolean allowDuplicateHeaderNames, @QueryParam("allowMissingColumnNames") Boolean allowMissingColumnNames) throws IOException { long startTime = System.currentTimeMillis(); CsvInspectionResponse response = new CsvInspectionResponse(); try { CsvConfig csvConfig = new CsvConfig(format); if (delimiter != null) { csvConfig.setDelimiter(delimiter.charAt(0)); } if (firstRecordAsHeader != null) { csvConfig.setFirstRecordAsHeader(firstRecordAsHeader); } csvConfig.setHeaders(headers); if (commentMarker != null) { csvConfig.setCommentMarker(commentMarker.charAt(0)); } if (escape != null) { csvConfig.setEscape(escape.charAt(0)); } csvConfig.setIgnoreEmptyLines(ignoreEmptyLines); csvConfig.setIgnoreHeaderCase(ignoreHeaderCase); csvConfig.setIgnoreSurroundingSpaces(ignoreSurroundingSpaces); csvConfig.setNullString(nullString); if (quote != null) { csvConfig.setQuote(quote.charAt(0)); } csvConfig.setAllowDuplicateHeaderNames(allowDuplicateHeaderNames); csvConfig.setAllowMissingColumnNames(allowMissingColumnNames); CsvFieldReader csvFieldReader = new CsvFieldReader(csvConfig); csvFieldReader.setDocument(request); Document document = csvFieldReader.readSchema(); response.setCsvDocument(document); request.close(); } catch (Exception e) { LOG.error("Error inspecting CSV: " + e.getMessage(), e); response.setErrorMessage(e.getMessage()); } finally { request.close();; response.setExecutionTime(System.currentTimeMillis() - startTime); } return Response.ok().entity(toJson(response)).build(); }  }
CsvService { @POST @Consumes({ MediaType.APPLICATION_JSON }) @Produces({ MediaType.APPLICATION_JSON }) @Path("/inspect") @Operation(summary = "Inspect CSV", description = "Inspect a CSV instance and return a Document object") @RequestBody(description = "Csv", content = @Content(mediaType = "text/csv", schema = @Schema(implementation = String.class))) @ApiResponses(@ApiResponse(responseCode = "200", content = @Content(schema = @Schema(implementation = CsvInspectionResponse.class)), description = "Return a Document object")) public Response inspect(InputStream request, @QueryParam("format") String format, @QueryParam("delimiter") String delimiter, @QueryParam("firstRecordAsHeader") Boolean firstRecordAsHeader, @QueryParam("headers") String headers, @QueryParam("commentMarker") String commentMarker, @QueryParam("escape") String escape, @QueryParam("ignoreEmptyLines") Boolean ignoreEmptyLines, @QueryParam("ignoreHeaderCase") Boolean ignoreHeaderCase, @QueryParam("ignoreSurroundingSpaces") Boolean ignoreSurroundingSpaces, @QueryParam("nullString") String nullString, @QueryParam("quote") String quote, @QueryParam("allowDuplicateHeaderNames") Boolean allowDuplicateHeaderNames, @QueryParam("allowMissingColumnNames") Boolean allowMissingColumnNames) throws IOException { long startTime = System.currentTimeMillis(); CsvInspectionResponse response = new CsvInspectionResponse(); try { CsvConfig csvConfig = new CsvConfig(format); if (delimiter != null) { csvConfig.setDelimiter(delimiter.charAt(0)); } if (firstRecordAsHeader != null) { csvConfig.setFirstRecordAsHeader(firstRecordAsHeader); } csvConfig.setHeaders(headers); if (commentMarker != null) { csvConfig.setCommentMarker(commentMarker.charAt(0)); } if (escape != null) { csvConfig.setEscape(escape.charAt(0)); } csvConfig.setIgnoreEmptyLines(ignoreEmptyLines); csvConfig.setIgnoreHeaderCase(ignoreHeaderCase); csvConfig.setIgnoreSurroundingSpaces(ignoreSurroundingSpaces); csvConfig.setNullString(nullString); if (quote != null) { csvConfig.setQuote(quote.charAt(0)); } csvConfig.setAllowDuplicateHeaderNames(allowDuplicateHeaderNames); csvConfig.setAllowMissingColumnNames(allowMissingColumnNames); CsvFieldReader csvFieldReader = new CsvFieldReader(csvConfig); csvFieldReader.setDocument(request); Document document = csvFieldReader.readSchema(); response.setCsvDocument(document); request.close(); } catch (Exception e) { LOG.error("Error inspecting CSV: " + e.getMessage(), e); response.setErrorMessage(e.getMessage()); } finally { request.close();; response.setExecutionTime(System.currentTimeMillis() - startTime); } return Response.ok().entity(toJson(response)).build(); }  @GET @Path("/simple") @Produces(MediaType.TEXT_PLAIN) @Operation(summary = "Simple", description = "Simple hello service") @ApiResponses(@ApiResponse(responseCode = "200", content = @Content(schema = @Schema(implementation = String.class)), description = "Return a response")) String simpleHelloWorld(@QueryParam("from") String from); @POST @Consumes({ MediaType.APPLICATION_JSON }) @Produces({ MediaType.APPLICATION_JSON }) @Path("/inspect") @Operation(summary = "Inspect CSV", description = "Inspect a CSV instance and return a Document object") @RequestBody(description = "Csv", content = @Content(mediaType = "text/csv", schema = @Schema(implementation = String.class))) @ApiResponses(@ApiResponse(responseCode = "200", content = @Content(schema = @Schema(implementation = CsvInspectionResponse.class)), description = "Return a Document object")) Response inspect(InputStream request, @QueryParam("format") String format, @QueryParam("delimiter") String delimiter,
                            @QueryParam("firstRecordAsHeader") Boolean firstRecordAsHeader, @QueryParam("headers") String headers,
                            @QueryParam("commentMarker") String commentMarker,
                            @QueryParam("escape") String escape,
                            @QueryParam("ignoreEmptyLines") Boolean ignoreEmptyLines,
                            @QueryParam("ignoreHeaderCase") Boolean ignoreHeaderCase,
                            @QueryParam("ignoreSurroundingSpaces") Boolean ignoreSurroundingSpaces,
                            @QueryParam("nullString") String nullString,
                            @QueryParam("quote") String quote,
                            @QueryParam("allowDuplicateHeaderNames") Boolean allowDuplicateHeaderNames,
                            @QueryParam("allowMissingColumnNames") Boolean allowMissingColumnNames); }
CsvService { @POST @Consumes({ MediaType.APPLICATION_JSON }) @Produces({ MediaType.APPLICATION_JSON }) @Path("/inspect") @Operation(summary = "Inspect CSV", description = "Inspect a CSV instance and return a Document object") @RequestBody(description = "Csv", content = @Content(mediaType = "text/csv", schema = @Schema(implementation = String.class))) @ApiResponses(@ApiResponse(responseCode = "200", content = @Content(schema = @Schema(implementation = CsvInspectionResponse.class)), description = "Return a Document object")) public Response inspect(InputStream request, @QueryParam("format") String format, @QueryParam("delimiter") String delimiter, @QueryParam("firstRecordAsHeader") Boolean firstRecordAsHeader, @QueryParam("headers") String headers, @QueryParam("commentMarker") String commentMarker, @QueryParam("escape") String escape, @QueryParam("ignoreEmptyLines") Boolean ignoreEmptyLines, @QueryParam("ignoreHeaderCase") Boolean ignoreHeaderCase, @QueryParam("ignoreSurroundingSpaces") Boolean ignoreSurroundingSpaces, @QueryParam("nullString") String nullString, @QueryParam("quote") String quote, @QueryParam("allowDuplicateHeaderNames") Boolean allowDuplicateHeaderNames, @QueryParam("allowMissingColumnNames") Boolean allowMissingColumnNames) throws IOException { long startTime = System.currentTimeMillis(); CsvInspectionResponse response = new CsvInspectionResponse(); try { CsvConfig csvConfig = new CsvConfig(format); if (delimiter != null) { csvConfig.setDelimiter(delimiter.charAt(0)); } if (firstRecordAsHeader != null) { csvConfig.setFirstRecordAsHeader(firstRecordAsHeader); } csvConfig.setHeaders(headers); if (commentMarker != null) { csvConfig.setCommentMarker(commentMarker.charAt(0)); } if (escape != null) { csvConfig.setEscape(escape.charAt(0)); } csvConfig.setIgnoreEmptyLines(ignoreEmptyLines); csvConfig.setIgnoreHeaderCase(ignoreHeaderCase); csvConfig.setIgnoreSurroundingSpaces(ignoreSurroundingSpaces); csvConfig.setNullString(nullString); if (quote != null) { csvConfig.setQuote(quote.charAt(0)); } csvConfig.setAllowDuplicateHeaderNames(allowDuplicateHeaderNames); csvConfig.setAllowMissingColumnNames(allowMissingColumnNames); CsvFieldReader csvFieldReader = new CsvFieldReader(csvConfig); csvFieldReader.setDocument(request); Document document = csvFieldReader.readSchema(); response.setCsvDocument(document); request.close(); } catch (Exception e) { LOG.error("Error inspecting CSV: " + e.getMessage(), e); response.setErrorMessage(e.getMessage()); } finally { request.close();; response.setExecutionTime(System.currentTimeMillis() - startTime); } return Response.ok().entity(toJson(response)).build(); }  @GET @Path("/simple") @Produces(MediaType.TEXT_PLAIN) @Operation(summary = "Simple", description = "Simple hello service") @ApiResponses(@ApiResponse(responseCode = "200", content = @Content(schema = @Schema(implementation = String.class)), description = "Return a response")) String simpleHelloWorld(@QueryParam("from") String from); @POST @Consumes({ MediaType.APPLICATION_JSON }) @Produces({ MediaType.APPLICATION_JSON }) @Path("/inspect") @Operation(summary = "Inspect CSV", description = "Inspect a CSV instance and return a Document object") @RequestBody(description = "Csv", content = @Content(mediaType = "text/csv", schema = @Schema(implementation = String.class))) @ApiResponses(@ApiResponse(responseCode = "200", content = @Content(schema = @Schema(implementation = CsvInspectionResponse.class)), description = "Return a Document object")) Response inspect(InputStream request, @QueryParam("format") String format, @QueryParam("delimiter") String delimiter,
                            @QueryParam("firstRecordAsHeader") Boolean firstRecordAsHeader, @QueryParam("headers") String headers,
                            @QueryParam("commentMarker") String commentMarker,
                            @QueryParam("escape") String escape,
                            @QueryParam("ignoreEmptyLines") Boolean ignoreEmptyLines,
                            @QueryParam("ignoreHeaderCase") Boolean ignoreHeaderCase,
                            @QueryParam("ignoreSurroundingSpaces") Boolean ignoreSurroundingSpaces,
                            @QueryParam("nullString") String nullString,
                            @QueryParam("quote") String quote,
                            @QueryParam("allowDuplicateHeaderNames") Boolean allowDuplicateHeaderNames,
                            @QueryParam("allowMissingColumnNames") Boolean allowMissingColumnNames);  }