Skip to content

Commit

Permalink
[#144] Fixing Warnings Part1
Browse files Browse the repository at this point in the history
  • Loading branch information
javieriserte committed Dec 20, 2024
1 parent e4725f5 commit 565dfc5
Show file tree
Hide file tree
Showing 3 changed files with 111 additions and 81 deletions.
15 changes: 5 additions & 10 deletions app/bulkupload/ProtoProfileRepository.scala
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,15 @@ import play.api.db.slick.Config.driver.simple.slickDriver
import play.api.db.slick.Config.driver.simple.stringColumnType
import play.api.db.slick.Config.driver.simple.valueToConstColumn
import play.api.db.slick.DB
import play.api.db.slick.DBAction
import models.Tables.ProfileDataRow
import javax.inject.Named

import play.api.i18n.Messages
import models.Tables.ProfileDataFiliationRow
import types.AlphanumericId
import profiledata.ProfileDataAttempt
import profiledata.DataFiliationAttempt
import configdata.{CategoryService, MatchingRule}
import kits.StrKitLocus
import util.{DefaultDb, Transaction}
import search.PaginationSearch
import bulkupload.KitNotExistsException

import scala.slick.driver.PostgresDriver

Expand Down Expand Up @@ -385,7 +380,7 @@ class SlickProtoProfileRepository @Inject() (

override def getBatchesStep1(userId: String, isSuperUser: Boolean): Future[Seq[ProtoProfilesBatchView]] = Future {
DB.withSession { implicit session =>
queryGetBatchesStep1(userId, isSuperUser).list map {
queryGetBatchesStep1((userId, isSuperUser)).list map {
case (id, user, date, total, appr, pend, rejected, label, approvedstep1, incompletestep1,analysisType) =>
ProtoProfilesBatchView(id, user, date, total.toInt, appr.toInt, pend.toInt, rejected.toInt, label, approvedstep1.toInt, incompletestep1.toInt,analysisType)
}
Expand All @@ -394,7 +389,7 @@ class SlickProtoProfileRepository @Inject() (

override def getBatchesStep2(userId: String, geneMapperId : String, isSuperUser: Boolean): Future[Seq[ProtoProfilesBatchView]] = Future {
DB.withSession { implicit session =>
queryGetBatchesStep2(geneMapperId, isSuperUser, geneMapperId, isSuperUser).list.filter(_._4 > 0). map {
queryGetBatchesStep2((geneMapperId, isSuperUser, geneMapperId, isSuperUser)).list.filter(_._4 > 0). map {
case (id, user, date, total, label, totalApproved, analysisType) =>
ProtoProfilesBatchView(id, user, date, total.toInt, 0, 0, 0, label, totalApproved.toInt,0,analysisType)
}
Expand Down Expand Up @@ -575,7 +570,7 @@ class SlickProtoProfileRepository @Inject() (

def getBatchSearchModalViewByIdOrLabel(input:String,idCase:Long):Future[List[BatchModelView]] = Future{
DB.withSession { implicit session =>
queryGetBatchesForModal(input,input).list map {
queryGetBatchesForModal((input,input)).list map {
case (id, label, date) =>{
val sdf = new java.text.SimpleDateFormat("dd/MM/yyyy");
BatchModelView(id, Some(label),sdf.format(date))
Expand All @@ -585,8 +580,8 @@ class SlickProtoProfileRepository @Inject() (
}

override def getSearchBachLabelID(userId: String, isSuperUser: Boolean, search :String): Future[Seq[ProtoProfilesBatchView]] = Future {
DB.withSession { implicit session =>
queryGetSearchBatchesLabelID(userId,isSuperUser,search, search).list map {
DB.withSession { implicit session =>
queryGetSearchBatchesLabelID((userId,isSuperUser,search, search)).list map {
case (id, user, date, total, appr, pend, rejected, label, approvedStep1, incompleteStep1, analysisType) =>
ProtoProfilesBatchView(id, user, date, total.toInt, appr.toInt, pend.toInt, rejected.toInt, label, approvedStep1.toInt, incompleteStep1.toInt,analysisType)
}
Expand Down
12 changes: 9 additions & 3 deletions app/connections/ConnectionRepository.scala
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,9 @@ class SlickConnectionRepository @Inject()(implicit val app: Application) extends
matchUpdateSendStatus.filter(_.id === id)
.filter(_.targetLab === targetLab.getOrElse("SUPERIOR"))
.map(x => (x.status,x.message,x.date))
.update(statusHitDiscard,message,Some(new java.sql.Timestamp(System.currentTimeMillis())))
.update(
(statusHitDiscard,message,Some(new java.sql.Timestamp(System.currentTimeMillis())))
)
Right(())
} catch {
case e: Exception => {
Expand All @@ -288,7 +290,9 @@ class SlickConnectionRepository @Inject()(implicit val app: Application) extends
override def getMatchSendStatusById(id:String, targetLab:Option[String] = None):Future[Option[Long]] = {
this.runInTransactionAsync { implicit session => {
try {
getMatchSendStatusByIdCompiled(id,targetLab.getOrElse("SUPERIOR")).firstOption.flatMap(_.status)
getMatchSendStatusByIdCompiled((id,targetLab.getOrElse("SUPERIOR")))
.firstOption
.flatMap(_.status)
} catch {
case e: Exception => {
None
Expand All @@ -301,7 +305,9 @@ class SlickConnectionRepository @Inject()(implicit val app: Application) extends
override def getMatchUpdateSendStatusById(id:String, targetLab:Option[String] = None):Future[Option[Long]] = {
this.runInTransactionAsync { implicit session => {
try {
getMatchUpdateSendStatusByIdCompiled(id,targetLab.getOrElse("SUPERIOR")).firstOption.flatMap(_.status)
getMatchUpdateSendStatusByIdCompiled((id,targetLab.getOrElse("SUPERIOR")))
.firstOption
.flatMap(_.status)
} catch {
case e: Exception => {
None
Expand Down
165 changes: 97 additions & 68 deletions app/connections/InterconnectionService.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import org.apache.commons.codec.binary.Base64
import akka.actor.{ActorRef, ActorSystem}
import akka.util.Timeout
import audit.PEOSignerActor
import connections.ProfileTransfer

import scala.concurrent.duration._
import scala.concurrent.Await
Expand All @@ -27,7 +26,6 @@ import profile.{Profile, ProfileService}
import profiledata.{DeletedMotive, ProfileData, ProfileDataAttempt, ProfileDataService}
import types.{AlphanumericId, Permission, SampleCode}
import user.{RoleService, UserService}
import connections.MatchSuperiorInstance
import util.FutureUtils

import java.util
Expand Down Expand Up @@ -208,7 +206,14 @@ class InterconnectionServiceImpl @Inject()(
private def sendRequestOnDemand(holder: WSRequestHolder, body: String = "", timeoutParam: Timeout = defaultTimeoutOnDemand): Future[WSResponse] = {
implicit val timeout = timeoutParam
val sendRequestActor: ActorRef = akkaSystem.actorOf(SendRequestActor.props())
(sendRequestActor ? (holder.withRequestTimeout(timeOutHolder), body, true, timeActorSendRequestGet)).mapTo[WSResponse]
(sendRequestActor ? (
(
holder.withRequestTimeout(timeOutHolder),
body,
true,
timeActorSendRequestGet
)))
.mapTo[WSResponse]
}

private def sendRequestQueue(
Expand All @@ -219,11 +224,13 @@ class InterconnectionServiceImpl @Inject()(
implicit val timeout: Timeout = timeoutParam
(
sendRequestActorGlobal ? (
addHeadersURL(holder)
.withRequestTimeout(timeOutHolder),
body,
false,
timeActorSendRequestPutPostDelete
(
addHeadersURL(holder)
.withRequestTimeout(timeOutHolder),
body,
false,
timeActorSendRequestPutPostDelete
)
)
)
.mapTo[WSResponse]
Expand Down Expand Up @@ -1629,14 +1636,15 @@ class InterconnectionServiceImpl @Inject()(
}
if (shouldDeleteProfileOnSupInst) {
await(this.profileDataService.updateUploadStatus(globalCode.text, PENDING_DELETE))
sendDeletionToSuperiorInstance(globalCode, motive).map {
case Left(m) => {
this.profileDataService.updateUploadStatus(globalCode.text, PENDING_DELETE, Some(m))
}
case _ => {
this.profileDataService.updateUploadStatus(globalCode.text, DELETED_IN_SUP_INS)
sendDeletionToSuperiorInstance(globalCode, motive)
.foreach {
case Left(m) => {
this.profileDataService.updateUploadStatus(globalCode.text, PENDING_DELETE, Some(m))
}
case _ => {
this.profileDataService.updateUploadStatus(globalCode.text, DELETED_IN_SUP_INS)
}
}
}
}
}
}
Expand Down Expand Up @@ -1862,7 +1870,7 @@ class InterconnectionServiceImpl @Inject()(

def traceMatch(left: SampleCode, right: SampleCode, matchingId: String, analysisType: Int, assignee: String): Unit = {
if (left.text.contains(currentInstanceLabCode)) {
traceService.add(Trace(left, assignee, new Date(),
val _ = traceService.add(Trace(left, assignee, new Date(),
MatchInfo(matchingId, right, analysisType, MatchTypeInfo.Insert)))
}
}
Expand Down Expand Up @@ -1935,28 +1943,26 @@ class InterconnectionServiceImpl @Inject()(
}else if (localProfiles.size == 0) {
// me tengo que fijar cuantos son de instancias inferiores mias
// y esa cantidad tiene que ser igual a la cantidad de uploaded profiles
var inferiorInstances = Await.result(this.inferiorInstanceRepository.findAll(), Duration.Inf)
val inferiorInstances = Await.result(this.inferiorInstanceRepository.findAll(), Duration.Inf)
inferiorInstances match {
case Left(a) => {
result = false
}
case Right(inferiorInstancesList) => {
case Left(_) => result = false
case Right(inferiorInstancesList) =>
val inferiorLabs = inferiorInstancesList.map(_.laboratory)
val profileLeftOpt = Await.result(profileDataService.getExternalProfileDataByGlobalCode(matchResult.leftProfile.globalCode.text), Duration.Inf)
val profileRightOpt = Await.result(profileDataService.getExternalProfileDataByGlobalCode(matchResult.rightProfile.globalCode.text), Duration.Inf)

(profileLeftOpt,profileRightOpt) match {
case (Some(profileLeft),Some(profileRight)) => {
result = List(profileLeft.laboratoryOrigin,profileRight.laboratoryOrigin)
.filter(inferiorLabs.contains(_)).size == uploadedProfiles.size
}
result = (profileLeftOpt, profileRightOpt) match {
case (Some(profileLeft), Some(profileRight)) =>
List(
profileLeft.laboratoryOrigin,
profileRight.laboratoryOrigin
)
.count(inferiorLabs.contains(_)) == uploadedProfiles.size
case (_, _) => false
}

}
}
}
result

} else {
result
}
Expand Down Expand Up @@ -1996,7 +2002,7 @@ class InterconnectionServiceImpl @Inject()(

def handleDeliveryConvertStatus(globalCode: SampleCode, convertStatus: ConvertStatusInterconnection, labImmediate: String, sendToSuperior: Boolean,
onlyUpload: Boolean = false): Unit = {
getUrl(globalCode).map {
getUrl(globalCode).foreach {
case Nil => {
logger.error("No deberia pasar por aca porque se supone que tiene configurada la url")
()
Expand Down Expand Up @@ -2046,53 +2052,54 @@ class InterconnectionServiceImpl @Inject()(
.withHeaders("Content-Type" -> "application/json")
val outputJson = Json.toJson(convertStatus)
val outputJsonString = outputJson.toString
this.markHitOrDiscardPending(convertStatus, Some(outputJsonString), labcode).map {
case Left(_) => {
Future.successful(())
}
case Right(()) => {
this.getConnectionsStatus(url).flatMap {
case Left(_) => Future.successful(Left("No se pudo enviar el status del match"))
case Right(_) => {
this.sendRequestQueue(holder.withMethod("POST"), outputJsonString).flatMap { result => {
if (result.status == 200) {
logger.debug("Se envió correctamente el status del match")
// Actualizar el estado a enviado
this.markHitOrDiscardSent(convertStatus, Some(outputJsonString), labcode)
Future.successful(Right(()))
} else {
logger.error(result.body)
// Actualizar el estado a error
logger.debug("No se pudo enviar el status del match")
Future.successful(Left("No se pudo enviar el status del match"))
val _ = this
.markHitOrDiscardPending(convertStatus, Some(outputJsonString), labcode)
.map {
case Left(_) => {
Future.successful(())
}
case Right(()) => {
this.getConnectionsStatus(url).flatMap {
case Left(_) => Future.successful(Left("No se pudo enviar el status del match"))
case Right(_) => {
this.sendRequestQueue(holder.withMethod("POST"), outputJsonString).flatMap { result => {
if (result.status == 200) {
logger.debug("Se envió correctamente el status del match")
// Actualizar el estado a enviado
this.markHitOrDiscardSent(convertStatus, Some(outputJsonString), labcode)
Future.successful(Right(()))
} else {
logger.error(result.body)
// Actualizar el estado a error
logger.debug("No se pudo enviar el status del match")
Future.successful(Left("No se pudo enviar el status del match"))
}
}
}
}
}
}
}
}
}
.recoverWith {
case _: Exception => Future.successful(Left("No se pudo enviar el status del match"))
}

}

def getUrl(globalCode: SampleCode): Future[List[(String, String)]] = {
(for {
pd <- profileDataService.getExternalProfileDataByGlobalCode(globalCode.text)
url <- connectionRepository.getSupInstanceUrl()
} yield (pd, url)).flatMap {
(
for {
pd <- profileDataService.getExternalProfileDataByGlobalCode(globalCode.text)
url <- connectionRepository.getSupInstanceUrl()
} yield (pd, url)
).flatMap {
case (Some(pd), None) => {
this.inferiorInstanceRepository.findByLabCode(pd.laboratoryImmediate).flatMap {
case Some(inferiorInstance) => {
// Send to inferior instance
Future.successful(List((inferiorInstance.url, inferiorInstance.laboratory)))
}
case None => {
// no deberia pasar por aca
Future.successful(Nil)
}
case None => Future.successful(Nil)
// no deberia pasar por aca
}
}
case (None, Some(url)) => {
Expand All @@ -2104,12 +2111,12 @@ class InterconnectionServiceImpl @Inject()(
// Send to inferior instance
Future.successful(List((inferiorInstance.url, inferiorInstance.laboratory),(url,superiorLabCode)))
}
case None => {
// no deberia pasar por aca
Future.successful(List((url,superiorLabCode)))
}
case None => Future.successful(List((url,superiorLabCode)))
// no deberia pasar por aca
}
}
case (None, None) => Future.successful(Nil)
// no deberia pasar por aca
}
}

Expand Down Expand Up @@ -2142,9 +2149,17 @@ class InterconnectionServiceImpl @Inject()(
()
}

def receiveMatchStatus(matchId: String, firingCode: SampleCode, leftCode: SampleCode, rightCode: SampleCode, status: String, labOrigin: String, labImmediate: String): Future[Unit] = Future {
def receiveMatchStatus(
matchId: String,
firingCode: SampleCode,
leftCode: SampleCode,
rightCode: SampleCode,
status: String,
labOrigin: String,
labImmediate: String
): Future[Unit] = Future {

matchingRepository.getByMatchingProfileId(matchId).flatMap {
val _ = matchingRepository.getByMatchingProfileId(matchId).flatMap {
case Some(matchingResult) => {
if (shouldBeForwarded(matchingResult.leftProfile.globalCode, labOrigin, labImmediate) ||
shouldBeForwarded(matchingResult.rightProfile.globalCode, labOrigin, labImmediate)) {
Expand All @@ -2153,7 +2168,14 @@ class InterconnectionServiceImpl @Inject()(
}
val isAdmin = true
matchingService.convertHitOrDiscard(matchId, firingCode, isAdmin, status)
notifyHitOrDiscard(matchId, firingCode, status, matchingResult.leftProfile.globalCode, matchingResult.rightProfile.globalCode, getAssignee(matchingResult))
notifyHitOrDiscard(
matchId,
firingCode,
status,
matchingResult.leftProfile.globalCode,
matchingResult.rightProfile.globalCode,
getAssignee(matchingResult)
)
// matching service hit or discard
Future.successful(())
}
Expand All @@ -2167,7 +2189,14 @@ class InterconnectionServiceImpl @Inject()(
}
val isAdmin = true
matchingService.convertHitOrDiscard(matchingResult._id.id, firingCode, isAdmin, status)
notifyHitOrDiscard(matchingResult._id.id, firingCode, status, matchingResult.leftProfile.globalCode, matchingResult.rightProfile.globalCode, getAssignee(matchingResult))
notifyHitOrDiscard(
matchingResult._id.id,
firingCode,
status,
matchingResult.leftProfile.globalCode,
matchingResult.rightProfile.globalCode,
getAssignee(matchingResult)
)
// matching service hit or discard
Future.successful(())
}
Expand Down

0 comments on commit 565dfc5

Please sign in to comment.