Migliorata gestione callback e chiamate in background per Picking Libero

This commit is contained in:
Giuseppe Scorrano 2025-02-28 15:26:02 +01:00
parent e5a4cf59c4
commit 5694d8bd1c
10 changed files with 689 additions and 647 deletions

View File

@ -269,8 +269,8 @@ public class MainApplicationModule {
@Provides @Provides
@Singleton @Singleton
GiacenzaRESTConsumer provideGiacenzaRESTConsumer(RESTBuilder restBuilder, ArticoloRESTConsumer articoloRESTConsumer) { GiacenzaRESTConsumer provideGiacenzaRESTConsumer(RESTBuilder restBuilder, ExecutorService executorService, ArticoloRESTConsumer articoloRESTConsumer) {
return new GiacenzaRESTConsumer(restBuilder, articoloRESTConsumer); return new GiacenzaRESTConsumer(restBuilder, executorService, articoloRESTConsumer);
} }
@Provides @Provides

View File

@ -16,8 +16,8 @@ import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.Objects; import java.util.Objects;
import java.util.concurrent.ExecutorService;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import javax.inject.Singleton; 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.RettificaULDTO;
import it.integry.integrywmsnative.core.rest.model.ServiceRESTResponse; import it.integry.integrywmsnative.core.rest.model.ServiceRESTResponse;
import it.integry.integrywmsnative.core.rest.model.SpostaArtsTraULRequestDTO; 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.SpostaULRequestDTO;
import it.integry.integrywmsnative.core.rest.model.UpdateTipoULRequestDTO; import it.integry.integrywmsnative.core.rest.model.UpdateTipoULRequestDTO;
import it.integry.integrywmsnative.core.rest.model.VersamentoAutomaticoULResponseDTO; import it.integry.integrywmsnative.core.rest.model.VersamentoAutomaticoULResponseDTO;
@ -75,7 +74,7 @@ public class ColliMagazzinoRESTConsumer extends _BaseRESTConsumer {
this.executorService = executorService; this.executorService = executorService;
} }
public void saveCollo(MtbColt mtbColtToSave, RunnableArgs<MtbColt> onComplete, RunnableArgs<Exception> onFailed) { public MtbColt saveColloSynchronized(MtbColt mtbColtToSave) throws Exception {
MtbColt mtbColtToSaveClone = (MtbColt) mtbColtToSave.clone(); MtbColt mtbColtToSaveClone = (MtbColt) mtbColtToSave.clone();
mtbColtToSaveClone.setOperation(CommonModelConsts.OPERATION.INSERT_OR_UPDATE); mtbColtToSaveClone.setOperation(CommonModelConsts.OPERATION.INSERT_OR_UPDATE);
mtbColtToSaveClone.setOnlyPkMaster(false); mtbColtToSaveClone.setOnlyPkMaster(false);
@ -86,17 +85,18 @@ public class ColliMagazzinoRESTConsumer extends _BaseRESTConsumer {
.setMtbPartitaMag(null); .setMtbPartitaMag(null);
} }
this.mEntityRESTConsumer.processEntity(mtbColtToSaveClone, new ISimpleOperationCallback<>() { return this.mEntityRESTConsumer.processEntitySynchronized(mtbColtToSaveClone, MtbColt.class);
@Override
public void onSuccess(MtbColt value) {
if (onComplete != null) onComplete.run(value);
} }
@Override public void saveCollo(MtbColt mtbColtToSave, RunnableArgs<MtbColt> onComplete, RunnableArgs<Exception> onFailed) {
public void onFailed(Exception ex) { executorService.execute(() -> {
try {
var mtbColt = saveColloSynchronized(mtbColtToSave);
if (onComplete != null) onComplete.run(mtbColt);
} catch (Exception ex) {
if (onFailed != null) onFailed.run(ex); if (onFailed != null) onFailed.run(ex);
} }
}, MtbColt.class); });
} }
@ -327,6 +327,36 @@ public class ColliMagazzinoRESTConsumer extends _BaseRESTConsumer {
}); });
} }
public List<MtbColr> fillMtbAartsOfMtbColrsSynchronized(List<MtbColr> mtbColrs) throws Exception {
List<String> 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<MtbAart> 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<MtbColt> fillMtbAartsOfMtbColtsSynchronized(List<MtbColt> mtbColts) throws Exception { public List<MtbColt> fillMtbAartsOfMtbColtsSynchronized(List<MtbColt> mtbColts) throws Exception {
List<String> codMarts = new ArrayList<>(); List<String> codMarts = new ArrayList<>();
@ -405,6 +435,7 @@ public class ColliMagazzinoRESTConsumer extends _BaseRESTConsumer {
return getByTestataSynchronized(mtbColtToRetrieve, onlyResiduo, throwExcIfNull); return getByTestataSynchronized(mtbColtToRetrieve, onlyResiduo, throwExcIfNull);
} }
public void getByChiaveCollo(GestioneEnum gestione, int numCollo, String dataCollo, String serCollo, boolean onlyResiduo, boolean throwExcIfNull, RunnableArgs<MtbColt> onComplete, RunnableArgs<Exception> onFailed) { public void getByChiaveCollo(GestioneEnum gestione, int numCollo, String dataCollo, String serCollo, boolean onlyResiduo, boolean throwExcIfNull, RunnableArgs<MtbColt> onComplete, RunnableArgs<Exception> onFailed) {
MtbColt mtbColtToRetrieve = new MtbColt() MtbColt mtbColtToRetrieve = new MtbColt()
.setGestione(gestione) .setGestione(gestione)
@ -424,9 +455,7 @@ public class ColliMagazzinoRESTConsumer extends _BaseRESTConsumer {
.execute(); .execute();
var mtbColt = analyzeAnswer(response, "getColloInGiac"); var mtbColt = analyzeAnswer(response, "getColloInGiac");
if (mtbColt != null && mtbColt.getMtbColr() != null && !mtbColt.getMtbColr().isEmpty()) { if (mtbColt != null && mtbColt.getMtbColr() != null && !mtbColt.getMtbColr().isEmpty()) {
List<MtbColt> mtbColtList = new ArrayList<>(); var mtbColts = fillMtbAartsOfMtbColtsSynchronized(Collections.singletonList(mtbColt));
mtbColtList.add(mtbColt);
var mtbColts = fillMtbAartsOfMtbColtsSynchronized(mtbColtList);
return mtbColts.get(0); return mtbColts.get(0);
} }
@ -576,8 +605,7 @@ public class ColliMagazzinoRESTConsumer extends _BaseRESTConsumer {
}); });
} }
public void spostaArtsTraUL(MtbColt sourceMtbColt, MtbColt destMtbColt, boolean flagForceUseRefs, RunnableArgs<List<MtbColr>> onComplete, RunnableArgs<Exception> onFailed) { public List<MtbColr> spostaArtsTraULSynchronized(MtbColt sourceMtbColt, MtbColt destMtbColt, boolean flagForceUseRefs) throws Exception {
executorService.execute(() -> {
MtbColt mtbColtToMoveClone = (MtbColt) sourceMtbColt.clone(); MtbColt mtbColtToMoveClone = (MtbColt) sourceMtbColt.clone();
MtbColt mtbColtDestClone = (MtbColt) destMtbColt.clone(); MtbColt mtbColtDestClone = (MtbColt) destMtbColt.clone();
@ -595,25 +623,27 @@ public class ColliMagazzinoRESTConsumer extends _BaseRESTConsumer {
.setFlagForceUseRefs(flagForceUseRefs); .setFlagForceUseRefs(flagForceUseRefs);
ColliMagazzinoRESTConsumerService colliMagazzinoRESTConsumerService = restBuilder.getService(ColliMagazzinoRESTConsumerService.class); ColliMagazzinoRESTConsumerService colliMagazzinoRESTConsumerService = restBuilder.getService(ColliMagazzinoRESTConsumerService.class);
colliMagazzinoRESTConsumerService.spostaArtsTraUL(spostaArtsTraULRequestDTO).enqueue(new ManagedErrorCallback<>() { var response = colliMagazzinoRESTConsumerService.spostaArtsTraUL(spostaArtsTraULRequestDTO)
@Override .execute();
public void onResponse(Call<ServiceRESTResponse<SpostaArtsTraULResponseDTO>> call, Response<ServiceRESTResponse<SpostaArtsTraULResponseDTO>> response) {
analyzeAnswer(response, "spostaArtsTraUL", data -> {
fillMtbAartsOfMtbColrs(data.getGeneratedMtbColr(), onComplete, onFailed); var data = analyzeAnswer(response, "spostaArtsTraUL");
var mtbColrs = fillMtbAartsOfMtbColrsSynchronized(data.getGeneratedMtbColr());
}, onFailed); return mtbColrs;
} }
@Override public void spostaArtsTraUL(MtbColt sourceMtbColt, MtbColt destMtbColt, boolean flagForceUseRefs, RunnableArgs<List<MtbColr>> onComplete, RunnableArgs<Exception> onFailed) {
public void onFailure(Call<ServiceRESTResponse<SpostaArtsTraULResponseDTO>> call, @NonNull final Exception e) { executorService.execute(() -> {
if (onFailed != null) onFailed.run(e); try {
var result = spostaArtsTraULSynchronized(sourceMtbColt, destMtbColt, flagForceUseRefs);
if (onComplete != null) onComplete.run(result);
} catch (Exception ex) {
if (onFailed != null) onFailed.run(ex);
} }
}); });
});
} }
public void assegnaLottoSuColloScarico(MtbColt sourceMtbColt, Runnable onComplete, RunnableArgs<Exception> onFailed) { public MtbColt assegnaLottoSuColloScaricoSynchronized(MtbColt sourceMtbColt) throws Exception {
MtbColt sourceMtbColtClone = (MtbColt) sourceMtbColt.clone(); MtbColt sourceMtbColtClone = (MtbColt) sourceMtbColt.clone();
for (int i = 0; i < sourceMtbColtClone.getMtbColr().size(); i++) { 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 colliMagazzinoRESTConsumerService = restBuilder.getService(ColliMagazzinoRESTConsumerService.class);
colliMagazzinoRESTConsumerService.assegnaLottoSuColloScarico(sourceMtbColtClone).enqueue(new ManagedErrorCallback<>() { var response = colliMagazzinoRESTConsumerService.assegnaLottoSuColloScarico(sourceMtbColtClone)
@Override .execute();
public void onResponse(Call<ServiceRESTResponse<MtbColt>> call, Response<ServiceRESTResponse<MtbColt>> response) {
analyzeAnswer(response, "assegnaLottoSuColloScarico", data -> { var data = analyzeAnswer(response, "assegnaLottoSuColloScarico");
onComplete.run(); return data;
}, onFailed);
} }
@Override public void assegnaLottoSuColloScarico(MtbColt sourceMtbColt, Runnable onComplete, RunnableArgs<Exception> onFailed) {
public void onFailure(Call<ServiceRESTResponse<MtbColt>> call, @NonNull final Exception e) { executorService.execute(() -> {
if (onFailed != null) onFailed.run(e); try {
var result = assegnaLottoSuColloScaricoSynchronized(sourceMtbColt);
if (onComplete != null) onComplete.run();
} catch (Exception ex) {
if (onFailed != null) onFailed.run(ex);
} }
}); });
} }

View File

@ -34,43 +34,39 @@ public class EntityRESTConsumer extends _BaseRESTConsumer {
this.executorService = executorService; this.executorService = executorService;
} }
public <T extends EntityBase> void processEntity(T entityToSave, final ISimpleOperationCallback<T> callback, Class<T> type) { public <T extends EntityBase> T processEntitySynchronized(T entityToSave, Class<T> type) throws Exception {
RunnableArgs<Exception> tmpFailed = ex -> {
if (callback != null) callback.onFailed(ex);
};
EntityRESTConsumerService service = restBuilder.getService(EntityRESTConsumerService.class); EntityRESTConsumerService service = restBuilder.getService(EntityRESTConsumerService.class);
service var response = service
.processEntity(entityToSave) .processEntity(entityToSave)
.enqueue(new ManagedErrorCallback<>() { .execute();
@Override
public void onResponse(Call<ServiceRESTResponse<JsonObject>> call, Response<ServiceRESTResponse<JsonObject>> response) {
if (response.isSuccessful()) {
if (response.isSuccessful()) {
if (response.body() != null) { if (response.body() != null) {
if (response.body().getEsito() == EsitoType.OK) { if (response.body().getEsito() == EsitoType.OK) {
Gson gson = UtilityGson.createObject(); Gson gson = UtilityGson.createObject();
T object = gson.fromJson(response.body().getEntity(), type);
callback.onSuccess(object); return gson.fromJson(response.body().getEntity(), type);
} else { } else {
Log.e("EntityRESTConsumer", response.body().getErrorMessage()); Log.e("EntityRESTConsumer", response.body().getErrorMessage());
tmpFailed.run(new Exception(response.body().getErrorMessage())); throw new Exception(response.body().getErrorMessage());
} }
} else { } else {
Log.e("EntityRESTConsumer", response.message()); Log.e("EntityRESTConsumer", response.message());
tmpFailed.run(new Exception(response.message())); throw new Exception(response.message());
} }
} else { } else {
Log.e("EntityRESTConsumer", "Status " + response.code() + ": " + response.message()); Log.e("EntityRESTConsumer", "Status " + response.code() + ": " + response.message());
tmpFailed.run(new Exception("Status " + response.code() + ": " + response.message())); throw new Exception("Status " + response.code() + ": " + response.message());
} }
} }
@Override public <T extends EntityBase> void processEntity(T entityToSave, final ISimpleOperationCallback<T> callback, Class<T> type) {
public void onFailure(Call<ServiceRESTResponse<JsonObject>> call, @NonNull final Exception e) { executorService.execute(() -> {
tmpFailed.run(e); try {
var data = processEntitySynchronized(entityToSave, type);
if (callback != null) callback.onSuccess(data);
} catch (Exception ex) {
if (callback != null) callback.onFailed(ex);
} }
}); });

View File

@ -7,6 +7,8 @@ import com.annimon.stream.Stream;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.stream.Collectors;
import javax.inject.Singleton; import javax.inject.Singleton;
@ -28,29 +30,30 @@ import retrofit2.Response;
public class GiacenzaRESTConsumer extends _BaseRESTConsumer { public class GiacenzaRESTConsumer extends _BaseRESTConsumer {
private final RESTBuilder restBuilder; private final RESTBuilder restBuilder;
private final ExecutorService executorService;
private final ArticoloRESTConsumer mArticoloRESTConsumer; private final ArticoloRESTConsumer mArticoloRESTConsumer;
public GiacenzaRESTConsumer(RESTBuilder restBuilder, ArticoloRESTConsumer articoloRESTConsumer) { public GiacenzaRESTConsumer(RESTBuilder restBuilder, ExecutorService executorService, ArticoloRESTConsumer articoloRESTConsumer) {
this.restBuilder = restBuilder; this.restBuilder = restBuilder;
this.executorService = executorService;
this.mArticoloRESTConsumer = articoloRESTConsumer; this.mArticoloRESTConsumer = articoloRESTConsumer;
} }
public void getGiacenzeInPosizione(MtbDepoPosizione posizione, RunnableArgs<List<MvwSitArtUdcDetInventario>> onComplete, RunnableArgs<Exception> onFailed) { public List<MvwSitArtUdcDetInventario> getGiacenzeInPosizioneSynchronized(MtbDepoPosizione posizione) throws Exception {
GiacenzaRESTConsumerService giacenzaRESTConsumerService = restBuilder.getService(GiacenzaRESTConsumerService.class); GiacenzaRESTConsumerService giacenzaRESTConsumerService = restBuilder.getService(GiacenzaRESTConsumerService.class);
giacenzaRESTConsumerService.retrieveAvailableItems(posizione.getPosizione()).enqueue(new ManagedErrorCallback<>() { var response = giacenzaRESTConsumerService.retrieveAvailableItems(posizione.getPosizione())
@Override .execute();
public void onResponse(Call<ServiceRESTResponse<List<MvwSitArtUdcDetInventario>>> call, Response<ServiceRESTResponse<List<MvwSitArtUdcDetInventario>>> response) {
analyzeAnswer(response, "getGiacenzeInPosizione", inventarioList -> { var inventarioList = analyzeAnswer(response, "getGiacenzeInPosizione");
if (inventarioList != null && !inventarioList.isEmpty()) { if (inventarioList != null && !inventarioList.isEmpty()) {
List<String> codMarts = Stream.of(inventarioList) List<String> codMarts = inventarioList.stream()
.map(x -> x.getCodMart().trim()) .map(x -> x.getCodMart().trim())
.toList(); .collect(Collectors.toList());
mArticoloRESTConsumer.getByCodMarts(codMarts, mtbAarts -> { var mtbAarts = mArticoloRESTConsumer.getByCodMartsSynchronized(codMarts);
for (var row : inventarioList) { for (var row : inventarioList) {
MtbAart foundMtbAart = null; MtbAart foundMtbAart = null;
Optional<MtbAart> mtbAartOpt = Stream.of(mtbAarts) Optional<MtbAart> mtbAartOpt = Stream.of(mtbAarts)
.filter(x -> x.getCodMart().equalsIgnoreCase(row.getCodMart())) .filter(x -> x.getCodMart().equalsIgnoreCase(row.getCodMart()))
@ -63,17 +66,19 @@ public class GiacenzaRESTConsumer extends _BaseRESTConsumer {
row.setMtbAart(foundMtbAart); row.setMtbAart(foundMtbAart);
} }
onComplete.run(inventarioList); return inventarioList;
}, onFailed);
}else{
onComplete.run(new ArrayList<>());
}
}, onFailed);
} }
@Override return new ArrayList<>();
public void onFailure(Call<ServiceRESTResponse<List<MvwSitArtUdcDetInventario>>> call, @NonNull final Exception e) { }
onFailed.run(e);
public void getGiacenzeInPosizione(MtbDepoPosizione posizione, RunnableArgs<List<MvwSitArtUdcDetInventario>> onComplete, RunnableArgs<Exception> onFailed) {
executorService.execute(() -> {
try {
var result = getGiacenzeInPosizioneSynchronized(posizione);
if (onComplete != null) onComplete.run(result);
} catch (Exception ex) {
if (onFailed != null) onFailed.run(ex);
} }
}); });
} }

View File

@ -28,7 +28,7 @@ public class MagazzinoAutomaticoRESTConsumer extends _BaseRESTConsumer {
this.restBuilder = restBuilder; 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); MagazzinoAutomaticoRESTConsumerService magazzinoAutomaticoRESTConsumerService = restBuilder.getService(MagazzinoAutomaticoRESTConsumerService.class);
var response = magazzinoAutomaticoRESTConsumerService.pickItems(posizione.getPosizione(), magazzinoAutomaticoPickItemsRequestDTO) var response = magazzinoAutomaticoRESTConsumerService.pickItems(posizione.getPosizione(), magazzinoAutomaticoPickItemsRequestDTO)
.execute(); .execute();
@ -39,7 +39,7 @@ public class MagazzinoAutomaticoRESTConsumer extends _BaseRESTConsumer {
public void pickItems(MtbDepoPosizione posizione, MagazzinoAutomaticoPickItemsRequestDTO magazzinoAutomaticoPickItemsRequestDTO, Runnable onComplete, RunnableArgs<Exception> onFailed) { public void pickItems(MtbDepoPosizione posizione, MagazzinoAutomaticoPickItemsRequestDTO magazzinoAutomaticoPickItemsRequestDTO, Runnable onComplete, RunnableArgs<Exception> onFailed) {
executorService.execute(() -> { executorService.execute(() -> {
try { try {
pickItemsSynchronous(posizione, magazzinoAutomaticoPickItemsRequestDTO); pickItemsSynchronized(posizione, magazzinoAutomaticoPickItemsRequestDTO);
if (onComplete != null) onComplete.run(); if (onComplete != null) onComplete.run();
} catch (Exception ex) { } catch (Exception ex) {
if (onFailed != null) onFailed.run(ex); if (onFailed != null) onFailed.run(ex);

View File

@ -3,6 +3,7 @@ package it.integry.integrywmsnative.gest.picking_libero;
import android.content.Context; import android.content.Context;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler;
import android.text.SpannableString; import android.text.SpannableString;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
@ -76,6 +77,9 @@ public class PickingLiberoFragment extends BaseFragment implements ITitledFragme
@Inject @Inject
DialogInputQuantityV2View mDialogInputQuantityV2View; DialogInputQuantityV2View mDialogInputQuantityV2View;
@Inject
Handler handler;
public BindableBoolean thereIsAnOpenedUL = new BindableBoolean(false); public BindableBoolean thereIsAnOpenedUL = new BindableBoolean(false);
public BindableBoolean thereIsntAnOpenedUL = new BindableBoolean(true); public BindableBoolean thereIsntAnOpenedUL = new BindableBoolean(true);
public BindableBoolean thereIsAnyRowInUL = new BindableBoolean(false); public BindableBoolean thereIsAnyRowInUL = new BindableBoolean(false);
@ -206,23 +210,41 @@ public class PickingLiberoFragment extends BaseFragment implements ITitledFragme
} }
private final RunnableArgs<BarcodeScanDTO> onScanSuccessful = data -> { private final RunnableArgs<BarcodeScanDTO> onScanSuccessful = data -> {
BarcodeManager.disable(mBarcodeScannerInstanceID);
this.onLoadingStarted(); this.onLoadingStarted();
this.mViewModel.processBarcodeDTO(data, () -> { executorService.execute(() -> {
BarcodeManager.enable(mBarcodeScannerInstanceID); try {
this.onLoadingEnded(); this.mViewModel.processBarcodeDTO(data);
} catch (Exception e) {
onError(e);
}
}); });
this.onLoadingEnded();
}; };
public void createNewLU() { 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() { public void closeLU() {
destroyAdapter(); destroyAdapter();
this.mViewModel.closeLU(null);
executorService.execute(() -> {
try {
this.onLoadingStarted();
this.mViewModel.closeLU();
this.onLoadingEnded();
} catch (Exception e) {
this.onError(e);
}
});
} }
@Override @Override
@ -241,7 +263,7 @@ public class PickingLiberoFragment extends BaseFragment implements ITitledFragme
@Override @Override
public void onLUOpened(MtbColt mtbColt) { public void onLUOpened(MtbColt mtbColt) {
requireActivity().runOnUiThread(() -> { handler.post(() -> {
mToolbarTitleText.setText(String.format(getActivity().getText(R.string.lu_number_text).toString(), mtbColt.getNumCollo())); mToolbarTitleText.setText(String.format(getActivity().getText(R.string.lu_number_text).toString(), mtbColt.getNumCollo()));
initAdapter(); initAdapter();
@ -264,7 +286,7 @@ public class PickingLiberoFragment extends BaseFragment implements ITitledFragme
@Override @Override
public void onLUClosed() { public void onLUClosed() {
requireActivity().runOnUiThread(() -> { handler.post(() -> {
mToolbarTitleText.setText(getActivity().getText(R.string.free_picking_title_fragment).toString()); mToolbarTitleText.setText(getActivity().getText(R.string.free_picking_title_fragment).toString());
destroyAdapter(); destroyAdapter();
@ -285,7 +307,7 @@ public class PickingLiberoFragment extends BaseFragment implements ITitledFragme
@Override @Override
public void onError(Exception ex) { public void onError(Exception ex) {
requireActivity().runOnUiThread(() -> { handler.post(() -> {
this.onLoadingEnded(); this.onLoadingEnded();
if (ex instanceof InvalidPesoKGException) { if (ex instanceof InvalidPesoKGException) {
@ -344,7 +366,7 @@ public class PickingLiberoFragment extends BaseFragment implements ITitledFragme
boolean canOverflowOrderQuantity, boolean canOverflowOrderQuantity,
boolean canPartitaMagBeChanged, boolean canPartitaMagBeChanged,
boolean canLUBeClosed, boolean canLUBeClosed,
RunnableArgss<PickedQuantityDTO, Boolean> onComplete) { RunnableArgs<PickedQuantityDTO> onComplete) {
DialogInputQuantityV2DTO dialogInputQuantityV2DTO = new DialogInputQuantityV2DTO() DialogInputQuantityV2DTO dialogInputQuantityV2DTO = new DialogInputQuantityV2DTO()
.setMtbAart(mtbAart) .setMtbAart(mtbAart)
@ -367,7 +389,7 @@ public class PickingLiberoFragment extends BaseFragment implements ITitledFragme
mDialogInputQuantityV2View.setDialogInputQuantityV2DTO(dialogInputQuantityV2DTO) mDialogInputQuantityV2View.setDialogInputQuantityV2DTO(dialogInputQuantityV2DTO)
.setOnComplete(resultDTO -> { .setOnComplete(resultDTO -> {
if (resultDTO == null || resultDTO.isAborted()) { if (resultDTO == null || resultDTO.isAborted()) {
onComplete.run(null, false); onComplete.run(null);
return; return;
} }
@ -378,17 +400,14 @@ public class PickingLiberoFragment extends BaseFragment implements ITitledFragme
.setPartitaMag(resultDTO.getPartitaMag()) .setPartitaMag(resultDTO.getPartitaMag())
.setDataScad(resultDTO.getDataScad()); .setDataScad(resultDTO.getDataScad());
onComplete.run(pickedQuantityDTO, resultDTO.isShouldCloseLu()); onComplete.run(pickedQuantityDTO);
})
.setOnAbort(() -> {
onComplete.run(null, false);
}) })
.show(requireActivity().getSupportFragmentManager(), "tag"); .show(requireActivity().getSupportFragmentManager(), "tag");
} }
@Override @Override
public void onRowSaved() { public void onRowSaved() {
requireActivity().runOnUiThread(() -> { handler.post(() -> {
Snackbar.make(mBindings.getRoot(), R.string.data_saved, Snackbar.LENGTH_SHORT) 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(); .show();
@ -398,19 +417,40 @@ public class PickingLiberoFragment extends BaseFragment implements ITitledFragme
@Override @Override
public void onMtbColrEdit(MtbColr mtbColr) { public void onMtbColrEdit(MtbColr mtbColr) {
executorService.execute(() -> {
try {
this.mViewModel.dispatchRowEdit(mtbColr); this.mViewModel.dispatchRowEdit(mtbColr);
} catch (Exception e) {
this.onError(e);
}
});
} }
@Override @Override
public void onMtbColrDelete(MtbColr mtbColr) { public void onMtbColrDelete(MtbColr mtbColr) {
executorService.execute(() -> {
try {
this.mViewModel.deleteRow(mtbColr); this.mViewModel.deleteRow(mtbColr);
} catch (Exception e) {
this.onError(e);
}
});
} }
@Override @Override
public void onPreDestroy(Runnable onComplete) { public void onPreDestroy(Runnable onComplete) {
BarcodeManager.removeCallback(mBarcodeScannerInstanceID); BarcodeManager.removeCallback(mBarcodeScannerInstanceID);
if (thereIsAnOpenedUL.get()) mViewModel.closeLU(onComplete); if (thereIsAnOpenedUL.get()) {
else onComplete.run(); executorService.execute(() -> {
try {
this.onLoadingStarted();
mViewModel.closeLU();
this.onLoadingEnded();
} catch (Exception e) {
onError(e);
}
});
} else onComplete.run();
} }
@Override @Override

View File

@ -1,5 +1,7 @@
package it.integry.integrywmsnative.gest.picking_libero; package it.integry.integrywmsnative.gest.picking_libero;
import android.os.Handler;
import java.util.concurrent.ExecutorService; import java.util.concurrent.ExecutorService;
import javax.inject.Singleton; import javax.inject.Singleton;
@ -22,6 +24,7 @@ public class PickingLiberoModule {
@Provides @Provides
@Singleton @Singleton
PickingLiberoViewModel providesPickingLiberoViewModel(ExecutorService executorService, PickingLiberoViewModel providesPickingLiberoViewModel(ExecutorService executorService,
Handler handler,
ArticoloRESTConsumer articoloRESTConsumer, ArticoloRESTConsumer articoloRESTConsumer,
ColliMagazzinoRESTConsumer colliMagazzinoRESTConsumer, ColliMagazzinoRESTConsumer colliMagazzinoRESTConsumer,
BarcodeRESTConsumer barcodeRESTConsumer, BarcodeRESTConsumer barcodeRESTConsumer,
@ -34,6 +37,7 @@ public class PickingLiberoModule {
) { ) {
return new PickingLiberoViewModel( return new PickingLiberoViewModel(
executorService, executorService,
handler,
articoloRESTConsumer, articoloRESTConsumer,
colliMagazzinoRESTConsumer, colliMagazzinoRESTConsumer,
barcodeRESTConsumer, barcodeRESTConsumer,

View File

@ -1,5 +1,8 @@
package it.integry.integrywmsnative.gest.picking_libero; package it.integry.integrywmsnative.gest.picking_libero;
import android.os.Handler;
import android.util.Pair;
import androidx.databinding.ObservableArrayList; import androidx.databinding.ObservableArrayList;
import com.annimon.stream.Stream; import com.annimon.stream.Stream;
@ -71,6 +74,7 @@ public class PickingLiberoViewModel {
private MtbColt mCurrentMtbColt = null; private MtbColt mCurrentMtbColt = null;
private final ExecutorService executorService; private final ExecutorService executorService;
private final Handler handler;
private final ArticoloRESTConsumer mArticoloRESTConsumer; private final ArticoloRESTConsumer mArticoloRESTConsumer;
private final ColliMagazzinoRESTConsumer mColliMagazzinoRESTConsumer; private final ColliMagazzinoRESTConsumer mColliMagazzinoRESTConsumer;
private final BarcodeRESTConsumer mBarcodeRESTConsumer; private final BarcodeRESTConsumer mBarcodeRESTConsumer;
@ -96,7 +100,7 @@ public class PickingLiberoViewModel {
@Inject @Inject
public PickingLiberoViewModel(ExecutorService executorService, public PickingLiberoViewModel(ExecutorService executorService, Handler handler,
ArticoloRESTConsumer articoloRESTConsumer, ArticoloRESTConsumer articoloRESTConsumer,
ColliMagazzinoRESTConsumer colliMagazzinoRESTConsumer, ColliMagazzinoRESTConsumer colliMagazzinoRESTConsumer,
BarcodeRESTConsumer barcodeRESTConsumer, BarcodeRESTConsumer barcodeRESTConsumer,
@ -107,6 +111,7 @@ public class PickingLiberoViewModel {
ColliSpedizioneRESTConsumer colliSpedizioneRESTConsumer, ColliSpedizioneRESTConsumer colliSpedizioneRESTConsumer,
ColliDataRecoverService colliDataRecoverService) { ColliDataRecoverService colliDataRecoverService) {
this.executorService = executorService; this.executorService = executorService;
this.handler = handler;
this.mArticoloRESTConsumer = articoloRESTConsumer; this.mArticoloRESTConsumer = articoloRESTConsumer;
this.mColliMagazzinoRESTConsumer = colliMagazzinoRESTConsumer; this.mColliMagazzinoRESTConsumer = colliMagazzinoRESTConsumer;
this.mBarcodeRESTConsumer = barcodeRESTConsumer; 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) { if (this.mCurrentMtbColt == null) {
this.createNewLU(null, null, () -> { this.createNewLU(null, null);
executeEtichettaBehaviour(barcodeScanDTO, onComplete);
});
} else {
executeEtichettaBehaviour(barcodeScanDTO, onComplete);
}
} }
private void executeEtichettaBehaviour(BarcodeScanDTO barcodeScanDTO, Runnable onComplete) { executeEtichettaBehaviour(barcodeScanDTO);
}
private void executeEtichettaBehaviour(BarcodeScanDTO barcodeScanDTO) throws Exception {
if (UtilityBarcode.isEtichettaAnonima(barcodeScanDTO)) { if (UtilityBarcode.isEtichettaAnonima(barcodeScanDTO)) {
//Cerco gli articoli presenti nell'ul dell'etichetta anonima //Cerco gli articoli presenti nell'ul dell'etichetta anonima
this.executeEtichettaLU(barcodeScanDTO.getStringValue(), onComplete); this.executeEtichettaLU(barcodeScanDTO.getStringValue());
} else if (UtilityBarcode.isEtichettaPosizione(barcodeScanDTO)) { } else if (UtilityBarcode.isEtichettaPosizione(barcodeScanDTO)) {
//Cerco tramite etichetta un collo in posizione mono ul //Cerco tramite etichetta un collo in posizione mono ul
this.executeEtichettaPosizione(barcodeScanDTO, onComplete); this.executeEtichettaPosizione(barcodeScanDTO);
} else if (UtilityBarcode.isEtichetta128(barcodeScanDTO)) { } else if (UtilityBarcode.isEtichetta128(barcodeScanDTO)) {
//Cerco tramite etichetta ean 128 (che può indicarmi una UL) //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()) { } else if (UtilityBarcode.isEanPeso(barcodeScanDTO) && SettingsManager.iDB().isFlagPickingLiberoEnableScanArt()) {
//Cerco tramite etichetta ean 128 (che può indicarmi un articolo o una UL) //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()) { } 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 //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 { } 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()) MtbDepoPosizione foundPosizione = Stream.of(SettingsManager.iDB().getAvailablePosizioni())
.filter(x -> x.getPosizione().equalsIgnoreCase(barcodeScanDTO.getStringValue())) .filter(x -> x.getPosizione().equalsIgnoreCase(barcodeScanDTO.getStringValue()))
@ -177,33 +180,27 @@ public class PickingLiberoViewModel {
if (foundPosizione == null) { if (foundPosizione == null) {
//Nessuna posizione trovata con questo barcode //Nessuna posizione trovata con questo barcode
this.sendError(new ScannedPositionNotExistException()); throw new ScannedPositionNotExistException();
return;
} }
if (foundPosizione.isMagazzinoAutomatico()) { if (foundPosizione.isMagazzinoAutomatico()) {
//Eseguo picking da magazzino automatico //Eseguo picking da magazzino automatico
this.executeMagazzinoAutomatico(foundPosizione, onComplete); this.executeMagazzinoAutomatico(foundPosizione);
} else { } else {
this.executePosizione(foundPosizione, null, onComplete); this.executePosizione(foundPosizione, null);
} }
} }
private void executeMagazzinoAutomatico(MtbDepoPosizione mtbDepoPosizione, Runnable onComplete) { private void executeMagazzinoAutomatico(MtbDepoPosizione mtbDepoPosizione) throws Exception {
mGiacenzaRESTConsumer.getGiacenzeInPosizione(mtbDepoPosizione, availableItems -> { this.sendOnLoadingStarted();
var availableItems = mGiacenzaRESTConsumer.getGiacenzeInPosizioneSynchronized(mtbDepoPosizione);
var mtbColrs = Stream.of(availableItems) var mtbColrs = availableItems.stream()
.map(MvwSitArtUdcDetInventario::toMtbColr) .map(MvwSitArtUdcDetInventario::toMtbColr)
.toList(); .collect(Collectors.toList());
List<MtbColr> selectedMtbColrs = null; List<MtbColr> selectedMtbColrs = this.sendArtSelectionRequest(mtbColrs, null);
try {
selectedMtbColrs = this.sendArtSelectionRequest(mtbColrs, null);
} catch (InterruptedException e) {
this.sendError(e);
return;
}
if (selectedMtbColrs == null) { if (selectedMtbColrs == null) {
this.sendOnLoadingEnded(); this.sendOnLoadingEnded();
@ -225,75 +222,64 @@ public class PickingLiberoViewModel {
.setDefaultGestioneOfNewUDS(mDefaultGestione.getText()) .setDefaultGestioneOfNewUDS(mDefaultGestione.getText())
.setItemsToPick(magazzinoAutomaticoPickItemRequestDTOList); .setItemsToPick(magazzinoAutomaticoPickItemRequestDTOList);
mMagazzinoAutomaticoRESTConsumer.pickItems(mtbDepoPosizione, mMagazzinoAutomaticoRESTConsumer.pickItemsSynchronized(mtbDepoPosizione,
magazzinoAutomaticoPickRequest, onComplete, this::sendError); magazzinoAutomaticoPickRequest);
this.sendOnLoadingEnded(); this.sendOnLoadingEnded();
}, this::sendError);
} }
private void executePosizione(MtbDepoPosizione posizione, MtbAart articolo, Runnable onComplete) { private void executePosizione(MtbDepoPosizione posizione, MtbAart articolo) throws Exception {
this.mPosizioniRESTConsumer.getBancaliInPosizione(posizione, mtbColtList -> { var mtbColtList = this.mPosizioniRESTConsumer.getBancaliInPosizioneSynchronized(posizione);
if (mtbColtList == null || mtbColtList.isEmpty()) { if (mtbColtList == null || mtbColtList.isEmpty()) {
if (articolo != null) { if (articolo != null) {
this.dispatchArt(articolo, null); this.dispatchArt(articolo, null);
} else { } else {
this.sendError(new NoLUFoundException()); throw new NoLUFoundException();
} }
} else if (mtbColtList.size() == 1) { } else if (mtbColtList.size() == 1) {
this.mColliMagazzinoRESTConsumer.getByTestata(mtbColtList.get(0), true, false, mtbColt -> { var mtbColt = this.mColliMagazzinoRESTConsumer.getByTestataSynchronized(mtbColtList.get(0), true, false);
boolean codMdepIsValid = Stream.of(SettingsManager.iDB().getAvailableCodMdep()) boolean codMdepIsValid = Stream.of(SettingsManager.iDB().getAvailableCodMdep())
.anyMatch(x -> x.getCodMdep().equalsIgnoreCase(mtbColt.getCodMdep())); .anyMatch(x -> x.getCodMdep().equalsIgnoreCase(mtbColt.getCodMdep()));
if (codMdepIsValid) { if (codMdepIsValid) {
pickMerceULtoUL(mtbColt, articolo, onComplete); pickMerceULtoUL(mtbColt, articolo);
} else this.sendError(new InvalidCodMdepException()); } else throw new InvalidCodMdepException();
}, this::sendError);
} else { } else {
this.sendError(new TooManyLUFoundInMonoLUPositionException()); throw new TooManyLUFoundInMonoLUPositionException();
}
} }
}, this::sendError); private void executeEtichettaEanPeso(BarcodeScanDTO barcodeScanDTO) throws Exception {
}
private void executeEtichettaEanPeso(BarcodeScanDTO barcodeScanDTO, Runnable onComplete) {
try {
Ean13PesoModel ean13PesoModel = Ean13PesoModel.fromBarcode(barcodeScanDTO.getStringValue()); Ean13PesoModel ean13PesoModel = Ean13PesoModel.fromBarcode(barcodeScanDTO.getStringValue());
this.loadArticolo(ean13PesoModel.getPrecode(), ean13PesoModel.toEan128(), onComplete); this.loadArticolo(ean13PesoModel.getPrecode(), ean13PesoModel.toEan128());
} catch (Exception ex) {
this.sendError(ex);
}
} }
private void executeEtichettaLU(String sscc, Runnable onComplete) { private void executeEtichettaLU(String sscc) throws Exception {
mColliMagazzinoRESTConsumer.getBySSCC(sscc, true, false, mtbColtScanned -> { var mtbColtScanned = mColliMagazzinoRESTConsumer.getBySsccSynchronized(sscc, true, false);
if (mtbColtScanned == null) { if (mtbColtScanned == null) {
this.sendError(new NoLUFoundException()); throw new NoLUFoundException();
} else if ((mtbColtScanned.getGestioneEnum() == GestioneEnum.ACQUISTO || mtbColtScanned.getGestioneEnum() == GestioneEnum.LAVORAZIONE) && mtbColtScanned.getSegno() > 0) { } else if ((mtbColtScanned.getGestioneEnum() == GestioneEnum.ACQUISTO || mtbColtScanned.getGestioneEnum() == GestioneEnum.LAVORAZIONE) && mtbColtScanned.getSegno() > 0) {
boolean codMdepIsValid = Stream.of(SettingsManager.iDB().getAvailableCodMdep()) boolean codMdepIsValid = SettingsManager.iDB().getAvailableCodMdep().stream()
.anyMatch(x -> x.getCodMdep().equalsIgnoreCase(mtbColtScanned.getCodMdep())); .anyMatch(x -> x.getCodMdep().equalsIgnoreCase(mtbColtScanned.getCodMdep()));
if (codMdepIsValid) { if (codMdepIsValid) {
pickMerceULtoUL(mtbColtScanned, onComplete); pickMerceULtoUL(mtbColtScanned);
} else this.sendError(new InvalidCodMdepException()); } else throw new InvalidCodMdepException();
} else { } else {
this.sendError(new NoLUFoundException()); throw new NoLUFoundException();
}
} }
}, this::sendError); private void executeEtichettaEan128(BarcodeScanDTO barcodeScanDTO) throws Exception {
} var ean128Model = mBarcodeRESTConsumer.decodeEan128Synchronized(barcodeScanDTO);
private void executeEtichettaEan128(BarcodeScanDTO barcodeScanDTO, Runnable onComplete) {
mBarcodeRESTConsumer.decodeEan128(barcodeScanDTO, ean128Model -> {
String barcodeProd = null; String barcodeProd = null;
@ -305,76 +291,79 @@ public class PickingLiberoViewModel {
if (!UtilityString.isNullOrEmpty(barcodeProd)) { if (!UtilityString.isNullOrEmpty(barcodeProd)) {
if (!UtilityString.isNullOrEmpty(ean128Model.Sscc)) { if (!UtilityString.isNullOrEmpty(ean128Model.Sscc)) {
this.executeEtichettaLU(ean128Model.Sscc, onComplete); this.executeEtichettaLU(ean128Model.Sscc);
} else if (!UtilityString.isNullOrEmpty(barcodeProd) && SettingsManager.iDB().isFlagPickingLiberoEnableScanArt()) { } else if (!UtilityString.isNullOrEmpty(barcodeProd) && SettingsManager.iDB().isFlagPickingLiberoEnableScanArt()) {
this.loadArticolo(barcodeProd, ean128Model, onComplete); this.loadArticolo(barcodeProd, ean128Model);
} else { } else {
this.sendError(new NoLUFoundException()); throw new NoLUFoundException();
} }
} else { } else {
//EAN 128 non completo o comunque mancano i riferimenti al prodotto //EAN 128 non completo o comunque mancano i riferimenti al prodotto
this.sendError(new NoLUFoundException()); throw new NoLUFoundException();
}
}, this::sendError);
} }
private void loadArticolo(String barcodeProd, Ean128Model ean128Model, Runnable onComplete) { }
mArticoloRESTConsumer.searchByBarcode(barcodeProd, mtbAartList -> {
private void loadArticolo(String barcodeProd, Ean128Model ean128Model) throws Exception {
var mtbAartList = mArticoloRESTConsumer.searchByBarcodeSynchronized(barcodeProd);
if (mtbAartList != null && !mtbAartList.isEmpty()) { if (mtbAartList != null && !mtbAartList.isEmpty()) {
MtbAart articolo = mtbAartList.get(0); MtbAart articolo = mtbAartList.get(0);
MtbDepoPosizione posizione = UtilityPosizione.getFromCache(articolo.getPosizione()); MtbDepoPosizione posizione = UtilityPosizione.getFromCache(articolo.getPosizione());
if (posizione != null && posizione.isFlagMonoCollo()) { if (posizione != null && posizione.isFlagMonoCollo()) {
this.executePosizione(posizione, articolo, onComplete); this.executePosizione(posizione, articolo);
} else if (mDefaultGestione == GestioneEnum.VENDITA) { } else if (mDefaultGestione == GestioneEnum.VENDITA) {
this.dispatchArt(articolo, ean128Model); this.dispatchArt(articolo, ean128Model);
onComplete.run();
} else { } else {
this.sendError(new NoResultFromBarcodeException(barcodeProd)); throw new NoResultFromBarcodeException(barcodeProd);
} }
} else { } else {
this.sendError(new NoResultFromBarcodeException(barcodeProd)); throw new NoResultFromBarcodeException(barcodeProd);
} }
}, this::sendError);
} }
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) { if (this.mFlagAskCliente) {
this.sendLUClienteRequired((vtbDest, codJcom) -> { var data = this.sendLUClienteRequired();
createNewLU_PostClienteAsk(customNumCollo, customSerCollo, vtbDest, onComplete); vtbDest = data.first;
}, this::sendOnLoadingEnded); codJcom = data.second;
} else {
createNewLU_PostClienteAsk(customNumCollo, customSerCollo, null, onComplete);
}
} }
private void createNewLU_PostClienteAsk(Integer customNumCollo, String customSerCollo, VtbDest vtbDest, Runnable onComplete) { createNewLU_PostClienteAsk(customNumCollo, customSerCollo, vtbDest);
}
private void createNewLU_PostClienteAsk(Integer customNumCollo, String customSerCollo, VtbDest vtbDest) throws Exception {
DialogAskLineaProdResponse dialogAskLineaProdResponse = null;
if (this.mFlagAskLineaProd) { if (this.mFlagAskLineaProd) {
this.sendLULineaProdRequired(response -> { dialogAskLineaProdResponse = this.sendLULineaProdRequired();
createNewLU_PostLineaProdAsk(customNumCollo, customSerCollo, vtbDest, response.getPosizione(), response.getIdLotto(), onComplete);
}, this::sendOnLoadingEnded);
} else {
createNewLU_PostLineaProdAsk(customNumCollo, customSerCollo, vtbDest, null, null, onComplete);
}
} }
private void createNewLU_PostLineaProdAsk(Integer customNumCollo, String customSerCollo, VtbDest vtbDest, String posizione, Integer idLotto, Runnable onComplete) { 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) throws Exception {
JtbComt commessa = null;
if (this.mFlagAskCommessa) { if (this.mFlagAskCommessa) {
this.sendLUCommessaRequired(response -> { commessa = this.sendLUCommessaRequired();
createNewLU_PostCommessaAsk(customNumCollo, customSerCollo, vtbDest, posizione, idLotto, response, onComplete);
}, this::sendOnLoadingEnded);
} else {
createNewLU_PostCommessaAsk(customNumCollo, customSerCollo, vtbDest, null, null, null, onComplete);
} }
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.mDefaultCommessa = codJcom;
this.sendOnLoadingStarted(); this.sendOnLoadingStarted();
@ -404,59 +393,19 @@ public class PickingLiberoViewModel {
} }
mColliScaricoRESTConsumer.createUDS(createUDSRequest, mtbColt -> { var mtbColt = mColliScaricoRESTConsumer.createUDSSynchronized(createUDSRequest);
mMtbColtSessionID = mColliDataRecoverService.startNewSession(mtbColt, null); mMtbColtSessionID = mColliDataRecoverService.startNewSession(mtbColt, null);
mtbColt mtbColt.setMtbColr(new ObservableArrayList<>());
.setMtbColr(new ObservableArrayList<>());
this.mCurrentMtbColt = mtbColt; this.mCurrentMtbColt = mtbColt;
this.sendOnLoadingEnded(); this.sendOnLoadingEnded();
if (onComplete != null) onComplete.run();
this.sendLUOpened(mtbColt); 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);
} }
private void dispatchArt(MtbAart mtbAart, Ean128Model ean128Model) { private void dispatchArt(MtbAart mtbAart, Ean128Model ean128Model) throws Exception {
PickingObjectDTO pickingObjectDTO = new PickingObjectDTO() PickingObjectDTO pickingObjectDTO = new PickingObjectDTO()
.setMtbAart(mtbAart) .setMtbAart(mtbAart)
.setTempPickData(PickDataDTO.fromEan128(ean128Model)); .setTempPickData(PickDataDTO.fromEan128(ean128Model));
@ -485,7 +434,7 @@ public class PickingLiberoViewModel {
if (manualPickDTO.isEanPeso()) { if (manualPickDTO.isEanPeso()) {
if (mtbAart.getUntMisRifPeso() == MtbAart.UntMisRifPesoEnum.M) { if (mtbAart.getUntMisRifPeso() == MtbAart.UntMisRifPesoEnum.M) {
if (UtilityBigDecimal.equalsTo(mtbAart.getPesoKg(), BigDecimal.ZERO)) { if (UtilityBigDecimal.equalsTo(mtbAart.getPesoKg(), BigDecimal.ZERO)) {
this.sendError(new InvalidPesoKGException()); throw new InvalidPesoKGException();
} else { } else {
qtaColDaPrelevare = UtilityBigDecimal.divide(qtaColDaPrelevare, mtbAart.getPesoKg()); qtaColDaPrelevare = UtilityBigDecimal.divide(qtaColDaPrelevare, mtbAart.getPesoKg());
} }
@ -533,7 +482,7 @@ public class PickingLiberoViewModel {
} }
this.sendOnItemDispatched( var pickedQuantityDTO = this.sendOnItemDispatched(
pickingObjectDTO, pickingObjectDTO,
pickingObjectDTO.getMtbAart(), pickingObjectDTO.getMtbAart(),
initialNumCnf, initialNumCnf,
@ -549,10 +498,9 @@ public class PickingLiberoViewModel {
dataScad, dataScad,
false, false,
true, true,
true, true);
(pickedQuantityDTO, shouldCloseLU) -> {
if (pickedQuantityDTO == null) { if (pickedQuantityDTO == null) {
this.sendOnLoadingEnded();
return; return;
} }
@ -562,18 +510,15 @@ public class PickingLiberoViewModel {
pickedQuantityDTO.getQtaTot(), pickedQuantityDTO.getQtaTot(),
pickedQuantityDTO.getPartitaMag(), pickedQuantityDTO.getPartitaMag(),
pickedQuantityDTO.getDataScad(), pickedQuantityDTO.getDataScad(),
shouldCloseLU); pickedQuantityDTO.isShouldCloseLu());
});
} }
private void pickMerceULtoUL(MtbColt sourceMtbColt, Runnable onComplete) { private void pickMerceULtoUL(MtbColt sourceMtbColt) throws Exception {
pickMerceULtoUL(sourceMtbColt, null, onComplete); pickMerceULtoUL(sourceMtbColt, null);
} }
private void pickMerceULtoUL(MtbColt sourceMtbColt, MtbAart mtbAart, Runnable onComplete) { private void pickMerceULtoUL(MtbColt sourceMtbColt, MtbAart mtbAart) throws Exception {
executorService.execute(() -> {
try {
List<MtbColr> mtbColrsToPick = sourceMtbColt.getMtbColr().stream() List<MtbColr> mtbColrsToPick = sourceMtbColt.getMtbColr().stream()
.filter(x -> UtilityBigDecimal.greaterThan(x.getQtaCol(), BigDecimal.ZERO)) .filter(x -> UtilityBigDecimal.greaterThan(x.getQtaCol(), BigDecimal.ZERO))
.collect(Collectors.toList()); .collect(Collectors.toList());
@ -581,7 +526,6 @@ public class PickingLiberoViewModel {
List<MtbColr> pickedAarts = this.sendArtSelectionRequest(mtbColrsToPick, mtbAart); List<MtbColr> pickedAarts = this.sendArtSelectionRequest(mtbColrsToPick, mtbAart);
if (pickedAarts == null) { if (pickedAarts == null) {
this.sendOnLoadingEnded();
return; return;
} }
@ -596,6 +540,7 @@ public class PickingLiberoViewModel {
} }
if (!mtbColrsToMove.isEmpty()) { if (!mtbColrsToMove.isEmpty()) {
this.sendOnLoadingStarted();
if (this.mDefaultCommessa != null) if (this.mDefaultCommessa != null)
mtbColrsToMove.forEach(x -> x.setCodJcom(this.mDefaultCommessa.getCodJcom())); mtbColrsToMove.forEach(x -> x.setCodJcom(this.mDefaultCommessa.getCodJcom()));
@ -604,31 +549,20 @@ public class PickingLiberoViewModel {
clonedSourceTestata.getMtbColr().clear(); clonedSourceTestata.getMtbColr().clear();
clonedSourceTestata.getMtbColr().addAll(mtbColrsToMove); clonedSourceTestata.getMtbColr().addAll(mtbColrsToMove);
mColliMagazzinoRESTConsumer.spostaArtsTraUL(clonedSourceTestata, var generatedMtbColrs = mColliMagazzinoRESTConsumer.spostaArtsTraULSynchronized(clonedSourceTestata,
this.mCurrentMtbColt, true, (generatedMtbColrs) -> { this.mCurrentMtbColt, true);
handler.post(() -> {
mCurrentMtbColt.getMtbColr().addAll(generatedMtbColrs); mCurrentMtbColt.getMtbColr().addAll(generatedMtbColrs);
});
this.sendOnRowSaved(); this.sendOnRowSaved();
this.sendOnLoadingEnded(); this.sendOnLoadingEnded();
onComplete.run();
}, this::sendError);
} else {
onComplete.run();
this.sendOnLoadingEnded();
} }
} else {
onComplete.run();
this.sendOnLoadingEnded();
} }
} catch (InterruptedException e) {
this.sendError(e);
}
});
} }
private MtbColr askSingleQuantity(MtbColr mtbColr) throws InterruptedException { private MtbColr askSingleQuantity(MtbColr mtbColr) throws InterruptedException {
@ -650,10 +584,7 @@ public class PickingLiberoViewModel {
new PickDataDTO() new PickDataDTO()
.setSourceMtbColt(sourceMtbColt)); .setSourceMtbColt(sourceMtbColt));
CountDownLatch countDownLatch = new CountDownLatch(1); var pickedQuantityDTO = this.sendOnItemDispatched(
AtomicReference<MtbColr> result = new AtomicReference<>();
this.sendOnItemDispatched(
pickingObjectDTO, pickingObjectDTO,
pickingObjectDTO.getMtbAart(), pickingObjectDTO.getMtbAart(),
mtbColr.getNumCnf(), mtbColr.getNumCnf(),
@ -669,12 +600,10 @@ public class PickingLiberoViewModel {
mtbColr.getDataScadPartita(), mtbColr.getDataScadPartita(),
false, false,
false, false,
false, false);
(pickedQuantityDTO, shouldCloseLU) -> {
if (pickedQuantityDTO == null) { if (pickedQuantityDTO == null)
countDownLatch.countDown(); return null;
return;
}
mtbColr mtbColr
.setPartitaMag(pickedQuantityDTO.getPartitaMag()) .setPartitaMag(pickedQuantityDTO.getPartitaMag())
@ -685,19 +614,11 @@ public class PickingLiberoViewModel {
.setDatetimeRow(UtilityDate.getDateInstance()) .setDatetimeRow(UtilityDate.getDateInstance())
.setMtbAart(pickingObjectDTO.getMtbAart()); .setMtbAart(pickingObjectDTO.getMtbAart());
result.set(mtbColr); return mtbColr;
countDownLatch.countDown();
});
countDownLatch.await();
return result.get();
} }
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() final MtbColr mtbColr = new MtbColr()
.setCodMart(pickingObjectDTO.getMtbAart().getCodMart()) .setCodMart(pickingObjectDTO.getMtbAart().getCodMart())
.setPartitaMag(partitaMag) .setPartitaMag(partitaMag)
@ -722,7 +643,8 @@ public class PickingLiberoViewModel {
return; return;
} }
mColliMagazzinoRESTConsumer.saveCollo(cloneMtbColt, value -> { var value = mColliMagazzinoRESTConsumer.saveColloSynchronized(cloneMtbColt);
mtbColr mtbColr
.setDataCollo(value.getDataColloS()) .setDataCollo(value.getDataColloS())
.setNumCollo(value.getNumCollo()) .setNumCollo(value.getNumCollo())
@ -735,15 +657,12 @@ public class PickingLiberoViewModel {
mCurrentMtbColt.getMtbColr().add(mtbColr); mCurrentMtbColt.getMtbColr().add(mtbColr);
this.sendOnRowSaved(); this.sendOnRowSaved();
this.sendOnLoadingEnded();
if (shouldCloseLU) closeLU(null);
}, this::sendError);
if (shouldCloseLU) closeLU();
} }
private void loadRifULFromMtbColr(MtbColr mtbColr, RunnableArgs<MtbColt> onComplete) { private MtbColt loadRifULFromMtbColr(MtbColr mtbColr) throws Exception {
//Se ho dei riferimenti ad una UL devo leggere la QTA ancora disponibile sulla Ul //Se ho dei riferimenti ad una UL devo leggere la QTA ancora disponibile sulla Ul
if (mtbColr != null && if (mtbColr != null &&
!UtilityString.isNullOrEmpty(mtbColr.getGestioneRif()) && !UtilityString.isNullOrEmpty(mtbColr.getGestioneRif()) &&
@ -751,28 +670,28 @@ public class PickingLiberoViewModel {
!UtilityString.isNullOrEmpty(mtbColr.getDataColloRifS()) && !UtilityString.isNullOrEmpty(mtbColr.getDataColloRifS()) &&
mtbColr.getNumColloRif() != null) { mtbColr.getNumColloRif() != null) {
mColliMagazzinoRESTConsumer.getByChiaveCollo( MtbColt mtbColt = mColliMagazzinoRESTConsumer.getByChiaveColloSynchronized(
mtbColr.getGestioneRifEnum(), mtbColr.getGestioneRifEnum(),
mtbColr.getNumColloRif(), mtbColr.getNumColloRif(),
mtbColr.getDataColloRifS(), mtbColr.getDataColloRifS(),
mtbColr.getSerColloRif(), mtbColr.getSerColloRif(),
true, true,
false, false);
onComplete,
this::sendError);
} else { return mtbColt;
onComplete.run(null);
} }
return null;
} }
public void dispatchRowEdit(MtbColr mtbColrToUpdate) { public void dispatchRowEdit(MtbColr mtbColrToUpdate) throws Exception {
this.sendOnLoadingStarted();
final PickingObjectDTO pickingObjectDTO = new PickingObjectDTO() final PickingObjectDTO pickingObjectDTO = new PickingObjectDTO()
.setMtbAart(mtbColrToUpdate.getMtbAart()); .setMtbAart(mtbColrToUpdate.getMtbAart());
loadRifULFromMtbColr(mtbColrToUpdate, mtbColtRif -> { var mtbColtRif = loadRifULFromMtbColr(mtbColrToUpdate);
BigDecimal totalQtaAvailable = null; BigDecimal totalQtaAvailable = null;
@ -786,30 +705,30 @@ public class PickingLiberoViewModel {
if (mtbColrRifs != null && !mtbColrRifs.isEmpty()) { if (mtbColrRifs != null && !mtbColrRifs.isEmpty()) {
//TODO: Da capire se è necessario controllare anche il cod_jcom //TODO: Da capire se è necessario controllare anche il cod_jcom
mtbColrRif = Stream.of(mtbColrRifs) mtbColrRif = mtbColrRifs.stream()
.filter(x -> UtilityString.equalsIgnoreCase(x.getCodMart(), mtbColrToUpdate.getCodMart()) && .filter(x -> UtilityString.equalsIgnoreCase(x.getCodMart(), mtbColrToUpdate.getCodMart()) &&
UtilityString.equalsIgnoreCase(x.getCodCol(), mtbColrToUpdate.getCodCol()) && UtilityString.equalsIgnoreCase(x.getCodCol(), mtbColrToUpdate.getCodCol()) &&
UtilityString.equalsIgnoreCase(x.getCodTagl(), mtbColrToUpdate.getCodTagl()) && UtilityString.equalsIgnoreCase(x.getCodTagl(), mtbColrToUpdate.getCodTagl()) &&
UtilityString.equalsIgnoreCase(x.getPartitaMag(), mtbColrToUpdate.getPartitaMag())) UtilityString.equalsIgnoreCase(x.getPartitaMag(), mtbColrToUpdate.getPartitaMag()))
.findFirstOrElse(null); .findFirst()
.orElse(null);
} }
if (mtbColrRif != null) { if (mtbColrRif != null) {
totalQtaAvailable = mtbColrRif.getQtaCol().add(mtbColrToUpdate.getQtaCol()); totalQtaAvailable = mtbColrRif.getQtaCol().add(mtbColrToUpdate.getQtaCol());
totalNumCnfAvailable = mtbColrRif.getNumCnf().add(mtbColrToUpdate.getNumCnf()); totalNumCnfAvailable = mtbColrRif.getNumCnf().add(mtbColrToUpdate.getNumCnf());
qtaCnfAvailable = mtbColrRif.getQtaCnf(); qtaCnfAvailable = mtbColrRif.getQtaCnf();
} else { } else {
totalQtaAvailable = mtbColrToUpdate.getQtaCol(); totalQtaAvailable = mtbColrToUpdate.getQtaCol();
totalNumCnfAvailable = mtbColrToUpdate.getNumCnf(); totalNumCnfAvailable = mtbColrToUpdate.getNumCnf();
qtaCnfAvailable = mtbColrToUpdate.getQtaCnf(); qtaCnfAvailable = mtbColrToUpdate.getQtaCnf();
} }
this.sendOnLoadingEnded();
this.sendOnItemDispatched( var pickedQuantityDTO = this.sendOnItemDispatched(
pickingObjectDTO, pickingObjectDTO,
pickingObjectDTO.getMtbAart(), pickingObjectDTO.getMtbAart(),
mtbColrToUpdate.getNumCnf(), mtbColrToUpdate.getNumCnf(),
@ -825,29 +744,25 @@ public class PickingLiberoViewModel {
mtbColrToUpdate.getDataScadPartita(), mtbColrToUpdate.getDataScadPartita(),
false, false,
false, false,
false, false);
(pickedQuantityDTO, shouldCloseLU) -> {
if (pickedQuantityDTO == null) { if (pickedQuantityDTO == null) {
this.sendOnLoadingEnded();
return; return;
} }
this.sendOnLoadingStarted();
this.saveEditedRow(mtbColrToUpdate, this.saveEditedRow(mtbColrToUpdate,
pickedQuantityDTO.getNumCnf(), pickedQuantityDTO.getNumCnf(),
pickedQuantityDTO.getQtaCnf(), pickedQuantityDTO.getQtaCnf(),
pickedQuantityDTO.getQtaTot(), pickedQuantityDTO.getQtaTot(),
pickedQuantityDTO.getPartitaMag(), pickedQuantityDTO.getPartitaMag(),
pickedQuantityDTO.getDataScad(), pickedQuantityDTO.getDataScad(),
shouldCloseLU); 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(); this.sendOnLoadingStarted();
@ -871,24 +786,24 @@ public class PickingLiberoViewModel {
mtbColt.getMtbColr().add(mtbColr); mtbColt.getMtbColr().add(mtbColr);
this.mColliMagazzinoRESTConsumer.saveCollo(mtbColt, (value) -> { var value = this.mColliMagazzinoRESTConsumer.saveColloSynchronized(mtbColt);
mtbColr.setNumCnf(numCnf) mtbColr.setNumCnf(numCnf)
.setQtaCnf(qtaCnf) .setQtaCnf(qtaCnf)
.setQtaCol(qtaTot); .setQtaCol(qtaTot);
handler.post(() -> {
this.mCurrentMtbColt.getMtbColr().remove(mtbColrToUpdate); this.mCurrentMtbColt.getMtbColr().remove(mtbColrToUpdate);
this.mCurrentMtbColt.getMtbColr().add(mtbColr); this.mCurrentMtbColt.getMtbColr().add(mtbColr);
});
this.sendOnRowSaved(); this.sendOnRowSaved();
this.sendOnLoadingEnded(); this.sendOnLoadingEnded();
}, this::sendError);
} }
public void deleteRow(MtbColr mtbColrToDelete) { public void deleteRow(MtbColr mtbColrToDelete) throws Exception {
this.sendMtbColrDeleteRequest(shouldDelete -> { var shouldDelete = this.sendMtbColrDeleteRequest();
if (shouldDelete) { if (shouldDelete) {
this.sendOnLoadingStarted(); this.sendOnLoadingStarted();
@ -898,6 +813,7 @@ public class PickingLiberoViewModel {
.setSerCollo(mtbColrToDelete.getSerCollo()) .setSerCollo(mtbColrToDelete.getSerCollo())
.setGestione(mtbColrToDelete.getGestione()) .setGestione(mtbColrToDelete.getGestione())
.setMtbColr(new ObservableArrayList<>()); .setMtbColr(new ObservableArrayList<>());
mtbColt.setOperation(CommonModelConsts.OPERATION.NO_OP); mtbColt.setOperation(CommonModelConsts.OPERATION.NO_OP);
MtbColr mtbColr = (MtbColr) mtbColrToDelete.clone(); MtbColr mtbColr = (MtbColr) mtbColrToDelete.clone();
@ -905,30 +821,30 @@ public class PickingLiberoViewModel {
mtbColr.setOperation(CommonModelConsts.OPERATION.DELETE); mtbColr.setOperation(CommonModelConsts.OPERATION.DELETE);
mtbColt.getMtbColr().add(mtbColr); mtbColt.getMtbColr().add(mtbColr);
this.mColliMagazzinoRESTConsumer.saveCollo(mtbColt, (value) -> { var value = this.mColliMagazzinoRESTConsumer.saveColloSynchronized(mtbColt);
handler.post(() -> {
this.mCurrentMtbColt.getMtbColr().remove(mtbColrToDelete); this.mCurrentMtbColt.getMtbColr().remove(mtbColrToDelete);
});
this.sendOnRowSaved(); this.sendOnRowSaved();
this.sendOnLoadingEnded(); this.sendOnLoadingEnded();
}, this::sendError);
} }
});
} }
public void closeLU(Runnable onComplete) { public void closeLU() throws Exception {
if (mCurrentMtbColt == null) { if (mCurrentMtbColt == null) {
if (onComplete != null) onComplete.run();
return; return;
} }
this.sendOnLoadingStarted();
this.mDefaultCommessa = null; this.mDefaultCommessa = null;
mColliMagazzinoRESTConsumer.canULBeDeleted(mCurrentMtbColt, canBeDeleted -> { var canBeDeleted = mColliMagazzinoRESTConsumer.canULBeDeletedSynchronized(mCurrentMtbColt);
if (canBeDeleted) { if (canBeDeleted) {
deleteLU(() -> { deleteLU();
if (mMtbColtSessionID != null) if (mMtbColtSessionID != null)
this.mColliDataRecoverService.closeSession(mMtbColtSessionID); this.mColliDataRecoverService.closeSession(mMtbColtSessionID);
@ -936,11 +852,9 @@ public class PickingLiberoViewModel {
this.sendOnLoadingEnded(); this.sendOnLoadingEnded();
this.mCurrentMtbColt = null; this.mCurrentMtbColt = null;
if (onComplete != null) onComplete.run();
});
} else {
this.mColliMagazzinoRESTConsumer.assegnaLottoSuColloScarico(mCurrentMtbColt, () -> { } else {
this.mColliMagazzinoRESTConsumer.assegnaLottoSuColloScaricoSynchronized(mCurrentMtbColt);
var closeUDSRequest = new CloseUDSRequestDTO() var closeUDSRequest = new CloseUDSRequestDTO()
.setMtbColt(mCurrentMtbColt); .setMtbColt(mCurrentMtbColt);
@ -952,29 +866,25 @@ public class PickingLiberoViewModel {
.setDocumentCodAnag(SettingsManager.iDB().getInternalCodAnags().stream().filter(InternalCodAnagsDTO::isFornitore).findFirst().get().getCodAnag()); .setDocumentCodAnag(SettingsManager.iDB().getInternalCodAnags().stream().filter(InternalCodAnagsDTO::isFornitore).findFirst().get().getCodAnag());
} }
this.mColliScaricoRESTConsumer.closeUDS(closeUDSRequest, response -> { var response = this.mColliScaricoRESTConsumer.closeUDSSynchronized(closeUDSRequest);
if (mMtbColtSessionID != null) if (mMtbColtSessionID != null)
this.mColliDataRecoverService.closeSession(mMtbColtSessionID); this.mColliDataRecoverService.closeSession(mMtbColtSessionID);
this.sendLUClosed(); this.sendLUClosed();
this.sendOnLoadingEnded();
this.mCurrentMtbColt = null; this.mCurrentMtbColt = null;
if (onComplete != null) onComplete.run();
}, this::sendError);
}, this::sendError);
}
}, this::sendError);
} }
private void deleteLU(Runnable onComplete) { }
private void deleteLU() throws Exception {
DeleteULRequestDTO deleteULRequestDTO = new DeleteULRequestDTO() DeleteULRequestDTO deleteULRequestDTO = new DeleteULRequestDTO()
.setMtbColt(mCurrentMtbColt); .setMtbColt(mCurrentMtbColt);
mColliMagazzinoRESTConsumer.deleteUL(deleteULRequestDTO, () -> {
this.mCurrentMtbColt = null;
if (onComplete != null) onComplete.run(); mColliMagazzinoRESTConsumer.deleteULSynchronized(deleteULRequestDTO);
}, this::sendError);
this.mCurrentMtbColt = null;
} }
@ -998,20 +908,61 @@ public class PickingLiberoViewModel {
if (this.mListener != null) mListener.onLUClosed(); if (this.mListener != null) mListener.onLUClosed();
} }
private void sendMtbColrDeleteRequest(RunnableArgs<Boolean> onComplete) { private Boolean sendMtbColrDeleteRequest() throws InterruptedException {
if (this.mListener != null) mListener.onMtbColrDeleteRequest(onComplete); CountDownLatch countDownLatch = new CountDownLatch(1);
AtomicReference<Boolean> 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<VtbDest, String> onComplete, Runnable onAbort) { private Pair<VtbDest, String> sendLUClienteRequired() throws InterruptedException {
if (this.mListener != null) mListener.onLUClienteRequired(onComplete, onAbort); CountDownLatch countDownLatch = new CountDownLatch(1);
AtomicReference<Pair<VtbDest, String>> 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<DialogAskLineaProdResponse> onComplete, Runnable onAbort) { private DialogAskLineaProdResponse sendLULineaProdRequired() throws InterruptedException {
if (this.mListener != null) mListener.onLULineaProdRequired(onComplete, onAbort); CountDownLatch countDownLatch = new CountDownLatch(1);
AtomicReference<DialogAskLineaProdResponse> 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<JtbComt> onComplete, Runnable onAbort) { private JtbComt sendLUCommessaRequired() throws InterruptedException {
if (this.mListener != null) mListener.onLUCommessaRequired(onComplete, onAbort); CountDownLatch countDownLatch = new CountDownLatch(1);
AtomicReference<JtbComt> 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<MtbColr> sendArtSelectionRequest(List<MtbColr> mtbColrsToPick, MtbAart mtbAart) throws InterruptedException { private List<MtbColr> sendArtSelectionRequest(List<MtbColr> mtbColrsToPick, MtbAart mtbAart) throws InterruptedException {
@ -1026,12 +977,11 @@ public class PickingLiberoViewModel {
}, countDownLatch::countDown); }, countDownLatch::countDown);
else countDownLatch.countDown(); else countDownLatch.countDown();
countDownLatch.await(); countDownLatch.await();
return result.get(); return result.get();
} }
private void sendOnItemDispatched(PickingObjectDTO pickingObjectDTO, private PickedQuantityDTO sendOnItemDispatched(PickingObjectDTO pickingObjectDTO,
MtbAart mtbAart, MtbAart mtbAart,
BigDecimal initialNumCnf, BigDecimal initialNumCnf,
BigDecimal initialQtaCnf, BigDecimal initialQtaCnf,
@ -1046,8 +996,11 @@ public class PickingLiberoViewModel {
LocalDate dataScad, LocalDate dataScad,
boolean canOverflowOrderQuantity, boolean canOverflowOrderQuantity,
boolean canPartitaMagBeChanged, boolean canPartitaMagBeChanged,
boolean canLUBeClosed, boolean canLUBeClosed) throws InterruptedException {
RunnableArgss<PickedQuantityDTO, Boolean> onComplete) {
CountDownLatch countDownLatch = new CountDownLatch(1);
AtomicReference<PickedQuantityDTO> result = new AtomicReference<>();
if (this.mListener != null) mListener.onItemDispatched(pickingObjectDTO, if (this.mListener != null) mListener.onItemDispatched(pickingObjectDTO,
mtbAart, mtbAart,
@ -1065,7 +1018,17 @@ public class PickingLiberoViewModel {
canOverflowOrderQuantity, canOverflowOrderQuantity,
canPartitaMagBeChanged, canPartitaMagBeChanged,
canLUBeClosed, canLUBeClosed,
onComplete); pickedQuantityDTO -> {
if (pickedQuantityDTO != null) {
result.set(pickedQuantityDTO);
}
countDownLatch.countDown();
});
countDownLatch.await();
return result.get();
} }
private void sendOnRowSaved() { private void sendOnRowSaved() {
@ -1105,7 +1068,7 @@ public class PickingLiberoViewModel {
boolean canOverflowOrderQuantity, boolean canOverflowOrderQuantity,
boolean canPartitaMagBeChanged, boolean canPartitaMagBeChanged,
boolean canLUBeClosed, boolean canLUBeClosed,
RunnableArgss<PickedQuantityDTO, Boolean> onComplete); RunnableArgs<PickedQuantityDTO> onComplete);
} }

View File

@ -812,7 +812,7 @@ public class SpedizioneViewModel {
.setOrdersOfNewUDS(orders) .setOrdersOfNewUDS(orders)
.setItemsToPick(magazzinoAutomaticoPickItemRequestDTOList); .setItemsToPick(magazzinoAutomaticoPickItemRequestDTOList);
mMagazzinoAutomaticoRESTConsumer.pickItemsSynchronous(mtbDepoPosizione, magazzinoAutomaticoPickRequest); mMagazzinoAutomaticoRESTConsumer.pickItemsSynchronized(mtbDepoPosizione, magazzinoAutomaticoPickRequest);
} }
public void executeEmptyMagazzinoAutomaticoRequest(MtbDepoPosizione mtbDepoPosizione) throws Exception { public void executeEmptyMagazzinoAutomaticoRequest(MtbDepoPosizione mtbDepoPosizione) throws Exception {
@ -826,7 +826,7 @@ public class SpedizioneViewModel {
.setDefaultGestioneOfNewUDS(mDefaultGestioneOfUL.getText()) .setDefaultGestioneOfNewUDS(mDefaultGestioneOfUL.getText())
.setOrdersOfNewUDS(orders); .setOrdersOfNewUDS(orders);
mMagazzinoAutomaticoRESTConsumer.pickItemsSynchronous(mtbDepoPosizione, magazzinoAutomaticoPickRequest); mMagazzinoAutomaticoRESTConsumer.pickItemsSynchronized(mtbDepoPosizione, magazzinoAutomaticoPickRequest);
} }
private void searchArtFromUL(MtbColt scannedUL) throws Exception { private void searchArtFromUL(MtbColt scannedUL) throws Exception {

View File

@ -298,6 +298,8 @@ public class DialogInputQuantityV2View extends BaseDialogFragment implements Dia
} }
private void dismiss(DialogInputQuantityV2ResultDTO result) { private void dismiss(DialogInputQuantityV2ResultDTO result) {
super.dismiss();
if (this.mOnComplete != null) { if (this.mOnComplete != null) {
if(result == null) { if(result == null) {
result = new DialogInputQuantityV2ResultDTO() result = new DialogInputQuantityV2ResultDTO()
@ -306,7 +308,6 @@ public class DialogInputQuantityV2View extends BaseDialogFragment implements Dia
this.mOnComplete.run(result); this.mOnComplete.run(result);
} }
super.dismiss();
} }
@Override @Override