feat 2factor refs #7775

This commit is contained in:
Sergio De la torre 2024-07-24 13:29:32 +02:00
parent 3cc2717a90
commit cdc5ebcd57
4 changed files with 142 additions and 162 deletions

View File

@ -21,11 +21,12 @@ abstract class SalixCallback<T>(val context: Context) : Callback<T> {
onSuccess(response) onSuccess(response)
} else { } else {
try { try {
val errorBodyString = response.errorBody()?.string()
if (response.code() == 555) { if (response.code() == 555) {
var message = JSONObject(response.message()).getString("Message") var message = JSONObject(response.message()).getString("Message")
onError(Error(message)) onError(Error(message))
} else if (response.code() == 401) { } else if (response.code() == 401) {
if (!(context as MobileApplication).isLoginRunning()){ if (!(context as MobileApplication).isLoginRunning()) {
val intent = Intent(context, LoginActivity::class.java) val intent = Intent(context, LoginActivity::class.java)
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_SINGLE_TOP or Intent.FLAG_ACTIVITY_NEW_TASK) intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_SINGLE_TOP or Intent.FLAG_ACTIVITY_NEW_TASK)
context.startActivity(intent) context.startActivity(intent)
@ -34,9 +35,7 @@ abstract class SalixCallback<T>(val context: Context) : Callback<T> {
onError(Error(response.message().toString())) onError(Error(response.message().toString()))
} }
} else { } else {
onError(Error(errorSalixMessage(response, errorBodyString)))
onError(Error(errorSalixMessage(response)))
// onError(Error(response.message().toString()))
} }
} catch (t: Throwable) { } catch (t: Throwable) {
defaultErrorHandler(t) defaultErrorHandler(t)
@ -71,30 +70,18 @@ abstract class SalixCallback<T>(val context: Context) : Callback<T> {
throw t throw t
} }
/* fun isActivityRunning(context: Context, activityClass: Class<*>): Boolean { private fun errorSalixMessage(response: Response<T>, errorBody: String?): String {
val packageName = context.packageName val myErrorCodeBody = errorBody?.let { errorBodyString
val activityManager = context.getSystemService(Context.ACTIVITY_SERVICE) as ActivityManager ->
val runningActivities = activityManager.getRunningTasks(Int.MAX_VALUE) JSONObject(errorBodyString).getJSONObject("error").getString("code")
for (taskInfo in runningActivities) {
if (taskInfo.baseActivity?.className == activityClass.name && taskInfo.topActivity?.packageName == packageName) {
return true
}
} }
return false
}*/
private fun errorSalixMessage(response: Response<T>): String {
val messageResponse = response.errorBody()!!.string()
return try { return try {
val messageResponse = response.errorBody()!!.string()
val jsonObject = Gson().fromJson(messageResponse, JsonObject::class.java) val jsonObject = Gson().fromJson(messageResponse, JsonObject::class.java)
jsonObject?.getAsJsonObject("error")?.get("message")?.asString.toString() var messageJson = jsonObject?.getAsJsonObject("error")?.get("message")?.asString
messageJson ?: "${response.message()}.$myErrorCodeBody"
} catch (ex: Exception) { } catch (ex: Exception) {
response.message() response.message() + ".$myErrorCodeBody"
} }
} }

View File

@ -98,6 +98,13 @@ interface SalixService {
@Body params: LoginSalixVO @Body params: LoginSalixVO
): Call<LoginSalixVO> ): Call<LoginSalixVO>
@POST("VnUsers/validate-auth")
fun validateAuth(
@Query("user") user: Any,
@Query("password") password: Any,
@Query("code") code: Any
): Call<LoginSalixVO>
@POST("Accounts/loginApp") @POST("Accounts/loginApp")
fun loginApp( fun loginApp(
@Body params: LoginApp @Body params: LoginApp
@ -201,7 +208,7 @@ interface SalixService {
@Query("params") params: Any? = null @Query("params") params: Any? = null
): Call<Any> ): Call<Any>
@POST("Applications/itemShelvingSale_addBySectorCollection/execute-proc") // PERMISOS GRANT @POST("Applications/itemShelvingSale_addBySectorCollection/execute-proc")
fun getReserveBySectorCollection( fun getReserveBySectorCollection(
@Query("schema") schema: String = "vn", @Query("schema") schema: String = "vn",
@Query("params") params: Any? = null @Query("params") params: Any? = null
@ -243,7 +250,7 @@ interface SalixService {
@POST("TicketObservations/upsertWithWhere") @POST("TicketObservations/upsertWithWhere")
fun updateNoteFromDropOff( fun updateNoteFromDropOff(
@Query("where") where: Any? = null, @Query("where") where: Any? = null,
@Body params: Any //description @Body params: Any
): Call<Any> ): Call<Any>
@POST("TicketObservations/addDropOff") @POST("TicketObservations/addDropOff")
@ -331,7 +338,7 @@ interface SalixService {
@Query("filter") filter: Any?, @Query("filter") filter: Any?,
): Call<List<ItemExpeditionTruckSalix>> ): Call<List<ItemExpeditionTruckSalix>>
@GET("Printers")//NO SALIX @GET("Printers")
fun getprinters( fun getprinters(
@Query("filter") filter: Any? @Query("filter") filter: Any?
): ):
@ -374,7 +381,7 @@ interface SalixService {
): ):
Call<Any> Call<Any>
@GET("Sales/getFromSectorCollection")//NO SALIX @GET("Sales/getFromSectorCollection")
fun sectorCollectionGetSale( fun sectorCollectionGetSale(
@Query("sectorFk") sectorFk: Int, @Query("sectorFk") sectorFk: Int,
@Query("sectorCollectionFk") sectorCollectionFk: Int, @Query("sectorCollectionFk") sectorCollectionFk: Int,
@ -465,7 +472,7 @@ interface SalixService {
): ):
Call<VersionApp> Call<VersionApp>
@GET("Items/get")//NO SALIX @GET("Items/get")
fun getCard( fun getCard(
@Query("barcode") barcode: Number, @Query("barcode") barcode: Number,
@Query("warehouseFk") warehouseFk: Int @Query("warehouseFk") warehouseFk: Int
@ -694,13 +701,6 @@ interface SalixService {
@Query("params") params: Any, @Query("params") params: Any,
): Call<Any> ): Call<Any>
/* @POST("Applications/itemShelvingLog_get/execute-proc")
fun itemShelvingLogGet(
@Query("schema") schema: String = "vn",
@Query("params") params: Any,
): Call<List<ItemShelvingLog>>*/
//Tarea 7168
@GET("ItemShelvingLogs") @GET("ItemShelvingLogs")
fun itemShelvingLogGet( fun itemShelvingLogGet(
@Query("filter") filter: String, @Query("filter") filter: String,
@ -744,7 +744,7 @@ interface SalixService {
Call<List<ItemDetails>> Call<List<ItemDetails>>
@POST("Applications/expedition_getState/execute-proc") @POST("Applications/expedition_getState/execute-proc")
fun expedition_getState( fun expeditionGetState(
@Query("schema") schema: String = "vn", @Query("schema") schema: String = "vn",
@Query("params") params: Any, @Query("params") params: Any,
): Call<ArrayList<JsonObject>> ): Call<ArrayList<JsonObject>>
@ -768,7 +768,7 @@ interface SalixService {
): Call<Any> ): Call<Any>
@POST("Applications/buffer_setTypeByName/execute-proc") @POST("Applications/buffer_setTypeByName/execute-proc")
fun buffer_setTypeByName( fun bufferSetTypeByName(
@Query("schema") schema: String = "srt", @Query("schema") schema: String = "srt",
@Query("params") params: Any @Query("params") params: Any
): Call<List<JsonObject>> ): Call<List<JsonObject>>
@ -789,10 +789,6 @@ interface SalixService {
@Body params: Any @Body params: Any
): Call<CollectionTicket> ): Call<CollectionTicket>
@GET("collections/sectorCollection_get")
fun sectorCollection_get(
): Call<List<CollectionVO>>
@POST("collections/setSaleQuantity") @POST("collections/setSaleQuantity")
fun collectionIncreaseQuantitySalix( fun collectionIncreaseQuantitySalix(
@Body params: SalixSaleQuantity @Body params: SalixSaleQuantity
@ -837,9 +833,8 @@ interface SalixService {
): ):
Call<EntrySalix> Call<EntrySalix>
@GET("Departments") @GET("Departments")
fun department_getHasMistake( fun departmentGetHasMistake(
@Query("filter") filter: String = """{"fields": {"id": true,"name": true},"where": {"hasToMistake": true}}""" @Query("filter") filter: String = """{"fields": {"id": true,"name": true},"where": {"hasToMistake": true}}"""
): Call<List<DepartmentMistake>> ): Call<List<DepartmentMistake>>
@ -859,16 +854,10 @@ interface SalixService {
): Call<Any> ): Call<Any>
@GET("Workers/{idWorker}/sip") @GET("Workers/{idWorker}/sip")
fun sip_getExtension( fun sipGetExtension(
@Path("idWorker") idWorker: Int, @Path("idWorker") idWorker: Int,
): Call<Any> ): Call<Any>
@PATCH("Items/{itemFk}")
fun update_ItemPackingType(
@Path("itemFk") itemFk: String,
@Body params: Any
): Call<Any>
@PATCH("Items/{itemFk}") @PATCH("Items/{itemFk}")
fun updateItem( fun updateItem(
@Path("itemFk") itemFk: Int, @Path("itemFk") itemFk: Int,
@ -903,7 +892,7 @@ interface SalixService {
): Call<Any> ): Call<Any>
@GET("ItemPackingTypes") @GET("ItemPackingTypes")
fun get_ItemPackingType( fun getItemPackingType(
@Query("filter") filter: String = """{"where": {"isActive": true}}""" @Query("filter") filter: String = """{"where": {"isActive": true}}"""
): Call<List<ItemPackingType>> ): Call<List<ItemPackingType>>
@ -941,7 +930,7 @@ interface SalixService {
): Call<List<StopMapTruckPallet>> ): Call<List<StopMapTruckPallet>>
@POST("PackingSiteAdvanceds") @POST("PackingSiteAdvanceds")
fun ticket_advancePackaging( fun ticketAdvancePackaging(
@Body parms: PackingSiteSalix @Body parms: PackingSiteSalix
): Call<Unit> ): Call<Unit>
@ -963,33 +952,10 @@ interface SalixService {
@GET("Suppliers") @GET("Suppliers")
fun getSuppliers( fun getSuppliers(
//@Query("filter") filter:String="""{"fields":{"id":true,"name":true}}"""
//@Body params:JSONObject=JSONObject("""filter"={"fields":{"id":true,"name":true},"include":[{"relation":"contacts","scope":{"fields":["email"],"order":"id DESC","limit":1,"where":{"email":{"neq":null}}}}]}""")
@Query("filter") filter: String = """{"fields":{"id":true,"name":true},"order":"name ASC","where":{"isActive":1,"name":{"neq":null}}, "include":[{"relation":"contacts","scope":{"fields":["email"],"where":{"email":{"neq":null}}}}]}""" @Query("filter") filter: String = """{"fields":{"id":true,"name":true},"order":"name ASC","where":{"isActive":1,"name":{"neq":null}}, "include":[{"relation":"contacts","scope":{"fields":["email"],"where":{"email":{"neq":null}}}}]}"""
/* @Query("filter") filter:String="{\"fields\":{\"id\":true,\"name\":true},\"include\":[{\"relation\":\"contacts\"," +
"\"scope\":{" +
"\"fields\":[\"email\"],\"order\":\"id DESC\",\"limit\":1," +
"\"where\":{ \"email\":{\"neq\":null } }}}]})"*/
//@Query("filter") filter:String? = """""\"order\":\"name DESC\""""
): Call<List<Supplier>> ): Call<List<Supplier>>
/* fun getEntries(
//@Body params:JSONObject=JSONObject("""filter"={"fields":{"id":true,"name":true},"include":[{"relation":"contacts","scope":{"fields":["email"],"order":"id DESC","limit":1,"where":{"email":{"neq":null}}}}]}""")
*//* @Query("filter") filter:String="{\"fields\":{\"id\":true,\"name\":true},\"include\":[{\"relation\":\"contacts\"," +
"\"scope\":{" +
"\"fields\":[\"email\"],\"order\":\"id DESC\",\"limit\":1," +
"\"where\":{ \"email\":{\"neq\":null } }}}]})"*//*
):
Call<List<EntrySalix>>*/
@PUT("Entries")
fun Entries(
@Body supplier: Any
):
Call<List<EntrySalix>>
@GET("Entries") @GET("Entries")
fun getEntriesFromSupplier( fun getEntriesFromSupplier(
@Query("filter") filter: String @Query("filter") filter: String
@ -997,20 +963,20 @@ interface SalixService {
Call<List<EntrySalix>> Call<List<EntrySalix>>
@GET("Entries") @GET("Entries")
fun add_entry( fun addEntry(
@Body entry: EntrySalix @Body entry: EntrySalix
): ):
Call<EntrySalix> Call<EntrySalix>
@PATCH("Entries/{entryId}") @PATCH("Entries/{entryId}")
fun entry_updateObserv( fun entryUpdateObserv(
@Path("entryId") entryId: Int, @Path("entryId") entryId: Int,
@Body entry: ObervationEntry @Body entry: ObervationEntry
): ):
Call<EntrySalix> Call<EntrySalix>
@GET("Shelvings") @GET("Shelvings")
fun Shelvings( fun shelvingsGet(
@Query("filter") filter: String @Query("filter") filter: String
): Call<List<ShelvingLogSalix>> ): Call<List<ShelvingLogSalix>>
@ -1052,13 +1018,13 @@ interface SalixService {
): Call<Any> ): Call<Any>
@PATCH("Operators/{id}") @PATCH("Operators/{id}")
fun update_operator( fun updateOperator(
@Path("id") id: Number, @Path("id") id: Number,
@Body params: Any @Body params: Any
): Call<Unit> ): Call<Unit>
@GET("Operators/{id}") @GET("Operators/{id}")
fun operator_getData( fun operatorGetData(
@Path("id") id: Number, @Path("id") id: Number,
@Query("filter") filter: String @Query("filter") filter: String
): Call<OperatorSalix> ): Call<OperatorSalix>
@ -1085,7 +1051,7 @@ interface SalixService {
@POST("TicketCollections/update") @POST("TicketCollections/update")
fun ticketCollectionUpdate( fun ticketCollectionUpdate(
@Query("where") filter: Any,//revisar si con Any vale, update generalmente pongo json (ejemplo: itemShelvingReset) @Query("where") filter: Any,
@Body params: Any @Body params: Any
): Call<Unit> ): Call<Unit>
@ -1111,15 +1077,10 @@ interface SalixService {
): Call<Any> ): Call<Any>
@POST("ItemShelvingSales/itemShelvingSale_addByCollection") @POST("ItemShelvingSales/itemShelvingSale_addByCollection")
fun itemShelvingSale_addByCollection( fun itemShelvingSaleAddByCollection(
@Body params: Any, @Body params: Any,
): Call<Any> ): Call<Any>
/* @POST("ItemShelvingSales/itemShelvingSale_addBySale")
fun itemShelvingSale_addBySale(
@Body params: Any,
): Call<Any>*/
@POST("ItemShelvings/getInventory") @POST("ItemShelvings/getInventory")
fun getInventoryParking( fun getInventoryParking(
@Query("parkingFrom") parkingFrom: String, @Query("parkingTo") parkingTo: String @Query("parkingFrom") parkingFrom: String, @Query("parkingTo") parkingTo: String

View File

@ -32,6 +32,7 @@ import es.verdnatura.presentation.base.BaseFragment
import es.verdnatura.presentation.common.OnTrashItemRowClickListener import es.verdnatura.presentation.common.OnTrashItemRowClickListener
import es.verdnatura.presentation.common.OnWorkFormsItemRowClickListener import es.verdnatura.presentation.common.OnWorkFormsItemRowClickListener
import es.verdnatura.presentation.view.component.CustomDialog import es.verdnatura.presentation.view.component.CustomDialog
import es.verdnatura.presentation.view.component.CustomDialogInput
import es.verdnatura.presentation.view.component.CustomDialogInputThreeValues import es.verdnatura.presentation.view.component.CustomDialogInputThreeValues
import es.verdnatura.presentation.view.component.CustomDialogList import es.verdnatura.presentation.view.component.CustomDialogList
import es.verdnatura.presentation.view.feature.login.adapter.WorkFormAdapter import es.verdnatura.presentation.view.feature.login.adapter.WorkFormAdapter
@ -44,6 +45,7 @@ import kotlin.system.exitProcess
class LoginFragment(private var imageUri: Uri?) : class LoginFragment(private var imageUri: Uri?) :
BaseFragment<FragmentLoginBinding, LoginViewModel>(LoginViewModel::class) { BaseFragment<FragmentLoginBinding, LoginViewModel>(LoginViewModel::class) {
private lateinit var customDialogInput: CustomDialogInput
private lateinit var customDialog: CustomDialog private lateinit var customDialog: CustomDialog
private lateinit var customNewForm: CustomDialogInputThreeValues private lateinit var customNewForm: CustomDialogInputThreeValues
private var workFormAdapter: WorkFormAdapter? = null private var workFormAdapter: WorkFormAdapter? = null
@ -60,6 +62,7 @@ class LoginFragment(private var imageUri: Uri?) :
customDialogList = CustomDialogList(requireContext()) customDialogList = CustomDialogList(requireContext())
customDialog = CustomDialog(requireContext()) customDialog = CustomDialog(requireContext())
customDialogInput = CustomDialogInput(requireContext())
//createFolderSerial() //createFolderSerial()
saveIdentifiers() saveIdentifiers()
checkUser() checkUser()
@ -466,25 +469,24 @@ class LoginFragment(private var imageUri: Uri?) :
if (it.isError) { if (it.isError) {
saveTokenPref("", 0) saveTokenPref("", 0)
customDialog.setTitle(getString(R.string.error)) if (it.errorMessage.contains("REQUIRES_2FA")) {
showInputCode()
} else {
customDialog.setTitle(getString(R.string.error))
.setDescription( .setDescription(
if (it.errorMessage.contains("Unauthorized")) { when {
getString(R.string.messageUserError) it.errorMessage.contains("Unauthorized") -> getString(R.string.messageUserError)
} else { it.errorMessage.contains("Unable to resolve") -> getString(R.string.messageInternetError)
if (it.errorMessage.contains("Unable to resolve")) { else -> it.errorMessage
getString(R.string.messageInternetError)
} else {
it.errorMessage
} }
).setOkButton(
getString(R.string.accept)
) {
customDialog.dismiss()
} }.show()
).setOkButton( }
getString(R.string.accept)
) {
customDialog.dismiss()
}.show()
} else { } else {
saveTokenPref(it.token, it.ttl) saveTokenPref(it.token, it.ttl)
app.userName = binding.edittextUsername.text.toString() app.userName = binding.edittextUsername.text.toString()
@ -533,6 +535,23 @@ class LoginFragment(private var imageUri: Uri?) :
super.observeViewModel() super.observeViewModel()
} }
private fun showInputCode() {
customDialogInput.setTitle(getString(R.string.messageTwoFactorTitle))
.setDescription(
getString(R.string.messageTwoFactor)
).setOkButton(
getString(R.string.validate)
) {
customDialogInput.dismiss()
viewModel.validateAuth(
user = binding.edittextUsername.text.toString(),
password = binding.edittextPassword.text.toString(),
code = customDialogInput.getValue())
}.show()
}
private fun setupFirebase(userName: String) { private fun setupFirebase(userName: String) {
Firebase.crashlytics.setUserId(userName) Firebase.crashlytics.setUserId(userName)
} }

View File

@ -80,37 +80,56 @@ class LoginViewModel(val context: Context) : BaseViewModel(context) {
.enqueue(object : SalixCallback<LoginSalixVO>(context) { .enqueue(object : SalixCallback<LoginSalixVO>(context) {
override fun onSuccess(response: Response<LoginSalixVO>) { override fun onSuccess(response: Response<LoginSalixVO>) {
val loginSalixVO: LoginSalixVO? _loginSalixItem.value = response.body()?.let {
if (response.body() != null) { LoginSalixVO(
loginSalixVO = response.body()?.let {
LoginSalixVO(
user,
password,
it.token,
it.created,
it.ttl,
isError = false,
errorMessage = ""
)
}
} else {
loginSalixVO = LoginSalixVO(
user, user,
password, password,
isError = true, it.token,
errorMessage = getMessageFromAllResponse( it.created,
nameofFunction(this), response.message() it.ttl,
) isError = false,
errorMessage = ""
) )
} }
_loginSalixItem.value = loginSalixVO
} }
override fun onError(t: Throwable) { override fun onError(t: Throwable) {
val loginSalixVO = LoginSalixVO( _loginSalixItem.value = LoginSalixVO(
user,
password,
"",
isError = true,
errorMessage = getMessageFromAllResponse(
nameofFunction(this), t.message!!
)
)
}
})
}
fun validateAuth(user: String, password: String, code: String) {
salix.validateAuth(user, password, code)
.enqueue(object : SalixCallback<LoginSalixVO>(context) {
override fun onSuccess(response: Response<LoginSalixVO>) {
_loginSalixItem.value = response.body()?.let {
LoginSalixVO(
user,
password,
it.token,
it.created,
it.ttl,
isError = false,
errorMessage = ""
)
}
}
override fun onError(t: Throwable) {
_loginSalixItem.value = LoginSalixVO(
user, user,
password, password,
"", "",
@ -119,7 +138,6 @@ class LoginViewModel(val context: Context) : BaseViewModel(context) {
nameofFunction(this), t.message!! nameofFunction(this), t.message!!
) )
) )
_loginSalixItem.value = loginSalixVO
} }
}) })
} }
@ -127,25 +145,23 @@ class LoginViewModel(val context: Context) : BaseViewModel(context) {
fun loginApp( fun loginApp(
login: LoginApp, login: LoginApp,
) { ) {
salix.loginApp(login) salix.loginApp(login).enqueue(object : SalixCallback<LoginAppData>(context) {
.enqueue(object : SalixCallback<LoginAppData>(context) {
override fun onSuccess(response: Response<LoginAppData>) { override fun onSuccess(response: Response<LoginAppData>) {
_loginApp.value = response.body() _loginApp.value = response.body()
} }
override fun onError(t: Throwable) { override fun onError(t: Throwable) {/* val loginSalixVO = LoginAppData(
/* val loginSalixVO = LoginAppData( user,
user, password,
password, "",
"", isError = true,
isError = true, errorMessage = getMessageFromAllResponse(
errorMessage = getMessageFromAllResponse( nameofFunction(this), t.message!!
nameofFunction(this), t.message!! )
) )
) _loginSalixItem.value = loginSalixVO*/
_loginSalixItem.value = loginSalixVO*/
} }
}) })
} }
@ -181,16 +197,16 @@ class LoginViewModel(val context: Context) : BaseViewModel(context) {
override fun onSuccess(response: Response<DataUserSalix>) { override fun onSuccess(response: Response<DataUserSalix>) {
app.userName = response.body()?.nickname app.userName = response.body()?.nickname
app.userId = response.body()?.id app.userId = response.body()?.id
deviceLog_addSalix( deviceLogAddSalix(
app = appName, app = appName,
versionApp = versionApp, versionApp = versionApp,
android_id = androidId, androidId = androidId,
userFk = app.userId!!, userFk = app.userId!!,
serialnumber = serialNumber serialnumber = serialNumber
) )
//Tarea 5870 //Tarea 5870
operator_add(app.userId) operatorAdd(app.userId)
operator_getDataSalix(app.userId!!) operatorGetData(app.userId!!)
deviceCheckLogin(app.userId!!, androidId) deviceCheckLogin(app.userId!!, androidId)
} }
}) })
@ -209,14 +225,14 @@ class LoginViewModel(val context: Context) : BaseViewModel(context) {
}) })
} }
fun deviceLog_addSalix( fun deviceLogAddSalix(
app: String, versionApp: String, android_id: String, userFk: Int, serialnumber: String? app: String, versionApp: String, androidId: String, userFk: Int, serialnumber: String?
) { ) {
//Tarea 4815 //Tarea 4815
salix.deviceLogInsert( salix.deviceLogInsert(
DeviceLogSalix( DeviceLogSalix(
android_id = android_id, android_id = androidId,
userFk = userFk, userFk = userFk,
nameApp = app, nameApp = app,
versionApp = versionApp, versionApp = versionApp,
@ -233,8 +249,7 @@ class LoginViewModel(val context: Context) : BaseViewModel(context) {
fun checkVersion(nameApp: String) { fun checkVersion(nameApp: String) {
//Tarea 6276 Modificado back //Tarea 6276 Modificado back
salix.getVersion(nameApp) salix.getVersion(nameApp).enqueue(object : SalixCallback<VersionApp>(context) {
.enqueue(object : SalixCallback<VersionApp>(context) {
override fun onSuccess(response: Response<VersionApp>) { override fun onSuccess(response: Response<VersionApp>) {
_versionappitem.value = response.body()?.let { _versionappitem.value = response.body()?.let {
@ -274,18 +289,16 @@ class LoginViewModel(val context: Context) : BaseViewModel(context) {
return list return list
} }
fun operator_add(workerFk: Int? = null) { fun operatorAdd(workerFk: Int? = null) {
//Tarea 6276 //Tarea 6276
salix.operatorAdd(OperatorAdd(workerFk!!,false)) salix.operatorAdd(OperatorAdd(workerFk!!, false))
.enqueue(object : SalixCallback<Any>(context) { .enqueue(object : SalixCallback<Any>(context) {
override fun onError(t: Throwable) { override fun onError(t: Throwable) {
if (!(t.message!!.contains("ER_DUP_ENTRY"))) if (!(t.message!!.contains("ER_DUP_ENTRY"))) _operatorAdd.value =
_operatorAdd.value = ResponseItemVO( ResponseItemVO(
isError = true, isError = true, errorMessage = getMessageFromAllResponse(
errorMessage = getMessageFromAllResponse( nameofFunction(this), t.message!!
nameofFunction(this),
t.message!!
) )
) )
} }
@ -297,12 +310,12 @@ class LoginViewModel(val context: Context) : BaseViewModel(context) {
} }
//Tarea 5870 //Tarea 5870
fun operator_getDataSalix( fun operatorGetData(
workerId: Int workerId: Int
) { ) {
val filter = val filter =
"""{"fields":["itemPackingTypeFk","numberOfWagons","sectorFk","trainFk","labelerFk","isOnReservationMode"],"include":[{"relation":"sector","scope":{"fields":["description","warehouseFk"]}},{"relation":"printer","scope":{"fields":["name"]}},{"relation":"train","scope":{"fields":["name"]}}]}""" """{"fields":["itemPackingTypeFk","numberOfWagons","sectorFk","trainFk","labelerFk","isOnReservationMode"],"include":[{"relation":"sector","scope":{"fields":["description","warehouseFk"]}},{"relation":"printer","scope":{"fields":["name"]}},{"relation":"train","scope":{"fields":["name"]}}]}"""
salix.operator_getData(id = workerId, filter) salix.operatorGetData(id = workerId, filter)
.enqueue(object : SalixCallback<OperatorSalix>(context) { .enqueue(object : SalixCallback<OperatorSalix>(context) {
override fun onError(t: Throwable) { override fun onError(t: Throwable) {