From 37b6313fb50c9244f9de0ae2483861be9a6b15c4 Mon Sep 17 00:00:00 2001 From: Ben Hermann Date: Mon, 30 Dec 2019 12:14:27 +0100 Subject: [PATCH 1/2] Integrated core library --- build.sbt | 1 + .../delphi/webapi/search/SearchQuery.scala | 3 +- .../webapi/search/querylanguage/AST.scala | 36 ---- .../webapi/search/querylanguage/Syntax.scala | 74 -------- .../search/querylanguage/SyntaxTest.scala | 176 ------------------ 5 files changed, 2 insertions(+), 288 deletions(-) delete mode 100644 src/main/scala/de/upb/cs/swt/delphi/webapi/search/querylanguage/AST.scala delete mode 100644 src/main/scala/de/upb/cs/swt/delphi/webapi/search/querylanguage/Syntax.scala delete mode 100644 src/test/scala/de/upb/cs/swt/delphi/webapi/search/querylanguage/SyntaxTest.scala diff --git a/build.sbt b/build.sbt index f4aecbb..4ae14e3 100644 --- a/build.sbt +++ b/build.sbt @@ -27,6 +27,7 @@ libraryDependencies ++= Seq( "com.sksamuel.elastic4s" %% "elastic4s-http-streams" % elastic4sVersion, ) +libraryDependencies += "de.upb.cs.swt.delphi" %% "delphi-core" % "0.9.0" libraryDependencies += "com.pauldijou" %% "jwt-core" % "4.2.0" diff --git a/src/main/scala/de/upb/cs/swt/delphi/webapi/search/SearchQuery.scala b/src/main/scala/de/upb/cs/swt/delphi/webapi/search/SearchQuery.scala index 3fbd09d..733f8bb 100644 --- a/src/main/scala/de/upb/cs/swt/delphi/webapi/search/SearchQuery.scala +++ b/src/main/scala/de/upb/cs/swt/delphi/webapi/search/SearchQuery.scala @@ -20,14 +20,13 @@ import com.sksamuel.elastic4s.http.ElasticDsl._ import com.sksamuel.elastic4s.http.search.SearchHits import com.sksamuel.elastic4s.http.{ElasticClient, RequestFailure, RequestSuccess} import com.sksamuel.elastic4s.searches.queries.{NoopQuery, Query} +import de.upb.cs.swt.delphi.core.ql._ import de.upb.cs.swt.delphi.webapi.artifacts.{Artifact, ArtifactTransformer} -import de.upb.cs.swt.delphi.webapi.search.querylanguage._ import de.upb.cs.swt.delphi.webapi.{Configuration, Feature, FeatureQuery, InternalFeature} import spray.json.JsArray import scala.io.Source import scala.util.{Failure, Success, Try} - import spray.json._ import de.upb.cs.swt.delphi.webapi.FeatureJson._ diff --git a/src/main/scala/de/upb/cs/swt/delphi/webapi/search/querylanguage/AST.scala b/src/main/scala/de/upb/cs/swt/delphi/webapi/search/querylanguage/AST.scala deleted file mode 100644 index ccece70..0000000 --- a/src/main/scala/de/upb/cs/swt/delphi/webapi/search/querylanguage/AST.scala +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright (C) 2018 The Delphi Team. -// See the LICENCE file distributed with this work for additional -// information regarding copyright ownership. -// -// 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 de.upb.cs.swt.delphi.webapi.search.querylanguage - -trait CombinatorialExpr - -case class AndExpr(left: CombinatorialExpr, right: CombinatorialExpr) extends CombinatorialExpr -case class OrExpr(left: CombinatorialExpr, right: CombinatorialExpr) extends CombinatorialExpr -case class NotExpr(expr: CombinatorialExpr) extends CombinatorialExpr -case class XorExpr(left: CombinatorialExpr, right: CombinatorialExpr) extends CombinatorialExpr - -trait SingularConditionExpr extends CombinatorialExpr - -case class EqualExpr(left: FieldReference, right: String) extends SingularConditionExpr -case class NotEqualExpr(left: FieldReference, right: String) extends SingularConditionExpr -case class GreaterThanExpr(left: FieldReference, right: String) extends SingularConditionExpr -case class GreaterOrEqualExpr(left: FieldReference, right: String) extends SingularConditionExpr -case class LessThanExpr(left: FieldReference, right: String) extends SingularConditionExpr -case class LessOrEqualExpr(left: FieldReference, right: String) extends SingularConditionExpr -case class LikeExpr(left: FieldReference, right: String) extends SingularConditionExpr -case class IsTrueExpr(fieldName: FieldReference) extends SingularConditionExpr -case class FieldReference(fieldName: String) extends CombinatorialExpr \ No newline at end of file diff --git a/src/main/scala/de/upb/cs/swt/delphi/webapi/search/querylanguage/Syntax.scala b/src/main/scala/de/upb/cs/swt/delphi/webapi/search/querylanguage/Syntax.scala deleted file mode 100644 index 389d05d..0000000 --- a/src/main/scala/de/upb/cs/swt/delphi/webapi/search/querylanguage/Syntax.scala +++ /dev/null @@ -1,74 +0,0 @@ -// Copyright (C) 2018 The Delphi Team. -// See the LICENCE file distributed with this work for additional -// information regarding copyright ownership. -// -// 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 de.upb.cs.swt.delphi.webapi.search.querylanguage - -import org.parboiled2.{CharPredicate, Parser, ParserInput, Rule1} - -/** - * The syntax definition and parser for the Delphi QL. - * - * @author Lisa Nguyen Quang Do - * @author Ben Hermann - * - */ -class Syntax(val input : ParserInput) extends Parser { - - def QueryRule = rule { - CombinatorialRule ~ EOI - } - - // Combinatorial rules. - def CombinatorialRule : Rule1[CombinatorialExpr] = rule { - OrOrElseRule | NotRule - } - def OrOrElseRule = rule { - AndOrElseRule ~ zeroOrMore("||" ~ AndOrElseRule ~> OrExpr) - } - def AndOrElseRule = rule { - XorOrElseRule ~ zeroOrMore("&&" ~ XorOrElseRule ~> AndExpr) - } - def XorOrElseRule = rule { - Factor ~ zeroOrMore("%%" ~ Factor ~> XorExpr) - } - - // Handling parentheses. - def Factor : Rule1[CombinatorialExpr] = rule { - Parentheses | SingularConditionRule | NotRule - } - def Parentheses = rule { '(' ~ CombinatorialRule ~ ')' } - def NotRule = rule { '!' ~ Factor ~> NotExpr } - - // Singular conditions. - def SingularConditionRule = rule { - EqualRule | NotEqualRule | GreaterThanRule | GreaterOrEqual | - LessThan | LessOrEqual | Like | IsTrue - } - def EqualRule = rule { FieldReferenceRule ~ "=" ~ Literal ~> EqualExpr } - def NotEqualRule = rule { FieldReferenceRule ~ "!=" ~ Literal ~> NotEqualExpr } - def GreaterThanRule = rule { FieldReferenceRule ~ ">" ~ Literal ~> GreaterThanExpr } - def GreaterOrEqual = rule { FieldReferenceRule ~ ">=" ~ Literal ~> GreaterOrEqualExpr } - def LessThan = rule { FieldReferenceRule ~ "<" ~ Literal ~> LessThanExpr } - def LessOrEqual = rule { FieldReferenceRule ~ "<=" ~ Literal ~> LessOrEqualExpr } - def Like = rule { FieldReferenceRule ~ "%" ~ Literal ~> LikeExpr } - def IsTrue = rule { FieldReferenceRule ~> IsTrueExpr } - - // Literals - def FieldReferenceRule = rule { "[" ~ capture(oneOrMore(CharPredicate.AlphaNum ++ '.' ++ '-' ++ ' ' ++ '_' ++ '(' ++ ':' ++')')) ~ "]" ~> FieldReference } - def Literal = rule { capture(oneOrMore(CharPredicate.AlphaNum)) ~> (_.toString) } -} - - diff --git a/src/test/scala/de/upb/cs/swt/delphi/webapi/search/querylanguage/SyntaxTest.scala b/src/test/scala/de/upb/cs/swt/delphi/webapi/search/querylanguage/SyntaxTest.scala deleted file mode 100644 index 94a79d0..0000000 --- a/src/test/scala/de/upb/cs/swt/delphi/webapi/search/querylanguage/SyntaxTest.scala +++ /dev/null @@ -1,176 +0,0 @@ -// Copyright (C) 2018 The Delphi Team. -// See the LICENCE file distributed with this work for additional -// information regarding copyright ownership. -// -// 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 de.upb.cs.swt.delphi.webapi.search.querylanguage - -import org.scalatest.{FlatSpec, Matchers} -import scala.util.{Failure, Success} - -/** - * Tests for the DelphiQL syntax. - * - * @author Lisa Nguyen Quang Do - */ -class SyntaxTest extends FlatSpec with Matchers { - - "Syntax.singularConditionWithOperator" should "be valid" in { - val parseResult = new Syntax("[Filter1]=abc").QueryRule.run() - parseResult shouldBe a [Success[_]] - parseResult match { - case Success(ast) => { - ast.toString shouldEqual "EqualExpr(FieldReference(Filter1),abc)" - } - } - } - - - "Syntax.singularConditionNoOperator" should "be valid" in { - val parseResult = new Syntax("[Filter1]").QueryRule.run() - parseResult shouldBe a [Success[_]] - parseResult match { - case Success(ast) => { - ast.toString shouldEqual "IsTrueExpr(FieldReference(Filter1))" - } - } - } - - - "Syntax.singularConditionTypo" should "be valid" in { - val parseResult = new Syntax("[Filter1]=<3").QueryRule.run() - parseResult shouldBe a [Failure[_]] - } - - "Syntax.singularConditionOddCharacters" should "be valid" in { - val parseResult = new Syntax("[Filter1]%[Filter2]%'}.:").QueryRule.run() - parseResult shouldBe a [Failure[_]] - } - - - "Syntax.combinatoryConditionSimple" should "be valid" in { - val parseResult = new Syntax("[Filter1]&&[Filter2]=3").QueryRule.run() - parseResult shouldBe a [Success[_]] - parseResult match { - case Success(ast) => { - ast.toString shouldEqual "AndExpr(IsTrueExpr(FieldReference(Filter1)),EqualExpr(FieldReference(Filter2),3))" - } - } - } - - - "Syntax.combinatoryConditionParentheses" should "be valid" in { - val parseResult = new Syntax("[Filter1]||([Filter2]&&([Filter3]<3||[Filter4]>0))").QueryRule.run() - parseResult shouldBe a [Success[_]] - parseResult match { - case Success(ast) => { - ast.toString shouldEqual "OrExpr(IsTrueExpr(FieldReference(Filter1)),AndExpr(IsTrueExpr(FieldReference(Filter2))," + - "OrExpr(LessThanExpr(FieldReference(Filter3),3),GreaterThanExpr(FieldReference(Filter4),0))))" - } - } - } - - - "Syntax.combinatoryConditionParenthesesComplex" should "be valid" in { - val parseResult = new Syntax("[Filter1]&&(([Filter2]<3||[Filter2]>0)%%([Filter4]&&[Filter5]))").QueryRule.run() - parseResult shouldBe a [Success[_]] - parseResult match { - case Success(ast) => { - ast.toString shouldEqual "AndExpr(IsTrueExpr(FieldReference(Filter1)),XorExpr(OrExpr(LessThanExpr(FieldReference(Filter2),3)," + - "GreaterThanExpr(FieldReference(Filter2),0)),AndExpr(IsTrueExpr(FieldReference(Filter4)),IsTrueExpr(FieldReference(Filter5)))))" - } - } - } - - - "Syntax.combinatoryConditionNonMatchingParentheses" should "be valid" in { - val parseResult = new Syntax("[Filter1]&&([Filter2]<3||[Filter2]>0%%([Filter4])").QueryRule.run() - parseResult shouldBe a [Failure[_]] - } - - "Syntax.combinatoryConditionTypo" should "be valid" in { - val parseResult = new Syntax("[Filter1]&[Filter2]<3)").QueryRule.run() - parseResult shouldBe a [Failure[_]] - } - - "Syntax.combinatoryConditionLeftToRightPriority" should "be valid" in { - val parseResult = new Syntax("[Filter1]&&[Filter2]&&[Filter3]").QueryRule.run() - parseResult shouldBe a [Success[_]] - parseResult match { - case Success(ast) => { - ast.toString shouldEqual "AndExpr(AndExpr(IsTrueExpr(FieldReference(Filter1))," + - "IsTrueExpr(FieldReference(Filter2))),IsTrueExpr(FieldReference(Filter3)))" - } - } - } - - "Syntax.combinatoryConditionOperatorPriorities" should "be valid" in { - val parseResult = new Syntax("[Filter1]||[Filter2]%%![Filter3]&&[Filter4]").QueryRule.run() - parseResult shouldBe a [Success[_]] - parseResult match { - case Success(ast) => { - ast.toString shouldEqual "OrExpr(IsTrueExpr(FieldReference(Filter1)),AndExpr(XorExpr(" + - "IsTrueExpr(FieldReference(Filter2)),NotExpr(IsTrueExpr(FieldReference(Filter3)))),IsTrueExpr(FieldReference(Filter4))))" - } - } - } - - - "Syntax.combinatoryConditionOperatorPrioritiesParentheses" should "be valid" in { - val parseResult = new Syntax("([Filter1]||[Filter2])&&![Filter3]%%!([Filter4]&&[Filter5])").QueryRule.run() - parseResult shouldBe a [Success[_]] - parseResult match { - case Success(ast) => { - ast.toString shouldEqual "AndExpr(OrExpr(IsTrueExpr(FieldReference(Filter1)),IsTrueExpr(FieldReference(Filter2)))," + - "XorExpr(NotExpr(IsTrueExpr(FieldReference(Filter3))),NotExpr(AndExpr(IsTrueExpr(FieldReference(Filter4))," + - "IsTrueExpr(FieldReference(Filter5))))))" - } - } - } - - - "Syntax.notConditionSimple" should "be valid" in { - val parseResult = new Syntax("![Filter1]&&!([Filter2])").QueryRule.run() - parseResult shouldBe a [Success[_]] - parseResult match { - case Success(ast) => { - ast.toString shouldEqual "AndExpr(NotExpr(IsTrueExpr(FieldReference(Filter1)))," + - "NotExpr(IsTrueExpr(FieldReference(Filter2))))" - } - } - } - - "Syntax.notConditionSimpleParentheses" should "be valid" in { - val parseResult = new Syntax("!([Filter1]&&![Filter2])").QueryRule.run() - parseResult shouldBe a [Success[_]] - parseResult match { - case Success(ast) => { - ast.toString shouldEqual "NotExpr(AndExpr(IsTrueExpr(FieldReference(Filter1))," + - "NotExpr(IsTrueExpr(FieldReference(Filter2)))))" - } - } - } - - "Syntax.notConditionComplex" should "be valid" in { - val parseResult = new Syntax("!!([Filter1])&&!([Filter2]<=0||!([Filter3]&&![Filter4]%abc))").QueryRule.run() - parseResult shouldBe a [Success[_]] - parseResult match { - case Success(ast) => { - ast.toString shouldEqual "AndExpr(NotExpr(NotExpr(IsTrueExpr(FieldReference(Filter1))))," + - "NotExpr(OrExpr(LessOrEqualExpr(FieldReference(Filter2),0),NotExpr(AndExpr(IsTrueExpr(FieldReference(Filter3))," + - "NotExpr(LikeExpr(FieldReference(Filter4),abc)))))))" - } - } - } -} \ No newline at end of file From 623fdd3c11eaac2d3df5bdd1fe84277c07c52499 Mon Sep 17 00:00:00 2001 From: Ben Hermann Date: Mon, 30 Dec 2019 12:27:42 +0100 Subject: [PATCH 2/2] Migrated to core models --- .../cs/swt/delphi/webapi/DelphiRoutes.scala | 4 +- .../swt/delphi/webapi/MavenIdentifier.scala | 62 ------------------- .../cs/swt/delphi/webapi/RetrieveQuery.scala | 3 +- .../delphi/webapi/artifacts/Artifact.scala | 19 ------ .../webapi/artifacts/ArtifactJson.scala | 46 -------------- .../webapi/artifacts/ArtifactMetadata.scala | 21 ------- .../artifacts/ArtifactTransformer.scala | 2 +- .../delphi/webapi/artifacts/Identifier.scala | 22 ------- .../delphi/webapi/search/SearchQuery.scala | 3 +- .../webapi/MavenIdentifierApplyTest.scala | 61 ------------------ 10 files changed, 7 insertions(+), 236 deletions(-) delete mode 100644 src/main/scala/de/upb/cs/swt/delphi/webapi/MavenIdentifier.scala delete mode 100644 src/main/scala/de/upb/cs/swt/delphi/webapi/artifacts/Artifact.scala delete mode 100644 src/main/scala/de/upb/cs/swt/delphi/webapi/artifacts/ArtifactJson.scala delete mode 100644 src/main/scala/de/upb/cs/swt/delphi/webapi/artifacts/ArtifactMetadata.scala delete mode 100644 src/main/scala/de/upb/cs/swt/delphi/webapi/artifacts/Identifier.scala delete mode 100644 src/test/scala/de/upb/cs/swt/delphi/webapi/MavenIdentifierApplyTest.scala diff --git a/src/main/scala/de/upb/cs/swt/delphi/webapi/DelphiRoutes.scala b/src/main/scala/de/upb/cs/swt/delphi/webapi/DelphiRoutes.scala index b8af861..1808a22 100644 --- a/src/main/scala/de/upb/cs/swt/delphi/webapi/DelphiRoutes.scala +++ b/src/main/scala/de/upb/cs/swt/delphi/webapi/DelphiRoutes.scala @@ -23,11 +23,11 @@ import akka.http.scaladsl.server.Directives._ import akka.http.scaladsl.server.Route import akka.pattern.ask import akka.stream.scaladsl.Source +import de.upb.cs.swt.delphi.core.model.ArtifactJson._ +import de.upb.cs.swt.delphi.webapi.FeatureJson._ import de.upb.cs.swt.delphi.webapi.IpLogActor._ import de.upb.cs.swt.delphi.webapi.StatisticsJson._ -import de.upb.cs.swt.delphi.webapi.artifacts.ArtifactJson._ import de.upb.cs.swt.delphi.webapi.search.QueryRequestJson._ -import de.upb.cs.swt.delphi.webapi.FeatureJson._ import de.upb.cs.swt.delphi.webapi.search.{QueryRequest, SearchError, SearchQuery} import spray.json._ diff --git a/src/main/scala/de/upb/cs/swt/delphi/webapi/MavenIdentifier.scala b/src/main/scala/de/upb/cs/swt/delphi/webapi/MavenIdentifier.scala deleted file mode 100644 index 81be0c1..0000000 --- a/src/main/scala/de/upb/cs/swt/delphi/webapi/MavenIdentifier.scala +++ /dev/null @@ -1,62 +0,0 @@ -// Copyright (C) 2018 The Delphi Team. -// See the LICENCE file distributed with this work for additional -// information regarding copyright ownership. -// -// 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 de.upb.cs.swt.delphi.webapi - -import java.net.{URI, URLEncoder} -import java.nio.charset.StandardCharsets - -import de.upb.cs.swt.delphi.webapi.artifacts.Identifier - -case class MavenIdentifier(val repository: Option[String], val groupId: String, val artifactId: String, val version: Option[String]) extends Identifier { - - def toUniqueString: String = { - repository.getOrElse(MavenIdentifier.DefaultRepository) + ":" + groupId + ":" + artifactId + ":" + version.getOrElse("") - } - - override val toString: String = groupId + ":" + artifactId + ":" + version - - def toJarLocation : URI = { - constructArtifactBaseUri().resolve(encode(artifactId) + "-" + encode(version.getOrElse("")) + ".jar") - } - - def toPomLocation : URI = { - constructArtifactBaseUri().resolve(encode(artifactId) + "-" + encode(version.getOrElse("")) + ".pom") - } - - private def constructArtifactBaseUri(): URI = - new URI(repository.getOrElse(MavenIdentifier.DefaultRepository)) - .resolve(encode(groupId).replace('.', '/') + "/") - .resolve(encode(artifactId) + "/") - .resolve(encode(version.getOrElse("")) + "/") - - private def encode(input : String) : String = - URLEncoder.encode(input, StandardCharsets.UTF_8.toString()) -} - -object MavenIdentifier { - private val DefaultRepository = "http://repo1.maven.org/maven2/" - - private implicit def wrapOption[A](value : A) : Option[A] = Some(value) - - def apply(s: String): Option[MavenIdentifier] = { - val splitString: Array[String] = s.split(':') - if (splitString.length < 2 || splitString.length > 3) return None - - MavenIdentifier(None, splitString(0), splitString(1), if (splitString.length < 3) None else splitString(2)) - - } -} \ No newline at end of file diff --git a/src/main/scala/de/upb/cs/swt/delphi/webapi/RetrieveQuery.scala b/src/main/scala/de/upb/cs/swt/delphi/webapi/RetrieveQuery.scala index 6c8a942..ccc44f9 100644 --- a/src/main/scala/de/upb/cs/swt/delphi/webapi/RetrieveQuery.scala +++ b/src/main/scala/de/upb/cs/swt/delphi/webapi/RetrieveQuery.scala @@ -19,7 +19,8 @@ package de.upb.cs.swt.delphi.webapi import com.sksamuel.elastic4s.http.ElasticDsl._ import com.sksamuel.elastic4s.http.get.GetResponse import com.sksamuel.elastic4s.http.{ElasticClient, RequestSuccess, Response} -import de.upb.cs.swt.delphi.webapi.artifacts.{Artifact, ArtifactTransformer} +import de.upb.cs.swt.delphi.core.model._ +import de.upb.cs.swt.delphi.webapi.artifacts.ArtifactTransformer object RetrieveQuery { diff --git a/src/main/scala/de/upb/cs/swt/delphi/webapi/artifacts/Artifact.scala b/src/main/scala/de/upb/cs/swt/delphi/webapi/artifacts/Artifact.scala deleted file mode 100644 index 265409b..0000000 --- a/src/main/scala/de/upb/cs/swt/delphi/webapi/artifacts/Artifact.scala +++ /dev/null @@ -1,19 +0,0 @@ -// Copyright (C) 2018 The Delphi Team. -// See the LICENCE file distributed with this work for additional -// information regarding copyright ownership. -// -// 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 de.upb.cs.swt.delphi.webapi.artifacts - -case class Artifact(id: String, metadata: ArtifactMetadata, metricResults: Map[String, Int]) diff --git a/src/main/scala/de/upb/cs/swt/delphi/webapi/artifacts/ArtifactJson.scala b/src/main/scala/de/upb/cs/swt/delphi/webapi/artifacts/ArtifactJson.scala deleted file mode 100644 index 617815c..0000000 --- a/src/main/scala/de/upb/cs/swt/delphi/webapi/artifacts/ArtifactJson.scala +++ /dev/null @@ -1,46 +0,0 @@ -// Copyright (C) 2018 The Delphi Team. -// See the LICENCE file distributed with this work for additional -// information regarding copyright ownership. -// -// 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 de.upb.cs.swt.delphi.webapi.artifacts - -import org.joda.time.DateTime -import org.joda.time.format.{DateTimeFormatter, ISODateTimeFormat} -import spray.json.{DefaultJsonProtocol, DeserializationException, JsString, JsValue, RootJsonFormat} - -object ArtifactJson extends DefaultJsonProtocol { - - implicit object DateJsonFormat extends RootJsonFormat[DateTime] { - - private val parserISO: DateTimeFormatter = ISODateTimeFormat.dateTime() - - override def write(obj: DateTime) = JsString(parserISO.print(obj)) - - override def read(json: JsValue): DateTime = json match { - case JsString(s) => parserISO.parseDateTime(s) - case _ => throw new DeserializationException("Error info you want here ...") - } - } - - implicit val artifactMetadataFormat = jsonFormat5(ArtifactMetadata) - implicit val artifactFormat = jsonFormat3(Artifact) - - def prettyPrint(pretty: Option[_], value: JsValue): String = { - pretty.isDefined match { - case true => value.sortedPrint - case false => value.compactPrint - } - } -} diff --git a/src/main/scala/de/upb/cs/swt/delphi/webapi/artifacts/ArtifactMetadata.scala b/src/main/scala/de/upb/cs/swt/delphi/webapi/artifacts/ArtifactMetadata.scala deleted file mode 100644 index f35dbfb..0000000 --- a/src/main/scala/de/upb/cs/swt/delphi/webapi/artifacts/ArtifactMetadata.scala +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright (C) 2018 The Delphi Team. -// See the LICENCE file distributed with this work for additional -// information regarding copyright ownership. -// -// 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 de.upb.cs.swt.delphi.webapi.artifacts - -import org.joda.time.DateTime - -case class ArtifactMetadata(source: String, discovered: DateTime, groupId: String, artifactId: String, version: String) diff --git a/src/main/scala/de/upb/cs/swt/delphi/webapi/artifacts/ArtifactTransformer.scala b/src/main/scala/de/upb/cs/swt/delphi/webapi/artifacts/ArtifactTransformer.scala index 2533c0d..54ab99c 100644 --- a/src/main/scala/de/upb/cs/swt/delphi/webapi/artifacts/ArtifactTransformer.scala +++ b/src/main/scala/de/upb/cs/swt/delphi/webapi/artifacts/ArtifactTransformer.scala @@ -17,12 +17,12 @@ package de.upb.cs.swt.delphi.webapi.artifacts import com.sksamuel.elastic4s.http.search.{SearchHit, SearchHits} +import de.upb.cs.swt.delphi.core.model._ import de.upb.cs.swt.delphi.webapi.InternalFeature import org.joda.time.format.ISODateTimeFormat import spray.json.JsArray import scala.io.Source - import spray.json._ import de.upb.cs.swt.delphi.webapi.FeatureJson._ diff --git a/src/main/scala/de/upb/cs/swt/delphi/webapi/artifacts/Identifier.scala b/src/main/scala/de/upb/cs/swt/delphi/webapi/artifacts/Identifier.scala deleted file mode 100644 index ed419b3..0000000 --- a/src/main/scala/de/upb/cs/swt/delphi/webapi/artifacts/Identifier.scala +++ /dev/null @@ -1,22 +0,0 @@ -// Copyright (C) 2018 The Delphi Team. -// See the LICENCE file distributed with this work for additional -// information regarding copyright ownership. -// -// 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 de.upb.cs.swt.delphi.webapi.artifacts - -/** - * Represents an identifier for a software artifact - */ -trait Identifier diff --git a/src/main/scala/de/upb/cs/swt/delphi/webapi/search/SearchQuery.scala b/src/main/scala/de/upb/cs/swt/delphi/webapi/search/SearchQuery.scala index 733f8bb..a9fd383 100644 --- a/src/main/scala/de/upb/cs/swt/delphi/webapi/search/SearchQuery.scala +++ b/src/main/scala/de/upb/cs/swt/delphi/webapi/search/SearchQuery.scala @@ -20,8 +20,9 @@ import com.sksamuel.elastic4s.http.ElasticDsl._ import com.sksamuel.elastic4s.http.search.SearchHits import com.sksamuel.elastic4s.http.{ElasticClient, RequestFailure, RequestSuccess} import com.sksamuel.elastic4s.searches.queries.{NoopQuery, Query} +import de.upb.cs.swt.delphi.core.model._ import de.upb.cs.swt.delphi.core.ql._ -import de.upb.cs.swt.delphi.webapi.artifacts.{Artifact, ArtifactTransformer} +import de.upb.cs.swt.delphi.webapi.artifacts.ArtifactTransformer import de.upb.cs.swt.delphi.webapi.{Configuration, Feature, FeatureQuery, InternalFeature} import spray.json.JsArray diff --git a/src/test/scala/de/upb/cs/swt/delphi/webapi/MavenIdentifierApplyTest.scala b/src/test/scala/de/upb/cs/swt/delphi/webapi/MavenIdentifierApplyTest.scala deleted file mode 100644 index ae55a7c..0000000 --- a/src/test/scala/de/upb/cs/swt/delphi/webapi/MavenIdentifierApplyTest.scala +++ /dev/null @@ -1,61 +0,0 @@ -// Copyright (C) 2018 The Delphi Team. -// See the LICENCE file distributed with this work for additional -// information regarding copyright ownership. -// -// 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 de.upb.cs.swt.delphi.webapi - -import org.scalatest.{FlatSpec, Matchers} - -class MavenIdentifierApplyTest extends FlatSpec with Matchers { - "Valid identifiers with version" should "convert nicely" in { - val fullIdentifier = MavenIdentifier("log4j:log4j-test:1.4.2") - fullIdentifier match { - case Some(m) => { - m.repository.isDefined shouldBe false - m.groupId shouldBe "log4j" - m.artifactId shouldBe "log4j-test" - m.version.isDefined shouldBe true - m.version.getOrElse("") shouldBe "1.4.2" - } - case _ => fail("Identifier could not be properly parsed.") - } - } - "Valid identifiers without version" should "convert nicely" in { - val partial = MavenIdentifier("log4j:log4j-test") - partial match { - case Some(m) => { - m.repository.isDefined shouldBe false - m.groupId shouldBe "log4j" - m.artifactId shouldBe "log4j-test" - m.version.isDefined shouldBe false - } - case _ => fail("Identifier could not be properly parsed.") - } - } - - "Invalid identifiers" should "fail" in { - val invalid = MavenIdentifier("log4j") - invalid.isDefined shouldBe false - - val invalid2 = MavenIdentifier("log4j:::") - invalid2.isDefined shouldBe false - - val invalid3 = MavenIdentifier("log4j::") - invalid3.isDefined shouldBe false - - val invalid4 = MavenIdentifier("") - invalid4.isDefined shouldBe false - } -}