Skip to content

Commit

Permalink
ran scalafix + scalafmt
Browse files Browse the repository at this point in the history
  • Loading branch information
hohonuuli committed Oct 22, 2024
1 parent 1a02308 commit d9e40b1
Show file tree
Hide file tree
Showing 35 changed files with 171 additions and 102 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,14 @@ case class DatabaseConfig(
driver: String,
queryView: String
):
lazy val dataSource = {
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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -525,8 +525,7 @@ class AnnotationController(
.getImageReferences
.isEmpty
then imDao.delete(imagedMoment)
else
imagedMoment.removeObservation(v)
else imagedMoment.removeObservation(v)
// d.delete(v)
true
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class CachedAncillaryDatumController(val daoFactory: JPADAOFactory)
)
// TODO should this return the existing data?
None
else {
else
val cad = dao.newPersistentObject(
latitude,
longitude,
Expand All @@ -104,7 +104,6 @@ class CachedAncillaryDatumController(val daoFactory: JPADAOFactory)
// println("---- " + cad)
imagedMoment.setAncillaryDatum(cad)
Some(cad)
}

for
entity <- exec(fn)
Expand All @@ -126,11 +125,10 @@ class CachedAncillaryDatumController(val daoFactory: JPADAOFactory)
throw new RuntimeException(
s"ImagedMoment with UUID of $imagedMomentUuid already has ancillary data"
)
else {
else
val entity = datum.toEntity
imagedMoment.setAncillaryDatum(entity)
entity
}

for
entity <- exec(fn)
Expand Down Expand Up @@ -289,10 +287,9 @@ class CachedAncillaryDatumController(val daoFactory: JPADAOFactory)
if im.getAncillaryDatum != null then
updateValues(im.getAncillaryDatum, d)
im.getAncillaryDatum
else {
else
im.setAncillaryDatum(d)
im.getAncillaryDatum
}

def merge(
data: Iterable[CachedAncillaryDatum],
Expand All @@ -315,7 +312,7 @@ class CachedAncillaryDatumController(val daoFactory: JPADAOFactory)
cd.recordedTimestamp.map(_.toEpochMilli).getOrElse(-1L).toDouble

if imagedMoments.isEmpty || usefulData.isEmpty then Seq.empty
else {
else
val mergedData = FastCollator(
imagedMoments,
imagedMomentToMillis,
Expand All @@ -330,7 +327,6 @@ class CachedAncillaryDatumController(val daoFactory: JPADAOFactory)
yield
val d = dao.newPersistentObject(cad.toEntity)
transform(createOrUpdate(d, im))
}

exec(fn)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ package org.mbari.annosaurus.controllers

import jakarta.persistence.EntityManager
import org.mbari.annosaurus.domain.CachedAncillaryDatum
import org.mbari.annosaurus.etc.jdk.Loggers.{*, given}
import org.mbari.annosaurus.etc.jdk.Loggers.given

import java.sql.Timestamp
import java.time.Instant
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,8 +243,7 @@ class ImageController(daoFactory: JPADAOFactory):
then
val imDao = daoFactory.newImagedMomentDAO(d)
imDao.delete(imagedMoment)
else
imagedMoment.removeImageReference(imageReference)
else imagedMoment.removeImageReference(imageReference)
// d.delete(imageReference)
true
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,7 @@ class ImageReferenceController(val daoFactory: JPADAOFactory)
then
val imDao = daoFactory.newImagedMomentDAO(dao)
imDao.delete(imagedMoment)
else
imagedMoment.removeImageReference(imageReference)
else imagedMoment.removeImageReference(imageReference)
// dao.delete(imageReference)
true
exec(fn)
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,7 @@ class ObservationController(
then
val imDao = daoFactory.newImagedMomentDAO(dao)
imDao.delete(imagedMoment)
else {
else
imagedMoment.removeObservation(observation)
dao.delete(observation)
}
true
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@

package org.mbari.annosaurus.domain



final case class QueryConstraintsResponse[A](queryConstraints: QueryConstraints, content: A):
def toSnakeCase: QueryConstraintsResponseSC[A] =
QueryConstraintsResponseSC(queryConstraints.toSnakeCase, content)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,17 +58,27 @@ case class QueryRequest(
/**
* ConstraintRequest is a case class that represents a constraint to apply to a query. It can have exactly 2 fields:
* column and one of the following fields: between, contains, equals, in, isnull, like, max, min, minmax.
* @param column The column to apply the constraint to
* @param between A list of two numeric, or dat2 (as iso8601) values to apply a between constraint
* @param contains Maps to a SQL 'LIKE' clause with the value wrapped in '%' characters
* @param equals A value to apply an equals constraint
* @param in A list of values to apply an 'IN' constraint
* @param isnull A boolean value to apply an 'IS NULL' constraint. If true, the constraint is 'IS NULL', if false, the
* constraint is 'IS NOT NULL'
* @param like A value to apply a 'LIKE' constraint. You must apply the '%' characters to the value before passing it
* @param max The maximum value to apply a '<=' constraint
* @param min The minimum value to apply a '>=' constraint
* @param minmax A list of 2 numeric values to apply a 'BETWEEN' constraint
* @param column
* The column to apply the constraint to
* @param between
* A list of two numeric, or dat2 (as iso8601) values to apply a between constraint
* @param contains
* Maps to a SQL 'LIKE' clause with the value wrapped in '%' characters
* @param equals
* A value to apply an equals constraint
* @param in
* A list of values to apply an 'IN' constraint
* @param isnull
* A boolean value to apply an 'IS NULL' constraint. If true, the constraint is 'IS NULL', if false, the constraint is
* 'IS NOT NULL'
* @param like
* A value to apply a 'LIKE' constraint. You must apply the '%' characters to the value before passing it
* @param max
* The maximum value to apply a '<=' constraint
* @param min
* The minimum value to apply a '>=' constraint
* @param minmax
* A list of 2 numeric values to apply a 'BETWEEN' constraint
*/
case class ConstraintRequest(
column: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,17 @@
package org.mbari.annosaurus.endpoints

import org.mbari.annosaurus.controllers.AnnotationController
import org.mbari.annosaurus.domain.{AnnotationCreateSC, AnnotationSC, AnnotationUpdateSC, BulkAnnotationSC, ConcurrentRequest, ConcurrentRequestCountSC, ErrorMsg, MultiRequest, MultiRequestCountSC}
import org.mbari.annosaurus.domain.{
AnnotationCreateSC,
AnnotationSC,
AnnotationUpdateSC,
BulkAnnotationSC,
ConcurrentRequest,
ConcurrentRequestCountSC,
ErrorMsg,
MultiRequest,
MultiRequestCountSC
}
import org.mbari.annosaurus.endpoints.CustomTapirJsonCirce.*
import org.mbari.annosaurus.etc.circe.CirceCodecs.given
import org.mbari.annosaurus.etc.jwt.JwtService
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,15 @@

package org.mbari.annosaurus.endpoints

import org.mbari.annosaurus.domain.{Authorization, AuthorizationSC, BadRequest, ErrorMsg, NotFound, ServerError, Unauthorized}
import org.mbari.annosaurus.domain.{
Authorization,
AuthorizationSC,
BadRequest,
ErrorMsg,
NotFound,
ServerError,
Unauthorized
}
import org.mbari.annosaurus.etc.circe.CirceCodecs.given
import org.mbari.annosaurus.etc.jwt.JwtService
import sttp.model.StatusCode
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ import org.mbari.annosaurus.etc.jdk.Loggers.given
import org.mbari.annosaurus.etc.jwt.JwtService
import sttp.model.StatusCode
import sttp.model.headers.WWWAuthenticateChallenge
import sttp.tapir.*
import sttp.tapir.generic.auto.*
import sttp.tapir.json.circe.*
import sttp.tapir.server.ServerEndpoint
import sttp.tapir.*

import java.net.{URI, URL}
import java.time.Instant
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,18 @@

package org.mbari.annosaurus.endpoints

import org.mbari.annosaurus.domain.{AnnotationSC, ConcurrentRequestSC, Count, DeleteCountSC, ErrorMsg, GeographicRangeSC, ImageSC, MultiRequestSC, QueryConstraints, QueryConstraintsResponseSC}
import org.mbari.annosaurus.domain.{
AnnotationSC,
ConcurrentRequestSC,
Count,
DeleteCountSC,
ErrorMsg,
GeographicRangeSC,
ImageSC,
MultiRequestSC,
QueryConstraints,
QueryConstraintsResponseSC
}
import org.mbari.annosaurus.endpoints.CustomTapirJsonCirce.*
import org.mbari.annosaurus.etc.circe.CirceCodecs.given
import org.mbari.annosaurus.etc.jwt.JwtService
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import sttp.tapir.server.ServerEndpoint
import sttp.tapir.server.ServerEndpoint.Full

import scala.concurrent.{ExecutionContext, Future}
import java.nio.charset.StandardCharsets

class QueryEndpoints(queryController: QueryController)(using executionContext: ExecutionContext) extends Endpoints:

Expand Down Expand Up @@ -62,9 +61,9 @@ class QueryEndpoints(queryController: QueryController)(using executionContext: E
)
)

// val runQueryStreaming =
// val runQueryStreaming =
// openEndpoint
// .post
// .post
// .in(base / "run")
// .in(jsonBody[QueryRequest])
// .out(streamTextBody(Fs2Streams[Future]), (CodecFormat.TextPlain(), Some(StandardCharsets.UTF_8)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ trait ImagedMomentDAO[T <: IPersistentObject] extends DAO[T]:
val im0 = elapsedTime.flatMap(findByVideoReferenceUUIDAndElapsedTime(uuid, _))
if im0.isEmpty then recordedDate.flatMap(findByVideoReferenceUUIDAndRecordedDate(uuid, _))
else im0
// This code has bug when resolving timecodes. See M3-15
// This code has bug when resolving timecodes. See M3-15
// val im0 = timecode.flatMap(findByVideoReferenceUUIDAndTimecode(uuid, _))
// val im1 = if (im0.isEmpty) elapsedTime.flatMap(findByVideoReferenceUUIDAndElapsedTime(uuid, _)) else im0
// if (im1.isEmpty) recordedDate.flatMap(findByVideoReferenceUUIDAndRecordedDate(uuid, _)) else im1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@

package org.mbari.annosaurus.repository.jdbc

import io.prometheus.metrics.shaded.com_google_protobuf_3_25_3.Timestamp

import java.time.Instant

object TimeHistogramSQL:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import java.lang.System.Logger.Level
import java.util.UUID
import scala.concurrent.{ExecutionContext, Future}
import scala.jdk.CollectionConverters.*
import scala.reflect.{ClassTag, classTag}
import scala.reflect.{classTag, ClassTag}

/**
* @author
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import org.mbari.vcr4j.time.Timecode
import java.sql.Timestamp
import java.time.{Duration, Instant}
import java.util.function.Function
import java.util.{UUID, stream}
import java.util.{stream, UUID}
import scala.jdk.CollectionConverters.*

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import org.mbari.annosaurus.repository.jpa.entity.ObservationEntity

import java.time.{Duration, Instant}
import java.util as ju
import java.util.{UUID, stream}
import java.util.{stream, UUID}
import scala.jdk.CollectionConverters.*

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ object PreparedStatementGenerator:
tableName: String,
query: Query
): String =
if (query.where.isEmpty) ""
if query.where.isEmpty then ""
else
val wheres = query.where.map(_.toPreparedStatementTemplate).mkString(" AND ")
if query.concurrentObservations && query.relatedAssociations then s"""WHERE $ObservationUuid IN (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,16 @@
package org.mbari.annosaurus.repository.query

import org.mbari.annosaurus.DatabaseConfig
import org.mbari.annosaurus.domain.Association
import org.mbari.annosaurus.etc.jdk.Loggers.{*, given}
import org.mbari.annosaurus.repository.jdbc.*

import java.sql.ResultSet
import scala.collection.mutable.ListBuffer
import scala.util.Using

class QueryService(databaseConfig: DatabaseConfig, viewName: String):

val jdbc = new JDBC(databaseConfig)
val jdbc = new JDBC(databaseConfig)
// val AnnotationViewName = "annotations"
private val log = System.getLogger(getClass.getName)
private val log = System.getLogger(getClass.getName)

// def findAllConceptNames(): Either[Throwable, Seq[String]] =
// jdbc.findDistinct(viewName, "concept", stringConverter)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,11 @@ case class Query(

object Query:

def validate(queryRequest: QueryRequest, checkWhere: Boolean = true, checkSelect: Boolean = true): Either[Throwable, Query] =
def validate(
queryRequest: QueryRequest,
checkWhere: Boolean = true,
checkSelect: Boolean = true
): Either[Throwable, Query] =
val query = from(queryRequest)
if checkWhere && query.where.isEmpty then Left(new IllegalArgumentException("where clause is required"))
else if checkSelect && query.select.isEmpty then Left(new IllegalArgumentException("select clause is required"))
Expand Down
10 changes: 9 additions & 1 deletion it/src/main/scala/org/mbari/annosaurus/AssertUtils.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,15 @@
package org.mbari.annosaurus

import org.junit.Assert.*
import org.mbari.annosaurus.repository.jpa.entity.{AssociationEntity, CachedAncillaryDatumEntity, CachedVideoReferenceInfoEntity, ImageReferenceEntity, ImagedMomentEntity, IndexEntity, ObservationEntity}
import org.mbari.annosaurus.repository.jpa.entity.{
AssociationEntity,
CachedAncillaryDatumEntity,
CachedVideoReferenceInfoEntity,
ImageReferenceEntity,
ImagedMomentEntity,
IndexEntity,
ObservationEntity
}

import scala.jdk.CollectionConverters.*

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package org.mbari.annosaurus.controllers

import org.mbari.annosaurus.AssertUtils
import org.mbari.annosaurus.domain.{Annotation, ConcurrentRequest, MultiRequest}
import org.mbari.annosaurus.etc.circe.CirceCodecs.*
import org.mbari.annosaurus.etc.sdk.Futures.*
import org.mbari.annosaurus.repository.jpa.{BaseDAOSuite, ImagedMomentDAOImpl, JPADAOFactory}
import org.mbari.vcr4j.time.Timecode
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import java.sql.Connection
import java.time.{Duration, Instant}
import java.util.UUID
import java.util.concurrent.TimeUnit
import scala.concurrent.{Await, ExecutionContext, duration}
import scala.concurrent.{duration, Await, ExecutionContext}
import scala.util.Random

object TestUtils:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,10 @@ trait AnalysisEndpointsSuite extends EndpointsSuite:

// TODO both the depth and time histogram logic needs to be reworked. They can give incorrect results
test("timeHistogram".flaky) {
val xs = TestUtils.create(5, 5, includeData = true)
val minTime = xs.map(_.getRecordedTimestamp).min
val maxTime = xs.map(_.getRecordedTimestamp).max
val expected = xs.flatMap(_.getObservations.asScala).size
val xs = TestUtils.create(5, 5, includeData = true)
val minTime = xs.map(_.getRecordedTimestamp).min
val maxTime = xs.map(_.getRecordedTimestamp).max
val expected = xs.flatMap(_.getObservations.asScala).size
val videoReferenceUuids = xs.map(_.getVideoReferenceUuid).distinct
val qcr = QueryConstraints(
videoReferenceUuids = Seq(xs.head.getVideoReferenceUuid),
Expand Down
Loading

0 comments on commit d9e40b1

Please sign in to comment.