Skip to content

Commit f1f9aea

Browse files
committed
Merge remote-tracking branch 'origin/develop' into feature/4/scalastyle
# Conflicts: # build.sbt # project/plugins.sbt
2 parents 993e4a5 + e194b71 commit f1f9aea

File tree

10 files changed

+243
-90
lines changed

10 files changed

+243
-90
lines changed

.travis.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
11
language: scala
22
scala:
3-
- 2.12.4
3+
- 2.12.4
4+
script:
5+
- 'if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then sbt ++$TRAVIS_SCALA_VERSION test; fi'
6+
- 'if [ "$TRAVIS_PULL_REQUEST" = "false" ]; then sbt ++$TRAVIS_SCALA_VERSION coverage test coverageReport coverageAggregate codacyCoverage; fi'
7+
after_success:
8+
- 'if [ "$TRAVIS_PULL_REQUEST" = "false" ]; then bash <(curl -s https://codecov.io/bash); fi'

LICENSE

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -175,18 +175,7 @@
175175

176176
END OF TERMS AND CONDITIONS
177177

178-
APPENDIX: How to apply the Apache License to your work.
179-
180-
To apply the Apache License to your work, attach the following
181-
boilerplate notice, with the fields enclosed by brackets "[]"
182-
replaced with your own identifying information. (Don't include
183-
the brackets!) The text should be enclosed in the appropriate
184-
comment syntax for the file format. We also recommend that a
185-
file or class name and description of purpose be included on the
186-
same "printed page" as the copyright notice for easier
187-
identification within third-party archives.
188-
189-
Copyright [yyyy] [name of copyright owner]
178+
Copyright 2018 The Delphi Team (represented by Ben Hermann)
190179

191180
Licensed under the Apache License, Version 2.0 (the "License");
192181
you may not use this file except in compliance with the License.

build.sbt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,11 @@ libraryDependencies += "com.typesafe.akka" %% "akka-http" % "10.0.11"
99
libraryDependencies += "com.typesafe.akka" %% "akka-stream" % "2.5.12"
1010
libraryDependencies += "com.typesafe.akka" %% "akka-http-spray-json" % "10.1.1"
1111
libraryDependencies += "io.spray" %% "spray-json" % "1.3.3"
12+
libraryDependencies += "org.parboiled" %% "parboiled" % "2.1.4"
13+
libraryDependencies += "org.scalactic" %% "scalactic" % "3.0.4"
14+
libraryDependencies += "org.scalatest" %% "scalatest" % "3.0.4" % "test"
1215

13-
val elastic4sVersion = "6.2.8"
16+
val elastic4sVersion = "6.3.0"
1417
libraryDependencies ++= Seq(
1518
"com.sksamuel.elastic4s" %% "elastic4s-core" % elastic4sVersion,
1619

@@ -39,6 +42,5 @@ lazy val webapi = (project in file(".")).
3942
buildInfoKeys := Seq[BuildInfoKey](name, version, scalaVersion, sbtVersion),
4043
buildInfoPackage := "de.upb.cs.swt.delphi.webapi"
4144
)
42-
scalastyleConfig := baseDirectory.value / "project" / "scalastyle-config.xml"
43-
4445

46+
scalastyleConfig := baseDirectory.value / "project" / "scalastyle_config.xml"

project/buildinfo.sbt

Lines changed: 0 additions & 1 deletion
This file was deleted.

project/plugins.sbt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,13 @@
1+
// build management and packaging
2+
addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % "0.7.0")
13
addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % "1.3.2")
4+
5+
// coverage
6+
addSbtPlugin("org.scoverage" % "sbt-scoverage" % "1.5.1")
7+
addSbtPlugin("com.codacy" % "sbt-codacy-coverage" % "1.3.12")
8+
9+
// preparation for dependency checking
10+
addSbtPlugin("net.virtual-void" % "sbt-dependency-graph" % "0.9.1")
11+
12+
// scalastyle
213
addSbtPlugin("org.scalastyle" %% "scalastyle-sbt-plugin" % "1.0.0")

project/scalastyle-config.xml renamed to project/scalastyle_config.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,4 +114,4 @@
114114
<check level="warning" class="org.scalastyle.scalariform.PublicMethodsHaveTypeChecker" enabled="true"></check>
115115
<check level="warning" class="org.scalastyle.file.NewLineAtEofChecker" enabled="true"></check>
116116
<check level="warning" class="org.scalastyle.file.NoNewLineAtEofChecker" enabled="false"></check>
117-
</scalastyle>
117+
</scalastyle>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package de.upb.cs.swt.delphi.querylanguage
2+
3+
trait CombinatorialExpr
4+
5+
case class AndExpr(Left: CombinatorialExpr, Right: CombinatorialExpr) extends CombinatorialExpr
6+
case class OrExpr(Left: CombinatorialExpr, Right: CombinatorialExpr) extends CombinatorialExpr
7+
case class NotExpr(Expr: CombinatorialExpr) extends CombinatorialExpr
8+
case class XorExpr(Left: CombinatorialExpr, Right: CombinatorialExpr) extends CombinatorialExpr
9+
10+
trait SingularConditionExpr extends CombinatorialExpr
11+
12+
case class EqualExpr(Left: String, Right: String) extends SingularConditionExpr
13+
case class NotEqualExpr(Left: String, Right: String) extends SingularConditionExpr
14+
case class GreaterThanExpr(Left: String, Right: String) extends SingularConditionExpr
15+
case class GreaterOrEqualExpr(Left: String, Right: String) extends SingularConditionExpr
16+
case class LessThanExpr(Left: String, Right: String) extends SingularConditionExpr
17+
case class LessOrEqualExpr(Left: String, Right: String) extends SingularConditionExpr
18+
case class LikeExpr(Left: String, Right: String) extends SingularConditionExpr
19+
case class TrueExpr(Expr: String) extends SingularConditionExpr

src/main/scala/de/upb/cs/swt/delphi/querylanguage/Syntax.scala

Lines changed: 36 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -3,84 +3,55 @@ package de.upb.cs.swt.delphi.querylanguage
33
import org.parboiled2.{CharPredicate, Parser, ParserInput, Rule1}
44

55
/**
6-
* Created by benhermann on 03.02.18.
6+
* The syntax definition and parser for the Delphi QL.
7+
*
8+
* @author Lisa Nguyen Quang Do
9+
* @author Ben Hermann
10+
*
711
*/
812
class Syntax(val input : ParserInput) extends Parser {
913

1014
def QueryRule = rule {
11-
QueryElementRule ~ EOI
15+
CombinatorialRule ~ EOI
1216
}
1317

14-
def QueryElementRule = rule {
15-
FeatureIdentifierRule ~ ConditionRule
18+
// Combinatorial rules.
19+
def CombinatorialRule : Rule1[CombinatorialExpr] = rule {
20+
OrOrElseRule | NotRule
1621
}
17-
18-
def FeatureIdentifierRule = rule {
19-
capture(oneOrMore(CharPredicate.Alpha))
20-
}
21-
22-
def ConditionRule = rule {
23-
SingularConditionRule // | ConjunctionRule | DisjunctionRule
24-
}
25-
26-
def SingularConditionRule = rule {
27-
EqualRule |
28-
NotEqualRule |
29-
GreaterThanRule |
30-
GreaterOrEqual |
31-
LessThan |
32-
LessOrEqual |
33-
Like
22+
def OrOrElseRule = rule {
23+
AndOrElseRule ~ zeroOrMore("||" ~ AndOrElseRule ~> OrExpr)
3424
}
35-
36-
/*
37-
def ConjunctionRule = rule {
38-
ConditionRule ~ "&&" ~ ConditionRule
39-
}
40-
41-
def DisjunctionRule = rule {
42-
ConditionRule ~ "||" ~ ConditionRule
25+
def AndOrElseRule = rule {
26+
XorOrElseRule ~ zeroOrMore("&&" ~ XorOrElseRule ~> AndExpr)
4327
}
44-
*/
45-
46-
def Literal = rule {
47-
NumberLiteral |
48-
StringLiteral
28+
def XorOrElseRule = rule {
29+
Factor ~ zeroOrMore("%%" ~ Factor ~> XorExpr)
4930
}
5031

51-
def StringLiteral = rule {
52-
capture(oneOrMore(CharPredicate.AlphaNum))
32+
// Handling parentheses.
33+
def Factor : Rule1[CombinatorialExpr] = rule {
34+
Parentheses | SingularConditionRule | NotRule
5335
}
36+
def Parentheses = rule { '(' ~ CombinatorialRule ~ ')' }
37+
def NotRule = rule { '!' ~ Factor ~> NotExpr }
5438

55-
def NumberLiteral = rule {
56-
capture(oneOrMore(CharPredicate.Digit))
57-
}
58-
59-
def EqualRule = rule {
60-
"=" ~ Literal
61-
}
62-
def NotEqualRule = rule {
63-
"!=" ~ NumberLiteral
64-
}
65-
def GreaterThanRule = rule {
66-
">" ~ NumberLiteral
67-
}
68-
def GreaterOrEqual = rule {
69-
">=" ~ NumberLiteral
70-
}
71-
72-
def LessThan = rule {
73-
"<" ~ NumberLiteral
74-
}
75-
def LessOrEqual = rule {
76-
"=<" ~ NumberLiteral
77-
}
78-
79-
def Like = rule {
80-
"~" ~ StringLiteral
81-
}
39+
// Singular conditions.
40+
def SingularConditionRule = rule {
41+
EqualRule | NotEqualRule | GreaterThanRule | GreaterOrEqual |
42+
LessThan | LessOrEqual | Like | True
43+
}
44+
def EqualRule = rule { Literal ~ "=" ~ Literal ~> EqualExpr }
45+
def NotEqualRule = rule { Literal ~ "!=" ~ Literal ~> NotEqualExpr }
46+
def GreaterThanRule = rule { Literal ~ ">" ~ Literal ~> GreaterThanExpr }
47+
def GreaterOrEqual = rule { Literal ~ ">=" ~ Literal ~> GreaterOrEqualExpr }
48+
def LessThan = rule { Literal ~ "<" ~ Literal ~> LessThanExpr }
49+
def LessOrEqual = rule { Literal ~ "<=" ~ Literal ~> LessOrEqualExpr }
50+
def Like = rule { Literal ~ "%" ~ Literal ~> LikeExpr }
51+
def True = rule { Literal ~> TrueExpr }
52+
53+
// Literals
54+
def Literal = rule { capture(oneOrMore(CharPredicate.AlphaNum)) ~> (_.toString) }
8255
}
8356

84-
class StringLiteral(value : String) {}
8557

86-
class NumberLiteral(value : Integer) {}

src/main/scala/de/upb/cs/swt/delphi/webapi/ElasticActor.scala

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ package de.upb.cs.swt.delphi.webapi
22

33
import akka.actor.{Actor, ActorLogging, Props}
44
import com.sksamuel.elastic4s.IndexAndType
5+
import com.sksamuel.elastic4s.http.{ElasticClient, RequestFailure, RequestSuccess}
56
import com.sksamuel.elastic4s.http.ElasticDsl._
6-
import com.sksamuel.elastic4s.http.HttpClient
77
import de.upb.cs.swt.delphi.webapi.ElasticActorManager.{Enqueue, Retrieve}
88

99
import scala.concurrent.ExecutionContext
@@ -12,7 +12,7 @@ import scala.concurrent.duration._
1212
class ElasticActor(configuration: Configuration, index: IndexAndType) extends Actor with ActorLogging{
1313

1414
implicit val executionContext: ExecutionContext = context.system.dispatchers.lookup("elasticsearch-handling-dispatcher")
15-
val client = HttpClient(configuration.elasticsearchClientUri)
15+
val client = ElasticClient(configuration.elasticsearchClientUri)
1616

1717
override def preStart(): Unit = log.info("Search actor started")
1818
override def postStop(): Unit = log.info("Search actor shut down")
@@ -25,11 +25,16 @@ class ElasticActor(configuration: Configuration, index: IndexAndType) extends Ac
2525

2626
private def getSource(id: String) = {
2727
log.info("Executing get on entry {}", id)
28-
def source = client.execute{
29-
get(id).from(index)
30-
}.await match {
31-
case Right(res) => res.body.get
32-
case Left(_) => Option.empty
28+
def queryResponse = client.execute{
29+
log.info(s"Got retrieve request for $id.")
30+
searchWithType(index) query must (
31+
matchQuery("name", s"http://repo1.maven.org/maven2/:$id")
32+
)
33+
}.await
34+
35+
val source = queryResponse match {
36+
case results: RequestSuccess[_] => results.body.get
37+
case failure: RequestFailure => Option.empty
3338
}
3439
sender().tell(source, context.self)
3540
}

0 commit comments

Comments
 (0)