updates to make it compileable again
This commit is contained in:
@@ -35,7 +35,7 @@ import org.mustangproject.ZUGFeRD.ZUGFeRDExporter;
|
|||||||
import org.mustangproject.ZUGFeRD.ZUGFeRDExporterFromA1Factory;
|
import org.mustangproject.ZUGFeRD.ZUGFeRDExporterFromA1Factory;
|
||||||
import org.mustangproject.ZUGFeRD.ZUGFeRDImporter;
|
import org.mustangproject.ZUGFeRD.ZUGFeRDImporter;
|
||||||
import org.mustangproject.ZUGFeRD.ZUGFeRDMigrator;
|
import org.mustangproject.ZUGFeRD.ZUGFeRDMigrator;
|
||||||
import ZUV.ZUGFeRDValidator;
|
import org.mustangproject.library.extended.ZUGFeRDValidator;
|
||||||
|
|
||||||
/***
|
/***
|
||||||
* This is the command line interface to mustangproject
|
* This is the command line interface to mustangproject
|
||||||
|
|||||||
@@ -7,6 +7,8 @@ import java.io.FileNotFoundException;
|
|||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
import java.io.File;
|
||||||
|
import java.nio.file.*;
|
||||||
|
|
||||||
import javax.annotation.security.RolesAllowed;
|
import javax.annotation.security.RolesAllowed;
|
||||||
import javax.ws.rs.Consumes;
|
import javax.ws.rs.Consumes;
|
||||||
@@ -23,6 +25,8 @@ import org.mustangproject.ZUGFeRD.ZUGFeRDConformanceLevel;
|
|||||||
import org.mustangproject.ZUGFeRD.ZUGFeRDExporter;
|
import org.mustangproject.ZUGFeRD.ZUGFeRDExporter;
|
||||||
import org.mustangproject.ZUGFeRD.ZUGFeRDExporterFromA1Factory;
|
import org.mustangproject.ZUGFeRD.ZUGFeRDExporterFromA1Factory;
|
||||||
import org.mustangproject.ZUGFeRD.ZUGFeRDImporter;
|
import org.mustangproject.ZUGFeRD.ZUGFeRDImporter;
|
||||||
|
|
||||||
|
import org.mustangproject.library.extended.ZUGFeRDValidator;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
@@ -41,15 +45,9 @@ import io.swagger.annotations.SwaggerDefinition;
|
|||||||
@Path("/mustang")
|
@Path("/mustang")
|
||||||
@Produces(MediaType.APPLICATION_JSON)
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
@Api(value = "Mustang")
|
@Api(value = "Mustang")
|
||||||
@SwaggerDefinition(info=@Info(
|
@SwaggerDefinition(info = @Info(description = "Rest API to read/write hybrid (ZUGFeRD/Factur-X) e-invoices with a Mustang Server", version = "V0.0.2", title = "Mustangproject API", license = @License(name = "Apache 2.0", url = "http://www.apache.org")
|
||||||
description = "Rest API to read/write hybrid (ZUGFeRD/Factur-X) e-invoices with a Mustang Server",
|
|
||||||
version = "V0.0.2",
|
|
||||||
title = "Mustangproject API",
|
|
||||||
license = @License(name = "Apache 2.0", url = "http://www.apache.org")
|
|
||||||
|
|
||||||
),
|
), schemes = { SwaggerDefinition.Scheme.HTTP, SwaggerDefinition.Scheme.HTTPS })
|
||||||
schemes = {SwaggerDefinition.Scheme.HTTP, SwaggerDefinition.Scheme.HTTPS}
|
|
||||||
)
|
|
||||||
public class MustangResource {
|
public class MustangResource {
|
||||||
|
|
||||||
Logger logger = LoggerFactory.getLogger(MustangResource.class.getName());
|
Logger logger = LoggerFactory.getLogger(MustangResource.class.getName());
|
||||||
@@ -59,56 +57,82 @@ public class MustangResource {
|
|||||||
|
|
||||||
@POST
|
@POST
|
||||||
@Path("/extract")
|
@Path("/extract")
|
||||||
//@RolesAllowed("ADMIN")
|
// @RolesAllowed("ADMIN")
|
||||||
@Consumes(MediaType.MULTIPART_FORM_DATA)
|
@Consumes(MediaType.MULTIPART_FORM_DATA)
|
||||||
@Produces(MediaType.APPLICATION_XML)
|
@Produces(MediaType.APPLICATION_XML)
|
||||||
@ApiOperation(value="Extracts XML from a zf/fx PDF",notes="Input PDF must be ZUGFeRD or Factur-X")
|
@ApiOperation(value = "Extracts XML from a zf/fx PDF", notes = "Input PDF must be ZUGFeRD or Factur-X")
|
||||||
public String extractFile(@ApiParam(required=true,value="Input ZUGFeRD/Factur-X file") @FormDataParam("file") final InputStream fileInputStream,
|
public String extractFile(
|
||||||
|
@ApiParam(required = true, value = "Input ZUGFeRD/Factur-X file") @FormDataParam("file") final InputStream fileInputStream,
|
||||||
@FormDataParam("file") final FormDataContentDisposition contentDispositionHeader) {
|
@FormDataParam("file") final FormDataContentDisposition contentDispositionHeader) {
|
||||||
|
|
||||||
ZUGFeRDImporter zi;
|
ZUGFeRDImporter zi;
|
||||||
logger.debug("Reading...");
|
logger.debug("Reading...");
|
||||||
zi = new ZUGFeRDImporter(fileInputStream);
|
zi = new ZUGFeRDImporter(fileInputStream);
|
||||||
return "<response>"+zi.getUTF8()+"</response>";
|
return "<response>" + zi.getUTF8() + "</response>";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@POST
|
||||||
|
@Path("/validateFX")
|
||||||
|
// @RolesAllowed("ADMIN")
|
||||||
|
@Consumes(MediaType.MULTIPART_FORM_DATA)
|
||||||
|
@Produces(MediaType.APPLICATION_XML)
|
||||||
|
@ApiOperation(value = "Validates a ZUGFeRD PDF file", notes = "Input PDF must be ZUGFeRD or Factur-X")
|
||||||
|
public String validateFX(
|
||||||
|
@ApiParam(required = true, value = "Input ZUGFeRD/Factur-X file") @FormDataParam("file") final InputStream fileInputStream,
|
||||||
|
@FormDataParam("file") final FormDataContentDisposition contentDispositionHeader) {
|
||||||
|
ZUGFeRDValidator zfv = new ZUGFeRDValidator();
|
||||||
|
String validationResult = "";
|
||||||
|
try {
|
||||||
|
|
||||||
|
final File tempFile = File.createTempFile("tovalidate", ".pdf");
|
||||||
|
tempFile.deleteOnExit();
|
||||||
|
|
||||||
|
Files.copy(fileInputStream, tempFile.toPath(), StandardCopyOption.REPLACE_EXISTING);
|
||||||
|
|
||||||
|
validationResult = zfv.validate(tempFile.getAbsolutePath());
|
||||||
|
} catch (Exception ex) {
|
||||||
|
logger.error(ex.getMessage(),ex);
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.debug("Validating...");
|
||||||
|
return validationResult;
|
||||||
|
}
|
||||||
|
|
||||||
@POST
|
@POST
|
||||||
@Path("/combine")
|
@Path("/combine")
|
||||||
@RolesAllowed("ADMIN")
|
@RolesAllowed("ADMIN")
|
||||||
@Consumes(MediaType.MULTIPART_FORM_DATA)
|
@Consumes(MediaType.MULTIPART_FORM_DATA)
|
||||||
@Produces(MediaType.APPLICATION_OCTET_STREAM)
|
@Produces(MediaType.APPLICATION_OCTET_STREAM)
|
||||||
@ApiOperation(value="Combine PDF file and custom XML to zf/fx PDF",notes="Input PDF must be PDF/A-1, output PDF will be a ZUGFeRD/Factur-X PDF/A-3 file called invoice.pdf. Demo authentication good-guy:secret")
|
@ApiOperation(value = "Combine PDF file and custom XML to zf/fx PDF", notes = "Input PDF must be PDF/A-1, output PDF will be a ZUGFeRD/Factur-X PDF/A-3 file called invoice.pdf. Demo authentication good-guy:secret")
|
||||||
public Response combineFile(@ApiParam(required=true,value="Input PDF/A-1 file") @FormDataParam("file") final InputStream fileInputStream,
|
public Response combineFile(
|
||||||
|
@ApiParam(required = true, value = "Input PDF/A-1 file") @FormDataParam("file") final InputStream fileInputStream,
|
||||||
@FormDataParam("file") final FormDataContentDisposition contentDispositionHeader,
|
@FormDataParam("file") final FormDataContentDisposition contentDispositionHeader,
|
||||||
@ApiParam(required=true, value="The zf/fx XML to add to the file") @FormDataParam("xml") String XML,
|
@ApiParam(required = true, value = "The zf/fx XML to add to the file") @FormDataParam("xml") String XML,
|
||||||
@ApiParam(required=true, defaultValue="zf", value="zf|fx:zf for ZUGFeRD, fx for Factur-X") @FormDataParam("format") String format,
|
@ApiParam(required = true, defaultValue = "zf", value = "zf|fx:zf for ZUGFeRD, fx for Factur-X") @FormDataParam("format") String format,
|
||||||
@ApiParam(required=true, defaultValue="2", value="version, i.e. fx 1 or zf 1 or 2") @FormDataParam("version") int version,
|
@ApiParam(required = true, defaultValue = "2", value = "version, i.e. fx 1 or zf 1 or 2") @FormDataParam("version") int version,
|
||||||
@ApiParam(required=true, defaultValue="EN16931", value="Profile: BASIC|COMFORT|EXTENDED for zf1, MINIMUM|BASICWL|BASIC|CIUS|EN16931|EXTENDED for zf2/fx1") @FormDataParam("profile") String profile
|
@ApiParam(required = true, defaultValue = "EN16931", value = "Profile: BASIC|COMFORT|EXTENDED for zf1, MINIMUM|BASICWL|BASIC|CIUS|EN16931|EXTENDED for zf2/fx1") @FormDataParam("profile") String profile) {
|
||||||
) {
|
|
||||||
|
|
||||||
ZUGFeRDExporter ze;
|
ZUGFeRDExporter ze;
|
||||||
ByteArrayOutputStream output=new ByteArrayOutputStream();
|
ByteArrayOutputStream output = new ByteArrayOutputStream();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
logger.debug("Converting to PDF/A-3u");
|
logger.debug("Converting to PDF/A-3u");
|
||||||
|
|
||||||
if ((version<1)||(version>2)) {
|
if ((version < 1) || (version > 2)) {
|
||||||
// this should be checked with annotations but I did not get it to work
|
// this should be checked with annotations but I did not get it to work
|
||||||
throw new IllegalArgumentException("invalid version");
|
throw new IllegalArgumentException("invalid version");
|
||||||
}
|
}
|
||||||
|
|
||||||
// this should be restricted to the enum with annotations but I did not get it to work
|
// this should be restricted to the enum with annotations but I did not get it
|
||||||
ZUGFeRDConformanceLevel prof=ZUGFeRDConformanceLevel.valueOf(profile);
|
// to work
|
||||||
|
ZUGFeRDConformanceLevel prof = ZUGFeRDConformanceLevel.valueOf(profile);
|
||||||
/*
|
/*
|
||||||
* Add .setZUGFeRDVersion and .setZUGFeRDConformanceLevel in the next lines to
|
* Add .setZUGFeRDVersion and .setZUGFeRDConformanceLevel in the next lines to
|
||||||
* set the ZUGFeRD version respective profile of the XML you are inserting.
|
* set the ZUGFeRD version respective profile of the XML you are inserting.
|
||||||
*/
|
*/
|
||||||
ze = new ZUGFeRDExporterFromA1Factory().setProducer("Mustang API")
|
ze = new ZUGFeRDExporterFromA1Factory().setProducer("Mustang API")
|
||||||
.setCreator(System.getProperty("user.name"))
|
.setCreator(System.getProperty("user.name")).setZUGFeRDVersion(version)
|
||||||
.setZUGFeRDVersion(version)
|
.setZUGFeRDConformanceLevel(prof).load(fileInputStream);
|
||||||
.setZUGFeRDConformanceLevel(prof)
|
|
||||||
.load(fileInputStream);
|
|
||||||
logger.debug("Attaching ZUGFeRD-Data");
|
logger.debug("Attaching ZUGFeRD-Data");
|
||||||
if (format.equalsIgnoreCase("fx")) {
|
if (format.equalsIgnoreCase("fx")) {
|
||||||
ze.setFacturX();
|
ze.setFacturX();
|
||||||
@@ -123,9 +147,7 @@ public class MustangResource {
|
|||||||
byte[] bytes = output.toByteArray();
|
byte[] bytes = output.toByteArray();
|
||||||
InputStream inputStream = new ByteArrayInputStream(bytes);
|
InputStream inputStream = new ByteArrayInputStream(bytes);
|
||||||
|
|
||||||
return Response.ok(inputStream)
|
return Response.ok(inputStream).header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"invoice.pdf\"")
|
||||||
.header(HttpHeaders.CONTENT_DISPOSITION,
|
|
||||||
"attachment; filename=\"invoice.pdf\"")
|
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -134,12 +156,10 @@ public class MustangResource {
|
|||||||
@Path("/test")
|
@Path("/test")
|
||||||
@Consumes(MediaType.APPLICATION_JSON)
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
@Produces(MediaType.APPLICATION_JSON)
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
@ApiOperation(value="Returns a hello world",notes="Just a test")
|
@ApiOperation(value = "Returns a hello world", notes = "Just a test")
|
||||||
public Response test() {
|
public Response test() {
|
||||||
|
|
||||||
return Response.status(Response.Status.OK)
|
return Response.status(Response.Status.OK).entity("{\"payload\":\"test\"}").build();
|
||||||
.entity("{\"payload\":\"test\"}")
|
|
||||||
.build();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user