Refactoring ID su recover colli
This commit is contained in:
parent
bcb301ef96
commit
438e9ca73c
@ -2,6 +2,8 @@ package it.integry.integrywmsnative.core.data_recover;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import com.annimon.stream.Optional;
|
||||
import com.annimon.stream.Stream;
|
||||
import com.google.android.gms.common.util.IOUtils;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
@ -16,6 +18,7 @@ import java.io.InputStream;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
import it.integry.integrywmsnative.core.CommonConst;
|
||||
import it.integry.integrywmsnative.core.model.MtbColt;
|
||||
@ -24,12 +27,22 @@ import it.integry.integrywmsnative.core.utility.UtilityExceptions;
|
||||
public class ColliDataRecover {
|
||||
|
||||
private static class RecoverDTO {
|
||||
private int id;
|
||||
private int numCollo;
|
||||
private String serCollo;
|
||||
private String dataCollo;
|
||||
private String gestioneCollo;
|
||||
private String filtro;
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public RecoverDTO setId(int id) {
|
||||
this.id = id;
|
||||
return this;
|
||||
}
|
||||
|
||||
public int getNumCollo() {
|
||||
return numCollo;
|
||||
}
|
||||
@ -105,13 +118,9 @@ public class ColliDataRecover {
|
||||
public static List<Integer> getAllSessionIDs() {
|
||||
if(thereIsAnExistantSession()) {
|
||||
|
||||
List<Integer> sessionIDs = new ArrayList<>();
|
||||
|
||||
for(int i = 0; i < mtbColtsSessions.size(); i++){
|
||||
sessionIDs.add(i);
|
||||
}
|
||||
|
||||
return sessionIDs;
|
||||
return Stream.of(mtbColtsSessions)
|
||||
.map(RecoverDTO::getId)
|
||||
.toList();
|
||||
|
||||
} else return null;
|
||||
}
|
||||
@ -120,7 +129,7 @@ public class ColliDataRecover {
|
||||
|
||||
if(sessionID == null) return null;
|
||||
|
||||
RecoverDTO dto = mtbColtsSessions.get(sessionID);
|
||||
RecoverDTO dto = getIfExists(sessionID);
|
||||
|
||||
return new MtbColt()
|
||||
.setNumCollo(dto.getNumCollo())
|
||||
@ -130,9 +139,27 @@ public class ColliDataRecover {
|
||||
.setFiltroOrdini(dto.getFiltro());
|
||||
}
|
||||
|
||||
private static RecoverDTO getIfExists(int id) {
|
||||
Optional<RecoverDTO> recoverDTOOptional = Stream.of(mtbColtsSessions)
|
||||
.filter(x -> x.getId() == id)
|
||||
.findSingle();
|
||||
|
||||
|
||||
return recoverDTOOptional.isPresent() ? recoverDTOOptional.get() : null;
|
||||
}
|
||||
|
||||
public static int startNewSession(MtbColt mtbColtSession) {
|
||||
Integer newId = null;
|
||||
|
||||
while(newId == null) {
|
||||
int randomId = new Random().nextInt(1000);
|
||||
RecoverDTO dto = getIfExists(randomId);
|
||||
if(dto == null) newId = randomId;
|
||||
}
|
||||
|
||||
|
||||
RecoverDTO recoverDTO = new RecoverDTO()
|
||||
.setId(newId)
|
||||
.setDataCollo(mtbColtSession.getDataColloS())
|
||||
.setNumCollo(mtbColtSession.getNumCollo())
|
||||
.setSerCollo(mtbColtSession.getSerCollo())
|
||||
@ -141,13 +168,17 @@ public class ColliDataRecover {
|
||||
|
||||
mtbColtsSessions.add(recoverDTO);
|
||||
updateLocalFile();
|
||||
return mtbColtsSessions.indexOf(recoverDTO);
|
||||
return newId;
|
||||
}
|
||||
|
||||
public static void closeSession(int ID) {
|
||||
mtbColtsSessions.remove(ID);
|
||||
RecoverDTO dto = getIfExists(ID);
|
||||
|
||||
if(dto != null) {
|
||||
mtbColtsSessions.remove(dto);
|
||||
updateLocalFile();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static void loadLocalFile() {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user