Skip to content

Commit

Permalink
Merge pull request #44 from mbari-org/feature/query
Browse files Browse the repository at this point in the history
Feature/query
  • Loading branch information
hohonuuli authored Oct 22, 2024
2 parents 22d8b29 + d9e40b1 commit ae39e2c
Show file tree
Hide file tree
Showing 189 changed files with 3,789 additions and 3,274 deletions.
9 changes: 9 additions & 0 deletions .scalafix.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
rules = [
OrganizeImports
]
OrganizeImports {
expandRelative = true
groupedImports = Merge
}
OrganizeImports.targetDialect = Scala3
OrganizeImports.removeUnused = true
21 changes: 16 additions & 5 deletions .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -1,14 +1,25 @@
version = "3.7.14"
version = "3.8.0"
runner.dialect = scala3

align.preset = most
docstrings.style = Asterisk
includeNoParensInSelectChains = true
indent.main = 4
indent.callSite = 4
maxColumn = 100
# Recommended, to not penalize `match` statements
# indent.matchSite = 0
maxColumn = 120
newlines.alwaysBeforeElseAfterCurlyIf = true

rewrite.rules = [
PreferCurlyFors,
RedundantParens,
RedundantParens,
SortModifiers,
SortImports
Imports
]
runner.dialect = scala3

rewrite.imports.expand = false
rewrite.imports.sort = original
rewrite.scala3.convertToNewSyntax = true
# rewrite.scala3.insertEndMarkerMinLines = 5
rewrite.scala3.removeOptionalBraces = yes
3 changes: 3 additions & 0 deletions annosaurus/src/main/resources/reference.conf
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ database {
url = ${?DATABASE_URL}
user = "sa"
user = ${?DATABASE_USER}

query.view = ${?DATABASE_QUERY_VIEW}
query.view = "annotations"
# name = "Derby"
# name = ${?DATABASE_NAME}
# https://docs.jboss.org/hibernate/orm/4.3/manual/en-US/html_single/#configuration-optional-dialects
Expand Down
48 changes: 36 additions & 12 deletions annosaurus/src/main/scala/org/mbari/annosaurus/AppConfig.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,22 @@
package org.mbari.annosaurus

import com.typesafe.config.ConfigFactory
import org.mbari.annosaurus.etc.jdk.Logging
import org.mbari.annosaurus.etc.jdk.Logging.{*, given}
import org.mbari.annosaurus.etc.jdk.Loggers
import org.mbari.annosaurus.etc.jdk.Loggers.{*, given}
import org.mbari.annosaurus.etc.jwt.JwtService

import scala.util.Try
import scala.util.control.NonFatal

object AppConfig {
object AppConfig:

private val log = Logging(getClass)
private val log = Loggers(getClass)

val Name: String = "annosaurus"

val Version: String = {
val Version: String =
val v = Try(getClass.getPackage.getImplementationVersion).getOrElse("0.0.0")
if (v == null) "0.0.0" else v
}
if v == null then "0.0.0" else v

val Description: String = "Annotation Service"

Expand All @@ -56,22 +55,47 @@ object AppConfig {
)

lazy val DefaultZeroMQConfig: Option[ZeroMQConfig] =
try {
try
val port = Config.getInt("messaging.zeromq.port")
val enable = Config.getBoolean("messaging.zeromq.enable")
val topic = Config.getString("messaging.zeromq.topic")
Some(ZeroMQConfig(port, enable, topic))
}
catch {
catch
case NonFatal(e) =>
log.atWarn.withCause(e).log("Failed to load ZeroMQ configuration")
None
}
}

lazy val DefaultDatabaseConfig: DatabaseConfig = DatabaseConfig(
url = Config.getString("database.url"),
user = Config.getString("database.user"),
password = Config.getString("database.password"),
driver = Config.getString("database.driver"),
queryView = Config.getString("database.query.view")
)

case class HttpConfig(
port: Int,
stopTimeout: Int,
connectorIdleTimeout: Int,
contextPath: String
)

case class DatabaseConfig(
url: String,
user: String,
password: String,
driver: String,
queryView: String
):
lazy val dataSource =
val ds = new com.zaxxer.hikari.HikariDataSource()
ds.setJdbcUrl(url)
ds.setUsername(user)
ds.setPassword(password)
ds.setDriverClassName(driver)
ds.setMaximumPoolSize(AppConfig.NumberOfVertxWorkers)
ds
def newConnection(): java.sql.Connection =
dataSource.getConnection()
// Class.forName(driver)
// java.sql.DriverManager.getConnection(url, user, password)
12 changes: 8 additions & 4 deletions annosaurus/src/main/scala/org/mbari/annosaurus/Endpoints.scala
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import sttp.tapir.swagger.bundle.SwaggerInterpreter

import scala.concurrent.{ExecutionContext, Future}

object Endpoints {
object Endpoints:

// --------------------------------
given ExecutionContext = ExecutionContext.global
Expand All @@ -44,6 +44,10 @@ object Endpoints {
val imageReferenceController = new ImageReferenceController(daoFactory)
val indexController = new IndexController(daoFactory)
val observationController = new ObservationController(daoFactory)
val queryController = new QueryController(
AppConfig.DefaultDatabaseConfig,
AppConfig.DefaultDatabaseConfig.queryView
)

// --------------------------------
val analysisRepository = new AnalysisRepository(daoFactory.entityManagerFactory)
Expand All @@ -67,6 +71,7 @@ object Endpoints {
val imageReferenceEndpoints = new ImageReferenceEndpoints(imageReferenceController)
val indexEndpoints = new IndexEndpoints(indexController)
val observationEndpoints = new ObservationEndpoints(observationController, jdbcRepository)
val queryEndpoints = new QueryEndpoints(queryController)

// --------------------------------
// For VertX, we need to separate the non-blocking endpoints from the blocking ones
Expand All @@ -86,7 +91,8 @@ object Endpoints {
imageEndpoints.allImpl,
imageReferenceEndpoints.allImpl,
indexEndpoints.allImpl,
observationEndpoints.allImpl
observationEndpoints.allImpl,
queryEndpoints.allImpl
).flatten

val apiEndpoints = nonBlockingEndpoints ++ blockingEndpoints
Expand All @@ -113,5 +119,3 @@ object Endpoints {

val all: List[ServerEndpoint[Any, Future]] =
apiEndpoints ++ docEndpoints ++ List(metricsEndpoint)

}
14 changes: 7 additions & 7 deletions annosaurus/src/main/scala/org/mbari/annosaurus/Main.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,20 @@ package org.mbari.annosaurus

import io.vertx.core.{Vertx, VertxOptions}
import io.vertx.ext.web.Router
import org.mbari.annosaurus.etc.jdk.Logging
import org.mbari.annosaurus.etc.jdk.Logging.{*, given}
import org.mbari.annosaurus.etc.jdk.Loggers
import org.mbari.annosaurus.etc.jdk.Loggers.given
import org.mbari.annosaurus.etc.zeromq.ZeroMQPublisher
import sttp.tapir.server.vertx.{VertxFutureServerInterpreter, VertxFutureServerOptions}
import sttp.tapir.server.vertx.VertxFutureServerInterpreter.VertxFutureToScalaFuture
import sttp.tapir.server.vertx.{VertxFutureServerInterpreter, VertxFutureServerOptions}

import scala.concurrent.{Await, ExecutionContext, Future}
import scala.concurrent.duration.Duration
import scala.io.StdIn
import scala.concurrent.{Await, ExecutionContext}

object Main:

// hold on to messaging objects so they don't get GC'd
private val zmq = ZeroMQPublisher.autowire(AppConfig.DefaultZeroMQConfig)
private val log = Logging(this.getClass)
private val log = Loggers(this.getClass)

def main(args: Array[String]): Unit =

Expand Down Expand Up @@ -63,7 +62,8 @@ object Main:
val port = sys.env.get("HTTP_PORT").flatMap(_.toIntOption).getOrElse(8080)
log.atInfo.log(s"Starting ${AppConfig.Name} v${AppConfig.Version} on port $port")

val vertx = Vertx.vertx(new VertxOptions().setWorkerPoolSize(AppConfig.NumberOfVertxWorkers))
val vertx =
Vertx.vertx(new VertxOptions().setWorkerPoolSize(AppConfig.NumberOfVertxWorkers))
// val vertx = Vertx.vertx()
val server = vertx.createHttpServer()
val router = Router.router(vertx)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,14 @@ package org.mbari.annosaurus

import java.util.UUID

/** We have made a design decision to always use UUIDs (aka GUIDs) as the primary key. This
* requirement is enforced so that external applications can rely on the use of that key. All
* persistent objects should implement this trait
*
* @author
* Brian Schlining
* @since 2016-05-05T16:21:00
*/
trait PersistentObject {
/**
* We have made a design decision to always use UUIDs (aka GUIDs) as the primary key. This requirement is enforced so
* that external applications can rely on the use of that key. All persistent objects should implement this trait
*
* @author
* Brian Schlining
* @since 2016-05-05T16:21:00
*/
trait PersistentObject:

def primaryKey: Option[UUID]
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@

package org.mbari

/** @author
* Brian Schlining
* @since 2016-06-15T16:50:00
*/
/**
* @author
* Brian Schlining
* @since 2016-06-15T16:50:00
*/
package object annosaurus {}
Loading

0 comments on commit ae39e2c

Please sign in to comment.