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 | 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 | 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 | 337 | }catch(Exception ex){ |
336 | 338 | registrarProblemaInclusao(inclusaoDocumento); |
337 | 339 | |
... | ... | @@ -710,9 +712,10 @@ public class DocumentoResource { |
710 | 712 | } |
711 | 713 | |
712 | 714 | public String transformarConteudoDocumentoInterno(String conteudo, String template) throws RemoteException, Exception{ |
715 | + StringWriter writer = new StringWriter(); | |
716 | + | |
713 | 717 | try{ |
714 | 718 | Mustache mustache = mustacheUtils.compile(removeExtensaoLegado(template)); |
715 | - StringWriter writer = new StringWriter(); | |
716 | 719 | |
717 | 720 | Map<String, Object> model = decodeConteudoMustache(conteudo); |
718 | 721 | |
... | ... | @@ -723,6 +726,8 @@ public class DocumentoResource { |
723 | 726 | }catch(JsonParseException ex){ |
724 | 727 | logger.debug(conteudo); |
725 | 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 | 99 | @Path("/conexoes/mysql") |
100 | 100 | @Produces(MediaType.TEXT_PLAIN) |
101 | 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 | 104 | try{ |
105 | 105 | return((String) query.getSingleResult()); |
... | ... | @@ -133,7 +133,7 @@ public class InfoResource { |
133 | 133 | @Path("/conexoes/oracle") |
134 | 134 | @Produces(MediaType.TEXT_PLAIN) |
135 | 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 | 138 | try{ |
139 | 139 | return ((String) query.getSingleResult()); |
... | ... | @@ -170,7 +170,7 @@ public class InfoResource { |
170 | 170 | try{ |
171 | 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 | 174 | }catch(Exception ex){ |
175 | 175 | logger.error(messages.getMessage("erro.testar.sei"),ex); |
176 | 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 @@ |
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 | 67 | @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) |
68 | 68 | public br.gov.ans.integracao.sei.client.Unidade[] listarUnidades() throws Exception{ |
69 | 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 | 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 | 6 | @Named |
7 | 7 | @ApplicationScoped |
8 | 8 | public class Constantes { |
9 | + public static final String ACCEPT_HEADER_KEY = "Accept"; | |
9 | 10 | private static final int AXIS_TIMEOUT_IN_MINUTES = 10; |
10 | 11 | public static final int AXIS_TIMEOUT = 1000 * (60 * AXIS_TIMEOUT_IN_MINUTES); |
11 | 12 | public static final String CODIGO_BRASIL = "76"; |
12 | 13 | public static final String CODIGO_ORGAO_ANS = "0"; |
14 | + public static final String CONTENT_TYPE_HEADER_KEY= "Content-Type"; | |
13 | 15 | public static final String DATE_PATTERN = "dd/MM/yyyy"; |
14 | 16 | public static final String DOCUMENTO_GERAL = "G"; |
15 | 17 | public static final String DOCUMENTO_RECEBIDO = "R"; |
18 | + public static final String JBOSS_HOME = System.getProperty("jboss.home.dir"); | |
16 | 19 | public static final String MASCARA_PROCESSO_17 = "#####.######/####-##"; |
17 | 20 | public static final String MASCARA_PROCESSO_21 = "#######.########/####-##"; |
21 | + public static final String MYSQL_SQL_TEST_CONECTION = "SELECT version()"; | |
18 | 22 | public static String NAO = "N"; |
19 | - public static final String JBOSS_HOME = System.getProperty("jboss.home.dir"); | |
20 | 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 | 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 | 26 | public static final String REGEX_SOMENTE_NUMEROS = "\\D+"; |
23 | 27 | public static final String RESOURCE_METHOD_INVOKER = "org.jboss.resteasy.core.ResourceMethodInvoker"; |
24 | 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 | 31 | public static final int TAMANHO_MAXIMO_ARQUIVO = 16777216; |
26 | 32 | public static final int TAMANHO_MAXIMO_DOCUMENTO = 22020096; |
27 | 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 | 110 | |
111 | 111 | private void preencherDadosAssociado(Pessoa pessoa, Contato contato) throws RemoteException, BusinessException, Exception{ |
112 | 112 | if(pessoa.getAssociado() == null){ |
113 | - contato.setSinEnderecoAssociado("N"); | |
113 | + contato.setSinEnderecoAssociado(Constantes.NAO); | |
114 | 114 | }else{ |
115 | - contato.setSinEnderecoAssociado("S"); | |
115 | + contato.setSinEnderecoAssociado(Constantes.SIM); | |
116 | 116 | |
117 | 117 | contato.setIdContatoAssociado(getIdContato(pessoa.getAssociado().getSigla())+""); |
118 | 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 | 21 | |
22 | 22 | public class Util { |
23 | 23 | private static final FastDateFormat dateFormater = FastDateFormat.getInstance(Constantes.DATE_PATTERN); |
24 | - | |
24 | + | |
25 | + private static final ObjectMapper mapper = new ObjectMapper(); | |
26 | + | |
25 | 27 | public static String getSOuN(String valor){ |
26 | 28 | if("S".equals(valor) || "s".equals(valor)){ |
27 | 29 | return "S"; |
... | ... | @@ -110,8 +112,6 @@ public class Util { |
110 | 112 | public static Map<String, Object> jsonToMap(String json) throws JsonParseException,JsonMappingException, IOException { |
111 | 113 | Map<String,Object> out = new HashMap<String,Object>(); |
112 | 114 | |
113 | - ObjectMapper mapper = new ObjectMapper(); | |
114 | - | |
115 | 115 | out = mapper.readValue(json, new TypeReference<Map<String, Object>>(){}); |
116 | 116 | |
117 | 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 | 13 | import br.gov.ans.exceptions.ErrorMessage; |
14 | 14 | import br.gov.ans.factories.qualifiers.Autenticado; |
15 | 15 | import br.gov.ans.factories.qualifiers.SeiQualifiers.TemplatesBrokerParameter; |
16 | +import br.gov.ans.integracao.sei.utils.Constantes; | |
16 | 17 | |
17 | 18 | public class ClientTemplatesBroker { |
18 | 19 | |
... | ... | @@ -44,13 +45,14 @@ public class ClientTemplatesBroker { |
44 | 45 | |
45 | 46 | return corpoTemplate; |
46 | 47 | }catch(ProcessingException ex){ |
47 | - logger.error(ex, ex); | |
48 | + logger.error(ex); | |
49 | + logger.debug(ex, ex); | |
48 | 50 | throw new Exception("Erro ao carregar o template, contacte a equipe responsável."); |
49 | 51 | } |
50 | 52 | } |
51 | 53 | |
52 | 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 | 56 | logger.error(response.readEntity(String.class)); |
55 | 57 | |
56 | 58 | response.close(); | ... | ... |
src/main/java/br/gov/ans/utils/HttpHeadersUtil.java
... | ... | @@ -7,13 +7,15 @@ import javax.ws.rs.core.MediaType; |
7 | 7 | import org.apache.commons.lang3.StringUtils; |
8 | 8 | import org.jboss.logging.Logger; |
9 | 9 | |
10 | +import br.gov.ans.integracao.sei.utils.Constantes; | |
11 | + | |
10 | 12 | public class HttpHeadersUtil { |
11 | 13 | |
12 | 14 | private static Logger logger = Logger.getLogger(HttpHeadersUtil.class); |
13 | 15 | |
14 | 16 | public static String getAcceptType(HttpHeaders headers){ |
15 | 17 | try{ |
16 | - String accept = headers.getRequestHeader("Accept").get(0); | |
18 | + String accept = headers.getRequestHeader(Constantes.ACCEPT_HEADER_KEY).get(0); | |
17 | 19 | |
18 | 20 | if(!StringUtils.isBlank(accept)&& StringUtils.contains(accept, MediaType.APPLICATION_XML)){ |
19 | 21 | return MediaType.APPLICATION_XML; |
... | ... | @@ -27,7 +29,7 @@ public class HttpHeadersUtil { |
27 | 29 | |
28 | 30 | public static String getAcceptType(HttpServletRequest request){ |
29 | 31 | try{ |
30 | - String accept = request.getHeader("Accept"); | |
32 | + String accept = request.getHeader(Constantes.ACCEPT_HEADER_KEY); | |
31 | 33 | |
32 | 34 | if(!StringUtils.isBlank(accept)&& StringUtils.contains(accept, MediaType.APPLICATION_XML)){ |
33 | 35 | return MediaType.APPLICATION_XML; | ... | ... |