Merge pull request '74307 - Exclusão do cache por operador feat bug#AL-4243' (!681) from AL-4243 into master
Reviewed-on: adm/VentaBoletosAdm#681 Reviewed-by: Gleison da Cruz <gleison.cruz@totvs.com.br>master 1.131.0
commit
8ea7800fe9
4
pom.xml
4
pom.xml
|
@ -4,11 +4,11 @@
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>br.com.rjconsultores</groupId>
|
<groupId>br.com.rjconsultores</groupId>
|
||||||
<artifactId>ventaboletosadm</artifactId>
|
<artifactId>ventaboletosadm</artifactId>
|
||||||
<version>1.130.1</version>
|
<version>1.131.0</version>
|
||||||
<packaging>war</packaging>
|
<packaging>war</packaging>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<modelWeb.version>1.100.0</modelWeb.version>
|
<modelWeb.version>1.101.0</modelWeb.version>
|
||||||
<flyway.version>1.88.0</flyway.version>
|
<flyway.version>1.88.0</flyway.version>
|
||||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
|
@ -42,9 +42,11 @@ import com.rjconsultores.ventaboletos.service.ClaseServicioService;
|
||||||
import com.rjconsultores.ventaboletos.service.MarcaService;
|
import com.rjconsultores.ventaboletos.service.MarcaService;
|
||||||
import com.rjconsultores.ventaboletos.service.OperadorEmbarcadaService;
|
import com.rjconsultores.ventaboletos.service.OperadorEmbarcadaService;
|
||||||
import com.rjconsultores.ventaboletos.utilerias.UsuarioLogado;
|
import com.rjconsultores.ventaboletos.utilerias.UsuarioLogado;
|
||||||
|
import com.rjconsultores.ventaboletos.web.utilerias.InputMessageBox;
|
||||||
import com.rjconsultores.ventaboletos.web.utilerias.MyComboboxPuntoVenta;
|
import com.rjconsultores.ventaboletos.web.utilerias.MyComboboxPuntoVenta;
|
||||||
import com.rjconsultores.ventaboletos.web.utilerias.MyGenericForwardComposer;
|
import com.rjconsultores.ventaboletos.web.utilerias.MyGenericForwardComposer;
|
||||||
import com.rjconsultores.ventaboletos.web.utilerias.MyListbox;
|
import com.rjconsultores.ventaboletos.web.utilerias.MyListbox;
|
||||||
|
import com.rjconsultores.ventaboletos.web.utilerias.api.CacheOperadorEmbarcada;
|
||||||
import com.rjconsultores.ventaboletos.web.utilerias.paginacion.HibernateSearchObject;
|
import com.rjconsultores.ventaboletos.web.utilerias.paginacion.HibernateSearchObject;
|
||||||
import com.rjconsultores.ventaboletos.web.utilerias.paginacion.PagedListWrapper;
|
import com.rjconsultores.ventaboletos.web.utilerias.paginacion.PagedListWrapper;
|
||||||
import com.rjconsultores.ventaboletos.web.utilerias.render.ItemRenderRutaOperadorEmbarcada;
|
import com.rjconsultores.ventaboletos.web.utilerias.render.ItemRenderRutaOperadorEmbarcada;
|
||||||
|
@ -553,7 +555,13 @@ public class EditarOperadorEmbarcadaController extends MyGenericForwardComposer
|
||||||
|
|
||||||
operador = operadorService.suscribirActualizar(operador, linhas, listaServicos);
|
operador = operadorService.suscribirActualizar(operador, linhas, listaServicos);
|
||||||
|
|
||||||
|
Usuario usuario = operador.getUsuario();
|
||||||
|
String OperadorId = operadorEdicao.getOperadorEmbarcadaId().toString();
|
||||||
|
|
||||||
|
String senha = InputMessageBox.showQuestion(Labels.getLabel("limparCacheAPI.message.senha"),
|
||||||
|
Labels.getLabel("limparCacheAPI.title"), Messagebox.OK);
|
||||||
|
|
||||||
|
CacheOperadorEmbarcada.getInstance().limparCacheOperador(OperadorId, senha, usuario);
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
Messagebox.show(Labels.getLabel("busquedaOperadorEmbarcada.mensage.operadorSalvo"), Labels.getLabel("busquedaOperadorEmbarcada.mensage.operadorSalvo.title"),
|
Messagebox.show(Labels.getLabel("busquedaOperadorEmbarcada.mensage.operadorSalvo"), Labels.getLabel("busquedaOperadorEmbarcada.mensage.operadorSalvo.title"),
|
||||||
|
@ -582,6 +590,12 @@ public class EditarOperadorEmbarcadaController extends MyGenericForwardComposer
|
||||||
|
|
||||||
if (resp == Messagebox.YES) {
|
if (resp == Messagebox.YES) {
|
||||||
|
|
||||||
|
String senha = InputMessageBox.showQuestion(Labels.getLabel("limparCacheAPI.message.senha"),
|
||||||
|
Labels.getLabel("limparCacheAPI.title"), Messagebox.OK);
|
||||||
|
|
||||||
|
Usuario usuario = operadorEdicao.getUsuario();
|
||||||
|
String OperadorId = operadorEdicao.getOperadorEmbarcadaId().toString();
|
||||||
|
|
||||||
operadorService.apagar(operadorEdicao);
|
operadorService.apagar(operadorEdicao);
|
||||||
|
|
||||||
Messagebox.show(
|
Messagebox.show(
|
||||||
|
@ -589,6 +603,8 @@ public class EditarOperadorEmbarcadaController extends MyGenericForwardComposer
|
||||||
Labels.getLabel("busquedaOperadorEmbarcada.MSG.borrarPergunta.title"),
|
Labels.getLabel("busquedaOperadorEmbarcada.MSG.borrarPergunta.title"),
|
||||||
Messagebox.OK, Messagebox.INFORMATION);
|
Messagebox.OK, Messagebox.INFORMATION);
|
||||||
|
|
||||||
|
CacheOperadorEmbarcada.getInstance().limparCacheOperador(OperadorId, senha, usuario);
|
||||||
|
|
||||||
closeWindow();
|
closeWindow();
|
||||||
}
|
}
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
|
|
|
@ -24,6 +24,7 @@ import com.rjconsultores.ventaboletos.utilerias.UsuarioLogado;
|
||||||
import com.rjconsultores.ventaboletos.web.utilerias.InputMessageBox;
|
import com.rjconsultores.ventaboletos.web.utilerias.InputMessageBox;
|
||||||
import com.rjconsultores.ventaboletos.web.utilerias.MyGenericForwardComposer;
|
import com.rjconsultores.ventaboletos.web.utilerias.MyGenericForwardComposer;
|
||||||
import com.rjconsultores.ventaboletos.web.utilerias.api.ApiCallRunnable;
|
import com.rjconsultores.ventaboletos.web.utilerias.api.ApiCallRunnable;
|
||||||
|
import com.rjconsultores.ventaboletos.web.utilerias.api.ETipoEnvio;
|
||||||
import com.rjconsultores.ventaboletos.web.utilerias.spring.AppContext;
|
import com.rjconsultores.ventaboletos.web.utilerias.spring.AppContext;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -119,7 +120,7 @@ public class LimparCacheApiController extends MyGenericForwardComposer {
|
||||||
urlBase,
|
urlBase,
|
||||||
user.getClaveUsuario(),
|
user.getClaveUsuario(),
|
||||||
secret,
|
secret,
|
||||||
false);
|
ETipoEnvio.POST);
|
||||||
Thread thread = new Thread(cache);
|
Thread thread = new Thread(cache);
|
||||||
thread.start();
|
thread.start();
|
||||||
thread.join();
|
thread.join();
|
||||||
|
|
|
@ -10,6 +10,7 @@ import org.apache.http.HttpEntity;
|
||||||
import org.apache.http.HttpResponse;
|
import org.apache.http.HttpResponse;
|
||||||
import org.apache.http.auth.UsernamePasswordCredentials;
|
import org.apache.http.auth.UsernamePasswordCredentials;
|
||||||
import org.apache.http.client.config.RequestConfig;
|
import org.apache.http.client.config.RequestConfig;
|
||||||
|
import org.apache.http.client.methods.HttpDelete;
|
||||||
import org.apache.http.client.methods.HttpGet;
|
import org.apache.http.client.methods.HttpGet;
|
||||||
import org.apache.http.client.methods.HttpPost;
|
import org.apache.http.client.methods.HttpPost;
|
||||||
import org.apache.http.client.methods.HttpUriRequest;
|
import org.apache.http.client.methods.HttpUriRequest;
|
||||||
|
@ -39,7 +40,7 @@ public class ApiCallRunnable implements Runnable {
|
||||||
private String retorno;
|
private String retorno;
|
||||||
private String urlBase;
|
private String urlBase;
|
||||||
private String user = "internal";
|
private String user = "internal";
|
||||||
private boolean get = true;
|
private ETipoEnvio tipoEnvio;
|
||||||
|
|
||||||
public String getUrl() {
|
public String getUrl() {
|
||||||
return url;
|
return url;
|
||||||
|
@ -71,14 +72,14 @@ public class ApiCallRunnable implements Runnable {
|
||||||
this.urlBase = urlOriginal;
|
this.urlBase = urlOriginal;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ApiCallRunnable(String url, String tenant, String urlBase, String user, String secret, boolean get) {
|
public ApiCallRunnable(String url, String tenant, String urlBase, String user, String secret, ETipoEnvio tipoEnvio) {
|
||||||
super();
|
super();
|
||||||
this.secret = secret;
|
this.secret = secret;
|
||||||
this.url = url;
|
this.url = url;
|
||||||
this.tenant = tenant;
|
this.tenant = tenant;
|
||||||
this.urlBase = urlBase;
|
this.urlBase = urlBase;
|
||||||
this.user = user;
|
this.user = user;
|
||||||
this.get = get;
|
this.tipoEnvio = tipoEnvio;
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
|
@ -90,10 +91,12 @@ public class ApiCallRunnable implements Runnable {
|
||||||
|
|
||||||
HttpUriRequest request;
|
HttpUriRequest request;
|
||||||
|
|
||||||
if(isGet()) {
|
if(ETipoEnvio.POST.equals(tipoEnvio)) {
|
||||||
request = new HttpGet(url);
|
|
||||||
}else {
|
|
||||||
request = new HttpPost(url);
|
request = new HttpPost(url);
|
||||||
|
} else if(ETipoEnvio.DELETE.equals(tipoEnvio)) {
|
||||||
|
request = new HttpDelete(url);
|
||||||
|
} else {
|
||||||
|
request = new HttpGet(url);
|
||||||
}
|
}
|
||||||
|
|
||||||
UsernamePasswordCredentials creds = null;
|
UsernamePasswordCredentials creds = null;
|
||||||
|
@ -172,12 +175,12 @@ public class ApiCallRunnable implements Runnable {
|
||||||
this.secret = secret;
|
this.secret = secret;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isGet() {
|
public ETipoEnvio getTipoEnvio() {
|
||||||
return get;
|
return tipoEnvio;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setGet(boolean get) {
|
public void setTipoEnvio(ETipoEnvio tipoEnvio) {
|
||||||
this.get = get;
|
this.tipoEnvio = tipoEnvio;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -0,0 +1,120 @@
|
||||||
|
package com.rjconsultores.ventaboletos.web.utilerias.api;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.apache.commons.lang.StringUtils;
|
||||||
|
import org.apache.logging.log4j.LogManager;
|
||||||
|
import org.apache.logging.log4j.Logger;
|
||||||
|
import org.springframework.context.ApplicationContext;
|
||||||
|
import org.zkoss.util.resource.Labels;
|
||||||
|
|
||||||
|
import com.rjconsultores.ventaboletos.entidad.Empresa;
|
||||||
|
import com.rjconsultores.ventaboletos.entidad.Usuario;
|
||||||
|
import com.rjconsultores.ventaboletos.enums.CacheApiEnum;
|
||||||
|
import com.rjconsultores.ventaboletos.service.ConstanteService;
|
||||||
|
import com.rjconsultores.ventaboletos.service.UsuarioEmpresaService;
|
||||||
|
import com.rjconsultores.ventaboletos.utilerias.UsuarioLogado;
|
||||||
|
import com.rjconsultores.ventaboletos.web.utilerias.spring.AppContext;
|
||||||
|
|
||||||
|
public class CacheOperadorEmbarcada {
|
||||||
|
|
||||||
|
private static CacheOperadorEmbarcada instance;
|
||||||
|
|
||||||
|
public final String URL_API_EMB = "URL_API_EMB";
|
||||||
|
|
||||||
|
private static Logger log = LogManager.getLogger(CacheOperadorEmbarcada.class);
|
||||||
|
|
||||||
|
public static CacheOperadorEmbarcada getInstance() {
|
||||||
|
if(instance == null) {
|
||||||
|
instance = new CacheOperadorEmbarcada();
|
||||||
|
}
|
||||||
|
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void limparCacheOperador(String OperadorId, String senha, Usuario usuario) {
|
||||||
|
try {
|
||||||
|
log.info("Inicio limparCacheOperador, OperadorId: " + OperadorId);
|
||||||
|
CacheApiEnum entidade = CacheApiEnum.OPERADOR_ESPECIFICO;
|
||||||
|
|
||||||
|
String[] urls = getURLSAPI();
|
||||||
|
|
||||||
|
if (urls == null || urls.length == 0) {
|
||||||
|
log.info(Labels.getLabel("limparCacheAPI.message.naoconfigurado"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Usuario user = UsuarioLogado.getUsuarioLogado();
|
||||||
|
|
||||||
|
List<Empresa> empresas = buscarEmpresas(usuario);
|
||||||
|
|
||||||
|
for (String url : urls) {
|
||||||
|
|
||||||
|
if (StringUtils.isBlank(url) || url.contains("|")) {
|
||||||
|
log.info(Labels.getLabel("limparCacheAPI.message.naoconfigurado"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
String tenant = StringUtils.substringBetween(url, "[", "]");
|
||||||
|
if (tenant != null) {
|
||||||
|
url = url.replaceAll("\\[.*?\\]", "");
|
||||||
|
}
|
||||||
|
String urlBase = url;
|
||||||
|
|
||||||
|
for(Empresa emp : empresas) {
|
||||||
|
|
||||||
|
url = montarUrlRequest(url, entidade.getUri(), OperadorId, emp.getEmpresaId());
|
||||||
|
|
||||||
|
log.info("URL: " + url);
|
||||||
|
|
||||||
|
ApiCallRunnable cache = new ApiCallRunnable(
|
||||||
|
url,
|
||||||
|
tenant,
|
||||||
|
urlBase,
|
||||||
|
user.getClaveUsuario(),
|
||||||
|
senha,
|
||||||
|
ETipoEnvio.DELETE);
|
||||||
|
|
||||||
|
Thread thread = new Thread(cache);
|
||||||
|
thread.start();
|
||||||
|
thread.join();
|
||||||
|
|
||||||
|
log.info(cache.getRetorno());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
log.info("Final limparCacheOperador, OperadorId: " + OperadorId);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("Erro ao limpar cache operador embarcada", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private String montarUrlRequest(String url, String uri, String OperadorId, Integer empresaId) {
|
||||||
|
url = url.toLowerCase();
|
||||||
|
|
||||||
|
if (!url.endsWith("/")) {
|
||||||
|
url += "/";
|
||||||
|
}
|
||||||
|
|
||||||
|
uri = uri.replace("operador_id", OperadorId);
|
||||||
|
uri = uri.replace("empresa_id", empresaId.toString());
|
||||||
|
|
||||||
|
return url.concat(uri);
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<Empresa> buscarEmpresas(Usuario usuario) {
|
||||||
|
ApplicationContext appContext = AppContext.getApplicationContext();
|
||||||
|
UsuarioEmpresaService usuarioEmpService = (UsuarioEmpresaService) appContext.getBean("usuarioEmpresaService");
|
||||||
|
|
||||||
|
return usuarioEmpService.obtenerEmpresa(usuario);
|
||||||
|
}
|
||||||
|
|
||||||
|
private String[] getURLSAPI() {
|
||||||
|
ApplicationContext appContext = AppContext.getApplicationContext();
|
||||||
|
ConstanteService constanteService = (ConstanteService) appContext.getBean("constanteService");
|
||||||
|
String constante = constanteService.buscarURLAPIEmb();
|
||||||
|
|
||||||
|
return constante == null ? null : constante.split("\\|");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,5 @@
|
||||||
|
package com.rjconsultores.ventaboletos.web.utilerias.api;
|
||||||
|
|
||||||
|
public enum ETipoEnvio {
|
||||||
|
GET, POST, DELETE;
|
||||||
|
}
|
Loading…
Reference in New Issue