Implementata gestione degli aggiornamenti obbligatori su WMS

This commit is contained in:
2024-12-06 11:38:05 +01:00
parent 88045e83f8
commit ce21b0b928
2 changed files with 36 additions and 33 deletions

View File

@@ -4,7 +4,6 @@ import it.integry.common.var.CommonConstants;
import it.integry.ems.Import.dto.AnomalieDTO;
import it.integry.ems.json.ResponseJSONObjectMapper;
import it.integry.ems.properties.EmsProperties;
import it.integry.ems.response.EsitoType;
import it.integry.ems.response.ServiceRestResponse;
import it.integry.ems.retail.dto.PrintOrderCloseDTO;
import it.integry.ems.retail.pvmRetail.dto.GiacenzaColliInMagDTO;
@@ -37,7 +36,7 @@ import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.io.StringWriter;
import java.io.FileNotFoundException;
import java.net.InetAddress;
import java.nio.file.Paths;
import java.text.SimpleDateFormat;
@@ -118,50 +117,44 @@ public class WMSGenericController {
@RequestMapping(value = EmsRestConstants.PATH_CHECK_LATEST_WMS_VERSION_JSON, method = RequestMethod.GET)
public Object checkWMSLatestVersionJSON() throws Exception {
try {
String wmsVersionFile = Paths.get(UtilityDirs.getWebAppPath(), "wms", "version.txt").toString();
String wmsVersionFile = Paths.get(UtilityDirs.getWebAppPath(), "wms", "version.txt").toString();
if (new File(wmsVersionFile).exists()) {
List<String> lines = UtilityString.splitStringToMultipleLine(IoUtils.readFileAsString(new File(wmsVersionFile)));
if (new File(wmsVersionFile).exists()) {
List<String> lines = UtilityString.splitStringToMultipleLine(IoUtils.readFileAsString(new File(wmsVersionFile)));
int versionCode = Integer.parseInt(lines.get(0)
.replaceAll("\r", "")
.replaceAll("\n", "")
.trim());
int versionCode = Integer.parseInt(lines.get(0)
.replaceAll("\r", "")
.replaceAll("\n", "")
.trim());
String versionString = lines.get(1)
.replaceAll("\r", "")
.replaceAll("\n", "")
.trim();
String versionString = lines.get(1)
.replaceAll("\r", "")
.replaceAll("\n", "")
.trim();
WMSVersionDTO wmsVersionDTO = new WMSVersionDTO()
.setLatestVersion(versionString)
.setLatestVersionCode(versionCode)
.setUrl("http://" + InetAddress.getLocalHost().getHostAddress() + ":8080" + emsProperties.getRootApi() + "/wms/android-release.apk");
WMSVersionDTO wmsVersionDTO = new WMSVersionDTO()
.setLatestVersion(versionString)
.setLatestVersionCode(versionCode)
.setUrl("http://" + InetAddress.getLocalHost().getHostAddress() + ":8080" + emsProperties.getRootApi() + "/wms/android-release.apk");
//ObjectMapper mapper = new ObjectMapper();
//mapper.enable(SerializationFeature.INDENT_OUTPUT);
StringWriter writer = new StringWriter();
jsonObjectMapper.writeValue(writer, wmsVersionDTO);
if(lines.size() > 2) {
String forcedLine = lines.get(2);
if(forcedLine.startsWith("forced=")) {
String forcedValue = forcedLine.replace("forced=", "").trim();
boolean forced = Boolean.parseBoolean(forcedValue);
wmsVersionDTO.setForced(forced);
}
return wmsVersionDTO;
} else throw new Exception("File version.txt non trovato");
}
} catch (Exception e) {
logger.error(e);
ServiceRestResponse serviceRestResponse = new ServiceRestResponse(EsitoType.KO, "Errore durante la lettura del file version.txt");
StringWriter writer = new StringWriter();
jsonObjectMapper.writeValue(writer, serviceRestResponse);
return writer.toString();
}
return wmsVersionDTO;
} else throw new FileNotFoundException("File version.txt non trovato");
}
@RequestMapping(value = EmsRestConstants.PATH_GET_GIACENZA_BANCALI_ARTICOLI_ORDINE, method = RequestMethod.GET)

View File

@@ -6,6 +6,7 @@ public class WMSVersionDTO {
private Integer latestVersionCode;
private String url;
private String[] releaseNotes;
private boolean forced;
public String getLatestVersion() {
@@ -43,4 +44,13 @@ public class WMSVersionDTO {
this.releaseNotes = releaseNotes;
return this;
}
public boolean isForced() {
return forced;
}
public WMSVersionDTO setForced(boolean forced) {
this.forced = forced;
return this;
}
}