@@ -11,6 +11,7 @@ import com.fasterxml.jackson.databind.ObjectMapper
1111import io.swagger.v3.oas.annotations.Operation
1212import io.swagger.v3.oas.annotations.tags.Tag
1313import org.joda.time.DateTime
14+ import org.slf4j.LoggerFactory
1415import org.springframework.beans.factory.annotation.Value
1516import org.springframework.kafka.core.KafkaTemplate
1617import org.springframework.web.bind.annotation.PostMapping
@@ -35,6 +36,8 @@ class InputController(
3536 private val kafkaTemplate : KafkaTemplate <String , String > // note: ignore jetbrains [false] warning
3637) {
3738
39+ private final val log = LoggerFactory .getLogger(InputController ::class .java)
40+
3841 // Just for tests, if you don't want to have kafka running, do:
3942 // export BB_NO_KAFKA=true
4043 @Value(" \$ {${HiddenEnvironmentVariables .NO_KAFKA } :false}" )
@@ -84,6 +87,7 @@ class InputController(
8487 val measure = if (rawMeasure.timestamp != null ) {
8588 // check that date is in the past
8689 if (rawMeasure.timestamp.millis > now.millis + MAX_LAG ) {
90+ log.info(" REJECTED: wrong timestamp: ${rawMeasure} " )
8791 throw WrongParamsException (" objectId ${rawMeasure.objectId} : date should be in the past. input='${rawMeasure.timestamp} ', now='$now '" )
8892 }
8993 rawMeasure
@@ -94,17 +98,21 @@ class InputController(
9498
9599 // get metadata
96100 val meta = inputRepository.getMeasureMeta(measure.objectId!! , measure.token!! ).orElseThrow {
101+ log.info(" REJECTED: wrong token: $measure " )
97102 ItemNotFoundException (msg = " objectId ${measure.objectId} : the pair <objectId, token> does not exist" )
98103 }
99104 // ensure the object is enabled. This is just a double check, as tokens cannot be created on disabled objects
100105 if (meta.disabled) {
106+ log.info(" REJECTED: object is disabled: $rawMeasure " )
101107 throw ForbiddenException (" objectId ${rawMeasure.objectId} is disabled." )
102108 }
103109 // ensure the measure matches the type declared, and parse it
104110 val parsedValue = BaseType .parseType(measure.value!! , meta.type)
105- parsedValue
106- ? : throw WrongParamsException (" objectId ${rawMeasure.objectId} : the value '${measure.value} ' does not match " +
107- " the unit ${meta.unitSymbol} (${meta.type} ) declared in the object definition." )
111+ if (parsedValue == null ) {
112+ log.info(" REJECTED: wrong value given the unit: $measure , $meta " )
113+ throw WrongParamsException (" objectId ${rawMeasure.objectId} : the value '${measure.value} ' does not match " +
114+ " the unit ${meta.unitSymbol} (${meta.type} ) declared in the object definition." )
115+ }
108116
109117 measure.value = parsedValue.toString()
110118
@@ -114,12 +122,14 @@ class InputController(
114122
115123 // ensure no duplicate objectId/timestamp in the data sent
116124 if (valueKeys.contains(key)) {
125+ log.info(" REJECTED: duplicate in body: $measure " )
117126 throw WrongParamsException (" objectId ${measure.objectId} : two or more values with the same timestamp" )
118127 }
119128 valueKeys.add(key)
120129
121130 // ensure it doesn't already exist in cassandra TODO: find a better way ?
122131 if (rawValueRepository.existsById(rawValue.key)) {
132+ log.info(" REJECTED: duplicate in cassandra: $measure " )
123133 throw WrongParamsException (" objectId ${rawMeasure.objectId} : " +
124134 " a value with the same timestamp (${measure.timestamp} ) already exists for this object." )
125135 }
0 commit comments