diff --git a/app/src/main/java/it/integry/integrywmsnative/MainApplicationModule.java b/app/src/main/java/it/integry/integrywmsnative/MainApplicationModule.java index ae78d4e7..cabc6fac 100644 --- a/app/src/main/java/it/integry/integrywmsnative/MainApplicationModule.java +++ b/app/src/main/java/it/integry/integrywmsnative/MainApplicationModule.java @@ -269,8 +269,8 @@ public class MainApplicationModule { @Provides @Singleton - GiacenzaRESTConsumer provideGiacenzaRESTConsumer(RESTBuilder restBuilder, ArticoloRESTConsumer articoloRESTConsumer) { - return new GiacenzaRESTConsumer(restBuilder, articoloRESTConsumer); + GiacenzaRESTConsumer provideGiacenzaRESTConsumer(RESTBuilder restBuilder, ExecutorService executorService, ArticoloRESTConsumer articoloRESTConsumer) { + return new GiacenzaRESTConsumer(restBuilder, executorService, articoloRESTConsumer); } @Provides 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 8314164e..e09577b9 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 @@ -16,8 +16,8 @@ import java.util.Collections; import java.util.HashMap; import java.util.Iterator; import java.util.List; -import java.util.concurrent.ExecutorService; import java.util.Objects; +import java.util.concurrent.ExecutorService; import java.util.stream.Collectors; import javax.inject.Singleton; @@ -37,7 +37,6 @@ import it.integry.integrywmsnative.core.rest.handler.ManagedErrorCallback; import it.integry.integrywmsnative.core.rest.model.RettificaULDTO; import it.integry.integrywmsnative.core.rest.model.ServiceRESTResponse; import it.integry.integrywmsnative.core.rest.model.SpostaArtsTraULRequestDTO; -import it.integry.integrywmsnative.core.rest.model.SpostaArtsTraULResponseDTO; import it.integry.integrywmsnative.core.rest.model.SpostaULRequestDTO; import it.integry.integrywmsnative.core.rest.model.UpdateTipoULRequestDTO; import it.integry.integrywmsnative.core.rest.model.VersamentoAutomaticoULResponseDTO; @@ -75,7 +74,7 @@ public class ColliMagazzinoRESTConsumer extends _BaseRESTConsumer { this.executorService = executorService; } - public void saveCollo(MtbColt mtbColtToSave, RunnableArgs onComplete, RunnableArgs onFailed) { + public MtbColt saveColloSynchronized(MtbColt mtbColtToSave) throws Exception { MtbColt mtbColtToSaveClone = (MtbColt) mtbColtToSave.clone(); mtbColtToSaveClone.setOperation(CommonModelConsts.OPERATION.INSERT_OR_UPDATE); mtbColtToSaveClone.setOnlyPkMaster(false); @@ -86,17 +85,18 @@ public class ColliMagazzinoRESTConsumer extends _BaseRESTConsumer { .setMtbPartitaMag(null); } - this.mEntityRESTConsumer.processEntity(mtbColtToSaveClone, new ISimpleOperationCallback<>() { - @Override - public void onSuccess(MtbColt value) { - if (onComplete != null) onComplete.run(value); - } + return this.mEntityRESTConsumer.processEntitySynchronized(mtbColtToSaveClone, MtbColt.class); + } - @Override - public void onFailed(Exception ex) { + public void saveCollo(MtbColt mtbColtToSave, RunnableArgs onComplete, RunnableArgs onFailed) { + executorService.execute(() -> { + try { + var mtbColt = saveColloSynchronized(mtbColtToSave); + if (onComplete != null) onComplete.run(mtbColt); + } catch (Exception ex) { if (onFailed != null) onFailed.run(ex); } - }, MtbColt.class); + }); } @@ -327,6 +327,36 @@ public class ColliMagazzinoRESTConsumer extends _BaseRESTConsumer { }); } + public List fillMtbAartsOfMtbColrsSynchronized(List mtbColrs) throws Exception { + + List codMarts = new ArrayList<>(mtbColrs.stream() + .map(MtbColr::getCodMart) + .filter(Objects::nonNull) + .distinct() + .collect(Collectors.toUnmodifiableList())); + + var arts = mArticoloRESTConsumer.getByCodMartsSynchronized(codMarts); + + + if (arts != null && !arts.isEmpty()) { + for (MtbColr mtbColr : mtbColrs) { + MtbAart foundMtbAart = null; + + List mtbAartStream = arts.stream() + .filter(x -> x.getCodMart().equalsIgnoreCase(mtbColr.getCodMart())) + .collect(Collectors.toList()); + + if (!mtbAartStream.isEmpty()) { + foundMtbAart = mtbAartStream.get(0); + } + + mtbColr.setMtbAart(foundMtbAart); + } + } + + return mtbColrs; + } + public List fillMtbAartsOfMtbColtsSynchronized(List mtbColts) throws Exception { List codMarts = new ArrayList<>(); @@ -405,6 +435,7 @@ public class ColliMagazzinoRESTConsumer extends _BaseRESTConsumer { return getByTestataSynchronized(mtbColtToRetrieve, onlyResiduo, throwExcIfNull); } + public void getByChiaveCollo(GestioneEnum gestione, int numCollo, String dataCollo, String serCollo, boolean onlyResiduo, boolean throwExcIfNull, RunnableArgs onComplete, RunnableArgs onFailed) { MtbColt mtbColtToRetrieve = new MtbColt() .setGestione(gestione) @@ -424,9 +455,7 @@ public class ColliMagazzinoRESTConsumer extends _BaseRESTConsumer { .execute(); var mtbColt = analyzeAnswer(response, "getColloInGiac"); if (mtbColt != null && mtbColt.getMtbColr() != null && !mtbColt.getMtbColr().isEmpty()) { - List mtbColtList = new ArrayList<>(); - mtbColtList.add(mtbColt); - var mtbColts = fillMtbAartsOfMtbColtsSynchronized(mtbColtList); + var mtbColts = fillMtbAartsOfMtbColtsSynchronized(Collections.singletonList(mtbColt)); return mtbColts.get(0); } @@ -576,44 +605,45 @@ public class ColliMagazzinoRESTConsumer extends _BaseRESTConsumer { }); } + public List spostaArtsTraULSynchronized(MtbColt sourceMtbColt, MtbColt destMtbColt, boolean flagForceUseRefs) throws Exception { + MtbColt mtbColtToMoveClone = (MtbColt) sourceMtbColt.clone(); + MtbColt mtbColtDestClone = (MtbColt) destMtbColt.clone(); + + for (int i = 0; i < mtbColtToMoveClone.getMtbColr().size(); i++) { + mtbColtToMoveClone.getMtbColr().get(i) + .setMtbAart(null) + .setMtbPartitaMag(null); + } + + mtbColtDestClone.setMtbColr(null); + + SpostaArtsTraULRequestDTO spostaArtsTraULRequestDTO = new SpostaArtsTraULRequestDTO() + .setSourceMtbColt(mtbColtToMoveClone) + .setDestinationMtbColt(mtbColtDestClone) + .setFlagForceUseRefs(flagForceUseRefs); + + ColliMagazzinoRESTConsumerService colliMagazzinoRESTConsumerService = restBuilder.getService(ColliMagazzinoRESTConsumerService.class); + var response = colliMagazzinoRESTConsumerService.spostaArtsTraUL(spostaArtsTraULRequestDTO) + .execute(); + + var data = analyzeAnswer(response, "spostaArtsTraUL"); + var mtbColrs = fillMtbAartsOfMtbColrsSynchronized(data.getGeneratedMtbColr()); + + return mtbColrs; + } + public void spostaArtsTraUL(MtbColt sourceMtbColt, MtbColt destMtbColt, boolean flagForceUseRefs, RunnableArgs> onComplete, RunnableArgs onFailed) { executorService.execute(() -> { - MtbColt mtbColtToMoveClone = (MtbColt) sourceMtbColt.clone(); - MtbColt mtbColtDestClone = (MtbColt) destMtbColt.clone(); - - for (int i = 0; i < mtbColtToMoveClone.getMtbColr().size(); i++) { - mtbColtToMoveClone.getMtbColr().get(i) - .setMtbAart(null) - .setMtbPartitaMag(null); + try { + var result = spostaArtsTraULSynchronized(sourceMtbColt, destMtbColt, flagForceUseRefs); + if (onComplete != null) onComplete.run(result); + } catch (Exception ex) { + if (onFailed != null) onFailed.run(ex); } - - mtbColtDestClone.setMtbColr(null); - - SpostaArtsTraULRequestDTO spostaArtsTraULRequestDTO = new SpostaArtsTraULRequestDTO() - .setSourceMtbColt(mtbColtToMoveClone) - .setDestinationMtbColt(mtbColtDestClone) - .setFlagForceUseRefs(flagForceUseRefs); - - ColliMagazzinoRESTConsumerService colliMagazzinoRESTConsumerService = restBuilder.getService(ColliMagazzinoRESTConsumerService.class); - colliMagazzinoRESTConsumerService.spostaArtsTraUL(spostaArtsTraULRequestDTO).enqueue(new ManagedErrorCallback<>() { - @Override - public void onResponse(Call> call, Response> response) { - analyzeAnswer(response, "spostaArtsTraUL", data -> { - - fillMtbAartsOfMtbColrs(data.getGeneratedMtbColr(), onComplete, onFailed); - - }, onFailed); - } - - @Override - public void onFailure(Call> call, @NonNull final Exception e) { - if (onFailed != null) onFailed.run(e); - } - }); }); } - public void assegnaLottoSuColloScarico(MtbColt sourceMtbColt, Runnable onComplete, RunnableArgs onFailed) { + public MtbColt assegnaLottoSuColloScaricoSynchronized(MtbColt sourceMtbColt) throws Exception { MtbColt sourceMtbColtClone = (MtbColt) sourceMtbColt.clone(); for (int i = 0; i < sourceMtbColtClone.getMtbColr().size(); i++) { @@ -623,17 +653,20 @@ public class ColliMagazzinoRESTConsumer extends _BaseRESTConsumer { } ColliMagazzinoRESTConsumerService colliMagazzinoRESTConsumerService = restBuilder.getService(ColliMagazzinoRESTConsumerService.class); - colliMagazzinoRESTConsumerService.assegnaLottoSuColloScarico(sourceMtbColtClone).enqueue(new ManagedErrorCallback<>() { - @Override - public void onResponse(Call> call, Response> response) { - analyzeAnswer(response, "assegnaLottoSuColloScarico", data -> { - onComplete.run(); - }, onFailed); - } + var response = colliMagazzinoRESTConsumerService.assegnaLottoSuColloScarico(sourceMtbColtClone) + .execute(); - @Override - public void onFailure(Call> call, @NonNull final Exception e) { - if (onFailed != null) onFailed.run(e); + var data = analyzeAnswer(response, "assegnaLottoSuColloScarico"); + return data; + } + + public void assegnaLottoSuColloScarico(MtbColt sourceMtbColt, Runnable onComplete, RunnableArgs onFailed) { + executorService.execute(() -> { + try { + var result = assegnaLottoSuColloScaricoSynchronized(sourceMtbColt); + if (onComplete != null) onComplete.run(); + } catch (Exception ex) { + if (onFailed != null) onFailed.run(ex); } }); } diff --git a/app/src/main/java/it/integry/integrywmsnative/core/rest/consumers/EntityRESTConsumer.java b/app/src/main/java/it/integry/integrywmsnative/core/rest/consumers/EntityRESTConsumer.java index 00e1abeb..2bfc7879 100644 --- a/app/src/main/java/it/integry/integrywmsnative/core/rest/consumers/EntityRESTConsumer.java +++ b/app/src/main/java/it/integry/integrywmsnative/core/rest/consumers/EntityRESTConsumer.java @@ -34,45 +34,41 @@ public class EntityRESTConsumer extends _BaseRESTConsumer { this.executorService = executorService; } - public void processEntity(T entityToSave, final ISimpleOperationCallback callback, Class type) { - - RunnableArgs tmpFailed = ex -> { - if (callback != null) callback.onFailed(ex); - }; - + public T processEntitySynchronized(T entityToSave, Class type) throws Exception { EntityRESTConsumerService service = restBuilder.getService(EntityRESTConsumerService.class); - service + var response = service .processEntity(entityToSave) - .enqueue(new ManagedErrorCallback<>() { - @Override - public void onResponse(Call> call, Response> response) { - if (response.isSuccessful()) { + .execute(); - if (response.body() != null) { - if (response.body().getEsito() == EsitoType.OK) { - Gson gson = UtilityGson.createObject(); - T object = gson.fromJson(response.body().getEntity(), type); + if (response.isSuccessful()) { + if (response.body() != null) { + if (response.body().getEsito() == EsitoType.OK) { + Gson gson = UtilityGson.createObject(); - callback.onSuccess(object); - } else { - Log.e("EntityRESTConsumer", response.body().getErrorMessage()); - tmpFailed.run(new Exception(response.body().getErrorMessage())); - } - } else { - Log.e("EntityRESTConsumer", response.message()); - tmpFailed.run(new Exception(response.message())); - } - } else { - Log.e("EntityRESTConsumer", "Status " + response.code() + ": " + response.message()); - tmpFailed.run(new Exception("Status " + response.code() + ": " + response.message())); - } - } + return gson.fromJson(response.body().getEntity(), type); + } else { + Log.e("EntityRESTConsumer", response.body().getErrorMessage()); + throw new Exception(response.body().getErrorMessage()); + } + } else { + Log.e("EntityRESTConsumer", response.message()); + throw new Exception(response.message()); + } + } else { + Log.e("EntityRESTConsumer", "Status " + response.code() + ": " + response.message()); + throw new Exception("Status " + response.code() + ": " + response.message()); + } + } - @Override - public void onFailure(Call> call, @NonNull final Exception e) { - tmpFailed.run(e); - } - }); + public void processEntity(T entityToSave, final ISimpleOperationCallback callback, Class type) { + executorService.execute(() -> { + try { + var data = processEntitySynchronized(entityToSave, type); + if (callback != null) callback.onSuccess(data); + } catch (Exception ex) { + if (callback != null) callback.onFailed(ex); + } + }); } diff --git a/app/src/main/java/it/integry/integrywmsnative/core/rest/consumers/GiacenzaRESTConsumer.java b/app/src/main/java/it/integry/integrywmsnative/core/rest/consumers/GiacenzaRESTConsumer.java index 8754f409..83506ee8 100644 --- a/app/src/main/java/it/integry/integrywmsnative/core/rest/consumers/GiacenzaRESTConsumer.java +++ b/app/src/main/java/it/integry/integrywmsnative/core/rest/consumers/GiacenzaRESTConsumer.java @@ -7,6 +7,8 @@ import com.annimon.stream.Stream; import java.util.ArrayList; import java.util.List; +import java.util.concurrent.ExecutorService; +import java.util.stream.Collectors; import javax.inject.Singleton; @@ -28,52 +30,55 @@ import retrofit2.Response; public class GiacenzaRESTConsumer extends _BaseRESTConsumer { private final RESTBuilder restBuilder; + private final ExecutorService executorService; private final ArticoloRESTConsumer mArticoloRESTConsumer; - public GiacenzaRESTConsumer(RESTBuilder restBuilder, ArticoloRESTConsumer articoloRESTConsumer) { + public GiacenzaRESTConsumer(RESTBuilder restBuilder, ExecutorService executorService, ArticoloRESTConsumer articoloRESTConsumer) { this.restBuilder = restBuilder; + this.executorService = executorService; this.mArticoloRESTConsumer = articoloRESTConsumer; } - public void getGiacenzeInPosizione(MtbDepoPosizione posizione, RunnableArgs> onComplete, RunnableArgs onFailed) { + public List getGiacenzeInPosizioneSynchronized(MtbDepoPosizione posizione) throws Exception { GiacenzaRESTConsumerService giacenzaRESTConsumerService = restBuilder.getService(GiacenzaRESTConsumerService.class); - giacenzaRESTConsumerService.retrieveAvailableItems(posizione.getPosizione()).enqueue(new ManagedErrorCallback<>() { - @Override - public void onResponse(Call>> call, Response>> response) { - analyzeAnswer(response, "getGiacenzeInPosizione", inventarioList -> { + var response = giacenzaRESTConsumerService.retrieveAvailableItems(posizione.getPosizione()) + .execute(); - if(inventarioList != null && !inventarioList.isEmpty()){ - List codMarts = Stream.of(inventarioList) - .map(x -> x.getCodMart().trim()) - .toList(); + var inventarioList = analyzeAnswer(response, "getGiacenzeInPosizione"); - mArticoloRESTConsumer.getByCodMarts(codMarts, mtbAarts -> { - for (var row : inventarioList) { + if (inventarioList != null && !inventarioList.isEmpty()) { + List codMarts = inventarioList.stream() + .map(x -> x.getCodMart().trim()) + .collect(Collectors.toList()); - MtbAart foundMtbAart = null; - Optional mtbAartOpt = Stream.of(mtbAarts) - .filter(x -> x.getCodMart().equalsIgnoreCase(row.getCodMart())) - .findFirst(); + var mtbAarts = mArticoloRESTConsumer.getByCodMartsSynchronized(codMarts); + for (var row : inventarioList) { + MtbAart foundMtbAart = null; + Optional mtbAartOpt = Stream.of(mtbAarts) + .filter(x -> x.getCodMart().equalsIgnoreCase(row.getCodMart())) + .findFirst(); - if (mtbAartOpt.isPresent()) { - foundMtbAart = mtbAartOpt.get(); - } + if (mtbAartOpt.isPresent()) { + foundMtbAart = mtbAartOpt.get(); + } - row.setMtbAart(foundMtbAart); - } - - onComplete.run(inventarioList); - }, onFailed); - }else{ - onComplete.run(new ArrayList<>()); - } - }, onFailed); + row.setMtbAart(foundMtbAart); } - @Override - public void onFailure(Call>> call, @NonNull final Exception e) { - onFailed.run(e); + return inventarioList; + } + + return new ArrayList<>(); + } + + public void getGiacenzeInPosizione(MtbDepoPosizione posizione, RunnableArgs> onComplete, RunnableArgs onFailed) { + executorService.execute(() -> { + try { + var result = getGiacenzeInPosizioneSynchronized(posizione); + if (onComplete != null) onComplete.run(result); + } catch (Exception ex) { + if (onFailed != null) onFailed.run(ex); } }); } @@ -92,8 +97,8 @@ public class GiacenzaRESTConsumer extends _BaseRESTConsumer { mArticoloRESTConsumer.getByCodMarts(codMarts, mtbAarts -> { for (var articoli : inventarioList) { List mvwSitArtUdcDetInventario = articoli.getMvwSitArtUdcDetInventarioDTO(); - if (mvwSitArtUdcDetInventario != null && !mvwSitArtUdcDetInventario.isEmpty()){ - for (var row : mvwSitArtUdcDetInventario){ + if (mvwSitArtUdcDetInventario != null && !mvwSitArtUdcDetInventario.isEmpty()) { + for (var row : mvwSitArtUdcDetInventario) { MtbAart foundMtbAart = null; Optional mtbAartOpt = Stream.of(mtbAarts) .filter(x -> x.getCodMart().equalsIgnoreCase(row.getCodMart())) diff --git a/app/src/main/java/it/integry/integrywmsnative/core/rest/consumers/MagazzinoAutomaticoRESTConsumer.java b/app/src/main/java/it/integry/integrywmsnative/core/rest/consumers/MagazzinoAutomaticoRESTConsumer.java index fcd79249..5177dcff 100644 --- a/app/src/main/java/it/integry/integrywmsnative/core/rest/consumers/MagazzinoAutomaticoRESTConsumer.java +++ b/app/src/main/java/it/integry/integrywmsnative/core/rest/consumers/MagazzinoAutomaticoRESTConsumer.java @@ -28,7 +28,7 @@ public class MagazzinoAutomaticoRESTConsumer extends _BaseRESTConsumer { this.restBuilder = restBuilder; } - public void pickItemsSynchronous(MtbDepoPosizione posizione, MagazzinoAutomaticoPickItemsRequestDTO magazzinoAutomaticoPickItemsRequestDTO) throws Exception { + public void pickItemsSynchronized(MtbDepoPosizione posizione, MagazzinoAutomaticoPickItemsRequestDTO magazzinoAutomaticoPickItemsRequestDTO) throws Exception { MagazzinoAutomaticoRESTConsumerService magazzinoAutomaticoRESTConsumerService = restBuilder.getService(MagazzinoAutomaticoRESTConsumerService.class); var response = magazzinoAutomaticoRESTConsumerService.pickItems(posizione.getPosizione(), magazzinoAutomaticoPickItemsRequestDTO) .execute(); @@ -39,7 +39,7 @@ public class MagazzinoAutomaticoRESTConsumer extends _BaseRESTConsumer { public void pickItems(MtbDepoPosizione posizione, MagazzinoAutomaticoPickItemsRequestDTO magazzinoAutomaticoPickItemsRequestDTO, Runnable onComplete, RunnableArgs onFailed) { executorService.execute(() -> { try { - pickItemsSynchronous(posizione, magazzinoAutomaticoPickItemsRequestDTO); + pickItemsSynchronized(posizione, magazzinoAutomaticoPickItemsRequestDTO); if (onComplete != null) onComplete.run(); } catch (Exception ex) { if (onFailed != null) onFailed.run(ex); diff --git a/app/src/main/java/it/integry/integrywmsnative/gest/picking_libero/PickingLiberoFragment.java b/app/src/main/java/it/integry/integrywmsnative/gest/picking_libero/PickingLiberoFragment.java index ee48c0e9..4a6859b5 100644 --- a/app/src/main/java/it/integry/integrywmsnative/gest/picking_libero/PickingLiberoFragment.java +++ b/app/src/main/java/it/integry/integrywmsnative/gest/picking_libero/PickingLiberoFragment.java @@ -3,6 +3,7 @@ package it.integry.integrywmsnative.gest.picking_libero; import android.content.Context; import android.os.Bundle; +import android.os.Handler; import android.text.SpannableString; import android.view.LayoutInflater; import android.view.View; @@ -76,6 +77,9 @@ public class PickingLiberoFragment extends BaseFragment implements ITitledFragme @Inject DialogInputQuantityV2View mDialogInputQuantityV2View; + @Inject + Handler handler; + public BindableBoolean thereIsAnOpenedUL = new BindableBoolean(false); public BindableBoolean thereIsntAnOpenedUL = new BindableBoolean(true); public BindableBoolean thereIsAnyRowInUL = new BindableBoolean(false); @@ -206,23 +210,41 @@ public class PickingLiberoFragment extends BaseFragment implements ITitledFragme } private final RunnableArgs onScanSuccessful = data -> { - BarcodeManager.disable(mBarcodeScannerInstanceID); this.onLoadingStarted(); - this.mViewModel.processBarcodeDTO(data, () -> { - BarcodeManager.enable(mBarcodeScannerInstanceID); - this.onLoadingEnded(); + executorService.execute(() -> { + try { + this.mViewModel.processBarcodeDTO(data); + } catch (Exception e) { + onError(e); + } }); + + this.onLoadingEnded(); }; public void createNewLU() { - this.mViewModel.createNewLU(null, null, () -> { + executorService.execute(() -> { + try { + this.mViewModel.createNewLU(null, null); + } catch (Exception e) { + this.onError(e); + } }); } public void closeLU() { destroyAdapter(); - this.mViewModel.closeLU(null); + + executorService.execute(() -> { + try { + this.onLoadingStarted(); + this.mViewModel.closeLU(); + this.onLoadingEnded(); + } catch (Exception e) { + this.onError(e); + } + }); } @Override @@ -241,7 +263,7 @@ public class PickingLiberoFragment extends BaseFragment implements ITitledFragme @Override public void onLUOpened(MtbColt mtbColt) { - requireActivity().runOnUiThread(() -> { + handler.post(() -> { mToolbarTitleText.setText(String.format(getActivity().getText(R.string.lu_number_text).toString(), mtbColt.getNumCollo())); initAdapter(); @@ -257,14 +279,14 @@ public class PickingLiberoFragment extends BaseFragment implements ITitledFragme }); Snackbar.make(mBindings.getRoot(), R.string.data_saved, Snackbar.LENGTH_SHORT) - .setBackgroundTint(getResources().getColor(R. color. green_500)) + .setBackgroundTint(getResources().getColor(R.color.green_500)) .show(); }); } @Override public void onLUClosed() { - requireActivity().runOnUiThread(() -> { + handler.post(() -> { mToolbarTitleText.setText(getActivity().getText(R.string.free_picking_title_fragment).toString()); destroyAdapter(); @@ -285,7 +307,7 @@ public class PickingLiberoFragment extends BaseFragment implements ITitledFragme @Override public void onError(Exception ex) { - requireActivity().runOnUiThread(() -> { + handler.post(() -> { this.onLoadingEnded(); if (ex instanceof InvalidPesoKGException) { @@ -344,7 +366,7 @@ public class PickingLiberoFragment extends BaseFragment implements ITitledFragme boolean canOverflowOrderQuantity, boolean canPartitaMagBeChanged, boolean canLUBeClosed, - RunnableArgss onComplete) { + RunnableArgs onComplete) { DialogInputQuantityV2DTO dialogInputQuantityV2DTO = new DialogInputQuantityV2DTO() .setMtbAart(mtbAart) @@ -366,8 +388,8 @@ public class PickingLiberoFragment extends BaseFragment implements ITitledFragme if (!mDialogInputQuantityV2View.isVisible()) mDialogInputQuantityV2View.setDialogInputQuantityV2DTO(dialogInputQuantityV2DTO) .setOnComplete(resultDTO -> { - if(resultDTO == null || resultDTO.isAborted()) { - onComplete.run(null, false); + if (resultDTO == null || resultDTO.isAborted()) { + onComplete.run(null); return; } @@ -378,19 +400,16 @@ public class PickingLiberoFragment extends BaseFragment implements ITitledFragme .setPartitaMag(resultDTO.getPartitaMag()) .setDataScad(resultDTO.getDataScad()); - onComplete.run(pickedQuantityDTO, resultDTO.isShouldCloseLu()); - }) - .setOnAbort(() -> { - onComplete.run(null, false); + onComplete.run(pickedQuantityDTO); }) .show(requireActivity().getSupportFragmentManager(), "tag"); } @Override public void onRowSaved() { - requireActivity().runOnUiThread(() -> { + handler.post(() -> { Snackbar.make(mBindings.getRoot(), R.string.data_saved, Snackbar.LENGTH_SHORT) - .setBackgroundTint(getResources().getColor(R. color. green_500)) + .setBackgroundTint(getResources().getColor(R.color.green_500)) .show(); }); } @@ -398,19 +417,40 @@ public class PickingLiberoFragment extends BaseFragment implements ITitledFragme @Override public void onMtbColrEdit(MtbColr mtbColr) { - this.mViewModel.dispatchRowEdit(mtbColr); + executorService.execute(() -> { + try { + this.mViewModel.dispatchRowEdit(mtbColr); + } catch (Exception e) { + this.onError(e); + } + }); } @Override public void onMtbColrDelete(MtbColr mtbColr) { - this.mViewModel.deleteRow(mtbColr); + executorService.execute(() -> { + try { + this.mViewModel.deleteRow(mtbColr); + } catch (Exception e) { + this.onError(e); + } + }); } @Override public void onPreDestroy(Runnable onComplete) { BarcodeManager.removeCallback(mBarcodeScannerInstanceID); - if (thereIsAnOpenedUL.get()) mViewModel.closeLU(onComplete); - else onComplete.run(); + if (thereIsAnOpenedUL.get()) { + executorService.execute(() -> { + try { + this.onLoadingStarted(); + mViewModel.closeLU(); + this.onLoadingEnded(); + } catch (Exception e) { + onError(e); + } + }); + } else onComplete.run(); } @Override diff --git a/app/src/main/java/it/integry/integrywmsnative/gest/picking_libero/PickingLiberoModule.java b/app/src/main/java/it/integry/integrywmsnative/gest/picking_libero/PickingLiberoModule.java index 43ddcd44..ffda1162 100644 --- a/app/src/main/java/it/integry/integrywmsnative/gest/picking_libero/PickingLiberoModule.java +++ b/app/src/main/java/it/integry/integrywmsnative/gest/picking_libero/PickingLiberoModule.java @@ -1,5 +1,7 @@ package it.integry.integrywmsnative.gest.picking_libero; +import android.os.Handler; + import java.util.concurrent.ExecutorService; import javax.inject.Singleton; @@ -22,6 +24,7 @@ public class PickingLiberoModule { @Provides @Singleton PickingLiberoViewModel providesPickingLiberoViewModel(ExecutorService executorService, + Handler handler, ArticoloRESTConsumer articoloRESTConsumer, ColliMagazzinoRESTConsumer colliMagazzinoRESTConsumer, BarcodeRESTConsumer barcodeRESTConsumer, @@ -34,6 +37,7 @@ public class PickingLiberoModule { ) { return new PickingLiberoViewModel( executorService, + handler, articoloRESTConsumer, colliMagazzinoRESTConsumer, barcodeRESTConsumer, diff --git a/app/src/main/java/it/integry/integrywmsnative/gest/picking_libero/PickingLiberoViewModel.java b/app/src/main/java/it/integry/integrywmsnative/gest/picking_libero/PickingLiberoViewModel.java index 0c71ad4b..e675d333 100644 --- a/app/src/main/java/it/integry/integrywmsnative/gest/picking_libero/PickingLiberoViewModel.java +++ b/app/src/main/java/it/integry/integrywmsnative/gest/picking_libero/PickingLiberoViewModel.java @@ -1,5 +1,8 @@ package it.integry.integrywmsnative.gest.picking_libero; +import android.os.Handler; +import android.util.Pair; + import androidx.databinding.ObservableArrayList; import com.annimon.stream.Stream; @@ -71,6 +74,7 @@ public class PickingLiberoViewModel { private MtbColt mCurrentMtbColt = null; private final ExecutorService executorService; + private final Handler handler; private final ArticoloRESTConsumer mArticoloRESTConsumer; private final ColliMagazzinoRESTConsumer mColliMagazzinoRESTConsumer; private final BarcodeRESTConsumer mBarcodeRESTConsumer; @@ -96,7 +100,7 @@ public class PickingLiberoViewModel { @Inject - public PickingLiberoViewModel(ExecutorService executorService, + public PickingLiberoViewModel(ExecutorService executorService, Handler handler, ArticoloRESTConsumer articoloRESTConsumer, ColliMagazzinoRESTConsumer colliMagazzinoRESTConsumer, BarcodeRESTConsumer barcodeRESTConsumer, @@ -107,6 +111,7 @@ public class PickingLiberoViewModel { ColliSpedizioneRESTConsumer colliSpedizioneRESTConsumer, ColliDataRecoverService colliDataRecoverService) { this.executorService = executorService; + this.handler = handler; this.mArticoloRESTConsumer = articoloRESTConsumer; this.mColliMagazzinoRESTConsumer = colliMagazzinoRESTConsumer; this.mBarcodeRESTConsumer = barcodeRESTConsumer; @@ -133,43 +138,41 @@ public class PickingLiberoViewModel { } - public void processBarcodeDTO(BarcodeScanDTO barcodeScanDTO, Runnable onComplete) { + public void processBarcodeDTO(BarcodeScanDTO barcodeScanDTO) throws Exception { if (this.mCurrentMtbColt == null) { - this.createNewLU(null, null, () -> { - executeEtichettaBehaviour(barcodeScanDTO, onComplete); - }); - } else { - executeEtichettaBehaviour(barcodeScanDTO, onComplete); + this.createNewLU(null, null); } + + executeEtichettaBehaviour(barcodeScanDTO); } - private void executeEtichettaBehaviour(BarcodeScanDTO barcodeScanDTO, Runnable onComplete) { + private void executeEtichettaBehaviour(BarcodeScanDTO barcodeScanDTO) throws Exception { if (UtilityBarcode.isEtichettaAnonima(barcodeScanDTO)) { //Cerco gli articoli presenti nell'ul dell'etichetta anonima - this.executeEtichettaLU(barcodeScanDTO.getStringValue(), onComplete); + this.executeEtichettaLU(barcodeScanDTO.getStringValue()); } else if (UtilityBarcode.isEtichettaPosizione(barcodeScanDTO)) { //Cerco tramite etichetta un collo in posizione mono ul - this.executeEtichettaPosizione(barcodeScanDTO, onComplete); + this.executeEtichettaPosizione(barcodeScanDTO); } else if (UtilityBarcode.isEtichetta128(barcodeScanDTO)) { //Cerco tramite etichetta ean 128 (che può indicarmi una UL) - this.executeEtichettaEan128(barcodeScanDTO, onComplete); + this.executeEtichettaEan128(barcodeScanDTO); } else if (UtilityBarcode.isEanPeso(barcodeScanDTO) && SettingsManager.iDB().isFlagPickingLiberoEnableScanArt()) { //Cerco tramite etichetta ean 128 (che può indicarmi un articolo o una UL) - this.executeEtichettaEanPeso(barcodeScanDTO, onComplete); + this.executeEtichettaEanPeso(barcodeScanDTO); } else if (SettingsManager.iDB().isFlagPickingLiberoEnableScanArt()) { //Cerco tramite ean13 un collo in posizione mono ul definita in anagrafica articolo, altrimenti se abilitato procedo con picking manuale - this.loadArticolo(barcodeScanDTO.getStringValue(), null, onComplete); + this.loadArticolo(barcodeScanDTO.getStringValue(), null); } else { - this.sendError(new NoArtsFoundException()); + throw new NoArtsFoundException(); } } - private void executeEtichettaPosizione(BarcodeScanDTO barcodeScanDTO, Runnable onComplete) { + private void executeEtichettaPosizione(BarcodeScanDTO barcodeScanDTO) throws Exception { MtbDepoPosizione foundPosizione = Stream.of(SettingsManager.iDB().getAvailablePosizioni()) .filter(x -> x.getPosizione().equalsIgnoreCase(barcodeScanDTO.getStringValue())) @@ -177,204 +180,190 @@ public class PickingLiberoViewModel { if (foundPosizione == null) { //Nessuna posizione trovata con questo barcode - this.sendError(new ScannedPositionNotExistException()); - return; + throw new ScannedPositionNotExistException(); } if (foundPosizione.isMagazzinoAutomatico()) { //Eseguo picking da magazzino automatico - this.executeMagazzinoAutomatico(foundPosizione, onComplete); + this.executeMagazzinoAutomatico(foundPosizione); } else { - this.executePosizione(foundPosizione, null, onComplete); + this.executePosizione(foundPosizione, null); } } - private void executeMagazzinoAutomatico(MtbDepoPosizione mtbDepoPosizione, Runnable onComplete) { - mGiacenzaRESTConsumer.getGiacenzeInPosizione(mtbDepoPosizione, availableItems -> { + private void executeMagazzinoAutomatico(MtbDepoPosizione mtbDepoPosizione) throws Exception { + this.sendOnLoadingStarted(); + var availableItems = mGiacenzaRESTConsumer.getGiacenzeInPosizioneSynchronized(mtbDepoPosizione); - var mtbColrs = Stream.of(availableItems) - .map(MvwSitArtUdcDetInventario::toMtbColr) - .toList(); + var mtbColrs = availableItems.stream() + .map(MvwSitArtUdcDetInventario::toMtbColr) + .collect(Collectors.toList()); - List selectedMtbColrs = null; - try { - selectedMtbColrs = this.sendArtSelectionRequest(mtbColrs, null); - } catch (InterruptedException e) { - this.sendError(e); - return; - } - - if (selectedMtbColrs == null) { - this.sendOnLoadingEnded(); - return; - } - - final List magazzinoAutomaticoPickItemRequestDTOList = new ArrayList<>(); - for (MtbColr selectedArt : selectedMtbColrs) { - MagazzinoAutomaticoPickItemRequestDTO itemDto = new MagazzinoAutomaticoPickItemRequestDTO(selectedArt.getCodMart()) - .setQtaTot(selectedArt.getQtaCol()) - .setNumCnf(selectedArt.getNumCnf()) - .setUntMis(selectedArt.getUntMis()); - - magazzinoAutomaticoPickItemRequestDTOList.add(itemDto); - } - - var magazzinoAutomaticoPickRequest = new MagazzinoAutomaticoPickItemsRequestDTO() - .setShouldCreateUDS(true) - .setDefaultGestioneOfNewUDS(mDefaultGestione.getText()) - .setItemsToPick(magazzinoAutomaticoPickItemRequestDTOList); - - mMagazzinoAutomaticoRESTConsumer.pickItems(mtbDepoPosizione, - magazzinoAutomaticoPickRequest, onComplete, this::sendError); + List selectedMtbColrs = this.sendArtSelectionRequest(mtbColrs, null); + if (selectedMtbColrs == null) { this.sendOnLoadingEnded(); + return; + } - }, this::sendError); + final List magazzinoAutomaticoPickItemRequestDTOList = new ArrayList<>(); + for (MtbColr selectedArt : selectedMtbColrs) { + MagazzinoAutomaticoPickItemRequestDTO itemDto = new MagazzinoAutomaticoPickItemRequestDTO(selectedArt.getCodMart()) + .setQtaTot(selectedArt.getQtaCol()) + .setNumCnf(selectedArt.getNumCnf()) + .setUntMis(selectedArt.getUntMis()); + magazzinoAutomaticoPickItemRequestDTOList.add(itemDto); + } + var magazzinoAutomaticoPickRequest = new MagazzinoAutomaticoPickItemsRequestDTO() + .setShouldCreateUDS(true) + .setDefaultGestioneOfNewUDS(mDefaultGestione.getText()) + .setItemsToPick(magazzinoAutomaticoPickItemRequestDTOList); + + mMagazzinoAutomaticoRESTConsumer.pickItemsSynchronized(mtbDepoPosizione, + magazzinoAutomaticoPickRequest); + + this.sendOnLoadingEnded(); } - private void executePosizione(MtbDepoPosizione posizione, MtbAart articolo, Runnable onComplete) { - this.mPosizioniRESTConsumer.getBancaliInPosizione(posizione, mtbColtList -> { + private void executePosizione(MtbDepoPosizione posizione, MtbAart articolo) throws Exception { + var mtbColtList = this.mPosizioniRESTConsumer.getBancaliInPosizioneSynchronized(posizione); - if (mtbColtList == null || mtbColtList.isEmpty()) { - if (articolo != null) { - this.dispatchArt(articolo, null); - } else { - this.sendError(new NoLUFoundException()); - } - } else if (mtbColtList.size() == 1) { - this.mColliMagazzinoRESTConsumer.getByTestata(mtbColtList.get(0), true, false, mtbColt -> { - - boolean codMdepIsValid = Stream.of(SettingsManager.iDB().getAvailableCodMdep()) - .anyMatch(x -> x.getCodMdep().equalsIgnoreCase(mtbColt.getCodMdep())); - - if (codMdepIsValid) { - pickMerceULtoUL(mtbColt, articolo, onComplete); - } else this.sendError(new InvalidCodMdepException()); - - }, this::sendError); + if (mtbColtList == null || mtbColtList.isEmpty()) { + if (articolo != null) { + this.dispatchArt(articolo, null); } else { - this.sendError(new TooManyLUFoundInMonoLUPositionException()); + throw new NoLUFoundException(); } + } else if (mtbColtList.size() == 1) { + var mtbColt = this.mColliMagazzinoRESTConsumer.getByTestataSynchronized(mtbColtList.get(0), true, false); - }, this::sendError); - } + boolean codMdepIsValid = Stream.of(SettingsManager.iDB().getAvailableCodMdep()) + .anyMatch(x -> x.getCodMdep().equalsIgnoreCase(mtbColt.getCodMdep())); - private void executeEtichettaEanPeso(BarcodeScanDTO barcodeScanDTO, Runnable onComplete) { - try { - Ean13PesoModel ean13PesoModel = Ean13PesoModel.fromBarcode(barcodeScanDTO.getStringValue()); - this.loadArticolo(ean13PesoModel.getPrecode(), ean13PesoModel.toEan128(), onComplete); - } catch (Exception ex) { - this.sendError(ex); + if (codMdepIsValid) { + pickMerceULtoUL(mtbColt, articolo); + } else throw new InvalidCodMdepException(); + + + } else { + throw new TooManyLUFoundInMonoLUPositionException(); } } - private void executeEtichettaLU(String sscc, Runnable onComplete) { - mColliMagazzinoRESTConsumer.getBySSCC(sscc, true, false, mtbColtScanned -> { - - if (mtbColtScanned == null) { - this.sendError(new NoLUFoundException()); - } else if ((mtbColtScanned.getGestioneEnum() == GestioneEnum.ACQUISTO || mtbColtScanned.getGestioneEnum() == GestioneEnum.LAVORAZIONE) && mtbColtScanned.getSegno() > 0) { - - boolean codMdepIsValid = Stream.of(SettingsManager.iDB().getAvailableCodMdep()) - .anyMatch(x -> x.getCodMdep().equalsIgnoreCase(mtbColtScanned.getCodMdep())); - - if (codMdepIsValid) { - pickMerceULtoUL(mtbColtScanned, onComplete); - } else this.sendError(new InvalidCodMdepException()); - - } else { - this.sendError(new NoLUFoundException()); - } - - }, this::sendError); + private void executeEtichettaEanPeso(BarcodeScanDTO barcodeScanDTO) throws Exception { + Ean13PesoModel ean13PesoModel = Ean13PesoModel.fromBarcode(barcodeScanDTO.getStringValue()); + this.loadArticolo(ean13PesoModel.getPrecode(), ean13PesoModel.toEan128()); } - private void executeEtichettaEan128(BarcodeScanDTO barcodeScanDTO, Runnable onComplete) { - mBarcodeRESTConsumer.decodeEan128(barcodeScanDTO, ean128Model -> { + private void executeEtichettaLU(String sscc) throws Exception { + var mtbColtScanned = mColliMagazzinoRESTConsumer.getBySsccSynchronized(sscc, true, false); - String barcodeProd = null; + if (mtbColtScanned == null) { + throw new NoLUFoundException(); - if (!UtilityString.isNullOrEmpty(ean128Model.Sscc)) barcodeProd = ean128Model.Sscc; - if (!UtilityString.isNullOrEmpty(ean128Model.Gtin)) barcodeProd = ean128Model.Gtin; - if (!UtilityString.isNullOrEmpty(ean128Model.Content)) - barcodeProd = ean128Model.Content; + } else if ((mtbColtScanned.getGestioneEnum() == GestioneEnum.ACQUISTO || mtbColtScanned.getGestioneEnum() == GestioneEnum.LAVORAZIONE) && mtbColtScanned.getSegno() > 0) { - if (!UtilityString.isNullOrEmpty(barcodeProd)) { + boolean codMdepIsValid = SettingsManager.iDB().getAvailableCodMdep().stream() + .anyMatch(x -> x.getCodMdep().equalsIgnoreCase(mtbColtScanned.getCodMdep())); - if (!UtilityString.isNullOrEmpty(ean128Model.Sscc)) { - this.executeEtichettaLU(ean128Model.Sscc, onComplete); - } else if (!UtilityString.isNullOrEmpty(barcodeProd) && SettingsManager.iDB().isFlagPickingLiberoEnableScanArt()) { - this.loadArticolo(barcodeProd, ean128Model, onComplete); - } else { - this.sendError(new NoLUFoundException()); - } + if (codMdepIsValid) { + pickMerceULtoUL(mtbColtScanned); + } else throw new InvalidCodMdepException(); - } else { - //EAN 128 non completo o comunque mancano i riferimenti al prodotto - this.sendError(new NoLUFoundException()); - } - }, this::sendError); + } else { + throw new NoLUFoundException(); + } } - private void loadArticolo(String barcodeProd, Ean128Model ean128Model, Runnable onComplete) { - mArticoloRESTConsumer.searchByBarcode(barcodeProd, mtbAartList -> { - if (mtbAartList != null && !mtbAartList.isEmpty()) { - MtbAart articolo = mtbAartList.get(0); - MtbDepoPosizione posizione = UtilityPosizione.getFromCache(articolo.getPosizione()); + private void executeEtichettaEan128(BarcodeScanDTO barcodeScanDTO) throws Exception { + var ean128Model = mBarcodeRESTConsumer.decodeEan128Synchronized(barcodeScanDTO); - if (posizione != null && posizione.isFlagMonoCollo()) { - this.executePosizione(posizione, articolo, onComplete); - } else if (mDefaultGestione == GestioneEnum.VENDITA) { - this.dispatchArt(articolo, ean128Model); - onComplete.run(); - } else { - this.sendError(new NoResultFromBarcodeException(barcodeProd)); - } + String barcodeProd = 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(barcodeProd)) { + + if (!UtilityString.isNullOrEmpty(ean128Model.Sscc)) { + this.executeEtichettaLU(ean128Model.Sscc); + + } else if (!UtilityString.isNullOrEmpty(barcodeProd) && SettingsManager.iDB().isFlagPickingLiberoEnableScanArt()) { + this.loadArticolo(barcodeProd, ean128Model); } else { - this.sendError(new NoResultFromBarcodeException(barcodeProd)); + throw new NoLUFoundException(); } - }, this::sendError); + } else { + //EAN 128 non completo o comunque mancano i riferimenti al prodotto + throw new NoLUFoundException(); + } + + } + + private void loadArticolo(String barcodeProd, Ean128Model ean128Model) throws Exception { + var mtbAartList = mArticoloRESTConsumer.searchByBarcodeSynchronized(barcodeProd); + if (mtbAartList != null && !mtbAartList.isEmpty()) { + MtbAart articolo = mtbAartList.get(0); + MtbDepoPosizione posizione = UtilityPosizione.getFromCache(articolo.getPosizione()); + + if (posizione != null && posizione.isFlagMonoCollo()) { + this.executePosizione(posizione, articolo); + + } else if (mDefaultGestione == GestioneEnum.VENDITA) { + this.dispatchArt(articolo, ean128Model); + + } else { + throw new NoResultFromBarcodeException(barcodeProd); + } + + } else { + throw new NoResultFromBarcodeException(barcodeProd); + } } - public void createNewLU(Integer customNumCollo, String customSerCollo, Runnable onComplete) { + public void createNewLU(Integer customNumCollo, String customSerCollo) throws Exception { + VtbDest vtbDest = null; + String codJcom = null; + if (this.mFlagAskCliente) { - this.sendLUClienteRequired((vtbDest, codJcom) -> { - createNewLU_PostClienteAsk(customNumCollo, customSerCollo, vtbDest, onComplete); - }, this::sendOnLoadingEnded); - } else { - createNewLU_PostClienteAsk(customNumCollo, customSerCollo, null, onComplete); + var data = this.sendLUClienteRequired(); + vtbDest = data.first; + codJcom = data.second; } + + createNewLU_PostClienteAsk(customNumCollo, customSerCollo, vtbDest); } - private void createNewLU_PostClienteAsk(Integer customNumCollo, String customSerCollo, VtbDest vtbDest, Runnable onComplete) { + private void createNewLU_PostClienteAsk(Integer customNumCollo, String customSerCollo, VtbDest vtbDest) throws Exception { + DialogAskLineaProdResponse dialogAskLineaProdResponse = null; + if (this.mFlagAskLineaProd) { - this.sendLULineaProdRequired(response -> { - createNewLU_PostLineaProdAsk(customNumCollo, customSerCollo, vtbDest, response.getPosizione(), response.getIdLotto(), onComplete); - - }, this::sendOnLoadingEnded); - } else { - createNewLU_PostLineaProdAsk(customNumCollo, customSerCollo, vtbDest, null, null, onComplete); + dialogAskLineaProdResponse = this.sendLULineaProdRequired(); } + + createNewLU_PostLineaProdAsk(customNumCollo, customSerCollo, vtbDest, + dialogAskLineaProdResponse != null ? dialogAskLineaProdResponse.getPosizione() : null, + dialogAskLineaProdResponse != null ? dialogAskLineaProdResponse.getIdLotto() : null); } - private void createNewLU_PostLineaProdAsk(Integer customNumCollo, String customSerCollo, VtbDest vtbDest, String posizione, Integer idLotto, Runnable onComplete) { + private void createNewLU_PostLineaProdAsk(Integer customNumCollo, String customSerCollo, VtbDest vtbDest, String posizione, Integer idLotto) throws Exception { + JtbComt commessa = null; + if (this.mFlagAskCommessa) { - this.sendLUCommessaRequired(response -> { - createNewLU_PostCommessaAsk(customNumCollo, customSerCollo, vtbDest, posizione, idLotto, response, onComplete); - - }, this::sendOnLoadingEnded); - } else { - createNewLU_PostCommessaAsk(customNumCollo, customSerCollo, vtbDest, null, null, null, onComplete); + commessa = this.sendLUCommessaRequired(); } + createNewLU_PostCommessaAsk(customNumCollo, customSerCollo, vtbDest, posizione, idLotto, commessa); } - private void createNewLU_PostCommessaAsk(Integer customNumCollo, String customSerCollo, VtbDest vtbDest, String codJfas, Integer idLotto, JtbComt codJcom, Runnable onComplete) { + private void createNewLU_PostCommessaAsk(Integer customNumCollo, String customSerCollo, VtbDest vtbDest, String codJfas, Integer idLotto, JtbComt codJcom) throws Exception { this.mDefaultCommessa = codJcom; this.sendOnLoadingStarted(); @@ -404,59 +393,19 @@ public class PickingLiberoViewModel { } - mColliScaricoRESTConsumer.createUDS(createUDSRequest, mtbColt -> { - mMtbColtSessionID = mColliDataRecoverService.startNewSession(mtbColt, null); + var mtbColt = mColliScaricoRESTConsumer.createUDSSynchronized(createUDSRequest); - mtbColt - .setMtbColr(new ObservableArrayList<>()); + mMtbColtSessionID = mColliDataRecoverService.startNewSession(mtbColt, null); - this.mCurrentMtbColt = mtbColt; + mtbColt.setMtbColr(new ObservableArrayList<>()); - this.sendOnLoadingEnded(); + this.mCurrentMtbColt = mtbColt; - if (onComplete != null) onComplete.run(); - this.sendLUOpened(mtbColt); - }, this::sendError); - -// MtbColt mtbColt = new MtbColt(); -// mtbColt.initDefaultFields(mDefaultGestione) -// .setRifOrd(mDefaultGestione == GestioneEnum.LAVORAZIONE ? "PICKING LIBERO" : null) -// .setSegno(-1) -// .setOperation(CommonModelConsts.OPERATION.INSERT_OR_UPDATE); -// -// if (customNumCollo != null) { -// mtbColt.setNumCollo(customNumCollo); -// } -// -// if (!UtilityString.isNullOrEmpty(customSerCollo)) { -// mtbColt.setSerCollo(customSerCollo); -// } -// -// if (vtbDest != null) { -// mtbColt.setCodAnag(vtbDest.getCodAnag()); -// mtbColt.setCodVdes(vtbDest.getCodVdes()); -// } -// -// if (!UtilityString.isNullOrEmpty(codJcom)) { -// mtbColt.setCodJcom(codJcom); -// } - -// mColliMagazzinoRESTConsumer.saveCollo(mtbColt, value -> { -// mtbColt -// .setNumCollo(value.getNumCollo()) -// .setDataCollo(value.getDataColloS()) -// .setMtbColr(new ObservableArrayList<>()); -// -// this.mCurrentMtbColt = mtbColt; -// -// this.sendOnLoadingEnded(); -// -// if (onComplete != null) onComplete.run(); -// this.sendLUOpened(mtbColt); -// }, this::sendError); + this.sendOnLoadingEnded(); + this.sendLUOpened(mtbColt); } - private void dispatchArt(MtbAart mtbAart, Ean128Model ean128Model) { + private void dispatchArt(MtbAart mtbAart, Ean128Model ean128Model) throws Exception { PickingObjectDTO pickingObjectDTO = new PickingObjectDTO() .setMtbAart(mtbAart) .setTempPickData(PickDataDTO.fromEan128(ean128Model)); @@ -485,7 +434,7 @@ public class PickingLiberoViewModel { if (manualPickDTO.isEanPeso()) { if (mtbAart.getUntMisRifPeso() == MtbAart.UntMisRifPesoEnum.M) { if (UtilityBigDecimal.equalsTo(mtbAart.getPesoKg(), BigDecimal.ZERO)) { - this.sendError(new InvalidPesoKGException()); + throw new InvalidPesoKGException(); } else { qtaColDaPrelevare = UtilityBigDecimal.divide(qtaColDaPrelevare, mtbAart.getPesoKg()); } @@ -533,7 +482,7 @@ public class PickingLiberoViewModel { } - this.sendOnItemDispatched( + var pickedQuantityDTO = this.sendOnItemDispatched( pickingObjectDTO, pickingObjectDTO.getMtbAart(), initialNumCnf, @@ -549,86 +498,71 @@ public class PickingLiberoViewModel { dataScad, false, true, - true, - (pickedQuantityDTO, shouldCloseLU) -> { - if (pickedQuantityDTO == null) { - this.sendOnLoadingEnded(); - return; - } + true); - this.saveNewRow(pickingObjectDTO, - pickedQuantityDTO.getNumCnf(), - pickedQuantityDTO.getQtaCnf(), - pickedQuantityDTO.getQtaTot(), - pickedQuantityDTO.getPartitaMag(), - pickedQuantityDTO.getDataScad(), - shouldCloseLU); - }); + if (pickedQuantityDTO == null) { + return; + } + + this.saveNewRow(pickingObjectDTO, + pickedQuantityDTO.getNumCnf(), + pickedQuantityDTO.getQtaCnf(), + pickedQuantityDTO.getQtaTot(), + pickedQuantityDTO.getPartitaMag(), + pickedQuantityDTO.getDataScad(), + pickedQuantityDTO.isShouldCloseLu()); } - private void pickMerceULtoUL(MtbColt sourceMtbColt, Runnable onComplete) { - pickMerceULtoUL(sourceMtbColt, null, onComplete); + private void pickMerceULtoUL(MtbColt sourceMtbColt) throws Exception { + pickMerceULtoUL(sourceMtbColt, null); } - private void pickMerceULtoUL(MtbColt sourceMtbColt, MtbAart mtbAart, Runnable onComplete) { - executorService.execute(() -> { + private void pickMerceULtoUL(MtbColt sourceMtbColt, MtbAart mtbAart) throws Exception { - try { - List mtbColrsToPick = sourceMtbColt.getMtbColr().stream() - .filter(x -> UtilityBigDecimal.greaterThan(x.getQtaCol(), BigDecimal.ZERO)) - .collect(Collectors.toList()); + List mtbColrsToPick = sourceMtbColt.getMtbColr().stream() + .filter(x -> UtilityBigDecimal.greaterThan(x.getQtaCol(), BigDecimal.ZERO)) + .collect(Collectors.toList()); - List pickedAarts = this.sendArtSelectionRequest(mtbColrsToPick, mtbAart); + List pickedAarts = this.sendArtSelectionRequest(mtbColrsToPick, mtbAart); - if (pickedAarts == null) { - this.sendOnLoadingEnded(); - return; - } + if (pickedAarts == null) { + return; + } - List mtbColrsToMove = new ArrayList<>(); + List mtbColrsToMove = new ArrayList<>(); - if (!pickedAarts.isEmpty()) { - for (var pickedArt : pickedAarts) { - var mtbColr = askSingleQuantity(pickedArt); + if (!pickedAarts.isEmpty()) { + for (var pickedArt : pickedAarts) { + var mtbColr = askSingleQuantity(pickedArt); - if (mtbColr != null) - mtbColrsToMove.add(mtbColr); - } - - if (!mtbColrsToMove.isEmpty()) { - - if (this.mDefaultCommessa != null) - mtbColrsToMove.forEach(x -> x.setCodJcom(this.mDefaultCommessa.getCodJcom())); - - MtbColt clonedSourceTestata = (MtbColt) sourceMtbColt.clone(); - clonedSourceTestata.getMtbColr().clear(); - clonedSourceTestata.getMtbColr().addAll(mtbColrsToMove); - - mColliMagazzinoRESTConsumer.spostaArtsTraUL(clonedSourceTestata, - this.mCurrentMtbColt, true, (generatedMtbColrs) -> { - - mCurrentMtbColt.getMtbColr().addAll(generatedMtbColrs); - - this.sendOnRowSaved(); - this.sendOnLoadingEnded(); - onComplete.run(); - }, this::sendError); - - } else { - onComplete.run(); - this.sendOnLoadingEnded(); - } - - } else { - onComplete.run(); - this.sendOnLoadingEnded(); - } - - } catch (InterruptedException e) { - this.sendError(e); + if (mtbColr != null) + mtbColrsToMove.add(mtbColr); } - }); + if (!mtbColrsToMove.isEmpty()) { + this.sendOnLoadingStarted(); + + if (this.mDefaultCommessa != null) + mtbColrsToMove.forEach(x -> x.setCodJcom(this.mDefaultCommessa.getCodJcom())); + + MtbColt clonedSourceTestata = (MtbColt) sourceMtbColt.clone(); + clonedSourceTestata.getMtbColr().clear(); + clonedSourceTestata.getMtbColr().addAll(mtbColrsToMove); + + var generatedMtbColrs = mColliMagazzinoRESTConsumer.spostaArtsTraULSynchronized(clonedSourceTestata, + this.mCurrentMtbColt, true); + + handler.post(() -> { + mCurrentMtbColt.getMtbColr().addAll(generatedMtbColrs); + }); + + this.sendOnRowSaved(); + this.sendOnLoadingEnded(); + } + + } + + } private MtbColr askSingleQuantity(MtbColr mtbColr) throws InterruptedException { @@ -650,10 +584,7 @@ public class PickingLiberoViewModel { new PickDataDTO() .setSourceMtbColt(sourceMtbColt)); - CountDownLatch countDownLatch = new CountDownLatch(1); - AtomicReference result = new AtomicReference<>(); - - this.sendOnItemDispatched( + var pickedQuantityDTO = this.sendOnItemDispatched( pickingObjectDTO, pickingObjectDTO.getMtbAart(), mtbColr.getNumCnf(), @@ -669,35 +600,25 @@ public class PickingLiberoViewModel { mtbColr.getDataScadPartita(), false, false, - false, - (pickedQuantityDTO, shouldCloseLU) -> { - if (pickedQuantityDTO == null) { - countDownLatch.countDown(); - return; - } + false); - mtbColr - .setPartitaMag(pickedQuantityDTO.getPartitaMag()) - .setDataScadPartita(pickedQuantityDTO.getDataScad()) - .setQtaCol(pickedQuantityDTO.getQtaTot()) - .setQtaCnf(pickedQuantityDTO.getQtaCnf()) - .setNumCnf(pickedQuantityDTO.getNumCnf()) - .setDatetimeRow(UtilityDate.getDateInstance()) - .setMtbAart(pickingObjectDTO.getMtbAart()); + if (pickedQuantityDTO == null) + return null; - result.set(mtbColr); - countDownLatch.countDown(); - }); + mtbColr + .setPartitaMag(pickedQuantityDTO.getPartitaMag()) + .setDataScadPartita(pickedQuantityDTO.getDataScad()) + .setQtaCol(pickedQuantityDTO.getQtaTot()) + .setQtaCnf(pickedQuantityDTO.getQtaCnf()) + .setNumCnf(pickedQuantityDTO.getNumCnf()) + .setDatetimeRow(UtilityDate.getDateInstance()) + .setMtbAart(pickingObjectDTO.getMtbAart()); - - countDownLatch.await(); - return result.get(); + return mtbColr; } - public void saveNewRow(PickingObjectDTO pickingObjectDTO, BigDecimal numCnf, BigDecimal qtaCnf, BigDecimal qtaTot, String partitaMag, LocalDate dataScad, boolean shouldCloseLU) { - this.sendOnLoadingStarted(); - + public void saveNewRow(PickingObjectDTO pickingObjectDTO, BigDecimal numCnf, BigDecimal qtaCnf, BigDecimal qtaTot, String partitaMag, LocalDate dataScad, boolean shouldCloseLU) throws Exception { final MtbColr mtbColr = new MtbColr() .setCodMart(pickingObjectDTO.getMtbAart().getCodMart()) .setPartitaMag(partitaMag) @@ -722,28 +643,26 @@ public class PickingLiberoViewModel { return; } - mColliMagazzinoRESTConsumer.saveCollo(cloneMtbColt, value -> { - mtbColr - .setDataCollo(value.getDataColloS()) - .setNumCollo(value.getNumCollo()) - .setGestione(value.getGestione()) - .setSerCollo(value.getSerCollo()) - .setRiga(value.getMtbColr().get(value.getMtbColr().size() - 1).getRiga()) - .setUntMis(pickingObjectDTO.getMtbAart().getUntMis()) - .setMtbAart(pickingObjectDTO.getMtbAart()); + var value = mColliMagazzinoRESTConsumer.saveColloSynchronized(cloneMtbColt); - mCurrentMtbColt.getMtbColr().add(mtbColr); + mtbColr + .setDataCollo(value.getDataColloS()) + .setNumCollo(value.getNumCollo()) + .setGestione(value.getGestione()) + .setSerCollo(value.getSerCollo()) + .setRiga(value.getMtbColr().get(value.getMtbColr().size() - 1).getRiga()) + .setUntMis(pickingObjectDTO.getMtbAart().getUntMis()) + .setMtbAart(pickingObjectDTO.getMtbAart()); - this.sendOnRowSaved(); - this.sendOnLoadingEnded(); + mCurrentMtbColt.getMtbColr().add(mtbColr); - if (shouldCloseLU) closeLU(null); - }, this::sendError); + this.sendOnRowSaved(); + if (shouldCloseLU) closeLU(); } - private void loadRifULFromMtbColr(MtbColr mtbColr, RunnableArgs onComplete) { + private MtbColt loadRifULFromMtbColr(MtbColr mtbColr) throws Exception { //Se ho dei riferimenti ad una UL devo leggere la QTA ancora disponibile sulla Ul if (mtbColr != null && !UtilityString.isNullOrEmpty(mtbColr.getGestioneRif()) && @@ -751,103 +670,99 @@ public class PickingLiberoViewModel { !UtilityString.isNullOrEmpty(mtbColr.getDataColloRifS()) && mtbColr.getNumColloRif() != null) { - mColliMagazzinoRESTConsumer.getByChiaveCollo( + MtbColt mtbColt = mColliMagazzinoRESTConsumer.getByChiaveColloSynchronized( mtbColr.getGestioneRifEnum(), mtbColr.getNumColloRif(), mtbColr.getDataColloRifS(), mtbColr.getSerColloRif(), true, - false, - onComplete, - this::sendError); + false); - } else { - onComplete.run(null); + return mtbColt; } + + return null; } - public void dispatchRowEdit(MtbColr mtbColrToUpdate) { + public void dispatchRowEdit(MtbColr mtbColrToUpdate) throws Exception { + this.sendOnLoadingStarted(); final PickingObjectDTO pickingObjectDTO = new PickingObjectDTO() .setMtbAart(mtbColrToUpdate.getMtbAart()); - loadRifULFromMtbColr(mtbColrToUpdate, mtbColtRif -> { + var mtbColtRif = loadRifULFromMtbColr(mtbColrToUpdate); - BigDecimal totalQtaAvailable = null; - BigDecimal totalNumCnfAvailable = null; - BigDecimal qtaCnfAvailable = null; + BigDecimal totalQtaAvailable = null; + BigDecimal totalNumCnfAvailable = null; + BigDecimal qtaCnfAvailable = null; - List mtbColrRifs = mtbColtRif != null && - mtbColtRif.getMtbColr() != null ? mtbColtRif.getMtbColr() : null; + List mtbColrRifs = mtbColtRif != null && + mtbColtRif.getMtbColr() != null ? mtbColtRif.getMtbColr() : null; - MtbColr mtbColrRif = null; + MtbColr mtbColrRif = null; - if (mtbColrRifs != null && !mtbColrRifs.isEmpty()) { - //TODO: Da capire se è necessario controllare anche il cod_jcom - mtbColrRif = Stream.of(mtbColrRifs) - .filter(x -> UtilityString.equalsIgnoreCase(x.getCodMart(), mtbColrToUpdate.getCodMart()) && - UtilityString.equalsIgnoreCase(x.getCodCol(), mtbColrToUpdate.getCodCol()) && - UtilityString.equalsIgnoreCase(x.getCodTagl(), mtbColrToUpdate.getCodTagl()) && - UtilityString.equalsIgnoreCase(x.getPartitaMag(), mtbColrToUpdate.getPartitaMag())) - .findFirstOrElse(null); - } + if (mtbColrRifs != null && !mtbColrRifs.isEmpty()) { + //TODO: Da capire se è necessario controllare anche il cod_jcom + mtbColrRif = mtbColrRifs.stream() + .filter(x -> UtilityString.equalsIgnoreCase(x.getCodMart(), mtbColrToUpdate.getCodMart()) && + UtilityString.equalsIgnoreCase(x.getCodCol(), mtbColrToUpdate.getCodCol()) && + UtilityString.equalsIgnoreCase(x.getCodTagl(), mtbColrToUpdate.getCodTagl()) && + UtilityString.equalsIgnoreCase(x.getPartitaMag(), mtbColrToUpdate.getPartitaMag())) + .findFirst() + .orElse(null); + } - if (mtbColrRif != null) { + if (mtbColrRif != null) { + totalQtaAvailable = mtbColrRif.getQtaCol().add(mtbColrToUpdate.getQtaCol()); + totalNumCnfAvailable = mtbColrRif.getNumCnf().add(mtbColrToUpdate.getNumCnf()); + qtaCnfAvailable = mtbColrRif.getQtaCnf(); - totalQtaAvailable = mtbColrRif.getQtaCol().add(mtbColrToUpdate.getQtaCol()); - totalNumCnfAvailable = mtbColrRif.getNumCnf().add(mtbColrToUpdate.getNumCnf()); - qtaCnfAvailable = mtbColrRif.getQtaCnf(); + } else { + totalQtaAvailable = mtbColrToUpdate.getQtaCol(); + totalNumCnfAvailable = mtbColrToUpdate.getNumCnf(); + qtaCnfAvailable = mtbColrToUpdate.getQtaCnf(); - } else { + } + this.sendOnLoadingEnded(); - totalQtaAvailable = mtbColrToUpdate.getQtaCol(); - totalNumCnfAvailable = mtbColrToUpdate.getNumCnf(); - qtaCnfAvailable = mtbColrToUpdate.getQtaCnf(); + var pickedQuantityDTO = this.sendOnItemDispatched( + pickingObjectDTO, + pickingObjectDTO.getMtbAart(), + mtbColrToUpdate.getNumCnf(), + mtbColrToUpdate.getQtaCnf(), + mtbColrToUpdate.getQtaCol(), + totalQtaAvailable, + totalNumCnfAvailable, + qtaCnfAvailable, + null, + null, + null, + mtbColrToUpdate.getPartitaMag(), + mtbColrToUpdate.getDataScadPartita(), + false, + false, + false); - } + if (pickedQuantityDTO == null) { + return; + } - this.sendOnItemDispatched( - pickingObjectDTO, - pickingObjectDTO.getMtbAart(), - mtbColrToUpdate.getNumCnf(), - mtbColrToUpdate.getQtaCnf(), - mtbColrToUpdate.getQtaCol(), - totalQtaAvailable, - totalNumCnfAvailable, - qtaCnfAvailable, - null, - null, - null, - mtbColrToUpdate.getPartitaMag(), - mtbColrToUpdate.getDataScadPartita(), - false, - false, - false, - (pickedQuantityDTO, shouldCloseLU) -> { - if (pickedQuantityDTO == null) { - this.sendOnLoadingEnded(); - return; - } - - this.saveEditedRow(mtbColrToUpdate, - pickedQuantityDTO.getNumCnf(), - pickedQuantityDTO.getQtaCnf(), - pickedQuantityDTO.getQtaTot(), - pickedQuantityDTO.getPartitaMag(), - pickedQuantityDTO.getDataScad(), - shouldCloseLU); - }); - - - }); + this.sendOnLoadingStarted(); + this.saveEditedRow(mtbColrToUpdate, + pickedQuantityDTO.getNumCnf(), + pickedQuantityDTO.getQtaCnf(), + pickedQuantityDTO.getQtaTot(), + pickedQuantityDTO.getPartitaMag(), + pickedQuantityDTO.getDataScad(), + pickedQuantityDTO.isShouldCloseLu()); + this.sendOnLoadingEnded(); } - 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(); @@ -871,110 +786,105 @@ public class PickingLiberoViewModel { mtbColt.getMtbColr().add(mtbColr); - this.mColliMagazzinoRESTConsumer.saveCollo(mtbColt, (value) -> { + var value = this.mColliMagazzinoRESTConsumer.saveColloSynchronized(mtbColt); - mtbColr.setNumCnf(numCnf) - .setQtaCnf(qtaCnf) - .setQtaCol(qtaTot); + mtbColr.setNumCnf(numCnf) + .setQtaCnf(qtaCnf) + .setQtaCol(qtaTot); + handler.post(() -> { this.mCurrentMtbColt.getMtbColr().remove(mtbColrToUpdate); this.mCurrentMtbColt.getMtbColr().add(mtbColr); + }); + + this.sendOnRowSaved(); + this.sendOnLoadingEnded(); + } + + + public void deleteRow(MtbColr mtbColrToDelete) throws Exception { + var shouldDelete = this.sendMtbColrDeleteRequest(); + if (shouldDelete) { + this.sendOnLoadingStarted(); + + MtbColt mtbColt = new MtbColt() + .setNumCollo(mtbColrToDelete.getNumCollo()) + .setDataCollo(mtbColrToDelete.getDataColloS()) + .setSerCollo(mtbColrToDelete.getSerCollo()) + .setGestione(mtbColrToDelete.getGestione()) + .setMtbColr(new ObservableArrayList<>()); + + mtbColt.setOperation(CommonModelConsts.OPERATION.NO_OP); + + MtbColr mtbColr = (MtbColr) mtbColrToDelete.clone(); + + mtbColr.setOperation(CommonModelConsts.OPERATION.DELETE); + mtbColt.getMtbColr().add(mtbColr); + + var value = this.mColliMagazzinoRESTConsumer.saveColloSynchronized(mtbColt); + + handler.post(() -> { + this.mCurrentMtbColt.getMtbColr().remove(mtbColrToDelete); + }); this.sendOnRowSaved(); this.sendOnLoadingEnded(); - - }, this::sendError); + } } - public void deleteRow(MtbColr mtbColrToDelete) { - this.sendMtbColrDeleteRequest(shouldDelete -> { - if (shouldDelete) { - this.sendOnLoadingStarted(); - - MtbColt mtbColt = new MtbColt() - .setNumCollo(mtbColrToDelete.getNumCollo()) - .setDataCollo(mtbColrToDelete.getDataColloS()) - .setSerCollo(mtbColrToDelete.getSerCollo()) - .setGestione(mtbColrToDelete.getGestione()) - .setMtbColr(new ObservableArrayList<>()); - mtbColt.setOperation(CommonModelConsts.OPERATION.NO_OP); - - MtbColr mtbColr = (MtbColr) mtbColrToDelete.clone(); - - mtbColr.setOperation(CommonModelConsts.OPERATION.DELETE); - mtbColt.getMtbColr().add(mtbColr); - - this.mColliMagazzinoRESTConsumer.saveCollo(mtbColt, (value) -> { - this.mCurrentMtbColt.getMtbColr().remove(mtbColrToDelete); - - this.sendOnRowSaved(); - this.sendOnLoadingEnded(); - - }, this::sendError); - } - }); - } - - - public void closeLU(Runnable onComplete) { + public void closeLU() throws Exception { if (mCurrentMtbColt == null) { - if (onComplete != null) onComplete.run(); return; } - this.sendOnLoadingStarted(); this.mDefaultCommessa = null; - mColliMagazzinoRESTConsumer.canULBeDeleted(mCurrentMtbColt, canBeDeleted -> { - if (canBeDeleted) { - deleteLU(() -> { - if (mMtbColtSessionID != null) - this.mColliDataRecoverService.closeSession(mMtbColtSessionID); + var canBeDeleted = mColliMagazzinoRESTConsumer.canULBeDeletedSynchronized(mCurrentMtbColt); - this.sendLUClosed(); - this.sendOnLoadingEnded(); + if (canBeDeleted) { + deleteLU(); - this.mCurrentMtbColt = null; - if (onComplete != null) onComplete.run(); - }); - } else { + if (mMtbColtSessionID != null) + this.mColliDataRecoverService.closeSession(mMtbColtSessionID); - this.mColliMagazzinoRESTConsumer.assegnaLottoSuColloScarico(mCurrentMtbColt, () -> { + this.sendLUClosed(); + this.sendOnLoadingEnded(); - var closeUDSRequest = new CloseUDSRequestDTO() - .setMtbColt(mCurrentMtbColt); - - if (this.mDefaultGestione == GestioneEnum.LAVORAZIONE) { - closeUDSRequest - .setCreateDocument(SettingsManager.iDB().isProduzioneGeneraDocScar()) - .setDocumentCodDtip(SettingsManager.iDB().getProduzioneCodDtipScar()) - .setDocumentCodAnag(SettingsManager.iDB().getInternalCodAnags().stream().filter(InternalCodAnagsDTO::isFornitore).findFirst().get().getCodAnag()); - } - - this.mColliScaricoRESTConsumer.closeUDS(closeUDSRequest, response -> { - if (mMtbColtSessionID != null) - this.mColliDataRecoverService.closeSession(mMtbColtSessionID); - - this.sendLUClosed(); - this.sendOnLoadingEnded(); - - this.mCurrentMtbColt = null; - if (onComplete != null) onComplete.run(); - }, this::sendError); - }, this::sendError); - } - }, this::sendError); - } - - private void deleteLU(Runnable onComplete) { - DeleteULRequestDTO deleteULRequestDTO = new DeleteULRequestDTO() - .setMtbColt(mCurrentMtbColt); - mColliMagazzinoRESTConsumer.deleteUL(deleteULRequestDTO, () -> { this.mCurrentMtbColt = null; - if (onComplete != null) onComplete.run(); - }, this::sendError); + } else { + this.mColliMagazzinoRESTConsumer.assegnaLottoSuColloScaricoSynchronized(mCurrentMtbColt); + + var closeUDSRequest = new CloseUDSRequestDTO() + .setMtbColt(mCurrentMtbColt); + + if (this.mDefaultGestione == GestioneEnum.LAVORAZIONE) { + closeUDSRequest + .setCreateDocument(SettingsManager.iDB().isProduzioneGeneraDocScar()) + .setDocumentCodDtip(SettingsManager.iDB().getProduzioneCodDtipScar()) + .setDocumentCodAnag(SettingsManager.iDB().getInternalCodAnags().stream().filter(InternalCodAnagsDTO::isFornitore).findFirst().get().getCodAnag()); + } + + var response = this.mColliScaricoRESTConsumer.closeUDSSynchronized(closeUDSRequest); + + if (mMtbColtSessionID != null) + this.mColliDataRecoverService.closeSession(mMtbColtSessionID); + + this.sendLUClosed(); + + this.mCurrentMtbColt = null; + } + + } + + private void deleteLU() throws Exception { + DeleteULRequestDTO deleteULRequestDTO = new DeleteULRequestDTO() + .setMtbColt(mCurrentMtbColt); + + mColliMagazzinoRESTConsumer.deleteULSynchronized(deleteULRequestDTO); + + this.mCurrentMtbColt = null; } @@ -998,20 +908,61 @@ public class PickingLiberoViewModel { if (this.mListener != null) mListener.onLUClosed(); } - private void sendMtbColrDeleteRequest(RunnableArgs onComplete) { - if (this.mListener != null) mListener.onMtbColrDeleteRequest(onComplete); + private Boolean sendMtbColrDeleteRequest() throws InterruptedException { + CountDownLatch countDownLatch = new CountDownLatch(1); + AtomicReference result = new AtomicReference<>(); + + if (this.mListener != null) mListener.onMtbColrDeleteRequest(data -> { + result.set(data); + countDownLatch.countDown(); + }); + else countDownLatch.countDown(); + + countDownLatch.await(); + return result.get(); } - private void sendLUClienteRequired(RunnableArgss onComplete, Runnable onAbort) { - if (this.mListener != null) mListener.onLUClienteRequired(onComplete, onAbort); + private Pair sendLUClienteRequired() throws InterruptedException { + CountDownLatch countDownLatch = new CountDownLatch(1); + AtomicReference> result = new AtomicReference<>(); + + + if (this.mListener != null) mListener.onLUClienteRequired((vtbDest, codJcom) -> { + result.set(new Pair<>(vtbDest, codJcom)); + countDownLatch.countDown(); + }, countDownLatch::countDown); + else countDownLatch.countDown(); + + countDownLatch.await(); + return result.get(); } - private void sendLULineaProdRequired(RunnableArgs onComplete, Runnable onAbort) { - if (this.mListener != null) mListener.onLULineaProdRequired(onComplete, onAbort); + private DialogAskLineaProdResponse sendLULineaProdRequired() throws InterruptedException { + CountDownLatch countDownLatch = new CountDownLatch(1); + AtomicReference result = new AtomicReference<>(); + + if (this.mListener != null) mListener.onLULineaProdRequired(data -> { + result.set(data); + countDownLatch.countDown(); + }, countDownLatch::countDown); + else countDownLatch.countDown(); + + countDownLatch.await(); + return result.get(); } - private void sendLUCommessaRequired(RunnableArgs onComplete, Runnable onAbort) { - if (this.mListener != null) mListener.onLUCommessaRequired(onComplete, onAbort); + private JtbComt sendLUCommessaRequired() throws InterruptedException { + CountDownLatch countDownLatch = new CountDownLatch(1); + AtomicReference result = new AtomicReference<>(); + + if (this.mListener != null) mListener.onLUCommessaRequired(data -> { + result.set(data); + countDownLatch.countDown(); + }, countDownLatch::countDown); + else countDownLatch.countDown(); + + countDownLatch.await(); + return result.get(); } private List sendArtSelectionRequest(List mtbColrsToPick, MtbAart mtbAart) throws InterruptedException { @@ -1026,28 +977,30 @@ public class PickingLiberoViewModel { }, countDownLatch::countDown); else countDownLatch.countDown(); - countDownLatch.await(); return result.get(); } - private void sendOnItemDispatched(PickingObjectDTO pickingObjectDTO, - MtbAart mtbAart, - BigDecimal initialNumCnf, - BigDecimal initialQtaCnf, - BigDecimal initialQtaTot, - BigDecimal totalQtaAvailable, - BigDecimal totalNumCnfAvailable, - BigDecimal qtaCnfAvailable, - 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 totalQtaAvailable, + BigDecimal totalNumCnfAvailable, + BigDecimal qtaCnfAvailable, + BigDecimal totalQtaToBeTaken, + BigDecimal totalNumCnfToBeTaken, + BigDecimal qtaCnfToBeTaken, + String partitaMag, + LocalDate dataScad, + boolean canOverflowOrderQuantity, + boolean canPartitaMagBeChanged, + boolean canLUBeClosed) throws InterruptedException { + + + CountDownLatch countDownLatch = new CountDownLatch(1); + AtomicReference result = new AtomicReference<>(); if (this.mListener != null) mListener.onItemDispatched(pickingObjectDTO, mtbAart, @@ -1065,7 +1018,17 @@ public class PickingLiberoViewModel { canOverflowOrderQuantity, canPartitaMagBeChanged, canLUBeClosed, - onComplete); + pickedQuantityDTO -> { + if (pickedQuantityDTO != null) { + result.set(pickedQuantityDTO); + } + + countDownLatch.countDown(); + }); + + + countDownLatch.await(); + return result.get(); } private void sendOnRowSaved() { @@ -1105,7 +1068,7 @@ public class PickingLiberoViewModel { boolean canOverflowOrderQuantity, boolean canPartitaMagBeChanged, boolean canLUBeClosed, - RunnableArgss onComplete); + RunnableArgs onComplete); } diff --git a/app/src/main/java/it/integry/integrywmsnative/gest/spedizione/SpedizioneViewModel.java b/app/src/main/java/it/integry/integrywmsnative/gest/spedizione/SpedizioneViewModel.java index f80a8460..c5c24e76 100644 --- a/app/src/main/java/it/integry/integrywmsnative/gest/spedizione/SpedizioneViewModel.java +++ b/app/src/main/java/it/integry/integrywmsnative/gest/spedizione/SpedizioneViewModel.java @@ -812,7 +812,7 @@ public class SpedizioneViewModel { .setOrdersOfNewUDS(orders) .setItemsToPick(magazzinoAutomaticoPickItemRequestDTOList); - mMagazzinoAutomaticoRESTConsumer.pickItemsSynchronous(mtbDepoPosizione, magazzinoAutomaticoPickRequest); + mMagazzinoAutomaticoRESTConsumer.pickItemsSynchronized(mtbDepoPosizione, magazzinoAutomaticoPickRequest); } public void executeEmptyMagazzinoAutomaticoRequest(MtbDepoPosizione mtbDepoPosizione) throws Exception { @@ -826,7 +826,7 @@ public class SpedizioneViewModel { .setDefaultGestioneOfNewUDS(mDefaultGestioneOfUL.getText()) .setOrdersOfNewUDS(orders); - mMagazzinoAutomaticoRESTConsumer.pickItemsSynchronous(mtbDepoPosizione, magazzinoAutomaticoPickRequest); + mMagazzinoAutomaticoRESTConsumer.pickItemsSynchronized(mtbDepoPosizione, magazzinoAutomaticoPickRequest); } private void searchArtFromUL(MtbColt scannedUL) throws Exception { diff --git a/app/src/main/java/it/integry/integrywmsnative/view/dialogs/input_quantity_v2/DialogInputQuantityV2View.java b/app/src/main/java/it/integry/integrywmsnative/view/dialogs/input_quantity_v2/DialogInputQuantityV2View.java index daa9b4df..81694f1e 100644 --- a/app/src/main/java/it/integry/integrywmsnative/view/dialogs/input_quantity_v2/DialogInputQuantityV2View.java +++ b/app/src/main/java/it/integry/integrywmsnative/view/dialogs/input_quantity_v2/DialogInputQuantityV2View.java @@ -298,6 +298,8 @@ public class DialogInputQuantityV2View extends BaseDialogFragment implements Dia } private void dismiss(DialogInputQuantityV2ResultDTO result) { + super.dismiss(); + if (this.mOnComplete != null) { if(result == null) { result = new DialogInputQuantityV2ResultDTO() @@ -306,7 +308,6 @@ public class DialogInputQuantityV2View extends BaseDialogFragment implements Dia this.mOnComplete.run(result); } - super.dismiss(); } @Override