We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 2662460 commit 9d324b5Copy full SHA for 9d324b5
3 files changed
other/mysql/test-data.sql
@@ -51,7 +51,7 @@ INSERT INTO `objects` (`id`, `name`, `description`, `ugrp_id`, `unit_symbol`, `c
51
(2, 'volts box 2', NULL, 2, 'V', '2019-01-01'),
52
(3, 'tmp box 1', NULL, 2, 'h', '2019-01-01'),
53
(4, 'tmp box 2', NULL, 2, 'Here', DEFAULT),
54
- (5, 'caching', NULL, 2, 'V', DEFAULT),
+ (5, 'some free text', NULL, 2, 'char', DEFAULT),
55
-- one object owned by the "other" usergroup
56
(6, 'owned by other', NULL, 3, 'V', DEFAULT),
57
-- objects that have values in cassandra
@@ -92,6 +92,7 @@ INSERT INTO `tokens` (`id`, `token`, `object_id`, `description`) VALUES
92
(1, '012345678901234567890123456789a1', 1, 'test'),
93
(2, '012345678901234567890123456789a2', 2, 'test'),
94
(3, '012345678901234567890123456789a3', 3, 'test'),
95
- (4, '012345678901234567890123456789a4', 4, 'test');
+ (4, '012345678901234567890123456789a4', 4, 'test'),
96
+ (5, '012345678901234567890123456789a5', 5, 'test');
97
98
COMMIT;
src/main/kotlin/ch/derlin/bbdata/output/api/types/BaseType.kt
@@ -12,10 +12,13 @@ package ch.derlin.bbdata.output.api.types
12
*/
13
14
15
+import ch.derlin.bbdata.common.truncate
16
import com.fasterxml.jackson.annotation.JsonIdentityInfo
17
import com.fasterxml.jackson.annotation.JsonIdentityReference
18
import com.fasterxml.jackson.annotation.ObjectIdGenerators
19
import org.hibernate.validator.constraints.Length
20
+import org.slf4j.Logger
21
+import org.slf4j.LoggerFactory
22
import javax.persistence.*
23
import javax.validation.constraints.NotEmpty
24
@@ -40,9 +43,12 @@ data class BaseType(
40
43
companion object {
41
44
const val TYPE_MAX = 45
42
45
46
+ private val log: Logger = LoggerFactory.getLogger(BaseType::class.java)
47
+
48
fun parseType(value: String, type: String): Any? {
49
try {
50
when (type) {
+ "string" -> return value
"float" -> return value.toFloat()
"int" -> return value.toInt()
"bool" -> {
@@ -52,8 +58,10 @@ data class BaseType(
58
return false
59
return null
60
}
61
+ else -> log.error("got an unknown unit type '$type' for value '$value'")
62
63
} catch (e: Exception) {
64
+ log.debug("exception while parsing value ${value.truncate()} of type $type: ${e.javaClass.simpleName} ${e.message}")
65
66
67
src/test/kotlin/ch/derlin/bbdata/input/InputApiTest.kt
@@ -203,6 +203,13 @@ class InputApiTest {
203
assertEquals(HttpStatus.OK, resp.statusCode, "good bool false: $v. ${resp.body}")
204
assertEquals("false", JsonPath.parse(resp.body).read<String>("$[0].value"))
205
206
207
+ // test good string
208
+ for (v in listOf("False", "12.0", """{\"json\": \"data\", \"works\": 1}""", " ", true)) {
209
+ resp = restTemplate.postWithBody(URL, getMeasureBody(objectId = 5, value = v))
210
+ assertEquals(HttpStatus.OK, resp.statusCode, "good string: $v. ${resp.body}")
211
+ assertEquals(v.toString().replace("\\\"", "\""), JsonPath.parse(resp.body).read<String>("$[0].value"))
212
+ }
213
214
215
@Test
0 commit comments