Compare commits

...

3 commits

Author SHA1 Message Date
22064c8c7c More extra data 2026-06-05 10:02:37 +02:00
625b023733 Use 1L as serial version to track data format easily 2025-11-28 12:03:39 +01:00
cc905ee6f2 Basic support for ExtraData 2025-11-28 11:49:52 +01:00
61 changed files with 1861 additions and 181 deletions

View file

@ -5,7 +5,7 @@ package org.pasteque.common.datasource;
*/ */
public class AssociationInconsistencyException extends Exception public class AssociationInconsistencyException extends Exception
{ {
private static final long serialVersionUID = -979786104345156783L; private static final long serialVersionUID = 1L;
/** {@see getFromField()} */ /** {@see getFromField()} */
private final String fromField; private final String fromField;

View file

@ -16,7 +16,7 @@ import org.pasteque.coreutil.datatransfer.parser.Reader;
*/ */
public class APIVersionDTO implements DTOInterface, Serializable public class APIVersionDTO implements DTOInterface, Serializable
{ {
private static final long serialVersionUID = 4654741357430549138L; private static final long serialVersionUID = 1L;
/** {@see getLevel()} */ /** {@see getLevel()} */
private final int level; private final int level;

View file

@ -10,7 +10,7 @@ import org.pasteque.coreutil.datatransfer.parser.Reader;
*/ */
public class CategoryDTO extends CommonDTO implements Serializable public class CategoryDTO extends CommonDTO implements Serializable
{ {
private static final long serialVersionUID = 8211717550217795453L; private static final long serialVersionUID = 1L;
/** {@see getParent} */ /** {@see getParent} */
private final Integer parent; private final Integer parent;

View file

@ -10,7 +10,7 @@ import org.pasteque.coreutil.ImmutableList;
*/ */
public class CompositionDTO extends ProductDTO implements Serializable public class CompositionDTO extends ProductDTO implements Serializable
{ {
private static final long serialVersionUID = -3223110713928387147L; private static final long serialVersionUID = 1L;
/** Always true */ /** Always true */
protected final boolean composition = true; protected final boolean composition = true;
@ -92,7 +92,7 @@ public class CompositionDTO extends ProductDTO implements Serializable
*/ */
public class CompositionGroupDTO implements Serializable public class CompositionGroupDTO implements Serializable
{ {
private static final long serialVersionUID = -5237752185922817170L; private static final long serialVersionUID = 1L;
/** {@see getLabel()} */ /** {@see getLabel()} */
private final String label; private final String label;
@ -144,7 +144,7 @@ public class CompositionDTO extends ProductDTO implements Serializable
*/ */
public class CompositionProductDTO implements Serializable public class CompositionProductDTO implements Serializable
{ {
private static final long serialVersionUID = 4024627602322411550L; private static final long serialVersionUID = 1L;
/** {@see getProduct()} */ /** {@see getProduct()} */
private final int product; private final int product;

View file

@ -11,7 +11,7 @@ import org.pasteque.coreutil.datatransfer.parser.Reader;
*/ */
public class CurrencyDTO extends CommonDTO implements Serializable public class CurrencyDTO extends CommonDTO implements Serializable
{ {
private static final long serialVersionUID = -6259735426241774167L; private static final long serialVersionUID = 1L;
/** {@see getSymbol()} */ /** {@see getSymbol()} */
private final String symbol; private final String symbol;

View file

@ -16,7 +16,7 @@ import org.pasteque.coreutil.datatransfer.parser.Reader;
*/ */
public class CustomerDTO extends CommonDTO implements Serializable public class CustomerDTO extends CommonDTO implements Serializable
{ {
private static final long serialVersionUID = 2904701878615495822L; private static final long serialVersionUID = 1L;
/** {@see getCard()} */ /** {@see getCard()} */
private final String card; private final String card;

View file

@ -14,7 +14,7 @@ import org.pasteque.coreutil.datatransfer.parser.Reader;
*/ */
public class DiscountProfileDTO extends CommonDTO implements Serializable public class DiscountProfileDTO extends CommonDTO implements Serializable
{ {
private static final long serialVersionUID = -2505636588019239236L; private static final long serialVersionUID = 1L;
/** See {@link getDiscountRate()}. */ /** See {@link getDiscountRate()}. */
private final double discountRate; private final double discountRate;

View file

@ -12,7 +12,7 @@ import org.pasteque.coreutil.datatransfer.parser.Reader;
*/ */
public class FloorDTO extends CommonDTO implements Serializable public class FloorDTO extends CommonDTO implements Serializable
{ {
private static final long serialVersionUID = -4474106026709243994L; private static final long serialVersionUID = 1L;
/** {@see getPlaces()} */ /** {@see getPlaces()} */
private final ImmutableList<PlaceDTO> places; private final ImmutableList<PlaceDTO> places;
@ -71,7 +71,7 @@ public class FloorDTO extends CommonDTO implements Serializable
*/ */
public class PlaceDTO implements Serializable public class PlaceDTO implements Serializable
{ {
private static final long serialVersionUID = 8129968704161611106L; private static final long serialVersionUID = 1L;
/** {@see getLabel()} */ /** {@see getLabel()} */
private final String label; private final String label;

View file

@ -20,7 +20,7 @@ import org.pasteque.coreutil.datatransfer.parser.Reader;
*/ */
public class ImageDTO implements DTOInterface, Serializable public class ImageDTO implements DTOInterface, Serializable
{ {
private static final long serialVersionUID = -7807272808383007554L; private static final long serialVersionUID = 1L;
/** {@see getModel()} */ /** {@see getModel()} */
private final String model; private final String model;

View file

@ -16,7 +16,7 @@ import org.pasteque.coreutil.datatransfer.parser.Reader;
*/ */
public class OptionDTO implements DTOInterface, Serializable public class OptionDTO implements DTOInterface, Serializable
{ {
private static final long serialVersionUID = 8951727299457218490L; private static final long serialVersionUID = 1L;
/** {@see getName()} */ /** {@see getName()} */
private final String name; private final String name;

View file

@ -15,7 +15,7 @@ import org.pasteque.coreutil.datatransfer.parser.Reader;
*/ */
public class OrderDTO implements DTOInterface, Serializable public class OrderDTO implements DTOInterface, Serializable
{ {
private static final long serialVersionUID = -3898628758749878634L; private static final long serialVersionUID = 1L;
/** See {@link getId()}. */ /** See {@link getId()}. */
private final String id; private final String id;
@ -194,7 +194,7 @@ public class OrderDTO implements DTOInterface, Serializable
*/ */
public class OrderLineDTO implements Serializable public class OrderLineDTO implements Serializable
{ {
private static final long serialVersionUID = 8802466032089572015L; private static final long serialVersionUID = 1L;
/** See {@link getDispOrder()}. */ /** See {@link getDispOrder()}. */
private final int dispOrder; private final int dispOrder;

View file

@ -17,7 +17,7 @@ import org.pasteque.coreutil.ImmutableList;
*/ */
public class PaymentModeDTO extends CommonDTO implements Serializable public class PaymentModeDTO extends CommonDTO implements Serializable
{ {
private static final long serialVersionUID = 5324960228614648256L; private static final long serialVersionUID = 1L;
/** {@see getBackLabel()} */ /** {@see getBackLabel()} */
private final String backLabel; private final String backLabel;
@ -139,7 +139,7 @@ public class PaymentModeDTO extends CommonDTO implements Serializable
*/ */
public class PaymentModeValueDTO implements Serializable public class PaymentModeValueDTO implements Serializable
{ {
private static final long serialVersionUID = 5503522521532600750L; private static final long serialVersionUID = 1L;
/** {@see getValue()} */ /** {@see getValue()} */
private final double value; private final double value;
@ -195,7 +195,7 @@ public class PaymentModeDTO extends CommonDTO implements Serializable
*/ */
public class PaymentModeReturnDTO implements Serializable public class PaymentModeReturnDTO implements Serializable
{ {
private static final long serialVersionUID = -5076562956398887860L; private static final long serialVersionUID = 1L;
/** {@see getMinAmount()} */ /** {@see getMinAmount()} */
private double minAmount; private double minAmount;

View file

@ -9,7 +9,7 @@ import org.pasteque.coreutil.datatransfer.parser.Reader;
*/ */
public class ProductDTO extends CommonDTO implements Serializable public class ProductDTO extends CommonDTO implements Serializable
{ {
private static final long serialVersionUID = -6083885399091129846L; private static final long serialVersionUID = 1L;
/** {@see getBarcode()} */ /** {@see getBarcode()} */
protected final String barcode; protected final String barcode;

View file

@ -22,7 +22,7 @@ import org.pasteque.coreutil.datatransfer.parser.Reader;
*/ */
public class ResourceDTO implements DTOInterface, Serializable public class ResourceDTO implements DTOInterface, Serializable
{ {
private static final long serialVersionUID = -7746795788087018857L; private static final long serialVersionUID = 1L;
/** {@see getModel()} */ /** {@see getModel()} */
private final String label; private final String label;

View file

@ -14,7 +14,7 @@ import org.pasteque.coreutil.ImmutableList;
*/ */
public class RoleDTO extends CommonDTO implements Serializable public class RoleDTO extends CommonDTO implements Serializable
{ {
private static final long serialVersionUID = 1835635017595972352L; private static final long serialVersionUID = 1L;
/** {@see getPermissions()} */ /** {@see getPermissions()} */
private final ImmutableList<String> permissions; private final ImmutableList<String> permissions;

View file

@ -12,7 +12,7 @@ import org.pasteque.coreutil.ImmutableList;
*/ */
public class TariffAreaDTO extends CommonDTO implements Serializable public class TariffAreaDTO extends CommonDTO implements Serializable
{ {
private static final long serialVersionUID = -2639559615366931293L; private static final long serialVersionUID = 1L;
/** {@see getSymbol()} */ /** {@see getSymbol()} */
private final ImmutableList<TariffAreaPriceDTO> prices; private final ImmutableList<TariffAreaPriceDTO> prices;
@ -70,7 +70,7 @@ public class TariffAreaDTO extends CommonDTO implements Serializable
*/ */
public class TariffAreaPriceDTO implements Serializable public class TariffAreaPriceDTO implements Serializable
{ {
private static final long serialVersionUID = 3384262202026051762L; private static final long serialVersionUID = 1L;
/** See {@link getProduct()}. */ /** See {@link getProduct()}. */
private int product; private int product;

View file

@ -14,7 +14,7 @@ import org.pasteque.coreutil.datatransfer.parser.Reader;
*/ */
public class TaxDTO extends CommonDTO implements Serializable public class TaxDTO extends CommonDTO implements Serializable
{ {
private static final long serialVersionUID = 8232927221600250003L; private static final long serialVersionUID = 1L;
/** See {@link getTaxRate()}. */ /** See {@link getTaxRate()}. */
private final double taxRate; private final double taxRate;

View file

@ -11,7 +11,7 @@ import org.pasteque.coreutil.datatransfer.parser.Reader;
*/ */
public class UserDTO extends CommonDTO implements Serializable public class UserDTO extends CommonDTO implements Serializable
{ {
private static final long serialVersionUID = 5162729826784894378L; private static final long serialVersionUID = 1L;
/** {@see getRole()} */ /** {@see getRole()} */
private final int role; private final int role;

View file

@ -15,7 +15,7 @@ import java.util.function.Consumer;
*/ */
public final class ImmutableList<T> implements Iterable<T>, Serializable public final class ImmutableList<T> implements Iterable<T>, Serializable
{ {
private static final long serialVersionUID = 4982637247874555568L; private static final long serialVersionUID = 1L;
/** See {@link get(int)} or {@link iterator()}. */ /** See {@link get(int)} or {@link iterator()}. */
private List<T> content; private List<T> content;

View file

@ -5,7 +5,7 @@ package org.pasteque.coreutil;
*/ */
public class ParseException extends Exception public class ParseException extends Exception
{ {
private static final long serialVersionUID = 3552338953002779225L; private static final long serialVersionUID = 1L;
/** /**
* Create a generic exception with only a message. * Create a generic exception with only a message.

View file

@ -8,6 +8,7 @@ import org.pasteque.coreutil.datatransfer.integrity.IntegrityExceptions;
import org.pasteque.coreutil.datatransfer.integrity.InvalidFieldException; import org.pasteque.coreutil.datatransfer.integrity.InvalidFieldException;
import org.pasteque.coreutil.datatransfer.integrity.IntegrityException; import org.pasteque.coreutil.datatransfer.integrity.IntegrityException;
import org.pasteque.coreutil.datatransfer.parser.Reader; import org.pasteque.coreutil.datatransfer.parser.Reader;
import org.pasteque.coreutil.extra.ExtraObject;
/** /**
* <p>Physical cash register hardware Data Transfer Object.</p> * <p>Physical cash register hardware Data Transfer Object.</p>
@ -15,30 +16,33 @@ import org.pasteque.coreutil.datatransfer.parser.Reader;
*/ */
public final class CashRegisterDTO implements DTOInterface, Serializable public final class CashRegisterDTO implements DTOInterface, Serializable
{ {
private static final long serialVersionUID = 1079581813013284003L; private static final long serialVersionUID = 1L;
/** {@see getReference()} */ /** See {@link getReference()}. */
private String reference; private String reference;
/** See {@link getLabel()}. */
/** {@see getLabel()} */
private String label; private String label;
/** See {@link getNextTicketNumber()}. */
/** {@see getNextTicketNumber()} */
private int nextTicketNumber; private int nextTicketNumber;
/** See {@link getExtra()}. */
private ExtraObject extra;
/** /**
* Create from all fields. * Create from all fields.
* @param reference The unique reference. * @param reference The unique reference.
* @param label The display name. * @param label The display name.
* @param nextTicketNumber See {@link getNextTicketNumber}. * @param nextTicketNumber See {@link getNextTicketNumber}.
* @param extra See {@link getExtra()}.
*/ */
public CashRegisterDTO( public CashRegisterDTO(
String reference, String reference,
String label, String label,
int nextTicketNumber) { int nextTicketNumber,
ExtraObject extra) {
this.reference = reference; this.reference = reference;
this.label = label; this.label = label;
this.nextTicketNumber = nextTicketNumber; this.nextTicketNumber = nextTicketNumber;
this.extra = extra;
} }
/** /**
@ -51,6 +55,7 @@ public final class CashRegisterDTO implements DTOInterface, Serializable
this.reference = reader.readString("reference"); this.reference = reader.readString("reference");
this.label = reader.readString("label"); this.label = reader.readString("label");
this.nextTicketNumber = reader.readInt("nextTicketId"); this.nextTicketNumber = reader.readInt("nextTicketId");
this.extra = reader.readExtra();
} }
/** /**
@ -78,6 +83,14 @@ public final class CashRegisterDTO implements DTOInterface, Serializable
return nextTicketNumber; return nextTicketNumber;
} }
/**
* Get all other data.
* @return The root object of extra data.
*/
public ExtraObject getExtra() {
return this.extra;
}
/** /**
* Check if the reference and labels are set and nextTicketNumber is * Check if the reference and labels are set and nextTicketNumber is
* positive or zero. * positive or zero.

View file

@ -7,6 +7,7 @@ import org.pasteque.coreutil.ParseException;
import org.pasteque.coreutil.datatransfer.integrity.IntegrityExceptions; import org.pasteque.coreutil.datatransfer.integrity.IntegrityExceptions;
import org.pasteque.coreutil.datatransfer.parser.DTOFactory; import org.pasteque.coreutil.datatransfer.parser.DTOFactory;
import org.pasteque.coreutil.datatransfer.parser.Reader; import org.pasteque.coreutil.datatransfer.parser.Reader;
import org.pasteque.coreutil.extra.ExtraObject;
/** /**
* <p>Non finished cash session Data Transfer Object.</p> * <p>Non finished cash session Data Transfer Object.</p>
@ -17,7 +18,7 @@ import org.pasteque.coreutil.datatransfer.parser.Reader;
*/ */
public final class CashSessionDTO implements DTOInterface, Serializable public final class CashSessionDTO implements DTOInterface, Serializable
{ {
private static final long serialVersionUID = 2312930086844551950L; private static final long serialVersionUID = 1L;
/** See {@link getCashRegister()}. */ /** See {@link getCashRegister()}. */
private WeakAssociationDTO cashRegister; private WeakAssociationDTO cashRegister;
@ -31,6 +32,8 @@ public final class CashSessionDTO implements DTOInterface, Serializable
private ImmutableList<MovementDTO> movements; private ImmutableList<MovementDTO> movements;
/** See {@link getTickets()}. */ /** See {@link getTickets()}. */
private ImmutableList<FiscalTicketDTO> tickets; private ImmutableList<FiscalTicketDTO> tickets;
/** See {@link getExtra()}. */
private ExtraObject extra;
/** /**
* Create a cash session from all fields. * Create a cash session from all fields.
@ -40,6 +43,7 @@ public final class CashSessionDTO implements DTOInterface, Serializable
* @param openDate See {@link getOpenDate()}. * @param openDate See {@link getOpenDate()}.
* @param movements See {@link getMovements()}. * @param movements See {@link getMovements()}.
* @param tickets See {@link getTickets()}. * @param tickets See {@link getTickets()}.
* @param extra See {@link getExtra()}.
*/ */
public CashSessionDTO( public CashSessionDTO(
WeakAssociationDTO cashRegister, WeakAssociationDTO cashRegister,
@ -47,13 +51,15 @@ public final class CashSessionDTO implements DTOInterface, Serializable
boolean continuous, boolean continuous,
Date openDate, Date openDate,
ImmutableList<MovementDTO> movements, ImmutableList<MovementDTO> movements,
ImmutableList<FiscalTicketDTO> tickets) { ImmutableList<FiscalTicketDTO> tickets,
ExtraObject extra) {
this.cashRegister = cashRegister; this.cashRegister = cashRegister;
this.sequence = sequence; this.sequence = sequence;
this.continuous = continuous; this.continuous = continuous;
this.openDate = openDate; this.openDate = openDate;
this.movements = movements; this.movements = movements;
this.tickets = tickets; this.tickets = tickets;
this.extra = extra;
} }
/** /**
@ -73,6 +79,7 @@ public final class CashSessionDTO implements DTOInterface, Serializable
this.movements = mvtFacto.immutableReadObjects("movements"); this.movements = mvtFacto.immutableReadObjects("movements");
DTOFactory<FiscalTicketDTO> tktFacto = new DTOFactory<FiscalTicketDTO>(reader, FiscalTicketDTO.class); DTOFactory<FiscalTicketDTO> tktFacto = new DTOFactory<FiscalTicketDTO>(reader, FiscalTicketDTO.class);
this.tickets = tktFacto.immutableReadObjects("tickets"); this.tickets = tktFacto.immutableReadObjects("tickets");
this.extra = reader.readExtra();
} }
/** /**
@ -131,6 +138,14 @@ public final class CashSessionDTO implements DTOInterface, Serializable
return this.tickets; return this.tickets;
} }
/**
* Get all other data.
* @return The root object of extra data.
*/
public ExtraObject getExtra() {
return this.extra;
}
@Override @Override
public void checkIntegrity() throws IntegrityExceptions { public void checkIntegrity() throws IntegrityExceptions {
// TODO Auto-generated method stub // TODO Auto-generated method stub

View file

@ -30,7 +30,7 @@ import org.pasteque.coreutil.datatransfer.parser.Reader;
*/ */
public final class FiscalTicketDTO implements DTOInterface, Serializable public final class FiscalTicketDTO implements DTOInterface, Serializable
{ {
private static final long serialVersionUID = 1622469748625149642L; private static final long serialVersionUID = 1L;
/** See {@link getType()}. */ /** See {@link getType()}. */
private String type; private String type;

View file

@ -5,6 +5,7 @@ import java.util.Date;
import org.pasteque.coreutil.ParseException; import org.pasteque.coreutil.ParseException;
import org.pasteque.coreutil.datatransfer.integrity.IntegrityExceptions; import org.pasteque.coreutil.datatransfer.integrity.IntegrityExceptions;
import org.pasteque.coreutil.datatransfer.parser.Reader; import org.pasteque.coreutil.datatransfer.parser.Reader;
import org.pasteque.coreutil.extra.ExtraObject;
/** /**
* <p>Change in currency amounts not introduced by the payment of a ticket. * <p>Change in currency amounts not introduced by the payment of a ticket.
@ -16,7 +17,7 @@ import org.pasteque.coreutil.datatransfer.parser.Reader;
*/ */
public final class MovementDTO implements DTOInterface, Serializable public final class MovementDTO implements DTOInterface, Serializable
{ {
private static final long serialVersionUID = 2409481140667639418L; private static final long serialVersionUID = 1L;
/** See {@link getPaymentMode()}. */ /** See {@link getPaymentMode()}. */
private WeakAssociationDTO paymentMode; private WeakAssociationDTO paymentMode;
@ -26,6 +27,8 @@ public final class MovementDTO implements DTOInterface, Serializable
private double currencyAmount; private double currencyAmount;
/** See {@link getDate()}. */ /** See {@link getDate()}. */
private Date date; private Date date;
/** See {@link getExtra()}. */
private ExtraObject extra;
/** /**
* Create a movement from all fields. * Create a movement from all fields.
@ -33,16 +36,19 @@ public final class MovementDTO implements DTOInterface, Serializable
* @param currency See {@link getCurrency()}. * @param currency See {@link getCurrency()}.
* @param currencyAmount See {@link getCurrencyAmount()}. * @param currencyAmount See {@link getCurrencyAmount()}.
* @param date See {@link getDate()}. * @param date See {@link getDate()}.
* @param extra See {@link getExtra()}.
*/ */
public MovementDTO( public MovementDTO(
WeakAssociationDTO paymentMode, WeakAssociationDTO paymentMode,
WeakAssociationDTO currency, WeakAssociationDTO currency,
double currencyAmount, double currencyAmount,
Date date) { Date date,
ExtraObject extra) {
this.paymentMode = paymentMode; this.paymentMode = paymentMode;
this.currency = currency; this.currency = currency;
this.currencyAmount = currencyAmount; this.currencyAmount = currencyAmount;
this.date = date; this.date = date;
this.extra = extra;
} }
/** /**
@ -60,6 +66,7 @@ public final class MovementDTO implements DTOInterface, Serializable
reader.endObject(); reader.endObject();
this.currencyAmount = reader.readDouble("currencyAmount"); this.currencyAmount = reader.readDouble("currencyAmount");
this.date = reader.readDate("date"); this.date = reader.readDate("date");
this.extra = reader.readExtra();
} }
/** /**
@ -94,6 +101,14 @@ public final class MovementDTO implements DTOInterface, Serializable
return this.date; return this.date;
} }
/**
* Get all other data.
* @return The root object of extra data.
*/
public ExtraObject getExtra() {
return this.extra;
}
@Override @Override
public void checkIntegrity() throws IntegrityExceptions { public void checkIntegrity() throws IntegrityExceptions {
// TODO Auto-generated method stub // TODO Auto-generated method stub

View file

@ -4,6 +4,7 @@ import java.io.Serializable;
import org.pasteque.coreutil.ParseException; import org.pasteque.coreutil.ParseException;
import org.pasteque.coreutil.datatransfer.integrity.IntegrityExceptions; import org.pasteque.coreutil.datatransfer.integrity.IntegrityExceptions;
import org.pasteque.coreutil.datatransfer.parser.Reader; import org.pasteque.coreutil.datatransfer.parser.Reader;
import org.pasteque.coreutil.extra.ExtraObject;
/** /**
* <p>Payment amount Data Transfer Object. A payment may refer to a single one * <p>Payment amount Data Transfer Object. A payment may refer to a single one
@ -14,7 +15,7 @@ import org.pasteque.coreutil.datatransfer.parser.Reader;
*/ */
public final class PaymentDTO implements DTOInterface, Serializable public final class PaymentDTO implements DTOInterface, Serializable
{ {
private static final long serialVersionUID = 3195260108460565293L; private static final long serialVersionUID = 1L;
/** See {@link getPaymentMode()}. */ /** See {@link getPaymentMode()}. */
private WeakAssociationDTO paymentMode; private WeakAssociationDTO paymentMode;
@ -24,6 +25,8 @@ public final class PaymentDTO implements DTOInterface, Serializable
private double amount; private double amount;
/** See {@link getCurrencyAmount()}. */ /** See {@link getCurrencyAmount()}. */
private double currencyAmount; private double currencyAmount;
/** See {@link getExtra()}. */
private ExtraObject extra;
/** /**
* Create a payment from all fields. * Create a payment from all fields.
@ -31,16 +34,19 @@ public final class PaymentDTO implements DTOInterface, Serializable
* @param amount See {@link getAmount()}. * @param amount See {@link getAmount()}.
* @param currency See {@link getCurrency()}. * @param currency See {@link getCurrency()}.
* @param currencyAmount See {@link getCurrencyAmount()}. * @param currencyAmount See {@link getCurrencyAmount()}.
* @param extra See {@link getExtra()}.
*/ */
public PaymentDTO( public PaymentDTO(
WeakAssociationDTO paymentMode, WeakAssociationDTO paymentMode,
double amount, double amount,
WeakAssociationDTO currency, WeakAssociationDTO currency,
double currencyAmount) { double currencyAmount,
ExtraObject extra) {
this.paymentMode = paymentMode; this.paymentMode = paymentMode;
this.amount = amount; this.amount = amount;
this.currency = currency; this.currency = currency;
this.currencyAmount = currencyAmount; this.currencyAmount = currencyAmount;
this.extra = extra;
} }
/** /**
@ -58,6 +64,7 @@ public final class PaymentDTO implements DTOInterface, Serializable
this.currency = new WeakAssociationDTO(reader); this.currency = new WeakAssociationDTO(reader);
reader.endObject(); reader.endObject();
this.currencyAmount = reader.readDouble("currencyAmount"); this.currencyAmount = reader.readDouble("currencyAmount");
this.extra = reader.readExtra();
} }
/** /**
@ -92,6 +99,14 @@ public final class PaymentDTO implements DTOInterface, Serializable
return this.currencyAmount; return this.currencyAmount;
} }
/**
* Get all other data.
* @return The root object of extra data.
*/
public ExtraObject getExtra() {
return this.extra;
}
@Override @Override
public void checkIntegrity() throws IntegrityExceptions { public void checkIntegrity() throws IntegrityExceptions {
// TODO Auto-generated method stub // TODO Auto-generated method stub

View file

@ -4,6 +4,7 @@ import java.io.Serializable;
import org.pasteque.coreutil.ParseException; import org.pasteque.coreutil.ParseException;
import org.pasteque.coreutil.datatransfer.integrity.IntegrityExceptions; import org.pasteque.coreutil.datatransfer.integrity.IntegrityExceptions;
import org.pasteque.coreutil.datatransfer.parser.Reader; import org.pasteque.coreutil.datatransfer.parser.Reader;
import org.pasteque.coreutil.extra.ExtraObject;
/** /**
* <p>Tax amount Data Transfer Object. A tax amount may refer to a single one * <p>Tax amount Data Transfer Object. A tax amount may refer to a single one
@ -14,7 +15,7 @@ import org.pasteque.coreutil.datatransfer.parser.Reader;
*/ */
public final class TaxAmountDTO implements DTOInterface, Serializable public final class TaxAmountDTO implements DTOInterface, Serializable
{ {
private static final long serialVersionUID = 7429827880917696693L; private static final long serialVersionUID = 1L;
/** See {@link getTax()}. */ /** See {@link getTax()}. */
private WeakAssociationDTO tax; private WeakAssociationDTO tax;
@ -26,6 +27,8 @@ public final class TaxAmountDTO implements DTOInterface, Serializable
private double amount; private double amount;
/** See {@link getIncludedInBase()}. */ /** See {@link getIncludedInBase()}. */
private boolean includedInBase; private boolean includedInBase;
/** See {@link getExtra()}. */
private ExtraObject extra;
/** /**
* Create a tax from all fields. * Create a tax from all fields.
@ -34,18 +37,21 @@ public final class TaxAmountDTO implements DTOInterface, Serializable
* @param base See {@link getBase()}. * @param base See {@link getBase()}.
* @param amount See {@link getAmount()}. * @param amount See {@link getAmount()}.
* @param includedInBase See {@link getIncludedInBase()}. * @param includedInBase See {@link getIncludedInBase()}.
* @param extra See {@link getExtra()}.
*/ */
public TaxAmountDTO( public TaxAmountDTO(
WeakAssociationDTO tax, WeakAssociationDTO tax,
double taxRate, double taxRate,
double base, double base,
double amount, double amount,
boolean includedInBase) { boolean includedInBase,
ExtraObject extra) {
this.tax = tax; this.tax = tax;
this.taxRate = taxRate; this.taxRate = taxRate;
this.base = base; this.base = base;
this.amount = amount; this.amount = amount;
this.includedInBase = includedInBase; this.includedInBase = includedInBase;
this.extra = extra;
} }
/** /**
@ -62,6 +68,7 @@ public final class TaxAmountDTO implements DTOInterface, Serializable
this.base = reader.readDouble("base"); this.base = reader.readDouble("base");
this.amount = reader.readDouble("amount"); this.amount = reader.readDouble("amount");
this.includedInBase = reader.readBoolean("includedInBase"); this.includedInBase = reader.readBoolean("includedInBase");
this.extra = reader.readExtra();
} }
/** /**
@ -106,6 +113,14 @@ public final class TaxAmountDTO implements DTOInterface, Serializable
return this.includedInBase; return this.includedInBase;
} }
/**
* Get all other data.
* @return The root object of extra data.
*/
public ExtraObject getExtra() {
return this.extra;
}
@Override @Override
public void checkIntegrity() throws IntegrityExceptions { public void checkIntegrity() throws IntegrityExceptions {
// TODO Auto-generated method stub // TODO Auto-generated method stub

View file

@ -4,33 +4,39 @@ import java.io.Serializable;
import org.pasteque.coreutil.ParseException; import org.pasteque.coreutil.ParseException;
import org.pasteque.coreutil.datatransfer.integrity.IntegrityExceptions; import org.pasteque.coreutil.datatransfer.integrity.IntegrityExceptions;
import org.pasteque.coreutil.datatransfer.parser.Reader; import org.pasteque.coreutil.datatransfer.parser.Reader;
import org.pasteque.coreutil.extra.ExtraObject;
/** /**
* Tax Data Transfer Object. * Tax Data Transfer Object.
*/ */
public final class TaxDTO implements DTOInterface, Serializable public final class TaxDTO implements DTOInterface, Serializable
{ {
private static final long serialVersionUID = 525507510660586665L; private static final long serialVersionUID = 1L;
/** See {@link getType()}. */ /** See {@link getType()}. */
private String type; private String type;
/** See {@link getAmount()}. */ /** See {@link getAmount()}. */
private double amount; private double amount;
/** See {@link getIncludedInBase()}. */ /** See {@link getIncludedInBase()}. */
private boolean includedInBase; private boolean includedInBase;
/** See {@link getExtra()}. */
private ExtraObject extra;
/** /**
* Create a tax from all fields. * Create a tax from all fields.
* @param type See {@link getType()}. * @param type See {@link getType()}.
* @param amount See {@link getAmount()}. * @param amount See {@link getAmount()}.
* @param includedInBase See {@link getIncludedInBase()}. * @param includedInBase See {@link getIncludedInBase()}.
* @param extra See {@link getExtra()}.
*/ */
public TaxDTO( public TaxDTO(
String type, String type,
double amount, double amount,
boolean includedInBase) { boolean includedInBase,
ExtraObject extra) {
this.type = type; this.type = type;
this.amount = amount; this.amount = amount;
this.includedInBase = includedInBase; this.includedInBase = includedInBase;
this.extra = extra;
} }
/** /**
@ -43,6 +49,7 @@ public final class TaxDTO implements DTOInterface, Serializable
this.type = reader.readString("type"); this.type = reader.readString("type");
this.amount = reader.readDouble("amount"); this.amount = reader.readDouble("amount");
this.includedInBase = reader.readBoolean("includedInBase"); this.includedInBase = reader.readBoolean("includedInBase");
this.extra = reader.readExtra();
} }
/** /**
@ -75,6 +82,14 @@ public final class TaxDTO implements DTOInterface, Serializable
return this.includedInBase; return this.includedInBase;
} }
/**
* Get all other data.
* @return The root object of extra data.
*/
public ExtraObject getExtra() {
return this.extra;
}
@Override @Override
public void checkIntegrity() throws IntegrityExceptions { public void checkIntegrity() throws IntegrityExceptions {
// TODO Auto-generated method stub // TODO Auto-generated method stub

View file

@ -7,6 +7,7 @@ import org.pasteque.coreutil.ParseException;
import org.pasteque.coreutil.datatransfer.integrity.IntegrityExceptions; import org.pasteque.coreutil.datatransfer.integrity.IntegrityExceptions;
import org.pasteque.coreutil.datatransfer.parser.DTOFactory; import org.pasteque.coreutil.datatransfer.parser.DTOFactory;
import org.pasteque.coreutil.datatransfer.parser.Reader; import org.pasteque.coreutil.datatransfer.parser.Reader;
import org.pasteque.coreutil.extra.ExtraObject;
/** /**
* <p>Receipt of a finalized and paid order. Tickets are immutable unless changes * <p>Receipt of a finalized and paid order. Tickets are immutable unless changes
@ -17,7 +18,7 @@ import org.pasteque.coreutil.datatransfer.parser.Reader;
*/ */
public final class TicketDTO implements DTOInterface, Serializable public final class TicketDTO implements DTOInterface, Serializable
{ {
private static final long serialVersionUID = 8831777799341373103L; private static final long serialVersionUID = 1L;
/** See {@link getCashRegister()}. */ /** See {@link getCashRegister()}. */
private WeakAssociationDTO cashRegister; private WeakAssociationDTO cashRegister;
@ -55,6 +56,8 @@ public final class TicketDTO implements DTOInterface, Serializable
private double finalPrice; private double finalPrice;
/** See {@link getFinalTaxedPrice()}. */ /** See {@link getFinalTaxedPrice()}. */
private double finalTaxedPrice; private double finalTaxedPrice;
/** See {@link getExtra()}. */
private ExtraObject extra;
/** /**
* Create an ticket from all fields. * Create an ticket from all fields.
@ -76,6 +79,7 @@ public final class TicketDTO implements DTOInterface, Serializable
* @param discountRate See {@link getDiscountRate()}. * @param discountRate See {@link getDiscountRate()}.
* @param finalPrice See {@link getFinalPrice()}. * @param finalPrice See {@link getFinalPrice()}.
* @param finalTaxedPrice See {@link getFinalTaxedPrice()}. * @param finalTaxedPrice See {@link getFinalTaxedPrice()}.
* @param extra See {@link getExtra()}.
*/ */
public TicketDTO( public TicketDTO(
WeakAssociationDTO cashRegister, WeakAssociationDTO cashRegister,
@ -95,7 +99,8 @@ public final class TicketDTO implements DTOInterface, Serializable
WeakAssociationDTO discountProfile, WeakAssociationDTO discountProfile,
double discountRate, double discountRate,
double finalPrice, double finalPrice,
double finalTaxedPrice) { double finalTaxedPrice,
ExtraObject extra) {
this.cashRegister = cashRegister; this.cashRegister = cashRegister;
this.sequence = sequence; this.sequence = sequence;
this.number = number; this.number = number;
@ -114,6 +119,7 @@ public final class TicketDTO implements DTOInterface, Serializable
this.discountRate = discountRate; this.discountRate = discountRate;
this.finalPrice = finalPrice; this.finalPrice = finalPrice;
this.finalTaxedPrice = finalTaxedPrice; this.finalTaxedPrice = finalTaxedPrice;
this.extra = extra;
} }
/** /**
@ -146,6 +152,7 @@ public final class TicketDTO implements DTOInterface, Serializable
this.taxes = taxFacto.immutableReadObjects("taxes"); this.taxes = taxFacto.immutableReadObjects("taxes");
DTOFactory<PaymentDTO> pmtFacto = new DTOFactory<PaymentDTO>(reader, PaymentDTO.class); DTOFactory<PaymentDTO> pmtFacto = new DTOFactory<PaymentDTO>(reader, PaymentDTO.class);
this.payments = pmtFacto.immutableReadObjects("payments"); this.payments = pmtFacto.immutableReadObjects("payments");
this.extra = reader.readExtra();
} }
/** /**
@ -311,6 +318,14 @@ public final class TicketDTO implements DTOInterface, Serializable
return this.finalTaxedPrice; return this.finalTaxedPrice;
} }
/**
* Get all other data.
* @return The root object of extra data.
*/
public ExtraObject getExtra() {
return this.extra;
}
@Override @Override
public void checkIntegrity() throws IntegrityExceptions { public void checkIntegrity() throws IntegrityExceptions {
// TODO Auto-generated method stub // TODO Auto-generated method stub
@ -326,7 +341,7 @@ public final class TicketDTO implements DTOInterface, Serializable
*/ */
public class TicketLineDTO implements DTOInterface, Serializable public class TicketLineDTO implements DTOInterface, Serializable
{ {
private static final long serialVersionUID = -9065013247136552814L; private static final long serialVersionUID = 1L;
/** See {@link getDispOrder()}. */ /** See {@link getDispOrder()}. */
private final int dispOrder; private final int dispOrder;

View file

@ -12,7 +12,7 @@ import org.pasteque.coreutil.datatransfer.parser.Reader;
*/ */
public class WeakAssociationDTO implements DTOInterface, Serializable public class WeakAssociationDTO implements DTOInterface, Serializable
{ {
private static final long serialVersionUID = -4033459839844194734L; private static final long serialVersionUID = 1L;
/** See {@link getReference()}. */ /** See {@link getReference()}. */
private final String reference; private final String reference;

View file

@ -7,6 +7,7 @@ import org.pasteque.coreutil.ParseException;
import org.pasteque.coreutil.datatransfer.integrity.IntegrityExceptions; import org.pasteque.coreutil.datatransfer.integrity.IntegrityExceptions;
import org.pasteque.coreutil.datatransfer.parser.DTOFactory; import org.pasteque.coreutil.datatransfer.parser.DTOFactory;
import org.pasteque.coreutil.datatransfer.parser.Reader; import org.pasteque.coreutil.datatransfer.parser.Reader;
import org.pasteque.coreutil.extra.ExtraObject;
/** /**
* <p>Receipt of a finalized cash session. Once a cash session is closed, * <p>Receipt of a finalized cash session. Once a cash session is closed,
@ -22,7 +23,7 @@ import org.pasteque.coreutil.datatransfer.parser.Reader;
*/ */
public final class ZTicketDTO implements DTOInterface, Serializable public final class ZTicketDTO implements DTOInterface, Serializable
{ {
private static final long serialVersionUID = -2784800199238764159L; private static final long serialVersionUID = 1L;
/** See {@link getCashRegister()}. */ /** See {@link getCashRegister()}. */
private WeakAssociationDTO cashRegister; private WeakAssociationDTO cashRegister;
@ -64,6 +65,8 @@ public final class ZTicketDTO implements DTOInterface, Serializable
private ImmutableList<PaymentDTO> payments; private ImmutableList<PaymentDTO> payments;
/** See {@link getCustBalances()}. */ /** See {@link getCustBalances()}. */
private ImmutableList<ZTicketCustBalanceDTO> custBalances; private ImmutableList<ZTicketCustBalanceDTO> custBalances;
/** See {@link getExtra()}. */
private ExtraObject extra;
/** /**
* Create an ticket from all fields. * Create an ticket from all fields.
@ -87,6 +90,7 @@ public final class ZTicketDTO implements DTOInterface, Serializable
* @param catTaxes See {@link getCatTaxes()}. * @param catTaxes See {@link getCatTaxes()}.
* @param payments See {@link getPayments()}. * @param payments See {@link getPayments()}.
* @param custBalances See {@link getCustBalances()}. * @param custBalances See {@link getCustBalances()}.
* @param extra See {@link getExtra()}.
*/ */
public ZTicketDTO( public ZTicketDTO(
WeakAssociationDTO cashRegister, WeakAssociationDTO cashRegister,
@ -108,7 +112,8 @@ public final class ZTicketDTO implements DTOInterface, Serializable
ZTicketCatSalesDTO[] catSales, ZTicketCatSalesDTO[] catSales,
ZTicketCatTaxesDTO[] catTaxes, ZTicketCatTaxesDTO[] catTaxes,
PaymentDTO[] payments, PaymentDTO[] payments,
ZTicketCustBalanceDTO[] custBalances) { ZTicketCustBalanceDTO[] custBalances,
ExtraObject extra) {
this.cashRegister = cashRegister; this.cashRegister = cashRegister;
this.sequence = sequence; this.sequence = sequence;
this.continuous = continuous; this.continuous = continuous;
@ -129,6 +134,7 @@ public final class ZTicketDTO implements DTOInterface, Serializable
this.catTaxes = new ImmutableList<ZTicketCatTaxesDTO>(catTaxes); this.catTaxes = new ImmutableList<ZTicketCatTaxesDTO>(catTaxes);
this.payments = new ImmutableList<PaymentDTO>(payments); this.payments = new ImmutableList<PaymentDTO>(payments);
this.custBalances = new ImmutableList<ZTicketCustBalanceDTO>(custBalances); this.custBalances = new ImmutableList<ZTicketCustBalanceDTO>(custBalances);
this.extra = extra;
} }
/** /**
@ -168,7 +174,7 @@ public final class ZTicketDTO implements DTOInterface, Serializable
this.payments = pmtFacto.immutableReadObjects("payments"); this.payments = pmtFacto.immutableReadObjects("payments");
DTOFactory<ZTicketCustBalanceDTO> custBFacto = new DTOFactory<ZTicketCustBalanceDTO>(reader, ZTicketCustBalanceDTO.class); DTOFactory<ZTicketCustBalanceDTO> custBFacto = new DTOFactory<ZTicketCustBalanceDTO>(reader, ZTicketCustBalanceDTO.class);
this.custBalances = custBFacto.immutableReadObjects("custBalances"); this.custBalances = custBFacto.immutableReadObjects("custBalances");
reader.startArray("custBalances"); this.extra = reader.readExtra();
} }
/** /**
@ -354,6 +360,14 @@ public final class ZTicketDTO implements DTOInterface, Serializable
return this.custBalances; return this.custBalances;
} }
/**
* Get all other data.
* @return The root object of extra data.
*/
public ExtraObject getExtra() {
return this.extra;
}
@Override @Override
public void checkIntegrity() throws IntegrityExceptions { public void checkIntegrity() throws IntegrityExceptions {
// TODO Auto-generated method stub // TODO Auto-generated method stub
@ -365,7 +379,7 @@ public final class ZTicketDTO implements DTOInterface, Serializable
*/ */
public class ZTicketCatSalesDTO implements DTOInterface, Serializable public class ZTicketCatSalesDTO implements DTOInterface, Serializable
{ {
private static final long serialVersionUID = -6392552469204214096L; private static final long serialVersionUID = 1L;
/** See {@link getCategory()}. */ /** See {@link getCategory()}. */
private final WeakAssociationDTO category; private final WeakAssociationDTO category;
@ -427,7 +441,7 @@ public final class ZTicketDTO implements DTOInterface, Serializable
*/ */
public class ZTicketCatTaxesDTO implements DTOInterface, Serializable public class ZTicketCatTaxesDTO implements DTOInterface, Serializable
{ {
private static final long serialVersionUID = -8934368775977813408L; private static final long serialVersionUID = 1L;
/** See {@link getCategory()}. */ /** See {@link getCategory()}. */
private final WeakAssociationDTO category; private final WeakAssociationDTO category;
@ -517,7 +531,7 @@ public final class ZTicketDTO implements DTOInterface, Serializable
*/ */
public class ZTicketCustBalanceDTO implements DTOInterface, Serializable public class ZTicketCustBalanceDTO implements DTOInterface, Serializable
{ {
private static final long serialVersionUID = 7698608167553284402L; private static final long serialVersionUID = 1L;
/** See {@link getCustomer()}. */ /** See {@link getCustomer()}. */
private final WeakAssociationDTO customer; private final WeakAssociationDTO customer;

View file

@ -4,5 +4,7 @@
* <p>All the DTO are final to ensure the immutability. Extensions should use * <p>All the DTO are final to ensure the immutability. Extensions should use
* encapsulation to add more data or ease-of-use, to ensure the major package * encapsulation to add more data or ease-of-use, to ensure the major package
* using them cannot be alterated.</p> * using them cannot be alterated.</p>
* <p>This objects contains only amounts and minimal content description, all
* other data are stored in extra objects allow extensions.</p>
*/ */
package org.pasteque.coreutil.datatransfer.dto; package org.pasteque.coreutil.datatransfer.dto;

View file

@ -5,7 +5,7 @@ package org.pasteque.coreutil.datatransfer.integrity;
*/ */
public abstract class IntegrityException extends Exception public abstract class IntegrityException extends Exception
{ {
private static final long serialVersionUID = 6208213847306142896L; private static final long serialVersionUID = 1L;
/** {@inheritDoc} */ /** {@inheritDoc} */
public IntegrityException() { public IntegrityException() {

View file

@ -8,7 +8,7 @@ import java.util.List;
*/ */
public class IntegrityExceptions extends Exception public class IntegrityExceptions extends Exception
{ {
private static final long serialVersionUID = -2603644891253059810L; private static final long serialVersionUID = 1L;
/** {@see getCauses()} */ /** {@see getCauses()} */
private IntegrityException[] causes; private IntegrityException[] causes;

View file

@ -5,7 +5,7 @@ package org.pasteque.coreutil.datatransfer.integrity;
*/ */
public class InvalidFieldException extends IntegrityException public class InvalidFieldException extends IntegrityException
{ {
private static final long serialVersionUID = 2512125224337518801L; private static final long serialVersionUID = 1L;
/** {@see getConstraint()} */ /** {@see getConstraint()} */
private final IntegrityFieldConstraint constraint; private final IntegrityFieldConstraint constraint;

View file

@ -6,7 +6,7 @@ package org.pasteque.coreutil.datatransfer.integrity;
*/ */
public class InvalidRecordException extends IntegrityException public class InvalidRecordException extends IntegrityException
{ {
private static final long serialVersionUID = -6234201939816973179L; private static final long serialVersionUID = 1L;
/** {@see getConstraint()} */ /** {@see getConstraint()} */
private final IntegrityRecordConstraint constraint; private final IntegrityRecordConstraint constraint;

View file

@ -15,7 +15,7 @@ import org.pasteque.coreutil.datatransfer.format.BinaryDTOFormat;
/** /**
* Read values from a JSON representation of data. * Read values from a JSON representation of data.
*/ */
public class JSONReader implements Reader public class JSONReader extends ReaderHelper
{ {
/** Constant for the state of not having parsed anything yet. */ /** Constant for the state of not having parsed anything yet. */
private static final String ROOT_NAME = "__ROOT__"; private static final String ROOT_NAME = "__ROOT__";
@ -98,13 +98,13 @@ public class JSONReader implements Reader
} }
} }
@Override @Override // from Reader
public boolean hasKey(String key) throws ParseException { public boolean hasKey(String key) throws ParseException {
this.checkCurrentObject(); this.checkCurrentObject();
return this.currentObject.has(key); return this.currentObject.has(key);
} }
@Override @Override // from Reader
public List<String> listKeys() throws ParseException { public List<String> listKeys() throws ParseException {
this.checkCurrentObject(); this.checkCurrentObject();
Set<String> keySet = this.currentObject.keySet(); Set<String> keySet = this.currentObject.keySet();
@ -116,25 +116,25 @@ public class JSONReader implements Reader
return keys; return keys;
} }
@Override @Override // from Reader
public int getArraySize() throws ParseException { public int getArraySize() throws ParseException {
this.checkCurrentArray(); this.checkCurrentArray();
return this.currentArray.length(); return this.currentArray.length();
} }
@Override @Override // from Reader
public boolean isNull(String key) throws ParseException { public boolean isNull(String key) throws ParseException {
this.checkCurrentObject(); this.checkCurrentObject();
return this.currentObject.isNull(key); return this.currentObject.isNull(key);
} }
@Override @Override // from Reader
public boolean isNull(int index) throws ParseException { public boolean isNull(int index) throws ParseException {
this.checkCurrentArrayIndex(index); this.checkCurrentArrayIndex(index);
return this.currentArray.isNull(index); return this.currentArray.isNull(index);
} }
@Override @Override // from Reader
public boolean readBoolean(String key) throws ParseException { public boolean readBoolean(String key) throws ParseException {
this.checkCurrentObject(); this.checkCurrentObject();
try { try {
@ -144,12 +144,7 @@ public class JSONReader implements Reader
} }
} }
@Override @Override // from Reader
public Boolean readBooleanOrNull(String key) throws ParseException {
return (this.isNull(key)) ? null : Boolean.valueOf(this.readBoolean(key));
}
@Override
public boolean readBoolean(int index) throws ParseException { public boolean readBoolean(int index) throws ParseException {
this.checkCurrentArrayIndex(index); this.checkCurrentArrayIndex(index);
try { try {
@ -159,12 +154,7 @@ public class JSONReader implements Reader
} }
} }
@Override @Override // from Reader
public Boolean readBooleanOrNull(int index) throws ParseException {
return (this.isNull(index)) ? null : Boolean.valueOf(this.readBoolean(index));
}
@Override
public String readString(String key) throws ParseException { public String readString(String key) throws ParseException {
this.checkCurrentObject(); this.checkCurrentObject();
try { try {
@ -174,17 +164,7 @@ public class JSONReader implements Reader
} }
} }
@Override @Override // from Reader
public String readStringOrNull(String key) throws ParseException {
return (this.isNull(key)) ? null : this.readString(key);
}
@Override
public String readStringOrEmpty(String key) throws ParseException {
return (this.isNull(key)) ? "" : this.readString(key);
}
@Override
public String readString(int index) throws ParseException { public String readString(int index) throws ParseException {
this.checkCurrentArrayIndex(index); this.checkCurrentArrayIndex(index);
try { try {
@ -194,17 +174,7 @@ public class JSONReader implements Reader
} }
} }
@Override @Override // from Reader
public String readStringOrNull(int index) throws ParseException {
return (this.isNull(index)) ? null : this.readString(index);
}
@Override
public String readStringOrEmpty(int index) throws ParseException {
return (this.isNull(index)) ? "" : this.readString(index);
}
@Override
public int readInt(String key) throws ParseException { public int readInt(String key) throws ParseException {
this.checkCurrentObject(); this.checkCurrentObject();
try { try {
@ -214,12 +184,7 @@ public class JSONReader implements Reader
} }
} }
@Override @Override // from Reader
public Integer readIntOrNull(String key) throws ParseException {
return (this.isNull(key)) ? null : Integer.valueOf(this.readInt(key));
}
@Override
public int readInt(int index) throws ParseException { public int readInt(int index) throws ParseException {
this.checkCurrentArrayIndex(index); this.checkCurrentArrayIndex(index);
try { try {
@ -229,13 +194,7 @@ public class JSONReader implements Reader
} }
} }
@Override @Override // from Reader
public Integer readIntOrNull(int index) throws ParseException {
return (this.isNull(index)) ? null : Integer.valueOf(this.readInt(index));
}
@Override
public double readDouble(String key) throws ParseException { public double readDouble(String key) throws ParseException {
this.checkCurrentObject(); this.checkCurrentObject();
try { try {
@ -245,12 +204,7 @@ public class JSONReader implements Reader
} }
} }
@Override @Override // from Reader
public Double readDoubleOrNull(String key) throws ParseException {
return (this.isNull(key)) ? null : Double.valueOf(this.readDouble(key));
}
@Override
public double readDouble(int index) throws ParseException { public double readDouble(int index) throws ParseException {
this.checkCurrentArray(); this.checkCurrentArray();
try { try {
@ -260,12 +214,7 @@ public class JSONReader implements Reader
} }
} }
@Override @Override // from Reader
public Double readDoubleOrNull(int index) throws ParseException {
return (this.isNull(index)) ? null : Double.valueOf(this.readDouble(index));
}
@Override
public Date readDate(String key) throws ParseException { public Date readDate(String key) throws ParseException {
this.checkCurrentObject(); this.checkCurrentObject();
try { try {
@ -281,12 +230,7 @@ public class JSONReader implements Reader
} }
} }
@Override @Override // from Reader
public Date readDateOrNull(String key) throws ParseException {
return (this.isNull(key)) ? null : this.readDate(key);
}
@Override
public Date readDate(int index) throws ParseException { public Date readDate(int index) throws ParseException {
this.checkCurrentArrayIndex(index); this.checkCurrentArrayIndex(index);
try { try {
@ -302,12 +246,7 @@ public class JSONReader implements Reader
} }
} }
@Override @Override // from Reader
public Date readDateOrNull(int index) throws ParseException {
return (this.isNull(index)) ? null : this.readDate(index);
}
@Override
public byte[] readBinary(String key) throws ParseException { public byte[] readBinary(String key) throws ParseException {
this.checkCurrentObject(); this.checkCurrentObject();
try { try {
@ -318,12 +257,7 @@ public class JSONReader implements Reader
} }
} }
@Override @Override // from Reader
public byte[] readBinaryOrNull(String key) throws ParseException {
return (this.isNull(key)) ? null : this.readBinary(key);
}
@Override
public byte[] readBinary(int index) throws ParseException { public byte[] readBinary(int index) throws ParseException {
this.checkCurrentArrayIndex(index); this.checkCurrentArrayIndex(index);
try { try {
@ -334,12 +268,7 @@ public class JSONReader implements Reader
} }
} }
@Override @Override // from Reader
public byte[] readBinaryOrNull(int index) throws ParseException {
return (this.isNull(index)) ? null : this.readBinary(index);
}
@Override
public void startObject() throws ParseException { public void startObject() throws ParseException {
if (this.currentObject == null && this.currentArray == null if (this.currentObject == null && this.currentArray == null
&& this.mainObject == null && this.mainArray == null) { && this.mainObject == null && this.mainArray == null) {
@ -350,7 +279,7 @@ public class JSONReader implements Reader
} }
} }
@Override @Override // from Reader
public void startObject(String key) throws ParseException { public void startObject(String key) throws ParseException {
this.checkCurrentObject(); this.checkCurrentObject();
try { try {
@ -361,7 +290,7 @@ public class JSONReader implements Reader
this.path.add(new Path(PathType.OBJECT, key)); this.path.add(new Path(PathType.OBJECT, key));
} }
@Override @Override // from Reader
public void startObject(int index) throws ParseException { public void startObject(int index) throws ParseException {
this.checkCurrentArrayIndex(index); this.checkCurrentArrayIndex(index);
try { try {
@ -373,14 +302,14 @@ public class JSONReader implements Reader
this.path.add(new Path(PathType.OBJECT, index)); this.path.add(new Path(PathType.OBJECT, index));
} }
@Override @Override // from Reader
public void endObject() throws ParseException { public void endObject() throws ParseException {
this.checkCurrentObject(); this.checkCurrentObject();
this.path.remove(this.path.size() - 1); this.path.remove(this.path.size() - 1);
this.runPath(); this.runPath();
} }
@Override @Override // from Reader
public void startArray() throws ParseException { public void startArray() throws ParseException {
if (this.currentObject == null && this.currentArray == null if (this.currentObject == null && this.currentArray == null
&& this.mainObject == null && this.mainArray == null) { && this.mainObject == null && this.mainArray == null) {
@ -391,7 +320,7 @@ public class JSONReader implements Reader
} }
} }
@Override @Override // from Reader
public void startArray(String key) throws ParseException { public void startArray(String key) throws ParseException {
this.checkCurrentObject(); this.checkCurrentObject();
try { try {
@ -403,7 +332,7 @@ public class JSONReader implements Reader
this.path.add(new Path(PathType.ARRAY, key)); this.path.add(new Path(PathType.ARRAY, key));
} }
@Override @Override // from Reader
public void startArray(int index) throws ParseException { public void startArray(int index) throws ParseException {
this.checkCurrentArrayIndex(index); this.checkCurrentArrayIndex(index);
try { try {
@ -414,7 +343,7 @@ public class JSONReader implements Reader
this.path.add(new Path(PathType.ARRAY, index)); this.path.add(new Path(PathType.ARRAY, index));
} }
@Override @Override // from Reader
public void endArray() throws ParseException { public void endArray() throws ParseException {
this.checkCurrentArray(); this.checkCurrentArray();
this.path.remove(this.path.size() - 1); this.path.remove(this.path.size() - 1);

View file

@ -3,6 +3,7 @@ package org.pasteque.coreutil.datatransfer.parser;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import org.pasteque.coreutil.ParseException; import org.pasteque.coreutil.ParseException;
import org.pasteque.coreutil.extra.ExtraObject;
/** /**
* <p>Data reader.</p> * <p>Data reader.</p>
@ -268,6 +269,15 @@ public interface Reader
*/ */
public byte[] readBinaryOrNull(String key) throws ParseException; public byte[] readBinaryOrNull(String key) throws ParseException;
/**
* Read the extra object.
* @return The root extra object. If not present, it must return an empty
* extra object.
* @throws ParseException When an error occurs while reading the extra
* object.
*/
public ExtraObject readExtra() throws ParseException;
/** /**
* Read binary data as base64 at the given index of the current element. * Read binary data as base64 at the given index of the current element.
* @param index The index to read in the current element. * @param index The index to read in the current element.

View file

@ -0,0 +1,169 @@
package org.pasteque.coreutil.datatransfer.parser;
import java.util.Date;
import java.util.List;
import org.pasteque.coreutil.ParseException;
import org.pasteque.coreutil.extra.ExtraObject;
/**
* <p>Common behaviour implementation of a data reader.</p>
*/
public abstract class ReaderHelper implements Reader
{
@Override // from Reader
public abstract boolean hasKey(String key) throws ParseException;
@Override // from Reader
public abstract List<String> listKeys() throws ParseException;
@Override // from Reader
public abstract int getArraySize() throws ParseException;
@Override // from Reader
public abstract boolean isNull(String key) throws ParseException;
@Override // from Reader
public abstract boolean isNull(int index) throws ParseException;
@Override // from Reader
public abstract boolean readBoolean(String key) throws ParseException;
@Override // from Reader
public Boolean readBooleanOrNull(String key) throws ParseException {
return (this.isNull(key)) ? null : Boolean.valueOf(this.readBoolean(key));
}
@Override // from Reader
public abstract boolean readBoolean(int index) throws ParseException;
@Override // from Reader
public Boolean readBooleanOrNull(int index) throws ParseException {
return (this.isNull(index)) ? null : Boolean.valueOf(this.readBoolean(index));
}
@Override // from Reader
public abstract String readString(String key) throws ParseException;
@Override // from Reader
public String readStringOrNull(String key) throws ParseException {
return (this.isNull(key)) ? null : this.readString(key);
}
@Override // from Reader
public String readStringOrEmpty(String key) throws ParseException {
return (this.isNull(key)) ? "" : this.readString(key);
}
@Override // from Reader
public abstract String readString(int index) throws ParseException;
@Override // from Reader
public String readStringOrNull(int index) throws ParseException {
return (this.isNull(index)) ? null : this.readString(index);
}
@Override // from Reader
public String readStringOrEmpty(int index) throws ParseException {
return (this.isNull(index)) ? "" : this.readString(index);
}
@Override // from Reader
public abstract int readInt(String key) throws ParseException;
@Override // from Reader
public Integer readIntOrNull(String key) throws ParseException {
return (this.isNull(key)) ? null : Integer.valueOf(this.readInt(key));
}
@Override // from Reader
public abstract int readInt(int index) throws ParseException;
@Override // from Reader
public Integer readIntOrNull(int index) throws ParseException {
return (this.isNull(index)) ? null : Integer.valueOf(this.readInt(index));
}
@Override // from Reader
public abstract double readDouble(String key) throws ParseException;
@Override // from Reader
public Double readDoubleOrNull(String key) throws ParseException {
return (this.isNull(key)) ? null : Double.valueOf(this.readDouble(key));
}
@Override // from Reader
public abstract double readDouble(int index) throws ParseException;
@Override // from Reader
public Double readDoubleOrNull(int index) throws ParseException {
return (this.isNull(index)) ? null : Double.valueOf(this.readDouble(index));
}
@Override // from Reader
public abstract Date readDate(String key) throws ParseException;
@Override // from Reader
public Date readDateOrNull(String key) throws ParseException {
return (this.isNull(key)) ? null : this.readDate(key);
}
@Override // from Reader
public abstract Date readDate(int index) throws ParseException;
@Override // from Reader
public Date readDateOrNull(int index) throws ParseException {
return (this.isNull(index)) ? null : this.readDate(index);
}
@Override // from Reader
public abstract byte[] readBinary(String key) throws ParseException;
@Override // from Reader
public byte[] readBinaryOrNull(String key) throws ParseException {
return (this.isNull(key)) ? null : this.readBinary(key);
}
@Override // from Reader
public abstract byte[] readBinary(int index) throws ParseException;
@Override // from Reader
public byte[] readBinaryOrNull(int index) throws ParseException {
return (this.isNull(index)) ? null : this.readBinary(index);
}
@Override // from Reader
public ExtraObject readExtra() throws ParseException {
if (!this.hasKey(ExtraObject.EXTRA_ROOT_FIELD)
|| this.isNull(ExtraObject.EXTRA_ROOT_FIELD)) {
return new ExtraObject();
} else {
this.startObject("extra");
ExtraObject o = new ExtraObject(this);
this.endObject();
return o;
}
}
@Override // from Reader
public abstract void startObject() throws ParseException;
@Override // from Reader
public abstract void startObject(String key) throws ParseException;
@Override // from Reader
public abstract void startObject(int index) throws ParseException;
@Override // from Reader
public abstract void endObject() throws ParseException;
@Override // from Reader
public abstract void startArray() throws ParseException;
@Override // from Reader
public abstract void startArray(String key) throws ParseException;
@Override // from Reader
public abstract void startArray(int index) throws ParseException;
@Override // from Reader
public abstract void endArray() throws ParseException;
}

View file

@ -1,5 +1,7 @@
package org.pasteque.coreutil.datatransfer.parser; package org.pasteque.coreutil.datatransfer.parser;
import org.pasteque.coreutil.ParseException;
/** /**
* <p>Data writer.</p> * <p>Data writer.</p>
* <p>A reader must always be initialized from its DTO, typically within * <p>A reader must always be initialized from its DTO, typically within
@ -7,6 +9,123 @@ package org.pasteque.coreutil.datatransfer.parser;
*/ */
public interface Writer public interface Writer
{ {
/**
* Add an int to the current array.
* @param value The value to write.
* @throws ParseException When writing from outside an array.
*/
public void writeInt(int value) throws ParseException;
/**
* Add an int to the current object.
* @param key The key of the value to write.
* @param value The value to write.
* @throws ParseException When writing from outside an object.
*/
public void writeInt(String key, int value) throws ParseException;
/**
* Add an int to the current array.
* @param value The value to write.
* @throws ParseException When writing from outside an array.
*/
public void writeDouble(double value) throws ParseException;
/**
* Add an int to the current object.
* @param key The key of the value to write.
* @param value The value to write.
* @throws ParseException When writing from outside an object.
*/
public void writeDouble(String key, double value) throws ParseException;
/**
* Add an int to the current array.
* @param value The value to write.
* @throws ParseException When writing from outside an array.
*/
public void writeBoolean(boolean value) throws ParseException;
/**
* Add an int to the current object.
* @param key The key of the value to write.
* @param value The value to write.
* @throws ParseException When writing from outside an object.
*/
public void writeBoolean(String key, boolean value) throws ParseException;
/**
* Add an int to the current array.
* @param value The value to write.
* @throws ParseException When writing from outside an array.
* @throws IllegalArgumentException When the value is null.
* Use {@link writeNull()} instead.
*/
public void writeString(String value) throws ParseException;
/**
* Add an int to the current object.
* @param key The key of the value to write.
* @param value The value to write.
* @throws ParseException When writing from outside an object.
* @throws IllegalArgumentException When the value is null.
* Use {@link writeNull()} instead.
*/
public void writeString(String key, String value) throws ParseException;
/**
* Add a null value to the current array.
* @throws ParseException When writing from outside an array.
*/
public void writeNull() throws ParseException;
/**
* Add a null value to the current object.
* @param key The key of the value to write.
* @throws ParseException When writing from outside an object.
*/
public void writeNull(String key) throws ParseException;
/**
* Start (create) a dictionary as the root element or inside an array.
* @throws ParseException When the root element is already created or
* not currently inside an array.
*/
public void startObject() throws ParseException;
/**
* Start (create) a dictionary as a child element.
* @param key The key to read in the current dictionary.
* @throws ParseException When writing a key from outside an object.
*/
public void startObject(String key) throws ParseException;
/**
* Finalize the current object and return up into the tree.
* @throws ParseException When the current element is not an object.
*/
public void endObject() throws ParseException;
/**
* Start (create) an array as the root element or inside an array.
* @throws ParseException When the root element is already created
* or not currently inside an array.
*/
public void startArray() throws ParseException;
/**
* Start (create) an array as a child element.
* @param key The key in the parent dictionary.
* @throws ParseException When writing a key from outside an object.
*/
public void startArray(String key) throws ParseException;
/**
* Finalize the current array and return up into the tree.
* @throws ParseException When the current element is not an array.
*/
public void endArray() throws ParseException;
/** /**
* Get the encoded data. * Get the encoded data.
* @return The encoded data. * @return The encoded data.

View file

@ -0,0 +1,193 @@
package org.pasteque.coreutil.extra;
import java.util.ArrayList;
import java.util.List;
import org.pasteque.coreutil.ImmutableList;
import org.pasteque.coreutil.ParseException;
import org.pasteque.coreutil.datatransfer.parser.Reader;
import org.pasteque.coreutil.datatransfer.parser.Writer;
/**
* Extra data as an array.
*/
public final class ExtraArray implements ExtraData
{
/** See {@link getField(). */
private final String field;
/** See {@link getValue()}. */
private final ImmutableList<ExtraData> value;
/** See {@link getType()}. */
private final ExtraType type;
/**
* Construct an array from a list of values.
* @param field The name of the field.
* @param type The type of data in the array.
* @param value The values in the array. Each data can have the index
* as field name.
* @throws IllegalArgumentException When the type of one value doesn't match
* the type of the array.
* @throws Error When one of the {@link ExtraType} is not handled.
*/
/* package */ ExtraArray(String field, ExtraType type, List<ExtraData> value)
throws IllegalArgumentException {
this.field = field;
this.type = type;
for (ExtraData extra : value) {
if (!this.type.checkExtraType(extra)) {
throw new IllegalArgumentException(String.format("Invalid type of data %s, expected %s", extra.getClass().toString(), type.getTypeExtraClass().toString()));
}
}
this.value = new ImmutableList<ExtraData>(value);
}
/**
* Construct an array from a list of values.
* @param field The name of the field.
* @param type The type of data in the array.
* @param value The values in the array. Each data can have the index
* as field name.
* @throws IllegalArgumentException When the type of one value doesn't match
* the type of the array.
* @throws Error When one of the {@link ExtraType} is not handled.
*/
/* package */ ExtraArray(String field, ExtraType type, ImmutableList<ExtraData> value)
throws IllegalArgumentException {
this.field = field;
this.type = type;
for (ExtraData extra : value) {
if (!this.type.checkExtraType(extra)) {
throw new IllegalArgumentException(String.format("Invalid type of data %s, expected %s", extra.getClass().toString(), type.getTypeExtraClass().toString()));
}
}
this.value = value;
}
/**
* Construct an array from a reader.
* @param field The name of the field.
* @param reader The reader to read data from. It must aready be pointing
* to the array.
* @throws ParseException When an error happens while reading the data.
*/
/* package */ ExtraArray(String field, Reader reader) throws ParseException {
ExtraType arrayType = ExtraType.fromCode(reader.readString("ta"));
reader.startArray("v");
List<ExtraData> data = new ArrayList<ExtraData>(reader.getArraySize());
for (int i = 0; i < reader.getArraySize(); i++) {
switch (arrayType) {
case STRING:
data.add(new ExtraString(String.valueOf(i), reader.readString(i)));
break;
case BOOLEAN:
data.add(new ExtraBoolean(String.valueOf(i), reader.readBoolean(i)));
break;
case INTEGER:
data.add(new ExtraInt(String.valueOf(i), reader.readInt(i)));
break;
case DOUBLE:
data.add(new ExtraDouble(String.valueOf(i), reader.readDouble(i)));
break;
case OBJECT:
reader.startObject(i);
try {
data.add(new ExtraObject(String.valueOf(i), reader));
} catch (ParseException e) {
reader.endObject();
reader.endArray();
throw e;
}
reader.endObject();
break;
case ARRAY:
reader.startObject(i);
try {
data.add(new ExtraArray(String.valueOf(i), reader));
} catch (ParseException e) {
reader.endObject();
reader.endArray();
throw e;
}
reader.endObject();
break;
case NULL:
data.add(new ExtraNull(String.valueOf(i)));
break;
default:
assert false;
}
}
reader.endArray();
this.field = field;
this.type = arrayType;
this.value = new ImmutableList<ExtraData>(data);
}
/**
* Get the field associated to this extra data.
* @return the field name.
*/
@Override // from ExtraData
public String getField() {
return this.field;
}
/**
* Get the type of value hold.
* @return The type of values.
*/
public ExtraType getType() {
return this.type;
}
@Override // from ExtraData
public ImmutableList<ExtraData> getValue() {
return this.value;
}
/**
* Write the content of this ExtraArray in the current writer object.
* The Writer must already be inside the object to write.
* @param to The writer to write to.
* @throws ParseException When an error occurs while writing.
*/
private void innerWrite(Writer to) throws ParseException {
to.writeString("t", ExtraType.ARRAY.getTypeCode());
to.writeString("ta", this.type.getTypeCode());
to.startArray("v");
for (ExtraData v : this.value) {
try {
if (v == null || this.type == ExtraType.NULL) {
to.writeNull();
} else if (this.type == ExtraType.STRING) {
to.writeString((String) v.getValue());
} else if (this.type == ExtraType.BOOLEAN) {
to.writeBoolean((Boolean) v.getValue());
} else if (this.type == ExtraType.INTEGER) {
to.writeInt((Integer) v.getValue());
} else if (this.type == ExtraType.DOUBLE) {
to.writeDouble((Double) v.getValue());
} else if (this.type == ExtraType.OBJECT) {
((ExtraObject) v).writeInArray(to);
} else if (this.type == ExtraType.ARRAY) {
to.startObject();
((ExtraArray) v).innerWrite(to);
to.endObject();
} else {
assert false;
}
} catch (ParseException e) {
to.endArray();
throw e;
}
}
to.endArray();
}
@Override // from ExtraData
public void write(Writer to) throws ParseException {
to.startObject(this.field);
this.innerWrite(to);
to.endObject();
}
}

View file

@ -0,0 +1,55 @@
package org.pasteque.coreutil.extra;
import org.pasteque.coreutil.ParseException;
import org.pasteque.coreutil.datatransfer.parser.Writer;
/**
* Extra data as a boolean.
*/
public final class ExtraBoolean implements ExtraData
{
/** See {@link getField(). */
private final String field;
/** See {@link getBoolean()}. */
private final boolean value;
/**
* Create an extra data.
* @param field The field name.
* @param value the value.
*/
/* package */ ExtraBoolean(String field, boolean value) {
this.field = field;
this.value = value;
}
/**
* Get the field associated to this extra data.
* @return the field name.
*/
@Override // from ExtraData
public String getField() {
return this.field;
}
/**
* Get value.
* @return The value.
*/
public boolean getBoolean() {
return this.value;
}
@Override // from ExtraData
public Object getValue() {
return Boolean.valueOf(this.value);
}
@Override // from ExtraData
public void write(Writer to) throws ParseException {
to.startObject(this.field);
to.writeString("t", ExtraType.BOOLEAN.getTypeCode());
to.writeBoolean("v", this.value);
to.endObject();
}
}

View file

@ -0,0 +1,372 @@
package org.pasteque.coreutil.extra;
import java.util.ArrayList;
import java.util.List;
/**
* <p>Generator to create and embed {@link org.pasteque.coreutil.extra.ExtraData}
* in a dedicated object.</p>
* <p>Create a builder and add fields for all extra data and close the builder
* to get the root {@link org.pasteque.coreutil.extra.ExtraObject}
* to pass to major objects.</p>
*/
public final class ExtraBuilder
{
/** The current object being built. Null when building an array. */
private TempExtraObject currentObject;
/** The current array being built. Null when building an object. */
private TempExtraArray currentArray;
/** The current branch of the tree of objects and array being built. */
private List<ExtraData> path;
/**
* Create an empty builder to create an {@link ExtraObject}.
* It will be already pointing to the root object and values can be added
* to it.
*/
public ExtraBuilder() {
this.path = new ArrayList<ExtraData>();
this.currentObject = new TempExtraObject(ExtraObject.EXTRA_ROOT_FIELD);
this.path.add(this.currentObject);
}
/**
* Check that the builder is currently building an object.
* @throws IllegalStateException When not currently building an object.
*/
private void checkCurrentObject() throws IllegalStateException {
if (this.currentObject == null) {
throw new IllegalStateException("ExtraBuilder is not currently building an object.");
}
}
/**
* Check that the builder is currently building an array.
* @throws IllegalStateException When not currently building an array.
*/
private void checkCurrentArray() throws IllegalStateException {
if (this.currentArray == null) {
throw new IllegalStateException("ExtraBuilder is not currently building an array.");
}
}
/**
* End building the current object or array and move up to the path
* to get back to editing the parent object or array.
* @throws IllegalStateException When already at the root object.
* @throws Error When the path contains anything but ExtraObject or ExtraArray.
*/
private void pathUp() throws IllegalStateException {
if (path.size() <= 1) {
throw new IllegalStateException("ExtraBuilder is already building the root object. Use close() instead.");
}
this.path.remove(this.path.size() - 1);
ExtraData last = this.path.get(this.path.size() - 1);
if (last instanceof TempExtraObject) {
this.currentObject = (TempExtraObject) last;
this.currentArray = null;
} else if (last instanceof TempExtraArray) {
this.currentObject = null;
this.currentArray = (TempExtraArray) last;
} else {
throw new Error(String.format("Corrupted ExtraBuilder path. Expecting TempExtraObject or TempExtraArray, found %s", last.getClass().toString()));
}
}
/**
* Start building a new object as a child of the current array.
* @throws IllegalStateException When not currently building an array.
*/
public void startObject() throws IllegalStateException {
this.checkCurrentArray();
TempExtraObject newObject = new TempExtraObject(String.valueOf(this.currentArray.size()));
this.currentArray.addValue(newObject);
this.path.add(newObject);
this.currentObject = newObject;
this.currentArray = null;
}
/**
* Start building a new object as a value of the current object.
* @param field The name of the field of the current object that will hold
* the new object.
* @throws IllegalStateException When not currently building an object.
*/
public void startObject(String field) throws IllegalStateException {
this.checkCurrentObject();
TempExtraObject newObject = new TempExtraObject(field);
this.currentObject.setValue(newObject);
this.path.add(newObject);
this.currentObject = newObject;
this.currentArray = null;
}
/**
* End building the current object and get back to editing its parent.
* @throws IllegalStateException When not currently building an object or
* when trying to end the root object.
*/
public void endObject() throws IllegalStateException {
this.checkCurrentObject();
this.pathUp();
}
/**
* Start building a new array as a child of the current array.
* @param type The type of data the array will contain.
* @throws IllegalStateException When not currently building an array.
*/
public void startArray(ExtraType type) throws IllegalStateException {
this.checkCurrentArray();
TempExtraArray array = new TempExtraArray(this.currentArray.size(), type);
this.currentArray.addValue(array);
this.path.add(array);
this.currentArray = array;
this.currentObject = null;
}
/**
* Start building a new array as a value of the current object.
* @param field The name of the field of the current object that will hold
* the new array.
* @param type The type of data the array will contain.
* @throws IllegalStateException When not currently building an object.
*/
public void startArray(String field, ExtraType type) throws IllegalStateException {
this.checkCurrentObject();
TempExtraArray array = new TempExtraArray(field, type);
this.currentObject.setValue(array);
this.path.add(array);
this.currentArray = array;
this.currentObject = null;
}
/**
* End building the current array and get back to editing its parent.
* @throws IllegalStateException When not currently building an array.
*/
public void endArray() throws IllegalStateException {
this.checkCurrentArray();
this.pathUp();
}
/**
* Add a null value to the current array.
* @throws IllegalStateException When not currently building an array.
*/
public void addNull() throws IllegalStateException {
this.checkCurrentArray();
this.currentArray.addValue(new ExtraNull(this.currentArray.size()));
}
/**
* Add a null value to the current object.
* @param field The name of the field that holds the value.
* @throws IllegalStateException When not currently building an object.
*/
public void addNull(String field) throws IllegalStateException {
this.checkCurrentObject();
ExtraNull value = new ExtraNull(field);
this.currentObject.setValue(value);
}
/**
* Add a value to the current array.
* @param value The value to add. It adds a null value instead when null.
* @throws IllegalStateException When not currently building an array.
* @throws IllegalArgumentException When not building an array of String.
*/
public void add(String value) throws IllegalStateException {
this.checkCurrentArray();
if (value == null) {
this.addNull();
} else {
this.currentArray.addValue(new ExtraString(this.currentArray.size(), value));
}
}
/**
* Add a value to the current object.
* @param field The name of the field that holds the value.
* @param value The value to add. It adds a null value instead when null.
* @throws IllegalStateException When not currently building an object.
*/
public void add(String field, String value) throws IllegalStateException {
this.checkCurrentObject();
if (value == null) {
this.addNull(field);
} else {
this.currentObject.setValue(new ExtraString(field, value));
}
}
/**
* Add a value to the current array.
* @param value The value to add.
* @throws IllegalStateException When not currently building an array.
* @throws IllegalArgumentException When not building an array of Integers.
*/
public void add(int value) throws IllegalStateException {
this.checkCurrentArray();
this.currentArray.addValue(new ExtraInt(this.currentArray.size(), value));
}
/**
* Add a value to the current object.
* @param field The name of the field that holds the value.
* @param value The value to add.
* @throws IllegalStateException When not currently building an object.
*/
public void add(String field, int value) throws IllegalStateException {
this.checkCurrentObject();
this.currentObject.setValue(new ExtraInt(field, value));
}
/**
* Stop building extra data and get the final object.
* Once close is called, no other operation can be done.
* @return The finalized extra data to pass to a major object.
*/
public ExtraObject close() {
TempExtraObject root = (TempExtraObject) this.path.get(0);
this.path.clear();
this.currentObject = null;
this.currentArray = null;
return (ExtraObject) root.finalizeExtra();
}
/**
* Interface to convert local temporary extra object and array
* to the definitive extra data.
*/
private interface TempExtra {
/**
* Convert the temporary extra to the definitive one.
* @return An immutable extra data.
*/
public ExtraData finalizeExtra();
}
/**
* A buildable extra object.
*/
private class TempExtraObject implements ExtraData, TempExtra
{
private List<ExtraData> data;
private String field;
public TempExtraObject(String field) {
this.data = new ArrayList<ExtraData>();
this.field = field;
}
/**
* Set or replace a value to the current object.
* If the field is already set, it is replaced.
* @param value The value to add.
*/
private void setValue(ExtraData value) {
for (int i = 0; i < this.data.size(); i++) {
ExtraData v = this.data.get(i);
if (value.getField().equals(v.getField())) {
this.data.set(i, value);
return;
}
}
this.data.add(value);
}
@Override // from ExtraData
public String getField() {
return this.field;
}
@Override // from ExtraData
public ExtraData getValue() {
return this.finalizeExtra();
}
/**
* Does nothing.
* @param w Not used.
*/
@Override // from ExtraData
public void write(org.pasteque.coreutil.datatransfer.parser.Writer w) {}
@Override // from TempExtra
public ExtraData finalizeExtra() {
for (int i = 0; i < this.data.size(); i++) {
ExtraData v = this.data.get(i);
if ((v instanceof TempExtra)) {
this.data.set(i, ((TempExtra) v).finalizeExtra());
}
}
return new ExtraObject(this.field, this.data);
}
}
/**
* A buildable extra array.
*/
private class TempExtraArray implements ExtraData, TempExtra
{
private List<ExtraData> data;
private String field;
private ExtraType type;
public TempExtraArray(String field, ExtraType type) {
this.data = new ArrayList<ExtraData>();
this.field = field;
this.type = type;
}
/**
* Get the size of the array as a string for the name of the next
* element to add.
* @return The size of the array as a string.
*/
public String size() {
return String.valueOf(data.size());
}
/**
* Add a value to the array.
* @param value The value to add.
* @throws IllegalArgumentException When the type of one value doesn't match
* the type of the array.
*/
private void addValue(ExtraData value) throws IllegalArgumentException {
if (!this.type.checkExtraType(value)) {
throw new IllegalArgumentException(String.format("Invalid type of data %s, expected %s", value.getClass().toString(), this.type.getTypeExtraClass().toString()));
}
this.data.add(value);
}
@Override // from ExtraData
public String getField() {
return this.field;
}
@Override // from ExtraData
public ExtraData getValue() {
return this.finalizeExtra();
}
/**
* Does nothing.
* @param w Not used.
*/
@Override // from ExtraData
public void write(org.pasteque.coreutil.datatransfer.parser.Writer w) {}
@Override // from TempExtra
public ExtraData finalizeExtra() {
for (int i = 0; i < this.data.size(); i++) {
ExtraData v = this.data.get(i);
if ((v instanceof TempExtra)) {
this.data.set(i, ((TempExtra) v).finalizeExtra());
}
}
return new ExtraArray(this.field, this.type, this.data);
}
}}

View file

@ -0,0 +1,31 @@
package org.pasteque.coreutil.extra;
import org.pasteque.coreutil.ParseException;
import org.pasteque.coreutil.datatransfer.parser.Writer;
/**
* Data outside the minimal ones to be passed to the major version.
*/
public interface ExtraData
{
/**
* Get the name of the field this data belongs to.
* @return The name of the field.
*/
public String getField();
/**
* Get the value of the data as an object.
* @return The value.
*/
public Object getValue();
/**
* Write the data to a writer.
* @param to The writer to put the data in. The data is not responsible
* of the state of the writer. The object holding the extra data must
* ensure the writer is in a correct state.
* @throws ParseException When the writer is in an incorrect state.
*/
public void write(Writer to) throws ParseException;
}

View file

@ -0,0 +1,55 @@
package org.pasteque.coreutil.extra;
import org.pasteque.coreutil.ParseException;
import org.pasteque.coreutil.datatransfer.parser.Writer;
/**
* Extra data as a double.
*/
public final class ExtraDouble implements ExtraData
{
/** See {@link getField(). */
private final String field;
/** See {@link getDouble()}. */
private final double value;
/**
* Create an extra data.
* @param field The field name.
* @param value the value.
*/
/* package */ ExtraDouble(String field, double value) {
this.field = field;
this.value = value;
}
/**
* Get the field associated to this extra data.
* @return the field name.
*/
@Override // from ExtraData
public String getField() {
return this.field;
}
/**
* Get value.
* @return The value.
*/
public double getDouble() {
return this.value;
}
@Override // from ExtraData
public Object getValue() {
return Double.valueOf(this.value);
}
@Override // from ExtraData
public void write(Writer to) throws ParseException {
to.startObject(this.field);
to.writeString("t", ExtraType.DOUBLE.getTypeCode());
to.writeDouble("v", this.value);
to.endObject();
}
}

View file

@ -0,0 +1,55 @@
package org.pasteque.coreutil.extra;
import org.pasteque.coreutil.ParseException;
import org.pasteque.coreutil.datatransfer.parser.Writer;
/**
* Extra data as an int.
*/
public final class ExtraInt implements ExtraData
{
/** See {@link getField(). */
private final String field;
/** See {@link getInt()}. */
private final int value;
/**
* Create an extra data.
* @param field The field name.
* @param value the value.
*/
/* package */ ExtraInt(String field, int value) {
this.field = field;
this.value = value;
}
/**
* Get the field associated to this extra data.
* @return the field name.
*/
@Override // from ExtraData
public String getField() {
return this.field;
}
/**
* Get value.
* @return The value.
*/
public int getInt() {
return this.value;
}
@Override // from ExtraData
public Object getValue() {
return Integer.valueOf(this.value);
}
@Override // from ExtraData
public void write(Writer to) throws ParseException {
to.startObject(this.field);
to.writeString("t", ExtraType.INTEGER.getTypeCode());
to.writeInt("v", this.value);
to.endObject();
}
}

View file

@ -0,0 +1,44 @@
package org.pasteque.coreutil.extra;
import org.pasteque.coreutil.ParseException;
import org.pasteque.coreutil.datatransfer.parser.Writer;
/**
* Extra data holding a null value. Use this class instead of
* typed extra data with a null value.
*/
public final class ExtraNull implements ExtraData
{
/** See {@link getField(). */
private final String field;
/**
* Create an extra data.
* @param field The field name.
*/
/* package */ ExtraNull(String field) {
this.field = field;
}
/**
* Get the field associated to this extra data.
* @return the field name.
*/
@Override // from ExtraData
public String getField() {
return this.field;
}
@Override // from ExtraData
public Object getValue() {
return null;
}
@Override // from ExtraData
public void write(Writer to) throws ParseException {
to.startObject(this.field);
to.writeString("t", ExtraType.NULL.getTypeCode());
to.writeNull("v");
to.endObject();
}
}

View file

@ -0,0 +1,200 @@
package org.pasteque.coreutil.extra;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.pasteque.coreutil.ImmutableList;
import org.pasteque.coreutil.ParseException;
import org.pasteque.coreutil.datatransfer.parser.Reader;
import org.pasteque.coreutil.datatransfer.parser.Writer;
/**
* Collection of {@link org.pasteque.coreutil.extra.ExtraData}
* to extend major classes. An extra object is the root of the extra data
* and can contain other extra objects as well.
*/
public final class ExtraObject implements ExtraData
{
/**
* The name of the field for the root element of extra data.
*/
public static final String EXTRA_ROOT_FIELD = "extra";
/** See {@link getField(). */
private final String field;
/** See {@link getObject(). */
private final ImmutableList<ExtraData> value;
/**
* Sort extra data by key and return an ordered list of them.
* @param data The maybe unsorted list of extra data.
* @return An immutable list of extra data containing all extra data
* sorted alphabetically by their key.
* @throws IllegalArgumentException When multiple extra data shares the
* same key.
*/
private static ImmutableList<ExtraData> sortExtraKeys(Iterable<ExtraData> data)
throws IllegalArgumentException {
List<String> keys = new ArrayList<String>();
List<ExtraData> sorted = new ArrayList<ExtraData>();
for (ExtraData d : data) {
keys.add(d.getField());
}
Collections.sort(keys);
String lastKey = null;
for (String key : keys) {
if (key.equals(lastKey)) {
throw new IllegalArgumentException(String.format("Key %s is set multiple times in extra object.", key));
}
for (ExtraData d : data) {
if (d.getField().equals(key)) {
sorted.add(d);
break;
}
}
lastKey = key;
}
return new ImmutableList<ExtraData>(sorted);
}
/**
* Create an empty extra data as the root element.
*/
public ExtraObject() {
this(EXTRA_ROOT_FIELD, new ImmutableList<ExtraData>());
}
/**
* Create an extra data as the root element.
* @param value the value.
* @throws IllegalArgumentException When multiple extra data shares the
* same key.
*/
/* package */ ExtraObject(List<ExtraData> data) {
this(EXTRA_ROOT_FIELD, data);
}
/**
* Create an extra data.
* @param value the value.
* @throws IllegalArgumentException When multiple extra data shares the
* same key.
*/
/* package */ ExtraObject(String field, List<ExtraData> data) {
this.field = field;
this.value = sortExtraKeys(data);
}
/**
* Create an extra data.
* @param value the value.
* @throws IllegalArgumentException When multiple extra data shares the
* same key.
*/
/* package */ ExtraObject(String field, ImmutableList<ExtraData> data) {
this.field = field;
this.value = sortExtraKeys(data);
}
/**
* Instantiate from raw data from a reader.
* @param key The key to assign to this extra object.
* @param reader The reader that must be currently pointing to this object.
* @throws IllegalArgumentException When multiple extra data shares the
* same key.
* @throws ParseException When an error occurs while parsing the object.
* See {@link org.pasteque.coreutil.datatransfer.parser.Reader} for details.
*/
/* package */ ExtraObject(String key, Reader reader)
throws ParseException, IllegalArgumentException {
List<String> keys = reader.listKeys();
List<ExtraData> data = new ArrayList<ExtraData>(keys.size());
for (String extraKey : keys) {
reader.startObject(extraKey);
String typeCode = reader.readString("t");
ExtraType type = ExtraType.fromCode(typeCode);
switch (type) {
case STRING:
data.add(new ExtraString(extraKey, reader.readString("v")));
break;
case BOOLEAN:
data.add(new ExtraBoolean(extraKey, reader.readBoolean("v")));
break;
case INTEGER:
data.add(new ExtraInt(extraKey, reader.readInt("v")));
break;
case DOUBLE:
data.add(new ExtraDouble(extraKey, reader.readDouble("v")));
break;
case OBJECT:
data.add(new ExtraObject(extraKey, reader));
break;
case ARRAY:
data.add(new ExtraArray(extraKey, reader));
case NULL:
data.add(new ExtraNull(extraKey));
break;
default:
assert false;
}
reader.endObject();
}
this.field = key;
this.value = sortExtraKeys(data);
}
/**
* Instantiate from raw data from a reader.
* @param r The reader that must be currently pointing to this object.
* @throws ParseException When an error occurs while parsing the object.
* See {@link org.pasteque.coreutil.datatransfer.parser.Reader} for details.
*/
public ExtraObject(Reader r) throws ParseException {
this(EXTRA_ROOT_FIELD, r);
}
@Override // from ExtraData
public String getField() {
return this.field;
}
@Override // from ExtraData
public Object getValue() {
return this.value;
}
/**
* Write this object in an {@link ExtraArray} without providing a field
* @param to The write to write this object to.
* @throws ParseException When an error occurs while writing a field.
*/
/* package */ void writeInArray(Writer to) throws ParseException {
to.startObject();
for (ExtraData d : this.value) {
try {
d.write(to);
} catch (ParseException e) {
to.endObject();
throw e;
}
}
to.endObject();
}
@Override // from ExtraData
public void write(Writer to) throws ParseException {
to.startObject(this.field);
to.writeString("t", ExtraType.OBJECT.getTypeCode());
to.startObject("v");
for (ExtraData d : this.value) {
try {
d.write(to);
} catch (ParseException e) {
to.endObject();
to.endObject();
throw e;
}
}
to.endObject();
to.endObject();
}
}

View file

@ -0,0 +1,61 @@
package org.pasteque.coreutil.extra;
import org.pasteque.coreutil.ParseException;
import org.pasteque.coreutil.datatransfer.parser.Writer;
/**
* Extra data as a {@link java.lang.String}. This can also holds the reference
* of an associated object.
*/
public final class ExtraString implements ExtraData
{
/** See {@link getField(). */
private final String field;
/** See {@link getString()}. */
private final String value;
/**
* Create an extra data.
* @param field The field name.
* @param value the value.
* @throws InvalidArgumentException When value is null.
* @see org.pasteque.coreutil.extra.ExtraNull
*/
/* package */ ExtraString(String field, String value) {
if (value == null) {
throw new IllegalArgumentException("ExtraData cannot have a null value. Use ExtraNull instead.");
}
this.field = field;
this.value = value;
}
/**
* Get the field associated to this extra data.
* @return the field name.
*/
@Override // from ExtraData
public String getField() {
return this.field;
}
/**
* Get value.
* @return The value.
*/
public String getString() {
return this.value;
}
@Override // from ExtraData
public Object getValue() {
return this.value;
}
@Override // from ExtraData
public void write(Writer to) throws ParseException {
to.startObject(this.field);
to.writeString("t", ExtraType.STRING.getTypeCode());
to.writeString("v", this.value);
to.endObject();
}
}

View file

@ -0,0 +1,116 @@
package org.pasteque.coreutil.extra;
import java.util.List;
import java.util.Map;
/**
* Enumeration of available data types}.
*/
public enum ExtraType
{
/** Type of {@link java.lang.String}, matching {@link ExtraString} data. */
STRING("s", String.class, ExtraString.class),
/** Type of boolean data. */
BOOLEAN("b", Boolean.class, ExtraBoolean.class),
/** Type of integer data. */
INTEGER("i", Integer.class, ExtraInt.class),
/** Type of float/double data. */
DOUBLE("d", Double.class, ExtraDouble.class),
/** Type of object data. */
OBJECT("o", Map.class, ExtraObject.class),
/** Type of array data. */
ARRAY("a", List.class, ExtraArray.class),
/** Type of null data. */
NULL("n", null, ExtraNull.class);
/** See {@link getTypeCode()}. */
private final String typeCode;
/** See {@link getTypeClass()}. */
private final Class<?> type;
/** See {@link getTypeExtraClass()}. */
private final Class<? extends ExtraData> extraType;
/**
* Get a type from its type code.
* @param code The code value.
* @return The according enumeration value.
* @throws IllegalArgumentException When code is not found
* within the enumerated values
*/
public static final ExtraType fromCode(String code) throws IllegalArgumentException {
for (ExtraType v : ExtraType.values()) {
if (v.getTypeCode().equals(code)) {
return v;
}
}
throw new IllegalArgumentException(code);
}
/**
* Get the type of an extra data.
* @param data The extra data to check.
* @return The type of that extra data.
*/
public static final ExtraType fromExtra(ExtraData data) {
for (ExtraType v : ExtraType.values()) {
if (v.checkExtraType(data)) {
return v;
}
}
throw new Error(String.format("Unknown ExtraData type %s", data.getClass().toString()));
}
/**
* Internal constructor.
* @param typeCode The code to identify the type.
* @param type The expected java class.
* @param extraType The expected {@link ExtraData} implementation class.
*/
private ExtraType(String typeCode, Class<?> type, Class<? extends ExtraData> extraType) {
this.typeCode = typeCode;
this.type = type;
this.extraType = extraType;
}
/**
* Get the associated constant.
* @return The code for DTO.
*/
public String getTypeCode() {
return this.typeCode;
}
/**
* Get the expected java class of this type.
* @return A java class, like String.class.
*/
public Class<?> getTypeClass() {
return this.type;
}
/**
* Get the expected {@link ExtraData} implementation class.
* @return An {@link ExtraData} implementation, like {@link ExtraString}.
*/
public Class<? extends ExtraData> getTypeExtraClass() {
return this.extraType;
}
/**
* Check if an object is the same java type as this type expects.
* @param o The object to check.
* @return True if the object is acceptable for this type.
*/
public boolean checkRawType(Object o) {
return this.type.isInstance(o);
}
/**
* Check if an extra object is the same type as this type expects.
* @param o The extra object.
* @return True if the object is the same extra type or an {@link ExtraNull}.
*/
public boolean checkExtraType(ExtraData o) {
return (this.extraType.isInstance(o)) || (o instanceof ExtraNull);
}
}

View file

@ -0,0 +1,16 @@
/**
* <p>Non-mandatory data to pass to the major version. Use an
* {@link org.pasteque.coreutil.extra.ExtraBuilder} to
* remove the semantic from model classes to pass them to major data
* that don't care about their meaning.</p>
* <p>An {@link org.pasteque.coreutil.extra.ExtraObject} is composed of
* types of {@link org.pasteque.coreutil.extra.ExtraData} for typed
* values. All values of {@link org.pasteque.coreutil.extra.ExtraData}
* implementations are non-null. When the value is null, use an explicit
* {@link org.pasteque.coreutil.extra.ExtraNull}.</p>
* <p>Extra objects will be found only in the major classes and their
* associated DTO from coreutil. Other packages will have the semantic values
* instead and convert them to extra data only when creating a major version
* of itself through transition interfaces.</p>
*/
package org.pasteque.coreutil.extra;

View file

@ -1,6 +1,7 @@
package org.pasteque.coreutil.transition; package org.pasteque.coreutil.transition;
import org.pasteque.coreutil.ImmutableList; import org.pasteque.coreutil.ImmutableList;
import org.pasteque.coreutil.extra.ExtraObject;
import org.pasteque.coreutil.price.Discount; import org.pasteque.coreutil.price.Discount;
import org.pasteque.coreutil.price.Price; import org.pasteque.coreutil.price.Price;
import org.pasteque.coreutil.price.Quantity; import org.pasteque.coreutil.price.Quantity;
@ -63,4 +64,12 @@ public interface LineTransition {
* @return The full discount applied to the base price. * @return The full discount applied to the base price.
*/ */
public Discount getFinalDiscount(); public Discount getFinalDiscount();
/**
* Get all other data.
* Implementations should use an {@link org.pasteque.coreutil.extra.ExtraBuilder}
* to remove the semantic of all non-mandatory fields.
* @return The root object of extra data.
*/
public ExtraObject getExtra();
} }

View file

@ -1,6 +1,8 @@
package org.pasteque.coreutil.transition; package org.pasteque.coreutil.transition;
import org.pasteque.coreutil.ImmutableList; import org.pasteque.coreutil.ImmutableList;
import org.pasteque.coreutil.extra.ExtraObject;
import org.pasteque.coreutil.price.Discount;
import org.pasteque.coreutil.price.FinalTaxAmount; import org.pasteque.coreutil.price.FinalTaxAmount;
import org.pasteque.coreutil.price.Price2; import org.pasteque.coreutil.price.Price2;
@ -32,4 +34,18 @@ public interface OrderTransition
* @return The content of the order. * @return The content of the order.
*/ */
public ImmutableList<LineTransition> getLines(); public ImmutableList<LineTransition> getLines();
/**
* Get the discount applied to the whole order.
* @return The discount applied to the whole order.
*/
public Discount getDiscount();
/**
* Get all other data.
* Implementations should use an {@link org.pasteque.coreutil.extra.ExtraBuilder}
* to remove the semantic of all non-mandatory fields.
* @return The root object of extra data.
*/
public ExtraObject getExtra();
} }

View file

@ -1,6 +1,7 @@
package org.pasteque.major.domain; package org.pasteque.major.domain;
import org.pasteque.coreutil.datatransfer.dto.CashRegisterDTO; import org.pasteque.coreutil.datatransfer.dto.CashRegisterDTO;
import org.pasteque.coreutil.extra.ExtraObject;
/** /**
* <p>Model for a cash register. Tickets are associated to a cash register * <p>Model for a cash register. Tickets are associated to a cash register
@ -14,6 +15,8 @@ public class MajorCashRegister
private String label; private String label;
/** {@see getNextTicketNumber()} */ /** {@see getNextTicketNumber()} */
private int nextTicketNumber; private int nextTicketNumber;
/** See {@link getExtra()}. */
private ExtraObject extra;
/** /**
* Create from all fields. * Create from all fields.
@ -21,24 +24,28 @@ public class MajorCashRegister
* @param label See {@link getLabel()}. * @param label See {@link getLabel()}.
* @param nextTicketNumber The number to assign to the next ticket * @param nextTicketNumber The number to assign to the next ticket
* from this cash register. * from this cash register.
* @param extra See {@link getExtra()}.
*/ */
public MajorCashRegister( public MajorCashRegister(
String reference, String reference,
String label, String label,
int nextTicketNumber) { int nextTicketNumber,
ExtraObject extra) {
this.reference = reference; this.reference = reference;
this.label = label; this.label = label;
this.nextTicketNumber = nextTicketNumber; this.nextTicketNumber = nextTicketNumber;
this.extra = extra;
} }
/** /**
* Create from a DTO. All data are copied to break references. * Create from a DTO.
* @param dto The DTO to convert. * @param dto The DTO to convert.
*/ */
public MajorCashRegister(CashRegisterDTO dto) { public MajorCashRegister(CashRegisterDTO dto) {
this.reference = new String(dto.getReference()); this.reference = dto.getReference();
this.label = new String(dto.getLabel()); this.label = dto.getLabel();
this.nextTicketNumber = dto.getNextTicketNumber(); this.nextTicketNumber = dto.getNextTicketNumber();
this.extra = dto.getExtra();
} }
/** /**
@ -77,4 +84,12 @@ public class MajorCashRegister
/* package */ final void revertNextTicketNumber() { /* package */ final void revertNextTicketNumber() {
this.nextTicketNumber--; this.nextTicketNumber--;
} }
/**
* Get all other data.
* @return The root object of extra data.
*/
public final ExtraObject getExtra() {
return this.extra;
}
} }

View file

@ -3,10 +3,10 @@ package org.pasteque.major.domain;
import java.util.Date; import java.util.Date;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import org.pasteque.coreutil.datatransfer.dto.CashSessionDTO; import org.pasteque.coreutil.datatransfer.dto.CashSessionDTO;
import org.pasteque.coreutil.datatransfer.dto.FiscalTicketDTO; import org.pasteque.coreutil.datatransfer.dto.FiscalTicketDTO;
import org.pasteque.coreutil.datatransfer.dto.MovementDTO; import org.pasteque.coreutil.datatransfer.dto.MovementDTO;
import org.pasteque.coreutil.extra.ExtraObject;
/** /**
* <p>Ongoing cash session, managing movements and payments.</p> * <p>Ongoing cash session, managing movements and payments.</p>
@ -32,6 +32,8 @@ public final class MajorCashSession
private List<MajorTicket> tickets; private List<MajorTicket> tickets;
/** See {@link isClosed()}. */ /** See {@link isClosed()}. */
private boolean closed; private boolean closed;
/** See {@link getExtra()}. */
private ExtraObject extra;
/** /**
* Create a cash session from all fields. * Create a cash session from all fields.
@ -41,6 +43,7 @@ public final class MajorCashSession
* @param openDate See {@link getOpenDate()}. * @param openDate See {@link getOpenDate()}.
* @param movements The list of movements registered during this session. * @param movements The list of movements registered during this session.
* @param tickets The list of tickets already registered during this session. * @param tickets The list of tickets already registered during this session.
* @param extra See {@link getExtra()}.
*/ */
public MajorCashSession( public MajorCashSession(
MajorCashRegister cashRegister, MajorCashRegister cashRegister,
@ -48,7 +51,8 @@ public final class MajorCashSession
boolean continuous, boolean continuous,
Date openDate, Date openDate,
List<Movement> movements, List<Movement> movements,
List<MajorTicket> tickets) { List<MajorTicket> tickets,
ExtraObject extra) {
this.cashRegister = cashRegister; this.cashRegister = cashRegister;
this.sequence = sequence; this.sequence = sequence;
this.continuous = continuous; this.continuous = continuous;
@ -56,6 +60,7 @@ public final class MajorCashSession
this.movements = movements; this.movements = movements;
this.tickets = tickets; this.tickets = tickets;
this.closed = false; this.closed = false;
this.extra = extra;
} }
/** /**
@ -239,4 +244,12 @@ public final class MajorCashSession
public Date getOpenDate() { public Date getOpenDate() {
return openDate; return openDate;
} }
/**
* Get all other data.
* @return The root object of extra data.
*/
public final ExtraObject getExtra() {
return this.extra;
}
} }

View file

@ -1,6 +1,7 @@
package org.pasteque.major.domain; package org.pasteque.major.domain;
import org.pasteque.coreutil.ImmutableList; import org.pasteque.coreutil.ImmutableList;
import org.pasteque.coreutil.extra.ExtraObject;
import org.pasteque.coreutil.price.Discount; import org.pasteque.coreutil.price.Discount;
import org.pasteque.coreutil.price.Price; import org.pasteque.coreutil.price.Price;
import org.pasteque.coreutil.price.Quantity; import org.pasteque.coreutil.price.Quantity;
@ -15,7 +16,6 @@ import org.pasteque.coreutil.transition.LineTransition;
* @see org.pasteque.major.domain.MajorOrder * @see org.pasteque.major.domain.MajorOrder
* @see org.pasteque.major.domain.MajorTicket * @see org.pasteque.major.domain.MajorTicket
*/ */
// TODO add extradata to pass to MajorTicket
public final class MajorLine implements LineTransition public final class MajorLine implements LineTransition
{ {
/** See {@link getProductReference()}. */ /** See {@link getProductReference()}. */
@ -34,6 +34,8 @@ public final class MajorLine implements LineTransition
private final Price totalPrice; private final Price totalPrice;
/** See {@link getFinalDiscount()}. */ /** See {@link getFinalDiscount()}. */
private final Discount finalDiscount; private final Discount finalDiscount;
/** See {@link getExtra()}. */
private final ExtraObject extra;
/** /**
* <p>Create a major line from outside this package. * <p>Create a major line from outside this package.
@ -61,6 +63,7 @@ public final class MajorLine implements LineTransition
* @param totalTaxes See {@link getTotalTaxes()}. * @param totalTaxes See {@link getTotalTaxes()}.
* @param totalPrice See {@link getTotalPrice()}. * @param totalPrice See {@link getTotalPrice()}.
* @param finalDiscount See {@link getFinalDiscount()}. * @param finalDiscount See {@link getFinalDiscount()}.
* @param extra See {@link getExtra()}.
*/ */
/* package */ MajorLine( /* package */ MajorLine(
String productReference, String productReference,
@ -70,7 +73,8 @@ public final class MajorLine implements LineTransition
Price price, Price price,
ImmutableList<TaxAmount> totalTaxes, ImmutableList<TaxAmount> totalTaxes,
Price totalPrice, Price totalPrice,
Discount finalDiscount) { Discount finalDiscount,
ExtraObject extra) {
this.productReference = productReference; this.productReference = productReference;
this.productLabel = productLabel; this.productLabel = productLabel;
this.unitPrice = unitPrice; this.unitPrice = unitPrice;
@ -79,6 +83,7 @@ public final class MajorLine implements LineTransition
this.totalTaxes = totalTaxes; this.totalTaxes = totalTaxes;
this.totalPrice = totalPrice; this.totalPrice = totalPrice;
this.finalDiscount = finalDiscount; this.finalDiscount = finalDiscount;
this.extra = extra;
} }
/** /**
@ -94,6 +99,7 @@ public final class MajorLine implements LineTransition
this.totalTaxes = source.getTotalTaxes(); this.totalTaxes = source.getTotalTaxes();
this.totalPrice = source.getTotalPrice(); this.totalPrice = source.getTotalPrice();
this.finalDiscount = source.getFinalDiscount(); this.finalDiscount = source.getFinalDiscount();
this.extra = source.getExtra();
} }
@Override // from LineTransition @Override // from LineTransition
@ -135,4 +141,9 @@ public final class MajorLine implements LineTransition
public Discount getFinalDiscount() { public Discount getFinalDiscount() {
return this.finalDiscount; return this.finalDiscount;
} }
@Override // from LineTransition
public ExtraObject getExtra() {
return this.extra;
}
} }

View file

@ -1,6 +1,8 @@
package org.pasteque.major.domain; package org.pasteque.major.domain;
import org.pasteque.coreutil.ImmutableList; import org.pasteque.coreutil.ImmutableList;
import org.pasteque.coreutil.extra.ExtraObject;
import org.pasteque.coreutil.price.Discount;
import org.pasteque.coreutil.price.FinalTaxAmount; import org.pasteque.coreutil.price.FinalTaxAmount;
import org.pasteque.coreutil.price.Price2; import org.pasteque.coreutil.price.Price2;
import org.pasteque.coreutil.transition.LineTransition; import org.pasteque.coreutil.transition.LineTransition;
@ -13,13 +15,15 @@ import org.pasteque.coreutil.transition.OrderTransition;
* for ease of use, but instances are not expected to be generated from * for ease of use, but instances are not expected to be generated from
* themselves.</p> * themselves.</p>
*/ */
// TODO add extradata to pass to MajorTicket
public final class MajorOrder implements OrderTransition public final class MajorOrder implements OrderTransition
{ {
private final Price2 finalPrice; private final Price2 finalPrice;
private final ImmutableList<FinalTaxAmount> taxAmounts; private final ImmutableList<FinalTaxAmount> taxAmounts;
private final Price2 finalTaxedPrice; private final Price2 finalTaxedPrice;
private final ImmutableList<MajorLine> lines; private final ImmutableList<MajorLine> lines;
private final Discount discount;
/** See {@link getExtra()}. */
private final ExtraObject extra;
/** /**
* Create a major order from all data. * Create a major order from all data.
@ -27,16 +31,22 @@ public final class MajorOrder implements OrderTransition
* @param taxAmounts See {@link getTaxAmounts()}. * @param taxAmounts See {@link getTaxAmounts()}.
* @param finalTaxedPrice See {@link getFinalTaxedPrice()}. * @param finalTaxedPrice See {@link getFinalTaxedPrice()}.
* @param lines See {@link getLines()}. * @param lines See {@link getLines()}.
* @param discount See {@link getDiscount()}.
* @param extra See {@link getExtra()}.
*/ */
public MajorOrder( public MajorOrder(
Price2 finalPrice, Price2 finalPrice,
ImmutableList<FinalTaxAmount> taxAmounts, ImmutableList<FinalTaxAmount> taxAmounts,
Price2 finalTaxedPrice, Price2 finalTaxedPrice,
ImmutableList<MajorLine> lines) { ImmutableList<MajorLine> lines,
Discount discount,
ExtraObject extra) {
this.finalPrice = finalPrice; this.finalPrice = finalPrice;
this.taxAmounts = taxAmounts; this.taxAmounts = taxAmounts;
this.finalTaxedPrice = finalTaxedPrice; this.finalTaxedPrice = finalTaxedPrice;
this.lines = lines; this.lines = lines;
this.discount = discount;
this.extra = extra;
} }
/** /**
@ -60,10 +70,13 @@ public final class MajorOrder implements OrderTransition
trans.getPrice(), trans.getPrice(),
trans.getTotalTaxes(), trans.getTotalTaxes(),
trans.getTotalPrice(), trans.getTotalPrice(),
trans.getFinalDiscount()); trans.getFinalDiscount(),
trans.getExtra());
} }
this.lines = MajorLine.fromTransition(order.getLines()); this.lines = MajorLine.fromTransition(order.getLines());
this.discount = order.getDiscount();
this.extra = order.getExtra();
} }
/** /**
@ -110,4 +123,20 @@ public final class MajorOrder implements OrderTransition
public ImmutableList<MajorLine> getMajorLines() { public ImmutableList<MajorLine> getMajorLines() {
return this.lines; return this.lines;
} }
/**
* Get the discount applied to the whole order.
* @return The discount applied to the whole order.
*/
public Discount getDiscount() {
return this.discount;
}
/**
* Get all other data.
* @return The root object of extra data.
*/
public ExtraObject getExtra() {
return this.extra;
}
} }

View file

@ -3,6 +3,7 @@ package org.pasteque.major.domain;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import org.pasteque.coreutil.constants.FiscalTicketType; import org.pasteque.coreutil.constants.FiscalTicketType;
import org.pasteque.coreutil.extra.ExtraObject;
import org.pasteque.coreutil.price.Price2; import org.pasteque.coreutil.price.Price2;
import org.pasteque.coreutil.price.TaxAmount; import org.pasteque.coreutil.price.TaxAmount;
import org.pasteque.coreutil.ImmutableList; import org.pasteque.coreutil.ImmutableList;
@ -38,7 +39,8 @@ public final class MajorTicket
private Price2 finalTaxedPrice; private Price2 finalTaxedPrice;
/** See {@link getFinalPrice(). */ /** See {@link getFinalPrice(). */
private Price2 finalPrice; private Price2 finalPrice;
// TODO: add extra data /** See {@link getExtra(). */
private ExtraObject extra;
/** /**
* Create by linking an order and payments. It will create the associated * Create by linking an order and payments. It will create the associated
@ -115,7 +117,7 @@ public final class MajorTicket
* @return The payment date, when the ticket was created.. * @return The payment date, when the ticket was created..
*/ */
public Date getDate() { public Date getDate() {
return date; return this.date;
} }
/** /**
@ -123,7 +125,7 @@ public final class MajorTicket
* @return The content of the ticket. * @return The content of the ticket.
*/ */
public ImmutableList<MajorLine> getLines() { public ImmutableList<MajorLine> getLines() {
return lines; return this.lines;
} }
/** /**
@ -131,7 +133,7 @@ public final class MajorTicket
* @return The list of payments used to pay the ticket. * @return The list of payments used to pay the ticket.
*/ */
public ImmutableList<Payment> getPayments() { public ImmutableList<Payment> getPayments() {
return payments; return this.payments;
} }
/** /**
@ -139,7 +141,7 @@ public final class MajorTicket
* @return The list of tax amounts. * @return The list of tax amounts.
*/ */
public ImmutableList<TaxAmount> getTaxAmounts() { public ImmutableList<TaxAmount> getTaxAmounts() {
return taxAmounts; return this.taxAmounts;
} }
/** /**
@ -147,7 +149,7 @@ public final class MajorTicket
* @return The total price. * @return The total price.
*/ */
public Price2 getFinalTaxedPrice() { public Price2 getFinalTaxedPrice() {
return finalTaxedPrice; return this.finalTaxedPrice;
} }
/** /**
@ -155,6 +157,14 @@ public final class MajorTicket
* @return The total price without taxes. * @return The total price without taxes.
*/ */
public Price2 getFinalPrice() { public Price2 getFinalPrice() {
return finalPrice; return this.finalPrice;
}
/**
* Get the non mandatory extra data.
* @return The root object containing all the extra data.
*/
public ExtraObject getExtra() {
return this.extra;
} }
} }

View file

@ -2,6 +2,7 @@ package org.pasteque.major.domain;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import org.pasteque.coreutil.extra.ExtraObject;
import org.pasteque.coreutil.constants.FiscalTicketType; import org.pasteque.coreutil.constants.FiscalTicketType;
import org.pasteque.coreutil.datatransfer.dto.FiscalTicketDTO; import org.pasteque.coreutil.datatransfer.dto.FiscalTicketDTO;
@ -23,7 +24,8 @@ public final class MajorZTicket
MajorCashSession session, MajorCashSession session,
Date closeDate, Date closeDate,
int closeType, int closeType,
List<Movement> endAmounts) { List<Movement> endAmounts,
ExtraObject extra) {
// TODO: not implemented // TODO: not implemented
throw new UnsupportedOperationException("Not implemented yet"); throw new UnsupportedOperationException("Not implemented yet");
} }

View file

@ -1,6 +1,7 @@
package org.pasteque.major.domain; package org.pasteque.major.domain;
import java.util.Date; import java.util.Date;
import org.pasteque.coreutil.extra.ExtraObject;
import org.pasteque.coreutil.datatransfer.dto.MovementDTO; import org.pasteque.coreutil.datatransfer.dto.MovementDTO;
import org.pasteque.coreutil.datatransfer.dto.WeakAssociationDTO; import org.pasteque.coreutil.datatransfer.dto.WeakAssociationDTO;
import org.pasteque.coreutil.price.Price2; import org.pasteque.coreutil.price.Price2;
@ -25,6 +26,8 @@ public class Movement
private final Price2 currencyAmount; private final Price2 currencyAmount;
/** See {@link getDate()}. */ /** See {@link getDate()}. */
private Date date; private Date date;
/** See {@link getExtra()}. */
private final ExtraObject extra;
/** /**
* Create a payment from all fields. * Create a payment from all fields.
@ -34,6 +37,7 @@ public class Movement
* @param currencyLabel See {@link getCurrencyLabel()}. * @param currencyLabel See {@link getCurrencyLabel()}.
* @param currencyAmount See {@link getCurrencyAmount()}. * @param currencyAmount See {@link getCurrencyAmount()}.
* @param date See {@link getDate()}. * @param date See {@link getDate()}.
* @param extra See {@link getExtra()}.
*/ */
public Movement( public Movement(
String paymentModeReference, String paymentModeReference,
@ -41,13 +45,15 @@ public class Movement
String currencyReference, String currencyReference,
String currencyLabel, String currencyLabel,
Price2 currencyAmount, Price2 currencyAmount,
Date date) { Date date,
ExtraObject extra) {
this.paymentModeReference = paymentModeReference; this.paymentModeReference = paymentModeReference;
this.paymentModeLabel = paymentModeLabel; this.paymentModeLabel = paymentModeLabel;
this.currencyReference = currencyReference; this.currencyReference = currencyReference;
this.currencyLabel = currencyLabel; this.currencyLabel = currencyLabel;
this.currencyAmount = currencyAmount; this.currencyAmount = currencyAmount;
this.date = date; this.date = date;
this.extra = extra;
} }
/** /**
@ -61,6 +67,7 @@ public class Movement
this.currencyLabel = dto.getCurrency().getLabel(); this.currencyLabel = dto.getCurrency().getLabel();
this.currencyAmount = new Price2(dto.getCurrencyAmount()); this.currencyAmount = new Price2(dto.getCurrencyAmount());
this.date = new Date(dto.getDate().getTime()); this.date = new Date(dto.getDate().getTime());
this.extra = dto.getExtra();
} }
/** /**
@ -116,6 +123,14 @@ public class Movement
return this.date; return this.date;
} }
/**
* Get all other data.
* @return The root object of extra data.
*/
public final ExtraObject getExtra() {
return this.extra;
}
/** /**
* Get a DTO from this object. * Get a DTO from this object.
* @return The content of this object as a DTO. * @return The content of this object as a DTO.
@ -129,6 +144,7 @@ public class Movement
this.currencyReference, this.currencyReference,
this.currencyLabel), this.currencyLabel),
this.currencyAmount.toDouble(), this.currencyAmount.toDouble(),
this.date); this.date,
this.extra);
} }
} }

View file

@ -1,6 +1,7 @@
package org.pasteque.major.domain; package org.pasteque.major.domain;
import org.pasteque.coreutil.datatransfer.dto.WeakAssociationDTO; import org.pasteque.coreutil.datatransfer.dto.WeakAssociationDTO;
import org.pasteque.coreutil.extra.ExtraObject;
import org.pasteque.coreutil.price.Price2; import org.pasteque.coreutil.price.Price2;
import org.pasteque.coreutil.datatransfer.dto.PaymentDTO; import org.pasteque.coreutil.datatransfer.dto.PaymentDTO;
@ -24,6 +25,8 @@ public final class Payment
private final String currencyLabel; private final String currencyLabel;
/** See {@link getCurrencyAmount()}. */ /** See {@link getCurrencyAmount()}. */
private final Price2 currencyAmount; private final Price2 currencyAmount;
/** See {@link getExtra()}. */
private final ExtraObject extra;
/** /**
* Create a payment from all fields. * Create a payment from all fields.
@ -33,6 +36,7 @@ public final class Payment
* @param currencyReference See {@link getCurrencyReference()}. * @param currencyReference See {@link getCurrencyReference()}.
* @param currencyLabel See {@link getCurrencyLabel()}. * @param currencyLabel See {@link getCurrencyLabel()}.
* @param currencyAmount See {@link getCurrencyAmount()}. * @param currencyAmount See {@link getCurrencyAmount()}.
* @param extra See {@link getExtra()}.
*/ */
public Payment( public Payment(
String paymentModeReference, String paymentModeReference,
@ -40,13 +44,15 @@ public final class Payment
String currencyReference, String currencyReference,
String currencyLabel, String currencyLabel,
Price2 amount, Price2 amount,
Price2 currencyAmount) { Price2 currencyAmount,
ExtraObject extra) {
this.paymentModeReference = paymentModeReference; this.paymentModeReference = paymentModeReference;
this.paymentModeLabel = paymentModeLabel; this.paymentModeLabel = paymentModeLabel;
this.currencyReference = currencyReference; this.currencyReference = currencyReference;
this.currencyLabel = currencyLabel; this.currencyLabel = currencyLabel;
this.amount = amount; this.amount = amount;
this.currencyAmount = currencyAmount; this.currencyAmount = currencyAmount;
this.extra = extra;
} }
/** /**
@ -60,6 +66,7 @@ public final class Payment
this.currencyReference = dto.getCurrency().getReference(); this.currencyReference = dto.getCurrency().getReference();
this.currencyLabel = dto.getCurrency().getLabel(); this.currencyLabel = dto.getCurrency().getLabel();
this.currencyAmount = new Price2(dto.getCurrencyAmount()); this.currencyAmount = new Price2(dto.getCurrencyAmount());
this.extra = dto.getExtra();
} }
/** /**
@ -116,6 +123,14 @@ public final class Payment
return currencyAmount; return currencyAmount;
} }
/**
* Get all other data.
* @return The root object of extra data.
*/
public ExtraObject getExtra() {
return this.extra;
}
/** /**
* Get a DTO from this object. * Get a DTO from this object.
* @return The content of this object as a DTO. * @return The content of this object as a DTO.
@ -129,6 +144,7 @@ public final class Payment
new WeakAssociationDTO( new WeakAssociationDTO(
this.currencyReference, this.currencyReference,
this.currencyLabel), this.currencyLabel),
this.currencyAmount.toDouble()); this.currencyAmount.toDouble(),
this.extra);
} }
} }

View file

@ -5,5 +5,4 @@
* but not modified. All properties and methods are then final but the class * but not modified. All properties and methods are then final but the class
* may be extended to include more data.</p> * may be extended to include more data.</p>
*/ */
// TODO: add a way to propagate extra data to the DTO
package org.pasteque.major.domain; package org.pasteque.major.domain;