diff --git a/app/src/main/java/it/integry/integrywmsnative/core/rest/consumers/ArticoloRESTConsumer.java b/app/src/main/java/it/integry/integrywmsnative/core/rest/consumers/ArticoloRESTConsumer.java index 1ce7c8aa..e8c69d29 100644 --- a/app/src/main/java/it/integry/integrywmsnative/core/rest/consumers/ArticoloRESTConsumer.java +++ b/app/src/main/java/it/integry/integrywmsnative/core/rest/consumers/ArticoloRESTConsumer.java @@ -180,6 +180,12 @@ public class ArticoloRESTConsumer extends _BaseRESTConsumer { } + public MtbAart getByCodMartSynchronized(String codMartToFind) throws Exception { + var artList = getByCodMartsSynchronized(Collections.singletonList(codMartToFind)); + return artList != null && !artList.isEmpty() ? artList.get(0) : null; + } + + public List getArtsGroupsSynchronized(List groupsToFind) throws Exception { var whereCondMap = Stream.of(groupsToFind) .map(x -> { diff --git a/app/src/main/java/it/integry/integrywmsnative/core/rest/consumers/ColliMagazzinoRESTConsumer.java b/app/src/main/java/it/integry/integrywmsnative/core/rest/consumers/ColliMagazzinoRESTConsumer.java index 98ee2d5c..948a653f 100644 --- a/app/src/main/java/it/integry/integrywmsnative/core/rest/consumers/ColliMagazzinoRESTConsumer.java +++ b/app/src/main/java/it/integry/integrywmsnative/core/rest/consumers/ColliMagazzinoRESTConsumer.java @@ -497,17 +497,6 @@ public class ColliMagazzinoRESTConsumer extends _BaseRESTConsumer { var value = saveColloSynchronized(cloneMtbColt); } - public void updateDataFine(MtbColt mtbColt, Runnable onComplete, RunnableArgs onFailed) { - executorService.execute(() -> { - try { - synchronousUpdateDataFine(mtbColt); - if (onComplete != null) onComplete.run(); - } catch (Exception ex) { - if (onFailed != null) onFailed.run(ex); - } - }); - } - public void retrieveBasketColli(RunnableArgs> onComplete, RunnableArgs onFailed) { ColliMagazzinoRESTConsumerService colliMagazzinoRESTConsumerService = restBuilder.getService(ColliMagazzinoRESTConsumerService.class); @@ -526,7 +515,7 @@ public class ColliMagazzinoRESTConsumer extends _BaseRESTConsumer { }); } - public void creaRettificaCollo(MtbColr sourceMtbColrOriginal, BigDecimal newNumCnf, BigDecimal newQtaTot, RunnableArgs onComplete, RunnableArgs onFailed) { + public MtbColr creaRettificaColloSynchronized(MtbColr sourceMtbColrOriginal, BigDecimal newNumCnf, BigDecimal newQtaTot) throws Exception { MtbColr sourceMtbColr = (MtbColr) sourceMtbColrOriginal.clone(); sourceMtbColr.setMtbPartitaMag(null); sourceMtbColr.setMtbAart(null); @@ -537,18 +526,22 @@ public class ColliMagazzinoRESTConsumer extends _BaseRESTConsumer { .setNewQtaCol(newQtaTot); ColliMagazzinoRESTConsumerService colliMagazzinoRESTConsumerService = restBuilder.getService(ColliMagazzinoRESTConsumerService.class); - colliMagazzinoRESTConsumerService.creaRettificaCollo( + var response = colliMagazzinoRESTConsumerService.creaRettificaCollo( SettingsManager.i().getUserSession().getDepo().getCodMdep(), rettificaULDTO - ).enqueue(new ManagedErrorCallback<>() { - @Override - public void onResponse(Call> call, Response> response) { - analyzeAnswer(response, "creaRettificaCollo", onComplete, onFailed); - } + ).execute(); - @Override - public void onFailure(Call> call, @NonNull final Exception e) { - if (onFailed != null) onFailed.run(e); + var data = analyzeAnswer(response, "creaRettificaCollo"); + return data; + } + + public void creaRettificaCollo(MtbColr sourceMtbColrOriginal, BigDecimal newNumCnf, BigDecimal newQtaTot, RunnableArgs onComplete, RunnableArgs onFailed) { + executorService.execute(() -> {; + try { + var result = creaRettificaColloSynchronized(sourceMtbColrOriginal, newNumCnf, newQtaTot); + if (onComplete != null) onComplete.run(result); + } catch (Exception ex) { + if (onFailed != null) onFailed.run(ex); } }); } @@ -664,25 +657,14 @@ public class ColliMagazzinoRESTConsumer extends _BaseRESTConsumer { }); } - public void confirmGiacenzaUL(MtbColt sourceMtbColt, Runnable onComplete, RunnableArgs onFailed) { + public void confirmGiacenzaULSynchronized(MtbColt sourceMtbColt) throws Exception { MtbColt sourceMtbColtClone = (MtbColt) sourceMtbColt.clone(); sourceMtbColtClone.setMtbColr(new ObservableArrayList<>()); ColliMagazzinoRESTConsumerService colliMagazzinoRESTConsumerService = restBuilder.getService(ColliMagazzinoRESTConsumerService.class); - colliMagazzinoRESTConsumerService.confirmGiacenzaUL(sourceMtbColtClone).enqueue(new ManagedErrorCallback<>() { - @Override - public void onResponse(Call> call, Response> response) { - analyzeAnswer(response, "confirmGiacenzaUL", data -> { - onComplete.run(); + var response = colliMagazzinoRESTConsumerService.confirmGiacenzaUL(sourceMtbColtClone).execute(); - }, onFailed); - } - - @Override - public void onFailure(Call> call, @NonNull final Exception e) { - if (onFailed != null) onFailed.run(e); - } - }); + analyzeAnswer(response, "confirmGiacenzaUL"); } public MtbColr makeSynchronousRetrieveShipmentUlFromProductionUlRequest(String barcodeUl) throws Exception { diff --git a/app/src/main/java/it/integry/integrywmsnative/core/rest/consumers/ColliMagazzinoRESTConsumerService.java b/app/src/main/java/it/integry/integrywmsnative/core/rest/consumers/ColliMagazzinoRESTConsumerService.java index 90ee3d06..467b47f3 100644 --- a/app/src/main/java/it/integry/integrywmsnative/core/rest/consumers/ColliMagazzinoRESTConsumerService.java +++ b/app/src/main/java/it/integry/integrywmsnative/core/rest/consumers/ColliMagazzinoRESTConsumerService.java @@ -55,7 +55,7 @@ public interface ColliMagazzinoRESTConsumerService { Call> versamentoAutomaticoUL(@Body MtbColt mtbColt); @POST("wms/confirmGiacenzaUL") - Call> confirmGiacenzaUL(@Body MtbColt mtbColt); + Call> confirmGiacenzaUL(@Body MtbColt mtbColt); @POST("wms/generic/canULBeDeleted") diff --git a/app/src/main/java/it/integry/integrywmsnative/gest/rettifica_giacenze/RettificaGiacenzeFragment.java b/app/src/main/java/it/integry/integrywmsnative/gest/rettifica_giacenze/RettificaGiacenzeFragment.java index 944e8008..8dad03c4 100644 --- a/app/src/main/java/it/integry/integrywmsnative/gest/rettifica_giacenze/RettificaGiacenzeFragment.java +++ b/app/src/main/java/it/integry/integrywmsnative/gest/rettifica_giacenze/RettificaGiacenzeFragment.java @@ -242,13 +242,21 @@ public class RettificaGiacenzeFragment extends BaseFragment implements ITitledFr private final RunnableArgs onScanSuccessful = data -> { this.onLoadingStarted(); - this.mViewModel.processBarcodeDTO(data, this::onLoadingEnded); + executorService.execute(() -> { + try { + this.mViewModel.processBarcodeDTO(data); + this.onLoadingEnded(); + } catch (Exception e) { + this.onError(e); + } + }); + }; public void setUIToForn() { mBinding.rettificaGiacenzeFornCheckBox.setChecked(true); - mBinding.rettificaGiacenzeFornLayout.setBackgroundTintList(ColorStateList.valueOf(getActivity().getResources().getColor(R.color.alpha_blue_500))); + mBinding.rettificaGiacenzeFornLayout.setBackgroundTintList(ColorStateList.valueOf(requireActivity().getResources().getColor(R.color.alpha_blue_500))); mBinding.rettificaGiacenzeArtIntCheckBox.setChecked(false); mBinding.rettificaGiacenzeArtIntLayout.setBackgroundTintList(null); @@ -264,7 +272,7 @@ public class RettificaGiacenzeFragment extends BaseFragment implements ITitledFr public void setUIToIntArt() { mBinding.rettificaGiacenzeArtIntCheckBox.setChecked(true); - mBinding.rettificaGiacenzeArtIntLayout.setBackgroundTintList(ColorStateList.valueOf(getActivity().getResources().getColor(R.color.alpha_blue_500))); + mBinding.rettificaGiacenzeArtIntLayout.setBackgroundTintList(ColorStateList.valueOf(requireActivity().getResources().getColor(R.color.alpha_blue_500))); mBinding.rettificaGiacenzeFornCheckBox.setChecked(false); mBinding.rettificaGiacenzeFornLayout.setBackgroundTintList(null); @@ -274,11 +282,23 @@ public class RettificaGiacenzeFragment extends BaseFragment implements ITitledFr mBinding.inputCodArtDescrInt.requestFocusFromTouch(); } + public void closeLU(boolean saveCausale) { + executorService.execute(() -> { + this.onLoadingStarted(); + try { + mViewModel.closeLU(saveCausale, true); + this.onLoadingEnded(); + } catch (Exception e) { + this.onError(e); + } + }); + } + @Override public void onFornitoriLoaded(ArrayList fornitoriList) { handler.post(() -> { - AutoCompleteFornitoreAdapter autoCompleteFornitoreAdapter = new AutoCompleteFornitoreAdapter(getActivity(), fornitoriList); + AutoCompleteFornitoreAdapter autoCompleteFornitoreAdapter = new AutoCompleteFornitoreAdapter(requireActivity(), fornitoriList); mBinding.autoCompleteFornitori.setAdapter(autoCompleteFornitoreAdapter); mBinding.autoCompleteFornitori.setDropDownWidth(getActivity().getResources().getDisplayMetrics().widthPixels); @@ -296,9 +316,15 @@ public class RettificaGiacenzeFragment extends BaseFragment implements ITitledFr return true; } - mViewModel.searchArtFor( - mBinding.autoCompleteFornitori.getText().toString(), - mBinding.inputCodArtDescrForn.getText().toString()); + executorService.execute(() -> { + try { + mViewModel.searchArtFor( + mBinding.autoCompleteFornitori.getText().toString(), + mBinding.inputCodArtDescrForn.getText().toString()); + } catch (Exception e) { + this.onError(e); + } + }); return true; } return false; @@ -314,7 +340,13 @@ public class RettificaGiacenzeFragment extends BaseFragment implements ITitledFr return true; } - mViewModel.searchArtInt(mBinding.inputCodArtDescrInt.getText().toString(), null, null); + executorService.execute(() -> { + try { + mViewModel.searchArtInt(mBinding.inputCodArtDescrInt.getText().toString(), null); + } catch (Exception e) { + this.onError(e); + } + }); return true; } return false; @@ -326,7 +358,13 @@ public class RettificaGiacenzeFragment extends BaseFragment implements ITitledFr public void onRequestNewArtCreation(String description, BarcodeScanDTO barcode) { DialogCreateNewArtView.newInstance(description, barcode, currentMtbColtObs.get().getPosizione(), createdCodMart -> { - mViewModel.searchArtInt(createdCodMart, null, null); + executorService.execute(() -> { + try { + mViewModel.searchArtInt(createdCodMart, null); + } catch (Exception e) { + throw new RuntimeException(e); + } + }); }) .show(requireActivity().getSupportFragmentManager(), "tag"); } @@ -359,14 +397,14 @@ public class RettificaGiacenzeFragment extends BaseFragment implements ITitledFr } @Override - public void onLUClosed() { + public void onLUClosed(boolean requestNewLu) { handler.post(() -> { destroyAdapter(); this.currentMtbColtObs.set(null); thereIsAnOpenedUL.set(false); - this.mViewModel.requestLU(); + if(requestNewLu) this.mViewModel.requestLU(); /*if (getActivity() != null) ((IPoppableActivity) getActivity()).pop();*/ }); } @@ -416,7 +454,7 @@ public class RettificaGiacenzeFragment extends BaseFragment implements ITitledFr boolean canOverflowOrderQuantity, boolean canPartitaMagBeChanged, boolean canLUBeClosed, - RunnableArgss onComplete) { + RunnableArgs onComplete) { DialogInputQuantityV2DTO dialogInputQuantityV2DTO = new DialogInputQuantityV2DTO() .setMtbAart(mtbAart) @@ -444,16 +482,20 @@ public class RettificaGiacenzeFragment extends BaseFragment implements ITitledFr mDialogInputQuantityV2View .setDialogInputQuantityV2DTO(dialogInputQuantityV2DTO) .setOnComplete(resultDTO -> { - if (resultDTO == null || resultDTO.isAborted()) return; + if (resultDTO == null || resultDTO.isAborted()) { + onComplete.run(null); + return; + }; PickedQuantityDTO pickedQuantityDTO = new PickedQuantityDTO() .setNumCnf(resultDTO.getNumCnf()) .setQtaCnf(resultDTO.getQtaCnf()) .setQtaTot(resultDTO.getQtaTot()) .setPartitaMag(resultDTO.getPartitaMag()) - .setDataScad(resultDTO.getDataScad()); + .setDataScad(resultDTO.getDataScad()) + .setShouldCloseLu(resultDTO.isShouldCloseLu()); - onComplete.run(pickedQuantityDTO, resultDTO.isShouldCloseLu()); + onComplete.run(pickedQuantityDTO); }) .show(requireActivity().getSupportFragmentManager(), "tag"); }, () -> { @@ -508,7 +550,15 @@ public class RettificaGiacenzeFragment extends BaseFragment implements ITitledFr @Override public void onMtbColrEdit(MtbColr mtbColr) { - this.mViewModel.dispatchRowEdit(mtbColr); + executorService.execute(() -> { + this.onLoadingStarted(); + try { + this.mViewModel.dispatchRowEdit(mtbColr); + this.onLoadingEnded(); + } catch (Exception e) { + this.onError(e); + } + }); } @Override @@ -605,7 +655,18 @@ public class RettificaGiacenzeFragment extends BaseFragment implements ITitledFr @Override public void onPreDestroy(Runnable onComplete) { if (mViewModel.getCurrentMtbColt() != null) - mViewModel.closeLU(false); + executorService.execute(() -> { + try { + this.onLoadingStarted(); + + mViewModel.closeLU(false, false); + + this.onLoadingEnded(); + onComplete.run(); + } catch (Exception e) { + this.onError(e); + } + }); else { BarcodeManager.removeCallback(mBarcodeScannerInstanceID); onComplete.run(); diff --git a/app/src/main/java/it/integry/integrywmsnative/gest/rettifica_giacenze/RettificaGiacenzeModule.java b/app/src/main/java/it/integry/integrywmsnative/gest/rettifica_giacenze/RettificaGiacenzeModule.java index d82edd5f..dc2414ee 100644 --- a/app/src/main/java/it/integry/integrywmsnative/gest/rettifica_giacenze/RettificaGiacenzeModule.java +++ b/app/src/main/java/it/integry/integrywmsnative/gest/rettifica_giacenze/RettificaGiacenzeModule.java @@ -1,5 +1,7 @@ package it.integry.integrywmsnative.gest.rettifica_giacenze; +import android.os.Handler; + import javax.inject.Singleton; import dagger.Module; @@ -25,11 +27,12 @@ public class RettificaGiacenzeModule { @Provides @Singleton - RettificaGiacenzeViewModel providesRettificaGiacenzeViewModel(ArticoloRESTConsumer articoloRESTConsumer, + RettificaGiacenzeViewModel providesRettificaGiacenzeViewModel(Handler handler, + ArticoloRESTConsumer articoloRESTConsumer, ColliMagazzinoRESTConsumer colliMagazzinoRESTConsumer, PrinterRESTConsumer printerRESTConsumer, BarcodeRESTConsumer barcodeRESTConsumer, RettificaGiacenzeRESTConsumer rettificaGiacenzeRESTConsumer) { - return new RettificaGiacenzeViewModel(articoloRESTConsumer, colliMagazzinoRESTConsumer, printerRESTConsumer, barcodeRESTConsumer, rettificaGiacenzeRESTConsumer); + return new RettificaGiacenzeViewModel(handler, articoloRESTConsumer, colliMagazzinoRESTConsumer, printerRESTConsumer, barcodeRESTConsumer, rettificaGiacenzeRESTConsumer); } } diff --git a/app/src/main/java/it/integry/integrywmsnative/gest/rettifica_giacenze/RettificaGiacenzeViewModel.java b/app/src/main/java/it/integry/integrywmsnative/gest/rettifica_giacenze/RettificaGiacenzeViewModel.java index aecaa621..fc9240f0 100644 --- a/app/src/main/java/it/integry/integrywmsnative/gest/rettifica_giacenze/RettificaGiacenzeViewModel.java +++ b/app/src/main/java/it/integry/integrywmsnative/gest/rettifica_giacenze/RettificaGiacenzeViewModel.java @@ -1,19 +1,23 @@ package it.integry.integrywmsnative.gest.rettifica_giacenze; -import com.annimon.stream.Stream; +import android.os.Handler; +import android.util.Pair; import java.math.BigDecimal; import java.time.LocalDate; import java.util.ArrayList; import java.util.List; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.atomic.AtomicReference; +import java.util.stream.Collectors; import javax.inject.Inject; import it.integry.barcode_base_android_library.model.BarcodeScanDTO; import it.integry.integrywmsnative.core.exception.NoArtsFoundException; import it.integry.integrywmsnative.core.exception.NoResultFromBarcodeException; +import it.integry.integrywmsnative.core.exception.ScannedPositionNotExistException; import it.integry.integrywmsnative.core.expansion.RunnableArgs; -import it.integry.integrywmsnative.core.expansion.RunnableArgss; import it.integry.integrywmsnative.core.interfaces.viewmodel_listeners.ILUPositionListener; import it.integry.integrywmsnative.core.interfaces.viewmodel_listeners.ILUPrintListener; import it.integry.integrywmsnative.core.model.CommonModelConsts; @@ -35,6 +39,7 @@ import it.integry.integrywmsnative.core.utility.UtilityBigDecimal; import it.integry.integrywmsnative.core.utility.UtilityDate; import it.integry.integrywmsnative.core.utility.UtilityString; import it.integry.integrywmsnative.gest.rettifica_giacenze.dto.FornitoreDTO; +import it.integry.integrywmsnative.gest.rettifica_giacenze.dto.SearchArticoloByCodArtFornOrDescrizioneResponseDTO; import it.integry.integrywmsnative.gest.rettifica_giacenze.rest.RettificaGiacenzeRESTConsumer; import it.integry.integrywmsnative.gest.spedizione.exceptions.InvalidPesoKGException; import it.integry.integrywmsnative.gest.spedizione.model.PickedQuantityDTO; @@ -45,6 +50,7 @@ public class RettificaGiacenzeViewModel { public MtbColt mCurrentMtbColt = null; + private final Handler handler; private final ArticoloRESTConsumer mArticoloRESTConsumer; private final ColliMagazzinoRESTConsumer mColliMagazzinoRESTConsumer; private final PrinterRESTConsumer mPrinterRESTConsumer; @@ -63,11 +69,13 @@ public class RettificaGiacenzeViewModel { private boolean mAnyEditDone = false; @Inject - public RettificaGiacenzeViewModel(ArticoloRESTConsumer articoloRESTConsumer, + public RettificaGiacenzeViewModel(Handler handler, + ArticoloRESTConsumer articoloRESTConsumer, ColliMagazzinoRESTConsumer colliMagazzinoRESTConsumer, PrinterRESTConsumer printerRESTConsumer, BarcodeRESTConsumer barcodeRESTConsumer, RettificaGiacenzeRESTConsumer rettificaGiacenzeRESTConsumer) { + this.handler = handler; this.mArticoloRESTConsumer = articoloRESTConsumer; this.mColliMagazzinoRESTConsumer = colliMagazzinoRESTConsumer; this.mPrinterRESTConsumer = printerRESTConsumer; @@ -111,107 +119,102 @@ public class RettificaGiacenzeViewModel { } - public void processBarcodeDTO(BarcodeScanDTO barcodeScanDTO, Runnable onComplete) { + public void processBarcodeDTO(BarcodeScanDTO barcodeScanDTO) throws Exception { if (UtilityBarcode.isEtichettaPosizione(barcodeScanDTO)) { //Not implemented now - onComplete.run(); + return; + } else if (UtilityBarcode.isEtichetta128(barcodeScanDTO)) { //Cerco tramite etichetta ean 128 (che può indicarmi un articolo o una UL) - this.executeEtichettaEan128(barcodeScanDTO, onComplete); + this.executeEtichettaEan128(barcodeScanDTO); } else if (UtilityBarcode.isEanPeso(barcodeScanDTO)) { //Cerco tramite articolo ean peso - this.executeEtichettaEanPeso(barcodeScanDTO, onComplete); + this.executeEtichettaEanPeso(barcodeScanDTO); } else if (UtilityBarcode.isEtichettaArt(barcodeScanDTO)) { - this.searchArtInt(null, barcodeScanDTO, onComplete); + this.searchArtInt(null, barcodeScanDTO); - } else { - onComplete.run(); } } - private void executeEtichettaEan128(BarcodeScanDTO barcodeScanDTO, Runnable onComplete) { - mBarcodeRESTConsumer.decodeEan128(barcodeScanDTO, ean128Model -> { - - String barcodeProd = null; - String codMart = null; - - if (!UtilityString.isNullOrEmpty(ean128Model.Sscc)) barcodeProd = ean128Model.Sscc; - if (!UtilityString.isNullOrEmpty(ean128Model.Gtin)) barcodeProd = ean128Model.Gtin; - if (!UtilityString.isNullOrEmpty(ean128Model.Content)) - barcodeProd = ean128Model.Content; - - if (!UtilityString.isNullOrEmpty(ean128Model.Internal1)) - codMart = ean128Model.Internal1; + private void executeEtichettaEan128(BarcodeScanDTO barcodeScanDTO) throws Exception { + var ean128Model = mBarcodeRESTConsumer.decodeEan128Synchronized(barcodeScanDTO); - if (!UtilityString.isNullOrEmpty(barcodeProd)) { + String barcodeProd = null; + String codMart = null; + + if (!UtilityString.isNullOrEmpty(ean128Model.Sscc)) barcodeProd = ean128Model.Sscc; + if (!UtilityString.isNullOrEmpty(ean128Model.Gtin)) barcodeProd = ean128Model.Gtin; + if (!UtilityString.isNullOrEmpty(ean128Model.Content)) + barcodeProd = ean128Model.Content; + + if (!UtilityString.isNullOrEmpty(ean128Model.Internal1)) + codMart = ean128Model.Internal1; + + + if (!UtilityString.isNullOrEmpty(barcodeProd)) { + PickDataDTO pickDataDTO = PickDataDTO.fromEan128(ean128Model); + this.loadArticolo(barcodeProd, pickDataDTO, barcodeScanDTO); + + } else if (!UtilityString.isNullOrEmpty(codMart)) { + this.searchArtInt(codMart, barcodeScanDTO); + + } + - PickDataDTO pickDataDTO = PickDataDTO.fromEan128(ean128Model); - this.loadArticolo(barcodeProd, pickDataDTO, barcodeScanDTO, onComplete); - } else if (!UtilityString.isNullOrEmpty(codMart)) { - this.searchArtInt(codMart, barcodeScanDTO, onComplete); - } else { - //EAN 128 non completo o comunque mancano i riferimenti al prodotto - onComplete.run(); - } - }, this::sendError); } - private void executeEtichettaEanPeso(BarcodeScanDTO barcodeScanDTO, Runnable onComplete) { + private void executeEtichettaEanPeso(BarcodeScanDTO barcodeScanDTO) { try { Ean13PesoModel ean13PesoModel = Ean13PesoModel.fromBarcode(barcodeScanDTO.getStringValue()); - this.loadArticolo(ean13PesoModel.getPrecode(), PickDataDTO.fromEan128(ean13PesoModel.toEan128()), barcodeScanDTO, onComplete); + this.loadArticolo(ean13PesoModel.getPrecode(), PickDataDTO.fromEan128(ean13PesoModel.toEan128()), barcodeScanDTO); } catch (Exception ex) { this.sendError(ex); } } - private void loadArticolo(String barcodeProd, PickDataDTO pickData, BarcodeScanDTO barcodeScanDTO, Runnable onComplete) { - this.mArticoloRESTConsumer.searchByBarcode(barcodeProd, mtbAartList -> { - if (onComplete != null) onComplete.run(); + private void loadArticolo(String barcodeProd, PickDataDTO pickData, BarcodeScanDTO barcodeScanDTO) throws Exception { + var mtbAartList = this.mArticoloRESTConsumer.searchByBarcodeSynchronized(barcodeProd); - if (mtbAartList != null && !mtbAartList.isEmpty()) { - this.dispatchArts(mtbAartList, pickData, null, barcodeScanDTO); - } else { - this.sendError(new NoResultFromBarcodeException(barcodeProd)); - } - - }, this::sendError); + if (mtbAartList != null && !mtbAartList.isEmpty()) { + this.dispatchArts(mtbAartList, pickData, null, barcodeScanDTO); + } else { + this.sendError(new NoResultFromBarcodeException(barcodeProd)); + } } - public void searchArtFor(String codAlis, String queryText) { + public void searchArtFor(String codAlis, String queryText) throws Exception { this.sendOnLoadingStarted(); - mRettificaGiacenzeRESTConsumer.searchArtForn(codAlis, queryText, listaArts -> { - this.sendOnLoadingEnded(); + var listaArts = mRettificaGiacenzeRESTConsumer.searchArtFornSynchronized(codAlis, queryText); - List mtbAarts = null; - if (listaArts != null) - mtbAarts = Stream.of(listaArts) - .map(x -> (MtbAart) x.getMtbAart()) - .toList(); + this.sendOnLoadingEnded(); - dispatchArts(mtbAarts, null, queryText, null); - }, this::sendError); + List mtbAarts = null; + + if (listaArts != null) + mtbAarts = listaArts.stream() + .map(SearchArticoloByCodArtFornOrDescrizioneResponseDTO::getMtbAart) + .collect(Collectors.toList()); + + dispatchArts(mtbAarts, null, queryText, null); } - public void searchArtInt(String queryText, BarcodeScanDTO barcodeScanDTO, Runnable onComplete) { + public void searchArtInt(String queryText, BarcodeScanDTO barcodeScanDTO) throws Exception { this.sendOnLoadingStarted(); String barcode = barcodeScanDTO != null ? barcodeScanDTO.getStringValue() : null; - mRettificaGiacenzeRESTConsumer.searchArtInt(UtilityString.isNull(queryText, barcode), listaArts -> { - this.sendOnLoadingEnded(); + var listaArts = mRettificaGiacenzeRESTConsumer.searchArtIntSynchronized(UtilityString.isNull(queryText, barcode)); - dispatchArts(listaArts, null, queryText, barcodeScanDTO); + this.sendOnLoadingEnded(); - if (onComplete != null) onComplete.run(); - }, this::sendError); + dispatchArts(listaArts, null, queryText, barcodeScanDTO); } - private void dispatchArts(List artsList, PickDataDTO pickData, String description, BarcodeScanDTO barcodeProd) { + private void dispatchArts(List artsList, PickDataDTO pickData, String description, BarcodeScanDTO barcodeProd) throws Exception { if (artsList == null || artsList.isEmpty()) { if (SettingsManager.iDB().isFlagEnableArtCreation()) this.sendRequestNewArtCreation(description, barcodeProd); @@ -220,29 +223,31 @@ public class RettificaGiacenzeViewModel { return; } - RunnableArgs dispatchArtRunnable = mtbAart -> { - - var matchRows = Stream.of(this.mCurrentMtbColt.getMtbColr()) - .filter(x -> x.getCodMart().equalsIgnoreCase(mtbAart.getCodMart())) - .toList(); - - if (matchRows.size() != 1) { - dispatchArt(mtbAart, pickData); - } else { - dispatchRowEdit(matchRows.get(0)); - } - - }; + MtbAart selectedArt = null; if (artsList.size() == 1) { - dispatchArtRunnable.run(artsList.get(0)); + selectedArt = artsList.get(0); } else { - this.sendOnArtListLoaded(new ArrayList<>(artsList), dispatchArtRunnable); + selectedArt = this.sendOnArtListLoaded(new ArrayList<>(artsList)); } + + + MtbAart finalSelectedArt = selectedArt; + var matchRows = this.mCurrentMtbColt.getMtbColr().stream() + .filter(x -> x.getCodMart().equalsIgnoreCase(finalSelectedArt.getCodMart())) + .collect(Collectors.toList()); + + if (matchRows.size() != 1) { + dispatchArt(selectedArt, pickData); + } else { + dispatchRowEdit(matchRows.get(0)); + } + + } - public void dispatchArt(MtbAart mtbAart, PickDataDTO pickDataDTO) { + public void dispatchArt(MtbAart mtbAart, PickDataDTO pickDataDTO) throws Exception { PickingObjectDTO pickingObjectDTO = new PickingObjectDTO() .setMtbAart(mtbAart) .setTempPickData(pickDataDTO); @@ -320,7 +325,7 @@ public class RettificaGiacenzeViewModel { dataScad.plusDays(pickingObjectDTO.getMtbAart().getGgScadPartita()); } - this.sendOnItemDispatched( + var pickedQuantityDTO = this.sendOnItemDispatched( pickingObjectDTO, pickingObjectDTO.getMtbAart(), initialNumCnf, @@ -337,20 +342,25 @@ public class RettificaGiacenzeViewModel { dataScad, false, canPartitaMagBeChanged, - true, - (pickedQuantityDTO, shouldCloseLU) -> { - this.saveNewRow(pickingObjectDTO, - pickedQuantityDTO.getNumCnf(), - pickedQuantityDTO.getQtaCnf(), - pickedQuantityDTO.getQtaTot(), - pickedQuantityDTO.getPartitaMag(), - pickedQuantityDTO.getDataScad(), - shouldCloseLU); - }); + true); + + + if (pickedQuantityDTO == null) { + return; + } + + this.saveNewRow(pickingObjectDTO, + pickedQuantityDTO.getNumCnf(), + pickedQuantityDTO.getQtaCnf(), + pickedQuantityDTO.getQtaTot(), + pickedQuantityDTO.getPartitaMag(), + pickedQuantityDTO.getDataScad(), + pickedQuantityDTO.isShouldCloseLu()); + } - public void saveNewRow(PickingObjectDTO pickingObjectDTO, BigDecimal numCnf, BigDecimal qtaCnf, BigDecimal qtaTot, String partitaMag, LocalDate dataScad, boolean shouldCloseLU) { + public void saveNewRow(PickingObjectDTO pickingObjectDTO, BigDecimal numCnf, BigDecimal qtaCnf, BigDecimal qtaTot, String partitaMag, LocalDate dataScad, boolean shouldCloseLU) throws Exception { this.sendOnLoadingStarted(); final MtbColr mtbColr = new MtbColr() @@ -375,215 +385,198 @@ public class RettificaGiacenzeViewModel { .setPosizioneIn(mCurrentMtbColt.getPosizione()) .setCodMdepIn(mCurrentMtbColt.getCodMdep()); + var savedMtbColr = mColliMagazzinoRESTConsumer.creaRettificaColloSynchronized(mtbColr, numCnf, qtaTot); + MtbAart mtbAart = mArticoloRESTConsumer.getByCodMartSynchronized(savedMtbColr.getCodMart()); - mColliMagazzinoRESTConsumer.creaRettificaCollo(mtbColr, - numCnf, - qtaTot, - savedMtbColr -> { - mtbColr - .setQtaCol(savedMtbColr.getQtaCol()) - .setQtaCnf(savedMtbColr.getQtaCnf()) - .setNumCnf(savedMtbColr.getNumCnf()) - .setUntMis(pickingObjectDTO.getMtbAart().getUntMis()) - .setMtbAart(pickingObjectDTO.getMtbAart()); + mtbColr + .setQtaCol(savedMtbColr.getQtaCol()) + .setQtaCnf(savedMtbColr.getQtaCnf()) + .setNumCnf(savedMtbColr.getNumCnf()) + .setUntMis(mtbAart.getUntMis()) + .setMtbAart(mtbAart); - mCurrentMtbColt.getMtbColr().add(mtbColr); - - this.mAnyEditDone = true; - - this.sendOnRowSaved(); - this.sendOnLoadingEnded(); - - if (shouldCloseLU) closeLU(true, null); - }, this::sendError); - } - - - public void closeLU(boolean saveCausale) { - closeLU(saveCausale, null); - } - - public void closeLU(boolean saveCausale, Runnable onComplete) { - if (mCurrentMtbColt == null) { - if (onComplete != null) onComplete.run(); - return; - } - - this.sendOnLoadingStarted(); - - this.mColliMagazzinoRESTConsumer.canULBeDeleted(mCurrentMtbColt, canBeDeleted -> { - - if (canBeDeleted) { - deleteLU(() -> { - this.sendLUClosed(); - this.sendOnLoadingEnded(); - }); - } else { - - Runnable saveAction = () -> { - this.mColliMagazzinoRESTConsumer.updateDataFine( - mCurrentMtbColt, () -> { - - this.askPostionChange(mCurrentMtbColt, () -> { - this.createDoc(mCurrentMtbColt, () -> { - this.mAnyEditDone = false; - postSaveBehaviour(onComplete); - }); - }); - - }, this::sendError); - }; - - if (saveCausale || mAnyEditDone) { - this.saveCausaleRettificaGiacenze(saveAction); - } else { - saveAction.run(); - } - - } - - }, this::sendError); - } - - - private void askPostionChange(MtbColt mtbColt, Runnable onComplete) { - if (mtbColt.getGestioneEnum() == GestioneEnum.VENDITA || mtbColt.getSegno() == -1 || !SettingsManager.iDB().isFlagPositionChangeRequest()) { - onComplete.run(); - return; - } - - - this.sendLUPositionChangeRequest((shouldChangePosition, mtbDepoPosizione) -> { - if (shouldChangePosition) { - this.savePosizione(mtbDepoPosizione, onComplete); - } else { - onComplete.run(); - } + handler.post(() -> { + mCurrentMtbColt.getMtbColr().add(mtbColr); }); + + this.mAnyEditDone = true; + + this.sendOnRowSaved(); + + if (shouldCloseLU) closeLU(true, true); + + this.sendOnLoadingEnded(); } - private void createDoc(MtbColt mtbColt, Runnable onComplete) { - if (!(mtbColt.getGestioneEnum() == GestioneEnum.VENDITA && mtbColt.getSegno() == -1) || !generaDocIfVendita) { - onComplete.run(); + + public void closeLU(boolean saveCausale, boolean requestNewLu) throws Exception { + if (mCurrentMtbColt == null) { return; } - mRettificaGiacenzeRESTConsumer.saveDoc(this.mCurrentMtbColt, onComplete, this::sendError); - } + var canBeDeleted = this.mColliMagazzinoRESTConsumer.canULBeDeletedSynchronized(mCurrentMtbColt); - private void saveCausaleRettificaGiacenze(Runnable onComplete) { - this.mColliMagazzinoRESTConsumer.confirmGiacenzaUL(mCurrentMtbColt, onComplete, this::sendError); - } - private void savePosizione(MtbDepoPosizione mtbDepoPosizione, Runnable onComplete) { - this.mColliMagazzinoRESTConsumer.updatePosizioneUL(mCurrentMtbColt.getBarcodeUl(), mtbDepoPosizione != null ? mtbDepoPosizione.getPosizione() : CommonModelConsts.ENTITY_NULL_STRING, - onComplete, - this::sendError); - } + if (canBeDeleted) { + deleteLU(); + + this.sendLUClosed(requestNewLu); - private void postSaveBehaviour(Runnable onComplete) { - if (!mCurrentMtbColt.getDisablePrint()) { - printLU(() -> { - this.mCurrentMtbColt = null; - this.sendLUClosed(); - this.sendOnLoadingEnded(); - if (onComplete != null) onComplete.run(); - }); } else { - this.mCurrentMtbColt = null; - this.sendLUClosed(); - this.sendOnLoadingEnded(); - if (onComplete != null) onComplete.run(); + + if (saveCausale || mAnyEditDone) { + this.saveCausaleRettificaGiacenze(); + } + + this.mColliMagazzinoRESTConsumer.synchronousUpdateDataFine(mCurrentMtbColt); + + this.askPostionChange(mCurrentMtbColt); + + this.createDoc(mCurrentMtbColt); + this.mAnyEditDone = false; + + postSaveBehaviour(requestNewLu); } + + } - private void deleteLU(Runnable onComplete) { + + private void askPostionChange(MtbColt mtbColt) throws Exception { + if (mtbColt.getGestioneEnum() == GestioneEnum.VENDITA || mtbColt.getSegno() == -1 || !SettingsManager.iDB().isFlagPositionChangeRequest()) { + return; + } + + + var response = this.sendLUPositionChangeRequest(); + + if (response == null || !response.first) { + return; + } + + var mtbDepoPosizione = response.second; + if (mtbDepoPosizione == null) { + //Nessuna posizione trovata con questo barcode + throw new ScannedPositionNotExistException(); + } + + this.savePosizione(mtbDepoPosizione); + } + + private void createDoc(MtbColt mtbColt) throws Exception { + if (!(mtbColt.getGestioneEnum() == GestioneEnum.VENDITA && mtbColt.getSegno() == -1) || !generaDocIfVendita) { + return; + } + + mRettificaGiacenzeRESTConsumer.saveDocSynchronized(this.mCurrentMtbColt); + } + + private void saveCausaleRettificaGiacenze() throws Exception { + this.mColliMagazzinoRESTConsumer.confirmGiacenzaULSynchronized(mCurrentMtbColt); + } + + private void savePosizione(MtbDepoPosizione mtbDepoPosizione) throws Exception { + this.mColliMagazzinoRESTConsumer.updatePosizioneULSynchronized(mCurrentMtbColt.getBarcodeUl(), mtbDepoPosizione != null ? mtbDepoPosizione.getPosizione() : CommonModelConsts.ENTITY_NULL_STRING); + } + + private void postSaveBehaviour(boolean requestNewLu) { + if (!mCurrentMtbColt.getDisablePrint()) { + printLU(); + } + + this.mCurrentMtbColt = null; + this.sendLUClosed(requestNewLu); + } + + private void deleteLU() throws Exception { DeleteULRequestDTO deleteULRequestDTO = new DeleteULRequestDTO() .setMtbColt(mCurrentMtbColt); - mColliMagazzinoRESTConsumer.deleteUL(deleteULRequestDTO, () -> { - this.mCurrentMtbColt = null; - - if (onComplete != null) onComplete.run(); - }, this::sendError); + mColliMagazzinoRESTConsumer.deleteULSynchronized(deleteULRequestDTO); + this.mCurrentMtbColt = null; } - private void printLU(Runnable onComplete) { + private void printLU() { var shouldPrint = this.sendLUPrintRequest(); if (!shouldPrint) { - onComplete.run(); - } else { + return; + } - this.mPrinterRESTConsumer.printCollo(mCurrentMtbColt, () -> { - this.sendLUSuccessfullyPrinted(); - onComplete.run(); - }, ex -> this.sendLUPrintError(ex, onComplete)); + try { + this.mPrinterRESTConsumer.synchronousPrintCollo(mCurrentMtbColt); + this.sendLUSuccessfullyPrinted(); + } catch (Exception e) { + this.sendLUPrintError(e); } } - public void dispatchRowEdit(MtbColr mtbColrToUpdate) { + public void dispatchRowEdit(MtbColr mtbColrToUpdate) throws Exception { - this.mRettificaGiacenzeRESTConsumer.searchArtInt(mtbColrToUpdate.getMtbAart().getCodMart(), newMtbAartList -> { + var newMtbAartList = this.mRettificaGiacenzeRESTConsumer.searchArtIntSynchronized(mtbColrToUpdate.getMtbAart().getCodMart()); - var newMtbAart = newMtbAartList.get(0); - final PickingObjectDTO pickingObjectDTO = new PickingObjectDTO() - .setMtbAart(newMtbAart); + var newMtbAart = newMtbAartList.get(0); - this.sendOnItemDispatched( - pickingObjectDTO, - pickingObjectDTO.getMtbAart(), - mtbColrToUpdate.getNumCnf(), - mtbColrToUpdate.getQtaCnf(), - mtbColrToUpdate.getQtaCol(), - newMtbAart.getQtaEsistente(), newMtbAart.getNumCnfEsistente(), - newMtbAart.getQtaImpegnata(), newMtbAart.getNumCnfImpegnata(), - null, - null, - null, - mtbColrToUpdate.getPartitaMag(), - mtbColrToUpdate.getDataScadPartita(), - false, - false, - true, - (pickedQuantityDTO, shouldCloseLU) -> { + final PickingObjectDTO pickingObjectDTO = new PickingObjectDTO() + .setMtbAart(newMtbAart); - this.saveEditedRow(mtbColrToUpdate, - pickedQuantityDTO.getNumCnf(), - pickedQuantityDTO.getQtaCnf(), - pickedQuantityDTO.getQtaTot(), - pickedQuantityDTO.getPartitaMag(), - pickedQuantityDTO.getDataScad(), - shouldCloseLU); - }); - }, this::sendError); + var pickedQuantityDTO = this.sendOnItemDispatched( + pickingObjectDTO, + pickingObjectDTO.getMtbAart(), + mtbColrToUpdate.getNumCnf(), + mtbColrToUpdate.getQtaCnf(), + mtbColrToUpdate.getQtaCol(), + newMtbAart.getQtaEsistente(), newMtbAart.getNumCnfEsistente(), + newMtbAart.getQtaImpegnata(), newMtbAart.getNumCnfImpegnata(), + null, + null, + null, + mtbColrToUpdate.getPartitaMag(), + mtbColrToUpdate.getDataScadPartita(), + false, + false, + true); + + + if (pickedQuantityDTO == null) { + return; + } + + this.saveEditedRow(mtbColrToUpdate, + pickedQuantityDTO.getNumCnf(), + pickedQuantityDTO.getQtaCnf(), + pickedQuantityDTO.getQtaTot(), + pickedQuantityDTO.getPartitaMag(), + pickedQuantityDTO.getDataScad(), + pickedQuantityDTO.isShouldCloseLu()); } - private void saveEditedRow(MtbColr mtbColrToUpdate, BigDecimal numCnf, BigDecimal qtaCnf, BigDecimal qtaTot, String partitaMag, LocalDate dataScad, boolean shouldCloseLU) { + private void saveEditedRow(MtbColr mtbColrToUpdate, BigDecimal numCnf, BigDecimal qtaCnf, BigDecimal qtaTot, String partitaMag, LocalDate dataScad, boolean shouldCloseLU) throws Exception { this.sendOnLoadingStarted(); - this.mColliMagazzinoRESTConsumer.creaRettificaCollo( + var savedMtbColr = this.mColliMagazzinoRESTConsumer.creaRettificaColloSynchronized( mtbColrToUpdate, numCnf, - qtaTot, - savedMtbColr -> { - mtbColrToUpdate - .setQtaCol(qtaTot) - .setQtaCnf(qtaCnf) - .setNumCnf(numCnf) - .setOperation(CommonModelConsts.OPERATION.NO_OP); + qtaTot); - this.mCurrentMtbColt.getMtbColr().remove(mtbColrToUpdate); - this.mCurrentMtbColt.getMtbColr().add(mtbColrToUpdate); + mtbColrToUpdate + .setQtaCol(qtaTot) + .setQtaCnf(qtaCnf) + .setNumCnf(numCnf) + .setOperation(CommonModelConsts.OPERATION.NO_OP); - this.mAnyEditDone = true; + handler.post(() -> { + this.mCurrentMtbColt.getMtbColr().remove(mtbColrToUpdate); + this.mCurrentMtbColt.getMtbColr().add(mtbColrToUpdate); + }); - this.sendOnRowSaved(); - this.sendOnLoadingEnded(); - }, - this::sendError - ); + this.mAnyEditDone = true; + + this.sendOnRowSaved(); + if (shouldCloseLU) closeLU(true, true); + + this.sendOnLoadingEnded(); } public void deleteRow(MtbColr mtbColrToDelete) { @@ -596,7 +589,9 @@ public class RettificaGiacenzeViewModel { BigDecimal.ZERO, BigDecimal.ZERO, savedMtbColr -> { - this.mCurrentMtbColt.getMtbColr().remove(mtbColrToDelete); + handler.post(() -> { + this.mCurrentMtbColt.getMtbColr().remove(mtbColrToDelete); + }); this.sendOnLoadingEnded(); this.sendOnRowSaved(); }, @@ -623,8 +618,27 @@ public class RettificaGiacenzeViewModel { } - private void sendOnArtListLoaded(ArrayList artList, RunnableArgs onArtChoosed) { - if (this.mListener != null) mListener.onArtListLoaded(artList, onArtChoosed); + private MtbAart sendOnArtListLoaded(ArrayList artList) { + CountDownLatch countDownLatch = new CountDownLatch(1); + AtomicReference result = new AtomicReference<>(); + + if (this.mListener != null) mListener.onArtListLoaded(artList, mtbAart -> { + result.set(mtbAart); + countDownLatch.countDown(); + }); + else { + result.set(null); + countDownLatch.countDown(); + } + + + try { + countDownLatch.await(); + } catch (InterruptedException e) { + this.sendError(e); + } + + return result.get(); } private void sendOnLUOpenRequest(boolean enableCreation, boolean checkIfDocumentExists, boolean warnOnOpeningVendita, RunnableArgs onComplete) { @@ -640,32 +654,35 @@ public class RettificaGiacenzeViewModel { if (this.mListener != null) mListener.onLUOpened(mtbColt); } - private void sendLUClosed() { - if (this.mListener != null) mListener.onLUClosed(); + private void sendLUClosed(boolean requestNewLu) { + if (this.mListener != null) mListener.onLUClosed(requestNewLu); } private void sendMtbColrDeleteRequest(RunnableArgs onComplete) { if (this.mListener != null) mListener.onMtbColrDeleteRequest(onComplete); } - private void sendOnItemDispatched(PickingObjectDTO pickingObjectDTO, - MtbAart mtbAart, - BigDecimal initialNumCnf, - BigDecimal initialQtaCnf, - BigDecimal initialQtaTot, - BigDecimal totalQtaInWarehouse, - BigDecimal totalNumCnfInWarehouse, - BigDecimal totalQtaCommitted, - BigDecimal totalNumCnfCommitted, - BigDecimal totalQtaToBeTaken, - BigDecimal totalNumCnfToBeTaken, - BigDecimal qtaCnfToBeTaken, - String partitaMag, - LocalDate dataScad, - boolean canOverflowOrderQuantity, - boolean canPartitaMagBeChanged, - boolean canLUBeClosed, - RunnableArgss onComplete) { + private PickedQuantityDTO sendOnItemDispatched(PickingObjectDTO pickingObjectDTO, + MtbAart mtbAart, + BigDecimal initialNumCnf, + BigDecimal initialQtaCnf, + BigDecimal initialQtaTot, + BigDecimal totalQtaInWarehouse, + BigDecimal totalNumCnfInWarehouse, + BigDecimal totalQtaCommitted, + BigDecimal totalNumCnfCommitted, + BigDecimal totalQtaToBeTaken, + BigDecimal totalNumCnfToBeTaken, + BigDecimal qtaCnfToBeTaken, + String partitaMag, + LocalDate dataScad, + boolean canOverflowOrderQuantity, + boolean canPartitaMagBeChanged, + boolean canLUBeClosed) { + + CountDownLatch countDownLatch = new CountDownLatch(1); + AtomicReference result = new AtomicReference<>(); + if (this.mListener != null) mListener.onItemDispatched(pickingObjectDTO, mtbAart, initialNumCnf, @@ -683,7 +700,23 @@ public class RettificaGiacenzeViewModel { canOverflowOrderQuantity, canPartitaMagBeChanged, canLUBeClosed, - onComplete); + pickedQuantity -> { + result.set(pickedQuantity); + countDownLatch.countDown(); + }); + else { + result.set(null); + countDownLatch.countDown(); + } + + + try { + countDownLatch.await(); + } catch (InterruptedException e) { + this.sendError(e); + } + + return result.get(); } private void sendOnRowSaved() { @@ -699,12 +732,26 @@ public class RettificaGiacenzeViewModel { return false; } - private void sendLUPrintError(Exception ex, Runnable onComplete) { - if (this.mListener != null) mListener.onLUPrintError(ex, onComplete); + private void sendLUPrintError(Exception ex) { + if (this.mListener != null) mListener.onLUPrintError(ex, null); } - private void sendLUPositionChangeRequest(RunnableArgss onComplete) { - if (this.mListener != null) mListener.onLUPositionChangeRequest(onComplete); + private Pair sendLUPositionChangeRequest() { + final CountDownLatch latch = new CountDownLatch(1); + AtomicReference> result = new AtomicReference<>(); + + mListener.onLUPositionChangeRequest((status, data) -> { + result.set(new Pair<>(status, data)); + latch.countDown(); + }); + + try { + latch.await(); // Attende che il dialog venga chiuso + return result.get(); + } catch (InterruptedException e) { + this.sendError(e); + } + return null; } public interface Listener extends ILUPrintListener, ILUPositionListener { @@ -722,7 +769,7 @@ public class RettificaGiacenzeViewModel { void onLUOpened(MtbColt mtbColt); - void onLUClosed(); + void onLUClosed(boolean requestNewLu); void onMtbColrDeleteRequest(RunnableArgs onComplete); @@ -745,7 +792,7 @@ public class RettificaGiacenzeViewModel { boolean canOverflowOrderQuantity, boolean canPartitaMagBeChanged, boolean canLUBeClosed, - RunnableArgss onComplete); + RunnableArgs onComplete); void onRowSaved(); } diff --git a/app/src/main/java/it/integry/integrywmsnative/gest/rettifica_giacenze/rest/RettificaGiacenzeRESTConsumer.java b/app/src/main/java/it/integry/integrywmsnative/gest/rettifica_giacenze/rest/RettificaGiacenzeRESTConsumer.java index 9bc42fcc..76644be6 100644 --- a/app/src/main/java/it/integry/integrywmsnative/gest/rettifica_giacenze/rest/RettificaGiacenzeRESTConsumer.java +++ b/app/src/main/java/it/integry/integrywmsnative/gest/rettifica_giacenze/rest/RettificaGiacenzeRESTConsumer.java @@ -1,8 +1,5 @@ package it.integry.integrywmsnative.gest.rettifica_giacenze.rest; -import androidx.annotation.NonNull; - -import com.annimon.stream.Stream; import com.google.gson.reflect.TypeToken; import java.lang.reflect.Type; @@ -18,16 +15,11 @@ import it.integry.integrywmsnative.core.model.MtbColt; import it.integry.integrywmsnative.core.rest.RESTBuilder; import it.integry.integrywmsnative.core.rest.consumers.SystemRESTConsumer; import it.integry.integrywmsnative.core.rest.consumers._BaseRESTConsumer; -import it.integry.integrywmsnative.core.rest.handler.ManagedErrorCallback; import it.integry.integrywmsnative.core.rest.model.SaveDocFromPickingRequestDTO; -import it.integry.integrywmsnative.core.rest.model.ServiceRESTResponse; import it.integry.integrywmsnative.gest.rettifica_giacenze.dto.FornitoreDTO; import it.integry.integrywmsnative.gest.rettifica_giacenze.dto.SearchArticoloByBarcodeOrCodMartRequestDTO; -import it.integry.integrywmsnative.gest.rettifica_giacenze.dto.SearchArticoloByBarcodeOrCodMartResponseDTO; import it.integry.integrywmsnative.gest.rettifica_giacenze.dto.SearchArticoloByCodArtFornOrDescrizioneRequestDTO; import it.integry.integrywmsnative.gest.rettifica_giacenze.dto.SearchArticoloByCodArtFornOrDescrizioneResponseDTO; -import retrofit2.Call; -import retrofit2.Response; @Singleton public class RettificaGiacenzeRESTConsumer extends _BaseRESTConsumer { @@ -52,79 +44,49 @@ public class RettificaGiacenzeRESTConsumer extends _BaseRESTConsumer { } - public void searchArtForn(String codAlis, String codArtForOrDescr, RunnableArgs> onComplete, RunnableArgs onError) { + public List searchArtFornSynchronized(String codAlis, String codArtForOrDescr) throws Exception { final RettificaGiacenzeRESTConsumerService service = restBuilder.getService(RettificaGiacenzeRESTConsumerService.class); - service.searchByCodArtFornOrDescrizione(new SearchArticoloByCodArtFornOrDescrizioneRequestDTO() + var response = service.searchByCodArtFornOrDescrizione(new SearchArticoloByCodArtFornOrDescrizioneRequestDTO() .setCodAlis(codAlis) .setCodArtFornOrDescrizione(codArtForOrDescr)) - .enqueue(new ManagedErrorCallback<>() { - @Override - public void onResponse(Call>> call, - Response>> response) { - analyzeAnswer(response, "searchByCodArtFornOrDescrizione", onComplete, onError); - } - - @Override - public void onFailure(Call>> call, @NonNull final Exception e) { - onError.run(e); - } - }); - - + .execute(); + var data = analyzeAnswer(response, "searchByCodArtFornOrDescrizione"); + return data; } - public void searchArtInt(String codMartOrBarcodeOrDescr, RunnableArgs> onComplete, RunnableArgs onError) { + public List searchArtIntSynchronized(String codMartOrBarcodeOrDescr) throws Exception { final RettificaGiacenzeRESTConsumerService service = restBuilder.getService(RettificaGiacenzeRESTConsumerService.class); - service.searchByCodMartOrBarcode(new SearchArticoloByBarcodeOrCodMartRequestDTO() + var response = service.searchByCodMartOrBarcode(new SearchArticoloByBarcodeOrCodMartRequestDTO() .setCodMartOrBarcode(codMartOrBarcodeOrDescr)) - .enqueue(new ManagedErrorCallback<>() { - @Override - public void onResponse(Call>> call, - Response>> response) { - analyzeAnswer(response, "searchByCodMartOrBarcode", data -> { + .execute(); - if(data == null) data = new ArrayList<>(); + var data = analyzeAnswer(response, "searchByCodMartOrBarcode"); - var listToReturn = Stream.of(data) - .map(x -> x.getMtbAart() - .setQtaEsistente(x.getQtaEsistente()) - .setQtaImpegnata(x.getQtaImpegnata()) - .setNumCnfEsistente(x.getNumCnfEsistente()) - .setNumCnfImpegnata(x.getNumCnfImpegnata())) - .toList(); + if (data == null) data = new ArrayList<>(); - onComplete.run(listToReturn); - }, onError); - } + var listToReturn = data.stream() + .map(x -> x.getMtbAart() + .setQtaEsistente(x.getQtaEsistente()) + .setQtaImpegnata(x.getQtaImpegnata()) + .setNumCnfEsistente(x.getNumCnfEsistente()) + .setNumCnfImpegnata(x.getNumCnfImpegnata())) + .toList(); - @Override - public void onFailure(Call>> call, @NonNull final Exception e) { - onError.run(e); - } - }); + return listToReturn; } - public void saveDoc(MtbColt mtbColt, Runnable onComplete, RunnableArgs onError) { + public void saveDocSynchronized(MtbColt mtbColt) throws Exception { var request = new SaveDocFromPickingRequestDTO() .setColliFromMtbColts(Collections.singletonList(mtbColt)); final RettificaGiacenzeRESTConsumerService service = restBuilder.getService(RettificaGiacenzeRESTConsumerService.class); - service.saveDocFromPickingPvm(request) - .enqueue(new ManagedErrorCallback<>() { - @Override - public void onResponse(Call> call, Response> response) { - analyzeAnswerList(response, "saveDocFromPickingPvm", data -> onComplete.run(), onError); - } - - @Override - public void onFailure(Call> call, @NonNull final Exception e) { - onError.run(e); - } - }); + var response = service.saveDocFromPickingPvm(request) + .execute(); + var data = analyzeAnswerList(response, "saveDocFromPickingPvm"); } } diff --git a/app/src/main/res/layout/fragment_main_rettifica_giacenze.xml b/app/src/main/res/layout/fragment_main_rettifica_giacenze.xml index 465a1fa7..7bb6a5dc 100644 --- a/app/src/main/res/layout/fragment_main_rettifica_giacenze.xml +++ b/app/src/main/res/layout/fragment_main_rettifica_giacenze.xml @@ -293,7 +293,7 @@ android:layout_alignParentBottom="true" android:layout_gravity="bottom|end" android:layout_margin="@dimen/fab_margin" - android:onClick="@{() -> viewmodel.closeLU(true)}" + android:onClick="@{() -> view.closeLU(true)}" android:tint="@android:color/white" app:srcCompat="@drawable/ic_round_check_24" app:visibility="@{view.thereIsAnOpenedUL}" />