diff --git a/docs/bill_of_lading_v1.md b/docs/bill_of_lading_v1.md new file mode 100644 index 000000000..635e7b7fe --- /dev/null +++ b/docs/bill_of_lading_v1.md @@ -0,0 +1,227 @@ +--- +title: Bill of Lading OCR Java +category: 622b805aaec68102ea7fcbc2 +slug: java-bill-of-lading-ocr +parentDoc: 631a062c3718850f3519b793 +--- +The Java OCR SDK supports the [Bill of Lading API](https://platform.mindee.com/mindee/bill_of_lading). + +The [sample below](https://github.com/mindee/client-lib-test-data/blob/main/products/bill_of_lading/default_sample.jpg) can be used for testing purposes. +![Bill of Lading sample](https://github.com/mindee/client-lib-test-data/blob/main/products/bill_of_lading/default_sample.jpg?raw=true) + +# Quick-Start +```java +import com.mindee.MindeeClient; +import com.mindee.input.LocalInputSource; +import com.mindee.parsing.common.AsyncPredictResponse; +import com.mindee.product.billoflading.BillOfLadingV1; +import java.io.File; +import java.io.IOException; + +public class SimpleMindeeClient { + + public static void main(String[] args) throws IOException, InterruptedException { + String apiKey = "my-api-key"; + String filePath = "/path/to/the/file.ext"; + + // Init a new client + MindeeClient mindeeClient = new MindeeClient(apiKey); + + // Load a file from disk + LocalInputSource inputSource = new LocalInputSource(new File(filePath)); + + // Parse the file asynchronously + AsyncPredictResponse response = mindeeClient.enqueueAndParse( + BillOfLadingV1.class, + inputSource + ); + + // Print a summary of the response + System.out.println(response.toString()); + + // Print a summary of the predictions +// System.out.println(response.getDocumentObj().toString()); + + // Print the document-level predictions +// System.out.println(response.getDocumentObj().getInference().getPrediction().toString()); + + // Print the page-level predictions +// response.getDocumentObj().getInference().getPages().forEach( +// page -> System.out.println(page.toString()) +// ); + } + +} + +``` +# Field Types +## Standard Fields +These fields are generic and used in several products. + +### BaseField +Each prediction object contains a set of fields that inherit from the generic `BaseField` class. +A typical `BaseField` object will have the following attributes: + +* **confidence** (`Double`): the confidence score of the field prediction. +* **boundingBox** (`Polygon`): contains exactly 4 relative vertices (points) coordinates of a right rectangle containing the field in the document. +* **polygon** (`Polygon`): contains the relative vertices coordinates (`polygon` extends `List`) of a polygon containing the field in the image. +* **pageId** (`Integer`): the ID of the page, always `null` when at document-level. + +> **Note:** A `Point` simply refers to a List of `Double`. + + +Aside from the previous attributes, all basic fields have access to a custom `toString` method that can be used to print their value as a string. + +### StringField +The text field `StringField` extends `BaseField`, but also implements: +* **value** (`String`): corresponds to the field value. +* **rawValue** (`String`): corresponds to the raw value as it appears on the document. + +### DateField +The date field `DateField` extends `BaseField`, but also implements: + +* **value** (`LocalDate`): an accessible representation of the value as a Java object. Can be `null`. + +## Specific Fields +Fields which are specific to this product; they are not used in any other product. + +### Carrier Field +The shipping company responsible for transporting the goods. + +A `BillOfLadingV1Carrier` implements the following attributes: + +* **name** (`String`): The name of the carrier. +* **professionalNumber** (`String`): The professional number of the carrier. +* **scac** (`String`): The Standard Carrier Alpha Code (SCAC) of the carrier. +Fields which are specific to this product; they are not used in any other product. + +### Consignee Field +The party to whom the goods are being shipped. + +A `BillOfLadingV1Consignee` implements the following attributes: + +* **address** (`String`): The address of the consignee. +* **email** (`String`): The email of the shipper. +* **name** (`String`): The name of the consignee. +* **phone** (`String`): The phone number of the consignee. +Fields which are specific to this product; they are not used in any other product. + +### Items Field +The goods being shipped. + +A `BillOfLadingV1CarrierItem` implements the following attributes: + +* **description** (`String`): A description of the item. +* **grossWeight** (`Double`): The gross weight of the item. +* **measurement** (`Double`): The measurement of the item. +* **measurementUnit** (`String`): The unit of measurement for the measurement. +* **quantity** (`Double`): The quantity of the item being shipped. +* **weightUnit** (`String`): The unit of measurement for weights. +Fields which are specific to this product; they are not used in any other product. + +### Notify Party Field +The party to be notified of the arrival of the goods. + +A `BillOfLadingV1NotifyParty` implements the following attributes: + +* **address** (`String`): The address of the notify party. +* **email** (`String`): The email of the shipper. +* **name** (`String`): The name of the notify party. +* **phone** (`String`): The phone number of the notify party. +Fields which are specific to this product; they are not used in any other product. + +### Shipper Field +The party responsible for shipping the goods. + +A `BillOfLadingV1Shipper` implements the following attributes: + +* **address** (`String`): The address of the shipper. +* **email** (`String`): The email of the shipper. +* **name** (`String`): The name of the shipper. +* **phone** (`String`): The phone number of the shipper. + +# Attributes +The following fields are extracted for Bill of Lading V1: + +## Bill of Lading Number +**billOfLadingNumber**: A unique identifier assigned to a Bill of Lading document. + +```java +System.out.println(result.getDocument().getInference().getPrediction().getBillOfLadingNumber().value); +``` + +## Carrier +**carrier**([BillOfLadingV1Carrier](#carrier-field)): The shipping company responsible for transporting the goods. + +```java +System.out.println(result.getDocument().getInference().getPrediction().getCarrier().value); +``` + +## Items +**carrierItems**(List<[BillOfLadingV1CarrierItem](#items-field)>): The goods being shipped. + +```java +for (carrierItemsElem : result.getDocument().getInference().getPrediction().getCarrierItems()) +{ + System.out.println(carrierItemsElem.value); +} +``` + +## Consignee +**consignee**([BillOfLadingV1Consignee](#consignee-field)): The party to whom the goods are being shipped. + +```java +System.out.println(result.getDocument().getInference().getPrediction().getConsignee().value); +``` + +## Date of issue +**dateOfIssue**: The date when the bill of lading is issued. + +```java +System.out.println(result.getDocument().getInference().getPrediction().getDateOfIssue().value); +``` + +## Departure Date +**departureDate**: The date when the vessel departs from the port of loading. + +```java +System.out.println(result.getDocument().getInference().getPrediction().getDepartureDate().value); +``` + +## Notify Party +**notifyParty**([BillOfLadingV1NotifyParty](#notify-party-field)): The party to be notified of the arrival of the goods. + +```java +System.out.println(result.getDocument().getInference().getPrediction().getNotifyParty().value); +``` + +## Place of Delivery +**placeOfDelivery**: The place where the goods are to be delivered. + +```java +System.out.println(result.getDocument().getInference().getPrediction().getPlaceOfDelivery().value); +``` + +## Port of Discharge +**portOfDischarge**: The port where the goods are unloaded from the vessel. + +```java +System.out.println(result.getDocument().getInference().getPrediction().getPortOfDischarge().value); +``` + +## Port of Loading +**portOfLoading**: The port where the goods are loaded onto the vessel. + +```java +System.out.println(result.getDocument().getInference().getPrediction().getPortOfLoading().value); +``` + +## Shipper +**shipper**([BillOfLadingV1Shipper](#shipper-field)): The party responsible for shipping the goods. + +```java +System.out.println(result.getDocument().getInference().getPrediction().getShipper().value); +``` + +# Questions? +[Join our Slack](https://join.slack.com/t/mindee-community/shared_invite/zt-2d0ds7dtz-DPAF81ZqTy20chsYpQBW5g) diff --git a/docs/code_samples/bill_of_lading_v1_async.txt b/docs/code_samples/bill_of_lading_v1_async.txt new file mode 100644 index 000000000..cebc3224d --- /dev/null +++ b/docs/code_samples/bill_of_lading_v1_async.txt @@ -0,0 +1,41 @@ +import com.mindee.MindeeClient; +import com.mindee.input.LocalInputSource; +import com.mindee.parsing.common.AsyncPredictResponse; +import com.mindee.product.billoflading.BillOfLadingV1; +import java.io.File; +import java.io.IOException; + +public class SimpleMindeeClient { + + public static void main(String[] args) throws IOException, InterruptedException { + String apiKey = "my-api-key"; + String filePath = "/path/to/the/file.ext"; + + // Init a new client + MindeeClient mindeeClient = new MindeeClient(apiKey); + + // Load a file from disk + LocalInputSource inputSource = new LocalInputSource(new File(filePath)); + + // Parse the file asynchronously + AsyncPredictResponse response = mindeeClient.enqueueAndParse( + BillOfLadingV1.class, + inputSource + ); + + // Print a summary of the response + System.out.println(response.toString()); + + // Print a summary of the predictions +// System.out.println(response.getDocumentObj().toString()); + + // Print the document-level predictions +// System.out.println(response.getDocumentObj().getInference().getPrediction().toString()); + + // Print the page-level predictions +// response.getDocumentObj().getInference().getPages().forEach( +// page -> System.out.println(page.toString()) +// ); + } + +} diff --git a/docs/code_samples/energy_bill_fra_v1_async.txt b/docs/code_samples/energy_bill_fra_v1_async.txt new file mode 100644 index 000000000..b6d01da7c --- /dev/null +++ b/docs/code_samples/energy_bill_fra_v1_async.txt @@ -0,0 +1,41 @@ +import com.mindee.MindeeClient; +import com.mindee.input.LocalInputSource; +import com.mindee.parsing.common.AsyncPredictResponse; +import com.mindee.product.fr.energybill.EnergyBillV1; +import java.io.File; +import java.io.IOException; + +public class SimpleMindeeClient { + + public static void main(String[] args) throws IOException, InterruptedException { + String apiKey = "my-api-key"; + String filePath = "/path/to/the/file.ext"; + + // Init a new client + MindeeClient mindeeClient = new MindeeClient(apiKey); + + // Load a file from disk + LocalInputSource inputSource = new LocalInputSource(new File(filePath)); + + // Parse the file asynchronously + AsyncPredictResponse response = mindeeClient.enqueueAndParse( + EnergyBillV1.class, + inputSource + ); + + // Print a summary of the response + System.out.println(response.toString()); + + // Print a summary of the predictions +// System.out.println(response.getDocumentObj().toString()); + + // Print the document-level predictions +// System.out.println(response.getDocumentObj().getInference().getPrediction().toString()); + + // Print the page-level predictions +// response.getDocumentObj().getInference().getPages().forEach( +// page -> System.out.println(page.toString()) +// ); + } + +} diff --git a/docs/code_samples/nutrition_facts_v1_async.txt b/docs/code_samples/nutrition_facts_v1_async.txt new file mode 100644 index 000000000..528658aec --- /dev/null +++ b/docs/code_samples/nutrition_facts_v1_async.txt @@ -0,0 +1,41 @@ +import com.mindee.MindeeClient; +import com.mindee.input.LocalInputSource; +import com.mindee.parsing.common.AsyncPredictResponse; +import com.mindee.product.nutritionfactslabel.NutritionFactsLabelV1; +import java.io.File; +import java.io.IOException; + +public class SimpleMindeeClient { + + public static void main(String[] args) throws IOException, InterruptedException { + String apiKey = "my-api-key"; + String filePath = "/path/to/the/file.ext"; + + // Init a new client + MindeeClient mindeeClient = new MindeeClient(apiKey); + + // Load a file from disk + LocalInputSource inputSource = new LocalInputSource(new File(filePath)); + + // Parse the file asynchronously + AsyncPredictResponse response = mindeeClient.enqueueAndParse( + NutritionFactsLabelV1.class, + inputSource + ); + + // Print a summary of the response + System.out.println(response.toString()); + + // Print a summary of the predictions +// System.out.println(response.getDocumentObj().toString()); + + // Print the document-level predictions +// System.out.println(response.getDocumentObj().getInference().getPrediction().toString()); + + // Print the page-level predictions +// response.getDocumentObj().getInference().getPages().forEach( +// page -> System.out.println(page.toString()) +// ); + } + +} diff --git a/docs/code_samples/payslip_fra_v2_async.txt b/docs/code_samples/payslip_fra_v2_async.txt new file mode 100644 index 000000000..de1f74358 --- /dev/null +++ b/docs/code_samples/payslip_fra_v2_async.txt @@ -0,0 +1,41 @@ +import com.mindee.MindeeClient; +import com.mindee.input.LocalInputSource; +import com.mindee.parsing.common.AsyncPredictResponse; +import com.mindee.product.fr.payslip.PayslipV2; +import java.io.File; +import java.io.IOException; + +public class SimpleMindeeClient { + + public static void main(String[] args) throws IOException, InterruptedException { + String apiKey = "my-api-key"; + String filePath = "/path/to/the/file.ext"; + + // Init a new client + MindeeClient mindeeClient = new MindeeClient(apiKey); + + // Load a file from disk + LocalInputSource inputSource = new LocalInputSource(new File(filePath)); + + // Parse the file asynchronously + AsyncPredictResponse response = mindeeClient.enqueueAndParse( + PayslipV2.class, + inputSource + ); + + // Print a summary of the response + System.out.println(response.toString()); + + // Print a summary of the predictions +// System.out.println(response.getDocumentObj().toString()); + + // Print the document-level predictions +// System.out.println(response.getDocumentObj().getInference().getPrediction().toString()); + + // Print the page-level predictions +// response.getDocumentObj().getInference().getPages().forEach( +// page -> System.out.println(page.toString()) +// ); + } + +} diff --git a/docs/energy_bill_fra_v1.md b/docs/energy_bill_fra_v1.md new file mode 100644 index 000000000..60318165d --- /dev/null +++ b/docs/energy_bill_fra_v1.md @@ -0,0 +1,276 @@ +--- +title: FR Energy Bill OCR Java +category: 622b805aaec68102ea7fcbc2 +slug: java-fr-energy-bill-ocr +parentDoc: 631a062c3718850f3519b793 +--- +The Java OCR SDK supports the [Energy Bill API](https://platform.mindee.com/mindee/energy_bill_fra). + +The [sample below](https://github.com/mindee/client-lib-test-data/blob/main/products/energy_bill_fra/default_sample.jpg) can be used for testing purposes. +![Energy Bill sample](https://github.com/mindee/client-lib-test-data/blob/main/products/energy_bill_fra/default_sample.jpg?raw=true) + +# Quick-Start +```java +import com.mindee.MindeeClient; +import com.mindee.input.LocalInputSource; +import com.mindee.parsing.common.AsyncPredictResponse; +import com.mindee.product.fr.energybill.EnergyBillV1; +import java.io.File; +import java.io.IOException; + +public class SimpleMindeeClient { + + public static void main(String[] args) throws IOException, InterruptedException { + String apiKey = "my-api-key"; + String filePath = "/path/to/the/file.ext"; + + // Init a new client + MindeeClient mindeeClient = new MindeeClient(apiKey); + + // Load a file from disk + LocalInputSource inputSource = new LocalInputSource(new File(filePath)); + + // Parse the file asynchronously + AsyncPredictResponse response = mindeeClient.enqueueAndParse( + EnergyBillV1.class, + inputSource + ); + + // Print a summary of the response + System.out.println(response.toString()); + + // Print a summary of the predictions +// System.out.println(response.getDocumentObj().toString()); + + // Print the document-level predictions +// System.out.println(response.getDocumentObj().getInference().getPrediction().toString()); + + // Print the page-level predictions +// response.getDocumentObj().getInference().getPages().forEach( +// page -> System.out.println(page.toString()) +// ); + } + +} + +``` +# Field Types +## Standard Fields +These fields are generic and used in several products. + +### BaseField +Each prediction object contains a set of fields that inherit from the generic `BaseField` class. +A typical `BaseField` object will have the following attributes: + +* **confidence** (`Double`): the confidence score of the field prediction. +* **boundingBox** (`Polygon`): contains exactly 4 relative vertices (points) coordinates of a right rectangle containing the field in the document. +* **polygon** (`Polygon`): contains the relative vertices coordinates (`polygon` extends `List`) of a polygon containing the field in the image. +* **pageId** (`Integer`): the ID of the page, always `null` when at document-level. + +> **Note:** A `Point` simply refers to a List of `Double`. + + +Aside from the previous attributes, all basic fields have access to a custom `toString` method that can be used to print their value as a string. + +### AmountField +An amount field `AmountField` extends `BaseField`, but also implements: +* **value** (`Double`): corresponds to the field value. Can be `null` if no value was extracted. + +### StringField +The text field `StringField` extends `BaseField`, but also implements: +* **value** (`String`): corresponds to the field value. +* **rawValue** (`String`): corresponds to the raw value as it appears on the document. + +### DateField +The date field `DateField` extends `BaseField`, but also implements: + +* **value** (`LocalDate`): an accessible representation of the value as a Java object. Can be `null`. + +## Specific Fields +Fields which are specific to this product; they are not used in any other product. + +### Energy Consumer Field +The entity that consumes the energy. + +A `EnergyBillV1EnergyConsumer` implements the following attributes: + +* **address** (`String`): The address of the energy consumer. +* **name** (`String`): The name of the energy consumer. +Fields which are specific to this product; they are not used in any other product. + +### Energy Supplier Field +The company that supplies the energy. + +A `EnergyBillV1EnergySupplier` implements the following attributes: + +* **address** (`String`): The address of the energy supplier. +* **name** (`String`): The name of the energy supplier. +Fields which are specific to this product; they are not used in any other product. + +### Energy Usage Field +Details of energy consumption. + +A `EnergyBillV1EnergyUsage` implements the following attributes: + +* **description** (`String`): Description or details of the energy usage. +* **endDate** (`String`): The end date of the energy usage. +* **startDate** (`String`): The start date of the energy usage. +* **taxRate** (`Double`): The rate of tax applied to the total cost. +* **total** (`Double`): The total cost of energy consumed. +* **unitPrice** (`Double`): The price per unit of energy consumed. +Fields which are specific to this product; they are not used in any other product. + +### Meter Details Field +Information about the energy meter. + +A `EnergyBillV1MeterDetail` implements the following attributes: + +* **meterNumber** (`String`): The unique identifier of the energy meter. +* **meterType** (`String`): The type of energy meter. + +#### Possible values include: + - electricity + - gas + - water + - None + +* **unit** (`String`): The unit of measurement for energy consumption, which can be kW, m³, or L. +Fields which are specific to this product; they are not used in any other product. + +### Subscription Field +The subscription details fee for the energy service. + +A `EnergyBillV1Subscription` implements the following attributes: + +* **description** (`String`): Description or details of the subscription. +* **endDate** (`String`): The end date of the subscription. +* **startDate** (`String`): The start date of the subscription. +* **taxRate** (`Double`): The rate of tax applied to the total cost. +* **total** (`Double`): The total cost of subscription. +* **unitPrice** (`Double`): The price per unit of subscription. +Fields which are specific to this product; they are not used in any other product. + +### Taxes and Contributions Field +Details of Taxes and Contributions. + +A `EnergyBillV1TaxesAndContribution` implements the following attributes: + +* **description** (`String`): Description or details of the Taxes and Contributions. +* **endDate** (`String`): The end date of the Taxes and Contributions. +* **startDate** (`String`): The start date of the Taxes and Contributions. +* **taxRate** (`Double`): The rate of tax applied to the total cost. +* **total** (`Double`): The total cost of Taxes and Contributions. +* **unitPrice** (`Double`): The price per unit of Taxes and Contributions. + +# Attributes +The following fields are extracted for Energy Bill V1: + +## Contract ID +**contractId**: The unique identifier associated with a specific contract. + +```java +System.out.println(result.getDocument().getInference().getPrediction().getContractId().value); +``` + +## Delivery Point +**deliveryPoint**: The unique identifier assigned to each electricity or gas consumption point. It specifies the exact location where the energy is delivered. + +```java +System.out.println(result.getDocument().getInference().getPrediction().getDeliveryPoint().value); +``` + +## Due Date +**dueDate**: The date by which the payment for the energy invoice is due. + +```java +System.out.println(result.getDocument().getInference().getPrediction().getDueDate().value); +``` + +## Energy Consumer +**energyConsumer**([EnergyBillV1EnergyConsumer](#energy-consumer-field)): The entity that consumes the energy. + +```java +System.out.println(result.getDocument().getInference().getPrediction().getEnergyConsumer().value); +``` + +## Energy Supplier +**energySupplier**([EnergyBillV1EnergySupplier](#energy-supplier-field)): The company that supplies the energy. + +```java +System.out.println(result.getDocument().getInference().getPrediction().getEnergySupplier().value); +``` + +## Energy Usage +**energyUsage**(List<[EnergyBillV1EnergyUsage](#energy-usage-field)>): Details of energy consumption. + +```java +for (energyUsageElem : result.getDocument().getInference().getPrediction().getEnergyUsage()) +{ + System.out.println(energyUsageElem.value); +} +``` + +## Invoice Date +**invoiceDate**: The date when the energy invoice was issued. + +```java +System.out.println(result.getDocument().getInference().getPrediction().getInvoiceDate().value); +``` + +## Invoice Number +**invoiceNumber**: The unique identifier of the energy invoice. + +```java +System.out.println(result.getDocument().getInference().getPrediction().getInvoiceNumber().value); +``` + +## Meter Details +**meterDetails**([EnergyBillV1MeterDetail](#meter-details-field)): Information about the energy meter. + +```java +System.out.println(result.getDocument().getInference().getPrediction().getMeterDetails().value); +``` + +## Subscription +**subscription**(List<[EnergyBillV1Subscription](#subscription-field)>): The subscription details fee for the energy service. + +```java +for (subscriptionElem : result.getDocument().getInference().getPrediction().getSubscription()) +{ + System.out.println(subscriptionElem.value); +} +``` + +## Taxes and Contributions +**taxesAndContributions**(List<[EnergyBillV1TaxesAndContribution](#taxes-and-contributions-field)>): Details of Taxes and Contributions. + +```java +for (taxesAndContributionsElem : result.getDocument().getInference().getPrediction().getTaxesAndContributions()) +{ + System.out.println(taxesAndContributionsElem.value); +} +``` + +## Total Amount +**totalAmount**: The total amount to be paid for the energy invoice. + +```java +System.out.println(result.getDocument().getInference().getPrediction().getTotalAmount().value); +``` + +## Total Before Taxes +**totalBeforeTaxes**: The total amount to be paid for the energy invoice before taxes. + +```java +System.out.println(result.getDocument().getInference().getPrediction().getTotalBeforeTaxes().value); +``` + +## Total Taxes +**totalTaxes**: Total of taxes applied to the invoice. + +```java +System.out.println(result.getDocument().getInference().getPrediction().getTotalTaxes().value); +``` + +# Questions? +[Join our Slack](https://join.slack.com/t/mindee-community/shared_invite/zt-2d0ds7dtz-DPAF81ZqTy20chsYpQBW5g) diff --git a/docs/nutrition_facts_v1.md b/docs/nutrition_facts_v1.md new file mode 100644 index 000000000..1fa498c7c --- /dev/null +++ b/docs/nutrition_facts_v1.md @@ -0,0 +1,318 @@ +--- +title: Nutrition Facts Label OCR Java +category: 622b805aaec68102ea7fcbc2 +slug: java-nutrition-facts-label-ocr +parentDoc: 631a062c3718850f3519b793 +--- +The Java OCR SDK supports the [Nutrition Facts Label API](https://platform.mindee.com/mindee/nutrition_facts). + +The [sample below](https://github.com/mindee/client-lib-test-data/blob/main/products/nutrition_facts/default_sample.jpg) can be used for testing purposes. +![Nutrition Facts Label sample](https://github.com/mindee/client-lib-test-data/blob/main/products/nutrition_facts/default_sample.jpg?raw=true) + +# Quick-Start +```java +import com.mindee.MindeeClient; +import com.mindee.input.LocalInputSource; +import com.mindee.parsing.common.AsyncPredictResponse; +import com.mindee.product.nutritionfactslabel.NutritionFactsLabelV1; +import java.io.File; +import java.io.IOException; + +public class SimpleMindeeClient { + + public static void main(String[] args) throws IOException, InterruptedException { + String apiKey = "my-api-key"; + String filePath = "/path/to/the/file.ext"; + + // Init a new client + MindeeClient mindeeClient = new MindeeClient(apiKey); + + // Load a file from disk + LocalInputSource inputSource = new LocalInputSource(new File(filePath)); + + // Parse the file asynchronously + AsyncPredictResponse response = mindeeClient.enqueueAndParse( + NutritionFactsLabelV1.class, + inputSource + ); + + // Print a summary of the response + System.out.println(response.toString()); + + // Print a summary of the predictions +// System.out.println(response.getDocumentObj().toString()); + + // Print the document-level predictions +// System.out.println(response.getDocumentObj().getInference().getPrediction().toString()); + + // Print the page-level predictions +// response.getDocumentObj().getInference().getPages().forEach( +// page -> System.out.println(page.toString()) +// ); + } + +} + +``` +# Field Types +## Standard Fields +These fields are generic and used in several products. + +### BaseField +Each prediction object contains a set of fields that inherit from the generic `BaseField` class. +A typical `BaseField` object will have the following attributes: + +* **confidence** (`Double`): the confidence score of the field prediction. +* **boundingBox** (`Polygon`): contains exactly 4 relative vertices (points) coordinates of a right rectangle containing the field in the document. +* **polygon** (`Polygon`): contains the relative vertices coordinates (`polygon` extends `List`) of a polygon containing the field in the image. +* **pageId** (`Integer`): the ID of the page, always `null` when at document-level. + +> **Note:** A `Point` simply refers to a List of `Double`. + + +Aside from the previous attributes, all basic fields have access to a custom `toString` method that can be used to print their value as a string. + +### AmountField +An amount field `AmountField` extends `BaseField`, but also implements: +* **value** (`Double`): corresponds to the field value. Can be `null` if no value was extracted. + +## Specific Fields +Fields which are specific to this product; they are not used in any other product. + +### Added Sugars Field +The amount of added sugars in the product. + +A `NutritionFactsLabelV1AddedSugar` implements the following attributes: + +* **dailyValue** (`Double`): DVs are the recommended amounts of added sugars to consume or not to exceed each day. +* **per100G** (`Double`): The amount of added sugars per 100g of the product. +* **perServing** (`Double`): The amount of added sugars per serving of the product. +Fields which are specific to this product; they are not used in any other product. + +### Calories Field +The amount of calories in the product. + +A `NutritionFactsLabelV1Calorie` implements the following attributes: + +* **dailyValue** (`Double`): DVs are the recommended amounts of calories to consume or not to exceed each day. +* **per100G** (`Double`): The amount of calories per 100g of the product. +* **perServing** (`Double`): The amount of calories per serving of the product. +Fields which are specific to this product; they are not used in any other product. + +### Cholesterol Field +The amount of cholesterol in the product. + +A `NutritionFactsLabelV1Cholesterol` implements the following attributes: + +* **dailyValue** (`Double`): DVs are the recommended amounts of cholesterol to consume or not to exceed each day. +* **per100G** (`Double`): The amount of cholesterol per 100g of the product. +* **perServing** (`Double`): The amount of cholesterol per serving of the product. +Fields which are specific to this product; they are not used in any other product. + +### Dietary Fiber Field +The amount of dietary fiber in the product. + +A `NutritionFactsLabelV1DietaryFiber` implements the following attributes: + +* **dailyValue** (`Double`): DVs are the recommended amounts of dietary fiber to consume or not to exceed each day. +* **per100G** (`Double`): The amount of dietary fiber per 100g of the product. +* **perServing** (`Double`): The amount of dietary fiber per serving of the product. +Fields which are specific to this product; they are not used in any other product. + +### nutrients Field +The amount of nutrients in the product. + +A `NutritionFactsLabelV1Nutrient` implements the following attributes: + +* **dailyValue** (`Double`): DVs are the recommended amounts of nutrients to consume or not to exceed each day. +* **name** (`String`): The name of nutrients of the product. +* **per100G** (`Double`): The amount of nutrients per 100g of the product. +* **perServing** (`Double`): The amount of nutrients per serving of the product. +* **unit** (`String`): The unit of measurement for the amount of nutrients. +Fields which are specific to this product; they are not used in any other product. + +### Protein Field +The amount of protein in the product. + +A `NutritionFactsLabelV1Protein` implements the following attributes: + +* **dailyValue** (`Double`): DVs are the recommended amounts of protein to consume or not to exceed each day. +* **per100G** (`Double`): The amount of protein per 100g of the product. +* **perServing** (`Double`): The amount of protein per serving of the product. +Fields which are specific to this product; they are not used in any other product. + +### Saturated Fat Field +The amount of saturated fat in the product. + +A `NutritionFactsLabelV1SaturatedFat` implements the following attributes: + +* **dailyValue** (`Double`): DVs are the recommended amounts of saturated fat to consume or not to exceed each day. +* **per100G** (`Double`): The amount of saturated fat per 100g of the product. +* **perServing** (`Double`): The amount of saturated fat per serving of the product. +Fields which are specific to this product; they are not used in any other product. + +### Serving Size Field +The size of a single serving of the product. + +A `NutritionFactsLabelV1ServingSize` implements the following attributes: + +* **amount** (`Double`): The amount of a single serving. +* **unit** (`String`): The unit for the amount of a single serving. +Fields which are specific to this product; they are not used in any other product. + +### sodium Field +The amount of sodium in the product. + +A `NutritionFactsLabelV1Sodium` implements the following attributes: + +* **dailyValue** (`Double`): DVs are the recommended amounts of sodium to consume or not to exceed each day. +* **per100G** (`Double`): The amount of sodium per 100g of the product. +* **perServing** (`Double`): The amount of sodium per serving of the product. +* **unit** (`String`): The unit of measurement for the amount of sodium. +Fields which are specific to this product; they are not used in any other product. + +### Total Carbohydrate Field +The total amount of carbohydrates in the product. + +A `NutritionFactsLabelV1TotalCarbohydrate` implements the following attributes: + +* **dailyValue** (`Double`): DVs are the recommended amounts of total carbohydrates to consume or not to exceed each day. +* **per100G** (`Double`): The amount of total carbohydrates per 100g of the product. +* **perServing** (`Double`): The amount of total carbohydrates per serving of the product. +Fields which are specific to this product; they are not used in any other product. + +### Total Fat Field +The total amount of fat in the product. + +A `NutritionFactsLabelV1TotalFat` implements the following attributes: + +* **dailyValue** (`Double`): DVs are the recommended amounts of total fat to consume or not to exceed each day. +* **per100G** (`Double`): The amount of total fat per 100g of the product. +* **perServing** (`Double`): The amount of total fat per serving of the product. +Fields which are specific to this product; they are not used in any other product. + +### Total Sugars Field +The total amount of sugars in the product. + +A `NutritionFactsLabelV1TotalSugar` implements the following attributes: + +* **dailyValue** (`Double`): DVs are the recommended amounts of total sugars to consume or not to exceed each day. +* **per100G** (`Double`): The amount of total sugars per 100g of the product. +* **perServing** (`Double`): The amount of total sugars per serving of the product. +Fields which are specific to this product; they are not used in any other product. + +### Trans Fat Field +The amount of trans fat in the product. + +A `NutritionFactsLabelV1TransFat` implements the following attributes: + +* **dailyValue** (`Double`): DVs are the recommended amounts of trans fat to consume or not to exceed each day. +* **per100G** (`Double`): The amount of trans fat per 100g of the product. +* **perServing** (`Double`): The amount of trans fat per serving of the product. + +# Attributes +The following fields are extracted for Nutrition Facts Label V1: + +## Added Sugars +**addedSugars**([NutritionFactsLabelV1AddedSugar](#added-sugars-field)): The amount of added sugars in the product. + +```java +System.out.println(result.getDocument().getInference().getPrediction().getAddedSugars().value); +``` + +## Calories +**calories**([NutritionFactsLabelV1Calorie](#calories-field)): The amount of calories in the product. + +```java +System.out.println(result.getDocument().getInference().getPrediction().getCalories().value); +``` + +## Cholesterol +**cholesterol**([NutritionFactsLabelV1Cholesterol](#cholesterol-field)): The amount of cholesterol in the product. + +```java +System.out.println(result.getDocument().getInference().getPrediction().getCholesterol().value); +``` + +## Dietary Fiber +**dietaryFiber**([NutritionFactsLabelV1DietaryFiber](#dietary-fiber-field)): The amount of dietary fiber in the product. + +```java +System.out.println(result.getDocument().getInference().getPrediction().getDietaryFiber().value); +``` + +## nutrients +**nutrients**(List<[NutritionFactsLabelV1Nutrient](#nutrients-field)>): The amount of nutrients in the product. + +```java +for (nutrientsElem : result.getDocument().getInference().getPrediction().getNutrients()) +{ + System.out.println(nutrientsElem.value); +} +``` + +## Protein +**protein**([NutritionFactsLabelV1Protein](#protein-field)): The amount of protein in the product. + +```java +System.out.println(result.getDocument().getInference().getPrediction().getProtein().value); +``` + +## Saturated Fat +**saturatedFat**([NutritionFactsLabelV1SaturatedFat](#saturated-fat-field)): The amount of saturated fat in the product. + +```java +System.out.println(result.getDocument().getInference().getPrediction().getSaturatedFat().value); +``` + +## Serving per Box +**servingPerBox**: The number of servings in each box of the product. + +```java +System.out.println(result.getDocument().getInference().getPrediction().getServingPerBox().value); +``` + +## Serving Size +**servingSize**([NutritionFactsLabelV1ServingSize](#serving-size-field)): The size of a single serving of the product. + +```java +System.out.println(result.getDocument().getInference().getPrediction().getServingSize().value); +``` + +## sodium +**sodium**([NutritionFactsLabelV1Sodium](#sodium-field)): The amount of sodium in the product. + +```java +System.out.println(result.getDocument().getInference().getPrediction().getSodium().value); +``` + +## Total Carbohydrate +**totalCarbohydrate**([NutritionFactsLabelV1TotalCarbohydrate](#total-carbohydrate-field)): The total amount of carbohydrates in the product. + +```java +System.out.println(result.getDocument().getInference().getPrediction().getTotalCarbohydrate().value); +``` + +## Total Fat +**totalFat**([NutritionFactsLabelV1TotalFat](#total-fat-field)): The total amount of fat in the product. + +```java +System.out.println(result.getDocument().getInference().getPrediction().getTotalFat().value); +``` + +## Total Sugars +**totalSugars**([NutritionFactsLabelV1TotalSugar](#total-sugars-field)): The total amount of sugars in the product. + +```java +System.out.println(result.getDocument().getInference().getPrediction().getTotalSugars().value); +``` + +## Trans Fat +**transFat**([NutritionFactsLabelV1TransFat](#trans-fat-field)): The amount of trans fat in the product. + +```java +System.out.println(result.getDocument().getInference().getPrediction().getTransFat().value); +``` + +# Questions? +[Join our Slack](https://join.slack.com/t/mindee-community/shared_invite/zt-2d0ds7dtz-DPAF81ZqTy20chsYpQBW5g) diff --git a/docs/payslip_fra_v2.md b/docs/payslip_fra_v2.md new file mode 100644 index 000000000..e7483258c --- /dev/null +++ b/docs/payslip_fra_v2.md @@ -0,0 +1,241 @@ +--- +title: FR Payslip OCR Java +category: 622b805aaec68102ea7fcbc2 +slug: java-fr-payslip-ocr +parentDoc: 631a062c3718850f3519b793 +--- +The Java OCR SDK supports the [Payslip API](https://platform.mindee.com/mindee/payslip_fra). + +The [sample below](https://github.com/mindee/client-lib-test-data/blob/main/products/payslip_fra/default_sample.jpg) can be used for testing purposes. +![Payslip sample](https://github.com/mindee/client-lib-test-data/blob/main/products/payslip_fra/default_sample.jpg?raw=true) + +# Quick-Start +```java +import com.mindee.MindeeClient; +import com.mindee.input.LocalInputSource; +import com.mindee.parsing.common.AsyncPredictResponse; +import com.mindee.product.fr.payslip.PayslipV2; +import java.io.File; +import java.io.IOException; + +public class SimpleMindeeClient { + + public static void main(String[] args) throws IOException, InterruptedException { + String apiKey = "my-api-key"; + String filePath = "/path/to/the/file.ext"; + + // Init a new client + MindeeClient mindeeClient = new MindeeClient(apiKey); + + // Load a file from disk + LocalInputSource inputSource = new LocalInputSource(new File(filePath)); + + // Parse the file asynchronously + AsyncPredictResponse response = mindeeClient.enqueueAndParse( + PayslipV2.class, + inputSource + ); + + // Print a summary of the response + System.out.println(response.toString()); + + // Print a summary of the predictions +// System.out.println(response.getDocumentObj().toString()); + + // Print the document-level predictions +// System.out.println(response.getDocumentObj().getInference().getPrediction().toString()); + + // Print the page-level predictions +// response.getDocumentObj().getInference().getPages().forEach( +// page -> System.out.println(page.toString()) +// ); + } + +} + +``` +# Field Types +## Standard Fields +These fields are generic and used in several products. + +### BaseField +Each prediction object contains a set of fields that inherit from the generic `BaseField` class. +A typical `BaseField` object will have the following attributes: + +* **confidence** (`Double`): the confidence score of the field prediction. +* **boundingBox** (`Polygon`): contains exactly 4 relative vertices (points) coordinates of a right rectangle containing the field in the document. +* **polygon** (`Polygon`): contains the relative vertices coordinates (`polygon` extends `List`) of a polygon containing the field in the image. +* **pageId** (`Integer`): the ID of the page, always `null` when at document-level. + +> **Note:** A `Point` simply refers to a List of `Double`. + + +Aside from the previous attributes, all basic fields have access to a custom `toString` method that can be used to print their value as a string. + +## Specific Fields +Fields which are specific to this product; they are not used in any other product. + +### Bank Account Details Field +Information about the employee's bank account. + +A `PayslipV2BankAccountDetail` implements the following attributes: + +* **bankName** (`String`): The name of the bank. +* **iban** (`String`): The IBAN of the bank account. +* **swift** (`String`): The SWIFT code of the bank. +Fields which are specific to this product; they are not used in any other product. + +### Employee Field +Information about the employee. + +A `PayslipV2Employee` implements the following attributes: + +* **address** (`String`): The address of the employee. +* **dateOfBirth** (`String`): The date of birth of the employee. +* **firstName** (`String`): The first name of the employee. +* **lastName** (`String`): The last name of the employee. +* **phoneNumber** (`String`): The phone number of the employee. +* **registrationNumber** (`String`): The registration number of the employee. +* **socialSecurityNumber** (`String`): The social security number of the employee. +Fields which are specific to this product; they are not used in any other product. + +### Employer Field +Information about the employer. + +A `PayslipV2Employer` implements the following attributes: + +* **address** (`String`): The address of the employer. +* **companyId** (`String`): The company ID of the employer. +* **companySite** (`String`): The site of the company. +* **nafCode** (`String`): The NAF code of the employer. +* **name** (`String`): The name of the employer. +* **phoneNumber** (`String`): The phone number of the employer. +* **urssafNumber** (`String`): The URSSAF number of the employer. +Fields which are specific to this product; they are not used in any other product. + +### Employment Field +Information about the employment. + +A `PayslipV2Employment` implements the following attributes: + +* **category** (`String`): The category of the employment. +* **coefficient** (`Double`): The coefficient of the employment. +* **collectiveAgreement** (`String`): The collective agreement of the employment. +* **jobTitle** (`String`): The job title of the employee. +* **positionLevel** (`String`): The position level of the employment. +* **startDate** (`String`): The start date of the employment. +Fields which are specific to this product; they are not used in any other product. + +### Pay Detail Field +Detailed information about the pay. + +A `PayslipV2PayDetail` implements the following attributes: + +* **grossSalary** (`Double`): The gross salary of the employee. +* **grossSalaryYtd** (`Double`): The year-to-date gross salary of the employee. +* **incomeTaxRate** (`Double`): The income tax rate of the employee. +* **incomeTaxWithheld** (`Double`): The income tax withheld from the employee's pay. +* **netPaid** (`Double`): The net paid amount of the employee. +* **netPaidBeforeTax** (`Double`): The net paid amount before tax of the employee. +* **netTaxable** (`Double`): The net taxable amount of the employee. +* **netTaxableYtd** (`Double`): The year-to-date net taxable amount of the employee. +* **totalCostEmployer** (`Double`): The total cost to the employer. +* **totalTaxesAndDeductions** (`Double`): The total taxes and deductions of the employee. +Fields which are specific to this product; they are not used in any other product. + +### Pay Period Field +Information about the pay period. + +A `PayslipV2PayPeriod` implements the following attributes: + +* **endDate** (`String`): The end date of the pay period. +* **month** (`String`): The month of the pay period. +* **paymentDate** (`String`): The date of payment for the pay period. +* **startDate** (`String`): The start date of the pay period. +* **year** (`String`): The year of the pay period. +Fields which are specific to this product; they are not used in any other product. + +### PTO Field +Information about paid time off. + +A `PayslipV2Pto` implements the following attributes: + +* **accruedThisPeriod** (`Double`): The amount of paid time off accrued in this period. +* **balanceEndOfPeriod** (`Double`): The balance of paid time off at the end of the period. +* **usedThisPeriod** (`Double`): The amount of paid time off used in this period. +Fields which are specific to this product; they are not used in any other product. + +### Salary Details Field +Detailed information about the earnings. + +A `PayslipV2SalaryDetail` implements the following attributes: + +* **amount** (`Double`): The amount of the earnings. +* **base** (`Double`): The base value of the earnings. +* **description** (`String`): The description of the earnings. +* **rate** (`Double`): The rate of the earnings. + +# Attributes +The following fields are extracted for Payslip V2: + +## Bank Account Details +**bankAccountDetails**([PayslipV2BankAccountDetail](#bank-account-details-field)): Information about the employee's bank account. + +```java +System.out.println(result.getDocument().getInference().getPrediction().getBankAccountDetails().value); +``` + +## Employee +**employee**([PayslipV2Employee](#employee-field)): Information about the employee. + +```java +System.out.println(result.getDocument().getInference().getPrediction().getEmployee().value); +``` + +## Employer +**employer**([PayslipV2Employer](#employer-field)): Information about the employer. + +```java +System.out.println(result.getDocument().getInference().getPrediction().getEmployer().value); +``` + +## Employment +**employment**([PayslipV2Employment](#employment-field)): Information about the employment. + +```java +System.out.println(result.getDocument().getInference().getPrediction().getEmployment().value); +``` + +## Pay Detail +**payDetail**([PayslipV2PayDetail](#pay-detail-field)): Detailed information about the pay. + +```java +System.out.println(result.getDocument().getInference().getPrediction().getPayDetail().value); +``` + +## Pay Period +**payPeriod**([PayslipV2PayPeriod](#pay-period-field)): Information about the pay period. + +```java +System.out.println(result.getDocument().getInference().getPrediction().getPayPeriod().value); +``` + +## PTO +**pto**([PayslipV2Pto](#pto-field)): Information about paid time off. + +```java +System.out.println(result.getDocument().getInference().getPrediction().getPto().value); +``` + +## Salary Details +**salaryDetails**(List<[PayslipV2SalaryDetail](#salary-details-field)>): Detailed information about the earnings. + +```java +for (salaryDetailsElem : result.getDocument().getInference().getPrediction().getSalaryDetails()) +{ + System.out.println(salaryDetailsElem.value); +} +``` + +# Questions? +[Join our Slack](https://join.slack.com/t/mindee-community/shared_invite/zt-2d0ds7dtz-DPAF81ZqTy20chsYpQBW5g) diff --git a/src/main/java/com/mindee/parsing/SummaryHelper.java b/src/main/java/com/mindee/parsing/SummaryHelper.java index d30151c05..c3954747e 100644 --- a/src/main/java/com/mindee/parsing/SummaryHelper.java +++ b/src/main/java/com/mindee/parsing/SummaryHelper.java @@ -18,7 +18,13 @@ public static String cleanSummary(String summaryToClean) { } public static String formatAmount(Double amountValue) { - return amountValue == null ? "" : new DecimalFormat("0.00#").format(amountValue); + if (amountValue == null) { + return ""; + } + DecimalFormat df = new DecimalFormat("0.00###"); + df.setMinimumFractionDigits(2); + df.setMaximumFractionDigits(5); + return df.format(amountValue); } public static String formatString(String str) { @@ -49,10 +55,11 @@ public static String formatForDisplay(String inputValue, Integer maxColSize) { if (inputValue == null || inputValue.isEmpty()) { return ""; } - if (maxColSize == null || inputValue.length() <= maxColSize) { - return inputValue; + String outputValue = inputValue.replace("\n", "\\n").replace("\t", "\\t").replace("\r", "\\r"); + if (maxColSize == null || outputValue.length() <= maxColSize) { + return outputValue; } else { - return inputValue.substring(0, maxColSize - 3) + "..."; + return outputValue.substring(0, maxColSize - 3) + "..."; } } diff --git a/src/main/java/com/mindee/product/billoflading/BillOfLadingV1.java b/src/main/java/com/mindee/product/billoflading/BillOfLadingV1.java new file mode 100644 index 000000000..c0b0ed20b --- /dev/null +++ b/src/main/java/com/mindee/product/billoflading/BillOfLadingV1.java @@ -0,0 +1,16 @@ +package com.mindee.product.billoflading; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.mindee.http.EndpointInfo; +import com.mindee.parsing.common.Inference; +import lombok.Getter; + +/** + * Bill of Lading API version 1 inference prediction. + */ +@Getter +@JsonIgnoreProperties(ignoreUnknown = true) +@EndpointInfo(endpointName = "bill_of_lading", version = "1") +public class BillOfLadingV1 + extends Inference { +} diff --git a/src/main/java/com/mindee/product/billoflading/BillOfLadingV1Carrier.java b/src/main/java/com/mindee/product/billoflading/BillOfLadingV1Carrier.java new file mode 100644 index 000000000..04e600dbd --- /dev/null +++ b/src/main/java/com/mindee/product/billoflading/BillOfLadingV1Carrier.java @@ -0,0 +1,68 @@ +package com.mindee.product.billoflading; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.mindee.parsing.SummaryHelper; +import com.mindee.parsing.standard.BaseField; +import java.util.HashMap; +import java.util.Map; +import lombok.Getter; + +/** + * The shipping company responsible for transporting the goods. + */ +@Getter +@JsonIgnoreProperties(ignoreUnknown = true) +public class BillOfLadingV1Carrier extends BaseField { + + /** + * The name of the carrier. + */ + @JsonProperty("name") + String name; + /** + * The professional number of the carrier. + */ + @JsonProperty("professional_number") + String professionalNumber; + /** + * The Standard Carrier Alpha Code (SCAC) of the carrier. + */ + @JsonProperty("scac") + String scac; + + public boolean isEmpty() { + return ( + (name == null || name.isEmpty()) + && (professionalNumber == null || professionalNumber.isEmpty()) + && (scac == null || scac.isEmpty()) + ); + } + + /** + * Output the object in a format suitable for inclusion in an rST field list. + */ + public String toFieldList() { + Map printable = this.printableValues(); + return String.format(" :Name: %s%n", printable.get("name")) + + String.format(" :Professional Number: %s%n", printable.get("professionalNumber")) + + String.format(" :SCAC: %s%n", printable.get("scac")); + } + + @Override + public String toString() { + Map printable = this.printableValues(); + return String.format("Name: %s", printable.get("name")) + + String.format(", Professional Number: %s", printable.get("professionalNumber")) + + String.format(", SCAC: %s", printable.get("scac")); + } + + private Map printableValues() { + Map printable = new HashMap<>(); + + printable.put("name", SummaryHelper.formatForDisplay(this.name, null)); + printable.put("professionalNumber", SummaryHelper.formatForDisplay(this.professionalNumber, null)); + printable.put("scac", SummaryHelper.formatForDisplay(this.scac, null)); + return printable; + } +} diff --git a/src/main/java/com/mindee/product/billoflading/BillOfLadingV1CarrierItem.java b/src/main/java/com/mindee/product/billoflading/BillOfLadingV1CarrierItem.java new file mode 100644 index 000000000..ebb4f281d --- /dev/null +++ b/src/main/java/com/mindee/product/billoflading/BillOfLadingV1CarrierItem.java @@ -0,0 +1,126 @@ +package com.mindee.product.billoflading; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.mindee.parsing.SummaryHelper; +import com.mindee.parsing.standard.BaseField; +import com.mindee.parsing.standard.LineItemField; +import java.util.HashMap; +import java.util.Map; +import lombok.Getter; + +/** + * The goods being shipped. + */ +@Getter +@JsonIgnoreProperties(ignoreUnknown = true) +public class BillOfLadingV1CarrierItem extends BaseField implements LineItemField { + + /** + * A description of the item. + */ + @JsonProperty("description") + String description; + /** + * The gross weight of the item. + */ + @JsonProperty("gross_weight") + Double grossWeight; + /** + * The measurement of the item. + */ + @JsonProperty("measurement") + Double measurement; + /** + * The unit of measurement for the measurement. + */ + @JsonProperty("measurement_unit") + String measurementUnit; + /** + * The quantity of the item being shipped. + */ + @JsonProperty("quantity") + Double quantity; + /** + * The unit of measurement for weights. + */ + @JsonProperty("weight_unit") + String weightUnit; + + public boolean isEmpty() { + return ( + (description == null || description.isEmpty()) + && grossWeight == null + && measurement == null + && (measurementUnit == null || measurementUnit.isEmpty()) + && quantity == null + && (weightUnit == null || weightUnit.isEmpty()) + ); + } + + private Map tablePrintableValues() { + Map printable = new HashMap<>(); + + printable.put("description", SummaryHelper.formatForDisplay(this.description, 36)); + printable.put( + "grossWeight", + SummaryHelper.formatAmount(this.grossWeight) + ); + printable.put( + "measurement", + SummaryHelper.formatAmount(this.measurement) + ); + printable.put("measurementUnit", SummaryHelper.formatForDisplay(this.measurementUnit, null)); + printable.put( + "quantity", + SummaryHelper.formatAmount(this.quantity) + ); + printable.put("weightUnit", SummaryHelper.formatForDisplay(this.weightUnit, null)); + return printable; + } + + /** + * Output the line in a format suitable for inclusion in an rST table. + */ + public String toTableLine() { + Map printable = this.tablePrintableValues(); + return String.format("| %-36s ", printable.get("description")) + + String.format("| %-12s ", printable.get("grossWeight")) + + String.format("| %-11s ", printable.get("measurement")) + + String.format("| %-16s ", printable.get("measurementUnit")) + + String.format("| %-8s ", printable.get("quantity")) + + String.format("| %-11s |", printable.get("weightUnit")); + } + + @Override + public String toString() { + Map printable = this.printableValues(); + return String.format("Description: %s", printable.get("description")) + + String.format(", Gross Weight: %s", printable.get("grossWeight")) + + String.format(", Measurement: %s", printable.get("measurement")) + + String.format(", Measurement Unit: %s", printable.get("measurementUnit")) + + String.format(", Quantity: %s", printable.get("quantity")) + + String.format(", Weight Unit: %s", printable.get("weightUnit")); + } + + private Map printableValues() { + Map printable = new HashMap<>(); + + printable.put("description", SummaryHelper.formatForDisplay(this.description, null)); + printable.put( + "grossWeight", + SummaryHelper.formatAmount(this.grossWeight) + ); + printable.put( + "measurement", + SummaryHelper.formatAmount(this.measurement) + ); + printable.put("measurementUnit", SummaryHelper.formatForDisplay(this.measurementUnit, null)); + printable.put( + "quantity", + SummaryHelper.formatAmount(this.quantity) + ); + printable.put("weightUnit", SummaryHelper.formatForDisplay(this.weightUnit, null)); + return printable; + } +} diff --git a/src/main/java/com/mindee/product/billoflading/BillOfLadingV1Consignee.java b/src/main/java/com/mindee/product/billoflading/BillOfLadingV1Consignee.java new file mode 100644 index 000000000..2a93ed54b --- /dev/null +++ b/src/main/java/com/mindee/product/billoflading/BillOfLadingV1Consignee.java @@ -0,0 +1,77 @@ +package com.mindee.product.billoflading; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.mindee.parsing.SummaryHelper; +import com.mindee.parsing.standard.BaseField; +import java.util.HashMap; +import java.util.Map; +import lombok.Getter; + +/** + * The party to whom the goods are being shipped. + */ +@Getter +@JsonIgnoreProperties(ignoreUnknown = true) +public class BillOfLadingV1Consignee extends BaseField { + + /** + * The address of the consignee. + */ + @JsonProperty("address") + String address; + /** + * The email of the shipper. + */ + @JsonProperty("email") + String email; + /** + * The name of the consignee. + */ + @JsonProperty("name") + String name; + /** + * The phone number of the consignee. + */ + @JsonProperty("phone") + String phone; + + public boolean isEmpty() { + return ( + (address == null || address.isEmpty()) + && (email == null || email.isEmpty()) + && (name == null || name.isEmpty()) + && (phone == null || phone.isEmpty()) + ); + } + + /** + * Output the object in a format suitable for inclusion in an rST field list. + */ + public String toFieldList() { + Map printable = this.printableValues(); + return String.format(" :Address: %s%n", printable.get("address")) + + String.format(" :Email: %s%n", printable.get("email")) + + String.format(" :Name: %s%n", printable.get("name")) + + String.format(" :Phone: %s%n", printable.get("phone")); + } + + @Override + public String toString() { + Map printable = this.printableValues(); + return String.format("Address: %s", printable.get("address")) + + String.format(", Email: %s", printable.get("email")) + + String.format(", Name: %s", printable.get("name")) + + String.format(", Phone: %s", printable.get("phone")); + } + + private Map printableValues() { + Map printable = new HashMap<>(); + + printable.put("address", SummaryHelper.formatForDisplay(this.address, null)); + printable.put("email", SummaryHelper.formatForDisplay(this.email, null)); + printable.put("name", SummaryHelper.formatForDisplay(this.name, null)); + printable.put("phone", SummaryHelper.formatForDisplay(this.phone, null)); + return printable; + } +} diff --git a/src/main/java/com/mindee/product/billoflading/BillOfLadingV1Document.java b/src/main/java/com/mindee/product/billoflading/BillOfLadingV1Document.java new file mode 100644 index 000000000..6f946347f --- /dev/null +++ b/src/main/java/com/mindee/product/billoflading/BillOfLadingV1Document.java @@ -0,0 +1,148 @@ +package com.mindee.product.billoflading; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.mindee.parsing.SummaryHelper; +import com.mindee.parsing.common.Prediction; +import com.mindee.parsing.standard.DateField; +import com.mindee.parsing.standard.StringField; +import java.util.ArrayList; +import java.util.List; +import lombok.EqualsAndHashCode; +import lombok.Getter; + +/** + * Bill of Lading API version 1.1 document data. + */ +@Getter +@EqualsAndHashCode(callSuper = false) +@JsonIgnoreProperties(ignoreUnknown = true) +public class BillOfLadingV1Document extends Prediction { + + /** + * A unique identifier assigned to a Bill of Lading document. + */ + @JsonProperty("bill_of_lading_number") + protected StringField billOfLadingNumber; + /** + * The shipping company responsible for transporting the goods. + */ + @JsonProperty("carrier") + protected BillOfLadingV1Carrier carrier; + /** + * The goods being shipped. + */ + @JsonProperty("carrier_items") + protected List carrierItems = new ArrayList<>(); + /** + * The party to whom the goods are being shipped. + */ + @JsonProperty("consignee") + protected BillOfLadingV1Consignee consignee; + /** + * The date when the bill of lading is issued. + */ + @JsonProperty("date_of_issue") + protected DateField dateOfIssue; + /** + * The date when the vessel departs from the port of loading. + */ + @JsonProperty("departure_date") + protected DateField departureDate; + /** + * The party to be notified of the arrival of the goods. + */ + @JsonProperty("notify_party") + protected BillOfLadingV1NotifyParty notifyParty; + /** + * The place where the goods are to be delivered. + */ + @JsonProperty("place_of_delivery") + protected StringField placeOfDelivery; + /** + * The port where the goods are unloaded from the vessel. + */ + @JsonProperty("port_of_discharge") + protected StringField portOfDischarge; + /** + * The port where the goods are loaded onto the vessel. + */ + @JsonProperty("port_of_loading") + protected StringField portOfLoading; + /** + * The party responsible for shipping the goods. + */ + @JsonProperty("shipper") + protected BillOfLadingV1Shipper shipper; + + @Override + public boolean isEmpty() { + return ( + this.billOfLadingNumber == null + && this.shipper == null + && this.consignee == null + && this.notifyParty == null + && this.carrier == null + && (this.carrierItems == null || this.carrierItems.isEmpty()) + && this.portOfLoading == null + && this.portOfDischarge == null + && this.placeOfDelivery == null + && this.dateOfIssue == null + && this.departureDate == null + ); + } + + @Override + public String toString() { + StringBuilder outStr = new StringBuilder(); + outStr.append( + String.format(":Bill of Lading Number: %s%n", this.getBillOfLadingNumber()) + ); + outStr.append( + String.format(":Shipper:%n%s", this.getShipper().toFieldList()) + ); + outStr.append( + String.format(":Consignee:%n%s", this.getConsignee().toFieldList()) + ); + outStr.append( + String.format(":Notify Party:%n%s", this.getNotifyParty().toFieldList()) + ); + outStr.append( + String.format(":Carrier:%n%s", this.getCarrier().toFieldList()) + ); + String carrierItemsSummary = ""; + if (!this.getCarrierItems().isEmpty()) { + int[] carrierItemsColSizes = new int[]{38, 14, 13, 18, 10, 13}; + carrierItemsSummary = + String.format("%n%s%n ", SummaryHelper.lineSeparator(carrierItemsColSizes, "-")) + + "| Description " + + "| Gross Weight " + + "| Measurement " + + "| Measurement Unit " + + "| Quantity " + + "| Weight Unit " + + String.format("|%n%s%n ", SummaryHelper.lineSeparator(carrierItemsColSizes, "=")); + carrierItemsSummary += SummaryHelper.arrayToString(this.getCarrierItems(), carrierItemsColSizes); + carrierItemsSummary += String.format("%n%s", SummaryHelper.lineSeparator(carrierItemsColSizes, "-")); + } + outStr.append( + String.format(":Items: %s%n", carrierItemsSummary) + ); + outStr.append( + String.format(":Port of Loading: %s%n", this.getPortOfLoading()) + ); + outStr.append( + String.format(":Port of Discharge: %s%n", this.getPortOfDischarge()) + ); + outStr.append( + String.format(":Place of Delivery: %s%n", this.getPlaceOfDelivery()) + ); + outStr.append( + String.format(":Date of issue: %s%n", this.getDateOfIssue()) + ); + outStr.append( + String.format(":Departure Date: %s%n", this.getDepartureDate()) + ); + return SummaryHelper.cleanSummary(outStr.toString()); + } +} diff --git a/src/main/java/com/mindee/product/billoflading/BillOfLadingV1NotifyParty.java b/src/main/java/com/mindee/product/billoflading/BillOfLadingV1NotifyParty.java new file mode 100644 index 000000000..ece433791 --- /dev/null +++ b/src/main/java/com/mindee/product/billoflading/BillOfLadingV1NotifyParty.java @@ -0,0 +1,77 @@ +package com.mindee.product.billoflading; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.mindee.parsing.SummaryHelper; +import com.mindee.parsing.standard.BaseField; +import java.util.HashMap; +import java.util.Map; +import lombok.Getter; + +/** + * The party to be notified of the arrival of the goods. + */ +@Getter +@JsonIgnoreProperties(ignoreUnknown = true) +public class BillOfLadingV1NotifyParty extends BaseField { + + /** + * The address of the notify party. + */ + @JsonProperty("address") + String address; + /** + * The email of the shipper. + */ + @JsonProperty("email") + String email; + /** + * The name of the notify party. + */ + @JsonProperty("name") + String name; + /** + * The phone number of the notify party. + */ + @JsonProperty("phone") + String phone; + + public boolean isEmpty() { + return ( + (address == null || address.isEmpty()) + && (email == null || email.isEmpty()) + && (name == null || name.isEmpty()) + && (phone == null || phone.isEmpty()) + ); + } + + /** + * Output the object in a format suitable for inclusion in an rST field list. + */ + public String toFieldList() { + Map printable = this.printableValues(); + return String.format(" :Address: %s%n", printable.get("address")) + + String.format(" :Email: %s%n", printable.get("email")) + + String.format(" :Name: %s%n", printable.get("name")) + + String.format(" :Phone: %s%n", printable.get("phone")); + } + + @Override + public String toString() { + Map printable = this.printableValues(); + return String.format("Address: %s", printable.get("address")) + + String.format(", Email: %s", printable.get("email")) + + String.format(", Name: %s", printable.get("name")) + + String.format(", Phone: %s", printable.get("phone")); + } + + private Map printableValues() { + Map printable = new HashMap<>(); + + printable.put("address", SummaryHelper.formatForDisplay(this.address, null)); + printable.put("email", SummaryHelper.formatForDisplay(this.email, null)); + printable.put("name", SummaryHelper.formatForDisplay(this.name, null)); + printable.put("phone", SummaryHelper.formatForDisplay(this.phone, null)); + return printable; + } +} diff --git a/src/main/java/com/mindee/product/billoflading/BillOfLadingV1Shipper.java b/src/main/java/com/mindee/product/billoflading/BillOfLadingV1Shipper.java new file mode 100644 index 000000000..6d611dbc0 --- /dev/null +++ b/src/main/java/com/mindee/product/billoflading/BillOfLadingV1Shipper.java @@ -0,0 +1,77 @@ +package com.mindee.product.billoflading; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.mindee.parsing.SummaryHelper; +import com.mindee.parsing.standard.BaseField; +import java.util.HashMap; +import java.util.Map; +import lombok.Getter; + +/** + * The party responsible for shipping the goods. + */ +@Getter +@JsonIgnoreProperties(ignoreUnknown = true) +public class BillOfLadingV1Shipper extends BaseField { + + /** + * The address of the shipper. + */ + @JsonProperty("address") + String address; + /** + * The email of the shipper. + */ + @JsonProperty("email") + String email; + /** + * The name of the shipper. + */ + @JsonProperty("name") + String name; + /** + * The phone number of the shipper. + */ + @JsonProperty("phone") + String phone; + + public boolean isEmpty() { + return ( + (address == null || address.isEmpty()) + && (email == null || email.isEmpty()) + && (name == null || name.isEmpty()) + && (phone == null || phone.isEmpty()) + ); + } + + /** + * Output the object in a format suitable for inclusion in an rST field list. + */ + public String toFieldList() { + Map printable = this.printableValues(); + return String.format(" :Address: %s%n", printable.get("address")) + + String.format(" :Email: %s%n", printable.get("email")) + + String.format(" :Name: %s%n", printable.get("name")) + + String.format(" :Phone: %s%n", printable.get("phone")); + } + + @Override + public String toString() { + Map printable = this.printableValues(); + return String.format("Address: %s", printable.get("address")) + + String.format(", Email: %s", printable.get("email")) + + String.format(", Name: %s", printable.get("name")) + + String.format(", Phone: %s", printable.get("phone")); + } + + private Map printableValues() { + Map printable = new HashMap<>(); + + printable.put("address", SummaryHelper.formatForDisplay(this.address, null)); + printable.put("email", SummaryHelper.formatForDisplay(this.email, null)); + printable.put("name", SummaryHelper.formatForDisplay(this.name, null)); + printable.put("phone", SummaryHelper.formatForDisplay(this.phone, null)); + return printable; + } +} diff --git a/src/main/java/com/mindee/product/financialdocument/FinancialDocumentV1LineItem.java b/src/main/java/com/mindee/product/financialdocument/FinancialDocumentV1LineItem.java index 2bb12cd5e..5498c2f69 100644 --- a/src/main/java/com/mindee/product/financialdocument/FinancialDocumentV1LineItem.java +++ b/src/main/java/com/mindee/product/financialdocument/FinancialDocumentV1LineItem.java @@ -70,11 +70,40 @@ public boolean isEmpty() { ); } + private Map tablePrintableValues() { + Map printable = new HashMap<>(); + + printable.put("description", SummaryHelper.formatForDisplay(this.description, 36)); + printable.put("productCode", SummaryHelper.formatForDisplay(this.productCode, null)); + printable.put( + "quantity", + SummaryHelper.formatAmount(this.quantity) + ); + printable.put( + "taxAmount", + SummaryHelper.formatAmount(this.taxAmount) + ); + printable.put( + "taxRate", + SummaryHelper.formatAmount(this.taxRate) + ); + printable.put( + "totalAmount", + SummaryHelper.formatAmount(this.totalAmount) + ); + printable.put("unitMeasure", SummaryHelper.formatForDisplay(this.unitMeasure, null)); + printable.put( + "unitPrice", + SummaryHelper.formatAmount(this.unitPrice) + ); + return printable; + } + /** * Output the line in a format suitable for inclusion in an rST table. */ public String toTableLine() { - Map printable = this.printableValues(); + Map printable = this.tablePrintableValues(); return String.format("| %-36s ", printable.get("description")) + String.format("| %-12s ", printable.get("productCode")) + String.format("| %-8s ", printable.get("quantity")) @@ -101,11 +130,7 @@ public String toString() { private Map printableValues() { Map printable = new HashMap<>(); - String descriptionSummary = (this.description != null ? this.description : ""); - if (descriptionSummary.length() >= 36) { - descriptionSummary = descriptionSummary.substring(0, 33) + "..."; - } - printable.put("description", descriptionSummary); + printable.put("description", SummaryHelper.formatForDisplay(this.description, null)); printable.put("productCode", SummaryHelper.formatForDisplay(this.productCode, null)); printable.put( "quantity", diff --git a/src/main/java/com/mindee/product/fr/energybill/EnergyBillV1.java b/src/main/java/com/mindee/product/fr/energybill/EnergyBillV1.java new file mode 100644 index 000000000..09d939298 --- /dev/null +++ b/src/main/java/com/mindee/product/fr/energybill/EnergyBillV1.java @@ -0,0 +1,16 @@ +package com.mindee.product.fr.energybill; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.mindee.http.EndpointInfo; +import com.mindee.parsing.common.Inference; +import lombok.Getter; + +/** + * Energy Bill API version 1 inference prediction. + */ +@Getter +@JsonIgnoreProperties(ignoreUnknown = true) +@EndpointInfo(endpointName = "energy_bill_fra", version = "1") +public class EnergyBillV1 + extends Inference { +} diff --git a/src/main/java/com/mindee/product/fr/energybill/EnergyBillV1Document.java b/src/main/java/com/mindee/product/fr/energybill/EnergyBillV1Document.java new file mode 100644 index 000000000..18c019713 --- /dev/null +++ b/src/main/java/com/mindee/product/fr/energybill/EnergyBillV1Document.java @@ -0,0 +1,206 @@ +package com.mindee.product.fr.energybill; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.mindee.parsing.SummaryHelper; +import com.mindee.parsing.common.Prediction; +import com.mindee.parsing.standard.AmountField; +import com.mindee.parsing.standard.DateField; +import com.mindee.parsing.standard.StringField; +import java.util.ArrayList; +import java.util.List; +import lombok.EqualsAndHashCode; +import lombok.Getter; + +/** + * Energy Bill API version 1.0 document data. + */ +@Getter +@EqualsAndHashCode(callSuper = false) +@JsonIgnoreProperties(ignoreUnknown = true) +public class EnergyBillV1Document extends Prediction { + + /** + * The unique identifier associated with a specific contract. + */ + @JsonProperty("contract_id") + protected StringField contractId; + /** + * The unique identifier assigned to each electricity or gas consumption point. It specifies the exact location where the energy is delivered. + */ + @JsonProperty("delivery_point") + protected StringField deliveryPoint; + /** + * The date by which the payment for the energy invoice is due. + */ + @JsonProperty("due_date") + protected DateField dueDate; + /** + * The entity that consumes the energy. + */ + @JsonProperty("energy_consumer") + protected EnergyBillV1EnergyConsumer energyConsumer; + /** + * The company that supplies the energy. + */ + @JsonProperty("energy_supplier") + protected EnergyBillV1EnergySupplier energySupplier; + /** + * Details of energy consumption. + */ + @JsonProperty("energy_usage") + protected List energyUsage = new ArrayList<>(); + /** + * The date when the energy invoice was issued. + */ + @JsonProperty("invoice_date") + protected DateField invoiceDate; + /** + * The unique identifier of the energy invoice. + */ + @JsonProperty("invoice_number") + protected StringField invoiceNumber; + /** + * Information about the energy meter. + */ + @JsonProperty("meter_details") + protected EnergyBillV1MeterDetail meterDetails; + /** + * The subscription details fee for the energy service. + */ + @JsonProperty("subscription") + protected List subscription = new ArrayList<>(); + /** + * Details of Taxes and Contributions. + */ + @JsonProperty("taxes_and_contributions") + protected List taxesAndContributions = new ArrayList<>(); + /** + * The total amount to be paid for the energy invoice. + */ + @JsonProperty("total_amount") + protected AmountField totalAmount; + /** + * The total amount to be paid for the energy invoice before taxes. + */ + @JsonProperty("total_before_taxes") + protected AmountField totalBeforeTaxes; + /** + * Total of taxes applied to the invoice. + */ + @JsonProperty("total_taxes") + protected AmountField totalTaxes; + + @Override + public boolean isEmpty() { + return ( + this.invoiceNumber == null + && this.contractId == null + && this.deliveryPoint == null + && this.invoiceDate == null + && this.dueDate == null + && this.totalBeforeTaxes == null + && this.totalTaxes == null + && this.totalAmount == null + && this.energySupplier == null + && this.energyConsumer == null + && (this.subscription == null || this.subscription.isEmpty()) + && (this.energyUsage == null || this.energyUsage.isEmpty()) + && (this.taxesAndContributions == null || this.taxesAndContributions.isEmpty()) + && this.meterDetails == null + ); + } + + @Override + public String toString() { + StringBuilder outStr = new StringBuilder(); + outStr.append( + String.format(":Invoice Number: %s%n", this.getInvoiceNumber()) + ); + outStr.append( + String.format(":Contract ID: %s%n", this.getContractId()) + ); + outStr.append( + String.format(":Delivery Point: %s%n", this.getDeliveryPoint()) + ); + outStr.append( + String.format(":Invoice Date: %s%n", this.getInvoiceDate()) + ); + outStr.append( + String.format(":Due Date: %s%n", this.getDueDate()) + ); + outStr.append( + String.format(":Total Before Taxes: %s%n", this.getTotalBeforeTaxes()) + ); + outStr.append( + String.format(":Total Taxes: %s%n", this.getTotalTaxes()) + ); + outStr.append( + String.format(":Total Amount: %s%n", this.getTotalAmount()) + ); + outStr.append( + String.format(":Energy Supplier:%n%s", this.getEnergySupplier().toFieldList()) + ); + outStr.append( + String.format(":Energy Consumer:%n%s", this.getEnergyConsumer().toFieldList()) + ); + String subscriptionSummary = ""; + if (!this.getSubscription().isEmpty()) { + int[] subscriptionColSizes = new int[]{38, 12, 12, 10, 11, 12}; + subscriptionSummary = + String.format("%n%s%n ", SummaryHelper.lineSeparator(subscriptionColSizes, "-")) + + "| Description " + + "| End Date " + + "| Start Date " + + "| Tax Rate " + + "| Total " + + "| Unit Price " + + String.format("|%n%s%n ", SummaryHelper.lineSeparator(subscriptionColSizes, "=")); + subscriptionSummary += SummaryHelper.arrayToString(this.getSubscription(), subscriptionColSizes); + subscriptionSummary += String.format("%n%s", SummaryHelper.lineSeparator(subscriptionColSizes, "-")); + } + outStr.append( + String.format(":Subscription: %s%n", subscriptionSummary) + ); + String energyUsageSummary = ""; + if (!this.getEnergyUsage().isEmpty()) { + int[] energyUsageColSizes = new int[]{38, 12, 12, 10, 11, 12}; + energyUsageSummary = + String.format("%n%s%n ", SummaryHelper.lineSeparator(energyUsageColSizes, "-")) + + "| Description " + + "| End Date " + + "| Start Date " + + "| Tax Rate " + + "| Total " + + "| Unit Price " + + String.format("|%n%s%n ", SummaryHelper.lineSeparator(energyUsageColSizes, "=")); + energyUsageSummary += SummaryHelper.arrayToString(this.getEnergyUsage(), energyUsageColSizes); + energyUsageSummary += String.format("%n%s", SummaryHelper.lineSeparator(energyUsageColSizes, "-")); + } + outStr.append( + String.format(":Energy Usage: %s%n", energyUsageSummary) + ); + String taxesAndContributionsSummary = ""; + if (!this.getTaxesAndContributions().isEmpty()) { + int[] taxesAndContributionsColSizes = new int[]{38, 12, 12, 10, 11, 12}; + taxesAndContributionsSummary = + String.format("%n%s%n ", SummaryHelper.lineSeparator(taxesAndContributionsColSizes, "-")) + + "| Description " + + "| End Date " + + "| Start Date " + + "| Tax Rate " + + "| Total " + + "| Unit Price " + + String.format("|%n%s%n ", SummaryHelper.lineSeparator(taxesAndContributionsColSizes, "=")); + taxesAndContributionsSummary += SummaryHelper.arrayToString(this.getTaxesAndContributions(), taxesAndContributionsColSizes); + taxesAndContributionsSummary += String.format("%n%s", SummaryHelper.lineSeparator(taxesAndContributionsColSizes, "-")); + } + outStr.append( + String.format(":Taxes and Contributions: %s%n", taxesAndContributionsSummary) + ); + outStr.append( + String.format(":Meter Details:%n%s", this.getMeterDetails().toFieldList()) + ); + return SummaryHelper.cleanSummary(outStr.toString()); + } +} diff --git a/src/main/java/com/mindee/product/fr/energybill/EnergyBillV1EnergyConsumer.java b/src/main/java/com/mindee/product/fr/energybill/EnergyBillV1EnergyConsumer.java new file mode 100644 index 000000000..1992107f1 --- /dev/null +++ b/src/main/java/com/mindee/product/fr/energybill/EnergyBillV1EnergyConsumer.java @@ -0,0 +1,59 @@ +package com.mindee.product.fr.energybill; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.mindee.parsing.SummaryHelper; +import com.mindee.parsing.standard.BaseField; +import java.util.HashMap; +import java.util.Map; +import lombok.Getter; + +/** + * The entity that consumes the energy. + */ +@Getter +@JsonIgnoreProperties(ignoreUnknown = true) +public class EnergyBillV1EnergyConsumer extends BaseField { + + /** + * The address of the energy consumer. + */ + @JsonProperty("address") + String address; + /** + * The name of the energy consumer. + */ + @JsonProperty("name") + String name; + + public boolean isEmpty() { + return ( + (address == null || address.isEmpty()) + && (name == null || name.isEmpty()) + ); + } + + /** + * Output the object in a format suitable for inclusion in an rST field list. + */ + public String toFieldList() { + Map printable = this.printableValues(); + return String.format(" :Address: %s%n", printable.get("address")) + + String.format(" :Name: %s%n", printable.get("name")); + } + + @Override + public String toString() { + Map printable = this.printableValues(); + return String.format("Address: %s", printable.get("address")) + + String.format(", Name: %s", printable.get("name")); + } + + private Map printableValues() { + Map printable = new HashMap<>(); + + printable.put("address", SummaryHelper.formatForDisplay(this.address, null)); + printable.put("name", SummaryHelper.formatForDisplay(this.name, null)); + return printable; + } +} diff --git a/src/main/java/com/mindee/product/fr/energybill/EnergyBillV1EnergySupplier.java b/src/main/java/com/mindee/product/fr/energybill/EnergyBillV1EnergySupplier.java new file mode 100644 index 000000000..08be27989 --- /dev/null +++ b/src/main/java/com/mindee/product/fr/energybill/EnergyBillV1EnergySupplier.java @@ -0,0 +1,59 @@ +package com.mindee.product.fr.energybill; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.mindee.parsing.SummaryHelper; +import com.mindee.parsing.standard.BaseField; +import java.util.HashMap; +import java.util.Map; +import lombok.Getter; + +/** + * The company that supplies the energy. + */ +@Getter +@JsonIgnoreProperties(ignoreUnknown = true) +public class EnergyBillV1EnergySupplier extends BaseField { + + /** + * The address of the energy supplier. + */ + @JsonProperty("address") + String address; + /** + * The name of the energy supplier. + */ + @JsonProperty("name") + String name; + + public boolean isEmpty() { + return ( + (address == null || address.isEmpty()) + && (name == null || name.isEmpty()) + ); + } + + /** + * Output the object in a format suitable for inclusion in an rST field list. + */ + public String toFieldList() { + Map printable = this.printableValues(); + return String.format(" :Address: %s%n", printable.get("address")) + + String.format(" :Name: %s%n", printable.get("name")); + } + + @Override + public String toString() { + Map printable = this.printableValues(); + return String.format("Address: %s", printable.get("address")) + + String.format(", Name: %s", printable.get("name")); + } + + private Map printableValues() { + Map printable = new HashMap<>(); + + printable.put("address", SummaryHelper.formatForDisplay(this.address, null)); + printable.put("name", SummaryHelper.formatForDisplay(this.name, null)); + return printable; + } +} diff --git a/src/main/java/com/mindee/product/fr/energybill/EnergyBillV1EnergyUsage.java b/src/main/java/com/mindee/product/fr/energybill/EnergyBillV1EnergyUsage.java new file mode 100644 index 000000000..5b85afc90 --- /dev/null +++ b/src/main/java/com/mindee/product/fr/energybill/EnergyBillV1EnergyUsage.java @@ -0,0 +1,126 @@ +package com.mindee.product.fr.energybill; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.mindee.parsing.SummaryHelper; +import com.mindee.parsing.standard.BaseField; +import com.mindee.parsing.standard.LineItemField; +import java.util.HashMap; +import java.util.Map; +import lombok.Getter; + +/** + * Details of energy consumption. + */ +@Getter +@JsonIgnoreProperties(ignoreUnknown = true) +public class EnergyBillV1EnergyUsage extends BaseField implements LineItemField { + + /** + * Description or details of the energy usage. + */ + @JsonProperty("description") + String description; + /** + * The end date of the energy usage. + */ + @JsonProperty("end_date") + String endDate; + /** + * The start date of the energy usage. + */ + @JsonProperty("start_date") + String startDate; + /** + * The rate of tax applied to the total cost. + */ + @JsonProperty("tax_rate") + Double taxRate; + /** + * The total cost of energy consumed. + */ + @JsonProperty("total") + Double total; + /** + * The price per unit of energy consumed. + */ + @JsonProperty("unit_price") + Double unitPrice; + + public boolean isEmpty() { + return ( + (description == null || description.isEmpty()) + && (endDate == null || endDate.isEmpty()) + && (startDate == null || startDate.isEmpty()) + && taxRate == null + && total == null + && unitPrice == null + ); + } + + private Map tablePrintableValues() { + Map printable = new HashMap<>(); + + printable.put("description", SummaryHelper.formatForDisplay(this.description, 36)); + printable.put("endDate", SummaryHelper.formatForDisplay(this.endDate, 10)); + printable.put("startDate", SummaryHelper.formatForDisplay(this.startDate, null)); + printable.put( + "taxRate", + SummaryHelper.formatAmount(this.taxRate) + ); + printable.put( + "total", + SummaryHelper.formatAmount(this.total) + ); + printable.put( + "unitPrice", + SummaryHelper.formatAmount(this.unitPrice) + ); + return printable; + } + + /** + * Output the line in a format suitable for inclusion in an rST table. + */ + public String toTableLine() { + Map printable = this.tablePrintableValues(); + return String.format("| %-36s ", printable.get("description")) + + String.format("| %-10s ", printable.get("endDate")) + + String.format("| %-10s ", printable.get("startDate")) + + String.format("| %-8s ", printable.get("taxRate")) + + String.format("| %-9s ", printable.get("total")) + + String.format("| %-10s |", printable.get("unitPrice")); + } + + @Override + public String toString() { + Map printable = this.printableValues(); + return String.format("Description: %s", printable.get("description")) + + String.format(", End Date: %s", printable.get("endDate")) + + String.format(", Start Date: %s", printable.get("startDate")) + + String.format(", Tax Rate: %s", printable.get("taxRate")) + + String.format(", Total: %s", printable.get("total")) + + String.format(", Unit Price: %s", printable.get("unitPrice")); + } + + private Map printableValues() { + Map printable = new HashMap<>(); + + printable.put("description", SummaryHelper.formatForDisplay(this.description, null)); + printable.put("endDate", SummaryHelper.formatForDisplay(this.endDate, null)); + printable.put("startDate", SummaryHelper.formatForDisplay(this.startDate, null)); + printable.put( + "taxRate", + SummaryHelper.formatAmount(this.taxRate) + ); + printable.put( + "total", + SummaryHelper.formatAmount(this.total) + ); + printable.put( + "unitPrice", + SummaryHelper.formatAmount(this.unitPrice) + ); + return printable; + } +} diff --git a/src/main/java/com/mindee/product/fr/energybill/EnergyBillV1MeterDetail.java b/src/main/java/com/mindee/product/fr/energybill/EnergyBillV1MeterDetail.java new file mode 100644 index 000000000..b07d30963 --- /dev/null +++ b/src/main/java/com/mindee/product/fr/energybill/EnergyBillV1MeterDetail.java @@ -0,0 +1,68 @@ +package com.mindee.product.fr.energybill; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.mindee.parsing.SummaryHelper; +import com.mindee.parsing.standard.BaseField; +import java.util.HashMap; +import java.util.Map; +import lombok.Getter; + +/** + * Information about the energy meter. + */ +@Getter +@JsonIgnoreProperties(ignoreUnknown = true) +public class EnergyBillV1MeterDetail extends BaseField { + + /** + * The unique identifier of the energy meter. + */ + @JsonProperty("meter_number") + String meterNumber; + /** + * The type of energy meter. + */ + @JsonProperty("meter_type") + String meterType; + /** + * The unit of measurement for energy consumption, which can be kW, m³, or L. + */ + @JsonProperty("unit") + String unit; + + public boolean isEmpty() { + return ( + (meterNumber == null || meterNumber.isEmpty()) + && (meterType == null || meterType.isEmpty()) + && (unit == null || unit.isEmpty()) + ); + } + + /** + * Output the object in a format suitable for inclusion in an rST field list. + */ + public String toFieldList() { + Map printable = this.printableValues(); + return String.format(" :Meter Number: %s%n", printable.get("meterNumber")) + + String.format(" :Meter Type: %s%n", printable.get("meterType")) + + String.format(" :Unit of Measure: %s%n", printable.get("unit")); + } + + @Override + public String toString() { + Map printable = this.printableValues(); + return String.format("Meter Number: %s", printable.get("meterNumber")) + + String.format(", Meter Type: %s", printable.get("meterType")) + + String.format(", Unit of Measure: %s", printable.get("unit")); + } + + private Map printableValues() { + Map printable = new HashMap<>(); + + printable.put("meterNumber", SummaryHelper.formatForDisplay(this.meterNumber, null)); + printable.put("meterType", SummaryHelper.formatForDisplay(this.meterType, null)); + printable.put("unit", SummaryHelper.formatForDisplay(this.unit, null)); + return printable; + } +} diff --git a/src/main/java/com/mindee/product/fr/energybill/EnergyBillV1Subscription.java b/src/main/java/com/mindee/product/fr/energybill/EnergyBillV1Subscription.java new file mode 100644 index 000000000..0e5a22843 --- /dev/null +++ b/src/main/java/com/mindee/product/fr/energybill/EnergyBillV1Subscription.java @@ -0,0 +1,126 @@ +package com.mindee.product.fr.energybill; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.mindee.parsing.SummaryHelper; +import com.mindee.parsing.standard.BaseField; +import com.mindee.parsing.standard.LineItemField; +import java.util.HashMap; +import java.util.Map; +import lombok.Getter; + +/** + * The subscription details fee for the energy service. + */ +@Getter +@JsonIgnoreProperties(ignoreUnknown = true) +public class EnergyBillV1Subscription extends BaseField implements LineItemField { + + /** + * Description or details of the subscription. + */ + @JsonProperty("description") + String description; + /** + * The end date of the subscription. + */ + @JsonProperty("end_date") + String endDate; + /** + * The start date of the subscription. + */ + @JsonProperty("start_date") + String startDate; + /** + * The rate of tax applied to the total cost. + */ + @JsonProperty("tax_rate") + Double taxRate; + /** + * The total cost of subscription. + */ + @JsonProperty("total") + Double total; + /** + * The price per unit of subscription. + */ + @JsonProperty("unit_price") + Double unitPrice; + + public boolean isEmpty() { + return ( + (description == null || description.isEmpty()) + && (endDate == null || endDate.isEmpty()) + && (startDate == null || startDate.isEmpty()) + && taxRate == null + && total == null + && unitPrice == null + ); + } + + private Map tablePrintableValues() { + Map printable = new HashMap<>(); + + printable.put("description", SummaryHelper.formatForDisplay(this.description, 36)); + printable.put("endDate", SummaryHelper.formatForDisplay(this.endDate, 10)); + printable.put("startDate", SummaryHelper.formatForDisplay(this.startDate, null)); + printable.put( + "taxRate", + SummaryHelper.formatAmount(this.taxRate) + ); + printable.put( + "total", + SummaryHelper.formatAmount(this.total) + ); + printable.put( + "unitPrice", + SummaryHelper.formatAmount(this.unitPrice) + ); + return printable; + } + + /** + * Output the line in a format suitable for inclusion in an rST table. + */ + public String toTableLine() { + Map printable = this.tablePrintableValues(); + return String.format("| %-36s ", printable.get("description")) + + String.format("| %-10s ", printable.get("endDate")) + + String.format("| %-10s ", printable.get("startDate")) + + String.format("| %-8s ", printable.get("taxRate")) + + String.format("| %-9s ", printable.get("total")) + + String.format("| %-10s |", printable.get("unitPrice")); + } + + @Override + public String toString() { + Map printable = this.printableValues(); + return String.format("Description: %s", printable.get("description")) + + String.format(", End Date: %s", printable.get("endDate")) + + String.format(", Start Date: %s", printable.get("startDate")) + + String.format(", Tax Rate: %s", printable.get("taxRate")) + + String.format(", Total: %s", printable.get("total")) + + String.format(", Unit Price: %s", printable.get("unitPrice")); + } + + private Map printableValues() { + Map printable = new HashMap<>(); + + printable.put("description", SummaryHelper.formatForDisplay(this.description, null)); + printable.put("endDate", SummaryHelper.formatForDisplay(this.endDate, null)); + printable.put("startDate", SummaryHelper.formatForDisplay(this.startDate, null)); + printable.put( + "taxRate", + SummaryHelper.formatAmount(this.taxRate) + ); + printable.put( + "total", + SummaryHelper.formatAmount(this.total) + ); + printable.put( + "unitPrice", + SummaryHelper.formatAmount(this.unitPrice) + ); + return printable; + } +} diff --git a/src/main/java/com/mindee/product/fr/energybill/EnergyBillV1TaxesAndContribution.java b/src/main/java/com/mindee/product/fr/energybill/EnergyBillV1TaxesAndContribution.java new file mode 100644 index 000000000..04cd23a78 --- /dev/null +++ b/src/main/java/com/mindee/product/fr/energybill/EnergyBillV1TaxesAndContribution.java @@ -0,0 +1,126 @@ +package com.mindee.product.fr.energybill; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.mindee.parsing.SummaryHelper; +import com.mindee.parsing.standard.BaseField; +import com.mindee.parsing.standard.LineItemField; +import java.util.HashMap; +import java.util.Map; +import lombok.Getter; + +/** + * Details of Taxes and Contributions. + */ +@Getter +@JsonIgnoreProperties(ignoreUnknown = true) +public class EnergyBillV1TaxesAndContribution extends BaseField implements LineItemField { + + /** + * Description or details of the Taxes and Contributions. + */ + @JsonProperty("description") + String description; + /** + * The end date of the Taxes and Contributions. + */ + @JsonProperty("end_date") + String endDate; + /** + * The start date of the Taxes and Contributions. + */ + @JsonProperty("start_date") + String startDate; + /** + * The rate of tax applied to the total cost. + */ + @JsonProperty("tax_rate") + Double taxRate; + /** + * The total cost of Taxes and Contributions. + */ + @JsonProperty("total") + Double total; + /** + * The price per unit of Taxes and Contributions. + */ + @JsonProperty("unit_price") + Double unitPrice; + + public boolean isEmpty() { + return ( + (description == null || description.isEmpty()) + && (endDate == null || endDate.isEmpty()) + && (startDate == null || startDate.isEmpty()) + && taxRate == null + && total == null + && unitPrice == null + ); + } + + private Map tablePrintableValues() { + Map printable = new HashMap<>(); + + printable.put("description", SummaryHelper.formatForDisplay(this.description, 36)); + printable.put("endDate", SummaryHelper.formatForDisplay(this.endDate, 10)); + printable.put("startDate", SummaryHelper.formatForDisplay(this.startDate, null)); + printable.put( + "taxRate", + SummaryHelper.formatAmount(this.taxRate) + ); + printable.put( + "total", + SummaryHelper.formatAmount(this.total) + ); + printable.put( + "unitPrice", + SummaryHelper.formatAmount(this.unitPrice) + ); + return printable; + } + + /** + * Output the line in a format suitable for inclusion in an rST table. + */ + public String toTableLine() { + Map printable = this.tablePrintableValues(); + return String.format("| %-36s ", printable.get("description")) + + String.format("| %-10s ", printable.get("endDate")) + + String.format("| %-10s ", printable.get("startDate")) + + String.format("| %-8s ", printable.get("taxRate")) + + String.format("| %-9s ", printable.get("total")) + + String.format("| %-10s |", printable.get("unitPrice")); + } + + @Override + public String toString() { + Map printable = this.printableValues(); + return String.format("Description: %s", printable.get("description")) + + String.format(", End Date: %s", printable.get("endDate")) + + String.format(", Start Date: %s", printable.get("startDate")) + + String.format(", Tax Rate: %s", printable.get("taxRate")) + + String.format(", Total: %s", printable.get("total")) + + String.format(", Unit Price: %s", printable.get("unitPrice")); + } + + private Map printableValues() { + Map printable = new HashMap<>(); + + printable.put("description", SummaryHelper.formatForDisplay(this.description, null)); + printable.put("endDate", SummaryHelper.formatForDisplay(this.endDate, null)); + printable.put("startDate", SummaryHelper.formatForDisplay(this.startDate, null)); + printable.put( + "taxRate", + SummaryHelper.formatAmount(this.taxRate) + ); + printable.put( + "total", + SummaryHelper.formatAmount(this.total) + ); + printable.put( + "unitPrice", + SummaryHelper.formatAmount(this.unitPrice) + ); + return printable; + } +} diff --git a/src/main/java/com/mindee/product/fr/payslip/PayslipV2.java b/src/main/java/com/mindee/product/fr/payslip/PayslipV2.java new file mode 100644 index 000000000..c14b743dc --- /dev/null +++ b/src/main/java/com/mindee/product/fr/payslip/PayslipV2.java @@ -0,0 +1,16 @@ +package com.mindee.product.fr.payslip; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.mindee.http.EndpointInfo; +import com.mindee.parsing.common.Inference; +import lombok.Getter; + +/** + * Payslip API version 2 inference prediction. + */ +@Getter +@JsonIgnoreProperties(ignoreUnknown = true) +@EndpointInfo(endpointName = "payslip_fra", version = "2") +public class PayslipV2 + extends Inference { +} diff --git a/src/main/java/com/mindee/product/fr/payslip/PayslipV2BankAccountDetail.java b/src/main/java/com/mindee/product/fr/payslip/PayslipV2BankAccountDetail.java new file mode 100644 index 000000000..a5efbfa1b --- /dev/null +++ b/src/main/java/com/mindee/product/fr/payslip/PayslipV2BankAccountDetail.java @@ -0,0 +1,68 @@ +package com.mindee.product.fr.payslip; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.mindee.parsing.SummaryHelper; +import com.mindee.parsing.standard.BaseField; +import java.util.HashMap; +import java.util.Map; +import lombok.Getter; + +/** + * Information about the employee's bank account. + */ +@Getter +@JsonIgnoreProperties(ignoreUnknown = true) +public class PayslipV2BankAccountDetail extends BaseField { + + /** + * The name of the bank. + */ + @JsonProperty("bank_name") + String bankName; + /** + * The IBAN of the bank account. + */ + @JsonProperty("iban") + String iban; + /** + * The SWIFT code of the bank. + */ + @JsonProperty("swift") + String swift; + + public boolean isEmpty() { + return ( + (bankName == null || bankName.isEmpty()) + && (iban == null || iban.isEmpty()) + && (swift == null || swift.isEmpty()) + ); + } + + /** + * Output the object in a format suitable for inclusion in an rST field list. + */ + public String toFieldList() { + Map printable = this.printableValues(); + return String.format(" :Bank Name: %s%n", printable.get("bankName")) + + String.format(" :IBAN: %s%n", printable.get("iban")) + + String.format(" :SWIFT: %s%n", printable.get("swift")); + } + + @Override + public String toString() { + Map printable = this.printableValues(); + return String.format("Bank Name: %s", printable.get("bankName")) + + String.format(", IBAN: %s", printable.get("iban")) + + String.format(", SWIFT: %s", printable.get("swift")); + } + + private Map printableValues() { + Map printable = new HashMap<>(); + + printable.put("bankName", SummaryHelper.formatForDisplay(this.bankName, null)); + printable.put("iban", SummaryHelper.formatForDisplay(this.iban, null)); + printable.put("swift", SummaryHelper.formatForDisplay(this.swift, null)); + return printable; + } +} diff --git a/src/main/java/com/mindee/product/fr/payslip/PayslipV2Document.java b/src/main/java/com/mindee/product/fr/payslip/PayslipV2Document.java new file mode 100644 index 000000000..34800c6fb --- /dev/null +++ b/src/main/java/com/mindee/product/fr/payslip/PayslipV2Document.java @@ -0,0 +1,117 @@ +package com.mindee.product.fr.payslip; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.mindee.parsing.SummaryHelper; +import com.mindee.parsing.common.Prediction; +import java.util.ArrayList; +import java.util.List; +import lombok.EqualsAndHashCode; +import lombok.Getter; + +/** + * Payslip API version 2.0 document data. + */ +@Getter +@EqualsAndHashCode(callSuper = false) +@JsonIgnoreProperties(ignoreUnknown = true) +public class PayslipV2Document extends Prediction { + + /** + * Information about the employee's bank account. + */ + @JsonProperty("bank_account_details") + protected PayslipV2BankAccountDetail bankAccountDetails; + /** + * Information about the employee. + */ + @JsonProperty("employee") + protected PayslipV2Employee employee; + /** + * Information about the employer. + */ + @JsonProperty("employer") + protected PayslipV2Employer employer; + /** + * Information about the employment. + */ + @JsonProperty("employment") + protected PayslipV2Employment employment; + /** + * Detailed information about the pay. + */ + @JsonProperty("pay_detail") + protected PayslipV2PayDetail payDetail; + /** + * Information about the pay period. + */ + @JsonProperty("pay_period") + protected PayslipV2PayPeriod payPeriod; + /** + * Information about paid time off. + */ + @JsonProperty("pto") + protected PayslipV2Pto pto; + /** + * Detailed information about the earnings. + */ + @JsonProperty("salary_details") + protected List salaryDetails = new ArrayList<>(); + + @Override + public boolean isEmpty() { + return ( + this.employee == null + && this.employer == null + && this.bankAccountDetails == null + && this.employment == null + && (this.salaryDetails == null || this.salaryDetails.isEmpty()) + && this.payDetail == null + && this.pto == null + && this.payPeriod == null + ); + } + + @Override + public String toString() { + StringBuilder outStr = new StringBuilder(); + outStr.append( + String.format(":Employee:%n%s", this.getEmployee().toFieldList()) + ); + outStr.append( + String.format(":Employer:%n%s", this.getEmployer().toFieldList()) + ); + outStr.append( + String.format(":Bank Account Details:%n%s", this.getBankAccountDetails().toFieldList()) + ); + outStr.append( + String.format(":Employment:%n%s", this.getEmployment().toFieldList()) + ); + String salaryDetailsSummary = ""; + if (!this.getSalaryDetails().isEmpty()) { + int[] salaryDetailsColSizes = new int[]{14, 11, 38, 11}; + salaryDetailsSummary = + String.format("%n%s%n ", SummaryHelper.lineSeparator(salaryDetailsColSizes, "-")) + + "| Amount " + + "| Base " + + "| Description " + + "| Rate " + + String.format("|%n%s%n ", SummaryHelper.lineSeparator(salaryDetailsColSizes, "=")); + salaryDetailsSummary += SummaryHelper.arrayToString(this.getSalaryDetails(), salaryDetailsColSizes); + salaryDetailsSummary += String.format("%n%s", SummaryHelper.lineSeparator(salaryDetailsColSizes, "-")); + } + outStr.append( + String.format(":Salary Details: %s%n", salaryDetailsSummary) + ); + outStr.append( + String.format(":Pay Detail:%n%s", this.getPayDetail().toFieldList()) + ); + outStr.append( + String.format(":PTO:%n%s", this.getPto().toFieldList()) + ); + outStr.append( + String.format(":Pay Period:%n%s", this.getPayPeriod().toFieldList()) + ); + return SummaryHelper.cleanSummary(outStr.toString()); + } +} diff --git a/src/main/java/com/mindee/product/fr/payslip/PayslipV2Employee.java b/src/main/java/com/mindee/product/fr/payslip/PayslipV2Employee.java new file mode 100644 index 000000000..950d42cf8 --- /dev/null +++ b/src/main/java/com/mindee/product/fr/payslip/PayslipV2Employee.java @@ -0,0 +1,104 @@ +package com.mindee.product.fr.payslip; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.mindee.parsing.SummaryHelper; +import com.mindee.parsing.standard.BaseField; +import java.util.HashMap; +import java.util.Map; +import lombok.Getter; + +/** + * Information about the employee. + */ +@Getter +@JsonIgnoreProperties(ignoreUnknown = true) +public class PayslipV2Employee extends BaseField { + + /** + * The address of the employee. + */ + @JsonProperty("address") + String address; + /** + * The date of birth of the employee. + */ + @JsonProperty("date_of_birth") + String dateOfBirth; + /** + * The first name of the employee. + */ + @JsonProperty("first_name") + String firstName; + /** + * The last name of the employee. + */ + @JsonProperty("last_name") + String lastName; + /** + * The phone number of the employee. + */ + @JsonProperty("phone_number") + String phoneNumber; + /** + * The registration number of the employee. + */ + @JsonProperty("registration_number") + String registrationNumber; + /** + * The social security number of the employee. + */ + @JsonProperty("social_security_number") + String socialSecurityNumber; + + public boolean isEmpty() { + return ( + (address == null || address.isEmpty()) + && (dateOfBirth == null || dateOfBirth.isEmpty()) + && (firstName == null || firstName.isEmpty()) + && (lastName == null || lastName.isEmpty()) + && (phoneNumber == null || phoneNumber.isEmpty()) + && (registrationNumber == null || registrationNumber.isEmpty()) + && (socialSecurityNumber == null || socialSecurityNumber.isEmpty()) + ); + } + + /** + * Output the object in a format suitable for inclusion in an rST field list. + */ + public String toFieldList() { + Map printable = this.printableValues(); + return String.format(" :Address: %s%n", printable.get("address")) + + String.format(" :Date of Birth: %s%n", printable.get("dateOfBirth")) + + String.format(" :First Name: %s%n", printable.get("firstName")) + + String.format(" :Last Name: %s%n", printable.get("lastName")) + + String.format(" :Phone Number: %s%n", printable.get("phoneNumber")) + + String.format(" :Registration Number: %s%n", printable.get("registrationNumber")) + + String.format(" :Social Security Number: %s%n", printable.get("socialSecurityNumber")); + } + + @Override + public String toString() { + Map printable = this.printableValues(); + return String.format("Address: %s", printable.get("address")) + + String.format(", Date of Birth: %s", printable.get("dateOfBirth")) + + String.format(", First Name: %s", printable.get("firstName")) + + String.format(", Last Name: %s", printable.get("lastName")) + + String.format(", Phone Number: %s", printable.get("phoneNumber")) + + String.format(", Registration Number: %s", printable.get("registrationNumber")) + + String.format(", Social Security Number: %s", printable.get("socialSecurityNumber")); + } + + private Map printableValues() { + Map printable = new HashMap<>(); + + printable.put("address", SummaryHelper.formatForDisplay(this.address, null)); + printable.put("dateOfBirth", SummaryHelper.formatForDisplay(this.dateOfBirth, null)); + printable.put("firstName", SummaryHelper.formatForDisplay(this.firstName, null)); + printable.put("lastName", SummaryHelper.formatForDisplay(this.lastName, null)); + printable.put("phoneNumber", SummaryHelper.formatForDisplay(this.phoneNumber, null)); + printable.put("registrationNumber", SummaryHelper.formatForDisplay(this.registrationNumber, null)); + printable.put("socialSecurityNumber", SummaryHelper.formatForDisplay(this.socialSecurityNumber, null)); + return printable; + } +} diff --git a/src/main/java/com/mindee/product/fr/payslip/PayslipV2Employer.java b/src/main/java/com/mindee/product/fr/payslip/PayslipV2Employer.java new file mode 100644 index 000000000..d0f3856a2 --- /dev/null +++ b/src/main/java/com/mindee/product/fr/payslip/PayslipV2Employer.java @@ -0,0 +1,104 @@ +package com.mindee.product.fr.payslip; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.mindee.parsing.SummaryHelper; +import com.mindee.parsing.standard.BaseField; +import java.util.HashMap; +import java.util.Map; +import lombok.Getter; + +/** + * Information about the employer. + */ +@Getter +@JsonIgnoreProperties(ignoreUnknown = true) +public class PayslipV2Employer extends BaseField { + + /** + * The address of the employer. + */ + @JsonProperty("address") + String address; + /** + * The company ID of the employer. + */ + @JsonProperty("company_id") + String companyId; + /** + * The site of the company. + */ + @JsonProperty("company_site") + String companySite; + /** + * The NAF code of the employer. + */ + @JsonProperty("naf_code") + String nafCode; + /** + * The name of the employer. + */ + @JsonProperty("name") + String name; + /** + * The phone number of the employer. + */ + @JsonProperty("phone_number") + String phoneNumber; + /** + * The URSSAF number of the employer. + */ + @JsonProperty("urssaf_number") + String urssafNumber; + + public boolean isEmpty() { + return ( + (address == null || address.isEmpty()) + && (companyId == null || companyId.isEmpty()) + && (companySite == null || companySite.isEmpty()) + && (nafCode == null || nafCode.isEmpty()) + && (name == null || name.isEmpty()) + && (phoneNumber == null || phoneNumber.isEmpty()) + && (urssafNumber == null || urssafNumber.isEmpty()) + ); + } + + /** + * Output the object in a format suitable for inclusion in an rST field list. + */ + public String toFieldList() { + Map printable = this.printableValues(); + return String.format(" :Address: %s%n", printable.get("address")) + + String.format(" :Company ID: %s%n", printable.get("companyId")) + + String.format(" :Company Site: %s%n", printable.get("companySite")) + + String.format(" :NAF Code: %s%n", printable.get("nafCode")) + + String.format(" :Name: %s%n", printable.get("name")) + + String.format(" :Phone Number: %s%n", printable.get("phoneNumber")) + + String.format(" :URSSAF Number: %s%n", printable.get("urssafNumber")); + } + + @Override + public String toString() { + Map printable = this.printableValues(); + return String.format("Address: %s", printable.get("address")) + + String.format(", Company ID: %s", printable.get("companyId")) + + String.format(", Company Site: %s", printable.get("companySite")) + + String.format(", NAF Code: %s", printable.get("nafCode")) + + String.format(", Name: %s", printable.get("name")) + + String.format(", Phone Number: %s", printable.get("phoneNumber")) + + String.format(", URSSAF Number: %s", printable.get("urssafNumber")); + } + + private Map printableValues() { + Map printable = new HashMap<>(); + + printable.put("address", SummaryHelper.formatForDisplay(this.address, null)); + printable.put("companyId", SummaryHelper.formatForDisplay(this.companyId, null)); + printable.put("companySite", SummaryHelper.formatForDisplay(this.companySite, null)); + printable.put("nafCode", SummaryHelper.formatForDisplay(this.nafCode, null)); + printable.put("name", SummaryHelper.formatForDisplay(this.name, null)); + printable.put("phoneNumber", SummaryHelper.formatForDisplay(this.phoneNumber, null)); + printable.put("urssafNumber", SummaryHelper.formatForDisplay(this.urssafNumber, null)); + return printable; + } +} diff --git a/src/main/java/com/mindee/product/fr/payslip/PayslipV2Employment.java b/src/main/java/com/mindee/product/fr/payslip/PayslipV2Employment.java new file mode 100644 index 000000000..72c4e5ab4 --- /dev/null +++ b/src/main/java/com/mindee/product/fr/payslip/PayslipV2Employment.java @@ -0,0 +1,98 @@ +package com.mindee.product.fr.payslip; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.mindee.parsing.SummaryHelper; +import com.mindee.parsing.standard.BaseField; +import java.util.HashMap; +import java.util.Map; +import lombok.Getter; + +/** + * Information about the employment. + */ +@Getter +@JsonIgnoreProperties(ignoreUnknown = true) +public class PayslipV2Employment extends BaseField { + + /** + * The category of the employment. + */ + @JsonProperty("category") + String category; + /** + * The coefficient of the employment. + */ + @JsonProperty("coefficient") + Double coefficient; + /** + * The collective agreement of the employment. + */ + @JsonProperty("collective_agreement") + String collectiveAgreement; + /** + * The job title of the employee. + */ + @JsonProperty("job_title") + String jobTitle; + /** + * The position level of the employment. + */ + @JsonProperty("position_level") + String positionLevel; + /** + * The start date of the employment. + */ + @JsonProperty("start_date") + String startDate; + + public boolean isEmpty() { + return ( + (category == null || category.isEmpty()) + && coefficient == null + && (collectiveAgreement == null || collectiveAgreement.isEmpty()) + && (jobTitle == null || jobTitle.isEmpty()) + && (positionLevel == null || positionLevel.isEmpty()) + && (startDate == null || startDate.isEmpty()) + ); + } + + /** + * Output the object in a format suitable for inclusion in an rST field list. + */ + public String toFieldList() { + Map printable = this.printableValues(); + return String.format(" :Category: %s%n", printable.get("category")) + + String.format(" :Coefficient: %s%n", printable.get("coefficient")) + + String.format(" :Collective Agreement: %s%n", printable.get("collectiveAgreement")) + + String.format(" :Job Title: %s%n", printable.get("jobTitle")) + + String.format(" :Position Level: %s%n", printable.get("positionLevel")) + + String.format(" :Start Date: %s%n", printable.get("startDate")); + } + + @Override + public String toString() { + Map printable = this.printableValues(); + return String.format("Category: %s", printable.get("category")) + + String.format(", Coefficient: %s", printable.get("coefficient")) + + String.format(", Collective Agreement: %s", printable.get("collectiveAgreement")) + + String.format(", Job Title: %s", printable.get("jobTitle")) + + String.format(", Position Level: %s", printable.get("positionLevel")) + + String.format(", Start Date: %s", printable.get("startDate")); + } + + private Map printableValues() { + Map printable = new HashMap<>(); + + printable.put("category", SummaryHelper.formatForDisplay(this.category, null)); + printable.put( + "coefficient", + SummaryHelper.formatAmount(this.coefficient) + ); + printable.put("collectiveAgreement", SummaryHelper.formatForDisplay(this.collectiveAgreement, null)); + printable.put("jobTitle", SummaryHelper.formatForDisplay(this.jobTitle, null)); + printable.put("positionLevel", SummaryHelper.formatForDisplay(this.positionLevel, null)); + printable.put("startDate", SummaryHelper.formatForDisplay(this.startDate, null)); + return printable; + } +} diff --git a/src/main/java/com/mindee/product/fr/payslip/PayslipV2PayDetail.java b/src/main/java/com/mindee/product/fr/payslip/PayslipV2PayDetail.java new file mode 100644 index 000000000..8117460e4 --- /dev/null +++ b/src/main/java/com/mindee/product/fr/payslip/PayslipV2PayDetail.java @@ -0,0 +1,161 @@ +package com.mindee.product.fr.payslip; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.mindee.parsing.SummaryHelper; +import com.mindee.parsing.standard.BaseField; +import java.util.HashMap; +import java.util.Map; +import lombok.Getter; + +/** + * Detailed information about the pay. + */ +@Getter +@JsonIgnoreProperties(ignoreUnknown = true) +public class PayslipV2PayDetail extends BaseField { + + /** + * The gross salary of the employee. + */ + @JsonProperty("gross_salary") + Double grossSalary; + /** + * The year-to-date gross salary of the employee. + */ + @JsonProperty("gross_salary_ytd") + Double grossSalaryYtd; + /** + * The income tax rate of the employee. + */ + @JsonProperty("income_tax_rate") + Double incomeTaxRate; + /** + * The income tax withheld from the employee's pay. + */ + @JsonProperty("income_tax_withheld") + Double incomeTaxWithheld; + /** + * The net paid amount of the employee. + */ + @JsonProperty("net_paid") + Double netPaid; + /** + * The net paid amount before tax of the employee. + */ + @JsonProperty("net_paid_before_tax") + Double netPaidBeforeTax; + /** + * The net taxable amount of the employee. + */ + @JsonProperty("net_taxable") + Double netTaxable; + /** + * The year-to-date net taxable amount of the employee. + */ + @JsonProperty("net_taxable_ytd") + Double netTaxableYtd; + /** + * The total cost to the employer. + */ + @JsonProperty("total_cost_employer") + Double totalCostEmployer; + /** + * The total taxes and deductions of the employee. + */ + @JsonProperty("total_taxes_and_deductions") + Double totalTaxesAndDeductions; + + public boolean isEmpty() { + return ( + grossSalary == null + && grossSalaryYtd == null + && incomeTaxRate == null + && incomeTaxWithheld == null + && netPaid == null + && netPaidBeforeTax == null + && netTaxable == null + && netTaxableYtd == null + && totalCostEmployer == null + && totalTaxesAndDeductions == null + ); + } + + /** + * Output the object in a format suitable for inclusion in an rST field list. + */ + public String toFieldList() { + Map printable = this.printableValues(); + return String.format(" :Gross Salary: %s%n", printable.get("grossSalary")) + + String.format(" :Gross Salary YTD: %s%n", printable.get("grossSalaryYtd")) + + String.format(" :Income Tax Rate: %s%n", printable.get("incomeTaxRate")) + + String.format(" :Income Tax Withheld: %s%n", printable.get("incomeTaxWithheld")) + + String.format(" :Net Paid: %s%n", printable.get("netPaid")) + + String.format(" :Net Paid Before Tax: %s%n", printable.get("netPaidBeforeTax")) + + String.format(" :Net Taxable: %s%n", printable.get("netTaxable")) + + String.format(" :Net Taxable YTD: %s%n", printable.get("netTaxableYtd")) + + String.format(" :Total Cost Employer: %s%n", printable.get("totalCostEmployer")) + + String.format(" :Total Taxes and Deductions: %s%n", printable.get("totalTaxesAndDeductions")); + } + + @Override + public String toString() { + Map printable = this.printableValues(); + return String.format("Gross Salary: %s", printable.get("grossSalary")) + + String.format(", Gross Salary YTD: %s", printable.get("grossSalaryYtd")) + + String.format(", Income Tax Rate: %s", printable.get("incomeTaxRate")) + + String.format(", Income Tax Withheld: %s", printable.get("incomeTaxWithheld")) + + String.format(", Net Paid: %s", printable.get("netPaid")) + + String.format(", Net Paid Before Tax: %s", printable.get("netPaidBeforeTax")) + + String.format(", Net Taxable: %s", printable.get("netTaxable")) + + String.format(", Net Taxable YTD: %s", printable.get("netTaxableYtd")) + + String.format(", Total Cost Employer: %s", printable.get("totalCostEmployer")) + + String.format(", Total Taxes and Deductions: %s", printable.get("totalTaxesAndDeductions")); + } + + private Map printableValues() { + Map printable = new HashMap<>(); + + printable.put( + "grossSalary", + SummaryHelper.formatAmount(this.grossSalary) + ); + printable.put( + "grossSalaryYtd", + SummaryHelper.formatAmount(this.grossSalaryYtd) + ); + printable.put( + "incomeTaxRate", + SummaryHelper.formatAmount(this.incomeTaxRate) + ); + printable.put( + "incomeTaxWithheld", + SummaryHelper.formatAmount(this.incomeTaxWithheld) + ); + printable.put( + "netPaid", + SummaryHelper.formatAmount(this.netPaid) + ); + printable.put( + "netPaidBeforeTax", + SummaryHelper.formatAmount(this.netPaidBeforeTax) + ); + printable.put( + "netTaxable", + SummaryHelper.formatAmount(this.netTaxable) + ); + printable.put( + "netTaxableYtd", + SummaryHelper.formatAmount(this.netTaxableYtd) + ); + printable.put( + "totalCostEmployer", + SummaryHelper.formatAmount(this.totalCostEmployer) + ); + printable.put( + "totalTaxesAndDeductions", + SummaryHelper.formatAmount(this.totalTaxesAndDeductions) + ); + return printable; + } +} diff --git a/src/main/java/com/mindee/product/fr/payslip/PayslipV2PayPeriod.java b/src/main/java/com/mindee/product/fr/payslip/PayslipV2PayPeriod.java new file mode 100644 index 000000000..55aeb3998 --- /dev/null +++ b/src/main/java/com/mindee/product/fr/payslip/PayslipV2PayPeriod.java @@ -0,0 +1,86 @@ +package com.mindee.product.fr.payslip; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.mindee.parsing.SummaryHelper; +import com.mindee.parsing.standard.BaseField; +import java.util.HashMap; +import java.util.Map; +import lombok.Getter; + +/** + * Information about the pay period. + */ +@Getter +@JsonIgnoreProperties(ignoreUnknown = true) +public class PayslipV2PayPeriod extends BaseField { + + /** + * The end date of the pay period. + */ + @JsonProperty("end_date") + String endDate; + /** + * The month of the pay period. + */ + @JsonProperty("month") + String month; + /** + * The date of payment for the pay period. + */ + @JsonProperty("payment_date") + String paymentDate; + /** + * The start date of the pay period. + */ + @JsonProperty("start_date") + String startDate; + /** + * The year of the pay period. + */ + @JsonProperty("year") + String year; + + public boolean isEmpty() { + return ( + (endDate == null || endDate.isEmpty()) + && (month == null || month.isEmpty()) + && (paymentDate == null || paymentDate.isEmpty()) + && (startDate == null || startDate.isEmpty()) + && (year == null || year.isEmpty()) + ); + } + + /** + * Output the object in a format suitable for inclusion in an rST field list. + */ + public String toFieldList() { + Map printable = this.printableValues(); + return String.format(" :End Date: %s%n", printable.get("endDate")) + + String.format(" :Month: %s%n", printable.get("month")) + + String.format(" :Payment Date: %s%n", printable.get("paymentDate")) + + String.format(" :Start Date: %s%n", printable.get("startDate")) + + String.format(" :Year: %s%n", printable.get("year")); + } + + @Override + public String toString() { + Map printable = this.printableValues(); + return String.format("End Date: %s", printable.get("endDate")) + + String.format(", Month: %s", printable.get("month")) + + String.format(", Payment Date: %s", printable.get("paymentDate")) + + String.format(", Start Date: %s", printable.get("startDate")) + + String.format(", Year: %s", printable.get("year")); + } + + private Map printableValues() { + Map printable = new HashMap<>(); + + printable.put("endDate", SummaryHelper.formatForDisplay(this.endDate, null)); + printable.put("month", SummaryHelper.formatForDisplay(this.month, null)); + printable.put("paymentDate", SummaryHelper.formatForDisplay(this.paymentDate, null)); + printable.put("startDate", SummaryHelper.formatForDisplay(this.startDate, null)); + printable.put("year", SummaryHelper.formatForDisplay(this.year, null)); + return printable; + } +} diff --git a/src/main/java/com/mindee/product/fr/payslip/PayslipV2Pto.java b/src/main/java/com/mindee/product/fr/payslip/PayslipV2Pto.java new file mode 100644 index 000000000..c88e3bbc3 --- /dev/null +++ b/src/main/java/com/mindee/product/fr/payslip/PayslipV2Pto.java @@ -0,0 +1,77 @@ +package com.mindee.product.fr.payslip; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.mindee.parsing.SummaryHelper; +import com.mindee.parsing.standard.BaseField; +import java.util.HashMap; +import java.util.Map; +import lombok.Getter; + +/** + * Information about paid time off. + */ +@Getter +@JsonIgnoreProperties(ignoreUnknown = true) +public class PayslipV2Pto extends BaseField { + + /** + * The amount of paid time off accrued in this period. + */ + @JsonProperty("accrued_this_period") + Double accruedThisPeriod; + /** + * The balance of paid time off at the end of the period. + */ + @JsonProperty("balance_end_of_period") + Double balanceEndOfPeriod; + /** + * The amount of paid time off used in this period. + */ + @JsonProperty("used_this_period") + Double usedThisPeriod; + + public boolean isEmpty() { + return ( + accruedThisPeriod == null + && balanceEndOfPeriod == null + && usedThisPeriod == null + ); + } + + /** + * Output the object in a format suitable for inclusion in an rST field list. + */ + public String toFieldList() { + Map printable = this.printableValues(); + return String.format(" :Accrued This Period: %s%n", printable.get("accruedThisPeriod")) + + String.format(" :Balance End of Period: %s%n", printable.get("balanceEndOfPeriod")) + + String.format(" :Used This Period: %s%n", printable.get("usedThisPeriod")); + } + + @Override + public String toString() { + Map printable = this.printableValues(); + return String.format("Accrued This Period: %s", printable.get("accruedThisPeriod")) + + String.format(", Balance End of Period: %s", printable.get("balanceEndOfPeriod")) + + String.format(", Used This Period: %s", printable.get("usedThisPeriod")); + } + + private Map printableValues() { + Map printable = new HashMap<>(); + + printable.put( + "accruedThisPeriod", + SummaryHelper.formatAmount(this.accruedThisPeriod) + ); + printable.put( + "balanceEndOfPeriod", + SummaryHelper.formatAmount(this.balanceEndOfPeriod) + ); + printable.put( + "usedThisPeriod", + SummaryHelper.formatAmount(this.usedThisPeriod) + ); + return printable; + } +} diff --git a/src/main/java/com/mindee/product/fr/payslip/PayslipV2SalaryDetail.java b/src/main/java/com/mindee/product/fr/payslip/PayslipV2SalaryDetail.java new file mode 100644 index 000000000..0448182a5 --- /dev/null +++ b/src/main/java/com/mindee/product/fr/payslip/PayslipV2SalaryDetail.java @@ -0,0 +1,106 @@ +package com.mindee.product.fr.payslip; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.mindee.parsing.SummaryHelper; +import com.mindee.parsing.standard.BaseField; +import com.mindee.parsing.standard.LineItemField; +import java.util.HashMap; +import java.util.Map; +import lombok.Getter; + +/** + * Detailed information about the earnings. + */ +@Getter +@JsonIgnoreProperties(ignoreUnknown = true) +public class PayslipV2SalaryDetail extends BaseField implements LineItemField { + + /** + * The amount of the earnings. + */ + @JsonProperty("amount") + Double amount; + /** + * The base value of the earnings. + */ + @JsonProperty("base") + Double base; + /** + * The description of the earnings. + */ + @JsonProperty("description") + String description; + /** + * The rate of the earnings. + */ + @JsonProperty("rate") + Double rate; + + public boolean isEmpty() { + return ( + amount == null + && base == null + && (description == null || description.isEmpty()) + && rate == null + ); + } + + private Map tablePrintableValues() { + Map printable = new HashMap<>(); + + printable.put( + "amount", + SummaryHelper.formatAmount(this.amount) + ); + printable.put( + "base", + SummaryHelper.formatAmount(this.base) + ); + printable.put("description", SummaryHelper.formatForDisplay(this.description, 36)); + printable.put( + "rate", + SummaryHelper.formatAmount(this.rate) + ); + return printable; + } + + /** + * Output the line in a format suitable for inclusion in an rST table. + */ + public String toTableLine() { + Map printable = this.tablePrintableValues(); + return String.format("| %-12s ", printable.get("amount")) + + String.format("| %-9s ", printable.get("base")) + + String.format("| %-36s ", printable.get("description")) + + String.format("| %-9s |", printable.get("rate")); + } + + @Override + public String toString() { + Map printable = this.printableValues(); + return String.format("Amount: %s", printable.get("amount")) + + String.format(", Base: %s", printable.get("base")) + + String.format(", Description: %s", printable.get("description")) + + String.format(", Rate: %s", printable.get("rate")); + } + + private Map printableValues() { + Map printable = new HashMap<>(); + + printable.put( + "amount", + SummaryHelper.formatAmount(this.amount) + ); + printable.put( + "base", + SummaryHelper.formatAmount(this.base) + ); + printable.put("description", SummaryHelper.formatForDisplay(this.description, null)); + printable.put( + "rate", + SummaryHelper.formatAmount(this.rate) + ); + return printable; + } +} diff --git a/src/main/java/com/mindee/product/invoice/InvoiceV4LineItem.java b/src/main/java/com/mindee/product/invoice/InvoiceV4LineItem.java index 8e5799b07..8a5f88fe1 100644 --- a/src/main/java/com/mindee/product/invoice/InvoiceV4LineItem.java +++ b/src/main/java/com/mindee/product/invoice/InvoiceV4LineItem.java @@ -70,11 +70,40 @@ public boolean isEmpty() { ); } + private Map tablePrintableValues() { + Map printable = new HashMap<>(); + + printable.put("description", SummaryHelper.formatForDisplay(this.description, 36)); + printable.put("productCode", SummaryHelper.formatForDisplay(this.productCode, null)); + printable.put( + "quantity", + SummaryHelper.formatAmount(this.quantity) + ); + printable.put( + "taxAmount", + SummaryHelper.formatAmount(this.taxAmount) + ); + printable.put( + "taxRate", + SummaryHelper.formatAmount(this.taxRate) + ); + printable.put( + "totalAmount", + SummaryHelper.formatAmount(this.totalAmount) + ); + printable.put("unitMeasure", SummaryHelper.formatForDisplay(this.unitMeasure, null)); + printable.put( + "unitPrice", + SummaryHelper.formatAmount(this.unitPrice) + ); + return printable; + } + /** * Output the line in a format suitable for inclusion in an rST table. */ public String toTableLine() { - Map printable = this.printableValues(); + Map printable = this.tablePrintableValues(); return String.format("| %-36s ", printable.get("description")) + String.format("| %-12s ", printable.get("productCode")) + String.format("| %-8s ", printable.get("quantity")) @@ -101,11 +130,7 @@ public String toString() { private Map printableValues() { Map printable = new HashMap<>(); - String descriptionSummary = (this.description != null ? this.description : ""); - if (descriptionSummary.length() >= 36) { - descriptionSummary = descriptionSummary.substring(0, 33) + "..."; - } - printable.put("description", descriptionSummary); + printable.put("description", SummaryHelper.formatForDisplay(this.description, null)); printable.put("productCode", SummaryHelper.formatForDisplay(this.productCode, null)); printable.put( "quantity", diff --git a/src/main/java/com/mindee/product/nutritionfactslabel/NutritionFactsLabelV1.java b/src/main/java/com/mindee/product/nutritionfactslabel/NutritionFactsLabelV1.java new file mode 100644 index 000000000..ca339d41f --- /dev/null +++ b/src/main/java/com/mindee/product/nutritionfactslabel/NutritionFactsLabelV1.java @@ -0,0 +1,16 @@ +package com.mindee.product.nutritionfactslabel; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.mindee.http.EndpointInfo; +import com.mindee.parsing.common.Inference; +import lombok.Getter; + +/** + * Nutrition Facts Label API version 1 inference prediction. + */ +@Getter +@JsonIgnoreProperties(ignoreUnknown = true) +@EndpointInfo(endpointName = "nutrition_facts", version = "1") +public class NutritionFactsLabelV1 + extends Inference { +} diff --git a/src/main/java/com/mindee/product/nutritionfactslabel/NutritionFactsLabelV1AddedSugar.java b/src/main/java/com/mindee/product/nutritionfactslabel/NutritionFactsLabelV1AddedSugar.java new file mode 100644 index 000000000..7bec45758 --- /dev/null +++ b/src/main/java/com/mindee/product/nutritionfactslabel/NutritionFactsLabelV1AddedSugar.java @@ -0,0 +1,77 @@ +package com.mindee.product.nutritionfactslabel; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.mindee.parsing.SummaryHelper; +import com.mindee.parsing.standard.BaseField; +import java.util.HashMap; +import java.util.Map; +import lombok.Getter; + +/** + * The amount of added sugars in the product. + */ +@Getter +@JsonIgnoreProperties(ignoreUnknown = true) +public class NutritionFactsLabelV1AddedSugar extends BaseField { + + /** + * DVs are the recommended amounts of added sugars to consume or not to exceed each day. + */ + @JsonProperty("daily_value") + Double dailyValue; + /** + * The amount of added sugars per 100g of the product. + */ + @JsonProperty("per_100g") + Double per100G; + /** + * The amount of added sugars per serving of the product. + */ + @JsonProperty("per_serving") + Double perServing; + + public boolean isEmpty() { + return ( + dailyValue == null + && per100G == null + && perServing == null + ); + } + + /** + * Output the object in a format suitable for inclusion in an rST field list. + */ + public String toFieldList() { + Map printable = this.printableValues(); + return String.format(" :Daily Value: %s%n", printable.get("dailyValue")) + + String.format(" :Per 100g: %s%n", printable.get("per100G")) + + String.format(" :Per Serving: %s%n", printable.get("perServing")); + } + + @Override + public String toString() { + Map printable = this.printableValues(); + return String.format("Daily Value: %s", printable.get("dailyValue")) + + String.format(", Per 100g: %s", printable.get("per100G")) + + String.format(", Per Serving: %s", printable.get("perServing")); + } + + private Map printableValues() { + Map printable = new HashMap<>(); + + printable.put( + "dailyValue", + SummaryHelper.formatAmount(this.dailyValue) + ); + printable.put( + "per100G", + SummaryHelper.formatAmount(this.per100G) + ); + printable.put( + "perServing", + SummaryHelper.formatAmount(this.perServing) + ); + return printable; + } +} diff --git a/src/main/java/com/mindee/product/nutritionfactslabel/NutritionFactsLabelV1Calorie.java b/src/main/java/com/mindee/product/nutritionfactslabel/NutritionFactsLabelV1Calorie.java new file mode 100644 index 000000000..373fd7d3d --- /dev/null +++ b/src/main/java/com/mindee/product/nutritionfactslabel/NutritionFactsLabelV1Calorie.java @@ -0,0 +1,77 @@ +package com.mindee.product.nutritionfactslabel; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.mindee.parsing.SummaryHelper; +import com.mindee.parsing.standard.BaseField; +import java.util.HashMap; +import java.util.Map; +import lombok.Getter; + +/** + * The amount of calories in the product. + */ +@Getter +@JsonIgnoreProperties(ignoreUnknown = true) +public class NutritionFactsLabelV1Calorie extends BaseField { + + /** + * DVs are the recommended amounts of calories to consume or not to exceed each day. + */ + @JsonProperty("daily_value") + Double dailyValue; + /** + * The amount of calories per 100g of the product. + */ + @JsonProperty("per_100g") + Double per100G; + /** + * The amount of calories per serving of the product. + */ + @JsonProperty("per_serving") + Double perServing; + + public boolean isEmpty() { + return ( + dailyValue == null + && per100G == null + && perServing == null + ); + } + + /** + * Output the object in a format suitable for inclusion in an rST field list. + */ + public String toFieldList() { + Map printable = this.printableValues(); + return String.format(" :Daily Value: %s%n", printable.get("dailyValue")) + + String.format(" :Per 100g: %s%n", printable.get("per100G")) + + String.format(" :Per Serving: %s%n", printable.get("perServing")); + } + + @Override + public String toString() { + Map printable = this.printableValues(); + return String.format("Daily Value: %s", printable.get("dailyValue")) + + String.format(", Per 100g: %s", printable.get("per100G")) + + String.format(", Per Serving: %s", printable.get("perServing")); + } + + private Map printableValues() { + Map printable = new HashMap<>(); + + printable.put( + "dailyValue", + SummaryHelper.formatAmount(this.dailyValue) + ); + printable.put( + "per100G", + SummaryHelper.formatAmount(this.per100G) + ); + printable.put( + "perServing", + SummaryHelper.formatAmount(this.perServing) + ); + return printable; + } +} diff --git a/src/main/java/com/mindee/product/nutritionfactslabel/NutritionFactsLabelV1Cholesterol.java b/src/main/java/com/mindee/product/nutritionfactslabel/NutritionFactsLabelV1Cholesterol.java new file mode 100644 index 000000000..3fdddf883 --- /dev/null +++ b/src/main/java/com/mindee/product/nutritionfactslabel/NutritionFactsLabelV1Cholesterol.java @@ -0,0 +1,77 @@ +package com.mindee.product.nutritionfactslabel; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.mindee.parsing.SummaryHelper; +import com.mindee.parsing.standard.BaseField; +import java.util.HashMap; +import java.util.Map; +import lombok.Getter; + +/** + * The amount of cholesterol in the product. + */ +@Getter +@JsonIgnoreProperties(ignoreUnknown = true) +public class NutritionFactsLabelV1Cholesterol extends BaseField { + + /** + * DVs are the recommended amounts of cholesterol to consume or not to exceed each day. + */ + @JsonProperty("daily_value") + Double dailyValue; + /** + * The amount of cholesterol per 100g of the product. + */ + @JsonProperty("per_100g") + Double per100G; + /** + * The amount of cholesterol per serving of the product. + */ + @JsonProperty("per_serving") + Double perServing; + + public boolean isEmpty() { + return ( + dailyValue == null + && per100G == null + && perServing == null + ); + } + + /** + * Output the object in a format suitable for inclusion in an rST field list. + */ + public String toFieldList() { + Map printable = this.printableValues(); + return String.format(" :Daily Value: %s%n", printable.get("dailyValue")) + + String.format(" :Per 100g: %s%n", printable.get("per100G")) + + String.format(" :Per Serving: %s%n", printable.get("perServing")); + } + + @Override + public String toString() { + Map printable = this.printableValues(); + return String.format("Daily Value: %s", printable.get("dailyValue")) + + String.format(", Per 100g: %s", printable.get("per100G")) + + String.format(", Per Serving: %s", printable.get("perServing")); + } + + private Map printableValues() { + Map printable = new HashMap<>(); + + printable.put( + "dailyValue", + SummaryHelper.formatAmount(this.dailyValue) + ); + printable.put( + "per100G", + SummaryHelper.formatAmount(this.per100G) + ); + printable.put( + "perServing", + SummaryHelper.formatAmount(this.perServing) + ); + return printable; + } +} diff --git a/src/main/java/com/mindee/product/nutritionfactslabel/NutritionFactsLabelV1DietaryFiber.java b/src/main/java/com/mindee/product/nutritionfactslabel/NutritionFactsLabelV1DietaryFiber.java new file mode 100644 index 000000000..92a36a8a0 --- /dev/null +++ b/src/main/java/com/mindee/product/nutritionfactslabel/NutritionFactsLabelV1DietaryFiber.java @@ -0,0 +1,77 @@ +package com.mindee.product.nutritionfactslabel; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.mindee.parsing.SummaryHelper; +import com.mindee.parsing.standard.BaseField; +import java.util.HashMap; +import java.util.Map; +import lombok.Getter; + +/** + * The amount of dietary fiber in the product. + */ +@Getter +@JsonIgnoreProperties(ignoreUnknown = true) +public class NutritionFactsLabelV1DietaryFiber extends BaseField { + + /** + * DVs are the recommended amounts of dietary fiber to consume or not to exceed each day. + */ + @JsonProperty("daily_value") + Double dailyValue; + /** + * The amount of dietary fiber per 100g of the product. + */ + @JsonProperty("per_100g") + Double per100G; + /** + * The amount of dietary fiber per serving of the product. + */ + @JsonProperty("per_serving") + Double perServing; + + public boolean isEmpty() { + return ( + dailyValue == null + && per100G == null + && perServing == null + ); + } + + /** + * Output the object in a format suitable for inclusion in an rST field list. + */ + public String toFieldList() { + Map printable = this.printableValues(); + return String.format(" :Daily Value: %s%n", printable.get("dailyValue")) + + String.format(" :Per 100g: %s%n", printable.get("per100G")) + + String.format(" :Per Serving: %s%n", printable.get("perServing")); + } + + @Override + public String toString() { + Map printable = this.printableValues(); + return String.format("Daily Value: %s", printable.get("dailyValue")) + + String.format(", Per 100g: %s", printable.get("per100G")) + + String.format(", Per Serving: %s", printable.get("perServing")); + } + + private Map printableValues() { + Map printable = new HashMap<>(); + + printable.put( + "dailyValue", + SummaryHelper.formatAmount(this.dailyValue) + ); + printable.put( + "per100G", + SummaryHelper.formatAmount(this.per100G) + ); + printable.put( + "perServing", + SummaryHelper.formatAmount(this.perServing) + ); + return printable; + } +} diff --git a/src/main/java/com/mindee/product/nutritionfactslabel/NutritionFactsLabelV1Document.java b/src/main/java/com/mindee/product/nutritionfactslabel/NutritionFactsLabelV1Document.java new file mode 100644 index 000000000..756cf5e72 --- /dev/null +++ b/src/main/java/com/mindee/product/nutritionfactslabel/NutritionFactsLabelV1Document.java @@ -0,0 +1,173 @@ +package com.mindee.product.nutritionfactslabel; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.mindee.parsing.SummaryHelper; +import com.mindee.parsing.common.Prediction; +import com.mindee.parsing.standard.AmountField; +import java.util.ArrayList; +import java.util.List; +import lombok.EqualsAndHashCode; +import lombok.Getter; + +/** + * Nutrition Facts Label API version 1.0 document data. + */ +@Getter +@EqualsAndHashCode(callSuper = false) +@JsonIgnoreProperties(ignoreUnknown = true) +public class NutritionFactsLabelV1Document extends Prediction { + + /** + * The amount of added sugars in the product. + */ + @JsonProperty("added_sugars") + protected NutritionFactsLabelV1AddedSugar addedSugars; + /** + * The amount of calories in the product. + */ + @JsonProperty("calories") + protected NutritionFactsLabelV1Calorie calories; + /** + * The amount of cholesterol in the product. + */ + @JsonProperty("cholesterol") + protected NutritionFactsLabelV1Cholesterol cholesterol; + /** + * The amount of dietary fiber in the product. + */ + @JsonProperty("dietary_fiber") + protected NutritionFactsLabelV1DietaryFiber dietaryFiber; + /** + * The amount of nutrients in the product. + */ + @JsonProperty("nutrients") + protected List nutrients = new ArrayList<>(); + /** + * The amount of protein in the product. + */ + @JsonProperty("protein") + protected NutritionFactsLabelV1Protein protein; + /** + * The amount of saturated fat in the product. + */ + @JsonProperty("saturated_fat") + protected NutritionFactsLabelV1SaturatedFat saturatedFat; + /** + * The number of servings in each box of the product. + */ + @JsonProperty("serving_per_box") + protected AmountField servingPerBox; + /** + * The size of a single serving of the product. + */ + @JsonProperty("serving_size") + protected NutritionFactsLabelV1ServingSize servingSize; + /** + * The amount of sodium in the product. + */ + @JsonProperty("sodium") + protected NutritionFactsLabelV1Sodium sodium; + /** + * The total amount of carbohydrates in the product. + */ + @JsonProperty("total_carbohydrate") + protected NutritionFactsLabelV1TotalCarbohydrate totalCarbohydrate; + /** + * The total amount of fat in the product. + */ + @JsonProperty("total_fat") + protected NutritionFactsLabelV1TotalFat totalFat; + /** + * The total amount of sugars in the product. + */ + @JsonProperty("total_sugars") + protected NutritionFactsLabelV1TotalSugar totalSugars; + /** + * The amount of trans fat in the product. + */ + @JsonProperty("trans_fat") + protected NutritionFactsLabelV1TransFat transFat; + + @Override + public boolean isEmpty() { + return ( + this.servingPerBox == null + && this.servingSize == null + && this.calories == null + && this.totalFat == null + && this.saturatedFat == null + && this.transFat == null + && this.cholesterol == null + && this.totalCarbohydrate == null + && this.dietaryFiber == null + && this.totalSugars == null + && this.addedSugars == null + && this.protein == null + && this.sodium == null + && (this.nutrients == null || this.nutrients.isEmpty()) + ); + } + + @Override + public String toString() { + StringBuilder outStr = new StringBuilder(); + outStr.append( + String.format(":Serving per Box: %s%n", this.getServingPerBox()) + ); + outStr.append( + String.format(":Serving Size:%n%s", this.getServingSize().toFieldList()) + ); + outStr.append( + String.format(":Calories:%n%s", this.getCalories().toFieldList()) + ); + outStr.append( + String.format(":Total Fat:%n%s", this.getTotalFat().toFieldList()) + ); + outStr.append( + String.format(":Saturated Fat:%n%s", this.getSaturatedFat().toFieldList()) + ); + outStr.append( + String.format(":Trans Fat:%n%s", this.getTransFat().toFieldList()) + ); + outStr.append( + String.format(":Cholesterol:%n%s", this.getCholesterol().toFieldList()) + ); + outStr.append( + String.format(":Total Carbohydrate:%n%s", this.getTotalCarbohydrate().toFieldList()) + ); + outStr.append( + String.format(":Dietary Fiber:%n%s", this.getDietaryFiber().toFieldList()) + ); + outStr.append( + String.format(":Total Sugars:%n%s", this.getTotalSugars().toFieldList()) + ); + outStr.append( + String.format(":Added Sugars:%n%s", this.getAddedSugars().toFieldList()) + ); + outStr.append( + String.format(":Protein:%n%s", this.getProtein().toFieldList()) + ); + outStr.append( + String.format(":sodium:%n%s", this.getSodium().toFieldList()) + ); + String nutrientsSummary = ""; + if (!this.getNutrients().isEmpty()) { + int[] nutrientsColSizes = new int[]{13, 22, 10, 13, 6}; + nutrientsSummary = + String.format("%n%s%n ", SummaryHelper.lineSeparator(nutrientsColSizes, "-")) + + "| Daily Value " + + "| Name " + + "| Per 100g " + + "| Per Serving " + + "| Unit " + + String.format("|%n%s%n ", SummaryHelper.lineSeparator(nutrientsColSizes, "=")); + nutrientsSummary += SummaryHelper.arrayToString(this.getNutrients(), nutrientsColSizes); + nutrientsSummary += String.format("%n%s", SummaryHelper.lineSeparator(nutrientsColSizes, "-")); + } + outStr.append( + String.format(":nutrients: %s%n", nutrientsSummary) + ); + return SummaryHelper.cleanSummary(outStr.toString()); + } +} diff --git a/src/main/java/com/mindee/product/nutritionfactslabel/NutritionFactsLabelV1Nutrient.java b/src/main/java/com/mindee/product/nutritionfactslabel/NutritionFactsLabelV1Nutrient.java new file mode 100644 index 000000000..1ed950a45 --- /dev/null +++ b/src/main/java/com/mindee/product/nutritionfactslabel/NutritionFactsLabelV1Nutrient.java @@ -0,0 +1,116 @@ +package com.mindee.product.nutritionfactslabel; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.mindee.parsing.SummaryHelper; +import com.mindee.parsing.standard.BaseField; +import com.mindee.parsing.standard.LineItemField; +import java.util.HashMap; +import java.util.Map; +import lombok.Getter; + +/** + * The amount of nutrients in the product. + */ +@Getter +@JsonIgnoreProperties(ignoreUnknown = true) +public class NutritionFactsLabelV1Nutrient extends BaseField implements LineItemField { + + /** + * DVs are the recommended amounts of nutrients to consume or not to exceed each day. + */ + @JsonProperty("daily_value") + Double dailyValue; + /** + * The name of nutrients of the product. + */ + @JsonProperty("name") + String name; + /** + * The amount of nutrients per 100g of the product. + */ + @JsonProperty("per_100g") + Double per100G; + /** + * The amount of nutrients per serving of the product. + */ + @JsonProperty("per_serving") + Double perServing; + /** + * The unit of measurement for the amount of nutrients. + */ + @JsonProperty("unit") + String unit; + + public boolean isEmpty() { + return ( + dailyValue == null + && (name == null || name.isEmpty()) + && per100G == null + && perServing == null + && (unit == null || unit.isEmpty()) + ); + } + + private Map tablePrintableValues() { + Map printable = new HashMap<>(); + + printable.put( + "dailyValue", + SummaryHelper.formatAmount(this.dailyValue) + ); + printable.put("name", SummaryHelper.formatForDisplay(this.name, 20)); + printable.put( + "per100G", + SummaryHelper.formatAmount(this.per100G) + ); + printable.put( + "perServing", + SummaryHelper.formatAmount(this.perServing) + ); + printable.put("unit", SummaryHelper.formatForDisplay(this.unit, null)); + return printable; + } + + /** + * Output the line in a format suitable for inclusion in an rST table. + */ + public String toTableLine() { + Map printable = this.tablePrintableValues(); + return String.format("| %-11s ", printable.get("dailyValue")) + + String.format("| %-20s ", printable.get("name")) + + String.format("| %-8s ", printable.get("per100G")) + + String.format("| %-11s ", printable.get("perServing")) + + String.format("| %-4s |", printable.get("unit")); + } + + @Override + public String toString() { + Map printable = this.printableValues(); + return String.format("Daily Value: %s", printable.get("dailyValue")) + + String.format(", Name: %s", printable.get("name")) + + String.format(", Per 100g: %s", printable.get("per100G")) + + String.format(", Per Serving: %s", printable.get("perServing")) + + String.format(", Unit: %s", printable.get("unit")); + } + + private Map printableValues() { + Map printable = new HashMap<>(); + + printable.put( + "dailyValue", + SummaryHelper.formatAmount(this.dailyValue) + ); + printable.put("name", SummaryHelper.formatForDisplay(this.name, null)); + printable.put( + "per100G", + SummaryHelper.formatAmount(this.per100G) + ); + printable.put( + "perServing", + SummaryHelper.formatAmount(this.perServing) + ); + printable.put("unit", SummaryHelper.formatForDisplay(this.unit, null)); + return printable; + } +} diff --git a/src/main/java/com/mindee/product/nutritionfactslabel/NutritionFactsLabelV1Protein.java b/src/main/java/com/mindee/product/nutritionfactslabel/NutritionFactsLabelV1Protein.java new file mode 100644 index 000000000..23a1eeaaf --- /dev/null +++ b/src/main/java/com/mindee/product/nutritionfactslabel/NutritionFactsLabelV1Protein.java @@ -0,0 +1,77 @@ +package com.mindee.product.nutritionfactslabel; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.mindee.parsing.SummaryHelper; +import com.mindee.parsing.standard.BaseField; +import java.util.HashMap; +import java.util.Map; +import lombok.Getter; + +/** + * The amount of protein in the product. + */ +@Getter +@JsonIgnoreProperties(ignoreUnknown = true) +public class NutritionFactsLabelV1Protein extends BaseField { + + /** + * DVs are the recommended amounts of protein to consume or not to exceed each day. + */ + @JsonProperty("daily_value") + Double dailyValue; + /** + * The amount of protein per 100g of the product. + */ + @JsonProperty("per_100g") + Double per100G; + /** + * The amount of protein per serving of the product. + */ + @JsonProperty("per_serving") + Double perServing; + + public boolean isEmpty() { + return ( + dailyValue == null + && per100G == null + && perServing == null + ); + } + + /** + * Output the object in a format suitable for inclusion in an rST field list. + */ + public String toFieldList() { + Map printable = this.printableValues(); + return String.format(" :Daily Value: %s%n", printable.get("dailyValue")) + + String.format(" :Per 100g: %s%n", printable.get("per100G")) + + String.format(" :Per Serving: %s%n", printable.get("perServing")); + } + + @Override + public String toString() { + Map printable = this.printableValues(); + return String.format("Daily Value: %s", printable.get("dailyValue")) + + String.format(", Per 100g: %s", printable.get("per100G")) + + String.format(", Per Serving: %s", printable.get("perServing")); + } + + private Map printableValues() { + Map printable = new HashMap<>(); + + printable.put( + "dailyValue", + SummaryHelper.formatAmount(this.dailyValue) + ); + printable.put( + "per100G", + SummaryHelper.formatAmount(this.per100G) + ); + printable.put( + "perServing", + SummaryHelper.formatAmount(this.perServing) + ); + return printable; + } +} diff --git a/src/main/java/com/mindee/product/nutritionfactslabel/NutritionFactsLabelV1SaturatedFat.java b/src/main/java/com/mindee/product/nutritionfactslabel/NutritionFactsLabelV1SaturatedFat.java new file mode 100644 index 000000000..feb299e66 --- /dev/null +++ b/src/main/java/com/mindee/product/nutritionfactslabel/NutritionFactsLabelV1SaturatedFat.java @@ -0,0 +1,77 @@ +package com.mindee.product.nutritionfactslabel; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.mindee.parsing.SummaryHelper; +import com.mindee.parsing.standard.BaseField; +import java.util.HashMap; +import java.util.Map; +import lombok.Getter; + +/** + * The amount of saturated fat in the product. + */ +@Getter +@JsonIgnoreProperties(ignoreUnknown = true) +public class NutritionFactsLabelV1SaturatedFat extends BaseField { + + /** + * DVs are the recommended amounts of saturated fat to consume or not to exceed each day. + */ + @JsonProperty("daily_value") + Double dailyValue; + /** + * The amount of saturated fat per 100g of the product. + */ + @JsonProperty("per_100g") + Double per100G; + /** + * The amount of saturated fat per serving of the product. + */ + @JsonProperty("per_serving") + Double perServing; + + public boolean isEmpty() { + return ( + dailyValue == null + && per100G == null + && perServing == null + ); + } + + /** + * Output the object in a format suitable for inclusion in an rST field list. + */ + public String toFieldList() { + Map printable = this.printableValues(); + return String.format(" :Daily Value: %s%n", printable.get("dailyValue")) + + String.format(" :Per 100g: %s%n", printable.get("per100G")) + + String.format(" :Per Serving: %s%n", printable.get("perServing")); + } + + @Override + public String toString() { + Map printable = this.printableValues(); + return String.format("Daily Value: %s", printable.get("dailyValue")) + + String.format(", Per 100g: %s", printable.get("per100G")) + + String.format(", Per Serving: %s", printable.get("perServing")); + } + + private Map printableValues() { + Map printable = new HashMap<>(); + + printable.put( + "dailyValue", + SummaryHelper.formatAmount(this.dailyValue) + ); + printable.put( + "per100G", + SummaryHelper.formatAmount(this.per100G) + ); + printable.put( + "perServing", + SummaryHelper.formatAmount(this.perServing) + ); + return printable; + } +} diff --git a/src/main/java/com/mindee/product/nutritionfactslabel/NutritionFactsLabelV1ServingSize.java b/src/main/java/com/mindee/product/nutritionfactslabel/NutritionFactsLabelV1ServingSize.java new file mode 100644 index 000000000..9b4bef0d3 --- /dev/null +++ b/src/main/java/com/mindee/product/nutritionfactslabel/NutritionFactsLabelV1ServingSize.java @@ -0,0 +1,62 @@ +package com.mindee.product.nutritionfactslabel; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.mindee.parsing.SummaryHelper; +import com.mindee.parsing.standard.BaseField; +import java.util.HashMap; +import java.util.Map; +import lombok.Getter; + +/** + * The size of a single serving of the product. + */ +@Getter +@JsonIgnoreProperties(ignoreUnknown = true) +public class NutritionFactsLabelV1ServingSize extends BaseField { + + /** + * The amount of a single serving. + */ + @JsonProperty("amount") + Double amount; + /** + * The unit for the amount of a single serving. + */ + @JsonProperty("unit") + String unit; + + public boolean isEmpty() { + return ( + amount == null + && (unit == null || unit.isEmpty()) + ); + } + + /** + * Output the object in a format suitable for inclusion in an rST field list. + */ + public String toFieldList() { + Map printable = this.printableValues(); + return String.format(" :Amount: %s%n", printable.get("amount")) + + String.format(" :Unit: %s%n", printable.get("unit")); + } + + @Override + public String toString() { + Map printable = this.printableValues(); + return String.format("Amount: %s", printable.get("amount")) + + String.format(", Unit: %s", printable.get("unit")); + } + + private Map printableValues() { + Map printable = new HashMap<>(); + + printable.put( + "amount", + SummaryHelper.formatAmount(this.amount) + ); + printable.put("unit", SummaryHelper.formatForDisplay(this.unit, null)); + return printable; + } +} diff --git a/src/main/java/com/mindee/product/nutritionfactslabel/NutritionFactsLabelV1Sodium.java b/src/main/java/com/mindee/product/nutritionfactslabel/NutritionFactsLabelV1Sodium.java new file mode 100644 index 000000000..9cd2d6556 --- /dev/null +++ b/src/main/java/com/mindee/product/nutritionfactslabel/NutritionFactsLabelV1Sodium.java @@ -0,0 +1,86 @@ +package com.mindee.product.nutritionfactslabel; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.mindee.parsing.SummaryHelper; +import com.mindee.parsing.standard.BaseField; +import java.util.HashMap; +import java.util.Map; +import lombok.Getter; + +/** + * The amount of sodium in the product. + */ +@Getter +@JsonIgnoreProperties(ignoreUnknown = true) +public class NutritionFactsLabelV1Sodium extends BaseField { + + /** + * DVs are the recommended amounts of sodium to consume or not to exceed each day. + */ + @JsonProperty("daily_value") + Double dailyValue; + /** + * The amount of sodium per 100g of the product. + */ + @JsonProperty("per_100g") + Double per100G; + /** + * The amount of sodium per serving of the product. + */ + @JsonProperty("per_serving") + Double perServing; + /** + * The unit of measurement for the amount of sodium. + */ + @JsonProperty("unit") + String unit; + + public boolean isEmpty() { + return ( + dailyValue == null + && per100G == null + && perServing == null + && (unit == null || unit.isEmpty()) + ); + } + + /** + * Output the object in a format suitable for inclusion in an rST field list. + */ + public String toFieldList() { + Map printable = this.printableValues(); + return String.format(" :Daily Value: %s%n", printable.get("dailyValue")) + + String.format(" :Per 100g: %s%n", printable.get("per100G")) + + String.format(" :Per Serving: %s%n", printable.get("perServing")) + + String.format(" :Unit: %s%n", printable.get("unit")); + } + + @Override + public String toString() { + Map printable = this.printableValues(); + return String.format("Daily Value: %s", printable.get("dailyValue")) + + String.format(", Per 100g: %s", printable.get("per100G")) + + String.format(", Per Serving: %s", printable.get("perServing")) + + String.format(", Unit: %s", printable.get("unit")); + } + + private Map printableValues() { + Map printable = new HashMap<>(); + + printable.put( + "dailyValue", + SummaryHelper.formatAmount(this.dailyValue) + ); + printable.put( + "per100G", + SummaryHelper.formatAmount(this.per100G) + ); + printable.put( + "perServing", + SummaryHelper.formatAmount(this.perServing) + ); + printable.put("unit", SummaryHelper.formatForDisplay(this.unit, null)); + return printable; + } +} diff --git a/src/main/java/com/mindee/product/nutritionfactslabel/NutritionFactsLabelV1TotalCarbohydrate.java b/src/main/java/com/mindee/product/nutritionfactslabel/NutritionFactsLabelV1TotalCarbohydrate.java new file mode 100644 index 000000000..e17d5adb1 --- /dev/null +++ b/src/main/java/com/mindee/product/nutritionfactslabel/NutritionFactsLabelV1TotalCarbohydrate.java @@ -0,0 +1,77 @@ +package com.mindee.product.nutritionfactslabel; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.mindee.parsing.SummaryHelper; +import com.mindee.parsing.standard.BaseField; +import java.util.HashMap; +import java.util.Map; +import lombok.Getter; + +/** + * The total amount of carbohydrates in the product. + */ +@Getter +@JsonIgnoreProperties(ignoreUnknown = true) +public class NutritionFactsLabelV1TotalCarbohydrate extends BaseField { + + /** + * DVs are the recommended amounts of total carbohydrates to consume or not to exceed each day. + */ + @JsonProperty("daily_value") + Double dailyValue; + /** + * The amount of total carbohydrates per 100g of the product. + */ + @JsonProperty("per_100g") + Double per100G; + /** + * The amount of total carbohydrates per serving of the product. + */ + @JsonProperty("per_serving") + Double perServing; + + public boolean isEmpty() { + return ( + dailyValue == null + && per100G == null + && perServing == null + ); + } + + /** + * Output the object in a format suitable for inclusion in an rST field list. + */ + public String toFieldList() { + Map printable = this.printableValues(); + return String.format(" :Daily Value: %s%n", printable.get("dailyValue")) + + String.format(" :Per 100g: %s%n", printable.get("per100G")) + + String.format(" :Per Serving: %s%n", printable.get("perServing")); + } + + @Override + public String toString() { + Map printable = this.printableValues(); + return String.format("Daily Value: %s", printable.get("dailyValue")) + + String.format(", Per 100g: %s", printable.get("per100G")) + + String.format(", Per Serving: %s", printable.get("perServing")); + } + + private Map printableValues() { + Map printable = new HashMap<>(); + + printable.put( + "dailyValue", + SummaryHelper.formatAmount(this.dailyValue) + ); + printable.put( + "per100G", + SummaryHelper.formatAmount(this.per100G) + ); + printable.put( + "perServing", + SummaryHelper.formatAmount(this.perServing) + ); + return printable; + } +} diff --git a/src/main/java/com/mindee/product/nutritionfactslabel/NutritionFactsLabelV1TotalFat.java b/src/main/java/com/mindee/product/nutritionfactslabel/NutritionFactsLabelV1TotalFat.java new file mode 100644 index 000000000..b5e0633ad --- /dev/null +++ b/src/main/java/com/mindee/product/nutritionfactslabel/NutritionFactsLabelV1TotalFat.java @@ -0,0 +1,77 @@ +package com.mindee.product.nutritionfactslabel; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.mindee.parsing.SummaryHelper; +import com.mindee.parsing.standard.BaseField; +import java.util.HashMap; +import java.util.Map; +import lombok.Getter; + +/** + * The total amount of fat in the product. + */ +@Getter +@JsonIgnoreProperties(ignoreUnknown = true) +public class NutritionFactsLabelV1TotalFat extends BaseField { + + /** + * DVs are the recommended amounts of total fat to consume or not to exceed each day. + */ + @JsonProperty("daily_value") + Double dailyValue; + /** + * The amount of total fat per 100g of the product. + */ + @JsonProperty("per_100g") + Double per100G; + /** + * The amount of total fat per serving of the product. + */ + @JsonProperty("per_serving") + Double perServing; + + public boolean isEmpty() { + return ( + dailyValue == null + && per100G == null + && perServing == null + ); + } + + /** + * Output the object in a format suitable for inclusion in an rST field list. + */ + public String toFieldList() { + Map printable = this.printableValues(); + return String.format(" :Daily Value: %s%n", printable.get("dailyValue")) + + String.format(" :Per 100g: %s%n", printable.get("per100G")) + + String.format(" :Per Serving: %s%n", printable.get("perServing")); + } + + @Override + public String toString() { + Map printable = this.printableValues(); + return String.format("Daily Value: %s", printable.get("dailyValue")) + + String.format(", Per 100g: %s", printable.get("per100G")) + + String.format(", Per Serving: %s", printable.get("perServing")); + } + + private Map printableValues() { + Map printable = new HashMap<>(); + + printable.put( + "dailyValue", + SummaryHelper.formatAmount(this.dailyValue) + ); + printable.put( + "per100G", + SummaryHelper.formatAmount(this.per100G) + ); + printable.put( + "perServing", + SummaryHelper.formatAmount(this.perServing) + ); + return printable; + } +} diff --git a/src/main/java/com/mindee/product/nutritionfactslabel/NutritionFactsLabelV1TotalSugar.java b/src/main/java/com/mindee/product/nutritionfactslabel/NutritionFactsLabelV1TotalSugar.java new file mode 100644 index 000000000..198edcff7 --- /dev/null +++ b/src/main/java/com/mindee/product/nutritionfactslabel/NutritionFactsLabelV1TotalSugar.java @@ -0,0 +1,77 @@ +package com.mindee.product.nutritionfactslabel; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.mindee.parsing.SummaryHelper; +import com.mindee.parsing.standard.BaseField; +import java.util.HashMap; +import java.util.Map; +import lombok.Getter; + +/** + * The total amount of sugars in the product. + */ +@Getter +@JsonIgnoreProperties(ignoreUnknown = true) +public class NutritionFactsLabelV1TotalSugar extends BaseField { + + /** + * DVs are the recommended amounts of total sugars to consume or not to exceed each day. + */ + @JsonProperty("daily_value") + Double dailyValue; + /** + * The amount of total sugars per 100g of the product. + */ + @JsonProperty("per_100g") + Double per100G; + /** + * The amount of total sugars per serving of the product. + */ + @JsonProperty("per_serving") + Double perServing; + + public boolean isEmpty() { + return ( + dailyValue == null + && per100G == null + && perServing == null + ); + } + + /** + * Output the object in a format suitable for inclusion in an rST field list. + */ + public String toFieldList() { + Map printable = this.printableValues(); + return String.format(" :Daily Value: %s%n", printable.get("dailyValue")) + + String.format(" :Per 100g: %s%n", printable.get("per100G")) + + String.format(" :Per Serving: %s%n", printable.get("perServing")); + } + + @Override + public String toString() { + Map printable = this.printableValues(); + return String.format("Daily Value: %s", printable.get("dailyValue")) + + String.format(", Per 100g: %s", printable.get("per100G")) + + String.format(", Per Serving: %s", printable.get("perServing")); + } + + private Map printableValues() { + Map printable = new HashMap<>(); + + printable.put( + "dailyValue", + SummaryHelper.formatAmount(this.dailyValue) + ); + printable.put( + "per100G", + SummaryHelper.formatAmount(this.per100G) + ); + printable.put( + "perServing", + SummaryHelper.formatAmount(this.perServing) + ); + return printable; + } +} diff --git a/src/main/java/com/mindee/product/nutritionfactslabel/NutritionFactsLabelV1TransFat.java b/src/main/java/com/mindee/product/nutritionfactslabel/NutritionFactsLabelV1TransFat.java new file mode 100644 index 000000000..123196da6 --- /dev/null +++ b/src/main/java/com/mindee/product/nutritionfactslabel/NutritionFactsLabelV1TransFat.java @@ -0,0 +1,77 @@ +package com.mindee.product.nutritionfactslabel; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.mindee.parsing.SummaryHelper; +import com.mindee.parsing.standard.BaseField; +import java.util.HashMap; +import java.util.Map; +import lombok.Getter; + +/** + * The amount of trans fat in the product. + */ +@Getter +@JsonIgnoreProperties(ignoreUnknown = true) +public class NutritionFactsLabelV1TransFat extends BaseField { + + /** + * DVs are the recommended amounts of trans fat to consume or not to exceed each day. + */ + @JsonProperty("daily_value") + Double dailyValue; + /** + * The amount of trans fat per 100g of the product. + */ + @JsonProperty("per_100g") + Double per100G; + /** + * The amount of trans fat per serving of the product. + */ + @JsonProperty("per_serving") + Double perServing; + + public boolean isEmpty() { + return ( + dailyValue == null + && per100G == null + && perServing == null + ); + } + + /** + * Output the object in a format suitable for inclusion in an rST field list. + */ + public String toFieldList() { + Map printable = this.printableValues(); + return String.format(" :Daily Value: %s%n", printable.get("dailyValue")) + + String.format(" :Per 100g: %s%n", printable.get("per100G")) + + String.format(" :Per Serving: %s%n", printable.get("perServing")); + } + + @Override + public String toString() { + Map printable = this.printableValues(); + return String.format("Daily Value: %s", printable.get("dailyValue")) + + String.format(", Per 100g: %s", printable.get("per100G")) + + String.format(", Per Serving: %s", printable.get("perServing")); + } + + private Map printableValues() { + Map printable = new HashMap<>(); + + printable.put( + "dailyValue", + SummaryHelper.formatAmount(this.dailyValue) + ); + printable.put( + "per100G", + SummaryHelper.formatAmount(this.per100G) + ); + printable.put( + "perServing", + SummaryHelper.formatAmount(this.perServing) + ); + return printable; + } +} diff --git a/src/main/java/com/mindee/product/receipt/ReceiptV5LineItem.java b/src/main/java/com/mindee/product/receipt/ReceiptV5LineItem.java index 6aa787667..c4f814bb0 100644 --- a/src/main/java/com/mindee/product/receipt/ReceiptV5LineItem.java +++ b/src/main/java/com/mindee/product/receipt/ReceiptV5LineItem.java @@ -46,11 +46,30 @@ public boolean isEmpty() { ); } + private Map tablePrintableValues() { + Map printable = new HashMap<>(); + + printable.put("description", SummaryHelper.formatForDisplay(this.description, 36)); + printable.put( + "quantity", + SummaryHelper.formatAmount(this.quantity) + ); + printable.put( + "totalAmount", + SummaryHelper.formatAmount(this.totalAmount) + ); + printable.put( + "unitPrice", + SummaryHelper.formatAmount(this.unitPrice) + ); + return printable; + } + /** * Output the line in a format suitable for inclusion in an rST table. */ public String toTableLine() { - Map printable = this.printableValues(); + Map printable = this.tablePrintableValues(); return String.format("| %-36s ", printable.get("description")) + String.format("| %-8s ", printable.get("quantity")) + String.format("| %-12s ", printable.get("totalAmount")) @@ -69,11 +88,7 @@ public String toString() { private Map printableValues() { Map printable = new HashMap<>(); - String descriptionSummary = (this.description != null ? this.description : ""); - if (descriptionSummary.length() >= 36) { - descriptionSummary = descriptionSummary.substring(0, 33) + "..."; - } - printable.put("description", descriptionSummary); + printable.put("description", SummaryHelper.formatForDisplay(this.description, null)); printable.put( "quantity", SummaryHelper.formatAmount(this.quantity) diff --git a/src/main/java/com/mindee/product/resume/ResumeV1Certificate.java b/src/main/java/com/mindee/product/resume/ResumeV1Certificate.java index f97a12322..d0b79428a 100644 --- a/src/main/java/com/mindee/product/resume/ResumeV1Certificate.java +++ b/src/main/java/com/mindee/product/resume/ResumeV1Certificate.java @@ -46,11 +46,21 @@ public boolean isEmpty() { ); } + private Map tablePrintableValues() { + Map printable = new HashMap<>(); + + printable.put("grade", SummaryHelper.formatForDisplay(this.grade, 10)); + printable.put("name", SummaryHelper.formatForDisplay(this.name, 30)); + printable.put("provider", SummaryHelper.formatForDisplay(this.provider, 25)); + printable.put("year", SummaryHelper.formatForDisplay(this.year, null)); + return printable; + } + /** * Output the line in a format suitable for inclusion in an rST table. */ public String toTableLine() { - Map printable = this.printableValues(); + Map printable = this.tablePrintableValues(); return String.format("| %-10s ", printable.get("grade")) + String.format("| %-30s ", printable.get("name")) + String.format("| %-25s ", printable.get("provider")) @@ -69,9 +79,9 @@ public String toString() { private Map printableValues() { Map printable = new HashMap<>(); - printable.put("grade", SummaryHelper.formatForDisplay(this.grade, 10)); - printable.put("name", SummaryHelper.formatForDisplay(this.name, 30)); - printable.put("provider", SummaryHelper.formatForDisplay(this.provider, 25)); + printable.put("grade", SummaryHelper.formatForDisplay(this.grade, null)); + printable.put("name", SummaryHelper.formatForDisplay(this.name, null)); + printable.put("provider", SummaryHelper.formatForDisplay(this.provider, null)); printable.put("year", SummaryHelper.formatForDisplay(this.year, null)); return printable; } diff --git a/src/main/java/com/mindee/product/resume/ResumeV1Education.java b/src/main/java/com/mindee/product/resume/ResumeV1Education.java index 27cb79d38..75951659e 100644 --- a/src/main/java/com/mindee/product/resume/ResumeV1Education.java +++ b/src/main/java/com/mindee/product/resume/ResumeV1Education.java @@ -64,11 +64,24 @@ public boolean isEmpty() { ); } + private Map tablePrintableValues() { + Map printable = new HashMap<>(); + + printable.put("degreeDomain", SummaryHelper.formatForDisplay(this.degreeDomain, 15)); + printable.put("degreeType", SummaryHelper.formatForDisplay(this.degreeType, 25)); + printable.put("endMonth", SummaryHelper.formatForDisplay(this.endMonth, null)); + printable.put("endYear", SummaryHelper.formatForDisplay(this.endYear, null)); + printable.put("school", SummaryHelper.formatForDisplay(this.school, 25)); + printable.put("startMonth", SummaryHelper.formatForDisplay(this.startMonth, null)); + printable.put("startYear", SummaryHelper.formatForDisplay(this.startYear, null)); + return printable; + } + /** * Output the line in a format suitable for inclusion in an rST table. */ public String toTableLine() { - Map printable = this.printableValues(); + Map printable = this.tablePrintableValues(); return String.format("| %-15s ", printable.get("degreeDomain")) + String.format("| %-25s ", printable.get("degreeType")) + String.format("| %-9s ", printable.get("endMonth")) @@ -93,11 +106,11 @@ public String toString() { private Map printableValues() { Map printable = new HashMap<>(); - printable.put("degreeDomain", SummaryHelper.formatForDisplay(this.degreeDomain, 15)); - printable.put("degreeType", SummaryHelper.formatForDisplay(this.degreeType, 25)); + printable.put("degreeDomain", SummaryHelper.formatForDisplay(this.degreeDomain, null)); + printable.put("degreeType", SummaryHelper.formatForDisplay(this.degreeType, null)); printable.put("endMonth", SummaryHelper.formatForDisplay(this.endMonth, null)); printable.put("endYear", SummaryHelper.formatForDisplay(this.endYear, null)); - printable.put("school", SummaryHelper.formatForDisplay(this.school, 25)); + printable.put("school", SummaryHelper.formatForDisplay(this.school, null)); printable.put("startMonth", SummaryHelper.formatForDisplay(this.startMonth, null)); printable.put("startYear", SummaryHelper.formatForDisplay(this.startYear, null)); return printable; diff --git a/src/main/java/com/mindee/product/resume/ResumeV1Language.java b/src/main/java/com/mindee/product/resume/ResumeV1Language.java index 90d70163a..6baed5e3e 100644 --- a/src/main/java/com/mindee/product/resume/ResumeV1Language.java +++ b/src/main/java/com/mindee/product/resume/ResumeV1Language.java @@ -34,11 +34,19 @@ public boolean isEmpty() { ); } + private Map tablePrintableValues() { + Map printable = new HashMap<>(); + + printable.put("language", SummaryHelper.formatForDisplay(this.language, null)); + printable.put("level", SummaryHelper.formatForDisplay(this.level, 20)); + return printable; + } + /** * Output the line in a format suitable for inclusion in an rST table. */ public String toTableLine() { - Map printable = this.printableValues(); + Map printable = this.tablePrintableValues(); return String.format("| %-8s ", printable.get("language")) + String.format("| %-20s |", printable.get("level")); } @@ -54,7 +62,7 @@ private Map printableValues() { Map printable = new HashMap<>(); printable.put("language", SummaryHelper.formatForDisplay(this.language, null)); - printable.put("level", SummaryHelper.formatForDisplay(this.level, 20)); + printable.put("level", SummaryHelper.formatForDisplay(this.level, null)); return printable; } } diff --git a/src/main/java/com/mindee/product/resume/ResumeV1ProfessionalExperience.java b/src/main/java/com/mindee/product/resume/ResumeV1ProfessionalExperience.java index 0f50eebaa..fca723c2a 100644 --- a/src/main/java/com/mindee/product/resume/ResumeV1ProfessionalExperience.java +++ b/src/main/java/com/mindee/product/resume/ResumeV1ProfessionalExperience.java @@ -70,11 +70,25 @@ public boolean isEmpty() { ); } + private Map tablePrintableValues() { + Map printable = new HashMap<>(); + + printable.put("contractType", SummaryHelper.formatForDisplay(this.contractType, 15)); + printable.put("department", SummaryHelper.formatForDisplay(this.department, 10)); + printable.put("employer", SummaryHelper.formatForDisplay(this.employer, 25)); + printable.put("endMonth", SummaryHelper.formatForDisplay(this.endMonth, null)); + printable.put("endYear", SummaryHelper.formatForDisplay(this.endYear, null)); + printable.put("role", SummaryHelper.formatForDisplay(this.role, 20)); + printable.put("startMonth", SummaryHelper.formatForDisplay(this.startMonth, null)); + printable.put("startYear", SummaryHelper.formatForDisplay(this.startYear, null)); + return printable; + } + /** * Output the line in a format suitable for inclusion in an rST table. */ public String toTableLine() { - Map printable = this.printableValues(); + Map printable = this.tablePrintableValues(); return String.format("| %-15s ", printable.get("contractType")) + String.format("| %-10s ", printable.get("department")) + String.format("| %-25s ", printable.get("employer")) @@ -101,12 +115,12 @@ public String toString() { private Map printableValues() { Map printable = new HashMap<>(); - printable.put("contractType", SummaryHelper.formatForDisplay(this.contractType, 15)); - printable.put("department", SummaryHelper.formatForDisplay(this.department, 10)); - printable.put("employer", SummaryHelper.formatForDisplay(this.employer, 25)); + printable.put("contractType", SummaryHelper.formatForDisplay(this.contractType, null)); + printable.put("department", SummaryHelper.formatForDisplay(this.department, null)); + printable.put("employer", SummaryHelper.formatForDisplay(this.employer, null)); printable.put("endMonth", SummaryHelper.formatForDisplay(this.endMonth, null)); printable.put("endYear", SummaryHelper.formatForDisplay(this.endYear, null)); - printable.put("role", SummaryHelper.formatForDisplay(this.role, 20)); + printable.put("role", SummaryHelper.formatForDisplay(this.role, null)); printable.put("startMonth", SummaryHelper.formatForDisplay(this.startMonth, null)); printable.put("startYear", SummaryHelper.formatForDisplay(this.startYear, null)); return printable; diff --git a/src/main/java/com/mindee/product/resume/ResumeV1SocialNetworksUrl.java b/src/main/java/com/mindee/product/resume/ResumeV1SocialNetworksUrl.java index f5330f9e9..0854131e9 100644 --- a/src/main/java/com/mindee/product/resume/ResumeV1SocialNetworksUrl.java +++ b/src/main/java/com/mindee/product/resume/ResumeV1SocialNetworksUrl.java @@ -34,11 +34,19 @@ public boolean isEmpty() { ); } + private Map tablePrintableValues() { + Map printable = new HashMap<>(); + + printable.put("name", SummaryHelper.formatForDisplay(this.name, 20)); + printable.put("url", SummaryHelper.formatForDisplay(this.url, 50)); + return printable; + } + /** * Output the line in a format suitable for inclusion in an rST table. */ public String toTableLine() { - Map printable = this.printableValues(); + Map printable = this.tablePrintableValues(); return String.format("| %-20s ", printable.get("name")) + String.format("| %-50s |", printable.get("url")); } @@ -53,8 +61,8 @@ public String toString() { private Map printableValues() { Map printable = new HashMap<>(); - printable.put("name", SummaryHelper.formatForDisplay(this.name, 20)); - printable.put("url", SummaryHelper.formatForDisplay(this.url, 50)); + printable.put("name", SummaryHelper.formatForDisplay(this.name, null)); + printable.put("url", SummaryHelper.formatForDisplay(this.url, null)); return printable; } } diff --git a/src/main/java/com/mindee/product/us/healthcarecard/HealthcareCardV1Copay.java b/src/main/java/com/mindee/product/us/healthcarecard/HealthcareCardV1Copay.java index 54c6b8b14..19dcaa9cc 100644 --- a/src/main/java/com/mindee/product/us/healthcarecard/HealthcareCardV1Copay.java +++ b/src/main/java/com/mindee/product/us/healthcarecard/HealthcareCardV1Copay.java @@ -34,11 +34,22 @@ public boolean isEmpty() { ); } + private Map tablePrintableValues() { + Map printable = new HashMap<>(); + + printable.put( + "serviceFees", + SummaryHelper.formatAmount(this.serviceFees) + ); + printable.put("serviceName", SummaryHelper.formatForDisplay(this.serviceName, null)); + return printable; + } + /** * Output the line in a format suitable for inclusion in an rST table. */ public String toTableLine() { - Map printable = this.printableValues(); + Map printable = this.tablePrintableValues(); return String.format("| %-12s ", printable.get("serviceFees")) + String.format("| %-12s |", printable.get("serviceName")); } diff --git a/src/main/java/com/mindee/product/us/usmail/UsMailV2RecipientAddress.java b/src/main/java/com/mindee/product/us/usmail/UsMailV2RecipientAddress.java index 8232af138..2597f6380 100644 --- a/src/main/java/com/mindee/product/us/usmail/UsMailV2RecipientAddress.java +++ b/src/main/java/com/mindee/product/us/usmail/UsMailV2RecipientAddress.java @@ -64,11 +64,24 @@ public boolean isEmpty() { ); } + private Map tablePrintableValues() { + Map printable = new HashMap<>(); + + printable.put("city", SummaryHelper.formatForDisplay(this.city, 15)); + printable.put("complete", SummaryHelper.formatForDisplay(this.complete, 35)); + printable.put("isAddressChange", SummaryHelper.formatForDisplay(this.isAddressChange, null)); + printable.put("postalCode", SummaryHelper.formatForDisplay(this.postalCode, null)); + printable.put("privateMailboxNumber", SummaryHelper.formatForDisplay(this.privateMailboxNumber, null)); + printable.put("state", SummaryHelper.formatForDisplay(this.state, null)); + printable.put("street", SummaryHelper.formatForDisplay(this.street, 25)); + return printable; + } + /** * Output the line in a format suitable for inclusion in an rST table. */ public String toTableLine() { - Map printable = this.printableValues(); + Map printable = this.tablePrintableValues(); return String.format("| %-15s ", printable.get("city")) + String.format("| %-35s ", printable.get("complete")) + String.format("| %-17s ", printable.get("isAddressChange")) @@ -93,13 +106,13 @@ public String toString() { private Map printableValues() { Map printable = new HashMap<>(); - printable.put("city", SummaryHelper.formatForDisplay(this.city, 15)); - printable.put("complete", SummaryHelper.formatForDisplay(this.complete, 35)); + printable.put("city", SummaryHelper.formatForDisplay(this.city, null)); + printable.put("complete", SummaryHelper.formatForDisplay(this.complete, null)); printable.put("isAddressChange", SummaryHelper.formatForDisplay(this.isAddressChange, null)); printable.put("postalCode", SummaryHelper.formatForDisplay(this.postalCode, null)); printable.put("privateMailboxNumber", SummaryHelper.formatForDisplay(this.privateMailboxNumber, null)); printable.put("state", SummaryHelper.formatForDisplay(this.state, null)); - printable.put("street", SummaryHelper.formatForDisplay(this.street, 25)); + printable.put("street", SummaryHelper.formatForDisplay(this.street, null)); return printable; } } diff --git a/src/main/java/com/mindee/product/us/usmail/UsMailV2SenderAddress.java b/src/main/java/com/mindee/product/us/usmail/UsMailV2SenderAddress.java index 32bfd52ea..5bb6411c7 100644 --- a/src/main/java/com/mindee/product/us/usmail/UsMailV2SenderAddress.java +++ b/src/main/java/com/mindee/product/us/usmail/UsMailV2SenderAddress.java @@ -76,11 +76,11 @@ public String toString() { private Map printableValues() { Map printable = new HashMap<>(); - printable.put("city", SummaryHelper.formatForDisplay(this.city, 15)); - printable.put("complete", SummaryHelper.formatForDisplay(this.complete, 35)); + printable.put("city", SummaryHelper.formatForDisplay(this.city, null)); + printable.put("complete", SummaryHelper.formatForDisplay(this.complete, null)); printable.put("postalCode", SummaryHelper.formatForDisplay(this.postalCode, null)); printable.put("state", SummaryHelper.formatForDisplay(this.state, null)); - printable.put("street", SummaryHelper.formatForDisplay(this.street, 25)); + printable.put("street", SummaryHelper.formatForDisplay(this.street, null)); return printable; } } diff --git a/src/test/java/com/mindee/product/billoflading/BillOfLadingV1Test.java b/src/test/java/com/mindee/product/billoflading/BillOfLadingV1Test.java new file mode 100644 index 000000000..44f4070b3 --- /dev/null +++ b/src/test/java/com/mindee/product/billoflading/BillOfLadingV1Test.java @@ -0,0 +1,71 @@ +package com.mindee.product.billoflading; + +import com.fasterxml.jackson.databind.JavaType; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.mindee.parsing.common.Document; +import com.mindee.parsing.common.PredictResponse; +import com.mindee.parsing.standard.ClassificationField; +import com.mindee.product.ProductTestHelper; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import java.io.File; +import java.io.IOException; + +/** + * Unit tests for BillOfLadingV1. + */ +public class BillOfLadingV1Test { + + protected PredictResponse getPrediction(String name) throws IOException { + ObjectMapper objectMapper = new ObjectMapper(); + objectMapper.findAndRegisterModules(); + + JavaType type = objectMapper.getTypeFactory().constructParametricType( + PredictResponse.class, + BillOfLadingV1.class + ); + return objectMapper.readValue( + new File("src/test/resources/products/bill_of_lading/response_v1/" + name + ".json"), + type + ); + } + + @Test + void whenEmptyDeserialized_mustHaveValidProperties() throws IOException { + PredictResponse response = getPrediction("empty"); + BillOfLadingV1Document docPrediction = response.getDocument().getInference().getPrediction(); + Assertions.assertNull(docPrediction.getBillOfLadingNumber().getValue()); + Assertions.assertNull(docPrediction.getShipper().getAddress()); + Assertions.assertNull(docPrediction.getShipper().getEmail()); + Assertions.assertNull(docPrediction.getShipper().getName()); + Assertions.assertNull(docPrediction.getShipper().getPhone()); + Assertions.assertNull(docPrediction.getConsignee().getAddress()); + Assertions.assertNull(docPrediction.getConsignee().getEmail()); + Assertions.assertNull(docPrediction.getConsignee().getName()); + Assertions.assertNull(docPrediction.getConsignee().getPhone()); + Assertions.assertNull(docPrediction.getNotifyParty().getAddress()); + Assertions.assertNull(docPrediction.getNotifyParty().getEmail()); + Assertions.assertNull(docPrediction.getNotifyParty().getName()); + Assertions.assertNull(docPrediction.getNotifyParty().getPhone()); + Assertions.assertNull(docPrediction.getCarrier().getName()); + Assertions.assertNull(docPrediction.getCarrier().getProfessionalNumber()); + Assertions.assertNull(docPrediction.getCarrier().getScac()); + Assertions.assertTrue(docPrediction.getCarrierItems().isEmpty()); + Assertions.assertNull(docPrediction.getPortOfLoading().getValue()); + Assertions.assertNull(docPrediction.getPortOfDischarge().getValue()); + Assertions.assertNull(docPrediction.getPlaceOfDelivery().getValue()); + Assertions.assertNull(docPrediction.getDateOfIssue().getValue()); + Assertions.assertNull(docPrediction.getDepartureDate().getValue()); + } + + @Test + void whenCompleteDeserialized_mustHaveValidDocumentSummary() throws IOException { + PredictResponse response = getPrediction("complete"); + Document doc = response.getDocument(); + ProductTestHelper.assertStringEqualsFile( + doc.toString(), + "src/test/resources/products/bill_of_lading/response_v1/summary_full.rst" + ); + } + +} diff --git a/src/test/java/com/mindee/product/fr/energybill/EnergyBillV1Test.java b/src/test/java/com/mindee/product/fr/energybill/EnergyBillV1Test.java new file mode 100644 index 000000000..4ab08dc63 --- /dev/null +++ b/src/test/java/com/mindee/product/fr/energybill/EnergyBillV1Test.java @@ -0,0 +1,67 @@ +package com.mindee.product.fr.energybill; + +import com.fasterxml.jackson.databind.JavaType; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.mindee.parsing.common.Document; +import com.mindee.parsing.common.PredictResponse; +import com.mindee.parsing.standard.ClassificationField; +import com.mindee.product.ProductTestHelper; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import java.io.File; +import java.io.IOException; + +/** + * Unit tests for EnergyBillV1. + */ +public class EnergyBillV1Test { + + protected PredictResponse getPrediction(String name) throws IOException { + ObjectMapper objectMapper = new ObjectMapper(); + objectMapper.findAndRegisterModules(); + + JavaType type = objectMapper.getTypeFactory().constructParametricType( + PredictResponse.class, + EnergyBillV1.class + ); + return objectMapper.readValue( + new File("src/test/resources/products/energy_bill_fra/response_v1/" + name + ".json"), + type + ); + } + + @Test + void whenEmptyDeserialized_mustHaveValidProperties() throws IOException { + PredictResponse response = getPrediction("empty"); + EnergyBillV1Document docPrediction = response.getDocument().getInference().getPrediction(); + Assertions.assertNull(docPrediction.getInvoiceNumber().getValue()); + Assertions.assertNull(docPrediction.getContractId().getValue()); + Assertions.assertNull(docPrediction.getDeliveryPoint().getValue()); + Assertions.assertNull(docPrediction.getInvoiceDate().getValue()); + Assertions.assertNull(docPrediction.getDueDate().getValue()); + Assertions.assertNull(docPrediction.getTotalBeforeTaxes().getValue()); + Assertions.assertNull(docPrediction.getTotalTaxes().getValue()); + Assertions.assertNull(docPrediction.getTotalAmount().getValue()); + Assertions.assertNull(docPrediction.getEnergySupplier().getAddress()); + Assertions.assertNull(docPrediction.getEnergySupplier().getName()); + Assertions.assertNull(docPrediction.getEnergyConsumer().getAddress()); + Assertions.assertNull(docPrediction.getEnergyConsumer().getName()); + Assertions.assertTrue(docPrediction.getSubscription().isEmpty()); + Assertions.assertTrue(docPrediction.getEnergyUsage().isEmpty()); + Assertions.assertTrue(docPrediction.getTaxesAndContributions().isEmpty()); + Assertions.assertNull(docPrediction.getMeterDetails().getMeterNumber()); + Assertions.assertNull(docPrediction.getMeterDetails().getMeterType()); + Assertions.assertNull(docPrediction.getMeterDetails().getUnit()); + } + + @Test + void whenCompleteDeserialized_mustHaveValidDocumentSummary() throws IOException { + PredictResponse response = getPrediction("complete"); + Document doc = response.getDocument(); + ProductTestHelper.assertStringEqualsFile( + doc.toString(), + "src/test/resources/products/energy_bill_fra/response_v1/summary_full.rst" + ); + } + +} diff --git a/src/test/java/com/mindee/product/fr/payslip/PayslipV2Test.java b/src/test/java/com/mindee/product/fr/payslip/PayslipV2Test.java new file mode 100644 index 000000000..c751eb46d --- /dev/null +++ b/src/test/java/com/mindee/product/fr/payslip/PayslipV2Test.java @@ -0,0 +1,91 @@ +package com.mindee.product.fr.payslip; + +import com.fasterxml.jackson.databind.JavaType; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.mindee.parsing.common.Document; +import com.mindee.parsing.common.PredictResponse; +import com.mindee.parsing.standard.ClassificationField; +import com.mindee.product.ProductTestHelper; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import java.io.File; +import java.io.IOException; + +/** + * Unit tests for PayslipV2. + */ +public class PayslipV2Test { + + protected PredictResponse getPrediction(String name) throws IOException { + ObjectMapper objectMapper = new ObjectMapper(); + objectMapper.findAndRegisterModules(); + + JavaType type = objectMapper.getTypeFactory().constructParametricType( + PredictResponse.class, + PayslipV2.class + ); + return objectMapper.readValue( + new File("src/test/resources/products/payslip_fra/response_v2/" + name + ".json"), + type + ); + } + + @Test + void whenEmptyDeserialized_mustHaveValidProperties() throws IOException { + PredictResponse response = getPrediction("empty"); + PayslipV2Document docPrediction = response.getDocument().getInference().getPrediction(); + Assertions.assertNull(docPrediction.getEmployee().getAddress()); + Assertions.assertNull(docPrediction.getEmployee().getDateOfBirth()); + Assertions.assertNull(docPrediction.getEmployee().getFirstName()); + Assertions.assertNull(docPrediction.getEmployee().getLastName()); + Assertions.assertNull(docPrediction.getEmployee().getPhoneNumber()); + Assertions.assertNull(docPrediction.getEmployee().getRegistrationNumber()); + Assertions.assertNull(docPrediction.getEmployee().getSocialSecurityNumber()); + Assertions.assertNull(docPrediction.getEmployer().getAddress()); + Assertions.assertNull(docPrediction.getEmployer().getCompanyId()); + Assertions.assertNull(docPrediction.getEmployer().getCompanySite()); + Assertions.assertNull(docPrediction.getEmployer().getNafCode()); + Assertions.assertNull(docPrediction.getEmployer().getName()); + Assertions.assertNull(docPrediction.getEmployer().getPhoneNumber()); + Assertions.assertNull(docPrediction.getEmployer().getUrssafNumber()); + Assertions.assertNull(docPrediction.getBankAccountDetails().getBankName()); + Assertions.assertNull(docPrediction.getBankAccountDetails().getIban()); + Assertions.assertNull(docPrediction.getBankAccountDetails().getSwift()); + Assertions.assertNull(docPrediction.getEmployment().getCategory()); + Assertions.assertNull(docPrediction.getEmployment().getCoefficient()); + Assertions.assertNull(docPrediction.getEmployment().getCollectiveAgreement()); + Assertions.assertNull(docPrediction.getEmployment().getJobTitle()); + Assertions.assertNull(docPrediction.getEmployment().getPositionLevel()); + Assertions.assertNull(docPrediction.getEmployment().getStartDate()); + Assertions.assertTrue(docPrediction.getSalaryDetails().isEmpty()); + Assertions.assertNull(docPrediction.getPayDetail().getGrossSalary()); + Assertions.assertNull(docPrediction.getPayDetail().getGrossSalaryYtd()); + Assertions.assertNull(docPrediction.getPayDetail().getIncomeTaxRate()); + Assertions.assertNull(docPrediction.getPayDetail().getIncomeTaxWithheld()); + Assertions.assertNull(docPrediction.getPayDetail().getNetPaid()); + Assertions.assertNull(docPrediction.getPayDetail().getNetPaidBeforeTax()); + Assertions.assertNull(docPrediction.getPayDetail().getNetTaxable()); + Assertions.assertNull(docPrediction.getPayDetail().getNetTaxableYtd()); + Assertions.assertNull(docPrediction.getPayDetail().getTotalCostEmployer()); + Assertions.assertNull(docPrediction.getPayDetail().getTotalTaxesAndDeductions()); + Assertions.assertNull(docPrediction.getPto().getAccruedThisPeriod()); + Assertions.assertNull(docPrediction.getPto().getBalanceEndOfPeriod()); + Assertions.assertNull(docPrediction.getPto().getUsedThisPeriod()); + Assertions.assertNull(docPrediction.getPayPeriod().getEndDate()); + Assertions.assertNull(docPrediction.getPayPeriod().getMonth()); + Assertions.assertNull(docPrediction.getPayPeriod().getPaymentDate()); + Assertions.assertNull(docPrediction.getPayPeriod().getStartDate()); + Assertions.assertNull(docPrediction.getPayPeriod().getYear()); + } + + @Test + void whenCompleteDeserialized_mustHaveValidDocumentSummary() throws IOException { + PredictResponse response = getPrediction("complete"); + Document doc = response.getDocument(); + ProductTestHelper.assertStringEqualsFile( + doc.toString(), + "src/test/resources/products/payslip_fra/response_v2/summary_full.rst" + ); + } + +} diff --git a/src/test/java/com/mindee/product/nutritionfactslabel/NutritionFactsLabelV1Test.java b/src/test/java/com/mindee/product/nutritionfactslabel/NutritionFactsLabelV1Test.java new file mode 100644 index 000000000..784d332f9 --- /dev/null +++ b/src/test/java/com/mindee/product/nutritionfactslabel/NutritionFactsLabelV1Test.java @@ -0,0 +1,87 @@ +package com.mindee.product.nutritionfactslabel; + +import com.fasterxml.jackson.databind.JavaType; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.mindee.parsing.common.Document; +import com.mindee.parsing.common.PredictResponse; +import com.mindee.parsing.standard.ClassificationField; +import com.mindee.product.ProductTestHelper; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import java.io.File; +import java.io.IOException; + +/** + * Unit tests for NutritionFactsLabelV1. + */ +public class NutritionFactsLabelV1Test { + + protected PredictResponse getPrediction(String name) throws IOException { + ObjectMapper objectMapper = new ObjectMapper(); + objectMapper.findAndRegisterModules(); + + JavaType type = objectMapper.getTypeFactory().constructParametricType( + PredictResponse.class, + NutritionFactsLabelV1.class + ); + return objectMapper.readValue( + new File("src/test/resources/products/nutrition_facts/response_v1/" + name + ".json"), + type + ); + } + + @Test + void whenEmptyDeserialized_mustHaveValidProperties() throws IOException { + PredictResponse response = getPrediction("empty"); + NutritionFactsLabelV1Document docPrediction = response.getDocument().getInference().getPrediction(); + Assertions.assertNull(docPrediction.getServingPerBox().getValue()); + Assertions.assertNull(docPrediction.getServingSize().getAmount()); + Assertions.assertNull(docPrediction.getServingSize().getUnit()); + Assertions.assertNull(docPrediction.getCalories().getDailyValue()); + Assertions.assertNull(docPrediction.getCalories().getPer100G()); + Assertions.assertNull(docPrediction.getCalories().getPerServing()); + Assertions.assertNull(docPrediction.getTotalFat().getDailyValue()); + Assertions.assertNull(docPrediction.getTotalFat().getPer100G()); + Assertions.assertNull(docPrediction.getTotalFat().getPerServing()); + Assertions.assertNull(docPrediction.getSaturatedFat().getDailyValue()); + Assertions.assertNull(docPrediction.getSaturatedFat().getPer100G()); + Assertions.assertNull(docPrediction.getSaturatedFat().getPerServing()); + Assertions.assertNull(docPrediction.getTransFat().getDailyValue()); + Assertions.assertNull(docPrediction.getTransFat().getPer100G()); + Assertions.assertNull(docPrediction.getTransFat().getPerServing()); + Assertions.assertNull(docPrediction.getCholesterol().getDailyValue()); + Assertions.assertNull(docPrediction.getCholesterol().getPer100G()); + Assertions.assertNull(docPrediction.getCholesterol().getPerServing()); + Assertions.assertNull(docPrediction.getTotalCarbohydrate().getDailyValue()); + Assertions.assertNull(docPrediction.getTotalCarbohydrate().getPer100G()); + Assertions.assertNull(docPrediction.getTotalCarbohydrate().getPerServing()); + Assertions.assertNull(docPrediction.getDietaryFiber().getDailyValue()); + Assertions.assertNull(docPrediction.getDietaryFiber().getPer100G()); + Assertions.assertNull(docPrediction.getDietaryFiber().getPerServing()); + Assertions.assertNull(docPrediction.getTotalSugars().getDailyValue()); + Assertions.assertNull(docPrediction.getTotalSugars().getPer100G()); + Assertions.assertNull(docPrediction.getTotalSugars().getPerServing()); + Assertions.assertNull(docPrediction.getAddedSugars().getDailyValue()); + Assertions.assertNull(docPrediction.getAddedSugars().getPer100G()); + Assertions.assertNull(docPrediction.getAddedSugars().getPerServing()); + Assertions.assertNull(docPrediction.getProtein().getDailyValue()); + Assertions.assertNull(docPrediction.getProtein().getPer100G()); + Assertions.assertNull(docPrediction.getProtein().getPerServing()); + Assertions.assertNull(docPrediction.getSodium().getDailyValue()); + Assertions.assertNull(docPrediction.getSodium().getPer100G()); + Assertions.assertNull(docPrediction.getSodium().getPerServing()); + Assertions.assertNull(docPrediction.getSodium().getUnit()); + Assertions.assertTrue(docPrediction.getNutrients().isEmpty()); + } + + @Test + void whenCompleteDeserialized_mustHaveValidDocumentSummary() throws IOException { + PredictResponse response = getPrediction("complete"); + Document doc = response.getDocument(); + ProductTestHelper.assertStringEqualsFile( + doc.toString(), + "src/test/resources/products/nutrition_facts/response_v1/summary_full.rst" + ); + } + +} diff --git a/src/test/resources b/src/test/resources index 4a55dd2a5..f737d62bb 160000 --- a/src/test/resources +++ b/src/test/resources @@ -1 +1 @@ -Subproject commit 4a55dd2a5c3c909d4cd5069a5faface547c20686 +Subproject commit f737d62bb2fb6b064e324f31f25c75767793aa1a