74307 - Exclusão do cache por operador feat bug#AL-4243
parent
5e83ce33fb
commit
1db2bc3118
4
pom.xml
4
pom.xml
|
@ -4,11 +4,11 @@
|
|||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>br.com.rjconsultores</groupId>
|
||||
<artifactId>ventaboletosadm</artifactId>
|
||||
<version>1.130.1</version>
|
||||
<version>1.131.0</version>
|
||||
<packaging>war</packaging>
|
||||
|
||||
<properties>
|
||||
<modelWeb.version>1.100.0</modelWeb.version>
|
||||
<modelWeb.version>1.101.0</modelWeb.version>
|
||||
<flyway.version>1.88.0</flyway.version>
|
||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||
</properties>
|
||||
|
|
|
@ -42,9 +42,11 @@ import com.rjconsultores.ventaboletos.service.ClaseServicioService;
|
|||
import com.rjconsultores.ventaboletos.service.MarcaService;
|
||||
import com.rjconsultores.ventaboletos.service.OperadorEmbarcadaService;
|
||||
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.MyGenericForwardComposer;
|
||||
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.PagedListWrapper;
|
||||
import com.rjconsultores.ventaboletos.web.utilerias.render.ItemRenderRutaOperadorEmbarcada;
|
||||
|
@ -553,7 +555,13 @@ public class EditarOperadorEmbarcadaController extends MyGenericForwardComposer
|
|||
|
||||
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 {
|
||||
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) {
|
||||
|
||||
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);
|
||||
|
||||
Messagebox.show(
|
||||
|
@ -589,6 +603,8 @@ public class EditarOperadorEmbarcadaController extends MyGenericForwardComposer
|
|||
Labels.getLabel("busquedaOperadorEmbarcada.MSG.borrarPergunta.title"),
|
||||
Messagebox.OK, Messagebox.INFORMATION);
|
||||
|
||||
CacheOperadorEmbarcada.getInstance().limparCacheOperador(OperadorId, senha, usuario);
|
||||
|
||||
closeWindow();
|
||||
}
|
||||
} 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.MyGenericForwardComposer;
|
||||
import com.rjconsultores.ventaboletos.web.utilerias.api.ApiCallRunnable;
|
||||
import com.rjconsultores.ventaboletos.web.utilerias.api.ETipoEnvio;
|
||||
import com.rjconsultores.ventaboletos.web.utilerias.spring.AppContext;
|
||||
|
||||
/**
|
||||
|
@ -119,7 +120,7 @@ public class LimparCacheApiController extends MyGenericForwardComposer {
|
|||
urlBase,
|
||||
user.getClaveUsuario(),
|
||||
secret,
|
||||
false);
|
||||
ETipoEnvio.POST);
|
||||
Thread thread = new Thread(cache);
|
||||
thread.start();
|
||||
thread.join();
|
||||
|
|
|
@ -10,6 +10,7 @@ import org.apache.http.HttpEntity;
|
|||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.auth.UsernamePasswordCredentials;
|
||||
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.HttpPost;
|
||||
import org.apache.http.client.methods.HttpUriRequest;
|
||||
|
@ -39,7 +40,7 @@ public class ApiCallRunnable implements Runnable {
|
|||
private String retorno;
|
||||
private String urlBase;
|
||||
private String user = "internal";
|
||||
private boolean get = true;
|
||||
private ETipoEnvio tipoEnvio;
|
||||
|
||||
public String getUrl() {
|
||||
return url;
|
||||
|
@ -71,14 +72,14 @@ public class ApiCallRunnable implements Runnable {
|
|||
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();
|
||||
this.secret = secret;
|
||||
this.url = url;
|
||||
this.tenant = tenant;
|
||||
this.urlBase = urlBase;
|
||||
this.user = user;
|
||||
this.get = get;
|
||||
this.tipoEnvio = tipoEnvio;
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
|
@ -90,10 +91,12 @@ public class ApiCallRunnable implements Runnable {
|
|||
|
||||
HttpUriRequest request;
|
||||
|
||||
if(isGet()) {
|
||||
request = new HttpGet(url);
|
||||
}else {
|
||||
if(ETipoEnvio.POST.equals(tipoEnvio)) {
|
||||
request = new HttpPost(url);
|
||||
} else if(ETipoEnvio.DELETE.equals(tipoEnvio)) {
|
||||
request = new HttpDelete(url);
|
||||
} else {
|
||||
request = new HttpGet(url);
|
||||
}
|
||||
|
||||
UsernamePasswordCredentials creds = null;
|
||||
|
@ -172,12 +175,12 @@ public class ApiCallRunnable implements Runnable {
|
|||
this.secret = secret;
|
||||
}
|
||||
|
||||
public boolean isGet() {
|
||||
return get;
|
||||
public ETipoEnvio getTipoEnvio() {
|
||||
return tipoEnvio;
|
||||
}
|
||||
|
||||
public void setGet(boolean get) {
|
||||
this.get = get;
|
||||
public void setTipoEnvio(ETipoEnvio tipoEnvio) {
|
||||
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