gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[libeufin] branch master updated: PAIN001 table.


From: gnunet
Subject: [libeufin] branch master updated: PAIN001 table.
Date: Tue, 18 Feb 2020 21:02:31 +0100

This is an automated email from the git hooks/post-receive script.

marcello pushed a commit to branch master
in repository libeufin.

The following commit(s) were added to refs/heads/master by this push:
     new 029d025  PAIN001 table.
029d025 is described below

commit 029d0258b5ea5cce71f544b1e874975115e4218f
Author: Marcello Stanisci <address@hidden>
AuthorDate: Tue Feb 18 21:02:14 2020 +0100

    PAIN001 table.
---
 .../kotlin/tech/libeufin/nexus/{Db.kt => DB.kt}    | 15 +++++
 .../src/main/kotlin/tech/libeufin/sandbox/DB.kt    | 61 +-------------------
 .../src/main/kotlin/tech/libeufin/sandbox/Main.kt  |  4 +-
 util/src/main/kotlin/DBTypes.kt                    | 67 ++++++++++++++++++++++
 4 files changed, 87 insertions(+), 60 deletions(-)

diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/Db.kt 
b/nexus/src/main/kotlin/tech/libeufin/nexus/DB.kt
similarity index 85%
rename from nexus/src/main/kotlin/tech/libeufin/nexus/Db.kt
rename to nexus/src/main/kotlin/tech/libeufin/nexus/DB.kt
index e28a3b7..f533906 100644
--- a/nexus/src/main/kotlin/tech/libeufin/nexus/Db.kt
+++ b/nexus/src/main/kotlin/tech/libeufin/nexus/DB.kt
@@ -6,6 +6,7 @@ import org.jetbrains.exposed.sql.transactions.TransactionManager
 import org.jetbrains.exposed.sql.transactions.transaction
 import tech.libeufin.nexus.EbicsSubscribersTable.entityId
 import tech.libeufin.nexus.EbicsSubscribersTable.primaryKey
+import tech.libeufin.util.IntIdTableWithAmount
 import java.sql.Connection
 
 const val ID_MAX_LENGTH = 50
@@ -56,6 +57,20 @@ const val ID_MAX_LENGTH = 50
 //
 //}
 
+object Pain001Table : IntIdTableWithAmount() {
+    val msgId = integer("msgId").uniqueIndex()
+    val paymentId = integer("paymentId").uniqueIndex() // id for this system
+    val date = date("fileDate")
+    val sum = amount("sum")
+    val debtorAccount = text("debtorAccount")
+    val endToEndId = integer("EndToEndId").uniqueIndex() // id for this and 
the creditor system
+    val subject = text("subject")
+    val creditorIban = text("creditorIban")
+    val creditorBic = text("creditorBic")
+    val creditorName = text("creditorName")
+    val submitted = bool("submitted") // indicates whether the PAIN message 
was sent to the bank.
+}
+
 object EbicsAccountsInfoTable : IdTable<String>() {
     override val id = varchar("id", ID_MAX_LENGTH).entityId().primaryKey()
     val subscriber = reference("subscriber", EbicsSubscribersTable)
diff --git a/sandbox/src/main/kotlin/tech/libeufin/sandbox/DB.kt 
b/sandbox/src/main/kotlin/tech/libeufin/sandbox/DB.kt
index 2c49ac7..32f62f9 100644
--- a/sandbox/src/main/kotlin/tech/libeufin/sandbox/DB.kt
+++ b/sandbox/src/main/kotlin/tech/libeufin/sandbox/DB.kt
@@ -24,12 +24,15 @@ import org.jetbrains.exposed.dao.*
 import org.jetbrains.exposed.sql.*
 import org.jetbrains.exposed.sql.transactions.TransactionManager
 import org.jetbrains.exposed.sql.transactions.transaction
+import tech.libeufin.util.IntIdTableWithAmount
 import java.lang.ArithmeticException
 import java.math.BigDecimal
 import java.math.MathContext
 import java.math.RoundingMode
 import java.sql.Blob
 import java.sql.Connection
+import tech.libeufin.util.IntIdTableWithAmount
+
 
 
 const val CUSTOMER_NAME_MAX_LENGTH = 20
@@ -39,8 +42,6 @@ const val EBICS_PARTNER_ID_MAX_LENGTH = 10
 const val EBICS_SYSTEM_ID_MAX_LENGTH = 10
 const val MAX_ID_LENGTH = 21 // enough to contain IBANs
 const val MAX_SUBJECT_LENGTH = 140 // okay?
-const val NUMBER_MAX_DIGITS = 20
-const val SCALE_TWO = 2
 
 /**
  * All the states to give a subscriber.
@@ -95,62 +96,6 @@ enum class KeyState {
     RELEASED
 }
 
-/**
- * Any number can become a Amount IF it does NOT need to be rounded to comply 
to the scale == 2.
- */
-typealias Amount = BigDecimal
-
-open class IntIdTableWithAmount : IntIdTable() {
-
-    class AmountColumnType : ColumnType() {
-        override fun sqlType(): String  = "DECIMAL(${NUMBER_MAX_DIGITS}, 
${SCALE_TWO})"
-
-        override fun valueFromDB(value: Any): Any {
-
-            val valueFromDB = super.valueFromDB(value)
-
-            try {
-                return when (valueFromDB) {
-                    is BigDecimal -> valueFromDB.setScale(SCALE_TWO, 
RoundingMode.UNNECESSARY)
-                    is Double -> 
BigDecimal.valueOf(valueFromDB).setScale(SCALE_TWO, RoundingMode.UNNECESSARY)
-                    is Float -> 
BigDecimal(java.lang.Float.toString(valueFromDB)).setScale(
-                        SCALE_TWO,
-                        RoundingMode.UNNECESSARY
-                    )
-                    is Int -> BigDecimal(valueFromDB)
-                    is Long -> BigDecimal.valueOf(valueFromDB)
-                    else -> valueFromDB
-                }
-            } catch (e: Exception) {
-                e.printStackTrace()
-                throw BadAmount(value)
-            }
-        }
-
-        override fun valueToDB(value: Any?): Any? {
-            try {
-                (value as BigDecimal).setScale(SCALE_TWO, 
RoundingMode.UNNECESSARY)
-            } catch (e: Exception) {
-                e.printStackTrace()
-                throw BadAmount(value)
-            }
-
-            if (value.compareTo(BigDecimal.ZERO) == 0) {
-                LOGGER.error("Cannot have transactions of ZERO amount")
-                throw BadAmount(value)
-            }
-            return super.valueToDB(value)
-        }
-    }
-
-    /**
-     * Make sure the number entered by upper layers does not need any rounding
-     * to conform to scale == 2
-     */
-    fun amount(name: String): Column<Amount> {
-        return registerColumn(name, AmountColumnType())
-    }
-}
 
 object BankTransactionsTable : IntIdTableWithAmount() {
 
diff --git a/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt 
b/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt
index 8315435..22e3c4a 100644
--- a/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt
+++ b/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt
@@ -48,6 +48,7 @@ import org.slf4j.Logger
 import org.slf4j.LoggerFactory
 import org.slf4j.event.Level
 import org.w3c.dom.Document
+import tech.libeufin.util.Amount
 import tech.libeufin.util.CryptoUtil
 import java.lang.ArithmeticException
 import java.math.BigDecimal
@@ -58,7 +59,6 @@ import javax.xml.bind.JAXBContext
 
 class CustomerNotFound(id: String?) : Exception("Customer ${id} not found")
 class BadInputData(inputData: String?) : Exception("Customer provided invalid 
input data: ${inputData}")
-class BadAmount(badValue: Any?) : Exception("Value '${badValue}' is not a 
valid amount")
 class UnacceptableFractional(badNumber: BigDecimal) : Exception(
     "Unacceptable fractional part ${badNumber}"
 )
@@ -149,7 +149,7 @@ fun sampleData() {
             nextOrderID = 1
             bankCustomer = customerEntity
         }
-        for (i in listOf<Amount>(Amount("-0.44"), Amount("6.02"))) {
+        for (i in listOf(Amount("-0.44"), Amount("6.02"))) {
             BankTransactionEntity.new {
                 counterpart = "IBAN"
                 amount = i
diff --git a/util/src/main/kotlin/DBTypes.kt b/util/src/main/kotlin/DBTypes.kt
new file mode 100644
index 0000000..c564e29
--- /dev/null
+++ b/util/src/main/kotlin/DBTypes.kt
@@ -0,0 +1,67 @@
+package tech.libeufin.util
+
+import org.jetbrains.exposed.dao.IntIdTable
+import org.jetbrains.exposed.sql.Column
+import org.jetbrains.exposed.sql.ColumnType
+import java.math.BigDecimal
+import java.math.RoundingMode
+
+const val SCALE_TWO = 2
+const val NUMBER_MAX_DIGITS = 20
+class BadAmount(badValue: Any?) : Exception("Value '${badValue}' is not a 
valid amount")
+
+/**
+ * Any number can become a Amount IF it does NOT need to be rounded to comply 
to the scale == 2.
+ */
+typealias Amount = BigDecimal
+
+open class IntIdTableWithAmount : IntIdTable() {
+
+    class AmountColumnType : ColumnType() {
+        override fun sqlType(): String  = "DECIMAL(${NUMBER_MAX_DIGITS}, 
${SCALE_TWO})"
+
+        override fun valueFromDB(value: Any): Any {
+
+            val valueFromDB = super.valueFromDB(value)
+
+            try {
+                return when (valueFromDB) {
+                    is BigDecimal -> valueFromDB.setScale(SCALE_TWO, 
RoundingMode.UNNECESSARY)
+                    is Double -> 
BigDecimal.valueOf(valueFromDB).setScale(SCALE_TWO, RoundingMode.UNNECESSARY)
+                    is Float -> 
BigDecimal(java.lang.Float.toString(valueFromDB)).setScale(
+                        SCALE_TWO,
+                        RoundingMode.UNNECESSARY
+                    )
+                    is Int -> BigDecimal(valueFromDB)
+                    is Long -> BigDecimal.valueOf(valueFromDB)
+                    else -> valueFromDB
+                }
+            } catch (e: Exception) {
+                e.printStackTrace()
+                throw BadAmount(value)
+            }
+        }
+
+        override fun valueToDB(value: Any?): Any? {
+            try {
+                (value as BigDecimal).setScale(SCALE_TWO, 
RoundingMode.UNNECESSARY)
+            } catch (e: Exception) {
+                e.printStackTrace()
+                throw BadAmount(value)
+            }
+
+            if (value.compareTo(BigDecimal.ZERO) == 0) {
+                throw BadAmount(value)
+            }
+            return super.valueToDB(value)
+        }
+    }
+
+    /**
+     * Make sure the number entered by upper layers does not need any rounding
+     * to conform to scale == 2
+     */
+    fun amount(name: String): Column<Amount> {
+        return registerColumn(name, AmountColumnType())
+    }
+}
\ No newline at end of file

-- 
To stop receiving notification emails like this one, please contact
address@hidden.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]