summaryrefslogtreecommitdiffstats
path: root/src/main
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/main/java/org/uic/barcode/asn1/datatypes/Asn1SequenceOf.java8
-rw-r--r--src/main/java/org/uic/barcode/asn1/uper/StringCoder.java8
-rw-r--r--src/main/java/org/uic/barcode/dynamicContent/api/DynamicContentCoder.java51
-rw-r--r--src/main/java/org/uic/barcode/dynamicContent/fdc1/TimeStamp.java20
-rw-r--r--src/main/java/org/uic/barcode/dynamicFrame/api/SimpleDynamicFrame.java56
-rw-r--r--src/main/java/org/uic/barcode/dynamicFrame/v2/DynamicFrame.java108
-rw-r--r--src/main/java/org/uic/barcode/dynamicFrame/v2/Level2DataType.java44
-rw-r--r--src/main/java/org/uic/barcode/logger/Logger.java20
-rw-r--r--src/main/java/org/uic/barcode/logger/LoggerFactory.java55
-rw-r--r--src/main/java/org/uic/barcode/ticket/api/asn/omv1/LineType.java14
-rw-r--r--src/main/java/org/uic/barcode/ticket/api/asn/omv3/SequenceOfPlaceNum.java1
-rw-r--r--src/main/java/org/uic/barcode/ticket/api/asn/omv3/SequenceOfServiceBrands.java1
-rw-r--r--src/main/java/org/uic/barcode/ticket/api/asn/omv3/SequenceOfTransportTypes.java1
-rw-r--r--src/main/java/org/uic/barcode/ticket/api/asn/omv3/SequenceOfTravelerId.java1
-rw-r--r--src/main/java/org/uic/barcode/ticket/api/impl/SimpleIncludedOpenTicket.java35
-rw-r--r--src/main/java/org/uic/barcode/ticket/api/impl/SimpleIssuingDetail.java24
-rw-r--r--src/main/java/org/uic/barcode/ticket/api/impl/SimpleTraveler.java2
-rw-r--r--src/main/java/org/uic/barcode/ticket/api/spec/IIncludedOpenTicket.java5
-rw-r--r--src/main/java/org/uic/barcode/ticket/api/spec/IIssuingDetail.java7
-rw-r--r--src/main/java/org/uic/barcode/ticket/api/utils/Api2OpenAsnEncoder.java112
-rw-r--r--src/main/java/org/uic/barcode/ticket/api/utils/Api2OpenAsnEncoderV2.java16
-rw-r--r--src/main/java/org/uic/barcode/ticket/api/utils/Api2OpenAsnEncoderV3.java215
-rw-r--r--src/main/java/org/uic/barcode/ticket/api/utils/Asn2ApiDecoder.java3
-rw-r--r--src/main/java/org/uic/barcode/ticket/api/utils/OpenAsn2ApiDecoder.java146
-rw-r--r--src/main/java/org/uic/barcode/ticket/api/utils/OpenAsn2ApiDecoderV2.java6
-rw-r--r--src/main/java/org/uic/barcode/ticket/api/utils/OpenAsn2ApiDecoderV3.java153
-rw-r--r--src/main/java/org/uic/barcode/ticket/api/utils/UicEncoderUtils.java45
-rw-r--r--src/main/java/org/uic/barcode/utils/AlgorithmNameResolver.java187
-rw-r--r--src/main/java/org/uic/barcode/utils/SecurityUtils.java203
29 files changed, 1114 insertions, 433 deletions
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 <T> type of elements contained.
*/
public abstract class Asn1SequenceOf<T> extends AbstractList<T> {
- private final static Logger logger = LoggerFactory.getLogger("asnLogger");
-
+
private final List<T> bakingList;
@Override public T get(int index) { return bakingList.get(index); }
@@ -45,7 +43,7 @@ public abstract class Asn1SequenceOf<T> extends AbstractList<T> {
public Asn1SequenceOf() { this(new ArrayList<T>()); }
public Asn1SequenceOf(Collection<T> 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 <T> 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/dynamicContent/api/DynamicContentCoder.java b/src/main/java/org/uic/barcode/dynamicContent/api/DynamicContentCoder.java
index 34406e0..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<IExtension> 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;
}
@@ -92,8 +96,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()));
@@ -158,8 +166,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;
@@ -167,10 +176,16 @@ public class DynamicContentCoder {
private static IGeoCoordinate getGeoCoordinate(GeoCoordinateType asnCoordinate) {
+ if (asnCoordinate == null) return null;
+
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()));
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;
}
/**
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..59ccd52 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
@@ -147,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) {
@@ -159,7 +163,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;
}
@@ -170,20 +174,29 @@ public class SimpleDynamicFrame implements IDynamicFrame {
PublicKey key = null;
try {
byte[] keyBytes = this.getLevel2Data().getLevel1Data().getLevel2publicKey();
- X509EncodedKeySpec keySpec = new X509EncodedKeySpec(keyBytes);
- key = KeyFactory.getInstance(keyAlgName).generatePublic(keySpec);
+
+ if (provider == null) {
+ 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;
+ }
+
} catch (InvalidKeySpecException e1) {
return Constants.LEVEL2_VALIDATION_KEY_ALG_NOT_IMPLEMENTED;
} catch (NoSuchAlgorithmException e1) {
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.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 +204,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;
@@ -256,6 +269,7 @@ public class SimpleDynamicFrame implements IDynamicFrame {
return Constants.LEVEL1_VALIDATION_NO_SIGNATURE;
}
+
byte[] signature = this.getLevel2Data().getLevel1Signature();
@@ -272,7 +286,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 {
@@ -296,6 +316,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;
@@ -321,7 +342,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 +365,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 +462,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/dynamicFrame/v2/DynamicFrame.java b/src/main/java/org/uic/barcode/dynamicFrame/v2/DynamicFrame.java
index 55af066..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,109 +118,5 @@ public class DynamicFrame extends Object{
return UperEncoder.decode(bytes, DynamicFrame.class);
}
-
- /**
- * 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());
-
- }
-
- /**
- * 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());
-
- }
-
- /**
- * 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/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/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<String,Logger> registeredLoggers = new HashMap<String,Logger>();
+
+ /** 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);
+ }
+
}
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/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<Long> {
}
}
- @Deprecated
public static SequenceOfPlaceNum getSequence(List<Long> 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<Long> {
}
}
- @Deprecated
public static SequenceOfServiceBrands getSequence(List<Long> 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<Long> {
}
}
- @Deprecated
public static SequenceOfTransportTypes getSequence(List<Long> 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<Long> {
}
}
- @Deprecated
public static SequenceOfTravelerId getSequence(List<Long> numList) {
if (numList == null || numList.isEmpty()) return null;
return new SequenceOfTravelerId(numList);
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 Collection<Integer>includedTransportTypes = new LinkedHashSet<Integer>();
+
+ /** The excluded service brands. */
+ protected Collection<Integer>excludedTransportTypes = new LinkedHashSet<Integer>();
/* (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<Integer> 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<Integer> 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/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/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 f4b9569..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
@@ -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;
@@ -348,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()));
@@ -359,6 +366,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 +397,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()));
@@ -486,9 +493,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.
*
@@ -544,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()));
@@ -602,6 +628,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 +745,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 +921,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 +946,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);
}
@@ -946,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()));
@@ -1013,12 +1058,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 +1133,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 +1243,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);
}
}
@@ -1324,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()));
@@ -1475,7 +1529,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 +1559,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 +1675,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 +1693,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 +1750,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);
@@ -2062,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/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..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()));
@@ -360,6 +367,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 +398,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()));
@@ -487,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.
*
@@ -543,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()));
@@ -603,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()));
@@ -679,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());
@@ -720,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()));
}
@@ -731,6 +765,8 @@ public class Api2OpenAsnEncoderV3 implements Api2AsnEncoder {
if (document.getValidRegionList()!= null && document.getValidRegionList().size() > 0) {
asnData.setValidRegion(encodeRegionCollection(document.getValidRegionList(), issuingDate));
}
+
+
return asnData;
}
@@ -841,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()));
@@ -894,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()));
}
@@ -915,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);
}
@@ -951,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()));
@@ -1022,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);
}
@@ -1101,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;
}
@@ -1206,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);
}
}
@@ -1332,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()));
@@ -1448,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));
@@ -1484,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;
}
/**
@@ -1505,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());
@@ -1546,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()));
@@ -1586,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 ){
@@ -1666,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()){
@@ -1681,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();
@@ -1721,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()));
@@ -1736,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);
@@ -1768,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()));
@@ -1975,29 +2036,29 @@ public class Api2OpenAsnEncoderV3 implements Api2AsnEncoder {
SequenceOfTicketLinkType asnList = new SequenceOfTicketLinkType();
- for (ITicketLink ticket : linkedTickets){
-
- TicketLinkType asnTicket = new TicketLinkType();
+ for (ITicketLink document : linkedTickets){
- asnTicket.setIssuerName(ticket.getIssuer());
+ TicketLinkType asnData = new TicketLinkType();
- asnTicket.setIssuerPNR(ticket.getIssuerPNR());
+ asnData.setIssuerName(document.getIssuer());
- asnTicket.setProductOwnerNum(UicEncoderUtils.getNum(ticket.getProductOwner()));
- asnTicket.setProductOwnerIA5(UicEncoderUtils.getIA5NonNum(ticket.getProductOwner()));
+ asnData.setIssuerPNR(document.getIssuerPNR());
- 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;
@@ -2105,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/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 031d5b3..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
@@ -5,12 +5,15 @@ 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.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;
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 +54,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 +98,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;
@@ -128,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();
@@ -145,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);
@@ -167,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()){
@@ -211,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<DocumentData> asnTransportDocuments,IUicRailTicket uicRailTicket, Date issuingDate) {
+ protected void populateTravelDocuments(List<DocumentData> asnTransportDocuments,IUicRailTicket uicRailTicket, Date issuingDate) throws EncodingFormatException {
for ( DocumentData asnDocument : asnTransportDocuments){
@@ -356,12 +365,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()));
}
@@ -434,6 +445,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()));
}
@@ -453,6 +468,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()));
@@ -515,6 +534,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;
+ }
@@ -646,7 +679,7 @@ public class OpenAsn2ApiDecoder implements Asn2ApiDecoder {
}
}
- return null;
+ return document;
}
@@ -699,11 +732,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.
*
@@ -794,7 +840,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()));
@@ -809,7 +858,6 @@ public class OpenAsn2ApiDecoder implements Asn2ApiDecoder {
}
document.setReturnDescription(convertReturnDescription(asnDocument.getReturnDescription(), issuingDate));
-
if(asnDocument.getReturnIncluded()!=null){
document.setReturnIncluded(asnDocument.getReturnIncluded());
@@ -817,7 +865,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());
@@ -930,6 +1000,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));
@@ -1056,6 +1130,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));
@@ -1171,9 +1249,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);
}
}
@@ -1336,9 +1414,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;
@@ -1393,6 +1475,13 @@ public class OpenAsn2ApiDecoder implements Asn2ApiDecoder {
zone.setNUTScode(asnDocument.getNutsCode());
+ if (asnDocument.getZoneId() != null && !asnDocument.getZoneId().isEmpty()) {
+ Iterator<Long> it = asnDocument.getZoneId().iterator();
+ while (it.hasNext()) {
+ zone.addZoneId(it.next().intValue());
+ }
+ }
+
return zone;
}
@@ -1411,6 +1500,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()){
@@ -1572,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()));
}
@@ -1585,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()));
@@ -1643,6 +1746,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());
}
@@ -1854,6 +1960,9 @@ public class OpenAsn2ApiDecoder implements Asn2ApiDecoder {
card.addIncludedService(new Integer(service.intValue()));
}
}
+
+ card.setExtension(convertExtension(asnDocument.getExtension()));
+
return card;
}
@@ -2108,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());
+ }
+
}
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..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
@@ -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()));
}
@@ -648,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 20d2319..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;
@@ -361,12 +365,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()));
}
@@ -439,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()));
}
@@ -458,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()));
@@ -520,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.
@@ -651,7 +674,7 @@ public class OpenAsn2ApiDecoderV3 implements Asn2ApiDecoder {
}
}
- return null;
+ return document;
}
@@ -704,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.
*
@@ -800,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()));
@@ -823,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());
@@ -935,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));
@@ -952,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());
@@ -976,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());
@@ -1010,6 +1075,8 @@ public class OpenAsn2ApiDecoderV3 implements Asn2ApiDecoder {
}
}
+ document.setReturnDescription(convertReturnDescription(asnDocument.getReturnDescription(), issuingDate));
+
if (asnDocument.getIssuerAutorizationId() != null) {
document.setAuthorizationCode(asnDocument.getIssuerAutorizationId().intValue());
}
@@ -1075,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));
@@ -1147,6 +1218,8 @@ public class OpenAsn2ApiDecoderV3 implements Asn2ApiDecoder {
if (asnDocument.getExternalIssuerId()!=null){
document.setExternalIssuer(asnDocument.getExternalIssuerId().intValue());
}
+
+
return document;
}
@@ -1202,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);
}
}
@@ -1379,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;
}
@@ -1436,6 +1512,14 @@ public class OpenAsn2ApiDecoderV3 implements Asn2ApiDecoder {
zone.setNUTScode(asnDocument.getNutsCode());
+ if (asnDocument.getZoneId() != null && !asnDocument.getZoneId().isEmpty()) {
+ Iterator<Long> it = asnDocument.getZoneId().iterator();
+ while (it.hasNext()) {
+ zone.addZoneId(it.next().intValue());
+ }
+ }
+
+
return zone;
}
@@ -1454,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()){
@@ -1628,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){
@@ -1686,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());
}
@@ -1956,6 +2054,9 @@ public class OpenAsn2ApiDecoderV3 implements Asn2ApiDecoder {
card.addIncludedService(new Integer(service.intValue()));
}
}
+
+ card.setExtension(convertExtension(asnDocument.getExtension()));
+
return card;
}
@@ -2210,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 {
}
+
+
}
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<String, HashMap<String, String>> map = new HashMap<String, HashMap<String, String>>();
+
+ /**
+ * 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<String,String> list = new HashMap<String , String>();
+ 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..1fcc18a
--- /dev/null
+++ b/src/main/java/org/uic/barcode/utils/SecurityUtils.java
@@ -0,0 +1,203 @@
+package org.uic.barcode.utils;
+
+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;
+import java.security.spec.PKCS8EncodedKeySpec;
+import java.security.spec.X509EncodedKeySpec;
+
+/**
+ * The Class SecurityUtils.
+ */
+public class SecurityUtils {
+
+ /**
+ * 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;
+ try {
+ name = AlgorithmNameResolver.getAlgorithmName(AlgorithmNameResolver.TYPE_KEY_GENERATOR_ALG, keyAlgorithmOid, null);
+ } catch (Exception e2) {
+ 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 provider;
+ } catch (Exception e) {
+ provider = null;
+ //try next
+ }
+ }
+ }
+
+ return null;
+ }
+
+ /**
+ * Find private key provider.
+ *
+ * @param key the private key
+ * @return the provider
+ */
+ 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;
+ }
+
+
+
+ /**
+ * Convert.
+ *
+ * @param key the key
+ * @param provider the provider
+ * @return the public key
+ */
+ public static PublicKey convert(PublicKey key, Provider provider) {
+
+ PublicKey publicKey;
+ KeyFactory keyFactory = null;
+
+ try {
+ 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;
+ }
+
+ return publicKey;
+
+
+ }
+
+
+ /**
+ * Convert.
+ *
+ * @param key the key
+ * @param provider the provider
+ * @return the private key
+ */
+ public static PrivateKey convert(PrivateKey key, Provider provider) {
+
+ PrivateKey privateKey;
+ KeyFactory keyFactory = null;
+
+ try {
+ 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;
+
+
+ }
+
+ /**
+ * 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;
+ 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;
+ }
+}