Skip to content
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

refactor(formatting-logging): reformat scala code and change logging policy (DEV-839) #2051

Merged
merged 4 commits into from Apr 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .scalafmt.conf
@@ -1,6 +1,6 @@
version = "2.7.5"
maxColumn = 120
align.preset = some
align.preset = most
align.multiline = false
continuationIndent.defnSite = 2
assumeStandardLibraryStripMargin = true
Expand Down
2 changes: 1 addition & 1 deletion build.sbt
Expand Up @@ -138,7 +138,7 @@ lazy val webapi: Project = Project(id = "webapi", base = file("webapi"))
}, // allows sbt-javaagent to work with sbt-revolver
reStart / javaOptions ++= webapiJavaRunOptions,
javaAgents += Dependencies.aspectjweaver,
fork := true, // run tests in a forked JVM
fork := true, // run tests in a forked JVM
Test / testForkedParallel := false, // run forked tests in parallel
Test / parallelExecution := false, // run non-forked tests in parallel
// Global / concurrentRestrictions += Tags.limit(Tags.Test, 1), // restrict the number of concurrently executing tests in all projects
Expand Down
6 changes: 3 additions & 3 deletions dsp-api-main/src/main/scala/dsp/api/main/MainApp.scala
Expand Up @@ -8,10 +8,10 @@ object MainApp extends ZIOAppDefault {
val effect: ZIO[Console with SchemaRepo, Nothing, Unit] =
for {
profile <- SchemaRepo.lookup("user1").orDie
_ <- printLine(profile).orDie
_ <- printLine(42).orDie
_ <- printLine(profile).orDie
_ <- printLine(42).orDie
} yield ()

val mainApp: ZIO[Any, Nothing, Unit] = effect.provide(Console.live ++ SchemaRepoLive.layer)
def run: ZIO[Any, Nothing, Unit] = mainApp
def run: ZIO[Any, Nothing, Unit] = mainApp
}
27 changes: 16 additions & 11 deletions project/plugins.sbt
Expand Up @@ -6,22 +6,27 @@ resolvers ++= Seq(
addDependencyTreePlugin

// Knora
addSbtPlugin("com.typesafe.sbt" % "sbt-git" % "1.0.2")
addSbtPlugin("com.github.sbt" % "sbt-native-packager" % "1.9.9")
addSbtPlugin("io.kamon" % "sbt-aspectj-runner" % "1.1.1")
addSbtPlugin("com.typesafe.sbt" % "sbt-git" % "1.0.2")
addSbtPlugin("com.github.sbt" % "sbt-native-packager" % "1.9.9")
addSbtPlugin("io.kamon" % "sbt-aspectj-runner" % "1.1.1")

// webapi
addSbtPlugin("io.spray" % "sbt-revolver" % "0.9.1")
addSbtPlugin("com.typesafe.sbt" % "sbt-twirl" % "1.5.1")
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.14.10")
addSbtPlugin("com.lightbend.sbt" % "sbt-javaagent" % "0.1.5")
addSbtPlugin("io.gatling" % "gatling-sbt" % "2.2.2")
addSbtPlugin("org.scoverage" % "sbt-scoverage" % "1.6.1")
addSbtPlugin("com.codacy" % "sbt-codacy-coverage" % "1.3.15")
addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % "0.11.0")
addSbtPlugin("io.spray" % "sbt-revolver" % "0.9.1")
addSbtPlugin("com.typesafe.sbt" % "sbt-twirl" % "1.5.1")
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.14.10")
addSbtPlugin("com.lightbend.sbt" % "sbt-javaagent" % "0.1.5")
addSbtPlugin("io.gatling" % "gatling-sbt" % "2.2.2")
addSbtPlugin("org.scoverage" % "sbt-scoverage" % "1.6.1")
addSbtPlugin("com.codacy" % "sbt-codacy-coverage" % "1.3.15")
addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % "0.11.0")

// ad-hoc plugins - uncomment on demenad and keep it commented out in main branch

// https://github.com/rtimush/sbt-updates
// addSbtPlugin("com.timushev.sbt" % "sbt-updates" % "0.6.1")

// https://github.com/cb372/sbt-explicit-dependencies
// addSbtPlugin("com.github.cb372" % "sbt-explicit-dependencies" % "0.2.16")

// https://scalameta.org/scalafmt/docs/installation.html#sbt
// addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.4.6")
Expand Up @@ -7,7 +7,6 @@ import zio.config._
import typesafe._
import magnolia._


final case class AppConfig(cacheService: CacheServiceConfig)

object AppConfig {
Expand Down
Expand Up @@ -23,13 +23,13 @@ object GenerateContributorsFile extends App {

// Configuration

val contributorsUrl = "https://api.github.com/repos/dasch-swiss/knora-api/contributors"
val contributorsUrl = "https://api.github.com/repos/dasch-swiss/knora-api/contributors"
val defaultOutputFile = "Contributors.md"

// Command-line args

private val conf = new GenerateContributorsFileConf(args.toIndexedSeq)
private val token = conf.token.toOption
private val conf = new GenerateContributorsFileConf(args.toIndexedSeq)
private val token = conf.token.toOption
private val outputFile: Path = Paths.get(conf.output())

// Get the list of contributors.
Expand Down
Expand Up @@ -355,7 +355,7 @@ object InconsistentRepositoryDataException {
}

case class MissingLastModificationDateOntologyException(message: String, cause: Option[Throwable] = None)
extends InternalServerException(message, cause)
extends InternalServerException(message, cause)

/**
* Indicates that the API server generated invalid JSON in an API response.
Expand Down
Expand Up @@ -118,13 +118,13 @@ object FeatureToggle {
/**
* The name of the HTTP request header containing feature toggles.
*/
val REQUEST_HEADER: String = "X-Knora-Feature-Toggles"
val REQUEST_HEADER: String = "X-Knora-Feature-Toggles"
val REQUEST_HEADER_LOWERCASE: String = REQUEST_HEADER.toLowerCase

/**
* The name of the HTTP response header that lists configured feature toggles.
*/
val RESPONSE_HEADER: String = REQUEST_HEADER
val RESPONSE_HEADER: String = REQUEST_HEADER
val RESPONSE_HEADER_LOWERCASE: String = REQUEST_HEADER_LOWERCASE

/**
Expand Down Expand Up @@ -369,7 +369,7 @@ class RequestContextFeatureFactoryConfig(requestContext: RequestContext, parent:
headerValueItem.split('=').map(_.trim) match {
case Array(featureNameAndVersionStr: String, isEnabledStr: String) =>
val featureNameAndVersion: Array[String] = featureNameAndVersionStr.split(':').map(_.trim)
val featureName: String = featureNameAndVersion.head
val featureName: String = featureNameAndVersion.head

// Accept the boolean values that are accepted in application.conf.
val isEnabled: Boolean = if (TRUE_STRINGS.contains(isEnabledStr.toLowerCase)) {
Expand Down
Expand Up @@ -110,7 +110,7 @@ object KnoraExceptionHandler extends LazyLogging {

val responseFields: Map[String, JsValue] = Map(
"status" -> JsNumber(apiStatus.id),
"error" -> JsString(makeClientErrorMessage(ex, settings))
"error" -> JsString(makeClientErrorMessage(ex, settings))
) ++ maybeAccess

HttpResponse(
Expand Down
Expand Up @@ -13,39 +13,39 @@ import org.knora.webapi.exceptions._
* Based on `salsah/api/ApiErrors.php`.
*/
object ApiStatusCodesV1 extends Enumeration {
val OK = Value(0)
val INVALID_REQUEST_METHOD = Value(1)
val CREDENTIALS_NOT_VALID = Value(2)
val OK = Value(0)
val INVALID_REQUEST_METHOD = Value(1)
val CREDENTIALS_NOT_VALID = Value(2)
val NO_RIGHTS_FOR_OPERATION = Value(3)
val INTERNAL_SALSAH_ERROR = Value(4)
val NO_PROPERTIES = Value(5)
val NOT_IN_USERDATA = Value(6)
val RESOURCE_ID_MISSING = Value(7)
val UNKNOWN_VOCABULARY = Value(8)
val INTERNAL_SALSAH_ERROR = Value(4)
val NO_PROPERTIES = Value(5)
val NOT_IN_USERDATA = Value(6)
val RESOURCE_ID_MISSING = Value(7)
val UNKNOWN_VOCABULARY = Value(8)

/**
* The requested item was not found. This was called NO_NODES_FOUND in SALSAH; its meaning has been broadened here.
*/
val NOT_FOUND = Value(9)

val API_ENDPOINT_NOT_FOUND = Value(10)
val INVALID_REQUEST_TYPE = Value(11)
val PROPERTY_ID_MISSING = Value(12)
val NOT_YET_IMPLEMENTED = Value(13)
val COULD_NOT_OPEN_PROGRESS_FILE = Value(14)
val API_ENDPOINT_NOT_FOUND = Value(10)
val INVALID_REQUEST_TYPE = Value(11)
val PROPERTY_ID_MISSING = Value(12)
val NOT_YET_IMPLEMENTED = Value(13)
val COULD_NOT_OPEN_PROGRESS_FILE = Value(14)
val VALUE_ID_OR_RESTYPE_ID_MISSING = Value(15)

val HLIST_ALREADY_EXISTENT = Value(16)
val HLIST_NO_LABELS = Value(17)
val HLIST_NOT_EXISTING = Value(18)
val HLIST_NO_POSITION = Value(19)
val HLIST_NO_LABELS = Value(17)
val HLIST_NOT_EXISTING = Value(18)
val HLIST_NO_POSITION = Value(19)
val HLIST_INVALID_POSITION = Value(20)

val SELECTION_NO_LABELS = Value(21)
val SELECTION_ALREADY_EXISTENT = Value(22)
val SELECTION_NO_LABELS = Value(21)
val SELECTION_ALREADY_EXISTENT = Value(22)
val SELECTION_MISSING_OR_INVALID_POSITION = Value(23)
val SELECTION_DELETE_FAILED = Value(24)
val SELECTION_NODE_ALREADY_EXISTENT = Value(25)
val SELECTION_DELETE_FAILED = Value(24)
val SELECTION_NODE_ALREADY_EXISTENT = Value(25)

val GEONAMES_GEONAME_ID_EXISTING = Value(26)

Expand Down
Expand Up @@ -15,9 +15,9 @@ import akka.http.scaladsl.server.Route
*/
object ServerVersion {

private val ApiNameAndVersion = s"${BuildInfo.name}/${BuildInfo.version}"
private val ApiNameAndVersion = s"${BuildInfo.name}/${BuildInfo.version}"
private val AkkaNameAndVersion = s"akka-http/${BuildInfo.akkaHttp}"
private val AllProducts = ApiNameAndVersion + " " + AkkaNameAndVersion
private val AllProducts = ApiNameAndVersion + " " + AkkaNameAndVersion

def serverVersionHeader: Server = Server(products = AllProducts)

Expand Down