Verified Commit 127f5183 authored by 35V LG84's avatar 35V LG84

tep-1010: Geo URI grammar

Signed-off-by: 35V LG84's avatar35V LG84 <[email protected]>
parent d993144c
......@@ -17,6 +17,7 @@
lexer grammar TxnLexer;
UUID_NAME: 'uuid';
LOCATION_NAME: 'location';
UUID_VALUE: HEX HEX HEX HEX HEX HEX HEX HEX '-' HEX HEX HEX HEX '-' HEX HEX HEX HEX '-' HEX HEX HEX HEX '-' HEX HEX HEX HEX HEX HEX HEX HEX HEX HEX HEX HEX;
......@@ -24,9 +25,11 @@ DATE: DIGIT DIGIT DIGIT DIGIT '-' DIGIT DIGIT '-' DIGIT DIGIT;
TS: DATE 'T' TIME;
TS_TZ: TS TZ;
GEO_URI: 'geo' ':' LATITUDE ',' LONGITUDE (',' NUMBER)?;
INT: DIGIT+;
NUMBER: ('+' | '-')? (INT | FLOAT);
NUMBER: '-'? (INT | FLOAT);
ID: NameStartChar (NameChar)*;
......@@ -36,6 +39,10 @@ fragment TIME: DIGIT DIGIT ':' DIGIT DIGIT ':' DIGIT DIGIT ('.' DIGIT+)?;
fragment TZ: 'Z' | (('+' | '-') DIGIT DIGIT ':' DIGIT DIGIT);
fragment LATITUDE: '-'? DIGIT DIGIT? ('.' DIGIT+)?;
fragment LONGITUDE: '-'? DIGIT DIGIT? DIGIT? ('.' DIGIT+)?;
fragment FLOAT: DIGIT+ '.' DIGIT+;
fragment
......
......@@ -39,11 +39,12 @@ description: sp '\'' text;
text: ~(NL)*;
txn_meta: indent '#' sp txn_meta_uuid NL;
txn_meta: indent '#' sp (txn_meta_uuid | txn_meta_location) NL;
txn_meta_uuid: UUID_NAME ':' sp UUID_VALUE opt_sp;
txn_meta_location: LOCATION_NAME ':' sp GEO_URI opt_sp;
txn_comment: indent comment NL;
indent: (' '|'\t')+;
......
......@@ -17,6 +17,7 @@
package fi.e257.tackler.parser
import java.time.{LocalDate, LocalDateTime, ZonedDateTime}
import java.util.UUID
import cats.implicits._
......@@ -250,8 +251,10 @@ abstract class CtxHandler {
})
val uuid = Option(txnCtx.txn_meta()).map(meta => {
java.util.UUID.fromString(meta.txn_meta_uuid().UUID_VALUE().getText)
val uuid: Option[UUID] = Option(txnCtx.txn_meta()).flatMap(meta => {
Option(meta.txn_meta_uuid()).map(muuid => {
java.util.UUID.fromString(muuid.UUID_VALUE().getText)
})
})
if (settings.Auditing.txnSetChecksum && uuid.isEmpty) {
......
......@@ -66,7 +66,7 @@ class TacklerParserHeaderDescriptionTest extends FunSpec {
|
|""".stripMargin,
"on line: 2",
"""at input ' +02'"""
"""at input ' +'"""
),
(
"""
......
......@@ -87,7 +87,7 @@ class TacklerParserHeaderTimestampTest extends FunSpec {
|
|""".stripMargin,
"on line: 2",
"""at input '+0200'"""
"""at input '+'"""
),
(
"""
......@@ -117,7 +117,7 @@ class TacklerParserHeaderTimestampTest extends FunSpec {
|
|""".stripMargin,
"on line: 2",
"""at input '+0200'"""
"""at input '+'"""
),
(
"""
......@@ -198,7 +198,7 @@ class TacklerParserHeaderTimestampTest extends FunSpec {
|
|""".stripMargin,
"on line: 2",
"""at input ' +02'"""
"""at input ' +'"""
),
(
"""
......@@ -228,7 +228,7 @@ class TacklerParserHeaderTimestampTest extends FunSpec {
|
|""".stripMargin,
"on line: 2",
"""at input ' +02'"""
"""at input ' +'"""
),
(
"""
......
/*
* Copyright 2019 E257.FI
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package fi.e257.tackler.parser
import fi.e257.tackler.core.Settings
import org.scalatest.FunSpec
class TacklerParserLocationTest extends FunSpec {
val tt = new TacklerTxns(Settings())
describe("Geo URI tests") {
/**
* test:
*
*/
it("pok: geo uris") {
val txnStr =
"""
|2019-04-01
| # location: geo:60.170833,24.9375
| e 1
| a
|
|2019-04-01
| # location: geo:66.5436,25.84715,160
| e 1
| a
|
|2019-04-01
| # location: geo:66.5436,25.84715,160.0
| e 1
| a
|
|2019-04-01
| # location: geo:59.90735,16.57532,-155
| e 1
| a
|
|2019-04-01
| # location: geo:59.90735,16.57532,-155.0
| e 1
| a
|
|2019-04-01
| # location: geo:0,0,0
| e 1
| a
|
|2019-04-01
| # location: geo:-90,0,0
| e 1
| a
|
|2019-04-01
| # location: geo:-90,25,0
| e 1
| a
|
|2019-04-01
| # location: geo:90,0,0
| e 1
| a
|
|2019-04-01
| # location: geo:90,25,0
| e 1
| a
|
|2019-04-01
| # location: geo:66.56,180,0
| e 1
| a
|
|2019-04-01
| # location: geo:-66.56,-180,0
| e 1
| a
|
|""".stripMargin
val txns = tt.string2Txns(txnStr)
assert(txns.txns.size === 12)
}
/**
* test:
*/
it("perr: detect invalid geo uris") {
val perrStrings: List[(String, String, String)] = List(
(
"""
|2017-01-01
| # location:
| e 1
| a
|
|""".stripMargin,
"on line: 3",
s"""at input '"""
),
(
// perr: no 'geo'
"""
|2017-01-01
| # location: 60.170833,24.9375
| e 1
| a
|
|""".stripMargin,
"on line: 3",
s"""at input '"""
),
(
// perr: decimal ','
"""
|2017-01-01
| # location: geo:0.0,0.0,0,0
| e 1
| a
|
|""".stripMargin,
"on line: 3",
"""at input ' '"""
),
(
// perr: missing lat/lon
"""
|2017-01-01
| # location: geo:0
| e 1
| a
|
|""".stripMargin,
"on line: 3",
"""at input 'location'"""
),
(
// perr: latitude out of spec
"""
|2017-01-01
| # location: geo:123,0
| e 1
| a
|
|""".stripMargin,
"on line: 3",
"""at input 'location'"""
),
(
// perr: longitude out of spec
"""
|2017-01-01
| # location: geo:0,1234
| e 1
| a
|
|""".stripMargin,
"on line: 3",
"""at input ' '"""
),
)
val count = perrStrings.map(perrStr => {
val ex = intercept[TacklerParseException]({
val _ = TacklerParser.txnsText(perrStr._1)
})
assert(ex.getMessage.contains(perrStr._2))
assert(ex.getMessage.contains(perrStr._3))
1
}).foldLeft(0)(_ + _)
assert(count === 6)
}
}
}
\ No newline at end of file
......@@ -189,27 +189,28 @@ Anything which wasn't implemented?
Normal, ok-case tests to validate functionality:
* [ ] Parse tests
** [ ] lat, lon
** [ ] lat, lon, alt
*** [ ] lat.deg, lon.deg, alt.deg
** [ ] -lat, -lon, -alt
** [ ] -lat.deg, -lon.deg, -alt.deg
* [x] Parse tests
** [x] lat, lon
** [x] lat, lon, alt
*** [x] lat.deg, lon.deg, alt.deg
** [x] -lat, -lon, -alt
** [x] -lat.deg, -lon.deg, -alt.deg
Various special values
* [ ] Poles
** [ ] lat: -90 or lat:90, lon:0
** [ ] lat: -90 or lat:90, lon:-180 - 0
** [ ] lat: -90 or lat:90, lon:180 - 0
* [ ] lat:0, lon:0
* [ ] lat:Y, lon:X, alt:-120
* [x] Poles
** [x] lat: -90 or lat:90, lon:0
** [x] lat: -90 or lat:90, lon:-180 - 0
** [x] lat: -90 or lat:90, lon:180 - 0
* [x] lat:0, lon:0
* [x] lat:Y, lon:X, alt:-120
==== Errors
Various error cases:
* [ ] e: missing lat/lon
* [x] e: comma (`,`) as decimal separator (especially for altitude (internally using NUMBER at the moment))
* [x] e: missing lat/lon
* [ ] e: Values outside of specification
** [ ] e: lat < -90 || lat > 90
** [ ] e: lon < -180 || lon > 180
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment