From 922076d807974cefa6ade28f689a20f1a90fddeb Mon Sep 17 00:00:00 2001 From: CGantert345 <57003061+CGantert345@users.noreply.github.com> Date: Tue, 5 Apr 2022 11:19:47 +0200 Subject: provide more control on the logging to users --- .../uic/barcode/asn1/datatypes/Asn1SequenceOf.java | 8 ++-- .../org/uic/barcode/asn1/uper/StringCoder.java | 8 +--- src/main/java/org/uic/barcode/logger/Logger.java | 20 +++++++- .../java/org/uic/barcode/logger/LoggerFactory.java | 55 +++++++++++++++++++++- 4 files changed, 76 insertions(+), 15 deletions(-) (limited to 'src/main') diff --git a/src/main/java/org/uic/barcode/asn1/datatypes/Asn1SequenceOf.java b/src/main/java/org/uic/barcode/asn1/datatypes/Asn1SequenceOf.java index 4924b50..8e24222 100644 --- a/src/main/java/org/uic/barcode/asn1/datatypes/Asn1SequenceOf.java +++ b/src/main/java/org/uic/barcode/asn1/datatypes/Asn1SequenceOf.java @@ -3,8 +3,7 @@ package org.uic.barcode.asn1.datatypes; import java.lang.reflect.ParameterizedType; import java.util.*; -import org.uic.barcode.logger.Logger; -import org.uic.barcode.logger.LoggerFactory; +import org.uic.barcode.asn1.uper.UperEncoder; /** @@ -35,8 +34,7 @@ import org.uic.barcode.logger.LoggerFactory; * @param type of elements contained. */ public abstract class Asn1SequenceOf extends AbstractList { - private final static Logger logger = LoggerFactory.getLogger("asnLogger"); - + private final List bakingList; @Override public T get(int index) { return bakingList.get(index); } @@ -45,7 +43,7 @@ public abstract class Asn1SequenceOf extends AbstractList { public Asn1SequenceOf() { this(new ArrayList()); } public Asn1SequenceOf(Collection coll) { - logger.debug(String.format("Instantiating Sequence Of %s with %s", + UperEncoder.logger.debug(String.format("Instantiating Sequence Of %s with %s", ((ParameterizedType)getClass().getGenericSuperclass()).getActualTypeArguments()[0], coll)); bakingList = new ArrayList<>(coll); diff --git a/src/main/java/org/uic/barcode/asn1/uper/StringCoder.java b/src/main/java/org/uic/barcode/asn1/uper/StringCoder.java index a504096..94e0aad 100644 --- a/src/main/java/org/uic/barcode/asn1/uper/StringCoder.java +++ b/src/main/java/org/uic/barcode/asn1/uper/StringCoder.java @@ -17,14 +17,10 @@ import org.uic.barcode.asn1.datatypes.DefaultAlphabet; import org.uic.barcode.asn1.datatypes.FixedSize; import org.uic.barcode.asn1.datatypes.RestrictedString; import org.uic.barcode.asn1.datatypes.SizeRange; -import org.uic.barcode.logger.Logger; -import org.uic.barcode.logger.LoggerFactory; class StringCoder implements Decoder, Encoder { - private static final Logger LOGGER = LoggerFactory.getLogger("asnLogger"); - @Override public boolean canEncode(T obj, Annotation[] extraAnnotations) { return obj instanceof String || obj instanceof Asn1String; } @@ -231,7 +227,7 @@ class StringCoder implements Decoder, Encoder { try { chars = UperEncoder.instantiate(restriction.alphabet()).chars().toCharArray(); } catch (IllegalArgumentException e) { - LOGGER.info("Uninstantinatable alphabet ", e); + UperEncoder.logger.info("Uninstantinatable alphabet ", e); throw new IllegalArgumentException("Uninstantinatable alphabet" + restriction.alphabet().getName()); } if (BigInteger.valueOf(chars.length - 1).bitLength() < BigInteger.valueOf(126) @@ -293,7 +289,7 @@ class StringCoder implements Decoder, Encoder { try { chars = UperEncoder.instantiate(restrictionAnnotation.alphabet()).chars().toCharArray(); } catch (IllegalArgumentException e) { - LOGGER.info("Uninstantinatable alphabet ", e); + UperEncoder.logger.info("Uninstantinatable alphabet ", e); throw new IllegalArgumentException("Uninstantinatable alphabet " + restrictionAnnotation.alphabet().getName()); } if (BigInteger.valueOf(chars.length - 1).bitLength() < BigInteger.valueOf(126) diff --git a/src/main/java/org/uic/barcode/logger/Logger.java b/src/main/java/org/uic/barcode/logger/Logger.java index b536154..baae70d 100644 --- a/src/main/java/org/uic/barcode/logger/Logger.java +++ b/src/main/java/org/uic/barcode/logger/Logger.java @@ -3,11 +3,23 @@ package org.uic.barcode.logger; import java.util.logging.Level; -public class Logger { +public class Logger { + + private boolean consoleLog = false; + + public Logger(boolean consoleLog) { + this.consoleLog = consoleLog; + } + + public Logger() { + this.consoleLog = false; + } public void debug(String text){ java.util.logging.Logger.getGlobal().log(Level.FINEST,text); - System.out.println(text); + if (consoleLog) { + System.out.println(text); + } } public void log(Level level,String text){ @@ -17,6 +29,10 @@ public class Logger { public void info(String text, IllegalArgumentException e) { java.util.logging.Logger.getGlobal().log(Level.INFO,text); } + + public void activateConsoleLog(boolean consoleLogActive) { + this.consoleLog = consoleLogActive; + } } diff --git a/src/main/java/org/uic/barcode/logger/LoggerFactory.java b/src/main/java/org/uic/barcode/logger/LoggerFactory.java index 0a1a83c..be5736e 100644 --- a/src/main/java/org/uic/barcode/logger/LoggerFactory.java +++ b/src/main/java/org/uic/barcode/logger/LoggerFactory.java @@ -1,9 +1,60 @@ package org.uic.barcode.logger; +import java.util.HashMap; + +/** + * A factory for creating Logger objects. This allows to replace the default logger by your own loggers. + */ public class LoggerFactory { + + /** The registered loggers. */ + private static HashMap registeredLoggers = new HashMap(); + + /** The activate console log. */ + public static boolean activateConsoleLog = false; + + /** + * Gets the logger. + * + * @param name the name of the logger. UperEncoder uses asnLogger + * @return the logger + */ public static Logger getLogger(String name) { - return new Logger(); - } + Logger logger = registeredLoggers.get(name); + if (logger == null) { + logger = new Logger(activateConsoleLog); + registeredLoggers.put(name, logger); + } + return logger; + } + /** + * Checks if console log is on. + * + * @return true, if console log is on + */ + public static boolean isActivateConsoleLog() { + return activateConsoleLog; + } + + /** + * Sets the console log on + * + * @param activateConsoleLog the new activate console log + */ + public static void setActivateConsoleLog(boolean activateConsoleLog) { + LoggerFactory.activateConsoleLog = activateConsoleLog; + } + + /** + * Register logger. + * + * @param name the name of the logger + * @param logger the logger to be registered + */ + public void registerLogger(String name, Logger logger) { + registeredLoggers.put(name, logger); + } + } -- cgit v1.2.3 From 9c1dec2f31e121b0f23a0270211961f3398445ac Mon Sep 17 00:00:00 2001 From: CGantert345 <57003061+CGantert345@users.noreply.github.com> Date: Mon, 11 Apr 2022 09:26:40 +0200 Subject: nullpointer exception fixed in dynamic content of dosipas --- .../barcode/dynamicContent/api/DynamicContentCoder.java | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'src/main') diff --git a/src/main/java/org/uic/barcode/dynamicContent/api/DynamicContentCoder.java b/src/main/java/org/uic/barcode/dynamicContent/api/DynamicContentCoder.java index 34406e0..00b5824 100644 --- a/src/main/java/org/uic/barcode/dynamicContent/api/DynamicContentCoder.java +++ b/src/main/java/org/uic/barcode/dynamicContent/api/DynamicContentCoder.java @@ -92,8 +92,12 @@ public class DynamicContentCoder { GeoCoordinateType asnPoint = new GeoCoordinateType(); - asnPoint.setLatitude(point.getLatitude()); - asnPoint.setLongitude(point.getLongitude()); + if (point.getLatitude() != null) { + asnPoint.setLatitude(point.getLatitude()); + } + if (point.getLongitude() != null) { + asnPoint.setLongitude(point.getLongitude()); + } if (point.getUnit() != IGeoUnitType.milliDegree && point.getUnit() != null){ asnPoint.setGeoUnit(GeoUnitType.valueOf(point.getUnit().name())); @@ -169,8 +173,12 @@ public class DynamicContentCoder { IGeoCoordinate g = new SimpleGeoCoordinate(); - g.setLatitude(asnCoordinate.getLatitude()); - g.setLongitude(asnCoordinate.getLongitude()); + if (asnCoordinate.getLatitude() != null) { + g.setLatitude(asnCoordinate.getLatitude()); + } + if (asnCoordinate.getLongitude() != null) { + g.setLongitude(asnCoordinate.getLongitude()); + } if (asnCoordinate.getCoordinateSystem() != null) { g.setSystem(IGeoCoordinateSystemType.valueOf(asnCoordinate.getCoordinateSystem().name())); -- cgit v1.2.3 From 0ea854b3232f1dc33bb55f2ef9946f72dc40ed21 Mon Sep 17 00:00:00 2001 From: CGantert345 <57003061+CGantert345@users.noreply.github.com> Date: Mon, 11 Apr 2022 09:30:06 +0200 Subject: nullpointer --- .../java/org/uic/barcode/dynamicContent/api/DynamicContentCoder.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src/main') diff --git a/src/main/java/org/uic/barcode/dynamicContent/api/DynamicContentCoder.java b/src/main/java/org/uic/barcode/dynamicContent/api/DynamicContentCoder.java index 00b5824..a4d38c6 100644 --- a/src/main/java/org/uic/barcode/dynamicContent/api/DynamicContentCoder.java +++ b/src/main/java/org/uic/barcode/dynamicContent/api/DynamicContentCoder.java @@ -162,8 +162,9 @@ public class DynamicContentCoder { content.setGeoCoordinate(getGeoCoordinate(asn.getGeoCoordinate())); - content.setTimeStamp(asn.getTimeStamp().getTimeAsDate()); - + if (asn.getTimeStamp() != null) { + content.setTimeStamp(asn.getTimeStamp().getTimeAsDate()); + } return content; -- cgit v1.2.3 From 6c625e1491ec3260790765f002ce75cf6fdd369c Mon Sep 17 00:00:00 2001 From: CGantert345 <57003061+CGantert345@users.noreply.github.com> Date: Mon, 11 Apr 2022 09:36:04 +0200 Subject: nullpointer --- .../java/org/uic/barcode/dynamicContent/api/DynamicContentCoder.java | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/main') diff --git a/src/main/java/org/uic/barcode/dynamicContent/api/DynamicContentCoder.java b/src/main/java/org/uic/barcode/dynamicContent/api/DynamicContentCoder.java index a4d38c6..ea90879 100644 --- a/src/main/java/org/uic/barcode/dynamicContent/api/DynamicContentCoder.java +++ b/src/main/java/org/uic/barcode/dynamicContent/api/DynamicContentCoder.java @@ -172,6 +172,8 @@ public class DynamicContentCoder { private static IGeoCoordinate getGeoCoordinate(GeoCoordinateType asnCoordinate) { + if (asnCoordinate == null) return null; + IGeoCoordinate g = new SimpleGeoCoordinate(); if (asnCoordinate.getLatitude() != null) { -- cgit v1.2.3 From 44f3079ffeb5cdb6d5338b48f0a6460c24f2503e Mon Sep 17 00:00:00 2001 From: CGantert345 <57003061+CGantert345@users.noreply.github.com> Date: Mon, 11 Apr 2022 09:39:35 +0200 Subject: nullpointer --- .../dynamicContent/api/DynamicContentCoder.java | 28 ++++++++++++---------- 1 file changed, 16 insertions(+), 12 deletions(-) (limited to 'src/main') diff --git a/src/main/java/org/uic/barcode/dynamicContent/api/DynamicContentCoder.java b/src/main/java/org/uic/barcode/dynamicContent/api/DynamicContentCoder.java index ea90879..b49bcb9 100644 --- a/src/main/java/org/uic/barcode/dynamicContent/api/DynamicContentCoder.java +++ b/src/main/java/org/uic/barcode/dynamicContent/api/DynamicContentCoder.java @@ -57,21 +57,25 @@ public class DynamicContentCoder { private static SequenceOfExtension getAsnContentExtensions(UicDynamicContentDataFDC1 asn, List dynamicContentResponseList) throws EncodingFormatException { - if (dynamicContentResponseList != null && !dynamicContentResponseList.isEmpty()){ + if (dynamicContentResponseList == null || dynamicContentResponseList.isEmpty()){ + return null; + } - SequenceOfExtension asnList = asn.getExtensions(); - if (asnList == null) asnList = new SequenceOfExtension(); - for (IExtension extension : dynamicContentResponseList){ - ExtensionData asnExtension = getAsnExtension(extension); - if (asnExtension!= null) { - asnList.add(asnExtension); - } - } - if (!asnList.isEmpty()){ - return asnList; + SequenceOfExtension asnList = asn.getExtensions(); + if (asnList == null) { + asnList = new SequenceOfExtension(); + } + + for (IExtension extension : dynamicContentResponseList){ + ExtensionData asnExtension = getAsnExtension(extension); + if (asnExtension!= null) { + asnList.add(asnExtension); } } - + if (!asnList.isEmpty()){ + return asnList; + } + return null; } -- cgit v1.2.3 From 32a1132a55a6493941ca8441104e1b9d85688147 Mon Sep 17 00:00:00 2001 From: CGantert345 <57003061+CGantert345@users.noreply.github.com> Date: Mon, 11 Apr 2022 10:10:04 +0200 Subject: TimeStamp using java compliant with older android version --- .../uic/barcode/dynamicContent/fdc1/TimeStamp.java | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) (limited to 'src/main') diff --git a/src/main/java/org/uic/barcode/dynamicContent/fdc1/TimeStamp.java b/src/main/java/org/uic/barcode/dynamicContent/fdc1/TimeStamp.java index c2cd8fa..2f54da3 100644 --- a/src/main/java/org/uic/barcode/dynamicContent/fdc1/TimeStamp.java +++ b/src/main/java/org/uic/barcode/dynamicContent/fdc1/TimeStamp.java @@ -1,11 +1,11 @@ package org.uic.barcode.dynamicContent.fdc1; import java.time.Instant; -import java.time.ZoneId; import java.time.ZoneOffset; import java.time.ZonedDateTime; -import java.time.temporal.ChronoField; +import java.util.Calendar; import java.util.Date; +import java.util.TimeZone; import org.uic.barcode.asn1.datatypes.FieldOrder; import org.uic.barcode.asn1.datatypes.IntRange; @@ -41,18 +41,22 @@ public class TimeStamp { * Instantiates a new time stamp and sets the time-stamp to now. */ public TimeStamp() { - ZonedDateTime now = ZonedDateTime.now(ZoneId.of("UTC")); - day = new Long(now.get(ChronoField.DAY_OF_YEAR)); - secondOfDay = new Long(now.get(ChronoField.SECOND_OF_DAY)); + setNow(); } /** * Sets the the time-stamp to now. */ public void setNow() { - ZonedDateTime now = ZonedDateTime.now(ZoneId.of("UTC")); - day = new Long(now.get(ChronoField.DAY_OF_YEAR)); - secondOfDay = new Long(now.get(ChronoField.SECOND_OF_DAY)); + Calendar c = Calendar.getInstance(TimeZone.getTimeZone("UTC")); + day = (long) c.get(Calendar.DAY_OF_YEAR); + long now = c.getTimeInMillis(); + c.set(Calendar.HOUR_OF_DAY, 0); + c.set(Calendar.MINUTE, 0); + c.set(Calendar.SECOND, 0); + c.set(Calendar.MILLISECOND, 0); + long passed = now - c.getTimeInMillis(); + secondOfDay = passed / 1000; } /** -- cgit v1.2.3 From e670f1fdbc43f0d0854896a1afe2815f8a9f4c87 Mon Sep 17 00:00:00 2001 From: CGantert345 <57003061+CGantert345@users.noreply.github.com> Date: Mon, 11 Apr 2022 15:06:48 +0200 Subject: fixing DOSIPAS algorithm names and supported EC curves --- .../dynamicFrame/api/SimpleDynamicFrame.java | 43 ++++- .../uic/barcode/utils/AlgorithmNameResolver.java | 187 ++++++++++++++------- .../java/org/uic/barcode/utils/SecurityUtils.java | 129 ++++++++++++++ 3 files changed, 288 insertions(+), 71 deletions(-) create mode 100644 src/main/java/org/uic/barcode/utils/SecurityUtils.java (limited to 'src/main') diff --git a/src/main/java/org/uic/barcode/dynamicFrame/api/SimpleDynamicFrame.java b/src/main/java/org/uic/barcode/dynamicFrame/api/SimpleDynamicFrame.java index a05a936..ef31166 100644 --- a/src/main/java/org/uic/barcode/dynamicFrame/api/SimpleDynamicFrame.java +++ b/src/main/java/org/uic/barcode/dynamicFrame/api/SimpleDynamicFrame.java @@ -20,6 +20,7 @@ import org.uic.barcode.dynamicFrame.v1.DynamicFrameCoderV1; import org.uic.barcode.dynamicFrame.v2.DynamicFrameCoderV2; import org.uic.barcode.ticket.EncodingFormatException; import org.uic.barcode.utils.AlgorithmNameResolver; +import org.uic.barcode.utils.SecurityUtils; @@ -132,13 +133,15 @@ public class SimpleDynamicFrame implements IDynamicFrame { * * Note: an appropriate security provider (e.g. BC) must be registered before * - * @param prov the registered security provider + * @param provider the registered security provider * @return the return error code * @throws EncodingFormatException */ @Override public int validateLevel2(Provider prov) throws EncodingFormatException { + Provider provider = prov; + if (getLevel2Data() == null || getLevel2Data().getLevel1Data() == null || getLevel2Data().getLevel1Data().getLevel2KeyAlg() == null @@ -159,7 +162,7 @@ public class SimpleDynamicFrame implements IDynamicFrame { String keyAlgName = null; try { - keyAlgName = AlgorithmNameResolver.getName(AlgorithmNameResolver.TYPE_KEY_GENERATOR_ALG, level2KeyAlg,prov); + keyAlgName = AlgorithmNameResolver.getName(AlgorithmNameResolver.TYPE_KEY_GENERATOR_ALG, level2KeyAlg,provider); } catch (Exception e1) { return Constants.LEVEL2_VALIDATION_KEY_ALG_NOT_IMPLEMENTED; } @@ -171,7 +174,20 @@ public class SimpleDynamicFrame implements IDynamicFrame { try { byte[] keyBytes = this.getLevel2Data().getLevel1Data().getLevel2publicKey(); X509EncodedKeySpec keySpec = new X509EncodedKeySpec(keyBytes); - key = KeyFactory.getInstance(keyAlgName).generatePublic(keySpec); + + KeyFactory keyFactory = null; + if (provider == null) { + keyFactory = SecurityUtils.findKeyFactory(level2KeyAlg, keyBytes); + provider = keyFactory.getProvider(); + } else { + keyFactory = KeyFactory.getInstance(keyAlgName,provider); + } + if (keyFactory != null) { + key = keyFactory.generatePublic(keySpec); + } else { + return Constants.LEVEL2_VALIDATION_KEY_ALG_NOT_IMPLEMENTED; + } + } catch (InvalidKeySpecException e1) { return Constants.LEVEL2_VALIDATION_KEY_ALG_NOT_IMPLEMENTED; } catch (NoSuchAlgorithmException e1) { @@ -183,7 +199,7 @@ public class SimpleDynamicFrame implements IDynamicFrame { String sigAlgName = null; try { - sigAlgName = AlgorithmNameResolver.getName(AlgorithmNameResolver.TYPE_SIGNATURE_ALG,level2SigAlg,prov); + sigAlgName = AlgorithmNameResolver.getSignatureAlgorithmName(level2SigAlg,provider); } catch (Exception e1) { return Constants.LEVEL2_VALIDATION_SIG_ALG_NOT_IMPLEMENTED; } @@ -191,12 +207,12 @@ public class SimpleDynamicFrame implements IDynamicFrame { return Constants.LEVEL2_VALIDATION_SIG_ALG_NOT_IMPLEMENTED; } - Signature sig; + Signature sig = null; try { - if (prov == null) { + if (provider == null) { sig = Signature.getInstance(sigAlgName); } else { - sig = Signature.getInstance(sigAlgName, prov); + sig = Signature.getInstance(sigAlgName,provider); } } catch (NoSuchAlgorithmException e) { return Constants.LEVEL2_VALIDATION_SIG_ALG_NOT_IMPLEMENTED; @@ -321,7 +337,7 @@ public class SimpleDynamicFrame implements IDynamicFrame { } else { return Constants.LEVEL1_VALIDATION_FRAUD; } - } catch (SignatureException e) { + } catch (Exception e) { return Constants.LEVEL1_VALIDATION_SIG_ALG_NOT_IMPLEMENTED; } } @@ -344,6 +360,9 @@ public class SimpleDynamicFrame implements IDynamicFrame { //find the algorithm name for the signature OID String algo = AlgorithmNameResolver.getSignatureAlgorithmName(this.getLevel2Data().getLevel1Data().getLevel2SigningAlg(), prov); Signature sig = null; + if (prov == null) { + prov = SecurityUtils.findPrivateKeyProvider(key); + } if (prov != null) { sig = Signature.getInstance(algo,prov); } else { @@ -438,10 +457,16 @@ public class SimpleDynamicFrame implements IDynamicFrame { ILevel1Data level1Data = level2Data.getLevel1Data(); if (level1Data == null) return; + + if (prov == null) { + //check for a provider supporting the key + prov = SecurityUtils.findPrivateKeyProvider(key); + } //find the algorithm name for the signature OID - String algo = AlgorithmNameResolver.getSignatureAlgorithmName(level1Data.getLevel1SigningAlg()); + String algo = AlgorithmNameResolver.getSignatureAlgorithmName(level1Data.getLevel1SigningAlg(), prov); Signature sig = null; + if (prov != null) { sig = Signature.getInstance(algo, prov); } else { diff --git a/src/main/java/org/uic/barcode/utils/AlgorithmNameResolver.java b/src/main/java/org/uic/barcode/utils/AlgorithmNameResolver.java index a3154f3..28f90e6 100644 --- a/src/main/java/org/uic/barcode/utils/AlgorithmNameResolver.java +++ b/src/main/java/org/uic/barcode/utils/AlgorithmNameResolver.java @@ -3,98 +3,161 @@ package org.uic.barcode.utils; import java.security.Provider; import java.security.Provider.Service; import java.security.Security; +import java.util.HashMap; +/** + * The Class AlgorithmNameResolver. + */ public class AlgorithmNameResolver { + /** The Constant TYPE_KEY_GENERATOR_ALG. */ public static final String TYPE_KEY_GENERATOR_ALG = "KeyPairGenerator"; + + /** The Constant TYPE_SIGNATURE_ALG. */ public static final String TYPE_SIGNATURE_ALG = "Signature"; + /** The map. */ + private static HashMap> map = new HashMap>(); + + /** + * Adds an entry for a mapping of algorithm type and oid to an algorithm name + * + * @param type the algorithm type + * @param oid the algorithm OID + * @param name the algorithm name + */ + public static void addMap (String type, String oid, String name) { + + if (map.get(type) == null) { + HashMap list = new HashMap(); + list.put(oid, name); + map.put(type, list); + } else { + map.get(type).put(oid, name); + } + } + + /** + * Gets the signature algorithm name. + * + * @param oid the oid + * @return the signature algorithm name + * @throws Exception the exception + */ public static String getSignatureAlgorithmName (String oid) throws Exception { - Provider[] provs = Security.getProviders(); - for (Provider prov : provs) { - Service service = prov.getService(AlgorithmNameResolver.TYPE_SIGNATURE_ALG,oid); - if (service != null) { - return service.getAlgorithm(); - } - } - return null; + return getSignatureAlgorithmName (oid, null); } + /** + * Gets the signature algorithm name. + * + * @param oid the oid + * @param provider the provider + * @return the signature algorithm name + * @throws Exception the exception + */ public static String getSignatureAlgorithmName (String oid, Provider provider) throws Exception { + return getAlgorithmName(AlgorithmNameResolver.TYPE_SIGNATURE_ALG,oid,provider); + + } + + /** + * Gets the name. + * + * @param type the type + * @param oid the oid + * @return the name + * @throws Exception the exception + */ + public static String getName (String type, String oid) throws Exception { + + return getAlgorithmName(type,oid,null); + + } + + + /** + * Gets the name. + * + * @param type the type + * @param oid the oid + * @param provider the provider + * @return the name + * @throws Exception the exception + */ + public static String getName(String type, String oid, Provider provider) throws Exception { + + return getAlgorithmName(type,oid,provider); + + } + + + + /** + * Gets the algorithm name. + * + * @param type the type + * @param oid the oid + * @param provider the provider + * @return the algorithm name + * @throws Exception the exception + */ + public static String getAlgorithmName (String type, String oid, Provider provider) throws Exception { + + String name = null; + if (provider != null) { - Service service = provider.getService(AlgorithmNameResolver.TYPE_SIGNATURE_ALG,oid); - return service.getAlgorithm(); + Service service = provider.getService(type,oid); + if (service != null) { + name = service.getAlgorithm(); + } + + if (name != null && name.length() > 0) { + return name; + } } Provider[] provs = Security.getProviders(); for (Provider prov : provs) { - Service service = prov.getService(AlgorithmNameResolver.TYPE_SIGNATURE_ALG,oid); + Service service = prov.getService(type,oid); if (service != null) { - return service.getAlgorithm(); + name = service.getAlgorithm(); + } + if (name != null && name.length() > 0) { + return name; } } - return null; - - } - - - public static String getName (String type, String oid) throws Exception { - - Provider[] provs = Security.getProviders(); - for (Provider prov : provs) { - Service service = prov.getService(type,oid); - if (service != null) { - return service.getAlgorithm(); - } - } - - if (oid.startsWith("1.2.840.10045")) { + + if (map.get(type) != null) { + if (map.get(type).get(oid) != null) { + return map.get(type).get(oid); + } + } + + + //fallback if the provider did not implement OIDs + if (oid.startsWith("1.2.840.10045.4")) { return "ECDSA"; - } else if (oid.startsWith("1.2.840.10040")) { - return "DSA"; - } - - return null; - - } - - - public static String getName(String type, String oid, Provider provider) throws Exception { - - Service service = null; - if (provider == null) { - - Provider[] provs = Security.getProviders(); - for (Provider prov : provs) { - service = prov.getService(type,oid); - } - - } else { - service = provider.getService(type,oid); - } - - - - if (service != null) { - return service.getAlgorithm(); - } - - if (oid.startsWith("1.2.840.10045")) { + } else if (oid.startsWith("1.2.840.10045.3")) { + return "EC"; + } else if (oid.startsWith("1.2.840.10045")) { return "ECDSA"; } else if (oid.startsWith("1.2.840.10040")) { return "DSA"; } - - return null; - - } + + return null; + + } + + diff --git a/src/main/java/org/uic/barcode/utils/SecurityUtils.java b/src/main/java/org/uic/barcode/utils/SecurityUtils.java new file mode 100644 index 0000000..542208b --- /dev/null +++ b/src/main/java/org/uic/barcode/utils/SecurityUtils.java @@ -0,0 +1,129 @@ +package org.uic.barcode.utils; + +import java.security.KeyFactory; +import java.security.NoSuchAlgorithmException; +import java.security.PrivateKey; +import java.security.Provider; +import java.security.PublicKey; +import java.security.Security; +import java.security.spec.InvalidKeySpecException; +import java.security.spec.PKCS8EncodedKeySpec; +import java.security.spec.X509EncodedKeySpec; + +public class SecurityUtils { + + public static KeyFactory findKeyFactory(String oid, byte[] keyBytes) { + + X509EncodedKeySpec keySpec = new X509EncodedKeySpec(keyBytes); + + String name = null; + try { + name = AlgorithmNameResolver.getName(AlgorithmNameResolver.TYPE_KEY_GENERATOR_ALG, oid); + } catch (Exception e2) { + return null; + } + if (name == null || name.length() == 0) { + return null; + } + + KeyFactory keyFactory = null; + + Provider[] provs = Security.getProviders(); + for (Provider provider : provs) { + try { + keyFactory = KeyFactory.getInstance(name,provider); + } catch (NoSuchAlgorithmException e1) { + //try next + } + if (keyFactory != null) { + try { + keyFactory.generatePublic(keySpec); + return keyFactory; + } catch (Exception e) { + //try next + } + } + } + return null; + + } + + + public static Provider findPrivateKeyProvider(PrivateKey key) { + + String name = key.getAlgorithm(); + byte[] keyBytes = key.getEncoded(); + + + PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(keyBytes); + + + KeyFactory keyFactory = null; + + Provider[] provs = Security.getProviders(); + for (Provider provider : provs) { + try { + keyFactory = KeyFactory.getInstance(name,provider); + } catch (NoSuchAlgorithmException e1) { + //try next + } + if (keyFactory != null) { + try { + keyFactory.generatePrivate(keySpec); + return provider; + } catch (Exception e) { + provider = null; + //try next + } + } + } + + return null; + } + + + + public static PublicKey convertPublicKey(PublicKey key) { + + + PublicKey publicKey; + try { + publicKey = KeyFactory.getInstance("RSA").generatePublic(new X509EncodedKeySpec(key.getEncoded())); + } catch (InvalidKeySpecException | NoSuchAlgorithmException e) { + return key; + } + + return publicKey; + + } + + + public static PublicKey convert(PublicKey key, Provider provider) { + + PublicKey publicKey; + try { + publicKey = KeyFactory.getInstance("RSA", provider).generatePublic(new X509EncodedKeySpec(key.getEncoded())); + } catch (InvalidKeySpecException | NoSuchAlgorithmException e) { + return key; + } + + return publicKey; + + + } + + + public static PrivateKey convertPrivateKey(PrivateKey key) { + + + PrivateKey privateKey; + try { + privateKey = KeyFactory.getInstance("RSA").generatePrivate(new PKCS8EncodedKeySpec(key.getEncoded())); + } catch (InvalidKeySpecException | NoSuchAlgorithmException e) { + return key; + } + + return privateKey; + + } +} -- cgit v1.2.3 From 6ef85723cca938e298b318dc6d564318b83ab4ba Mon Sep 17 00:00:00 2001 From: CGantert345 <57003061+CGantert345@users.noreply.github.com> Date: Mon, 11 Apr 2022 16:30:32 +0200 Subject: use one provider only within validation --- .../dynamicFrame/api/SimpleDynamicFrame.java | 10 ++- .../java/org/uic/barcode/utils/SecurityUtils.java | 77 ++++++++++++++++------ 2 files changed, 67 insertions(+), 20 deletions(-) (limited to 'src/main') diff --git a/src/main/java/org/uic/barcode/dynamicFrame/api/SimpleDynamicFrame.java b/src/main/java/org/uic/barcode/dynamicFrame/api/SimpleDynamicFrame.java index ef31166..a8d7a0f 100644 --- a/src/main/java/org/uic/barcode/dynamicFrame/api/SimpleDynamicFrame.java +++ b/src/main/java/org/uic/barcode/dynamicFrame/api/SimpleDynamicFrame.java @@ -272,6 +272,7 @@ public class SimpleDynamicFrame implements IDynamicFrame { return Constants.LEVEL1_VALIDATION_NO_SIGNATURE; } + byte[] signature = this.getLevel2Data().getLevel1Signature(); @@ -288,7 +289,13 @@ public class SimpleDynamicFrame implements IDynamicFrame { if (signingAlgorithmOid == null || signingAlgorithmOid.length() == 0) { return Constants.LEVEL1_VALIDATION_NO_SIGNATURE; - } + } + + if (prov == null) { + prov = SecurityUtils.findSignatureProvider(key.getEncoded(), signingAlgorithmOid); + } + + //find the algorithm name for the signature OID String algo = null; try { @@ -312,6 +319,7 @@ public class SimpleDynamicFrame implements IDynamicFrame { return Constants.LEVEL1_VALIDATION_SIG_ALG_NOT_IMPLEMENTED; } try { + key = SecurityUtils.convert(key, prov); sig.initVerify(key); } catch (InvalidKeyException e) { return Constants.LEVEL1_VALIDATION_SIG_ALG_NOT_IMPLEMENTED; diff --git a/src/main/java/org/uic/barcode/utils/SecurityUtils.java b/src/main/java/org/uic/barcode/utils/SecurityUtils.java index 542208b..af1a65a 100644 --- a/src/main/java/org/uic/barcode/utils/SecurityUtils.java +++ b/src/main/java/org/uic/barcode/utils/SecurityUtils.java @@ -4,6 +4,7 @@ import java.security.KeyFactory; import java.security.NoSuchAlgorithmException; import java.security.PrivateKey; import java.security.Provider; +import java.security.Provider.Service; import java.security.PublicKey; import java.security.Security; import java.security.spec.InvalidKeySpecException; @@ -81,28 +82,22 @@ public class SecurityUtils { return null; } - - - public static PublicKey convertPublicKey(PublicKey key) { - - - PublicKey publicKey; - try { - publicKey = KeyFactory.getInstance("RSA").generatePublic(new X509EncodedKeySpec(key.getEncoded())); - } catch (InvalidKeySpecException | NoSuchAlgorithmException e) { - return key; - } - - return publicKey; - - } public static PublicKey convert(PublicKey key, Provider provider) { PublicKey publicKey; + KeyFactory keyFactory = null; + try { - publicKey = KeyFactory.getInstance("RSA", provider).generatePublic(new X509EncodedKeySpec(key.getEncoded())); + if (key.getAlgorithm() != null && key.getAlgorithm().toUpperCase().contains("EC") ) { + keyFactory = KeyFactory.getInstance("EC",provider); + } else if (key.getAlgorithm() != null && key.getAlgorithm().length() > 0 ) { + keyFactory = KeyFactory.getInstance("DSA",provider); + } else { + return key; + } + publicKey = keyFactory.generatePublic(new X509EncodedKeySpec(key.getEncoded())); } catch (InvalidKeySpecException | NoSuchAlgorithmException e) { return key; } @@ -113,17 +108,61 @@ public class SecurityUtils { } - public static PrivateKey convertPrivateKey(PrivateKey key) { - + public static PrivateKey convert(PrivateKey key, Provider provider) { PrivateKey privateKey; + KeyFactory keyFactory = null; + try { - privateKey = KeyFactory.getInstance("RSA").generatePrivate(new PKCS8EncodedKeySpec(key.getEncoded())); + if (key.getAlgorithm() != null && key.getAlgorithm().toUpperCase().contains("EC") ) { + keyFactory = KeyFactory.getInstance("EC",provider); + } else if (key.getAlgorithm() != null && key.getAlgorithm().length() > 0 ) { + keyFactory = KeyFactory.getInstance("DSA",provider); + } else { + return key; + } + privateKey = keyFactory.generatePrivate(new PKCS8EncodedKeySpec(key.getEncoded())); } catch (InvalidKeySpecException | NoSuchAlgorithmException e) { return key; } return privateKey; + + } + + public static Provider findSignatureProvider(byte[] encoded, String oid) { + + KeyFactory keyFactory = null; + String signatureAlgorithmName = null; + + Provider[] provs = Security.getProviders(); + for (Provider provider : provs) { + try { + Service service = provider.getService(AlgorithmNameResolver.TYPE_SIGNATURE_ALG, oid); + if (service != null) { + signatureAlgorithmName = service.getAlgorithm(); + if (signatureAlgorithmName != null && signatureAlgorithmName.length() > 0) { + if (signatureAlgorithmName.toUpperCase().contains("EC") ) { + keyFactory = KeyFactory.getInstance("EC",provider); + } else { + keyFactory = KeyFactory.getInstance("DSA",provider); + } + if (keyFactory != null) { + X509EncodedKeySpec spec = new X509EncodedKeySpec(encoded); + //try to encode the key + keyFactory.generatePublic(spec); + } + } + } + } catch (Exception e1) { + keyFactory = null; + } + if (keyFactory != null) { + return keyFactory.getProvider(); + } + } + + return null; } } -- cgit v1.2.3 From 58bafb860b060c609a01815657b4df22ce8fbffc Mon Sep 17 00:00:00 2001 From: CGantert345 <57003061+CGantert345@users.noreply.github.com> Date: Tue, 12 Apr 2022 12:54:16 +0200 Subject: test on algorithm name resolver --- .../dynamicFrame/api/SimpleDynamicFrame.java | 15 +++--- .../uic/barcode/dynamicFrame/v2/DynamicFrame.java | 56 --------------------- .../barcode/ticket/api/impl/SimpleTraveler.java | 2 +- .../ticket/api/utils/OpenAsn2ApiDecoder.java | 4 +- .../ticket/api/utils/OpenAsn2ApiDecoderV2.java | 4 +- .../ticket/api/utils/OpenAsn2ApiDecoderV3.java | 6 ++- .../java/org/uic/barcode/utils/SecurityUtils.java | 57 +++++++++++++++++----- 7 files changed, 63 insertions(+), 81 deletions(-) (limited to 'src/main') diff --git a/src/main/java/org/uic/barcode/dynamicFrame/api/SimpleDynamicFrame.java b/src/main/java/org/uic/barcode/dynamicFrame/api/SimpleDynamicFrame.java index a8d7a0f..59ccd52 100644 --- a/src/main/java/org/uic/barcode/dynamicFrame/api/SimpleDynamicFrame.java +++ b/src/main/java/org/uic/barcode/dynamicFrame/api/SimpleDynamicFrame.java @@ -150,6 +150,7 @@ public class SimpleDynamicFrame implements IDynamicFrame { } String level2KeyAlg = getLevel2Data().getLevel1Data().getLevel2KeyAlg(); + String level2SigAlg = this.getLevel2Data().getLevel1Data().getLevel2SigningAlg(); if (level2KeyAlg == null || level2KeyAlg.length() == 0) { @@ -173,16 +174,13 @@ public class SimpleDynamicFrame implements IDynamicFrame { PublicKey key = null; try { byte[] keyBytes = this.getLevel2Data().getLevel1Data().getLevel2publicKey(); - X509EncodedKeySpec keySpec = new X509EncodedKeySpec(keyBytes); - KeyFactory keyFactory = null; if (provider == null) { - keyFactory = SecurityUtils.findKeyFactory(level2KeyAlg, keyBytes); - provider = keyFactory.getProvider(); - } else { - keyFactory = KeyFactory.getInstance(keyAlgName,provider); - } + provider = SecurityUtils.findPublicKeyProvider(level2KeyAlg,keyBytes); + } + KeyFactory keyFactory = KeyFactory.getInstance(keyAlgName,provider); if (keyFactory != null) { + X509EncodedKeySpec keySpec = new X509EncodedKeySpec(keyBytes); key = keyFactory.generatePublic(keySpec); } else { return Constants.LEVEL2_VALIDATION_KEY_ALG_NOT_IMPLEMENTED; @@ -194,9 +192,8 @@ public class SimpleDynamicFrame implements IDynamicFrame { return Constants.LEVEL2_VALIDATION_KEY_ALG_NOT_IMPLEMENTED; } - //find the algorithm name for the signature OID - String level2SigAlg = this.getLevel2Data().getLevel1Data().getLevel2SigningAlg(); + //find the algorithm name for the signature OID String sigAlgName = null; try { sigAlgName = AlgorithmNameResolver.getSignatureAlgorithmName(level2SigAlg,provider); diff --git a/src/main/java/org/uic/barcode/dynamicFrame/v2/DynamicFrame.java b/src/main/java/org/uic/barcode/dynamicFrame/v2/DynamicFrame.java index 55af066..30043c0 100644 --- a/src/main/java/org/uic/barcode/dynamicFrame/v2/DynamicFrame.java +++ b/src/main/java/org/uic/barcode/dynamicFrame/v2/DynamicFrame.java @@ -123,43 +123,6 @@ public class DynamicFrame extends Object{ } - /** - * Sign level 2 data without a specific security provider. - * - * @param key the key - * @throws Exception the exception - */ - public void signLevel2(PrivateKey key) throws Exception { - - //find the algorithm name for the signature OID - String algo = AlgorithmNameResolver.getSignatureAlgorithmName(this.getLevel2SignedData().getLevel1Data().level2SigningAlg); - Signature sig = Signature.getInstance(algo); - sig.initSign(key); - byte[] data = level2SignedData.encode(); - sig.update(data); - byte[] signature = sig.sign(); - this.level2Signature = new OctetString(signature); - - } - - /** - * Sign level 2 data. - * - * @param key the key - * @param prov the security Provider - * @throws Exception the exception - */ - public void signLevel2(PrivateKey key, Provider prov) throws Exception { - - //find the algorithm name for the signature OID - String algo = AlgorithmNameResolver.getSignatureAlgorithmName(this.getLevel2SignedData().getLevel1Data().level2SigningAlg); - Signature sig = Signature.getInstance(algo,prov); - sig.initSign(key); - byte[] data = level2SignedData.encode(); - sig.update(data); - this.level2Signature = new OctetString(sig.sign()); - - } /** @@ -207,24 +170,5 @@ public class DynamicFrame extends Object{ } - /** - * Gets the dynamic data FDC 1. - * - * @return the dynamic data FDC 1 - */ - public UicDynamicContentDataFDC1 getDynamicDataFDC1() { - - if (this.getLevel2SignedData() == null || - this.getLevel2SignedData().getLevel2Data() == null){ - return null; - } - - if ( UicDynamicContentDataFDC1.getFormat().equals(this.getLevel2SignedData().getLevel2Data().getFormat())) { - return UperEncoder.decode(this.getLevel2SignedData().getLevel2Data().getByteData(), UicDynamicContentDataFDC1.class); - } - return null; - - } - } diff --git a/src/main/java/org/uic/barcode/ticket/api/impl/SimpleTraveler.java b/src/main/java/org/uic/barcode/ticket/api/impl/SimpleTraveler.java index afc351d..e7edd45 100644 --- a/src/main/java/org/uic/barcode/ticket/api/impl/SimpleTraveler.java +++ b/src/main/java/org/uic/barcode/ticket/api/impl/SimpleTraveler.java @@ -53,7 +53,7 @@ public class SimpleTraveler implements ITraveler { protected IPassengerType passengerType; /** The passenger with reduced mobility. */ - protected boolean passengerWithReducedMobility; + protected Boolean passengerWithReducedMobility; /** The country of residence. */ protected int countryOfResidence = 0; 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 031d5b3..f4e041f 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 @@ -356,12 +356,14 @@ public class OpenAsn2ApiDecoder implements Asn2ApiDecoder { private IDelayConfirmation convertDelayConfirmation(DelayConfirmation asnDocument, Date issuingDate) { IDelayConfirmation document = factory.createDelayConfirmation(); - document.setReference(UicEncoderUtils.mapToString(asnDocument.getReferenceNum().longValue(),asnDocument.getReferenceIA5())); + document.setReference(UicEncoderUtils.mapToString(asnDocument.getReferenceNum(),asnDocument.getReferenceIA5())); document.setExtension(convertExtension(asnDocument.getExtension())); document.setInfoText(asnDocument.getInfoText()); + document.setTrain(UicEncoderUtils.mapToString(asnDocument.getTrainNum(), asnDocument.getTrainIA5())); + if (asnDocument.getStationCodeTable()!=null){ document.setStationCodeTable(IStationCodeTable.valueOf(asnDocument.getStationCodeTable().name())); } diff --git a/src/main/java/org/uic/barcode/ticket/api/utils/OpenAsn2ApiDecoderV2.java b/src/main/java/org/uic/barcode/ticket/api/utils/OpenAsn2ApiDecoderV2.java index 1d50cb8..57d2366 100644 --- a/src/main/java/org/uic/barcode/ticket/api/utils/OpenAsn2ApiDecoderV2.java +++ b/src/main/java/org/uic/barcode/ticket/api/utils/OpenAsn2ApiDecoderV2.java @@ -358,12 +358,14 @@ public class OpenAsn2ApiDecoderV2 implements Asn2ApiDecoder { private IDelayConfirmation convertDelayConfirmation(DelayConfirmation asnDocument, Date issuingDate) { IDelayConfirmation document = factory.createDelayConfirmation(); - document.setReference(UicEncoderUtils.mapToString(asnDocument.getReferenceNum().longValue(),asnDocument.getReferenceIA5())); + document.setReference(UicEncoderUtils.mapToString(asnDocument.getReferenceNum(),asnDocument.getReferenceIA5())); document.setExtension(convertExtension(asnDocument.getExtension())); document.setInfoText(asnDocument.getInfoText()); + document.setTrain(UicEncoderUtils.mapToString(asnDocument.getTrainNum(), asnDocument.getTrainIA5())); + if (asnDocument.getStationCodeTable()!=null){ document.setStationCodeTable(IStationCodeTable.valueOf(asnDocument.getStationCodeTable().toString())); } 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 20d2319..9521858 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 @@ -361,12 +361,14 @@ public class OpenAsn2ApiDecoderV3 implements Asn2ApiDecoder { private IDelayConfirmation convertDelayConfirmation(DelayConfirmation asnDocument, Date issuingDate) { IDelayConfirmation document = factory.createDelayConfirmation(); - document.setReference(UicEncoderUtils.mapToString(asnDocument.getReferenceNum().longValue(),asnDocument.getReferenceIA5())); + document.setReference(UicEncoderUtils.mapToString(asnDocument.getReferenceNum(),asnDocument.getReferenceIA5())); document.setExtension(convertExtension(asnDocument.getExtension())); - document.setInfoText(asnDocument.getInfoText()); + document.setInfoText(asnDocument.getInfoText()); + document.setTrain(UicEncoderUtils.mapToString(asnDocument.getTrainNum(), asnDocument.getTrainIA5())); + if (asnDocument.getStationCodeTable()!=null){ document.setStationCodeTable(IStationCodeTable.valueOf(asnDocument.getStationCodeTable().toString())); } diff --git a/src/main/java/org/uic/barcode/utils/SecurityUtils.java b/src/main/java/org/uic/barcode/utils/SecurityUtils.java index af1a65a..1fcc18a 100644 --- a/src/main/java/org/uic/barcode/utils/SecurityUtils.java +++ b/src/main/java/org/uic/barcode/utils/SecurityUtils.java @@ -11,22 +11,30 @@ import java.security.spec.InvalidKeySpecException; import java.security.spec.PKCS8EncodedKeySpec; import java.security.spec.X509EncodedKeySpec; +/** + * The Class SecurityUtils. + */ public class SecurityUtils { - public static KeyFactory findKeyFactory(String oid, byte[] keyBytes) { + /** + * Find provider by public key. + * + * @param algorithmOid the algorithm oid used to generate the key + * @param keyBytes the encoded bytes of the public key + * @return the provider + */ + public static Provider findPublicKeyProvider(String keyAlgorithmOid, byte[] keyBytes) { + X509EncodedKeySpec keySpec = new X509EncodedKeySpec(keyBytes); - String name = null; + String name; try { - name = AlgorithmNameResolver.getName(AlgorithmNameResolver.TYPE_KEY_GENERATOR_ALG, oid); + name = AlgorithmNameResolver.getAlgorithmName(AlgorithmNameResolver.TYPE_KEY_GENERATOR_ALG, keyAlgorithmOid, null); } catch (Exception e2) { return null; } - if (name == null || name.length() == 0) { - return null; - } - + KeyFactory keyFactory = null; Provider[] provs = Security.getProviders(); @@ -39,17 +47,23 @@ public class SecurityUtils { if (keyFactory != null) { try { keyFactory.generatePublic(keySpec); - return keyFactory; + return provider; } catch (Exception e) { + provider = null; //try next } } } - return null; - + + return null; } - + /** + * Find private key provider. + * + * @param key the private key + * @return the provider + */ public static Provider findPrivateKeyProvider(PrivateKey key) { String name = key.getAlgorithm(); @@ -84,6 +98,13 @@ public class SecurityUtils { + /** + * Convert. + * + * @param key the key + * @param provider the provider + * @return the public key + */ public static PublicKey convert(PublicKey key, Provider provider) { PublicKey publicKey; @@ -108,6 +129,13 @@ public class SecurityUtils { } + /** + * Convert. + * + * @param key the key + * @param provider the provider + * @return the private key + */ public static PrivateKey convert(PrivateKey key, Provider provider) { PrivateKey privateKey; @@ -131,6 +159,13 @@ public class SecurityUtils { } + /** + * Find signature provider. + * + * @param encoded the encoded + * @param oid the oid + * @return the provider + */ public static Provider findSignatureProvider(byte[] encoded, String oid) { KeyFactory keyFactory = null; -- cgit v1.2.3 From c830c865409321401504ac1ca296ced194811a16 Mon Sep 17 00:00:00 2001 From: CGantert345 <57003061+CGantert345@users.noreply.github.com> Date: Tue, 12 Apr 2022 14:12:55 +0200 Subject: test on car carriage cleanup --- .../uic/barcode/dynamicFrame/v2/DynamicFrame.java | 52 ---------------------- .../barcode/dynamicFrame/v2/Level2DataType.java | 44 ------------------ .../ticket/api/asn/omv3/SequenceOfPlaceNum.java | 1 - .../api/asn/omv3/SequenceOfServiceBrands.java | 1 - .../api/asn/omv3/SequenceOfTransportTypes.java | 1 - .../ticket/api/asn/omv3/SequenceOfTravelerId.java | 1 - .../ticket/api/utils/Api2OpenAsnEncoder.java | 16 +++---- .../ticket/api/utils/Api2OpenAsnEncoderV2.java | 16 +++---- .../ticket/api/utils/Api2OpenAsnEncoderV3.java | 17 +++---- .../ticket/api/utils/OpenAsn2ApiDecoder.java | 2 +- .../ticket/api/utils/OpenAsn2ApiDecoderV2.java | 2 +- .../ticket/api/utils/OpenAsn2ApiDecoderV3.java | 2 +- 12 files changed, 28 insertions(+), 127 deletions(-) (limited to 'src/main') diff --git a/src/main/java/org/uic/barcode/dynamicFrame/v2/DynamicFrame.java b/src/main/java/org/uic/barcode/dynamicFrame/v2/DynamicFrame.java index 30043c0..cb5c37a 100644 --- a/src/main/java/org/uic/barcode/dynamicFrame/v2/DynamicFrame.java +++ b/src/main/java/org/uic/barcode/dynamicFrame/v2/DynamicFrame.java @@ -1,8 +1,5 @@ package org.uic.barcode.dynamicFrame.v2; -import java.security.PrivateKey; -import java.security.Provider; -import java.security.Signature; import org.uic.barcode.asn1.datatypes.Asn1Optional; import org.uic.barcode.asn1.datatypes.CharacterRestriction; import org.uic.barcode.asn1.datatypes.FieldOrder; @@ -14,7 +11,6 @@ import org.uic.barcode.dynamicContent.api.DynamicContentCoder; import org.uic.barcode.dynamicContent.api.IUicDynamicContent; import org.uic.barcode.dynamicContent.fdc1.UicDynamicContentDataFDC1; import org.uic.barcode.ticket.EncodingFormatException; -import org.uic.barcode.utils.AlgorithmNameResolver; /** @@ -122,53 +118,5 @@ public class DynamicFrame extends Object{ return UperEncoder.decode(bytes, DynamicFrame.class); } - - - /** - * Adds the dynamic content and encodes it. (API level) - * - * @param content the dynamic content - * @throws EncodingFormatException the encoding format exception - */ - public void addDynamicContent(IUicDynamicContent content) throws EncodingFormatException { - - - this.getLevel2SignedData().setLevel2Data(new DataType()); - - this.getLevel2SignedData().getLevel2Data().setFormat(DynamicContentCoder.dynamicContentDataFDC1); - - this.getLevel2SignedData().getLevel2Data().setByteData(DynamicContentCoder.encode(content, DynamicContentCoder.dynamicContentDataFDC1)); - - } - - /** - * Adds the level 2 dynamic data. (ASN level) - * - * @param dynamicData the dynamic data - */ - public void addLevel2DynamicData(UicDynamicContentDataFDC1 dynamicData) { - DataType dt = new DataType(); - dt.setByteData(dynamicData.getDataType().getByteData()); - dt.setFormat(dynamicData.getDataType().getFormat()); - level2SignedData.setLevel2Data(dt); - } - - /** - * Gets the dynamic content. - * - * @return the dynamic content - */ - public IUicDynamicContent getDynamicContent() { - - if (this.getLevel2SignedData() == null || - this.getLevel2SignedData().getLevel2Data() == null){ - return null; - } - - return DynamicContentCoder.decode(this.getLevel2SignedData().getLevel2Data().getByteData()); - - } - - } diff --git a/src/main/java/org/uic/barcode/dynamicFrame/v2/Level2DataType.java b/src/main/java/org/uic/barcode/dynamicFrame/v2/Level2DataType.java index cd0800e..262fa2f 100644 --- a/src/main/java/org/uic/barcode/dynamicFrame/v2/Level2DataType.java +++ b/src/main/java/org/uic/barcode/dynamicFrame/v2/Level2DataType.java @@ -1,15 +1,10 @@ package org.uic.barcode.dynamicFrame.v2; -import java.security.PrivateKey; -import java.security.Provider; -import java.security.Signature; - import org.uic.barcode.asn1.datatypes.Asn1Optional; import org.uic.barcode.asn1.datatypes.FieldOrder; import org.uic.barcode.asn1.datatypes.Sequence; import org.uic.barcode.asn1.datatypesimpl.OctetString; import org.uic.barcode.asn1.uper.UperEncoder; -import org.uic.barcode.utils.AlgorithmNameResolver; /** * The Class DataType. @@ -76,46 +71,7 @@ public class Level2DataType { return UperEncoder.encode(this); } - /** - * Sign the contained data block. - * - * Note: an appropriate security provider (e.g. BC) must be registered before - * - * @param key the key - * @return - * @return the byte[] - * @throws Exception - */ - public void signLevel1(PrivateKey key) throws Exception { - //find the algorithm name for the signature OID - String algo = AlgorithmNameResolver.getSignatureAlgorithmName(getLevel1Data().level1SigningAlg); - Signature sig = Signature.getInstance(algo); - sig.initSign(key); - byte[] data = level1Data.encode(); - sig.update(data); - this.level1Signature = new OctetString(sig.sign()); - } - /** - * Sign the contained data block. - * - * Note: an appropriate security provider (e.g. BC) must be registered before - * - * @param key the key - * @param security provider - security provider that must be sued to create the signature - * @return - * @return the byte[] - * @throws Exception - */ - public void signLevel1(PrivateKey key, Provider prov) throws Exception { - //find the algorithm name for the signature OID - String algo = AlgorithmNameResolver.getSignatureAlgorithmName(getLevel1Data().level1SigningAlg); - Signature sig = Signature.getInstance(algo, prov); - sig.initSign(key); - byte[] data = level1Data.encode(); - sig.update(data); - this.level1Signature = new OctetString(sig.sign()); - } } diff --git a/src/main/java/org/uic/barcode/ticket/api/asn/omv3/SequenceOfPlaceNum.java b/src/main/java/org/uic/barcode/ticket/api/asn/omv3/SequenceOfPlaceNum.java index 3780dc3..1a6dbfc 100644 --- a/src/main/java/org/uic/barcode/ticket/api/asn/omv3/SequenceOfPlaceNum.java +++ b/src/main/java/org/uic/barcode/ticket/api/asn/omv3/SequenceOfPlaceNum.java @@ -20,7 +20,6 @@ public class SequenceOfPlaceNum extends Asn1SequenceOf { } } - @Deprecated public static SequenceOfPlaceNum getSequence(List numList) { if (numList == null || numList.isEmpty()) return null; return new SequenceOfPlaceNum(numList); diff --git a/src/main/java/org/uic/barcode/ticket/api/asn/omv3/SequenceOfServiceBrands.java b/src/main/java/org/uic/barcode/ticket/api/asn/omv3/SequenceOfServiceBrands.java index 388392b..3048235 100644 --- a/src/main/java/org/uic/barcode/ticket/api/asn/omv3/SequenceOfServiceBrands.java +++ b/src/main/java/org/uic/barcode/ticket/api/asn/omv3/SequenceOfServiceBrands.java @@ -19,7 +19,6 @@ public class SequenceOfServiceBrands extends Asn1SequenceOf { } } - @Deprecated public static SequenceOfServiceBrands getSequence(List numList) { if (numList == null || numList.isEmpty()) return null; return new SequenceOfServiceBrands(numList); diff --git a/src/main/java/org/uic/barcode/ticket/api/asn/omv3/SequenceOfTransportTypes.java b/src/main/java/org/uic/barcode/ticket/api/asn/omv3/SequenceOfTransportTypes.java index 934b5c9..edec045 100644 --- a/src/main/java/org/uic/barcode/ticket/api/asn/omv3/SequenceOfTransportTypes.java +++ b/src/main/java/org/uic/barcode/ticket/api/asn/omv3/SequenceOfTransportTypes.java @@ -19,7 +19,6 @@ public class SequenceOfTransportTypes extends Asn1SequenceOf { } } - @Deprecated public static SequenceOfTransportTypes getSequence(List numList) { if (numList == null || numList.isEmpty()) return null; return new SequenceOfTransportTypes(numList); diff --git a/src/main/java/org/uic/barcode/ticket/api/asn/omv3/SequenceOfTravelerId.java b/src/main/java/org/uic/barcode/ticket/api/asn/omv3/SequenceOfTravelerId.java index b04fcfa..6808104 100644 --- a/src/main/java/org/uic/barcode/ticket/api/asn/omv3/SequenceOfTravelerId.java +++ b/src/main/java/org/uic/barcode/ticket/api/asn/omv3/SequenceOfTravelerId.java @@ -18,7 +18,6 @@ public class SequenceOfTravelerId extends Asn1SequenceOf { } } - @Deprecated public static SequenceOfTravelerId getSequence(List numList) { if (numList == null || numList.isEmpty()) return null; return new SequenceOfTravelerId(numList); 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 f4b9569..633f2d7 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 @@ -359,6 +359,7 @@ public class Api2OpenAsnEncoder implements Api2AsnEncoder { asnData.setCarrierNum(SequenceOfCarrierNum.getSequence(UicEncoderUtils.getNumList(document.getCarriers()))); asnData.setCarrierIA5(UicEncoderUtils.getIA5NonNumList(document.getCarriers())); + asnData.setInfoText(document.getInfoText()); asnData.setExtension(encodeExtension(document.getExtension())); asnData.setCompartmentDetails(encodeCompartmentDetails(document.getCompartmentDetails())); @@ -389,21 +390,20 @@ public class Api2OpenAsnEncoder implements Api2AsnEncoder { asnData.setToStationNameUTF8(document.getToStationName()); - asnData.setAttachedBicycles(UicEncoderUtils.getRestrictedInt(document.getAttachedBicycles(),1,5)); - asnData.setAttachedBoats(UicEncoderUtils.getRestrictedInt(document.getAttachedBoats(),1,2)); - asnData.setAttachedSurfboards(UicEncoderUtils.getRestrictedInt(document.getAttachedSurfboards(),1,5)); + asnData.setAttachedBicycles(UicEncoderUtils.getRestrictedInt(document.getAttachedBicycles(),0,4)); + asnData.setAttachedBoats(UicEncoderUtils.getRestrictedInt(document.getAttachedBoats(),0,2)); + asnData.setAttachedSurfboards(UicEncoderUtils.getRestrictedInt(document.getAttachedSurfboards(),0,5)); if (document.getLoadingDeck() != ILoadingDeckType.upper && document.getLoadingDeck() != null){ asnData.setLoadingDeck(LoadingDeckType.valueOf(document.getLoadingDeck().name())); } - asnData.setLoadingListEntry(UicEncoderUtils.getRestrictedInt(document.getAttachedSurfboards(),1,200)); - - asnData.setBoatCategory(UicEncoderUtils.getRestrictedInt(document.getBoatCategory(),1,6)); - asnData.setCarCategory(UicEncoderUtils.getRestrictedInt(document.getCarCategory(),1,9)); + asnData.setLoadingListEntry(UicEncoderUtils.getRestrictedInt(document.getLoadingListEntry(),0,999)); + asnData.setBoatCategory(UicEncoderUtils.getRestrictedInt(document.getBoatCategory(),0,6)); + asnData.setCarCategory(UicEncoderUtils.getRestrictedInt(document.getCarCategory(),0,9)); asnData.setCoach(UicEncoderUtils.getIA5(document.getCoach())); - asnData.setRoofRackHeight(UicEncoderUtils.getRestrictedInt(document.getRoofRackHeight(),1,99)); + asnData.setRoofRackHeight(UicEncoderUtils.getRestrictedInt(document.getRoofRackHeight(),0,99)); if (document.getRoofRackType()!= IRoofRackType.norack && document.getRoofRackType() != null ) { asnData.setRoofRackType(RoofRackType.valueOf(document.getRoofRackType().name())); diff --git a/src/main/java/org/uic/barcode/ticket/api/utils/Api2OpenAsnEncoderV2.java b/src/main/java/org/uic/barcode/ticket/api/utils/Api2OpenAsnEncoderV2.java index 6bffddc..00c0ce3 100644 --- a/src/main/java/org/uic/barcode/ticket/api/utils/Api2OpenAsnEncoderV2.java +++ b/src/main/java/org/uic/barcode/ticket/api/utils/Api2OpenAsnEncoderV2.java @@ -386,21 +386,21 @@ public class Api2OpenAsnEncoderV2 implements Api2AsnEncoder { asnData.setToStationNameUTF8(document.getToStationName()); - asnData.setAttachedBicycles(UicEncoderUtils.getRestrictedInt(document.getAttachedBicycles(),1,5)); - asnData.setAttachedBoats(UicEncoderUtils.getRestrictedInt(document.getAttachedBoats(),1,2)); - asnData.setAttachedSurfboards(UicEncoderUtils.getRestrictedInt(document.getAttachedSurfboards(),1,5)); - + asnData.setAttachedBicycles(UicEncoderUtils.getRestrictedInt(document.getAttachedBicycles(),0,4)); + asnData.setAttachedBoats(UicEncoderUtils.getRestrictedInt(document.getAttachedBoats(),0,2)); + asnData.setAttachedSurfboards(UicEncoderUtils.getRestrictedInt(document.getAttachedSurfboards(),0,5)); + if (document.getLoadingDeck() != ILoadingDeckType.upper && document.getLoadingDeck() != null){ asnData.setLoadingDeck(LoadingDeckType.valueOf(document.getLoadingDeck().name())); } - asnData.setLoadingListEntry(UicEncoderUtils.getRestrictedInt(document.getAttachedSurfboards(),1,200)); + asnData.setLoadingListEntry(UicEncoderUtils.getRestrictedInt(document.getAttachedSurfboards(),0,999)); - asnData.setBoatCategory(UicEncoderUtils.getRestrictedInt(document.getBoatCategory(),1,6)); - asnData.setCarCategory(UicEncoderUtils.getRestrictedInt(document.getCarCategory(),1,9)); + asnData.setBoatCategory(UicEncoderUtils.getRestrictedInt(document.getBoatCategory(),0,6)); + asnData.setCarCategory(UicEncoderUtils.getRestrictedInt(document.getCarCategory(),0,9)); asnData.setCoach(UicEncoderUtils.getIA5(document.getCoach())); - asnData.setRoofRackHeight(UicEncoderUtils.getRestrictedInt(document.getRoofRackHeight(),1,99)); + asnData.setRoofRackHeight(UicEncoderUtils.getRestrictedInt(document.getRoofRackHeight(),0,99)); if (document.getRoofRackType()!= IRoofRackType.norack && document.getRoofRackType() != null) { asnData.setRoofRackType(RoofRackType.valueOf(document.getRoofRackType().name())); 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 0ead754..c586da0 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 @@ -360,6 +360,7 @@ public class Api2OpenAsnEncoderV3 implements Api2AsnEncoder { asnData.setCarrierNum(SequenceOfCarrierNum.getSequence(UicEncoderUtils.getNumList(document.getCarriers()))); asnData.setCarrierIA5(UicEncoderUtils.getIA5NonNumList(document.getCarriers())); + asnData.setInfoText(document.getInfoText()); asnData.setExtension(encodeExtension(document.getExtension())); asnData.setCompartmentDetails(encodeCompartmentDetails(document.getCompartmentDetails())); @@ -390,21 +391,21 @@ public class Api2OpenAsnEncoderV3 implements Api2AsnEncoder { asnData.setToStationNameUTF8(document.getToStationName()); - asnData.setAttachedBicycles(UicEncoderUtils.getRestrictedInt(document.getAttachedBicycles(),1,5)); - asnData.setAttachedBoats(UicEncoderUtils.getRestrictedInt(document.getAttachedBoats(),1,2)); - asnData.setAttachedSurfboards(UicEncoderUtils.getRestrictedInt(document.getAttachedSurfboards(),1,5)); + asnData.setAttachedBicycles(UicEncoderUtils.getRestrictedInt(document.getAttachedBicycles(),0,4)); + asnData.setAttachedBoats(UicEncoderUtils.getRestrictedInt(document.getAttachedBoats(),0,2)); + asnData.setAttachedSurfboards(UicEncoderUtils.getRestrictedInt(document.getAttachedSurfboards(),0,5)); if (document.getLoadingDeck() != ILoadingDeckType.upper && document.getLoadingDeck() != null){ asnData.setLoadingDeck(LoadingDeckType.valueOf(document.getLoadingDeck().name())); } - asnData.setLoadingListEntry(UicEncoderUtils.getRestrictedInt(document.getAttachedSurfboards(),1,200)); - - asnData.setBoatCategory(UicEncoderUtils.getRestrictedInt(document.getBoatCategory(),1,6)); - asnData.setCarCategory(UicEncoderUtils.getRestrictedInt(document.getCarCategory(),1,9)); + asnData.setLoadingListEntry(UicEncoderUtils.getRestrictedInt(document.getLoadingListEntry(),0,999)); + asnData.setBoatCategory(UicEncoderUtils.getRestrictedInt(document.getBoatCategory(),0,6)); + asnData.setCarCategory(UicEncoderUtils.getRestrictedInt(document.getCarCategory(),0,9)); + asnData.setRoofRackHeight(UicEncoderUtils.getRestrictedInt(document.getRoofRackHeight(),0,99)); + asnData.setCoach(UicEncoderUtils.getIA5(document.getCoach())); - asnData.setRoofRackHeight(UicEncoderUtils.getRestrictedInt(document.getRoofRackHeight(),1,99)); if (document.getRoofRackType()!= IRoofRackType.norack && document.getRoofRackType() != null) { asnData.setRoofRackType(RoofRackType.valueOf(document.getRoofRackType().name())); 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 f4e041f..f62e1f9 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 @@ -648,7 +648,7 @@ public class OpenAsn2ApiDecoder implements Asn2ApiDecoder { } } - return null; + return document; } diff --git a/src/main/java/org/uic/barcode/ticket/api/utils/OpenAsn2ApiDecoderV2.java b/src/main/java/org/uic/barcode/ticket/api/utils/OpenAsn2ApiDecoderV2.java index 57d2366..1f8e25b 100644 --- a/src/main/java/org/uic/barcode/ticket/api/utils/OpenAsn2ApiDecoderV2.java +++ b/src/main/java/org/uic/barcode/ticket/api/utils/OpenAsn2ApiDecoderV2.java @@ -650,7 +650,7 @@ public class OpenAsn2ApiDecoderV2 implements Asn2ApiDecoder { } } - return null; + return document; } 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 9521858..b656d3c 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 @@ -653,7 +653,7 @@ public class OpenAsn2ApiDecoderV3 implements Asn2ApiDecoder { } } - return null; + return document; } -- cgit v1.2.3 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 From 4204b79b6fd1f783ac8c5282ea46d50b88cd0355 Mon Sep 17 00:00:00 2001 From: CGantert345 <57003061+CGantert345@users.noreply.github.com> Date: Wed, 13 Apr 2022 17:48:04 +0200 Subject: unit test for fcb version 1 including all elements --- .../uic/barcode/ticket/api/asn/omv1/LineType.java | 14 ++++++--- .../ticket/api/utils/Api2OpenAsnEncoder.java | 20 +++++++++++- .../barcode/ticket/api/utils/Asn2ApiDecoder.java | 3 +- .../ticket/api/utils/OpenAsn2ApiDecoder.java | 36 ++++++++++++++++++---- 4 files changed, 61 insertions(+), 12 deletions(-) (limited to 'src/main') diff --git a/src/main/java/org/uic/barcode/ticket/api/asn/omv1/LineType.java b/src/main/java/org/uic/barcode/ticket/api/asn/omv1/LineType.java index 290f0e6..eb9249a 100644 --- a/src/main/java/org/uic/barcode/ticket/api/asn/omv1/LineType.java +++ b/src/main/java/org/uic/barcode/ticket/api/asn/omv1/LineType.java @@ -127,8 +127,11 @@ public class LineType extends Object { } public byte[] getBinaryZoneId() { - - return binaryZoneId.toByteArray(); + if (binaryZoneId != null) { + return binaryZoneId.toByteArray(); + } else { + return null; + } } public void setCarrierNum(Long carrierNum) { @@ -177,8 +180,11 @@ public class LineType extends Object { } public void setBinaryZoneId(byte[] binaryZoneId) { - - this.binaryZoneId = new OctetString(binaryZoneId); + if (binaryZoneId != null && binaryZoneId.length > 0) { + this.binaryZoneId = new OctetString(binaryZoneId); + } else { + this.binaryZoneId = null; + } } 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 835a324..6cf1673 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 @@ -352,7 +352,10 @@ public class Api2OpenAsnEncoder implements Api2AsnEncoder { asnData.setProductOwnerNum(UicEncoderUtils.getNum(document.getProductOwner())); asnData.setProductOwnerIA5(UicEncoderUtils.getIA5NonNum(document.getProductOwner())); - + + 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())); @@ -564,6 +567,9 @@ public class Api2OpenAsnEncoder implements Api2AsnEncoder { asnData.setProductOwnerNum(UicEncoderUtils.getNum(document.getProductOwner())); asnData.setProductOwnerIA5(UicEncoderUtils.getIA5NonNum(document.getProductOwner())); + + 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())); @@ -983,6 +989,8 @@ public class Api2OpenAsnEncoder implements Api2AsnEncoder { asnData.setProductOwnerNum(UicEncoderUtils.getNum(document.getProductOwner())); asnData.setProductOwnerIA5(UicEncoderUtils.getIA5NonNum(document.getProductOwner())); + asnData.setProductIdNum(UicEncoderUtils.getRestrictedNum(document.getProductId(),0,65535)); + asnData.setProductIdIA5(UicEncoderUtils.getIA5RestrictedNonNum(document.getProductId(),0,65535)); asnData.setTicketReferenceNum(UicEncoderUtils.getNum(document.getTicketReference())); asnData.setTicketReferenceIA5(UicEncoderUtils.getIA5NonNum(document.getTicketReference())); @@ -1366,6 +1374,10 @@ public class Api2OpenAsnEncoder implements Api2AsnEncoder { asnData.setProductOwnerNum(UicEncoderUtils.getNum(document.getProductOwner())); asnData.setProductOwnerIA5(UicEncoderUtils.getIA5NonNum(document.getProductOwner())); + 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())); @@ -2110,6 +2122,12 @@ public class Api2OpenAsnEncoder 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/Asn2ApiDecoder.java b/src/main/java/org/uic/barcode/ticket/api/utils/Asn2ApiDecoder.java index e751f48..79acf75 100644 --- a/src/main/java/org/uic/barcode/ticket/api/utils/Asn2ApiDecoder.java +++ b/src/main/java/org/uic/barcode/ticket/api/utils/Asn2ApiDecoder.java @@ -2,12 +2,13 @@ package org.uic.barcode.ticket.api.utils; import java.io.IOException; +import org.uic.barcode.ticket.EncodingFormatException; import org.uic.barcode.ticket.api.spec.IUicRailTicket; public interface Asn2ApiDecoder { - public IUicRailTicket decodeFromAsn (byte[] data) throws IOException; + public IUicRailTicket decodeFromAsn (byte[] data) throws IOException, EncodingFormatException; } 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 5f5ce4d..4cccb18 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 @@ -8,6 +8,7 @@ import java.util.Date; import java.util.Iterator; import java.util.List; +import org.uic.barcode.ticket.EncodingFormatException; 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; @@ -132,8 +133,9 @@ public class OpenAsn2ApiDecoder implements Asn2ApiDecoder { * @param asnUicRailTicketData the asn uic rail ticket data * @return the decoded uic rail ticket * @throws IOException Signals that an I/O exception has occurred. + * @throws EncodingFormatException */ - public IUicRailTicket decodeFromAsn (UicRailTicketData asnUicRailTicketData) throws IOException{ + public IUicRailTicket decodeFromAsn (UicRailTicketData asnUicRailTicketData) throws IOException, EncodingFormatException{ IUicRailTicket uicRailTicket = factory.createUicRailTicket(); @@ -149,8 +151,9 @@ public class OpenAsn2ApiDecoder implements Asn2ApiDecoder { * @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. + * @throws EncodingFormatException */ - public IUicRailTicket decodeFromAsn (byte[] data) throws IOException{ + public IUicRailTicket decodeFromAsn (byte[] data) throws IOException, EncodingFormatException{ UicRailTicketData asnUicRailTicketData = UicRailTicketData.decode(data); @@ -171,8 +174,9 @@ public class OpenAsn2ApiDecoder implements Asn2ApiDecoder { * * @param uicRailTicket the uic rail ticket * @param asnUicRailTicketData the asn uic rail ticket data + * @throws EncodingFormatException */ - protected void populateFromAsn1Model(IUicRailTicket uicRailTicket, UicRailTicketData asnUicRailTicketData) { + protected void populateFromAsn1Model(IUicRailTicket uicRailTicket, UicRailTicketData asnUicRailTicketData) throws EncodingFormatException { if (asnUicRailTicketData.getExtension()!= null && !asnUicRailTicketData.getExtension().isEmpty()) { for (ExtensionData asnExtension : asnUicRailTicketData.getExtension()){ @@ -215,8 +219,9 @@ public class OpenAsn2ApiDecoder implements Asn2ApiDecoder { * @param asnTransportDocuments the asn transport documents * @param uicRailTicket the uic rail ticket * @param issuingDate the issuing date + * @throws EncodingFormatException */ - protected void populateTravelDocuments(List asnTransportDocuments,IUicRailTicket uicRailTicket, Date issuingDate) { + protected void populateTravelDocuments(List asnTransportDocuments,IUicRailTicket uicRailTicket, Date issuingDate) throws EncodingFormatException { for ( DocumentData asnDocument : asnTransportDocuments){ @@ -1658,12 +1663,15 @@ public class OpenAsn2ApiDecoder implements Asn2ApiDecoder { * @param asnDocument the asn document * @param issuingDate the issuing date * @return the i fip ticket + * @throws EncodingFormatException */ - protected IFipTicket convertFipTicket(FIPTicketData asnDocument , Date issuingDate) { + protected IFipTicket convertFipTicket(FIPTicketData asnDocument , Date issuingDate) throws EncodingFormatException { if (asnDocument == null) return null; IFipTicket document = factory.createFipTicket(); + + if(asnDocument.getClassCode()!=null){ document.setClassCode(ITravelClassType.valueOf(asnDocument.getClassCode().name())); } @@ -1671,7 +1679,16 @@ public class OpenAsn2ApiDecoder implements Asn2ApiDecoder { document.setValidFrom(asnDocument.getValidFromDate(issuingDate)); document.setValidUntil(asnDocument.getValidUntilDate(issuingDate)); - + 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); + } + } document.setProductId(UicEncoderUtils.mapToString(asnDocument.getProductIdNum(),asnDocument.getProductIdIA5())); document.setProductOwner(UicEncoderUtils.mapToString(asnDocument.getProductOwnerNum(),asnDocument.getProductOwnerIA5())); @@ -2200,6 +2217,13 @@ public class OpenAsn2ApiDecoder implements Asn2ApiDecoder { issuingDetail.setPointOfSale(convertGeoCoordinate(asnIssuingDetail.getPointOfSale())); } + + issuingDetail.setCurrency(asnIssuingDetail.getCurrency()); + + if (asnIssuingDetail.getCurrencyFract() != null) { + issuingDetail.setCurrencyFraction(asnIssuingDetail.getCurrencyFract().intValue()); + } + } -- cgit v1.2.3