This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ComparativeRepository { | |
val hdlProcessingSideEffects = Handler.create[String]("").unsafeRunSync() | |
def processingSideEffects = hdlProcessingSideEffects.map { | |
case "" => None | |
case msg => Some(div( clear.both, cls:="processingSideEffects", msg)) | |
} | |
val storeComparative = new StoreComparative() | |
val eventComparative = PublishSubject[String]() | |
//val eventComparativePublish = eventComparative.publish | |
val eventComparativePublish = eventComparative.multicast(Pipe.publish[String]) | |
val cancelEventComparativePublish = eventComparativePublish.connect() | |
val getMinimosRetensionISR = eventComparativePublish.dump("0").mapEval { case idComparative => | |
println("Ha ver, ha ver, changos !!!!!!!!! en el getMinimosRetensionISR") | |
hdlProcessingSideEffects.onNext("Procesando el Comparativo!") | |
val payload = Pickle.intoBytes[String](idComparative) | |
val respondWS = WSMyCeliumAnalytics.ws.send("getMinimosRetensionISR" :: Nil, payload, SendType.WhenConnected, 100 seconds) | |
respondWS.failed.foreach( x => println(s"################### ERROR getMinimosRetensionISR ####################################: $x ")) | |
respondWS.failed.foreach(println) | |
Task.suspend { | |
Task.fromFuture(respondWS).redeem( err => Left(err.getMessage), | |
result => { | |
result match { | |
case Right(value) => | |
val unPickle = Unpickle[Either[String, Double]].fromBytes(value) | |
unPickle match { | |
case Right(value) => | |
storeComparative.store.onNext(storeComparative.UpdateMinimosRetensionISR(value)) | |
println("Procesando con exito getMinimosRetensionISR !!!!!!!!!!") | |
Right(value) | |
case Left(error) => Left(error + "--getMinimosRetensionISR") | |
} | |
case Left(error) => Left(error) | |
} | |
} | |
) | |
} | |
} | |
val getProcess = eventComparativePublish.dump("0").mapEval { case idComparative => | |
hdlProcessingSideEffects.onNext("Procesando el Comparativo!") | |
val payload = Pickle.intoBytes[String](idComparative) | |
val respondWS = WSMyCeliumAnalytics.ws.send("getProcess" :: Nil, payload, SendType.WhenConnected, 100 seconds) | |
respondWS.failed.foreach( x => println(s"################### ERROR getProcess ####################################: $x ")) | |
//respondWS.failed.foreach(println) | |
Task.suspend { | |
Task.fromFuture(respondWS).redeem( err => Left(err.getMessage), | |
result => { | |
result match { | |
case Right(value) => | |
implicit val datePickler = transformPickler((t: Long) => new java.util.Date(t))(_.getTime) | |
val unPickle = Unpickle[Either[String, ViewProcess]].fromBytes(value) | |
unPickle match { | |
case Right(value) => | |
storeComparative.store.onNext(storeComparative.UpdateGralDataOfComparative(value)) | |
println("Procesando con exito getProcess !!!!!!!!!!") | |
Right(value) | |
case Left(error) => Left(error + " getProcess") | |
} | |
case Left(error) => Left(error) | |
} | |
} | |
) | |
} | |
} | |
val getComparativo = eventComparativePublish.dump("0").mapEval { case idComparative => | |
hdlProcessingSideEffects.onNext("Procesando el Comparativo!") | |
val payload = Pickle.intoBytes[String](idComparative) | |
val respondWS = WSMyCeliumAnalytics.ws.send("getComparativo" :: Nil, payload, SendType.WhenConnected, 100 seconds) | |
respondWS.failed.foreach( x => println(s"################### ERROR getProcess ####################################: $x ")) | |
//respondWS.failed.foreach(println) | |
Task.suspend { | |
Task.fromFuture(respondWS).redeem( err => Left(err.getMessage), | |
result => { | |
result match { | |
case Right(value) => | |
val unPickle = Unpickle[Either[String, List[(QryRow, Comparative)] ]].fromBytes(value) | |
unPickle match { | |
case Right(value) => | |
storeComparative.store.onNext ( storeComparative.UpdateTenders( value ) ) | |
println("Procesando con exito getComparative !!!!!!!!!!") | |
Right(value) | |
case Left(error) => Left(error + " getComparativo") | |
} | |
case Left(error) => Left(error) | |
} | |
} | |
) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment