From 85595c7fa17e056f4dd664fb7e01d6940e1c5d8e Mon Sep 17 00:00:00 2001 From: CGantert345 <57003061+CGantert345@users.noreply.github.com> Date: Wed, 13 Apr 2022 16:17:52 +0200 Subject: complete test for v3 fcb elements fixes on high level data mappings --- .../ticket/api/impl/SimpleIncludedOpenTicket.java | 35 ++-- .../ticket/api/impl/SimpleIssuingDetail.java | 24 +++ .../ticket/api/spec/IIncludedOpenTicket.java | 5 + .../barcode/ticket/api/spec/IIssuingDetail.java | 7 + .../ticket/api/utils/Api2OpenAsnEncoder.java | 76 ++++++-- .../ticket/api/utils/Api2OpenAsnEncoderV3.java | 198 ++++++++++++++------- .../ticket/api/utils/OpenAsn2ApiDecoder.java | 104 ++++++++++- .../ticket/api/utils/OpenAsn2ApiDecoderV3.java | 145 ++++++++++++--- .../barcode/ticket/api/utils/UicEncoderUtils.java | 45 +++++ 9 files changed, 522 insertions(+), 117 deletions(-) (limited to 'src/main') diff --git a/src/main/java/org/uic/barcode/ticket/api/impl/SimpleIncludedOpenTicket.java b/src/main/java/org/uic/barcode/ticket/api/impl/SimpleIncludedOpenTicket.java index 765b992..3dcf641 100644 --- a/src/main/java/org/uic/barcode/ticket/api/impl/SimpleIncludedOpenTicket.java +++ b/src/main/java/org/uic/barcode/ticket/api/impl/SimpleIncludedOpenTicket.java @@ -81,10 +81,18 @@ public class SimpleIncludedOpenTicket implements IIncludedOpenTicket { /** The info text. */ - protected String infoText; + protected String infoText; /** The extension. */ - protected IExtension extension; + protected IExtension extension; + + protected String serviceLevel; + + /** The included service brands. */ + protected CollectionincludedTransportTypes = new LinkedHashSet(); + + /** The excluded service brands. */ + protected CollectionexcludedTransportTypes = new LinkedHashSet(); /* (nicht-Javadoc) * @see org.uic.ticket.api.spec.IIncludedOpenTicket#getDepartureDate() @@ -435,28 +443,35 @@ public class SimpleIncludedOpenTicket implements IIncludedOpenTicket { this.validUntil = date; } + @Override public Collection getExcludedTransportTypes() { - // TODO Auto-generated method stub - return null; + return excludedTransportTypes; } @Override public void addExcludedTransportType(Integer excludedTransportType) { - // TODO Auto-generated method stub - + excludedTransportTypes.add(excludedTransportType); } @Override public Collection getIncludedTransportTypes() { - // TODO Auto-generated method stub - return null; + return includedTransportTypes; } @Override public void addInludedTransportType(Integer includedTransportType) { - // TODO Auto-generated method stub - + includedTransportTypes.add(includedTransportType); + } + + @Override + public String getServiceLevel() { + return serviceLevel; + } + + @Override + public void setServiceLevel(String serviceLevel) { + this.serviceLevel = serviceLevel; } } diff --git a/src/main/java/org/uic/barcode/ticket/api/impl/SimpleIssuingDetail.java b/src/main/java/org/uic/barcode/ticket/api/impl/SimpleIssuingDetail.java index 34a1ef2..dad50c2 100644 --- a/src/main/java/org/uic/barcode/ticket/api/impl/SimpleIssuingDetail.java +++ b/src/main/java/org/uic/barcode/ticket/api/impl/SimpleIssuingDetail.java @@ -51,6 +51,10 @@ public class SimpleIssuingDetail implements IIssuingDetail{ /** The secure paper ticket. */ protected boolean securePaperTicket; + + protected String currency; + + protected Integer currencyFraction; /* (nicht-Javadoc) * @see org.uic.ticket.api.IIssuingDetail#getIssuer() @@ -224,6 +228,26 @@ public class SimpleIssuingDetail implements IIssuingDetail{ public void setSecurePaperTicket(boolean securePaperTicket) { this.securePaperTicket = securePaperTicket; } + + @Override + public String getCurrency() { + return currency; + } + + @Override + public void setCurrency(String currency) { + this.currency = currency; + } + + @Override + public Integer getCurrencyFraction() { + return currencyFraction; + } + + @Override + public void setCurrencyFraction(Integer fraction) { + this.currencyFraction = fraction; + } diff --git a/src/main/java/org/uic/barcode/ticket/api/spec/IIncludedOpenTicket.java b/src/main/java/org/uic/barcode/ticket/api/spec/IIncludedOpenTicket.java index f64d374..24645f1 100644 --- a/src/main/java/org/uic/barcode/ticket/api/spec/IIncludedOpenTicket.java +++ b/src/main/java/org/uic/barcode/ticket/api/spec/IIncludedOpenTicket.java @@ -429,5 +429,10 @@ public interface IIncludedOpenTicket { * @param validUntilDateTime the new validUntil date time */ public void setValidUntilUTCoffset(Long validUntilUTCoffset) ; + + + public String getServiceLevel(); + + public void setServiceLevel(String serviceLevel); } diff --git a/src/main/java/org/uic/barcode/ticket/api/spec/IIssuingDetail.java b/src/main/java/org/uic/barcode/ticket/api/spec/IIssuingDetail.java index ecaf9c7..d09b226 100644 --- a/src/main/java/org/uic/barcode/ticket/api/spec/IIssuingDetail.java +++ b/src/main/java/org/uic/barcode/ticket/api/spec/IIssuingDetail.java @@ -185,5 +185,12 @@ public interface IIssuingDetail { public boolean isSecurePaperTicket(); public void setSecurePaperTicket(boolean securePaperTicket); + + public String getCurrency(); + public void setCurrency(String currency); + + public Integer getCurrencyFraction(); + public void setCurrencyFraction(Integer fraction); + } diff --git a/src/main/java/org/uic/barcode/ticket/api/utils/Api2OpenAsnEncoder.java b/src/main/java/org/uic/barcode/ticket/api/utils/Api2OpenAsnEncoder.java index 633f2d7..835a324 100644 --- a/src/main/java/org/uic/barcode/ticket/api/utils/Api2OpenAsnEncoder.java +++ b/src/main/java/org/uic/barcode/ticket/api/utils/Api2OpenAsnEncoder.java @@ -18,6 +18,7 @@ import org.uic.barcode.ticket.api.asn.omv1.CardReferenceType; import org.uic.barcode.ticket.api.asn.omv1.CodeTableType; import org.uic.barcode.ticket.api.asn.omv1.CompartmentDetailsType; import org.uic.barcode.ticket.api.asn.omv1.CompartmentGenderType; +import org.uic.barcode.ticket.api.asn.omv1.CompartmentPositionType; import org.uic.barcode.ticket.api.asn.omv1.ConfirmationTypeType; import org.uic.barcode.ticket.api.asn.omv1.ControlData; import org.uic.barcode.ticket.api.asn.omv1.CountermarkData; @@ -91,11 +92,14 @@ import org.uic.barcode.ticket.api.asn.omv1.VatDetailType; import org.uic.barcode.ticket.api.asn.omv1.ViaStationType; import org.uic.barcode.ticket.api.asn.omv1.VoucherData; import org.uic.barcode.ticket.api.asn.omv1.ZoneType; +import org.uic.barcode.ticket.api.asn.omv1.SequenceOfValidityPeriodType; +import org.uic.barcode.ticket.api.asn.omv1.SequenceOfTimeRangeType; import org.uic.barcode.ticket.api.spec.IBerth; import org.uic.barcode.ticket.api.spec.ICarCarriageReservation; import org.uic.barcode.ticket.api.spec.ICardReference; import org.uic.barcode.ticket.api.spec.ICompartmentDetails; import org.uic.barcode.ticket.api.spec.ICompartmentGenderType; +import org.uic.barcode.ticket.api.spec.ICompartmentPositionType; import org.uic.barcode.ticket.api.spec.IControlDetail; import org.uic.barcode.ticket.api.spec.ICounterMark; import org.uic.barcode.ticket.api.spec.ICustomerCard; @@ -486,9 +490,25 @@ public class Api2OpenAsnEncoder implements Api2AsnEncoder { asnData.setSpecialAllocation(UicEncoderUtils.getRestrictedInt(compartmentDetails.getSpecialAllocation(), 1,99)); asnData.setSpecialAllocationDescr(compartmentDetails.getSpecialAllocationDescr()); + asnData.setPosition(convert(compartmentDetails.getPosition())); return asnData; } + private CompartmentPositionType convert(ICompartmentPositionType position) { + if (position == null) { + return null; + } else if (position.equals(ICompartmentPositionType.lowerLevel)) { + return CompartmentPositionType.lowerLevel; + } else if (position.equals(ICompartmentPositionType.upperLevel)) { + return CompartmentPositionType.upperLevel; + } else if (position.equals(ICompartmentPositionType.unspecified)) { + return CompartmentPositionType.unspecified; + } + return null; + } + + + /** * Encode berths. * @@ -602,6 +622,10 @@ public class Api2OpenAsnEncoder implements Api2AsnEncoder { asnData.setTypeOfSupplement(UicEncoderUtils.getRestrictedInt(document.getTypeOfSupplement(), 1, 9)); asnData.setPlaces(encodePlaces(document.getPlaces())); + + if (document.getAdditionalPlaces() != null) { + asnData.setAdditionalPlaces(encodePlaces(document.getAdditionalPlaces())); + } asnData.setBicyclePlaces(encodePlaces(document.getBicyclePlaces())); @@ -715,6 +739,11 @@ public class Api2OpenAsnEncoder implements Api2AsnEncoder { if (document.getClassCode() != classCode){ asnData.setClassCode(convertTravelClass(document.getClassCode())); } + + if (document.getServiceLevel() != null && document.getServiceLevel().length() > 0) { + asnData.setServiceLevel(document.getServiceLevel()); + } + if (document.getExternalIssuer() > 0) { asnData.setExternalIssuerId(new Long(document.getExternalIssuer())); } @@ -886,6 +915,11 @@ public class Api2OpenAsnEncoder implements Api2AsnEncoder { if (document.getClassCode() != ITravelClassType.second){ asnData.setClassCode(convertTravelClass(document.getClassCode())); } + + if (document.getServiceLevel() != null && document.getServiceLevel().length() > 0) { + asnData.setServiceLevel(document.getServiceLevel()); + } + if (document.getExternalIssuer()>0) { asnData.setExtIssuerId(new Long(document.getExternalIssuer())); } @@ -906,10 +940,13 @@ public class Api2OpenAsnEncoder implements Api2AsnEncoder { if (document.getLuggageRestriction() != null) { asnData.setLuggage(encodeLuggage(document.getLuggageRestriction())); } + + if (document.getReturnDescription() != null) { + asnData.setReturnDescription(encodeReturnDescription(document.getReturnDescription(),issuingDate)); + } if (document.isReturnIncluded()) { asnData.setReturnIncluded(true); - asnData.setReturnDescription(encodeReturnDescription(document.getReturnDescription(),issuingDate)); } else { asnData.setReturnIncluded(false); } @@ -1013,12 +1050,11 @@ public class Api2OpenAsnEncoder implements Api2AsnEncoder { asnData.setClassCode(convertTravelClass(document.getClassCode())); } - + if (document.getReturnDescription()!= null) { + asnData.setReturnDescription(encodeReturnDescription(document.getReturnDescription(),issuingDate)); + } if (document.isReturnIncluded()) { asnData.setReturnIncluded(true); - if (document.getReturnDescription()!= null) { - asnData.setReturnDescription(encodeReturnDescription(document.getReturnDescription(),issuingDate)); - } } else { asnData.setReturnIncluded(false); } @@ -1089,8 +1125,13 @@ public class Api2OpenAsnEncoder implements Api2AsnEncoder { asnData.setRoute(encodeViaStationCollection(document.getRoute())); if (document.getRouteId() > 0){ - asnData.setSeriesId(new Long(document.getRouteId())); + asnData.setRouteId(new Long(document.getRouteId())); + } + + if (document.getSeriesId() > 0) { + asnData.setSeriesId(new Long(document.getSeriesId())); } + return asnData; } @@ -1194,7 +1235,8 @@ public class Api2OpenAsnEncoder implements Api2AsnEncoder { } else { DeltaCoordinates delta = new DeltaCoordinates(); delta.setLatitude(Asn1BigInteger.toAsn1(asnData.getFirstEdge().getLatitude() - edge.getLatitude())); - delta.setLatitude(Asn1BigInteger.toAsn1(asnData.getFirstEdge().getLongitude() - edge.getLongitude())); + delta.setLongitude(Asn1BigInteger.toAsn1(asnData.getFirstEdge().getLongitude() - edge.getLongitude())); + asnList.add(delta); } } @@ -1475,7 +1517,7 @@ public class Api2OpenAsnEncoder implements Api2AsnEncoder { details.setSeries(UicEncoderUtils.getRestrictedInt(seriesDataDetails.getSeries(), 1, 99999)); details.setSupplyingCarrier(UicEncoderUtils.getRestrictedInt(seriesDataDetails.getSupplyingCarrier(), 1, 9999)); details.setOfferIdentification(UicEncoderUtils.getRestrictedInt(seriesDataDetails.getOfferIdentification(), 1, 99)); - return null; + return details; } /** @@ -1505,6 +1547,7 @@ public class Api2OpenAsnEncoder implements Api2AsnEncoder { asnData.setReferenceIA5(UicEncoderUtils.getIA5NonNum(document.getReference())); asnData.setInfoText(document.getInfoText()); + asnData.setExtension(encodeExtension(document.getExtension())); asnData.setValidity(document.getValidFrom(), document.getValidUntil()); @@ -1620,7 +1663,10 @@ public class Api2OpenAsnEncoder implements Api2AsnEncoder { ValidityPeriodDetailType asnData = new ValidityPeriodDetailType(); - if (validityDetails.getTimeRanges() != null) { + if (validityDetails.getTimeRanges() != null && !validityDetails.getTimeRanges().isEmpty()) { + + asnData.setExcludedTimeRange(new SequenceOfTimeRangeType()); + for (ITimeRange range : validityDetails.getTimeRanges()) { if (range.getFromTime() == range.getUntilTime()){ @@ -1635,8 +1681,11 @@ public class Api2OpenAsnEncoder implements Api2AsnEncoder { } } - if (validityDetails.getValidityRanges() != null) { - for (IValidityRange range : validityDetails.getValidityRanges()) { + if (validityDetails.getValidityRanges() != null && !validityDetails.getValidityRanges().isEmpty()) { + + asnData.setValidityPeriod(new SequenceOfValidityPeriodType()); + + for (IValidityRange range : validityDetails.getValidityRanges()) { ValidityPeriodType asnRange = new ValidityPeriodType(); @@ -1689,9 +1738,8 @@ public class Api2OpenAsnEncoder implements Api2AsnEncoder { asnData.setClassCode(convertTravelClass(document.getClassCode())); - if (!document.isIncludesSupplements()){ - asnData.setIncludesSupplements(false); - } + asnData.setIncludesSupplements(document.isIncludesSupplements()); + asnData.setNumberOfTravelDays(UicEncoderUtils.getRestrictedInt(document.getNumberOfTravelDates(), 1, 8)); asnData.setValidityDates(document.getValidFrom(), document.getValidUntil(), issuingDate); diff --git a/src/main/java/org/uic/barcode/ticket/api/utils/Api2OpenAsnEncoderV3.java b/src/main/java/org/uic/barcode/ticket/api/utils/Api2OpenAsnEncoderV3.java index c586da0..fd9995f 100644 --- a/src/main/java/org/uic/barcode/ticket/api/utils/Api2OpenAsnEncoderV3.java +++ b/src/main/java/org/uic/barcode/ticket/api/utils/Api2OpenAsnEncoderV3.java @@ -11,6 +11,7 @@ import org.uic.barcode.asn1.datatypesimpl.SequenceOfStringIA5; import org.uic.barcode.asn1.datatypesimpl.SequenceOfStringUTF8; import org.uic.barcode.asn1.datatypesimpl.SequenceOfUnrestrictedLong; import org.uic.barcode.ticket.EncodingFormatException; +import org.uic.barcode.ticket.api.asn.omv3.CompartmentPositionType; import org.uic.barcode.ticket.api.asn.omv3.BerthDetailData; import org.uic.barcode.ticket.api.asn.omv3.BerthTypeType; import org.uic.barcode.ticket.api.asn.omv3.BoardingOrArrivalType; @@ -69,9 +70,11 @@ import org.uic.barcode.ticket.api.asn.omv3.SequenceOfRegisteredLuggageType; import org.uic.barcode.ticket.api.asn.omv3.SequenceOfServiceBrands; import org.uic.barcode.ticket.api.asn.omv3.SequenceOfTariffType; import org.uic.barcode.ticket.api.asn.omv3.SequenceOfTicketLinkType; +import org.uic.barcode.ticket.api.asn.omv3.SequenceOfTimeRangeType; import org.uic.barcode.ticket.api.asn.omv3.SequenceOfTransportTypes; import org.uic.barcode.ticket.api.asn.omv3.SequenceOfTravelerId; import org.uic.barcode.ticket.api.asn.omv3.SequenceOfTravelerType; +import org.uic.barcode.ticket.api.asn.omv3.SequenceOfValidityPeriodType; import org.uic.barcode.ticket.api.asn.omv3.SequenceOfViaStationType; import org.uic.barcode.ticket.api.asn.omv3.SeriesDetailType; import org.uic.barcode.ticket.api.asn.omv3.ServiceType; @@ -99,6 +102,7 @@ import org.uic.barcode.ticket.api.spec.ICarCarriageReservation; import org.uic.barcode.ticket.api.spec.ICardReference; import org.uic.barcode.ticket.api.spec.ICompartmentDetails; import org.uic.barcode.ticket.api.spec.ICompartmentGenderType; +import org.uic.barcode.ticket.api.spec.ICompartmentPositionType; import org.uic.barcode.ticket.api.spec.IControlDetail; import org.uic.barcode.ticket.api.spec.ICounterMark; import org.uic.barcode.ticket.api.spec.ICustomerCard; @@ -347,8 +351,11 @@ public class Api2OpenAsnEncoderV3 implements Api2AsnEncoder { asnData.setTrainIA5(UicEncoderUtils.getIA5NonNum(document.getTrain())); asnData.setTrainNum(UicEncoderUtils.getNum(document.getTrain())); - asnData.setProductOwnerNum(UicEncoderUtils.getNum(document.getProductOwner())); - asnData.setProductOwnerIA5(UicEncoderUtils.getIA5NonNum(document.getProductOwner())); + asnData.setProductOwnerNum(UicEncoderUtils.getRestrictedNum(document.getProductOwner(),1,32000)); + asnData.setProductOwnerIA5(UicEncoderUtils.getIA5RestrictedNonNum(document.getProductOwner(),1,32000)); + + asnData.setProductIdNum(UicEncoderUtils.getRestrictedNum(document.getProductId(),0,65535)); + asnData.setProductIdIA5(UicEncoderUtils.getIA5RestrictedNonNum(document.getProductId(),0,65535)); asnData.setReferenceNum(UicEncoderUtils.getNum(document.getReference())); asnData.setReferenceIA5(UicEncoderUtils.getIA5NonNum(document.getReference())); @@ -488,9 +495,23 @@ public class Api2OpenAsnEncoderV3 implements Api2AsnEncoder { asnData.setSpecialAllocation(UicEncoderUtils.getRestrictedInt(compartmentDetails.getSpecialAllocation(), 1,99)); asnData.setSpecialAllocationDescr(compartmentDetails.getSpecialAllocationDescr()); + asnData.setPosition(convert(compartmentDetails.getPosition())); return asnData; } + private CompartmentPositionType convert(ICompartmentPositionType position) { + if (position == null) { + return null; + } else if (position.equals(ICompartmentPositionType.lowerLevel)) { + return CompartmentPositionType.lowerLevel; + } else if (position.equals(ICompartmentPositionType.upperLevel)) { + return CompartmentPositionType.upperLevel; + } else if (position.equals(ICompartmentPositionType.unspecified)) { + return CompartmentPositionType.unspecified; + } + return null; + } + /** * Encode berths. * @@ -544,8 +565,11 @@ public class Api2OpenAsnEncoderV3 implements Api2AsnEncoder { ReservationData asnData = new ReservationData(); asnDocument.getTicket().setReservation(asnData); - asnData.setProductOwnerNum(UicEncoderUtils.getNum(document.getProductOwner())); - asnData.setProductOwnerIA5(UicEncoderUtils.getIA5NonNum(document.getProductOwner())); + asnData.setProductOwnerNum(UicEncoderUtils.getRestrictedNum(document.getProductOwner(),1,32000)); + asnData.setProductOwnerIA5(UicEncoderUtils.getIA5RestrictedNonNum(document.getProductOwner(),1,32000)); + + asnData.setProductIdNum(UicEncoderUtils.getRestrictedNum(document.getProductId(),0,65535)); + asnData.setProductIdIA5(UicEncoderUtils.getIA5RestrictedNonNum(document.getProductId(),0,65535)); asnData.setReferenceNum(UicEncoderUtils.getNum(document.getReference())); asnData.setReferenceIA5(UicEncoderUtils.getIA5NonNum(document.getReference())); @@ -604,6 +628,10 @@ public class Api2OpenAsnEncoderV3 implements Api2AsnEncoder { asnData.setTypeOfSupplement(UicEncoderUtils.getRestrictedInt(document.getTypeOfSupplement(), 1, 9)); asnData.setPlaces(encodePlaces(document.getPlaces())); + + if (document.getAdditionalPlaces() != null) { + asnData.setAdditionalPlaces(encodePlaces(document.getAdditionalPlaces())); + } asnData.setBicyclePlaces(encodePlaces(document.getBicyclePlaces())); @@ -680,11 +708,11 @@ public class Api2OpenAsnEncoderV3 implements Api2AsnEncoder { IncludedOpenTicketType asnData = new IncludedOpenTicketType(); - asnData.setProductOwnerNum(UicEncoderUtils.getNum(document.getProductOwner())); - asnData.setProductOwnerIA5(UicEncoderUtils.getIA5NonNum(document.getProductOwner())); + asnData.setProductOwnerNum(UicEncoderUtils.getRestrictedNum(document.getProductOwner(),1,32000)); + asnData.setProductOwnerIA5(UicEncoderUtils.getIA5RestrictedNonNum(document.getProductOwner(),1,32000)); - asnData.setProductIdNum(UicEncoderUtils.getNum(document.getProductId())); - asnData.setProductIdIA5(UicEncoderUtils.getIA5NonNum(document.getProductId())); + asnData.setProductIdNum(UicEncoderUtils.getRestrictedNum(document.getProductId(),0,65535)); + asnData.setProductIdIA5(UicEncoderUtils.getIA5RestrictedNonNum(document.getProductId(),0,65535)); asnData.setInfoText(document.getInfoText()); @@ -721,6 +749,11 @@ public class Api2OpenAsnEncoderV3 implements Api2AsnEncoder { if (document.getClassCode() != classCode && document.getClassCode() != null){ asnData.setClassCode(TravelClassType.valueOf(document.getClassCode().name())); } + + if (document.getServiceLevel() != null && document.getServiceLevel().length() > 0) { + asnData.setServiceLevel(document.getServiceLevel()); + } + if (document.getExternalIssuer() > 0) { asnData.setExternalIssuerId(new Long(document.getExternalIssuer())); } @@ -732,6 +765,8 @@ public class Api2OpenAsnEncoderV3 implements Api2AsnEncoder { if (document.getValidRegionList()!= null && document.getValidRegionList().size() > 0) { asnData.setValidRegion(encodeRegionCollection(document.getValidRegionList(), issuingDate)); } + + return asnData; } @@ -842,11 +877,11 @@ public class Api2OpenAsnEncoderV3 implements Api2AsnEncoder { asnDocument.setTicket(asnTicket); asnTicket.setOpenTicket(asnData); - asnData.setProductOwnerNum(UicEncoderUtils.getNum(document.getProductOwner())); - asnData.setProductOwnerIA5(UicEncoderUtils.getIA5NonNum(document.getProductOwner())); + asnData.setProductOwnerNum(UicEncoderUtils.getRestrictedNum(document.getProductOwner(),1,32000)); + asnData.setProductOwnerIA5(UicEncoderUtils.getIA5RestrictedNonNum(document.getProductOwner(),1,32000)); - asnData.setProductIdNum(UicEncoderUtils.getNum(document.getProductId())); - asnData.setProductIdIA5(UicEncoderUtils.getIA5NonNum(document.getProductId())); + asnData.setProductIdNum(UicEncoderUtils.getRestrictedNum(document.getProductId(),0,65535)); + asnData.setProductIdIA5(UicEncoderUtils.getIA5RestrictedNonNum(document.getProductId(),0,65535)); asnData.setReferenceNum(UicEncoderUtils.getNum(document.getReference())); asnData.setReferenceIA5(UicEncoderUtils.getIA5NonNum(document.getReference())); @@ -895,6 +930,11 @@ public class Api2OpenAsnEncoderV3 implements Api2AsnEncoder { if (document.getClassCode() != ITravelClassType.second && document.getClassCode() != null){ asnData.setClassCode(TravelClassType.valueOf(document.getClassCode().name())); } + + if (document.getServiceLevel() != null && document.getServiceLevel().length() > 0) { + asnData.setServiceLevel(document.getServiceLevel()); + } + if (document.getExternalIssuer()>0) { asnData.setExtIssuerId(new Long(document.getExternalIssuer())); } @@ -916,9 +956,12 @@ public class Api2OpenAsnEncoderV3 implements Api2AsnEncoder { asnData.setLuggage(encodeLuggage(document.getLuggageRestriction())); } + if (document.getReturnDescription() != null) { + asnData.setReturnDescription(encodeReturnDescription(document.getReturnDescription(),issuingDate)); + } + if (document.isReturnIncluded()) { asnData.setReturnIncluded(true); - asnData.setReturnDescription(encodeReturnDescription(document.getReturnDescription(),issuingDate)); } else { asnData.setReturnIncluded(false); } @@ -952,8 +995,11 @@ public class Api2OpenAsnEncoderV3 implements Api2AsnEncoder { CountermarkData asnData = new CountermarkData(); asnDocument.getTicket().setCounterMark(asnData); - asnData.setProductOwnerNum(UicEncoderUtils.getNum(document.getProductOwner())); - asnData.setProductOwnerIA5(UicEncoderUtils.getIA5NonNum(document.getProductOwner())); + asnData.setProductOwnerNum(UicEncoderUtils.getRestrictedNum(document.getProductOwner(),1,32000)); + asnData.setProductOwnerIA5(UicEncoderUtils.getIA5RestrictedNonNum(document.getProductOwner(),1,32000)); + + asnData.setProductIdNum(UicEncoderUtils.getRestrictedNum(document.getProductId(),0,65535)); + asnData.setProductIdIA5(UicEncoderUtils.getIA5RestrictedNonNum(document.getProductId(),0,65535)); asnData.setTicketReferenceNum(UicEncoderUtils.getNum(document.getTicketReference())); @@ -1023,12 +1069,11 @@ public class Api2OpenAsnEncoderV3 implements Api2AsnEncoder { asnData.setClassCode(TravelClassType.valueOf(document.getClassCode().name())); } - + if (document.getReturnDescription()!= null) { + asnData.setReturnDescription(encodeReturnDescription(document.getReturnDescription(),issuingDate)); + } if (document.isReturnIncluded()) { asnData.setReturnIncluded(true); - if (document.getReturnDescription()!= null) { - asnData.setReturnDescription(encodeReturnDescription(document.getReturnDescription(),issuingDate)); - } } else { asnData.setReturnIncluded(false); } @@ -1102,8 +1147,13 @@ public class Api2OpenAsnEncoderV3 implements Api2AsnEncoder { asnData.setRoute(encodeViaStationCollection(document.getRoute())); if (document.getRouteId() > 0){ - asnData.setSeriesId(new Long(document.getRouteId())); + asnData.setRouteId(new Long(document.getRouteId())); + } + + if (document.getSeriesId() > 0) { + asnData.setSeriesId(new Long(document.getSeriesId())); } + return asnData; } @@ -1207,7 +1257,8 @@ public class Api2OpenAsnEncoderV3 implements Api2AsnEncoder { } else { DeltaCoordinates delta = new DeltaCoordinates(); delta.setLatitude(Asn1BigInteger.toAsn1(asnData.getFirstEdge().getLatitude() - edge.getLatitude())); - delta.setLatitude(Asn1BigInteger.toAsn1(asnData.getFirstEdge().getLongitude() - edge.getLongitude())); + delta.setLongitude(Asn1BigInteger.toAsn1(asnData.getFirstEdge().getLongitude() - edge.getLongitude())); + asnList.add(delta); } } @@ -1333,8 +1384,11 @@ public class Api2OpenAsnEncoderV3 implements Api2AsnEncoder { ParkingGroundData asnData = new ParkingGroundData(); asnDocument.getTicket().setParkingGround(asnData); - asnData.setProductOwnerNum(UicEncoderUtils.getNum(document.getProductOwner())); - asnData.setProductOwnerIA5(UicEncoderUtils.getIA5NonNum(document.getProductOwner())); + asnData.setProductOwnerNum(UicEncoderUtils.getRestrictedNum(document.getProductOwner(),1,32000)); + asnData.setProductOwnerIA5(UicEncoderUtils.getIA5RestrictedNonNum(document.getProductOwner(),1,32000)); + + asnData.setProductIdNum(UicEncoderUtils.getRestrictedNum(document.getProductId(),0,65535)); + asnData.setProductIdIA5(UicEncoderUtils.getIA5RestrictedNonNum(document.getProductId(),0,65535)); asnData.setReferenceNum(Asn1BigInteger.toAsn1(UicEncoderUtils.getNum(document.getReference()))); asnData.setReferenceIA5(UicEncoderUtils.getIA5NonNum(document.getReference())); @@ -1449,8 +1503,8 @@ public class Api2OpenAsnEncoderV3 implements Api2AsnEncoder { TariffType asnTariff = new TariffType(); - asnTariff.setAgeAbove(UicEncoderUtils.getRestrictedInt(tariff.getAgeAbove(),2,120)); - asnTariff.setAgeBelow(UicEncoderUtils.getRestrictedInt(tariff.getAgeBelow(),1,40)); + asnTariff.setAgeAbove(UicEncoderUtils.getRestrictedInt(tariff.getAgeAbove(),2,128)); + asnTariff.setAgeBelow(UicEncoderUtils.getRestrictedInt(tariff.getAgeBelow(),1,64)); asnTariff.setNumberOfPassengers(UicEncoderUtils.getRestrictedIntWithDefault(tariff.getNumberOfPassengers(),1,200,1)); @@ -1485,9 +1539,9 @@ public class Api2OpenAsnEncoderV3 implements Api2AsnEncoder { private SeriesDetailType encodeSeriesDataDetails( ISeriesDataDetails seriesDataDetails) throws EncodingFormatException { SeriesDetailType details = new SeriesDetailType(); details.setSeries(UicEncoderUtils.getRestrictedInt(seriesDataDetails.getSeries(), 1, 99999)); - details.setSupplyingCarrier(UicEncoderUtils.getRestrictedInt(seriesDataDetails.getSupplyingCarrier(), 1, 9999)); + details.setSupplyingCarrier(UicEncoderUtils.getRestrictedInt(seriesDataDetails.getSupplyingCarrier(), 1, 32000)); details.setOfferIdentification(UicEncoderUtils.getRestrictedInt(seriesDataDetails.getOfferIdentification(), 1, 99)); - return null; + return details; } /** @@ -1506,16 +1560,17 @@ public class Api2OpenAsnEncoderV3 implements Api2AsnEncoder { VoucherData asnData = new VoucherData(); asnDocument.getTicket().setVoucher(asnData); - asnData.setProductOwnerNum(UicEncoderUtils.getNum(document.getProductOwner())); - asnData.setProductOwnerIA5(UicEncoderUtils.getIA5NonNum(document.getProductOwner())); + asnData.setProductOwnerNum(UicEncoderUtils.getRestrictedNum(document.getProductOwner(),1,32000)); + asnData.setProductOwnerIA5(UicEncoderUtils.getIA5RestrictedNonNum(document.getProductOwner(),1,32000)); - asnData.setProductIdNum(UicEncoderUtils.getNum(document.getProductId())); - asnData.setProductIdIA5(UicEncoderUtils.getIA5NonNum(document.getProductId())); + asnData.setProductIdNum(UicEncoderUtils.getRestrictedNum(document.getProductId(),0,65535)); + asnData.setProductIdIA5(UicEncoderUtils.getIA5RestrictedNonNum(document.getProductId(),0,65535)); asnData.setReferenceNum(Asn1BigInteger.toAsn1(UicEncoderUtils.getNum(document.getReference()))); asnData.setReferenceIA5(UicEncoderUtils.getIA5NonNum(document.getReference())); asnData.setInfoText(document.getInfoText()); + asnData.setExtension(encodeExtension(document.getExtension())); asnData.setValidity(document.getValidFrom(), document.getValidUntil()); @@ -1547,11 +1602,11 @@ public class Api2OpenAsnEncoderV3 implements Api2AsnEncoder { PassData asnData = new PassData(); asnDocument.getTicket().setPass(asnData); - asnData.setProductOwnerNum(UicEncoderUtils.getNum(document.getProductOwner())); - asnData.setProductOwnerIA5(UicEncoderUtils.getIA5NonNum(document.getProductOwner())); - - asnData.setProductIdNum(UicEncoderUtils.getNum(document.getProductId())); - asnData.setProductIdIA5(UicEncoderUtils.getIA5NonNum(document.getProductId())); + asnData.setProductOwnerNum(UicEncoderUtils.getRestrictedNum(document.getProductOwner(),1,32000)); + asnData.setProductOwnerIA5(UicEncoderUtils.getIA5RestrictedNonNum(document.getProductOwner(),1,32000)); + + asnData.setProductIdNum(UicEncoderUtils.getRestrictedNum(document.getProductId(),0,65535)); + asnData.setProductIdIA5(UicEncoderUtils.getIA5RestrictedNonNum(document.getProductId(),0,65535)); asnData.setReferenceNum(Asn1BigInteger.toAsn1(UicEncoderUtils.getNum(document.getReference()))); asnData.setReferenceIA5(UicEncoderUtils.getIA5NonNum(document.getReference())); @@ -1587,8 +1642,8 @@ public class Api2OpenAsnEncoderV3 implements Api2AsnEncoder { asnData.setExcludedServiceBrands(SequenceOfServiceBrands.getSequence(UicEncoderUtils.encodeRestrictedIntegerCollection(document.getExcludedServiceBrands(),1,32000))); asnData.setIncludedServiceBrands(SequenceOfServiceBrands.getSequence(UicEncoderUtils.encodeRestrictedIntegerCollection(document.getIncludedServiceBrands(),1,32000))); - asnData.setNumberOfDaysOfTravel(UicEncoderUtils.getRestrictedInt(document.getNumberOfDaysOfTravel(), 1, 93)); - asnData.setNumberOfPossibleTrips(UicEncoderUtils.getRestrictedInt(document.getNumberOfPossibleTrips(), 1, 30)); + asnData.setNumberOfDaysOfTravel(UicEncoderUtils.getRestrictedInt(document.getNumberOfDaysOfTravel(), 1, 250)); + asnData.setNumberOfPossibleTrips(UicEncoderUtils.getRestrictedInt(document.getNumberOfPossibleTrips(), 1, 250)); asnData.setNumberOfValidityDays(UicEncoderUtils.getRestrictedInt(document.getNumberOfValidityDays(), 1, 370)); asnData.setPassDescription(document.getPassDescription()); if (document.getPassType() > 0 ){ @@ -1667,7 +1722,9 @@ public class Api2OpenAsnEncoderV3 implements Api2AsnEncoder { ValidityPeriodDetailType asnData = new ValidityPeriodDetailType(); - if (validityDetails.getTimeRanges() != null) { + if (validityDetails.getTimeRanges() != null && !validityDetails.getTimeRanges().isEmpty()) { + asnData.setExcludedTimeRange(new SequenceOfTimeRangeType()); + for (ITimeRange range : validityDetails.getTimeRanges()) { if (range.getFromTime() == range.getUntilTime()){ @@ -1682,7 +1739,10 @@ public class Api2OpenAsnEncoderV3 implements Api2AsnEncoder { } } - if (validityDetails.getValidityRanges() != null) { + if (validityDetails.getValidityRanges() != null && !validityDetails.getValidityRanges().isEmpty()) { + + asnData.setValidityPeriod(new SequenceOfValidityPeriodType()); + for (IValidityRange range : validityDetails.getValidityRanges()) { ValidityPeriodType asnRange = new ValidityPeriodType(); @@ -1722,11 +1782,11 @@ public class Api2OpenAsnEncoderV3 implements Api2AsnEncoder { FIPTicketData asnData = new FIPTicketData(); asnDocument.getTicket().setFipTicket(asnData); - asnData.setProductOwnerNum(UicEncoderUtils.getNum(document.getProductOwner())); - asnData.setProductOwnerIA5(UicEncoderUtils.getIA5NonNum(document.getProductOwner())); + asnData.setProductOwnerNum(UicEncoderUtils.getRestrictedNum(document.getProductOwner(),1,32000)); + asnData.setProductOwnerIA5(UicEncoderUtils.getIA5RestrictedNonNum(document.getProductOwner(),1,32000)); - asnData.setProductIdNum(UicEncoderUtils.getNum(document.getProductId())); - asnData.setProductIdIA5(UicEncoderUtils.getIA5NonNum(document.getProductId())); + asnData.setProductIdNum(UicEncoderUtils.getRestrictedNum(document.getProductId(),0,65535)); + asnData.setProductIdIA5(UicEncoderUtils.getIA5RestrictedNonNum(document.getProductId(),0,65535)); asnData.setReferenceNum(Asn1BigInteger.toAsn1(UicEncoderUtils.getNum(document.getReference()))); asnData.setReferenceIA5(UicEncoderUtils.getIA5NonNum(document.getReference())); @@ -1737,9 +1797,9 @@ public class Api2OpenAsnEncoderV3 implements Api2AsnEncoder { if (document.getClassCode() != null) { asnData.setClassCode(TravelClassType.valueOf(document.getClassCode().name())); } - if (!document.isIncludesSupplements()){ - asnData.setIncludesSupplements(false); - } + + asnData.setIncludesSupplements(document.isIncludesSupplements()); + asnData.setNumberOfTravelDays(UicEncoderUtils.getRestrictedInt(document.getNumberOfTravelDates(), 1, 8)); asnData.setValidityDates(document.getValidFrom(), document.getValidUntil(), issuingDate); @@ -1769,11 +1829,11 @@ public class Api2OpenAsnEncoderV3 implements Api2AsnEncoder { StationPassageData asnData = new StationPassageData(); asnDocument.getTicket().setStationPassage(asnData); - asnData.setProductOwnerNum(UicEncoderUtils.getNum(document.getProductOwner())); - asnData.setProductOwnerIA5(UicEncoderUtils.getIA5NonNum(document.getProductOwner())); - - asnData.setProductIdNum(UicEncoderUtils.getNum(document.getProductId())); - asnData.setProductIdIA5(UicEncoderUtils.getIA5NonNum(document.getProductId())); + asnData.setProductOwnerNum(UicEncoderUtils.getRestrictedNum(document.getProductOwner(),1,32000)); + asnData.setProductOwnerIA5(UicEncoderUtils.getIA5RestrictedNonNum(document.getProductOwner(),1,32000)); + + asnData.setProductIdNum(UicEncoderUtils.getRestrictedNum(document.getProductId(),0,65535)); + asnData.setProductIdIA5(UicEncoderUtils.getIA5RestrictedNonNum(document.getProductId(),0,65535)); asnData.setReferenceNum(Asn1BigInteger.toAsn1(UicEncoderUtils.getNum(document.getReference()))); asnData.setReferenceIA5(UicEncoderUtils.getIA5NonNum(document.getReference())); @@ -1976,29 +2036,29 @@ public class Api2OpenAsnEncoderV3 implements Api2AsnEncoder { SequenceOfTicketLinkType asnList = new SequenceOfTicketLinkType(); - for (ITicketLink ticket : linkedTickets){ + for (ITicketLink document : linkedTickets){ - TicketLinkType asnTicket = new TicketLinkType(); + TicketLinkType asnData = new TicketLinkType(); - asnTicket.setIssuerName(ticket.getIssuer()); + asnData.setIssuerName(document.getIssuer()); - asnTicket.setIssuerPNR(ticket.getIssuerPNR()); + asnData.setIssuerPNR(document.getIssuerPNR()); - asnTicket.setProductOwnerNum(UicEncoderUtils.getNum(ticket.getProductOwner())); - asnTicket.setProductOwnerIA5(UicEncoderUtils.getIA5NonNum(ticket.getProductOwner())); - - asnTicket.setReferenceNum(UicEncoderUtils.getNum(ticket.getReference())); - asnTicket.setReferenceIA5(UicEncoderUtils.getIA5NonNum(ticket.getReference())); + asnData.setProductOwnerNum(UicEncoderUtils.getRestrictedNum(document.getProductOwner(),1,32000)); + asnData.setProductOwnerIA5(UicEncoderUtils.getIA5RestrictedNonNum(document.getProductOwner(),1,32000)); + + asnData.setReferenceNum(UicEncoderUtils.getNum(document.getReference())); + asnData.setReferenceIA5(UicEncoderUtils.getIA5NonNum(document.getReference())); - if (ticket.getTicketType() != ITicketType.openTicket && ticket.getTicketType() != null){ - asnTicket.setTicketType(TicketType.valueOf(ticket.getTicketType().name())); + if (document.getTicketType() != ITicketType.openTicket && document.getTicketType() != null){ + asnData.setTicketType(TicketType.valueOf(document.getTicketType().name())); } - if (ticket.getLinkMode() != ILinkMode.issuedTogether && ticket.getLinkMode() != null){ - asnTicket.setLinkMode(LinkMode.valueOf(ticket.getLinkMode().name())); + if (document.getLinkMode() != ILinkMode.issuedTogether && document.getLinkMode() != null){ + asnData.setLinkMode(LinkMode.valueOf(document.getLinkMode().name())); } - asnList.add(asnTicket); + asnList.add(asnData); } if (asnList.isEmpty()) return null; @@ -2106,6 +2166,12 @@ public class Api2OpenAsnEncoderV3 implements Api2AsnEncoder { asnData.setPointOfSale(encodeGeoCoordinate(data.getPointOfSale())); } + asnData.setCurrency(data.getCurrency()); + + if (data.getCurrencyFraction() != null) { + asnData.setCurrencyFract(data.getCurrencyFraction().longValue()); + } + return asnData; } diff --git a/src/main/java/org/uic/barcode/ticket/api/utils/OpenAsn2ApiDecoder.java b/src/main/java/org/uic/barcode/ticket/api/utils/OpenAsn2ApiDecoder.java index f62e1f9..5f5ce4d 100644 --- a/src/main/java/org/uic/barcode/ticket/api/utils/OpenAsn2ApiDecoder.java +++ b/src/main/java/org/uic/barcode/ticket/api/utils/OpenAsn2ApiDecoder.java @@ -5,12 +5,14 @@ package org.uic.barcode.ticket.api.utils; import java.io.IOException; import java.util.Date; +import java.util.Iterator; import java.util.List; import org.uic.barcode.ticket.api.asn.omv1.BerthDetailData; import org.uic.barcode.ticket.api.asn.omv1.CarCarriageReservationData; import org.uic.barcode.ticket.api.asn.omv1.CardReferenceType; import org.uic.barcode.ticket.api.asn.omv1.CompartmentDetailsType; +import org.uic.barcode.ticket.api.asn.omv1.CompartmentPositionType; import org.uic.barcode.ticket.api.asn.omv1.ControlData; import org.uic.barcode.ticket.api.asn.omv1.CountermarkData; import org.uic.barcode.ticket.api.asn.omv1.CustomerCardData; @@ -51,6 +53,7 @@ import org.uic.barcode.ticket.api.asn.omv1.VatDetailType; import org.uic.barcode.ticket.api.asn.omv1.ViaStationType; import org.uic.barcode.ticket.api.asn.omv1.VoucherData; import org.uic.barcode.ticket.api.asn.omv1.ZoneType; +import org.uic.barcode.ticket.api.asn.omv1.ServiceType; import org.uic.barcode.ticket.api.impl.SimpleUicTicketObjectFactory; import org.uic.barcode.ticket.api.spec.IBerth; import org.uic.barcode.ticket.api.spec.IBerthTypeType; @@ -94,6 +97,7 @@ import org.uic.barcode.ticket.api.spec.IRoofRackType; import org.uic.barcode.ticket.api.spec.IRouteSection; import org.uic.barcode.ticket.api.spec.ISeriesDataDetails; import org.uic.barcode.ticket.api.spec.IServiceBrand; +import org.uic.barcode.ticket.api.spec.IServiceType; import org.uic.barcode.ticket.api.spec.IStationCodeTable; import org.uic.barcode.ticket.api.spec.IStationPassage; import org.uic.barcode.ticket.api.spec.ITariff; @@ -436,6 +440,10 @@ public class OpenAsn2ApiDecoder implements Asn2ApiDecoder { document.setArrivalUTCoffset(asnDocument.getDepartureUTCOffset()); } + if (asnDocument.getService() != null) { + document.setService(convert(asnDocument.getService())); + } + if(asnDocument.getClassCode()!=null){ document.setClassCode(ITravelClassType.valueOf(asnDocument.getClassCode().name())); } @@ -455,6 +463,10 @@ public class OpenAsn2ApiDecoder implements Asn2ApiDecoder { if (asnDocument.getPlaces()!=null) { document.setPlaces(convertPlaces(asnDocument.getPlaces())); } + + if (asnDocument.getAdditionalPlaces()!=null) { + document.setAdditionalPlaces(convertPlaces(asnDocument.getAdditionalPlaces())); + } if (asnDocument.getBicyclePlaces()!=null) { document.setBicyclePlaces(convertPlaces(asnDocument.getBicyclePlaces())); @@ -517,6 +529,20 @@ public class OpenAsn2ApiDecoder implements Asn2ApiDecoder { } + private IServiceType convert(ServiceType service) { + + if (service == null) { + return null; + } else if (service.equals(ServiceType.seat)) { + return IServiceType.seat; + } else if (service.equals(ServiceType.couchette)) { + return IServiceType.couchette; + } else if (service.equals(ServiceType.berth)) { + return IServiceType.berth; + } + + return null; + } @@ -701,11 +727,24 @@ public class OpenAsn2ApiDecoder implements Asn2ApiDecoder { details.setCompartmentTypeDescr(asnDetails.getCompartmentTypeDescr()); details.setSpecialAllocationDescr(asnDetails.getSpecialAllocationDescr()); - details.setPosition(ICompartmentPositionType.valueOf(asnDetails.getPosition().name())); + details.setPosition(convert(asnDetails.getPosition())); return details; } + private ICompartmentPositionType convert(CompartmentPositionType position) { + if (position == null) { + return null; + } else if (position.equals(CompartmentPositionType.lowerLevel)) { + return ICompartmentPositionType.lowerLevel; + } else if (position.equals(CompartmentPositionType.upperLevel)) { + return ICompartmentPositionType.upperLevel; + } else if (position.equals(CompartmentPositionType.unspecified)) { + return ICompartmentPositionType.unspecified; + } + return null; + } + /** * Convert places. * @@ -796,7 +835,10 @@ public class OpenAsn2ApiDecoder implements Asn2ApiDecoder { document.setReference(UicEncoderUtils.mapToString(asnDocument.getReferenceNum(),asnDocument.getReferenceIA5())); document.setTicketReference(UicEncoderUtils.mapToString(asnDocument.getTicketReferenceNum(),asnDocument.getTicketReferenceIA5())); - + + if (asnDocument.getStationCodeTable()!=null){ + document.setStationCodeTable(IStationCodeTable.valueOf(asnDocument.getStationCodeTable().name())); + } document.setFromStation(UicEncoderUtils.mapToString(asnDocument.getFromStationNum(),asnDocument.getFromStationIA5())); document.setToStation(UicEncoderUtils.mapToString(asnDocument.getToStationNum(),asnDocument.getToStationIA5())); @@ -811,7 +853,6 @@ public class OpenAsn2ApiDecoder implements Asn2ApiDecoder { } document.setReturnDescription(convertReturnDescription(asnDocument.getReturnDescription(), issuingDate)); - if(asnDocument.getReturnIncluded()!=null){ document.setReturnIncluded(asnDocument.getReturnIncluded()); @@ -819,7 +860,29 @@ public class OpenAsn2ApiDecoder implements Asn2ApiDecoder { document.setReturnIncluded(false); } - + + if (asnDocument.getCarriersNum()!=null && !asnDocument.getCarriersNum().isEmpty()){ + for(Long carrier :asnDocument.getCarriersNum()){ + document.addIncludedCarrier(carrier.toString()); + } + } + if (asnDocument.getCarriersIA5()!=null && !asnDocument.getCarriersIA5().isEmpty()){ + for(String carrier :asnDocument.getCarriersIA5()){ + document.addIncludedCarrier(carrier); + } + } + + if (asnDocument.getIncludedServiceBrands()!=null && !asnDocument.getIncludedServiceBrands().isEmpty()){ + for(Long number :asnDocument.getIncludedServiceBrands()){ + document.addIncludedServiceBrand(number.intValue()); + } + } + + if (asnDocument.getExcludedServiceBrands()!=null && !asnDocument.getExcludedServiceBrands().isEmpty()){ + for(Long number :asnDocument.getExcludedServiceBrands()){ + document.addExcludedServiceBrand(number.intValue()); + } + } document.setGroupName(asnDocument.getGroupName()); @@ -932,6 +995,10 @@ public class OpenAsn2ApiDecoder implements Asn2ApiDecoder { document.setClassCode(ITravelClassType.valueOf(asnDocument.getClassCode().name())); } + if (asnDocument.getServiceLevel() != null && asnDocument.getServiceLevel().length() > 0) { + document.setServiceLevel(asnDocument.getServiceLevel()); + } + document.setValidFrom(asnDocument.getValidFromDate(issuingDate)); document.setValidUntil(asnDocument.getValidUntilDate(issuingDate)); @@ -1058,6 +1125,10 @@ public class OpenAsn2ApiDecoder implements Asn2ApiDecoder { document.setClassCode(classCode); } + if (asnDocument.getServiceLevel() != null && asnDocument.getServiceLevel().length() > 0) { + document.setServiceLevel(asnDocument.getServiceLevel()); + } + document.setValidFrom(asnDocument.getValidFromDate(issuingDate)); document.setValidUntil(asnDocument.getValidUntilDate(issuingDate)); @@ -1173,9 +1244,9 @@ public class OpenAsn2ApiDecoder implements Asn2ApiDecoder { document.setProductName(asnDocument.getProductName()); document.setProductOwner(UicEncoderUtils.mapToString(asnDocument.getProductOwnerNum(),asnDocument.getProductOwnerIA5())); - if (asnDocument.getStationNameUTF8()!= null && asnDocument.getStationNameUTF8().isEmpty() ) { + if (asnDocument.getStationNameUTF8()!= null && !asnDocument.getStationNameUTF8().isEmpty() ) { for (String name : asnDocument.getStationNameUTF8()) { - document.addStation(name); + document.addStationName(name); } } @@ -1338,9 +1409,13 @@ public class OpenAsn2ApiDecoder implements Asn2ApiDecoder { } if (asnDocument.getAlternativeRoutes()!= null && !asnDocument.getAlternativeRoutes().isEmpty()) { for ( ViaStationType routeVia: asnDocument.getAlternativeRoutes()) { - via.addRouteStation(convertViaStation(routeVia)); + via.getAlternativeRoutes().add(convertViaStation(routeVia)); } } + + if (asnDocument.getSeriesId() != null) { + via.setSeriesId(asnDocument.getSeriesId().intValue()); + } return via; @@ -1395,6 +1470,13 @@ public class OpenAsn2ApiDecoder implements Asn2ApiDecoder { zone.setNUTScode(asnDocument.getNutsCode()); + if (asnDocument.getZoneId() != null && !asnDocument.getZoneId().isEmpty()) { + Iterator it = asnDocument.getZoneId().iterator(); + while (it.hasNext()) { + zone.addZoneId(it.next().intValue()); + } + } + return zone; } @@ -1413,6 +1495,8 @@ public class OpenAsn2ApiDecoder implements Asn2ApiDecoder { IGeoCoordinate firstEdge = convertGeoCoordinate(asnPolygone.getFirstEdge()); if (firstEdge == null) return null; + + polygone.addEdge(firstEdge); if (asnPolygone.getEdges()!=null && !asnPolygone.getEdges().isEmpty()) { for (DeltaCoordinates asnEdge :asnPolygone.getEdges()){ @@ -1645,6 +1729,9 @@ public class OpenAsn2ApiDecoder implements Asn2ApiDecoder { if (asnDocument.getNumberOfDaysOfTravel() != null) { document.setNumberOfDaysOfTravel(asnDocument.getNumberOfDaysOfTravel().intValue()); } + if (asnDocument.getNumberOfValidityDays() != null) { + document.setNumberOfValidityDays(asnDocument.getNumberOfValidityDays().intValue()); + } if (asnDocument.getNumberOfPossibleTrips() != null) { document.setNumberOfPossibleTrips(asnDocument.getNumberOfPossibleTrips().intValue()); } @@ -1856,6 +1943,9 @@ public class OpenAsn2ApiDecoder implements Asn2ApiDecoder { card.addIncludedService(new Integer(service.intValue())); } } + + card.setExtension(convertExtension(asnDocument.getExtension())); + return card; } diff --git a/src/main/java/org/uic/barcode/ticket/api/utils/OpenAsn2ApiDecoderV3.java b/src/main/java/org/uic/barcode/ticket/api/utils/OpenAsn2ApiDecoderV3.java index b656d3c..a9cc0d3 100644 --- a/src/main/java/org/uic/barcode/ticket/api/utils/OpenAsn2ApiDecoderV3.java +++ b/src/main/java/org/uic/barcode/ticket/api/utils/OpenAsn2ApiDecoderV3.java @@ -5,8 +5,10 @@ package org.uic.barcode.ticket.api.utils; import java.io.IOException; import java.util.Date; +import java.util.Iterator; import java.util.List; +import org.uic.barcode.ticket.api.asn.omv3.CompartmentPositionType; import org.uic.barcode.ticket.api.asn.omv3.BerthDetailData; import org.uic.barcode.ticket.api.asn.omv3.CarCarriageReservationData; import org.uic.barcode.ticket.api.asn.omv3.CardReferenceType; @@ -36,6 +38,7 @@ import org.uic.barcode.ticket.api.asn.omv3.ReservationData; import org.uic.barcode.ticket.api.asn.omv3.ReturnRouteDescriptionType; import org.uic.barcode.ticket.api.asn.omv3.RouteSectionType; import org.uic.barcode.ticket.api.asn.omv3.SeriesDetailType; +import org.uic.barcode.ticket.api.asn.omv3.ServiceType; import org.uic.barcode.ticket.api.asn.omv3.StationPassageData; import org.uic.barcode.ticket.api.asn.omv3.TariffType; import org.uic.barcode.ticket.api.asn.omv3.TicketLinkType; @@ -96,6 +99,7 @@ import org.uic.barcode.ticket.api.spec.IRoofRackType; import org.uic.barcode.ticket.api.spec.IRouteSection; import org.uic.barcode.ticket.api.spec.ISeriesDataDetails; import org.uic.barcode.ticket.api.spec.IServiceBrand; +import org.uic.barcode.ticket.api.spec.IServiceType; import org.uic.barcode.ticket.api.spec.IStationCodeTable; import org.uic.barcode.ticket.api.spec.IStationPassage; import org.uic.barcode.ticket.api.spec.ITariff; @@ -441,6 +445,10 @@ public class OpenAsn2ApiDecoderV3 implements Asn2ApiDecoder { document.setArrivalUTCoffset(asnDocument.getDepartureUTCOffset()); } + if (asnDocument.getService() != null) { + document.setService(convert(asnDocument.getService())); + } + if(asnDocument.getClassCode()!=null){ document.setClassCode(ITravelClassType.valueOf(asnDocument.getClassCode().name())); } @@ -460,6 +468,11 @@ public class OpenAsn2ApiDecoderV3 implements Asn2ApiDecoder { if (asnDocument.getPlaces()!=null) { document.setPlaces(convertPlaces(asnDocument.getPlaces())); } + + if (asnDocument.getAdditionalPlaces()!=null) { + document.setAdditionalPlaces(convertPlaces(asnDocument.getAdditionalPlaces())); + } + if (asnDocument.getBicyclePlaces()!=null) { document.setBicyclePlaces(convertPlaces(asnDocument.getBicyclePlaces())); @@ -522,12 +535,20 @@ public class OpenAsn2ApiDecoderV3 implements Asn2ApiDecoder { } - - - - - - + private IServiceType convert(ServiceType service) { + + if (service == null) { + return null; + } else if (service.equals(ServiceType.seat)) { + return IServiceType.seat; + } else if (service.equals(ServiceType.couchette)) { + return IServiceType.couchette; + } else if (service.equals(ServiceType.berth)) { + return IServiceType.berth; + } + + return null; + } /** * Convert car carriage. @@ -706,11 +727,24 @@ public class OpenAsn2ApiDecoderV3 implements Asn2ApiDecoder { details.setCompartmentTypeDescr(asnDetails.getCompartmentTypeDescr()); details.setSpecialAllocationDescr(asnDetails.getSpecialAllocationDescr()); - details.setPosition(ICompartmentPositionType.valueOf(asnDetails.getPosition().name())); + details.setPosition(convert(asnDetails.getPosition())); return details; } + private ICompartmentPositionType convert(CompartmentPositionType position) { + if (position == null) { + return null; + } else if (position.equals(CompartmentPositionType.lowerLevel)) { + return ICompartmentPositionType.lowerLevel; + } else if (position.equals(CompartmentPositionType.upperLevel)) { + return ICompartmentPositionType.upperLevel; + } else if (position.equals(CompartmentPositionType.unspecified)) { + return ICompartmentPositionType.unspecified; + } + return null; + } + /** * Convert places. * @@ -802,6 +836,9 @@ public class OpenAsn2ApiDecoderV3 implements Asn2ApiDecoder { document.setReference(UicEncoderUtils.mapToString(asnDocument.getReferenceNum(),asnDocument.getReferenceIA5())); document.setTicketReference(UicEncoderUtils.mapToString(asnDocument.getTicketReferenceNum(),asnDocument.getTicketReferenceIA5())); + if (asnDocument.getStationCodeTable()!=null){ + document.setStationCodeTable(IStationCodeTable.valueOf(asnDocument.getStationCodeTable().name())); + } document.setFromStation(UicEncoderUtils.mapToString(asnDocument.getFromStationNum(),asnDocument.getFromStationIA5())); document.setToStation(UicEncoderUtils.mapToString(asnDocument.getToStationNum(),asnDocument.getToStationIA5())); @@ -825,6 +862,28 @@ public class OpenAsn2ApiDecoderV3 implements Asn2ApiDecoder { } + if (asnDocument.getCarriersNum()!=null && !asnDocument.getCarriersNum().isEmpty()){ + for(Long carrier :asnDocument.getCarriersNum()){ + document.addIncludedCarrier(carrier.toString()); + } + } + if (asnDocument.getCarriersIA5()!=null && !asnDocument.getCarriersIA5().isEmpty()){ + for(String carrier :asnDocument.getCarriersIA5()){ + document.addIncludedCarrier(carrier); + } + } + + if (asnDocument.getIncludedServiceBrands()!=null && !asnDocument.getIncludedServiceBrands().isEmpty()){ + for(Long number :asnDocument.getIncludedServiceBrands()){ + document.addIncludedServiceBrand(number.intValue()); + } + } + + if (asnDocument.getExcludedServiceBrands()!=null && !asnDocument.getExcludedServiceBrands().isEmpty()){ + for(Long number :asnDocument.getExcludedServiceBrands()){ + document.addExcludedServiceBrand(number.intValue()); + } + } document.setGroupName(asnDocument.getGroupName()); @@ -937,6 +996,10 @@ public class OpenAsn2ApiDecoderV3 implements Asn2ApiDecoder { document.setClassCode(ITravelClassType.valueOf(asnDocument.getClassCode().name())); } + if (asnDocument.getServiceLevel() != null && asnDocument.getServiceLevel().length() > 0) { + document.setServiceLevel(asnDocument.getServiceLevel()); + } + document.setValidFrom(asnDocument.getValidFromDate(issuingDate)); document.setValidUntil(asnDocument.getValidUntilDate(issuingDate)); @@ -954,12 +1017,6 @@ public class OpenAsn2ApiDecoderV3 implements Asn2ApiDecoder { document.setProductOwner(UicEncoderUtils.mapToString(asnDocument.getProductOwnerNum(),asnDocument.getProductOwnerIA5())); document.setReference(UicEncoderUtils.mapToString(asnDocument.getReferenceNum(),asnDocument.getReferenceIA5())); - if (asnDocument.getExcludedServiceBrands()!=null && !asnDocument.getExcludedServiceBrands().isEmpty()){ - for(Long number :asnDocument.getExcludedServiceBrands()){ - document.addExcludedServiceBrand(number.intValue()); - } - } - if (asnDocument.getCarriersNum()!=null && !asnDocument.getCarriersNum().isEmpty()){ for(Long carrier :asnDocument.getCarriersNum()){ document.addIncludedCarrier(carrier.toString()); @@ -978,6 +1035,12 @@ public class OpenAsn2ApiDecoderV3 implements Asn2ApiDecoder { } } + if (asnDocument.getExcludedServiceBrands()!=null && !asnDocument.getExcludedServiceBrands().isEmpty()){ + for(Long number :asnDocument.getExcludedServiceBrands()){ + document.addExcludedServiceBrand(number.intValue()); + } + } + if (asnDocument.getIncludedTransportTypes()!=null && !asnDocument.getIncludedTransportTypes().isEmpty()){ for(Long number :asnDocument.getIncludedTransportTypes()){ document.addInludedTransportType(number.intValue()); @@ -1012,6 +1075,8 @@ public class OpenAsn2ApiDecoderV3 implements Asn2ApiDecoder { } } + document.setReturnDescription(convertReturnDescription(asnDocument.getReturnDescription(), issuingDate)); + if (asnDocument.getIssuerAutorizationId() != null) { document.setAuthorizationCode(asnDocument.getIssuerAutorizationId().intValue()); } @@ -1077,6 +1142,10 @@ public class OpenAsn2ApiDecoderV3 implements Asn2ApiDecoder { document.setClassCode(classCode); } + if (asnDocument.getServiceLevel() != null && asnDocument.getServiceLevel().length() > 0) { + document.setServiceLevel(asnDocument.getServiceLevel()); + } + document.setValidFrom(asnDocument.getValidFromDate(issuingDate)); document.setValidUntil(asnDocument.getValidUntilDate(issuingDate)); @@ -1149,6 +1218,8 @@ public class OpenAsn2ApiDecoderV3 implements Asn2ApiDecoder { if (asnDocument.getExternalIssuerId()!=null){ document.setExternalIssuer(asnDocument.getExternalIssuerId().intValue()); } + + return document; } @@ -1204,9 +1275,9 @@ public class OpenAsn2ApiDecoderV3 implements Asn2ApiDecoder { document.setProductName(asnDocument.getProductName()); document.setProductOwner(UicEncoderUtils.mapToString(asnDocument.getProductOwnerNum(),asnDocument.getProductOwnerIA5())); - if (asnDocument.getStationNameUTF8()!= null && asnDocument.getStationNameUTF8().isEmpty() ) { + if (asnDocument.getStationNameUTF8()!= null && !asnDocument.getStationNameUTF8().isEmpty() ) { for (String name : asnDocument.getStationNameUTF8()) { - document.addStation(name); + document.addStationName(name); } } @@ -1381,10 +1452,13 @@ public class OpenAsn2ApiDecoderV3 implements Asn2ApiDecoder { } if (asnDocument.getAlternativeRoutes()!= null && !asnDocument.getAlternativeRoutes().isEmpty()) { for ( ViaStationType routeVia: asnDocument.getAlternativeRoutes()) { - via.addRouteStation(convertViaStation(routeVia)); + via.getAlternativeRoutes().add(convertViaStation(routeVia)); } } - + + if (asnDocument.getSeriesId() != null) { + via.setSeriesId(asnDocument.getSeriesId().intValue()); + } return via; } @@ -1438,6 +1512,14 @@ public class OpenAsn2ApiDecoderV3 implements Asn2ApiDecoder { zone.setNUTScode(asnDocument.getNutsCode()); + if (asnDocument.getZoneId() != null && !asnDocument.getZoneId().isEmpty()) { + Iterator it = asnDocument.getZoneId().iterator(); + while (it.hasNext()) { + zone.addZoneId(it.next().intValue()); + } + } + + return zone; } @@ -1456,6 +1538,8 @@ public class OpenAsn2ApiDecoderV3 implements Asn2ApiDecoder { IGeoCoordinate firstEdge = convertGeoCoordinate(asnPolygone.getFirstEdge()); if (firstEdge == null) return null; + + polygone.addEdge(firstEdge); if (asnPolygone.getEdges()!=null && !asnPolygone.getEdges().isEmpty()) { for (DeltaCoordinates asnEdge :asnPolygone.getEdges()){ @@ -1630,17 +1714,26 @@ public class OpenAsn2ApiDecoderV3 implements Asn2ApiDecoder { document.setValidFrom(asnDocument.getValidFromDate(issuingDate)); document.setValidUntil(asnDocument.getValidUntilDate(issuingDate)); - - document.setProductId(UicEncoderUtils.mapToString(asnDocument.getProductIdNum(),asnDocument.getProductIdIA5())); document.setProductOwner(UicEncoderUtils.mapToString(asnDocument.getProductOwnerNum(),asnDocument.getProductOwnerIA5())); document.setReference(UicEncoderUtils.mapToString(asnDocument.getReferenceNum(),asnDocument.getReferenceIA5())); + if (asnDocument.getCarrierNum()!=null && !asnDocument.getCarrierNum().isEmpty()){ + for(Long carrier :asnDocument.getCarrierNum()){ + document.addCarrier(carrier.toString()); + } + } + if (asnDocument.getCarrierIA5()!=null && !asnDocument.getCarrierIA5().isEmpty()){ + for(String carrier :asnDocument.getCarrierIA5()){ + document.addCarrier(carrier); + } + } + if (asnDocument.getActivatedDay() != null && !asnDocument.getActivatedDay().isEmpty()) { document.getActivatedDays().addAll(asnDocument.getActivatedDays(issuingDate)); } - if(asnDocument.getIncludesSupplements()!=null) { + if(asnDocument.getIncludesSupplements()!= null) { document.setIncludesSupplements(asnDocument.getIncludesSupplements()); } if(asnDocument.getNumberOfTravelDays()!=null){ @@ -1688,6 +1781,9 @@ public class OpenAsn2ApiDecoderV3 implements Asn2ApiDecoder { if (asnDocument.getNumberOfDaysOfTravel() != null) { document.setNumberOfDaysOfTravel(asnDocument.getNumberOfDaysOfTravel().intValue()); } + if (asnDocument.getNumberOfValidityDays() != null) { + document.setNumberOfValidityDays(asnDocument.getNumberOfValidityDays().intValue()); + } if (asnDocument.getNumberOfPossibleTrips() != null) { document.setNumberOfPossibleTrips(asnDocument.getNumberOfPossibleTrips().intValue()); } @@ -1958,6 +2054,9 @@ public class OpenAsn2ApiDecoderV3 implements Asn2ApiDecoder { card.addIncludedService(new Integer(service.intValue())); } } + + card.setExtension(convertExtension(asnDocument.getExtension())); + return card; } @@ -2212,6 +2311,12 @@ public class OpenAsn2ApiDecoderV3 implements Asn2ApiDecoder { issuingDetail.setPointOfSale(convertGeoCoordinate(asnIssuingDetail.getPointOfSale())); } + issuingDetail.setCurrency(asnIssuingDetail.getCurrency()); + + if (asnIssuingDetail.getCurrencyFract() != null) { + issuingDetail.setCurrencyFraction(asnIssuingDetail.getCurrencyFract().intValue()); + } + } diff --git a/src/main/java/org/uic/barcode/ticket/api/utils/UicEncoderUtils.java b/src/main/java/org/uic/barcode/ticket/api/utils/UicEncoderUtils.java index 73f96f1..f5eb15c 100644 --- a/src/main/java/org/uic/barcode/ticket/api/utils/UicEncoderUtils.java +++ b/src/main/java/org/uic/barcode/ticket/api/utils/UicEncoderUtils.java @@ -329,6 +329,49 @@ public class UicEncoderUtils { } } + + public static Long getRestrictedNum(String text, int min, int max) { + + if (text == null || text.length() == 0) { + return null; + } + + Long i; + try { + i = Long.parseLong(text); + } catch (NumberFormatException e) { + return null; + } + if (i < min || i > max) { + return null; + } + return i; + + } + + public static String getIA5RestrictedNonNum(String text, int min, int max) throws EncodingFormatException { + if (text == null || text.length() == 0) { + return null; + } + + for (int i = 0; i < text.length(); i++){ + int index = text.charAt(i); + if (index < 0 || index > 127) { + throw new EncodingFormatException("Wrong Characters in IA5 String encoding"); + } + } + + try { + long l = Long.parseLong(text); + if (l < min || l > max) { + return text; + } else { + return null; + } + } catch (NumberFormatException e) { + return text; + } + } /** * Gets the restricted int. @@ -511,4 +554,6 @@ public class UicEncoderUtils { } + + } -- cgit v1.2.3