Skip to content

Alpha Release #24

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 26 commits into from
Nov 1, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
d445616
Added synk and develop codacy badge to README
bhermann Aug 11, 2018
51b1b70
Bumped akka-http version b/c of CVE-2018-16131
bhermann Sep 17, 2018
a69506c
Added license information
bhermann Oct 28, 2018
b23a74e
Changed Http Client infrastructure from `BlockingHttpClient` to akka …
bhermann Oct 28, 2018
50ebf1d
Added search command
bhermann Oct 28, 2018
4a7a722
Added output beautification (Closes #18)
bhermann Oct 29, 2018
44bad0d
Update README.md
bhermann Oct 29, 2018
07c95a3
Handled empty result sets correctly
bhermann Oct 29, 2018
c80c7ee
Layout configuration
bhermann Oct 29, 2018
9583307
Adjusted expected header in scalastyle file
bhermann Oct 30, 2018
0e36d98
Supressed stylecheck warning for the only place where println is actu…
bhermann Oct 30, 2018
ca92e66
Adjustments for coding style
bhermann Oct 30, 2018
3ac90bd
Removed the need for some list.head calls
bhermann Oct 30, 2018
1692a35
Renaming and error stability
bhermann Oct 30, 2018
e429884
Changed application name
bhermann Oct 30, 2018
5e2efb1
Measure execution time
bhermann Oct 30, 2018
6fe10a8
Changed characters for query output
bhermann Oct 30, 2018
08363b2
Added support for query limit
bhermann Oct 30, 2018
53ea08b
Added color
bhermann Oct 30, 2018
329ea32
Disabled complexity checker
bhermann Oct 30, 2018
50c5e22
Organized and bumped dependencies
bhermann Oct 30, 2018
f6089da
Organized imports
bhermann Oct 30, 2018
b8c291a
Fixed error handling
bhermann Oct 30, 2018
a5fb88a
Adjusted result presentation for the retrieve command
bhermann Oct 31, 2018
944b4b2
Added --list mode. Closes #23
bhermann Oct 31, 2018
f74c0fd
Merge branch 'master' into develop
bhermann Nov 1, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Added search command
Closes #2
  • Loading branch information
bhermann committed Oct 28, 2018
commit 50ebf1d43b6eb8a43f839868a5aa2a030dad73c7
3 changes: 3 additions & 0 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,14 @@ wixProductUpgradeId := "4552fb0e-e257-4dbd-9ecb-dba9dbacf424"
scalastyleConfig := baseDirectory.value / "project" / "scalastyle_config.xml"

libraryDependencies += "com.github.scopt" %% "scopt" % "3.7.0"
libraryDependencies += "io.spray" %% "spray-json" % "1.3.3"
libraryDependencies ++= Seq(
"com.typesafe.akka" %% "akka-http-core" % "10.1.5",
"com.typesafe.akka" %% "akka-http-spray-json" % "10.1.5",
"com.typesafe.akka" %% "akka-stream" % "2.5.12"
)


debianPackageDependencies := Seq("java8-runtime-headless")

lazy val cli = (project in file(".")).
Expand Down
13 changes: 9 additions & 4 deletions src/main/scala/de/upb/cs/swt/delphi/cli/DelphiCLI.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ package de.upb.cs.swt.delphi.cli
import akka.actor.ActorSystem
import akka.http.scaladsl.Http
import akka.stream.ActorMaterializer
import de.upb.cs.swt.delphi.cli.commands.{RetrieveCommand, TestCommand}
import de.upb.cs.swt.delphi.cli.commands.{RetrieveCommand, SearchCommand, TestCommand}

import scala.concurrent.duration.Duration
import scala.concurrent.{Await, ExecutionContext}
Expand Down Expand Up @@ -55,7 +55,11 @@ object DelphiCLI extends App {
"with the filepath given in place of the ID")
)

//cmd("search")
cmd("search").action((s, c) => c.copy(mode = "search"))
.text("Search artifact using a query.")
.children(
arg[String]("query").action((x,c) => c.copy(args = List(x))).text("The query to be used")
)
}
}

Expand All @@ -66,10 +70,11 @@ object DelphiCLI extends App {
config.mode match {
case "test" => TestCommand.execute(config)
case "retrieve" => RetrieveCommand.execute(config)
case _ => println("Unknown command")
case "search" => SearchCommand.execute(config)
case x => println(s"Unknown command: $x")
}

case None => println("nope")
case None =>
}

val poolShutdown = Http().shutdownAllConnectionPools()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// 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.cli.commands

import akka.actor.ActorSystem
import akka.http.scaladsl.Http
import akka.http.scaladsl.marshallers.sprayjson.SprayJsonSupport
import akka.http.scaladsl.marshalling.Marshal
import akka.http.scaladsl.model._
import akka.stream.ActorMaterializer
import akka.util.ByteString
import de.upb.cs.swt.delphi.cli.Config
import spray.json.DefaultJsonProtocol

import scala.concurrent.Await
import scala.concurrent.duration._

object SearchCommand extends Command with SprayJsonSupport with DefaultJsonProtocol {
/**
* Executes the command implementation
*
* @param config The current configuration for the command
*/
override def execute(config: Config)(implicit system: ActorSystem): Unit = {
implicit val ec = system.dispatcher
implicit val materializer = ActorMaterializer()

def query = config.args.head
implicit val queryFormat = jsonFormat2(Query)

val baseUri = Uri(config.server)
val searchUri = baseUri.withPath(baseUri.path + "/search").withQuery(akka.http.scaladsl.model.Uri.Query(Map("pretty"->"")))
val responseFuture = Marshal(Query(query)).to[RequestEntity] flatMap { entity =>
Http().singleRequest(HttpRequest(uri = searchUri, method = HttpMethods.POST, entity = entity))
}

val result = Await.result(responseFuture, 30 seconds)
result match {
case HttpResponse(StatusCodes.OK, headers, entity, _) =>
entity.dataBytes.runFold(ByteString(""))(_ ++ _).foreach { body =>
println(body.utf8String)
}
case resp @ HttpResponse(code, _, _, _) =>
println("Request failed, response code: " + code)
resp.discardEntityBytes()
}
}

case class Query(query : String, pretty : Option[Boolean] = Some(true))
}