From aaeb77f8f58ebc01fd241139439a8d290765e5fc Mon Sep 17 00:00:00 2001 From: CGantert345 <57003061+CGantert345@users.noreply.github.com> Date: Tue, 28 Jul 2020 17:56:59 +0200 Subject: Draft of the new DOSIPAS included --- .../uic/ticket/api/utils/Api2OpenAsnEncoder.java | 295 ++++++++++++--------- .../uic/ticket/api/utils/OpenAsn2ApiDecoder.java | 244 +++++++++-------- src/org/uic/ticket/api/utils/UicEncoderUtils.java | 4 +- 3 files changed, 314 insertions(+), 229 deletions(-) (limited to 'src/org/uic/ticket/api/utils') diff --git a/src/org/uic/ticket/api/utils/Api2OpenAsnEncoder.java b/src/org/uic/ticket/api/utils/Api2OpenAsnEncoder.java index cb274c1..ba2f13a 100644 --- a/src/org/uic/ticket/api/utils/Api2OpenAsnEncoder.java +++ b/src/org/uic/ticket/api/utils/Api2OpenAsnEncoder.java @@ -10,7 +10,7 @@ import net.gcdc.asn1.datatypesimpl.SequenceOfStringIA5; import net.gcdc.asn1.datatypesimpl.SequenceOfStringUTF8; import net.gcdc.asn1.datatypesimpl.SequenceOfUnrestrictedLong; -import org.uic.ticket.api.EncodingFormatException; +import org.uic.ticket.EncodingFormatException; import org.uic.ticket.api.asn.omv1.BerthDetailData; import org.uic.ticket.api.asn.omv1.CarCarriageReservationData; import org.uic.ticket.api.asn.omv1.CardReferenceType; @@ -90,10 +90,12 @@ import org.uic.ticket.api.asn.omv1.VatDetailType; import org.uic.ticket.api.asn.omv1.ViaStationType; import org.uic.ticket.api.asn.omv1.VoucherData; import org.uic.ticket.api.asn.omv1.ZoneType; +import org.uic.ticket.api.asn.omv1.BerthTypeType; import org.uic.ticket.api.spec.IBerth; import org.uic.ticket.api.spec.ICarCarriageReservation; import org.uic.ticket.api.spec.ICardReference; import org.uic.ticket.api.spec.ICompartmentDetails; +import org.uic.ticket.api.spec.ICompartmentGenderType; import org.uic.ticket.api.spec.IControlDetail; import org.uic.ticket.api.spec.ICounterMark; import org.uic.ticket.api.spec.ICustomerCard; @@ -103,27 +105,38 @@ import org.uic.ticket.api.spec.IDocumentData; import org.uic.ticket.api.spec.IExtension; import org.uic.ticket.api.spec.IFipTicket; import org.uic.ticket.api.spec.IGeoCoordinate; +import org.uic.ticket.api.spec.IGeoCoordinateSystemType; +import org.uic.ticket.api.spec.IGeoUnitType; +import org.uic.ticket.api.spec.IHemisphereLatitudeType; +import org.uic.ticket.api.spec.IHemisphereLongitudeType; import org.uic.ticket.api.spec.IIncludedOpenTicket; import org.uic.ticket.api.spec.IIssuingDetail; import org.uic.ticket.api.spec.ILine; +import org.uic.ticket.api.spec.ILinkMode; +import org.uic.ticket.api.spec.ILoadingDeckType; import org.uic.ticket.api.spec.ILuggageRestriction; import org.uic.ticket.api.spec.IOpenTicket; import org.uic.ticket.api.spec.IParkingGround; import org.uic.ticket.api.spec.IPass; import org.uic.ticket.api.spec.IPlaces; import org.uic.ticket.api.spec.IPolygone; +import org.uic.ticket.api.spec.IPriceTypeType; import org.uic.ticket.api.spec.IRegionalValidity; import org.uic.ticket.api.spec.IRegisteredLuggage; import org.uic.ticket.api.spec.IReservation; import org.uic.ticket.api.spec.IReturnRouteDescription; +import org.uic.ticket.api.spec.IRoofRackType; import org.uic.ticket.api.spec.IRouteSection; import org.uic.ticket.api.spec.ISeriesDataDetails; +import org.uic.ticket.api.spec.IServiceType; import org.uic.ticket.api.spec.IStationPassage; import org.uic.ticket.api.spec.ITariff; import org.uic.ticket.api.spec.ITicketLink; +import org.uic.ticket.api.spec.ITicketType; import org.uic.ticket.api.spec.ITimeRange; import org.uic.ticket.api.spec.IToken; import org.uic.ticket.api.spec.ITrainLink; +import org.uic.ticket.api.spec.ITravelClassType; import org.uic.ticket.api.spec.ITraveler; import org.uic.ticket.api.spec.ITravelerDetail; import org.uic.ticket.api.spec.IUicRailTicket; @@ -133,6 +146,7 @@ import org.uic.ticket.api.spec.IVatDetail; import org.uic.ticket.api.spec.IViaStation; import org.uic.ticket.api.spec.IVoucher; import org.uic.ticket.api.spec.IZone; +import org.uic.ticket.api.spec.IStationCodeTable; /** * The Class Api2OpenAsnEncoder. @@ -140,6 +154,23 @@ import org.uic.ticket.api.spec.IZone; public class Api2OpenAsnEncoder { + /** + * encode to asn1 model. + * + * @param uicTicket the uic ticket + * @return the encoded byte array + * @throws EncodingFormatException the encoding format exception + */ + public byte[] encode(IUicRailTicket uicTicket) throws EncodingFormatException { + + UicRailTicketData asnUicRailTicketData = populateToAsn1Model(uicTicket); + + return asnUicRailTicketData.encode(); + + } + + + /** * Populate asn1 model. * @@ -251,6 +282,8 @@ public class Api2OpenAsnEncoder { return asnTicket; } + + private DocumentData encodeDelayConfirmation(IDelayConfirmation document, Date issuingDate) throws EncodingFormatException { DocumentData asnDocument = new DocumentData(); @@ -266,8 +299,8 @@ public class Api2OpenAsnEncoder { asnData.setReferenceNum(UicEncoderUtils.getNum(document.getReference())); asnData.setReferenceIA5(UicEncoderUtils.getIA5NonNum(document.getReference())); - if (document.getStationCodeTable() != CodeTableType.stationUICReservation){ - asnData.setStationCodeTable(document.getStationCodeTable()); + if (document.getStationCodeTable() != IStationCodeTable.stationUIC && document.getStationCodeTable() != null){ + asnData.setStationCodeTable(CodeTableType.valueOf(document.getStationCodeTable().name())); } asnData.setStationIA5(UicEncoderUtils.getIA5NonNum(document.getStation())); asnData.setStationNum(UicEncoderUtils.getNum(document.getStation())); @@ -321,8 +354,8 @@ public class Api2OpenAsnEncoder { asnData.setReferenceNum(UicEncoderUtils.getNum(document.getReference())); asnData.setReferenceIA5(UicEncoderUtils.getIA5NonNum(document.getReference())); - if (document.getStationCodeTable() != CodeTableType.stationUICReservation){ - asnData.setStationCodeTable(document.getStationCodeTable()); + if (document.getStationCodeTable() != IStationCodeTable.stationUICReservation && document.getStationCodeTable() != null){ + asnData.setStationCodeTable(CodeTableType.valueOf(document.getStationCodeTable().name())); } asnData.setCarrierNum(SequenceOfCarrierNum.getSequence(UicEncoderUtils.getNumList(document.getCarriers()))); @@ -333,8 +366,8 @@ public class Api2OpenAsnEncoder { asnData.setCompartmentDetails(encodeCompartmentDetails(document.getCompartmentDetails())); - if (document.getPriceType()!= PriceTypeType.travelPrice){ - asnData.setPriceType(document.getPriceType()); + if (document.getPriceType()!= IPriceTypeType.travelPrice && document.getPriceType() != null ){ + asnData.setPriceType(PriceTypeType.valueOf(document.getPriceType().name())); } @@ -344,8 +377,8 @@ public class Api2OpenAsnEncoder { asnData.setServiceBrandNameUTF8(document.getServiceBrand().getServiceBrandDescription()); } - if (document.getStationCodeTable() != CodeTableType.stationUICReservation){ - asnData.setStationCodeTable(document.getStationCodeTable()); + if (document.getStationCodeTable() != IStationCodeTable.stationUICReservation && document.getStationCodeTable() != null){ + asnData.setStationCodeTable(CodeTableType.valueOf(document.getStationCodeTable().name())); } asnData.setFromStationIA5(UicEncoderUtils.getIA5NonNum(document.getFromStation())); @@ -362,8 +395,8 @@ public class Api2OpenAsnEncoder { asnData.setAttachedBoats(UicEncoderUtils.getRestrictedInt(document.getAttachedBoats(),1,2)); asnData.setAttachedSurfboards(UicEncoderUtils.getRestrictedInt(document.getAttachedSurfboards(),1,5)); - if (document.getLoadingDeck() != LoadingDeckType.upper){ - asnData.setLoadingDeck(document.getLoadingDeck()); + if (document.getLoadingDeck() != ILoadingDeckType.upper && document.getLoadingDeck() != null){ + asnData.setLoadingDeck(LoadingDeckType.valueOf(document.getLoadingDeck().name())); } asnData.setLoadingListEntry(UicEncoderUtils.getRestrictedInt(document.getAttachedSurfboards(),1,200)); @@ -374,8 +407,8 @@ public class Api2OpenAsnEncoder { asnData.setRoofRackHeight(UicEncoderUtils.getRestrictedInt(document.getRoofRackHeight(),1,99)); - if (document.getRoofRackType()!= RoofRackType.norack) { - asnData.setRoofRackType(document.getRoofRackType()); + if (document.getRoofRackType()!= IRoofRackType.norack && document.getRoofRackType() != null ) { + asnData.setRoofRackType(RoofRackType.valueOf(document.getRoofRackType().name())); } if (document.getTariff() != null) { @@ -475,10 +508,12 @@ public class Api2OpenAsnEncoder { for ( IBerth berth : berths){ BerthDetailData asnBerth = new BerthDetailData(); - asnBerth.setBerthType(berth.getType()); + if (berth.getType() != null) { + asnBerth.setBerthType(BerthTypeType.valueOf(berth.getType().name())); + } - if (berth.getGender()!= CompartmentGenderType.family) { - asnBerth.setGender(berth.getGender()); + if (berth.getGender()!= ICompartmentGenderType.family && berth.getGender() != null) { + asnBerth.setGender(CompartmentGenderType.valueOf(berth.getGender().name())); } asnBerth.setNumberOfBerths(UicEncoderUtils.getRestrictedInt(berth.getNumberOfBerths(), 1 , 999 )); @@ -521,8 +556,8 @@ public class Api2OpenAsnEncoder { asnData.setCarrierNum(SequenceOfCarrierNum.getSequence(UicEncoderUtils.getNumList(document.getCarriers()))); asnData.setCarrierIA5(UicEncoderUtils.getIA5NonNumList(document.getCarriers())); - if (document.getStationCodeTable() != CodeTableType.stationUICReservation){ - asnData.setStationCodeTable(document.getStationCodeTable()); + if (document.getStationCodeTable() != IStationCodeTable.stationUICReservation && document.getStationCodeTable() != null){ + asnData.setStationCodeTable(CodeTableType.valueOf(document.getStationCodeTable().name())); } asnData.setFromStationIA5(UicEncoderUtils.getIA5NonNum(document.getFromStation())); @@ -550,8 +585,8 @@ public class Api2OpenAsnEncoder { - if (document.getClassCode() != TravelClassType.second){ - asnData.setClassCode(document.getClassCode()); + if (document.getClassCode() != ITravelClassType.second){ + asnData.setClassCode(convertTravelClass(document.getClassCode())); } asnData.setBerth(encodeBerths(document.getBerths())); @@ -563,8 +598,8 @@ public class Api2OpenAsnEncoder { asnData.setNumberOfOverbooked(UicEncoderUtils.getRestrictedInt(document.getNumberOfOverbooked(), 1, 200)); asnData.setNumberOfSupplements(UicEncoderUtils.getRestrictedInt(document.getNumberOfSupplements(), 1, 200)); - if (document.getPriceType()!=PriceTypeType.travelPrice){ - asnData.setPriceType(document.getPriceType()); + if (document.getPriceType()!= IPriceTypeType.travelPrice && document.getPriceType() != null){ + asnData.setPriceType(PriceTypeType.valueOf(document.getPriceType().name())); } asnData.setTypeOfSupplement(UicEncoderUtils.getRestrictedInt(document.getTypeOfSupplement(), 1, 9)); @@ -572,8 +607,8 @@ public class Api2OpenAsnEncoder { asnData.setBicyclePlaces(encodePlaces(document.getBicyclePlaces())); - if (document.getService() != ServiceType.seat) { - asnData.setService(document.getService()); + if (document.getService() != IServiceType.seat && document.getService() != null) { + asnData.setService(ServiceType.valueOf(document.getService().name())); } if (document.getServiceBrand()!= null) { @@ -604,11 +639,11 @@ public class Api2OpenAsnEncoder { * * @param tickets the tickets * @param issuingDate the issuing date - * @param classCode the class code + * @param travelClassType the class code * @return the list * @throws EncodingFormatException the encoding format exception */ - private SequenceOfIncludedOpenTicketType encodeIncludedAddons(Collection tickets, Date issuingDate, TravelClassType classCode) throws EncodingFormatException { + private SequenceOfIncludedOpenTicketType encodeIncludedAddons(Collection tickets, Date issuingDate, ITravelClassType travelClassType) throws EncodingFormatException { if (tickets == null || tickets.isEmpty()) { return null; @@ -617,7 +652,7 @@ public class Api2OpenAsnEncoder { for ( IIncludedOpenTicket ticket : tickets){ - IncludedOpenTicketType asnTicket = encodeIncludedOpenTicket(ticket,issuingDate,classCode); + IncludedOpenTicketType asnTicket = encodeIncludedOpenTicket(ticket,issuingDate,travelClassType); if (asnTicket!=null) { asnList.add(asnTicket); } @@ -639,7 +674,7 @@ public class Api2OpenAsnEncoder { * @return the included open ticket type * @throws EncodingFormatException the encoding format exception */ - private IncludedOpenTicketType encodeIncludedOpenTicket(IIncludedOpenTicket document, Date issuingDate, TravelClassType classCode) throws EncodingFormatException { + private IncludedOpenTicketType encodeIncludedOpenTicket(IIncludedOpenTicket document, Date issuingDate, ITravelClassType classCode) throws EncodingFormatException { if (document == null) return null; @@ -655,8 +690,8 @@ public class Api2OpenAsnEncoder { asnData.setInfoText(document.getInfoText()); asnData.setExtension(encodeExtension(document.getExtension())); - if (document.getStationCodeTable() != CodeTableType.stationUIC){ - asnData.setStationCodeTable(document.getStationCodeTable()); + if (document.getStationCodeTable() != IStationCodeTable.stationUIC && document.getStationCodeTable() != null){ + asnData.setStationCodeTable(CodeTableType.valueOf(document.getStationCodeTable().name())); } asnData.setIncludedCarriersNum(SequenceOfCarrierNum.getSequence(UicEncoderUtils.getNumList(document.getIncludedCarriers()))); @@ -680,7 +715,7 @@ public class Api2OpenAsnEncoder { } if (document.getClassCode() != classCode){ - asnData.setClassCode(document.getClassCode()); + asnData.setClassCode(convertTravelClass(document.getClassCode())); } if (document.getExternalIssuer() > 0) { asnData.setExternalIssuerId(new Long(document.getExternalIssuer())); @@ -815,8 +850,8 @@ public class Api2OpenAsnEncoder { asnData.setInfoText(document.getInfoText()); asnData.setExtension(encodeExtension(document.getExtension())); - if (document.getStationCodeTable() != CodeTableType.stationUIC){ - asnData.setStationCodeTable(document.getStationCodeTable()); + if (document.getStationCodeTable() != IStationCodeTable.stationUIC && document.getStationCodeTable() != null){ + asnData.setStationCodeTable(CodeTableType.valueOf(document.getStationCodeTable().name())); } asnData.setFromStationIA5(UicEncoderUtils.getIA5NonNum(document.getFromStation())); @@ -848,8 +883,8 @@ public class Api2OpenAsnEncoder { asnData.setActivatedDays(document.getActivatedDays(),document.getValidFrom()); - if (document.getClassCode() != TravelClassType.second){ - asnData.setClassCode(document.getClassCode()); + if (document.getClassCode() != ITravelClassType.second){ + asnData.setClassCode(convertTravelClass(document.getClassCode())); } if (document.getExternalIssuer()>0) { asnData.setExtIssuerId(new Long(document.getExternalIssuer())); @@ -918,8 +953,8 @@ public class Api2OpenAsnEncoder { asnData.setInfoText(document.getInfoText()); asnData.setExtension(encodeExtension(document.getExtension())); - if (document.getStationCodeTable() != CodeTableType.stationUIC){ - asnData.setStationCodeTable(document.getStationCodeTable()); + if (document.getStationCodeTable() != IStationCodeTable.stationUIC && document.getStationCodeTable() != null){ + asnData.setStationCodeTable(CodeTableType.valueOf(document.getStationCodeTable().name())); } asnData.setFromStationIA5(UicEncoderUtils.getIA5NonNum(document.getFromStation())); @@ -948,8 +983,8 @@ public class Api2OpenAsnEncoder { asnData.setInfoText(document.getInfoText()); asnData.setExtension(encodeExtension(document.getExtension())); - if (document.getStationCodeTable() != CodeTableType.stationUIC){ - asnData.setStationCodeTable(document.getStationCodeTable()); + if (document.getStationCodeTable() != IStationCodeTable.stationUIC && document.getStationCodeTable() != null){ + asnData.setStationCodeTable(CodeTableType.valueOf(document.getStationCodeTable().name())); } asnData.setFromStationIA5(UicEncoderUtils.getIA5NonNum(document.getFromStation())); @@ -972,8 +1007,8 @@ public class Api2OpenAsnEncoder { } asnData.setValidRegionDesc(document.getValidRegionDesc()); - if (document.getClassCode() != TravelClassType.second){ - asnData.setClassCode(document.getClassCode()); + if (document.getClassCode() != ITravelClassType.second){ + asnData.setClassCode(convertTravelClass(document.getClassCode())); } @@ -1022,37 +1057,37 @@ public class Api2OpenAsnEncoder { /** * Encode via station. * - * @param data the data + * @param document the data * @return the via station type * @throws EncodingFormatException the encoding format exception */ - private ViaStationType encodeViaStation(IViaStation data) throws EncodingFormatException { - if (data == null) return null; + private ViaStationType encodeViaStation(IViaStation document) throws EncodingFormatException { + if (document == null) return null; ViaStationType asnData =new ViaStationType(); - if (data.getStationCodeTable() != CodeTableType.stationUIC){ - asnData.setStationCodeTable(data.getStationCodeTable()); + if (document.getStationCodeTable() != IStationCodeTable.stationUIC && document.getStationCodeTable() != null){ + asnData.setStationCodeTable(CodeTableType.valueOf(document.getStationCodeTable().name())); } - asnData.setStationIA5(UicEncoderUtils.getIA5NonNum(data.getStation())); - asnData.setStationNum(UicEncoderUtils.getNum(data.getStation())); + asnData.setStationIA5(UicEncoderUtils.getIA5NonNum(document.getStation())); + asnData.setStationNum(UicEncoderUtils.getNum(document.getStation())); - asnData.setAlternativeRoutes(encodeViaStationCollection(data.getAlternativeRoutes())); + asnData.setAlternativeRoutes(encodeViaStationCollection(document.getAlternativeRoutes())); - if (data.isBorder()) { + if (document.isBorder()) { asnData.setBorder(true); } else { asnData.setBorder(false); } - asnData.setCarriersNum(SequenceOfCarrierNum.getSequence(UicEncoderUtils.getNumList(data.getCarriers()))); - asnData.setCarriersIA5(UicEncoderUtils.getIA5NonNumList(data.getCarriers())); + asnData.setCarriersNum(SequenceOfCarrierNum.getSequence(UicEncoderUtils.getNumList(document.getCarriers()))); + asnData.setCarriersIA5(UicEncoderUtils.getIA5NonNumList(document.getCarriers())); - asnData.setRoute(encodeViaStationCollection(data.getRoute())); + asnData.setRoute(encodeViaStationCollection(document.getRoute())); - if (data.getRouteId() > 0){ - asnData.setSeriesId(new Long(data.getRouteId())); + if (document.getRouteId() > 0){ + asnData.setSeriesId(new Long(document.getRouteId())); } return asnData; } @@ -1075,8 +1110,8 @@ public class Api2OpenAsnEncoder { asnData.setCarrierNum(UicEncoderUtils.getNum(data.getCarrier())); asnData.setCarrierIA5(UicEncoderUtils.getIA5NonNum(data.getCarrier())); - if (data.getStationCodeTable() != CodeTableType.stationUIC){ - asnData.setStationCodeTable(data.getStationCodeTable()); + if (data.getStationCodeTable() != IStationCodeTable.stationUIC && data.getStationCodeTable() != null){ + asnData.setStationCodeTable(CodeTableType.valueOf(data.getStationCodeTable().name())); } asnData.setEntryStationIA5(UicEncoderUtils.getIA5NonNum(data.getEntryStation())); asnData.setEntryStationNum(UicEncoderUtils.getNum(data.getEntryStation())); @@ -1181,8 +1216,8 @@ public class Api2OpenAsnEncoder { asnData.setBinaryZoneId(data.getBinaryZoneId()); asnData.setCarrierNum(UicEncoderUtils.getNum(data.getCarrier())); asnData.setCarrierIA5(UicEncoderUtils.getIA5NonNum(data.getCarrier())); - if (data.getStationCodeTable() != CodeTableType.stationUIC){ - asnData.setStationCodeTable(data.getStationCodeTable()); + if (data.getStationCodeTable() != IStationCodeTable.stationUIC && data.getStationCodeTable() != null){ + asnData.setStationCodeTable(CodeTableType.valueOf(data.getStationCodeTable().name())); } asnData.setEntryStationIA5(UicEncoderUtils.getIA5NonNum(data.getEntryStation())); asnData.setEntryStationNum(UicEncoderUtils.getNum(data.getEntryStation())); @@ -1292,8 +1327,8 @@ public class Api2OpenAsnEncoder { asnData.setExtension(encodeExtension(document.getExtension())); - if (document.getStationCodeTable() != CodeTableType.stationUIC){ - asnData.setStationCodeTable(document.getStationCodeTable()); + if (document.getStationCodeTable() != IStationCodeTable.stationUIC && document.getStationCodeTable() != null){ + asnData.setStationCodeTable(CodeTableType.valueOf(document.getStationCodeTable().name())); } asnData.setStationIA5(UicEncoderUtils.getIA5NonNum(document.getStation())); @@ -1326,29 +1361,29 @@ public class Api2OpenAsnEncoder { /** * Encode route section. * - * @param route the route + * @param document the route * @return the route section type * @throws EncodingFormatException the encoding format exception */ - private RouteSectionType encodeRouteSection(IRouteSection route) throws EncodingFormatException { + private RouteSectionType encodeRouteSection(IRouteSection document) throws EncodingFormatException { - if (route == null) return null; + if (document == null) return null; RouteSectionType asnRoute = new RouteSectionType(); - if (route.getStationCodeTable() != CodeTableType.stationUIC){ - asnRoute.setStationCodeTable(route.getStationCodeTable()); + if (document.getStationCodeTable() != IStationCodeTable.stationUIC && document.getStationCodeTable() != null){ + asnRoute.setStationCodeTable(CodeTableType.valueOf(document.getStationCodeTable().name())); } - asnRoute.setFromStationIA5(UicEncoderUtils.getIA5NonNum(route.getFromStation())); - asnRoute.setFromStationNum(UicEncoderUtils.getNum(route.getFromStation())); + asnRoute.setFromStationIA5(UicEncoderUtils.getIA5NonNum(document.getFromStation())); + asnRoute.setFromStationNum(UicEncoderUtils.getNum(document.getFromStation())); - asnRoute.setToStationIA5(UicEncoderUtils.getIA5NonNum(route.getToStation())); - asnRoute.setToStationNum(UicEncoderUtils.getNum(route.getToStation())); + asnRoute.setToStationIA5(UicEncoderUtils.getIA5NonNum(document.getToStation())); + asnRoute.setToStationNum(UicEncoderUtils.getNum(document.getToStation())); - asnRoute.setFromStationNameUTF8(route.getFromStationName()); - asnRoute.setToStationNameUTF8(route.getToStationName()); + asnRoute.setFromStationNameUTF8(document.getFromStationName()); + asnRoute.setToStationNameUTF8(document.getToStationName()); return asnRoute; @@ -1407,8 +1442,9 @@ public class Api2OpenAsnEncoder { try { - PassengerType passengerType = PassengerType.valueOf(tariff.getPassengerType().name()); - asnTariff.setPassengerType(passengerType); + if (tariff.getPassengerType() != null) { + asnTariff.setPassengerType(PassengerType.valueOf(tariff.getPassengerType().name())); + } } catch (Exception e){ //no value found } @@ -1530,7 +1566,7 @@ public class Api2OpenAsnEncoder { } } - asnData.setClassCode(document.getClassCode()); + asnData.setClassCode(convertTravelClass(document.getClassCode())); if (document.getCountries() != null && document.getCountries().size() > 0){ asnData.setCountries(SequenceOfCountries.getSequence(UicEncoderUtils.encodeRestrictedIntegerCollection(document.getCountries(),1,250))); @@ -1652,7 +1688,7 @@ public class Api2OpenAsnEncoder { asnData.setCarrierNum(SequenceOfCarrierNum.getSequence(UicEncoderUtils.getNumList(document.getCarriers()))); asnData.setCarrierIA5(UicEncoderUtils.getIA5NonNumList(document.getCarriers())); - asnData.setClassCode(document.getClassCode()); + asnData.setClassCode(convertTravelClass(document.getClassCode())); if (!document.isIncludesSupplements()){ asnData.setIncludesSupplements(false); @@ -1702,8 +1738,8 @@ public class Api2OpenAsnEncoder { asnData.setProductName(document.getProductName()); - if (document.getStationCodeTable() != CodeTableType.stationUIC){ - asnData.setStationCodeTable(document.getStationCodeTable()); + if (document.getStationCodeTable() != IStationCodeTable.stationUIC && document.getStationCodeTable() != null){ + asnData.setStationCodeTable(CodeTableType.valueOf(document.getStationCodeTable().name())); } @@ -1908,12 +1944,12 @@ public class Api2OpenAsnEncoder { asnTicket.setReferenceNum(UicEncoderUtils.getNum(ticket.getReference())); asnTicket.setReferenceIA5(UicEncoderUtils.getIA5NonNum(ticket.getReference())); - if (ticket.getTicketType() != TicketType.openTicket){ - asnTicket.setTicketType(ticket.getTicketType()); + if (ticket.getTicketType() != ITicketType.openTicket && ticket.getTicketType() != null){ + asnTicket.setTicketType(TicketType.valueOf(ticket.getTicketType().name())); } - if (ticket.getLinkMode() != LinkMode.issuedTogether){ - asnTicket.setLinkMode(ticket.getLinkMode()); + if (ticket.getLinkMode() != ILinkMode.issuedTogether && ticket.getLinkMode() != null){ + asnTicket.setLinkMode(LinkMode.valueOf(ticket.getLinkMode().name())); } asnList.add(asnTicket); @@ -1999,9 +2035,12 @@ public class Api2OpenAsnEncoder { asnData.setIssuedOnTrainNum(UicEncoderUtils.getNum(data.getIssuedOnTrain())); asnData.setIssuedOnTrainIA5(UicEncoderUtils.getIA5NonNum(data.getIssuedOnTrain())); - - asnData.setSecurityProviderNum(UicEncoderUtils.getNum(data.getSecurityProvider())); - + if (data.getSecurityProvider() != null) { + asnData.setSecurityProviderNum(UicEncoderUtils.getNum(data.getSecurityProvider())); + data.setSecurityProvider(data.getIssuer()); + } else { + asnData.setSecurityProviderNum(UicEncoderUtils.getNum(data.getIssuer())); + } if (data.getIssuer()!= null && !data.getIssuer().equals(data.getSecurityProvider()) ){ asnData.setIssuerNum(UicEncoderUtils.getNum(data.getIssuer())); @@ -2042,22 +2081,24 @@ public class Api2OpenAsnEncoder { asnPoint.setLatitude(point.getLatitude()); asnPoint.setLongitude(point.getLongitude()); - if (point.getUnit() != GeoUnitType.milliDegree){ - asnPoint.setGeoUnit(point.getUnit()); + if (point.getUnit() != IGeoUnitType.milliDegree && point.getUnit() != null){ + asnPoint.setGeoUnit(GeoUnitType.valueOf(point.getUnit().name())); } - asnPoint.setAccuracy(point.getAccuracy()); + if (point.getAccuracy() != null) { + asnPoint.setAccuracy(GeoUnitType.valueOf(point.getAccuracy().name())); + } - if (point.getHemisphereLatitude() != HemisphereLatitudeType.east) { - asnPoint.setHemisphereLatitude(point.getHemisphereLatitude()); + if (point.getHemisphereLatitude() != IHemisphereLatitudeType.east && point.getHemisphereLatitude() != null) { + asnPoint.setHemisphereLatitude(HemisphereLatitudeType.valueOf(point.getHemisphereLatitude().name())); } - if (point.getHemisphereLongitude() != HemisphereLongitudeType.north) { - asnPoint.setHemisphereLongitude(point.getHemisphereLongitude()); + if (point.getHemisphereLongitude() != IHemisphereLongitudeType.north && point.getHemisphereLongitude() != null) { + asnPoint.setHemisphereLongitude(HemisphereLongitudeType.valueOf(point.getHemisphereLongitude().name())); } - if (point.getSystem() != GeoCoordinateSystemType.wgs84){ - asnPoint.setCoordinateSystem(point.getSystem()); + if (point.getSystem() != IGeoCoordinateSystemType.wgs84 && point.getSystem() != null){ + asnPoint.setCoordinateSystem(GeoCoordinateSystemType.valueOf(point.getSystem().name())); } return asnPoint; @@ -2066,51 +2107,51 @@ public class Api2OpenAsnEncoder { /** * Encode customer card. * - * @param customerCard the customer card + * @param document the customer card * @param issuingDate the issuing date * @return the document data * @throws EncodingFormatException the encoding format exception */ - private DocumentData encodeCustomerCard(ICustomerCard customerCard,Date issuingDate) throws EncodingFormatException { + private DocumentData encodeCustomerCard(ICustomerCard document,Date issuingDate) throws EncodingFormatException { DocumentData asnDocument = new DocumentData(); TicketDetailData asnTicket = new TicketDetailData(); asnDocument.setTicket(asnTicket); - CustomerCardData asnCustomerCard = new CustomerCardData(); - asnDocument.getTicket().setCustomerCard(asnCustomerCard); + CustomerCardData asnData = new CustomerCardData(); + asnDocument.getTicket().setCustomerCard(asnData); - if (customerCard.getCardId() != null && customerCard.getCardId().length() > 0){ + if (document.getCardId() != null && document.getCardId().length() > 0){ //only longs allowed try { - long num = Long.parseLong(customerCard.getCardId()); - asnCustomerCard.setCardIdNum(num); + long num = Long.parseLong(document.getCardId()); + asnData.setCardIdNum(num); } catch (Exception e ){ - asnCustomerCard.setCardIdIA5(customerCard.getCardId()); + asnData.setCardIdIA5(document.getCardId()); } } - asnCustomerCard.setCardType(UicEncoderUtils.getRestrictedInt(customerCard.getCardType(),1,1000)); + asnData.setCardType(UicEncoderUtils.getRestrictedInt(document.getCardType(),1,1000)); - asnCustomerCard.setCardTypeDescr(customerCard.getCardTypeDescr()); + asnData.setCardTypeDescr(document.getCardTypeDescr()); - asnCustomerCard.setClassCode(customerCard.getClassCode()); + asnData.setClassCode(convertTravelClass(document.getClassCode())); - if (customerCard.getCustomer()!=null){ - asnCustomerCard.setCustomer(encodeTraveler(customerCard.getCustomer())); + if (document.getCustomer()!=null){ + asnData.setCustomer(encodeTraveler(document.getCustomer())); } - asnCustomerCard.setCustomerStatus(UicEncoderUtils.getUnRestrictedInt(customerCard.getCustomerStatus())); + asnData.setCustomerStatus(UicEncoderUtils.getUnRestrictedInt(document.getCustomerStatus())); - asnCustomerCard.setCustomerStatusDescr(customerCard.getCustomerStatusDescr()); + asnData.setCustomerStatusDescr(document.getCustomerStatusDescr()); - asnCustomerCard.setExtension(encodeExtension(customerCard.getExtension())); + asnData.setExtension(encodeExtension(document.getExtension())); - asnCustomerCard.setIncludedServices(SequenceOfUnrestrictedLong.getSequence(UicEncoderUtils.getUnRestrictedIntList(customerCard.getIncludedServices()))); + asnData.setIncludedServices(SequenceOfUnrestrictedLong.getSequence(UicEncoderUtils.getUnRestrictedIntList(document.getIncludedServices()))); - asnCustomerCard.setValidity(customerCard.getValidFrom(), customerCard.getValidUntil()); + asnData.setValidity(document.getValidFrom(), document.getValidUntil()); return asnDocument; } @@ -2168,18 +2209,16 @@ public class Api2OpenAsnEncoder { asnTraveler.setFirstName(traveler.getFirstName()); asnTraveler.setSecondName(traveler.getSecondName()); asnTraveler.setLastName(traveler.getLastName()); - asnTraveler.setGender(GenderType.valueOf(traveler.getGender().toString())); + if (traveler.getGender() != null) { + asnTraveler.setGender(GenderType.valueOf(traveler.getGender().name())); + } asnTraveler.setIdCard(UicEncoderUtils.getIA5(traveler.getIdCard())); asnTraveler.setPassportId(UicEncoderUtils.getIA5(traveler.getPassportId())); asnTraveler.setTitle(UicEncoderUtils.getIA5(traveler.getTitle())); - try { - PassengerType passengerType = PassengerType.valueOf(traveler.getPassengerType().name()); - asnTraveler.setPassengerType(passengerType); - } catch (Exception e){ - //no value found + if (traveler.getPassengerType() != null) { + asnTraveler.setPassengerType(PassengerType.valueOf(traveler.getPassengerType().name())); } - asnTraveler.setPassengerWithReducedMobility(traveler.isPassengerWithReducedMobility()); if (traveler.isTicketHolder()){ @@ -2252,5 +2291,23 @@ public class Api2OpenAsnEncoder { return asnExtension; } + private TravelClassType convertTravelClass(ITravelClassType apiClass){ + + if (apiClass == null) return null; + + if (apiClass == ITravelClassType.premiumFirst || apiClass == ITravelClassType.standardFirst){ + return TravelClassType.first; + } + + if (apiClass == ITravelClassType.premiumSecond || apiClass == ITravelClassType.standardSecond){ + return TravelClassType.second; + } + + + return TravelClassType.valueOf(apiClass.name()); + + + } + } diff --git a/src/org/uic/ticket/api/utils/OpenAsn2ApiDecoder.java b/src/org/uic/ticket/api/utils/OpenAsn2ApiDecoder.java index 4a5848d..61dfe6b 100644 --- a/src/org/uic/ticket/api/utils/OpenAsn2ApiDecoder.java +++ b/src/org/uic/ticket/api/utils/OpenAsn2ApiDecoder.java @@ -7,8 +7,6 @@ import java.io.IOException; import java.util.Date; import java.util.List; -import net.gcdc.asn1.datatypes.Asn1BigInteger; - import org.uic.ticket.api.asn.omv1.BerthDetailData; import org.uic.ticket.api.asn.omv1.CarCarriageReservationData; import org.uic.ticket.api.asn.omv1.CardReferenceType; @@ -44,7 +42,6 @@ import org.uic.ticket.api.asn.omv1.TicketLinkType; import org.uic.ticket.api.asn.omv1.TimeRangeType; import org.uic.ticket.api.asn.omv1.TokenType; import org.uic.ticket.api.asn.omv1.TrainLinkType; -import org.uic.ticket.api.asn.omv1.TravelClassType; import org.uic.ticket.api.asn.omv1.TravelerData; import org.uic.ticket.api.asn.omv1.TravelerType; import org.uic.ticket.api.asn.omv1.UicRailTicketData; @@ -56,9 +53,12 @@ import org.uic.ticket.api.asn.omv1.VoucherData; import org.uic.ticket.api.asn.omv1.ZoneType; import org.uic.ticket.api.impl.SimpleUicTicketObjectFactory; import org.uic.ticket.api.spec.IBerth; +import org.uic.ticket.api.spec.IBerthTypeType; import org.uic.ticket.api.spec.ICarCarriageReservation; import org.uic.ticket.api.spec.ICardReference; import org.uic.ticket.api.spec.ICompartmentDetails; +import org.uic.ticket.api.spec.ICompartmentGenderType; +import org.uic.ticket.api.spec.ICompartmentPositionType; import org.uic.ticket.api.spec.IControlDetail; import org.uic.ticket.api.spec.ICounterMark; import org.uic.ticket.api.spec.ICustomerCard; @@ -67,29 +67,42 @@ import org.uic.ticket.api.spec.IDelayConfirmation; import org.uic.ticket.api.spec.IDocumentExtension; import org.uic.ticket.api.spec.IExtension; import org.uic.ticket.api.spec.IFipTicket; +import org.uic.ticket.api.spec.IGenderType; import org.uic.ticket.api.spec.IGeoCoordinate; +import org.uic.ticket.api.spec.IGeoCoordinateSystemType; +import org.uic.ticket.api.spec.IGeoUnitType; +import org.uic.ticket.api.spec.IHemisphereLatitudeType; +import org.uic.ticket.api.spec.IHemisphereLongitudeType; import org.uic.ticket.api.spec.IIncludedOpenTicket; import org.uic.ticket.api.spec.IIssuingDetail; import org.uic.ticket.api.spec.ILine; +import org.uic.ticket.api.spec.ILinkMode; +import org.uic.ticket.api.spec.ILoadingDeckType; import org.uic.ticket.api.spec.ILuggageRestriction; import org.uic.ticket.api.spec.IOpenTicket; import org.uic.ticket.api.spec.IParkingGround; import org.uic.ticket.api.spec.IPass; +import org.uic.ticket.api.spec.IPassengerType; import org.uic.ticket.api.spec.IPlaces; import org.uic.ticket.api.spec.IPolygone; +import org.uic.ticket.api.spec.IPriceTypeType; import org.uic.ticket.api.spec.IRegionalValidity; import org.uic.ticket.api.spec.IRegisteredLuggage; import org.uic.ticket.api.spec.IReservation; import org.uic.ticket.api.spec.IReturnRouteDescription; +import org.uic.ticket.api.spec.IRoofRackType; import org.uic.ticket.api.spec.IRouteSection; import org.uic.ticket.api.spec.ISeriesDataDetails; import org.uic.ticket.api.spec.IServiceBrand; +import org.uic.ticket.api.spec.IStationCodeTable; import org.uic.ticket.api.spec.IStationPassage; import org.uic.ticket.api.spec.ITariff; import org.uic.ticket.api.spec.ITicketLink; +import org.uic.ticket.api.spec.ITicketType; import org.uic.ticket.api.spec.ITimeRange; import org.uic.ticket.api.spec.IToken; import org.uic.ticket.api.spec.ITrainLink; +import org.uic.ticket.api.spec.ITravelClassType; import org.uic.ticket.api.spec.ITraveler; import org.uic.ticket.api.spec.ITravelerDetail; import org.uic.ticket.api.spec.IUicRailTicket; @@ -126,7 +139,24 @@ public class OpenAsn2ApiDecoder { } - + /** + * Decode from asn.1 unaligned PER encoded data. + * + * @param data byte array of the asn.1 encoded FCB data + * @return the decoded uic rail ticket + * @throws IOException Signals that an I/O exception has occurred. + */ + public IUicRailTicket decodeFromAsn (byte[] data) throws IOException{ + + UicRailTicketData asnUicRailTicketData = UicRailTicketData.decode(data); + + IUicRailTicket uicRailTicket = factory.createUicRailTicket(); + + populateFromAsn1Model(uicRailTicket, asnUicRailTicketData); + + return uicRailTicket; + + } @@ -328,7 +358,7 @@ public class OpenAsn2ApiDecoder { document.setInfoText(asnDocument.getInfoText()); if (asnDocument.getStationCodeTable()!=null){ - document.setStationCodeTable(asnDocument.getStationCodeTable()); + document.setStationCodeTable(IStationCodeTable.valueOf(asnDocument.getStationCodeTable().name())); } document.setStation(UicEncoderUtils.mapToString(asnDocument.getStationNum(),asnDocument.getStationIA5())); @@ -384,7 +414,7 @@ public class OpenAsn2ApiDecoder { document.setInfoText(asnDocument.getInfoText()); if (asnDocument.getStationCodeTable()!=null){ - document.setStationCodeTable(asnDocument.getStationCodeTable()); + document.setStationCodeTable(IStationCodeTable.valueOf(asnDocument.getStationCodeTable().name())); } document.setFromStation(UicEncoderUtils.mapToString(asnDocument.getFromStationNum(),asnDocument.getFromStationIA5())); document.setToStation(UicEncoderUtils.mapToString(asnDocument.getToStationNum(),asnDocument.getToStationIA5())); @@ -402,7 +432,7 @@ public class OpenAsn2ApiDecoder { } if(asnDocument.getClassCode()!=null){ - document.setClassCode(asnDocument.getClassCode()); + document.setClassCode(ITravelClassType.valueOf(asnDocument.getClassCode().name())); } document.setCompartmentDetails(convertCompartmentDetails(asnDocument.getCompartmentDetails())); @@ -425,7 +455,7 @@ public class OpenAsn2ApiDecoder { document.setBicyclePlaces(convertPlaces(asnDocument.getBicyclePlaces())); } - document.setPriceType(asnDocument.getPriceType()); + document.setPriceType(IPriceTypeType.valueOf(asnDocument.getPriceType().name())); IServiceBrand serviceBrand = factory.createServiceBrand(); @@ -508,7 +538,7 @@ public class OpenAsn2ApiDecoder { document.setInfoText(asnDocument.getInfoText()); if (asnDocument.getStationCodeTable()!=null){ - document.setStationCodeTable(asnDocument.getStationCodeTable()); + document.setStationCodeTable(IStationCodeTable.valueOf(asnDocument.getStationCodeTable().name())); } document.setFromStation(UicEncoderUtils.mapToString(asnDocument.getFromStationNum(),asnDocument.getFromStationIA5())); document.setToStation(UicEncoderUtils.mapToString(asnDocument.getToStationNum(),asnDocument.getToStationIA5())); @@ -542,7 +572,7 @@ public class OpenAsn2ApiDecoder { } if (asnDocument.getLoadingDeck()!=null){ - document.setLoadingDeck(asnDocument.getLoadingDeck()); + document.setLoadingDeck(ILoadingDeckType.valueOf(asnDocument.getLoadingDeck().name())); } if(asnDocument.getLoadingListEntry()!=null){ @@ -557,7 +587,7 @@ public class OpenAsn2ApiDecoder { document.setTrailerPlate(asnDocument.getTrailerPlate()); if(asnDocument.getRoofRackType()!=null){ - document.setRoofRackType(asnDocument.getRoofRackType()); + document.setRoofRackType(IRoofRackType.valueOf(asnDocument.getRoofRackType().name())); } if(asnDocument.getTextileRoof()) { @@ -586,7 +616,7 @@ public class OpenAsn2ApiDecoder { } - document.setPriceType(asnDocument.getPriceType()); + document.setPriceType(IPriceTypeType.valueOf(asnDocument.getPriceType().name())); IServiceBrand serviceBrand = factory.createServiceBrand(); @@ -666,7 +696,7 @@ public class OpenAsn2ApiDecoder { details.setCompartmentTypeDescr(asnDetails.getCompartmentTypeDescr()); details.setSpecialAllocationDescr(asnDetails.getSpecialAllocationDescr()); - details.setPosition(asnDetails.getPosition()); + details.setPosition(ICompartmentPositionType.valueOf(asnDetails.getPosition().name())); return details; } @@ -715,13 +745,13 @@ public class OpenAsn2ApiDecoder { IBerth berth = factory.createBerth(); if (asnBerth.getGender()!= null) { - berth.setGender(asnBerth.getGender()); + berth.setGender(ICompartmentGenderType.valueOf(asnBerth.getGender().name())); } if (asnBerth.getNumberOfBerths()!=null) { berth.setNumberOfBerths(asnBerth.getNumberOfBerths().intValue()); } if (asnBerth.getBerthType()!=null){ - berth.setType(asnBerth.getBerthType()); + berth.setType(IBerthTypeType.valueOf(asnBerth.getBerthType().name())); } return berth; @@ -742,7 +772,7 @@ public class OpenAsn2ApiDecoder { document.setProductOwner(UicEncoderUtils.mapToString(asnDocument.getProductOwnerNum(),asnDocument.getProductOwnerIA5())); if(asnDocument.getClassCode()!=null){ - document.setClassCode(asnDocument.getClassCode()); + document.setClassCode(ITravelClassType.valueOf(asnDocument.getClassCode().name())); } document.setValidFrom(asnDocument.getValidFromDate(issuingDate)); @@ -894,7 +924,7 @@ public class OpenAsn2ApiDecoder { IOpenTicket document = factory.createOpenTicket(); if(asnDocument.getClassCode()!=null){ - document.setClassCode(asnDocument.getClassCode()); + document.setClassCode(ITravelClassType.valueOf(asnDocument.getClassCode().name())); } document.setValidFrom(asnDocument.getValidFromDate(issuingDate)); @@ -945,7 +975,7 @@ public class OpenAsn2ApiDecoder { } if (asnDocument.getStationCodeTable()!=null){ - document.setStationCodeTable(asnDocument.getStationCodeTable()); + document.setStationCodeTable(IStationCodeTable.valueOf(asnDocument.getStationCodeTable().name())); } document.setFromStation(UicEncoderUtils.mapToString(asnDocument.getFromStationNum(),asnDocument.getFromStationIA5())); document.setToStation(UicEncoderUtils.mapToString(asnDocument.getToStationNum(),asnDocument.getToStationIA5())); @@ -1013,12 +1043,12 @@ public class OpenAsn2ApiDecoder { * @param classCode the class code * @return the simple included open ticket */ - private IIncludedOpenTicket convertIncludedOpenTicket( IncludedOpenTicketType asnDocument, Date issuingDate, TravelClassType classCode) { + private IIncludedOpenTicket convertIncludedOpenTicket( IncludedOpenTicketType asnDocument, Date issuingDate,ITravelClassType classCode) { IIncludedOpenTicket document = factory.createIncludedOpenTicket(); if(asnDocument.getClassCode()!=null){ - document.setClassCode(asnDocument.getClassCode()); + document.setClassCode(ITravelClassType.valueOf(asnDocument.getClassCode().name())); } else { document.setClassCode(classCode); } @@ -1068,7 +1098,7 @@ public class OpenAsn2ApiDecoder { } if (asnDocument.getStationCodeTable()!=null){ - document.setStationCodeTable(asnDocument.getStationCodeTable()); + document.setStationCodeTable(IStationCodeTable.valueOf(asnDocument.getStationCodeTable().name())); } if (asnDocument.getValidRegion()!= null && !asnDocument.getValidRegion().isEmpty()) { @@ -1120,9 +1150,9 @@ public class OpenAsn2ApiDecoder { } if (asnDocument.getStationNum()!=null && !asnDocument.getStationNum().isEmpty()){ - for (Asn1BigInteger station : asnDocument.getStationNum()) { - if (station.value() != null) { - document.addStation(station.value().toString()); + for (Long station : asnDocument.getStationNum()) { + if (station != null) { + document.addStation(station.toString()); } } } @@ -1145,7 +1175,7 @@ public class OpenAsn2ApiDecoder { } if (asnDocument.getStationCodeTable()!=null){ - document.setStationCodeTable(asnDocument.getStationCodeTable()); + document.setStationCodeTable(IStationCodeTable.valueOf(asnDocument.getStationCodeTable().name())); } document.setExtension(convertExtension(asnDocument.getExtension())); @@ -1156,9 +1186,9 @@ public class OpenAsn2ApiDecoder { } } if (asnDocument.getAreaCodeNum() != null && !asnDocument.getAreaCodeNum().isEmpty()) { - for (Asn1BigInteger code : asnDocument.getAreaCodeNum()) { - if (code.value() != null) { - document.addAreaCode(code.value().toString()); + for (Long code : asnDocument.getAreaCodeNum()) { + if (code != null) { + document.addAreaCode(code.toString()); } } } @@ -1239,7 +1269,7 @@ public class OpenAsn2ApiDecoder { document.setSpecialInformation(asnDocument.getSpecialInformation()); if (asnDocument.getStationCodeTable()!=null){ - document.setStationCodeTable(asnDocument.getStationCodeTable()); + document.setStationCodeTable(IStationCodeTable.valueOf(asnDocument.getStationCodeTable().name())); } document.setStation(UicEncoderUtils.mapToString(asnDocument.getStationNum(),asnDocument.getStationIA5())); @@ -1258,51 +1288,51 @@ public class OpenAsn2ApiDecoder { /** * Convert via station. * - * @param asnVia the asn via + * @param asnDocument the asn via * @return the i via station */ - protected IViaStation convertViaStation(ViaStationType asnVia) { + protected IViaStation convertViaStation(ViaStationType asnDocument) { - if (asnVia == null) return null; + if (asnDocument == null) return null; IViaStation via = factory.createViaStation(); - if (asnVia.getBorder()!=null) { - via.setBorder(asnVia.getBorder()); + if (asnDocument.getBorder()!=null) { + via.setBorder(asnDocument.getBorder()); } - if (asnVia.getRouteId() != null) { - via.setRouteId(asnVia.getRouteId().intValue()); + if (asnDocument.getRouteId() != null) { + via.setRouteId(asnDocument.getRouteId().intValue()); } - if (asnVia.getStationCodeTable()!=null){ - via.setStationCodeTable(asnVia.getStationCodeTable()); + if (asnDocument.getStationCodeTable()!=null){ + via.setStationCodeTable(IStationCodeTable.valueOf(asnDocument.getStationCodeTable().name())); } - if (asnVia.getStationNum() != null) { - via.setStation(asnVia.getStationNum().toString()); - } else if (asnVia.getStationIA5() != null) { - via.setStation(asnVia.getStationIA5()); + if (asnDocument.getStationNum() != null) { + via.setStation(asnDocument.getStationNum().toString()); + } else if (asnDocument.getStationIA5() != null) { + via.setStation(asnDocument.getStationIA5()); } - if (asnVia.getCarriersNum()!=null && !asnVia.getCarriersNum().isEmpty()){ - for(Long carrier :asnVia.getCarriersNum()){ + if (asnDocument.getCarriersNum()!=null && !asnDocument.getCarriersNum().isEmpty()){ + for(Long carrier :asnDocument.getCarriersNum()){ via.addCarrier(carrier.toString()); } } - if (asnVia.getCarriersIA5()!=null && !asnVia.getCarriersIA5().isEmpty()){ - for(String carrier :asnVia.getCarriersIA5()){ + if (asnDocument.getCarriersIA5()!=null && !asnDocument.getCarriersIA5().isEmpty()){ + for(String carrier :asnDocument.getCarriersIA5()){ via.addCarrier(carrier); } } - if (asnVia.getRoute()!= null && !asnVia.getRoute().isEmpty()) { - for ( ViaStationType routeVia: asnVia.getRoute()) { + if (asnDocument.getRoute()!= null && !asnDocument.getRoute().isEmpty()) { + for ( ViaStationType routeVia: asnDocument.getRoute()) { via.addRouteStation(convertViaStation(routeVia)); } } - if (asnVia.getAlternativeRoutes()!= null && !asnVia.getAlternativeRoutes().isEmpty()) { - for ( ViaStationType routeVia: asnVia.getAlternativeRoutes()) { + if (asnDocument.getAlternativeRoutes()!= null && !asnDocument.getAlternativeRoutes().isEmpty()) { + for ( ViaStationType routeVia: asnDocument.getAlternativeRoutes()) { via.addRouteStation(convertViaStation(routeVia)); } } @@ -1337,28 +1367,28 @@ public class OpenAsn2ApiDecoder { /** * Convert zone. * - * @param asnZone the asn zone + * @param asnDocument the asn zone * @return the i regional validity */ - protected IRegionalValidity convertZone(ZoneType asnZone) { + protected IRegionalValidity convertZone(ZoneType asnDocument) { - if (asnZone == null) return null; + if (asnDocument == null) return null; IZone zone = factory.createZone(); - zone.setBinaryZoneId(asnZone.getBinaryZoneId()); - zone.setCarrier(UicEncoderUtils.mapToString(asnZone.getCarrierNum(),asnZone.getCarrierIA5())); + zone.setBinaryZoneId(asnDocument.getBinaryZoneId()); + zone.setCarrier(UicEncoderUtils.mapToString(asnDocument.getCarrierNum(),asnDocument.getCarrierIA5())); - if (asnZone.getCity() != null) { - zone.setCity(asnZone.getCity().intValue()); + if (asnDocument.getCity() != null) { + zone.setCity(asnDocument.getCity().intValue()); } - if (asnZone.getStationCodeTable()!=null){ - zone.setStationCodeTable(asnZone.getStationCodeTable()); + if (asnDocument.getStationCodeTable()!=null){ + zone.setStationCodeTable(IStationCodeTable.valueOf(asnDocument.getStationCodeTable().name())); } - zone.setEntryStation(UicEncoderUtils.mapToString(asnZone.getEntryStationNum(),asnZone.getEntryStationIA5())); - zone.setTerminatingStation(UicEncoderUtils.mapToString(asnZone.getTerminatingStationNum(),asnZone.getTerminatingStationIA5())); + zone.setEntryStation(UicEncoderUtils.mapToString(asnDocument.getEntryStationNum(),asnDocument.getEntryStationIA5())); + zone.setTerminatingStation(UicEncoderUtils.mapToString(asnDocument.getTerminatingStationNum(),asnDocument.getTerminatingStationIA5())); - zone.setNUTScode(asnZone.getNutsCode()); + zone.setNUTScode(asnDocument.getNutsCode()); return zone; } @@ -1398,27 +1428,27 @@ public class OpenAsn2ApiDecoder { /** * Convert line. * - * @param asnLine the asn line + * @param asnDocument the asn line * @return the i regional validity */ - protected IRegionalValidity convertLine(LineType asnLine) { + protected IRegionalValidity convertLine(LineType asnDocument) { - if (asnLine == null) return null; + if (asnDocument == null) return null; ILine line = factory.createLine(); - line.setBinaryZoneId(asnLine.getBinaryZoneId()); - line.setCarrier(UicEncoderUtils.mapToString(asnLine.getCarrierNum(),asnLine.getCarrierIA5())); - if (asnLine.getCity()!=null) { - line.setCity(asnLine.getCity().intValue()); + line.setBinaryZoneId(asnDocument.getBinaryZoneId()); + line.setCarrier(UicEncoderUtils.mapToString(asnDocument.getCarrierNum(),asnDocument.getCarrierIA5())); + if (asnDocument.getCity()!=null) { + line.setCity(asnDocument.getCity().intValue()); } - if (asnLine.getStationCodeTable()!=null){ - line.setStationCodeTable(asnLine.getStationCodeTable()); + if (asnDocument.getStationCodeTable()!=null){ + line.setStationCodeTable(IStationCodeTable.valueOf(asnDocument.getStationCodeTable().name())); } - line.setEntryStation(UicEncoderUtils.mapToString(asnLine.getEntryStationNum(),asnLine.getEntryStationIA5())); - line.setTerminatingStation(UicEncoderUtils.mapToString(asnLine.getTerminatingStationNum(),asnLine.getTerminatingStationIA5())); - if (asnLine.getLineId()!=null && !asnLine.getLineId().isEmpty()){ - for (Asn1BigInteger lineId : asnLine.getLineId()) { + line.setEntryStation(UicEncoderUtils.mapToString(asnDocument.getEntryStationNum(),asnDocument.getEntryStationIA5())); + line.setTerminatingStation(UicEncoderUtils.mapToString(asnDocument.getTerminatingStationNum(),asnDocument.getTerminatingStationIA5())); + if (asnDocument.getLineId()!=null && !asnDocument.getLineId().isEmpty()){ + for (Long lineId : asnDocument.getLineId()) { line.addLineId(lineId.intValue()); } } @@ -1455,7 +1485,7 @@ public class OpenAsn2ApiDecoder { if (asnTariff.getPassengerType()!=null) { - tariff.setPassengerType(asnTariff.getPassengerType()); + tariff.setPassengerType(IPassengerType.valueOf(asnTariff.getPassengerType().name())); } @@ -1524,7 +1554,7 @@ public class OpenAsn2ApiDecoder { IRouteSection document = factory.createRouteSection(); if (asnDocument.getStationCodeTable()!=null){ - document.setStationCodeTable(asnDocument.getStationCodeTable()); + document.setStationCodeTable(IStationCodeTable.valueOf(asnDocument.getStationCodeTable().name())); } document.setFromStation(UicEncoderUtils.mapToString(asnDocument.getFromStationNum(),asnDocument.getFromStationIA5())); document.setToStation(UicEncoderUtils.mapToString(asnDocument.getToStationNum(),asnDocument.getToStationIA5())); @@ -1546,7 +1576,7 @@ public class OpenAsn2ApiDecoder { IFipTicket document = factory.createFipTicket(); if(asnDocument.getClassCode()!=null){ - document.setClassCode(asnDocument.getClassCode()); + document.setClassCode(ITravelClassType.valueOf(asnDocument.getClassCode().name())); } document.setValidFrom(asnDocument.getValidFromDate(issuingDate)); @@ -1588,7 +1618,7 @@ public class OpenAsn2ApiDecoder { IPass document = factory.createPass(); if(asnDocument.getClassCode()!=null){ - document.setClassCode(asnDocument.getClassCode()); + document.setClassCode(ITravelClassType.valueOf(asnDocument.getClassCode().name())); } document.setValidFrom(asnDocument.getValidFromDate(issuingDate)); @@ -1785,40 +1815,40 @@ public class OpenAsn2ApiDecoder { /** * Convert customer card. * - * @param asnCard the asn card + * @param asnDocument the asn card * @param issuingDate the issuing date * @return the i customer card */ - protected ICustomerCard convertCustomerCard(CustomerCardData asnCard, Date issuingDate ) { + protected ICustomerCard convertCustomerCard(CustomerCardData asnDocument, Date issuingDate ) { - if (asnCard == null) return null; + if (asnDocument == null) return null; ICustomerCard card = factory.createCustomerCard(); - card.setCardId(UicEncoderUtils.mapToString(asnCard.getCardIdNum(), asnCard.getCardIdIA5())); - if (asnCard.getCardType()!= null) { - card.setCardType(asnCard.getCardType().intValue()); + card.setCardId(UicEncoderUtils.mapToString(asnDocument.getCardIdNum(), asnDocument.getCardIdIA5())); + if (asnDocument.getCardType()!= null) { + card.setCardType(asnDocument.getCardType().intValue()); } - card.setCardTypeDescr(asnCard.getCardTypeDescr()); - if(asnCard.getClassCode()!=null){ - card.setClassCode(asnCard.getClassCode()); + card.setCardTypeDescr(asnDocument.getCardTypeDescr()); + if(asnDocument.getClassCode()!=null){ + card.setClassCode(ITravelClassType.valueOf(asnDocument.getClassCode().name())); } - if(asnCard.getCustomer()!=null) { - card.setCustomer(convertTraveler(asnCard.getCustomer())); + if(asnDocument.getCustomer()!=null) { + card.setCustomer(convertTraveler(asnDocument.getCustomer())); } - if (asnCard.getCustomerStatus()!=null) { - card.setCustomerStatus(asnCard.getCustomerStatus().intValue()); + if (asnDocument.getCustomerStatus()!=null) { + card.setCustomerStatus(asnDocument.getCustomerStatus().intValue()); } - card.setCustomerStatusDescr(asnCard.getCustomerStatusDescr()); + card.setCustomerStatusDescr(asnDocument.getCustomerStatusDescr()); - card.setValidFrom(asnCard.getValidFromDate()); + card.setValidFrom(asnDocument.getValidFromDate()); - card.setValidUntil(asnCard.getValidUntilDate()); + card.setValidUntil(asnDocument.getValidUntilDate()); - if (asnCard.getIncludedServices() != null && !asnCard.getIncludedServices().isEmpty()){ - for (Asn1BigInteger service: asnCard.getIncludedServices()){ + if (asnDocument.getIncludedServices() != null && !asnDocument.getIncludedServices().isEmpty()){ + for (Long service: asnDocument.getIncludedServices()){ card.addIncludedService(new Integer(service.intValue())); } } @@ -1894,13 +1924,13 @@ public class OpenAsn2ApiDecoder { traveler.setFirstName(asnTraveler.getFirstName()); if (asnTraveler.getGender()!= null) { - traveler.setGender(asnTraveler.getGender()); + traveler.setGender(IGenderType.valueOf(asnTraveler.getGender().name())); } traveler.setIdCard(asnTraveler.getIdCard()); traveler.setLastName(asnTraveler.getLastName()); if (asnTraveler.getPassengerType()!= null) { - traveler.setPassengerType(asnTraveler.getPassengerType()); + traveler.setPassengerType(IPassengerType.valueOf(asnTraveler.getPassengerType().name())); } if (asnTraveler.getPassengerWithReducedMobility()!= null) { traveler.setPassengerWithReducedMobility(asnTraveler.getPassengerWithReducedMobility()); @@ -2093,24 +2123,24 @@ public class OpenAsn2ApiDecoder { IGeoCoordinate coordinate = factory.createGeoCoordinate(); if (asnCoordinate.getCoordinateSystem() != null) { - coordinate.setSystem(asnCoordinate.getCoordinateSystem()); + coordinate.setSystem(IGeoCoordinateSystemType.valueOf(asnCoordinate.getCoordinateSystem().name())); } if (asnCoordinate.getAccuracy() != null) { - coordinate.setAccuracy(asnCoordinate.getAccuracy()); + coordinate.setAccuracy(IGeoUnitType.valueOf(asnCoordinate.getAccuracy().name())); } if (asnCoordinate.getGeoUnit() != null) { - coordinate.setUnit(asnCoordinate.getGeoUnit()); + coordinate.setUnit(IGeoUnitType.valueOf(asnCoordinate.getGeoUnit().name())); } if (asnCoordinate.getHemisphereLatitude() != null) { - coordinate.setHemisphereLatitude(asnCoordinate.getHemisphereLatitude()); + coordinate.setHemisphereLatitude(IHemisphereLatitudeType.valueOf(asnCoordinate.getHemisphereLatitude().name())); } if (asnCoordinate.getHemisphereLongitude() != null) { - coordinate.setHemisphereLongitude(asnCoordinate.getHemisphereLongitude()); - } + coordinate.setHemisphereLongitude(IHemisphereLongitudeType.valueOf(asnCoordinate.getHemisphereLongitude().name())); + } coordinate.setLongitude (asnCoordinate.getLongitude()); coordinate.setLatitude (asnCoordinate.getLatitude()); @@ -2151,10 +2181,10 @@ public class OpenAsn2ApiDecoder { ticketLink.setProductOwner(UicEncoderUtils.mapToString(asnTicketLink.getProductOwnerNum(),asnTicketLink.getProductOwnerIA5())); ticketLink.setReference(UicEncoderUtils.mapToString(asnTicketLink.getReferenceNum(),asnTicketLink.getReferenceIA5())); if(asnTicketLink.getTicketType()!=null) { - ticketLink.setTicketType(asnTicketLink.getTicketType()); + ticketLink.setTicketType(ITicketType.valueOf(asnTicketLink.getTicketType().name())); } if(asnTicketLink.getLinkMode()!=null) { - ticketLink.setLinkMode(asnTicketLink.getLinkMode()); + ticketLink.setLinkMode(ILinkMode.valueOf(asnTicketLink.getLinkMode().name())); } return ticketLink; } diff --git a/src/org/uic/ticket/api/utils/UicEncoderUtils.java b/src/org/uic/ticket/api/utils/UicEncoderUtils.java index 0f3a5b4..f4c9f89 100644 --- a/src/org/uic/ticket/api/utils/UicEncoderUtils.java +++ b/src/org/uic/ticket/api/utils/UicEncoderUtils.java @@ -9,14 +9,12 @@ import java.util.Collection; import java.util.HashSet; import java.util.List; - +import org.uic.ticket.EncodingFormatException; import net.gcdc.asn1.datatypes.Asn1BigInteger; import net.gcdc.asn1.datatypesimpl.SequenceOfStringIA5; import net.gcdc.asn1.datatypesimpl.SequenceOfStringUTF8; -import org.uic.ticket.api.EncodingFormatException; - /** * The Class UicEncoderUtils. -- cgit v1.2.3