Commit dec392b2997e2c3a9451e0248a9325e61c0f8752
1 parent
7e10bf4f
Exists in
master
and in
1 other branch
Cria novas constantes
- Novas constantes criadas para valores utilizados com frequência. - Criação de atributo estático para ObjectMapper
Showing
9 changed files
with
41 additions
and
18 deletions
Show diff stats
src/main/java/br/gov/ans/integracao/sei/rest/DocumentoResource.java
@@ -329,9 +329,11 @@ public class DocumentoResource { | @@ -329,9 +329,11 @@ public class DocumentoResource { | ||
329 | documento.setConteudo(conteudoHTML); | 329 | documento.setConteudo(conteudoHTML); |
330 | } | 330 | } |
331 | 331 | ||
332 | - logger.debug(messages.getMessage("debug.novo.documento.enviado")); | 332 | + logger.debug(messages.getMessage(MessagesKeys.DEBUG_NOVO_DOCUMENTO_ENVIADO)); |
333 | + | ||
333 | retorno = seiNativeService.incluirDocumento(Constantes.SEI_BROKER, Operacao.INCLUIR_DOCUMENTO, unidadeResource.consultarCodigo(unidade), documento); | 334 | retorno = seiNativeService.incluirDocumento(Constantes.SEI_BROKER, Operacao.INCLUIR_DOCUMENTO, unidadeResource.consultarCodigo(unidade), documento); |
334 | - logger.debug(messages.getMessage("debug.novo.documento.processado")); | 335 | + |
336 | + logger.debug(messages.getMessage(MessagesKeys.DEBUG_NOVO_DOCUMENTO_PROCESSADO)); | ||
335 | }catch(Exception ex){ | 337 | }catch(Exception ex){ |
336 | registrarProblemaInclusao(inclusaoDocumento); | 338 | registrarProblemaInclusao(inclusaoDocumento); |
337 | 339 | ||
@@ -710,9 +712,10 @@ public class DocumentoResource { | @@ -710,9 +712,10 @@ public class DocumentoResource { | ||
710 | } | 712 | } |
711 | 713 | ||
712 | public String transformarConteudoDocumentoInterno(String conteudo, String template) throws RemoteException, Exception{ | 714 | public String transformarConteudoDocumentoInterno(String conteudo, String template) throws RemoteException, Exception{ |
715 | + StringWriter writer = new StringWriter(); | ||
716 | + | ||
713 | try{ | 717 | try{ |
714 | Mustache mustache = mustacheUtils.compile(removeExtensaoLegado(template)); | 718 | Mustache mustache = mustacheUtils.compile(removeExtensaoLegado(template)); |
715 | - StringWriter writer = new StringWriter(); | ||
716 | 719 | ||
717 | Map<String, Object> model = decodeConteudoMustache(conteudo); | 720 | Map<String, Object> model = decodeConteudoMustache(conteudo); |
718 | 721 | ||
@@ -723,6 +726,8 @@ public class DocumentoResource { | @@ -723,6 +726,8 @@ public class DocumentoResource { | ||
723 | }catch(JsonParseException ex){ | 726 | }catch(JsonParseException ex){ |
724 | logger.debug(conteudo); | 727 | logger.debug(conteudo); |
725 | throw new BusinessException(messages.getMessage("erro.processar.conteudo.json")); | 728 | throw new BusinessException(messages.getMessage("erro.processar.conteudo.json")); |
729 | + }finally{ | ||
730 | + writer.close(); | ||
726 | } | 731 | } |
727 | } | 732 | } |
728 | 733 |
src/main/java/br/gov/ans/integracao/sei/rest/InfoResource.java
@@ -99,7 +99,7 @@ public class InfoResource { | @@ -99,7 +99,7 @@ public class InfoResource { | ||
99 | @Path("/conexoes/mysql") | 99 | @Path("/conexoes/mysql") |
100 | @Produces(MediaType.TEXT_PLAIN) | 100 | @Produces(MediaType.TEXT_PLAIN) |
101 | public String testMySQLConnection() throws Exception{ | 101 | public String testMySQLConnection() throws Exception{ |
102 | - Query query = emMySQL.createNativeQuery("SELECT version()"); | 102 | + Query query = emMySQL.createNativeQuery(Constantes.MYSQL_SQL_TEST_CONECTION); |
103 | 103 | ||
104 | try{ | 104 | try{ |
105 | return((String) query.getSingleResult()); | 105 | return((String) query.getSingleResult()); |
@@ -133,7 +133,7 @@ public class InfoResource { | @@ -133,7 +133,7 @@ public class InfoResource { | ||
133 | @Path("/conexoes/oracle") | 133 | @Path("/conexoes/oracle") |
134 | @Produces(MediaType.TEXT_PLAIN) | 134 | @Produces(MediaType.TEXT_PLAIN) |
135 | public String testOracleConnection() throws Exception{ | 135 | public String testOracleConnection() throws Exception{ |
136 | - Query query = emOracle.createNativeQuery("SELECT BANNER FROM V$VERSION WHERE ROWNUM = 1"); | 136 | + Query query = emOracle.createNativeQuery(Constantes.ORACLE_SQL_TEST_CONECTION); |
137 | 137 | ||
138 | try{ | 138 | try{ |
139 | return ((String) query.getSingleResult()); | 139 | return ((String) query.getSingleResult()); |
@@ -170,7 +170,7 @@ public class InfoResource { | @@ -170,7 +170,7 @@ public class InfoResource { | ||
170 | try{ | 170 | try{ |
171 | seiNativeService.listarUnidades(Constantes.SEI_BROKER, Operacao.LISTAR_UNIDADES, null, null); | 171 | seiNativeService.listarUnidades(Constantes.SEI_BROKER, Operacao.LISTAR_UNIDADES, null, null); |
172 | 172 | ||
173 | - return "SEI respondeu com sucesso."; | 173 | + return Constantes.SEI_RESPONDEU_COM_SUCESSO; |
174 | }catch(Exception ex){ | 174 | }catch(Exception ex){ |
175 | logger.error(messages.getMessage("erro.testar.sei"),ex); | 175 | logger.error(messages.getMessage("erro.testar.sei"),ex); |
176 | throw new Exception(messages.getMessage("erro.testar.sei")); | 176 | throw new Exception(messages.getMessage("erro.testar.sei")); |
src/main/java/br/gov/ans/integracao/sei/rest/MessagesKeys.java
0 → 100644
@@ -0,0 +1,6 @@ | @@ -0,0 +1,6 @@ | ||
1 | +package br.gov.ans.integracao.sei.rest; | ||
2 | + | ||
3 | +public class MessagesKeys { | ||
4 | + public static final String DEBUG_NOVO_DOCUMENTO_ENVIADO = "debug.novo.documento.enviado"; | ||
5 | + public static final String DEBUG_NOVO_DOCUMENTO_PROCESSADO = "debug.novo.documento.processado"; | ||
6 | +} |
src/main/java/br/gov/ans/integracao/sei/rest/UnidadeResource.java
@@ -67,8 +67,10 @@ public class UnidadeResource { | @@ -67,8 +67,10 @@ public class UnidadeResource { | ||
67 | @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) | 67 | @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) |
68 | public br.gov.ans.integracao.sei.client.Unidade[] listarUnidades() throws Exception{ | 68 | public br.gov.ans.integracao.sei.client.Unidade[] listarUnidades() throws Exception{ |
69 | Unidade[] lista = seiNativeService.listarUnidades(Constantes.SEI_BROKER, Operacao.LISTAR_UNIDADES, null, null); | 69 | Unidade[] lista = seiNativeService.listarUnidades(Constantes.SEI_BROKER, Operacao.LISTAR_UNIDADES, null, null); |
70 | - | ||
71 | - carregarMapUnidades(lista); | 70 | + |
71 | + if(isMapUnidadesExpirado()){ | ||
72 | + carregarMapUnidades(lista); | ||
73 | + } | ||
72 | 74 | ||
73 | return lista; | 75 | return lista; |
74 | } | 76 | } |
src/main/java/br/gov/ans/integracao/sei/utils/Constantes.java
@@ -6,22 +6,28 @@ import javax.inject.Named; | @@ -6,22 +6,28 @@ import javax.inject.Named; | ||
6 | @Named | 6 | @Named |
7 | @ApplicationScoped | 7 | @ApplicationScoped |
8 | public class Constantes { | 8 | public class Constantes { |
9 | + public static final String ACCEPT_HEADER_KEY = "Accept"; | ||
9 | private static final int AXIS_TIMEOUT_IN_MINUTES = 10; | 10 | private static final int AXIS_TIMEOUT_IN_MINUTES = 10; |
10 | public static final int AXIS_TIMEOUT = 1000 * (60 * AXIS_TIMEOUT_IN_MINUTES); | 11 | public static final int AXIS_TIMEOUT = 1000 * (60 * AXIS_TIMEOUT_IN_MINUTES); |
11 | public static final String CODIGO_BRASIL = "76"; | 12 | public static final String CODIGO_BRASIL = "76"; |
12 | public static final String CODIGO_ORGAO_ANS = "0"; | 13 | public static final String CODIGO_ORGAO_ANS = "0"; |
14 | + public static final String CONTENT_TYPE_HEADER_KEY= "Content-Type"; | ||
13 | public static final String DATE_PATTERN = "dd/MM/yyyy"; | 15 | public static final String DATE_PATTERN = "dd/MM/yyyy"; |
14 | public static final String DOCUMENTO_GERAL = "G"; | 16 | public static final String DOCUMENTO_GERAL = "G"; |
15 | public static final String DOCUMENTO_RECEBIDO = "R"; | 17 | public static final String DOCUMENTO_RECEBIDO = "R"; |
18 | + public static final String JBOSS_HOME = System.getProperty("jboss.home.dir"); | ||
16 | public static final String MASCARA_PROCESSO_17 = "#####.######/####-##"; | 19 | public static final String MASCARA_PROCESSO_17 = "#####.######/####-##"; |
17 | public static final String MASCARA_PROCESSO_21 = "#######.########/####-##"; | 20 | public static final String MASCARA_PROCESSO_21 = "#######.########/####-##"; |
21 | + public static final String MYSQL_SQL_TEST_CONECTION = "SELECT version()"; | ||
18 | public static String NAO = "N"; | 22 | public static String NAO = "N"; |
19 | - public static final String JBOSS_HOME = System.getProperty("jboss.home.dir"); | ||
20 | public static final String NOME_SISTEMA = "sei-broker"; | 23 | public static final String NOME_SISTEMA = "sei-broker"; |
24 | + public static final String ORACLE_SQL_TEST_CONECTION = "SELECT BANNER FROM V$VERSION WHERE ROWNUM = 1"; | ||
21 | public static final String REGEX_MASCARA_PROCESSO = "(\\d)(\\d)(\\d)(\\d)(\\d)(\\.)(\\d)(\\d)(\\d)(\\d)(\\d)(\\d)(\\/)(\\d)(\\d)(\\d)(\\d)(-)(\\d)(\\d)"; | 25 | public static final String REGEX_MASCARA_PROCESSO = "(\\d)(\\d)(\\d)(\\d)(\\d)(\\.)(\\d)(\\d)(\\d)(\\d)(\\d)(\\d)(\\/)(\\d)(\\d)(\\d)(\\d)(-)(\\d)(\\d)"; |
22 | public static final String REGEX_SOMENTE_NUMEROS = "\\D+"; | 26 | public static final String REGEX_SOMENTE_NUMEROS = "\\D+"; |
23 | public static final String RESOURCE_METHOD_INVOKER = "org.jboss.resteasy.core.ResourceMethodInvoker"; | 27 | public static final String RESOURCE_METHOD_INVOKER = "org.jboss.resteasy.core.ResourceMethodInvoker"; |
24 | public static final String SEI_BROKER = "SEI-Broker"; | 28 | public static final String SEI_BROKER = "SEI-Broker"; |
29 | + public static final String SEI_RESPONDEU_COM_SUCESSO = "SEI respondeu com sucesso."; | ||
30 | + public static String SIM = "S"; | ||
25 | public static final int TAMANHO_MAXIMO_ARQUIVO = 16777216; | 31 | public static final int TAMANHO_MAXIMO_ARQUIVO = 16777216; |
26 | public static final int TAMANHO_MAXIMO_DOCUMENTO = 22020096; | 32 | public static final int TAMANHO_MAXIMO_DOCUMENTO = 22020096; |
27 | public static final Integer TAMANHO_PAGINA_PADRAO = 50; | 33 | public static final Integer TAMANHO_PAGINA_PADRAO = 50; |
src/main/java/br/gov/ans/integracao/sei/utils/ContatoHelper.java
@@ -110,9 +110,9 @@ public class ContatoHelper { | @@ -110,9 +110,9 @@ public class ContatoHelper { | ||
110 | 110 | ||
111 | private void preencherDadosAssociado(Pessoa pessoa, Contato contato) throws RemoteException, BusinessException, Exception{ | 111 | private void preencherDadosAssociado(Pessoa pessoa, Contato contato) throws RemoteException, BusinessException, Exception{ |
112 | if(pessoa.getAssociado() == null){ | 112 | if(pessoa.getAssociado() == null){ |
113 | - contato.setSinEnderecoAssociado("N"); | 113 | + contato.setSinEnderecoAssociado(Constantes.NAO); |
114 | }else{ | 114 | }else{ |
115 | - contato.setSinEnderecoAssociado("S"); | 115 | + contato.setSinEnderecoAssociado(Constantes.SIM); |
116 | 116 | ||
117 | contato.setIdContatoAssociado(getIdContato(pessoa.getAssociado().getSigla())+""); | 117 | contato.setIdContatoAssociado(getIdContato(pessoa.getAssociado().getSigla())+""); |
118 | contato.setNomeContatoAssociado(pessoa.getAssociado().getNome()); | 118 | contato.setNomeContatoAssociado(pessoa.getAssociado().getNome()); |
src/main/java/br/gov/ans/integracao/sei/utils/Util.java
@@ -21,7 +21,9 @@ import br.gov.ans.exceptions.BusinessException; | @@ -21,7 +21,9 @@ import br.gov.ans.exceptions.BusinessException; | ||
21 | 21 | ||
22 | public class Util { | 22 | public class Util { |
23 | private static final FastDateFormat dateFormater = FastDateFormat.getInstance(Constantes.DATE_PATTERN); | 23 | private static final FastDateFormat dateFormater = FastDateFormat.getInstance(Constantes.DATE_PATTERN); |
24 | - | 24 | + |
25 | + private static final ObjectMapper mapper = new ObjectMapper(); | ||
26 | + | ||
25 | public static String getSOuN(String valor){ | 27 | public static String getSOuN(String valor){ |
26 | if("S".equals(valor) || "s".equals(valor)){ | 28 | if("S".equals(valor) || "s".equals(valor)){ |
27 | return "S"; | 29 | return "S"; |
@@ -110,8 +112,6 @@ public class Util { | @@ -110,8 +112,6 @@ public class Util { | ||
110 | public static Map<String, Object> jsonToMap(String json) throws JsonParseException,JsonMappingException, IOException { | 112 | public static Map<String, Object> jsonToMap(String json) throws JsonParseException,JsonMappingException, IOException { |
111 | Map<String,Object> out = new HashMap<String,Object>(); | 113 | Map<String,Object> out = new HashMap<String,Object>(); |
112 | 114 | ||
113 | - ObjectMapper mapper = new ObjectMapper(); | ||
114 | - | ||
115 | out = mapper.readValue(json, new TypeReference<Map<String, Object>>(){}); | 115 | out = mapper.readValue(json, new TypeReference<Map<String, Object>>(){}); |
116 | 116 | ||
117 | return out; | 117 | return out; |
src/main/java/br/gov/ans/integracao/templates/client/ClientTemplatesBroker.java
@@ -13,6 +13,7 @@ import br.gov.ans.exceptions.BusinessException; | @@ -13,6 +13,7 @@ import br.gov.ans.exceptions.BusinessException; | ||
13 | import br.gov.ans.exceptions.ErrorMessage; | 13 | import br.gov.ans.exceptions.ErrorMessage; |
14 | import br.gov.ans.factories.qualifiers.Autenticado; | 14 | import br.gov.ans.factories.qualifiers.Autenticado; |
15 | import br.gov.ans.factories.qualifiers.SeiQualifiers.TemplatesBrokerParameter; | 15 | import br.gov.ans.factories.qualifiers.SeiQualifiers.TemplatesBrokerParameter; |
16 | +import br.gov.ans.integracao.sei.utils.Constantes; | ||
16 | 17 | ||
17 | public class ClientTemplatesBroker { | 18 | public class ClientTemplatesBroker { |
18 | 19 | ||
@@ -44,13 +45,14 @@ public class ClientTemplatesBroker { | @@ -44,13 +45,14 @@ public class ClientTemplatesBroker { | ||
44 | 45 | ||
45 | return corpoTemplate; | 46 | return corpoTemplate; |
46 | }catch(ProcessingException ex){ | 47 | }catch(ProcessingException ex){ |
47 | - logger.error(ex, ex); | 48 | + logger.error(ex); |
49 | + logger.debug(ex, ex); | ||
48 | throw new Exception("Erro ao carregar o template, contacte a equipe responsável."); | 50 | throw new Exception("Erro ao carregar o template, contacte a equipe responsável."); |
49 | } | 51 | } |
50 | } | 52 | } |
51 | 53 | ||
52 | public void errorHandling(Response response) throws Exception{ | 54 | public void errorHandling(Response response) throws Exception{ |
53 | - if(!response.getHeaderString("Content-Type").equals(MediaType.APPLICATION_JSON)){ | 55 | + if(!response.getHeaderString(Constantes.CONTENT_TYPE_HEADER_KEY).equals(MediaType.APPLICATION_JSON)){ |
54 | logger.error(response.readEntity(String.class)); | 56 | logger.error(response.readEntity(String.class)); |
55 | 57 | ||
56 | response.close(); | 58 | response.close(); |
src/main/java/br/gov/ans/utils/HttpHeadersUtil.java
@@ -7,13 +7,15 @@ import javax.ws.rs.core.MediaType; | @@ -7,13 +7,15 @@ import javax.ws.rs.core.MediaType; | ||
7 | import org.apache.commons.lang3.StringUtils; | 7 | import org.apache.commons.lang3.StringUtils; |
8 | import org.jboss.logging.Logger; | 8 | import org.jboss.logging.Logger; |
9 | 9 | ||
10 | +import br.gov.ans.integracao.sei.utils.Constantes; | ||
11 | + | ||
10 | public class HttpHeadersUtil { | 12 | public class HttpHeadersUtil { |
11 | 13 | ||
12 | private static Logger logger = Logger.getLogger(HttpHeadersUtil.class); | 14 | private static Logger logger = Logger.getLogger(HttpHeadersUtil.class); |
13 | 15 | ||
14 | public static String getAcceptType(HttpHeaders headers){ | 16 | public static String getAcceptType(HttpHeaders headers){ |
15 | try{ | 17 | try{ |
16 | - String accept = headers.getRequestHeader("Accept").get(0); | 18 | + String accept = headers.getRequestHeader(Constantes.ACCEPT_HEADER_KEY).get(0); |
17 | 19 | ||
18 | if(!StringUtils.isBlank(accept)&& StringUtils.contains(accept, MediaType.APPLICATION_XML)){ | 20 | if(!StringUtils.isBlank(accept)&& StringUtils.contains(accept, MediaType.APPLICATION_XML)){ |
19 | return MediaType.APPLICATION_XML; | 21 | return MediaType.APPLICATION_XML; |
@@ -27,7 +29,7 @@ public class HttpHeadersUtil { | @@ -27,7 +29,7 @@ public class HttpHeadersUtil { | ||
27 | 29 | ||
28 | public static String getAcceptType(HttpServletRequest request){ | 30 | public static String getAcceptType(HttpServletRequest request){ |
29 | try{ | 31 | try{ |
30 | - String accept = request.getHeader("Accept"); | 32 | + String accept = request.getHeader(Constantes.ACCEPT_HEADER_KEY); |
31 | 33 | ||
32 | if(!StringUtils.isBlank(accept)&& StringUtils.contains(accept, MediaType.APPLICATION_XML)){ | 34 | if(!StringUtils.isBlank(accept)&& StringUtils.contains(accept, MediaType.APPLICATION_XML)){ |
33 | return MediaType.APPLICATION_XML; | 35 | return MediaType.APPLICATION_XML; |