Skip to content

Commit

Permalink
Add explicit type annotations for implicit definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
andrew-nowak committed Nov 13, 2024
1 parent 5cb7599 commit 2fec085
Show file tree
Hide file tree
Showing 32 changed files with 119 additions and 119 deletions.
5 changes: 2 additions & 3 deletions common-lib/src/main/scala/com/gu/mediaservice/lib/Files.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@ import java.io.{File, FileOutputStream}
import java.net.URL
import java.nio.channels.Channels
import java.util.concurrent.Executors

import scala.concurrent.{ExecutionContext, Future}
import scala.concurrent.{ExecutionContext, ExecutionContextExecutor, Future}


object Files {

private implicit val ctx = ExecutionContext.fromExecutor(Executors.newCachedThreadPool)
private implicit val ctx: ExecutionContextExecutor = ExecutionContext.fromExecutor(Executors.newCachedThreadPool)

def createTempFile(prefix: String, suffix: String, tempDir: File): Future[File] =
Future {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import com.gu.mediaservice.model._
import com.gu.mediaservice.model.leases.MediaLease
import com.gu.mediaservice.model.usage.UsageNotice
import org.joda.time.{DateTime, DateTimeZone}
import play.api.libs.functional.syntax.{toFunctionalBuilderOps}
import play.api.libs.json.{JodaReads, JodaWrites, Json, __}
import play.api.libs.functional.syntax.toFunctionalBuilderOps
import play.api.libs.json.{JodaReads, JodaWrites, Json, OWrites, Reads, Writes, __}

// TODO MRB: replace this with the simple Kinesis class once we migrate off SNS
class ThrallMessageSender(config: KinesisSenderConfig) {
Expand All @@ -27,17 +27,17 @@ case class BulkIndexRequest(
)

object BulkIndexRequest {
implicit val reads = Json.reads[BulkIndexRequest]
implicit val writes = Json.writes[BulkIndexRequest]
implicit val reads: Reads[BulkIndexRequest] = Json.reads[BulkIndexRequest]
implicit val writes: OWrites[BulkIndexRequest] = Json.writes[BulkIndexRequest]
}

object UpdateMessage extends GridLogging {
implicit val yourJodaDateReads = JodaReads.DefaultJodaDateTimeReads.map(d => d.withZone(DateTimeZone.UTC))
implicit val yourJodaDateWrites = JodaWrites.JodaDateTimeWrites
implicit val unw = Json.writes[UsageNotice]
implicit val unr = Json.reads[UsageNotice]
implicit val writes = Json.writes[UpdateMessage]
implicit val reads =
implicit val yourJodaDateReads: Reads[DateTime] = JodaReads.DefaultJodaDateTimeReads.map(d => d.withZone(DateTimeZone.UTC))
implicit val yourJodaDateWrites: Writes[DateTime] = JodaWrites.JodaDateTimeWrites
implicit val unw: OWrites[UsageNotice] = Json.writes[UsageNotice]
implicit val unr: Reads[UsageNotice] = Json.reads[UsageNotice]
implicit val writes: OWrites[UpdateMessage] = Json.writes[UpdateMessage]
implicit val reads: Reads[UpdateMessage] =
(
(__ \ "subject").read[String] ~
(__ \ "image").readNullable[Image] ~
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ trait ElasticSearchClient extends ElasticSearchExecutions with GridLogging {
}

def healthCheck(): Future[Boolean] = {
implicit val logMarker = MarkerMap()
implicit val logMarker: MarkerMap = MarkerMap()
val request = search(imagesCurrentAlias) limit 0
executeAndLog(request, "Healthcheck").map { _ => true}.recover { case _ => false}
}
Expand All @@ -81,7 +81,7 @@ trait ElasticSearchClient extends ElasticSearchExecutions with GridLogging {
}

def countImages(indexName: String = imagesCurrentAlias): Future[ElasticSearchImageCounts] = {
implicit val logMarker = MarkerMap()
implicit val logMarker: MarkerMap = MarkerMap()
val queryCatCount = catCount(indexName) // document count only of index including live documents, not deleted documents which have not yet been removed by the merge process
val queryImageSearch = search(indexName) trackTotalHits true limit 0 // hits that match the query defined in the request
val uploadedInLastFiveMinutes = count(indexName) query rangeQuery("uploadTime").gte("now-5m")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ object Collection {
case class ActionData(author: String, date: DateTime)
object ActionData {
// TODO: Use the generic formats for DateTime
implicit val dateWrites = jodaDateWrites("yyyy-MM-dd'T'HH:mm:ss.SSSZZ")
implicit val dateReads = jodaDateReads("yyyy-MM-dd'T'HH:mm:ss.SSSZZ")
implicit val dateWrites: Writes[DateTime] = jodaDateWrites("yyyy-MM-dd'T'HH:mm:ss.SSSZZ")
implicit val dateReads: Reads[DateTime] = jodaDateReads("yyyy-MM-dd'T'HH:mm:ss.SSSZZ")
implicit def formats: Format[ActionData] = Json.format[ActionData]
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ case class SyndicationRights(
def isAvailableForSyndication: Boolean = isRightsAcquired && published.exists(_.isBeforeNow)
}
object SyndicationRights {
implicit val dateWrites = jodaDateWrites("yyyy-MM-dd'T'HH:mm:ss.SSSZZ")
implicit val dateReads = jodaDateReads("yyyy-MM-dd'T'HH:mm:ss.SSSZZ")
implicit val dateWrites: Writes[DateTime] = jodaDateWrites("yyyy-MM-dd'T'HH:mm:ss.SSSZZ")
implicit val dateReads: Reads[DateTime] = jodaDateReads("yyyy-MM-dd'T'HH:mm:ss.SSSZZ")

val reads: Reads[SyndicationRights] =
(
Expand Down Expand Up @@ -73,8 +73,8 @@ case class Property(
expiresOn: Option[DateTime],
value: Option[String])
object Property {
implicit val dateWrites = jodaDateWrites("yyyy-MM-dd'T'HH:mm:ss.SSSZZ")
implicit val dateReads = jodaDateReads("yyyy-MM-dd'T'HH:mm:ss.SSSZZ")
implicit val dateWrites: Writes[DateTime] = jodaDateWrites("yyyy-MM-dd'T'HH:mm:ss.SSSZZ")
implicit val dateReads: Reads[DateTime] = jodaDateReads("yyyy-MM-dd'T'HH:mm:ss.SSSZZ")

val reads: Reads[Property] = Json.reads[Property]
val writes: Writes[Property] = (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ object SyndicationStatus {

implicit val reads: Reads[SyndicationStatus] = JsPath.read[String].map(SyndicationStatus(_))

implicit val writer = new Writes[SyndicationStatus] {
implicit val writer: Writes[SyndicationStatus] = new Writes[SyndicationStatus] {
def writes(status: SyndicationStatus) = JsString(status.toString)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ package com.gu.mediaservice.model
import com.gu.mediaservice.model.leases.MediaLease
import com.gu.mediaservice.model.usage.UsageNotice
import org.joda.time.{DateTime, DateTimeZone}
import play.api.libs.json
import play.api.libs.json.{JodaReads, JodaWrites, JsValue, Json, Reads}
import play.api.libs.json.{JodaReads, JodaWrites, JsValue, Json, OFormat, OWrites, Reads, Writes}
import com.gu.mediaservice.lib.logging.{GridLogging, LogMarker}
import org.joda.time.format.DateTimeFormat

Expand Down Expand Up @@ -43,7 +42,7 @@ object MigrateImageMessage {

sealed trait ExternalThrallMessage extends ThrallMessage {
implicit val yourJodaDateReads: Reads[DateTime] = JodaReads.DefaultJodaDateTimeReads.map(d => d.withZone(DateTimeZone.UTC))
implicit val yourJodaDateWrites: json.JodaWrites.JodaDateTimeWrites.type = JodaWrites.JodaDateTimeWrites
implicit val yourJodaDateWrites: Writes[DateTime] = JodaWrites.JodaDateTimeWrites
val id: String
val lastModified: DateTime
def toJson: JsValue = Json.toJson(this)(ExternalThrallMessage.writes)
Expand All @@ -59,35 +58,35 @@ sealed trait ExternalThrallMessage extends ThrallMessage {
}

object ExternalThrallMessage{
implicit val yourJodaDateReads = JodaReads.DefaultJodaDateTimeReads.map(d => d.withZone(DateTimeZone.UTC))
implicit val yourJodaDateWrites = JodaWrites.JodaDateTimeWrites

implicit val usageNoticeFormat = Json.format[UsageNotice]

implicit val replaceImageLeasesMessageFormat = Json.format[ReplaceImageLeasesMessage]
implicit val deleteImageMessageFormat = Json.format[DeleteImageMessage]
implicit val updateImageSyndicationMetadataMessageFormat = Json.format[UpdateImageSyndicationMetadataMessage]
implicit val setImageCollectionsMessageFormat = Json.format[SetImageCollectionsMessage]
implicit val updateImageUserMetadataMessageFormat = Json.format[UpdateImageUserMetadataMessage]
implicit val deleteImageExportsMessageFormat = Json.format[DeleteImageExportsMessage]
implicit val softDeleteImageMessageFormat = Json.format[SoftDeleteImageMessage]
implicit val unSoftDeleteImageMessageFormat = Json.format[UnSoftDeleteImageMessage]
implicit val imageMessageFormat = Json.format[ImageMessage]
implicit val updateImagePhotoshootMetadataMessage = Json.format[UpdateImagePhotoshootMetadataMessage]
implicit val deleteUsagesMessage = Json.format[DeleteUsagesMessage]
implicit val deleteSingleUsageMessage = Json.format[DeleteSingleUsageMessage]
implicit val updateUsageStatusMessage = Json.format[UpdateUsageStatusMessage]
implicit val updateImageUsagesMessage = Json.format[UpdateImageUsagesMessage]
implicit val addImageLeaseMessage = Json.format[AddImageLeaseMessage]
implicit val removeImageLeaseMessage = Json.format[RemoveImageLeaseMessage]
implicit val updateImageExportsMessage = Json.format[UpdateImageExportsMessage]

implicit val createMigrationIndexMessage = Json.format[CreateMigrationIndexMessage]
implicit val completeMigrationMessage = Json.format[CompleteMigrationMessage]
implicit val upsertFromProjectionMessage = Json.format[UpsertFromProjectionMessage]

implicit val writes = Json.writes[ExternalThrallMessage]
implicit val reads = Json.reads[ExternalThrallMessage]
implicit val yourJodaDateReads: Reads[DateTime] = JodaReads.DefaultJodaDateTimeReads.map(d => d.withZone(DateTimeZone.UTC))
implicit val yourJodaDateWrites: Writes[DateTime] = JodaWrites.JodaDateTimeWrites

implicit val usageNoticeFormat: OFormat[UsageNotice] = Json.format[UsageNotice]

implicit val replaceImageLeasesMessageFormat: OFormat[ReplaceImageLeasesMessage] = Json.format[ReplaceImageLeasesMessage]
implicit val deleteImageMessageFormat: OFormat[DeleteImageMessage] = Json.format[DeleteImageMessage]
implicit val updateImageSyndicationMetadataMessageFormat: OFormat[UpdateImageSyndicationMetadataMessage] = Json.format[UpdateImageSyndicationMetadataMessage]
implicit val setImageCollectionsMessageFormat: OFormat[SetImageCollectionsMessage] = Json.format[SetImageCollectionsMessage]
implicit val updateImageUserMetadataMessageFormat: OFormat[UpdateImageUserMetadataMessage] = Json.format[UpdateImageUserMetadataMessage]
implicit val deleteImageExportsMessageFormat: OFormat[DeleteImageExportsMessage] = Json.format[DeleteImageExportsMessage]
implicit val softDeleteImageMessageFormat: OFormat[SoftDeleteImageMessage] = Json.format[SoftDeleteImageMessage]
implicit val unSoftDeleteImageMessageFormat: OFormat[UnSoftDeleteImageMessage] = Json.format[UnSoftDeleteImageMessage]
implicit val imageMessageFormat: OFormat[ImageMessage] = Json.format[ImageMessage]
implicit val updateImagePhotoshootMetadataMessage: OFormat[UpdateImagePhotoshootMetadataMessage] = Json.format[UpdateImagePhotoshootMetadataMessage]
implicit val deleteUsagesMessage: OFormat[DeleteUsagesMessage] = Json.format[DeleteUsagesMessage]
implicit val deleteSingleUsageMessage: OFormat[DeleteSingleUsageMessage] = Json.format[DeleteSingleUsageMessage]
implicit val updateUsageStatusMessage: OFormat[UpdateUsageStatusMessage] = Json.format[UpdateUsageStatusMessage]
implicit val updateImageUsagesMessage: OFormat[UpdateImageUsagesMessage] = Json.format[UpdateImageUsagesMessage]
implicit val addImageLeaseMessage: OFormat[AddImageLeaseMessage] = Json.format[AddImageLeaseMessage]
implicit val removeImageLeaseMessage: OFormat[RemoveImageLeaseMessage] = Json.format[RemoveImageLeaseMessage]
implicit val updateImageExportsMessage: OFormat[UpdateImageExportsMessage] = Json.format[UpdateImageExportsMessage]

implicit val createMigrationIndexMessage: OFormat[CreateMigrationIndexMessage] = Json.format[CreateMigrationIndexMessage]
implicit val completeMigrationMessage: OFormat[CompleteMigrationMessage] = Json.format[CompleteMigrationMessage]
implicit val upsertFromProjectionMessage: OFormat[UpsertFromProjectionMessage] = Json.format[UpsertFromProjectionMessage]

implicit val writes: OWrites[ExternalThrallMessage] = Json.writes[ExternalThrallMessage]
implicit val reads: Reads[ExternalThrallMessage] = Json.reads[ExternalThrallMessage]

}

Expand Down Expand Up @@ -128,9 +127,9 @@ case class DeleteUsagesMessage(id: String, lastModified: DateTime) extends Exter
case class UpdateUsageStatusMessage(id: String, usageNotice: UsageNotice, lastModified: DateTime) extends ExternalThrallMessage

object DeleteUsagesMessage {
implicit val yourJodaDateReads = JodaReads.DefaultJodaDateTimeReads.map(d => d.withZone(DateTimeZone.UTC))
implicit val yourJodaDateWrites = JodaWrites.JodaDateTimeWrites
implicit val what = Json.format[DeleteUsagesMessage]
implicit val yourJodaDateReads: Reads[DateTime] = JodaReads.DefaultJodaDateTimeReads.map(d => d.withZone(DateTimeZone.UTC))
implicit val yourJodaDateWrites: Writes[DateTime] = JodaWrites.JodaDateTimeWrites
implicit val what: OFormat[DeleteUsagesMessage] = Json.format[DeleteUsagesMessage]
}

case class UpdateImageSyndicationMetadataMessage(id: String, lastModified: DateTime, maybeSyndicationRights: Option[SyndicationRights]) extends ExternalThrallMessage
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.gu.mediaservice.model

import play.api.libs.json.Json
import play.api.libs.json.{Json, OWrites, Reads}

case class UploadInfo(filename: Option[String] = None)

object UploadInfo {
implicit val jsonWrites = Json.writes[UploadInfo]
implicit val jsonReads = Json.reads[UploadInfo]
implicit val jsonWrites: OWrites[UploadInfo] = Json.writes[UploadInfo]
implicit val jsonReads: Reads[UploadInfo] = Json.reads[UploadInfo]
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ object LeasesByMedia {
import JodaReads._
implicit val reader: Reads[LeasesByMedia] = Json.reads[LeasesByMedia]

implicit val writer = new Writes[LeasesByMedia] {
implicit val writer: Writes[LeasesByMedia] = new Writes[LeasesByMedia] {
def writes(leaseByMedia: LeasesByMedia) = {
Json.obj(
"leases" -> leaseByMedia.leases,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ object UsageStatus {

implicit val reads: Reads[UsageStatus] = JsPath.read[String].map(UsageStatus(_))

implicit val writer = new Writes[UsageStatus] {
implicit val writer: Writes[UsageStatus] = new Writes[UsageStatus] {
def writes(usageStatus: UsageStatus) = JsString(usageStatus.toString)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ trait PlayJsonSyntax {
def logParseErrors(): Unit = PlayJsonHelpers.logParseErrors(self)
}

implicit val uriWrites = new Writes[URI] {
implicit val uriWrites: Writes[URI] = new Writes[URI] {
override def writes(o: URI): JsValue = JsString(o.toString)
}

implicit val uriReads = new Reads[URI] {
implicit val uriReads: Reads[URI] = new Reads[URI] {
override def reads(json: JsValue): JsResult[URI] = json match {
case JsString(uriInJson) => Try {
new URI(uriInJson)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import scala.concurrent.ExecutionContext.Implicits.global
@Ignore
class ImageOperationsTest extends AnyFunSpec with Matchers with ScalaFutures {

implicit override val patienceConfig = PatienceConfig(timeout = Span(1000, Millis), interval = Span(25, Millis))
implicit override val patienceConfig: PatienceConfig = PatienceConfig(timeout = Span(1000, Millis), interval = Span(25, Millis))
implicit val logMarker: LogMarker = MarkerMap()

describe("identifyColourModel") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ package com.gu.mediaservice.lib.json

import org.scalatest.funsuite.AnyFunSuite
import org.scalatest.matchers.should.Matchers
import play.api.libs.json.Json
import play.api.libs.json.{Json, OWrites, Reads}

case class Shape(name: String, numberOfSides: Int)

object Shape {
implicit val reads = Json.reads[Shape]
implicit val writes = Json.writes[Shape]
implicit val reads: Reads[Shape] = Json.reads[Shape]
implicit val writes: OWrites[Shape] = Json.writes[Shape]
}

class JsonByteArrayUtilTest extends AnyFunSuite with Matchers {
Expand Down
2 changes: 1 addition & 1 deletion image-loader/app/controllers/ImageLoaderController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ class ImageLoaderController(auth: Authentication,
tempFile,
expectedSize = s3IngestObject.contentLength
)
implicit val logMarker = initialLogMarker ++ Map(
implicit val logMarker: LogMarker = initialLogMarker ++ Map(
"mediaId" -> digestedFile.digest
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class FileMetadataReaderTest extends AnyFunSpec with Matchers with ScalaFutures

import test.lib.ResourceHelpers._

implicit override val patienceConfig = PatienceConfig(timeout = Span(1000, Millis), interval = Span(25, Millis))
implicit override val patienceConfig: PatienceConfig = PatienceConfig(timeout = Span(1000, Millis), interval = Span(25, Millis))
implicit val logMarker: LogMarker = MarkerMap()

it("should read the correct dimensions for a JPG image") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import org.scalatest.matchers.should.Matchers
class MimeTypeDetectionTest extends AnyFunSpec with Matchers with ScalaFutures {
import test.lib.ResourceHelpers._

implicit val markers = MarkerMap()
implicit val markers: MarkerMap = MarkerMap()

it("should detect jpeg mime types for images") {
for (fileName <- List("getty.jpg", "corbis.jpg", "guardian-turner.jpg", "pa.jpg")) {
Expand Down
4 changes: 2 additions & 2 deletions leases/app/lib/LeaseStore.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ import scala.concurrent.{ExecutionContext, Future}
class LeaseStore(config: LeasesConfig) {
val client = config.withAWSCredentialsV2(DynamoDbAsyncClient.builder()).build()

implicit val dateTimeFormat =
implicit val dateTimeFormat: Typeclass[DateTime] =
DynamoFormat.coercedXmap[DateTime, String, IllegalArgumentException](DateTime.parse, _.toString)
implicit val enumFormat =
implicit val enumFormat: Typeclass[MediaLeaseType] =
DynamoFormat.coercedXmap[MediaLeaseType, String, IllegalArgumentException](MediaLeaseType(_), _.toString)

private val leasesTable = Table[MediaLease](config.leasesTable)
Expand Down
2 changes: 1 addition & 1 deletion media-api/app/controllers/AggregationController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class AggregationController(auth: Authentication, elasticSearch: ElasticSearch,
extends BaseController with AggregateResponses {

def dateHistogram(field: String, q: Option[String]) = auth.async { request =>
implicit val r = request
implicit val r: Authentication.Request[AnyContent] = request

elasticSearch.dateHistogramAggregate(AggregateSearchParams(field, request))
.map(aggregateResponse)
Expand Down
Loading

0 comments on commit 2fec085

Please sign in to comment.