Commit 18ad530b6445a24f42817792a616a141eae2afb1

Authored by andre.guimaraes
1 parent eaa6edc1

Corrige problemas apontados pelo Sonnar

- Alguns atributos estáticos não eram ThreadSafe
- Havia um iteração com problemas de performance
- Invocação ineficiente do construtor da classe Boolean
src/main/java/br/gov/ans/integracao/sei/client/AtributoAndamento.java
@@ -15,185 +15,175 @@ import org.codehaus.jackson.map.annotate.JsonSerialize; @@ -15,185 +15,175 @@ import org.codehaus.jackson.map.annotate.JsonSerialize;
15 @JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL) 15 @JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)
16 @JsonIgnoreProperties(ignoreUnknown = true) 16 @JsonIgnoreProperties(ignoreUnknown = true)
17 @XmlRootElement 17 @XmlRootElement
18 -public class AtributoAndamento implements java.io.Serializable {  
19 - private java.lang.String nome;  
20 -  
21 - private java.lang.String valor;  
22 -  
23 - private java.lang.String idOrigem;  
24 -  
25 - public AtributoAndamento() {  
26 - }  
27 -  
28 - public AtributoAndamento(  
29 - java.lang.String nome,  
30 - java.lang.String valor,  
31 - java.lang.String idOrigem) {  
32 - this.nome = nome;  
33 - this.valor = valor;  
34 - this.idOrigem = idOrigem;  
35 - }  
36 -  
37 -  
38 - /**  
39 - * Gets the nome value for this AtributoAndamento.  
40 - *  
41 - * @return nome  
42 - */  
43 - public java.lang.String getNome() {  
44 - return nome;  
45 - }  
46 -  
47 -  
48 - /**  
49 - * Sets the nome value for this AtributoAndamento.  
50 - *  
51 - * @param nome  
52 - */  
53 - public void setNome(java.lang.String nome) {  
54 - this.nome = nome;  
55 - }  
56 -  
57 -  
58 - /**  
59 - * Gets the valor value for this AtributoAndamento.  
60 - *  
61 - * @return valor  
62 - */  
63 - public java.lang.String getValor() {  
64 - return valor;  
65 - }  
66 -  
67 -  
68 - /**  
69 - * Sets the valor value for this AtributoAndamento.  
70 - *  
71 - * @param valor  
72 - */  
73 - public void setValor(java.lang.String valor) {  
74 - this.valor = valor;  
75 - }  
76 -  
77 -  
78 - /**  
79 - * Gets the idOrigem value for this AtributoAndamento.  
80 - *  
81 - * @return idOrigem  
82 - */  
83 - public java.lang.String getIdOrigem() {  
84 - return idOrigem;  
85 - }  
86 -  
87 -  
88 - /**  
89 - * Sets the idOrigem value for this AtributoAndamento.  
90 - *  
91 - * @param idOrigem  
92 - */  
93 - public void setIdOrigem(java.lang.String idOrigem) {  
94 - this.idOrigem = idOrigem;  
95 - }  
96 -  
97 - private java.lang.Object __equalsCalc = null;  
98 - public boolean equals(java.lang.Object obj) {  
99 - if (!(obj instanceof AtributoAndamento)) return false;  
100 - AtributoAndamento other = (AtributoAndamento) obj;  
101 - if (obj == null) return false;  
102 - if (this == obj) return true;  
103 - if (__equalsCalc != null) {  
104 - return (__equalsCalc == obj);  
105 - }  
106 - __equalsCalc = obj;  
107 - boolean _equals;  
108 - _equals = true &&  
109 - ((this.nome==null && other.getNome()==null) ||  
110 - (this.nome!=null &&  
111 - this.nome.equals(other.getNome()))) &&  
112 - ((this.valor==null && other.getValor()==null) ||  
113 - (this.valor!=null &&  
114 - this.valor.equals(other.getValor()))) &&  
115 - ((this.idOrigem==null && other.getIdOrigem()==null) ||  
116 - (this.idOrigem!=null &&  
117 - this.idOrigem.equals(other.getIdOrigem())));  
118 - __equalsCalc = null;  
119 - return _equals;  
120 - }  
121 -  
122 - private boolean __hashCodeCalc = false;  
123 - public int hashCode() {  
124 - if (__hashCodeCalc) {  
125 - return 0;  
126 - }  
127 - __hashCodeCalc = true;  
128 - int _hashCode = 1;  
129 - if (getNome() != null) {  
130 - _hashCode += getNome().hashCode();  
131 - }  
132 - if (getValor() != null) {  
133 - _hashCode += getValor().hashCode();  
134 - }  
135 - if (getIdOrigem() != null) {  
136 - _hashCode += getIdOrigem().hashCode();  
137 - }  
138 - __hashCodeCalc = false;  
139 - return _hashCode;  
140 - }  
141 -  
142 - // Type metadata  
143 - private static org.apache.axis.description.TypeDesc typeDesc =  
144 - new org.apache.axis.description.TypeDesc(AtributoAndamento.class, true);  
145 -  
146 - static {  
147 - typeDesc.setXmlType(new javax.xml.namespace.QName("Sei", "AtributoAndamento"));  
148 - org.apache.axis.description.ElementDesc elemField = new org.apache.axis.description.ElementDesc();  
149 - elemField.setFieldName("nome");  
150 - elemField.setXmlName(new javax.xml.namespace.QName("", "Nome"));  
151 - elemField.setXmlType(new javax.xml.namespace.QName("http://www.w3.org/2001/XMLSchema", "string"));  
152 - elemField.setNillable(false);  
153 - typeDesc.addFieldDesc(elemField);  
154 - elemField = new org.apache.axis.description.ElementDesc();  
155 - elemField.setFieldName("valor");  
156 - elemField.setXmlName(new javax.xml.namespace.QName("", "Valor"));  
157 - elemField.setXmlType(new javax.xml.namespace.QName("http://www.w3.org/2001/XMLSchema", "string"));  
158 - elemField.setNillable(false);  
159 - typeDesc.addFieldDesc(elemField);  
160 - elemField = new org.apache.axis.description.ElementDesc();  
161 - elemField.setFieldName("idOrigem");  
162 - elemField.setXmlName(new javax.xml.namespace.QName("", "IdOrigem"));  
163 - elemField.setXmlType(new javax.xml.namespace.QName("http://www.w3.org/2001/XMLSchema", "string"));  
164 - elemField.setNillable(true);  
165 - typeDesc.addFieldDesc(elemField);  
166 - }  
167 -  
168 - /**  
169 - * Return type metadata object  
170 - */  
171 - public static org.apache.axis.description.TypeDesc getTypeDesc() {  
172 - return typeDesc;  
173 - }  
174 -  
175 - /**  
176 - * Get Custom Serializer  
177 - */  
178 - public static org.apache.axis.encoding.Serializer getSerializer(  
179 - java.lang.String mechType,  
180 - java.lang.Class _javaType,  
181 - javax.xml.namespace.QName _xmlType) {  
182 - return  
183 - new org.apache.axis.encoding.ser.BeanSerializer(  
184 - _javaType, _xmlType, typeDesc);  
185 - }  
186 -  
187 - /**  
188 - * Get Custom Deserializer  
189 - */  
190 - public static org.apache.axis.encoding.Deserializer getDeserializer(  
191 - java.lang.String mechType,  
192 - java.lang.Class _javaType,  
193 - javax.xml.namespace.QName _xmlType) {  
194 - return  
195 - new org.apache.axis.encoding.ser.BeanDeserializer(  
196 - _javaType, _xmlType, typeDesc);  
197 - } 18 +public class AtributoAndamento implements java.io.Serializable {
  19 + private java.lang.String nome;
  20 +
  21 + private java.lang.String valor;
  22 +
  23 + private java.lang.String idOrigem;
  24 +
  25 + public AtributoAndamento() {
  26 + }
  27 +
  28 + public AtributoAndamento(String nome, String valor) {
  29 + this.nome = nome;
  30 + this.valor = valor;
  31 + }
  32 +
  33 + public AtributoAndamento(java.lang.String nome, java.lang.String valor, java.lang.String idOrigem) {
  34 + this.nome = nome;
  35 + this.valor = valor;
  36 + this.idOrigem = idOrigem;
  37 + }
  38 +
  39 + /**
  40 + * Gets the nome value for this AtributoAndamento.
  41 + *
  42 + * @return nome
  43 + */
  44 + public java.lang.String getNome() {
  45 + return nome;
  46 + }
  47 +
  48 + /**
  49 + * Sets the nome value for this AtributoAndamento.
  50 + *
  51 + * @param nome
  52 + */
  53 + public void setNome(java.lang.String nome) {
  54 + this.nome = nome;
  55 + }
  56 +
  57 + /**
  58 + * Gets the valor value for this AtributoAndamento.
  59 + *
  60 + * @return valor
  61 + */
  62 + public java.lang.String getValor() {
  63 + return valor;
  64 + }
  65 +
  66 + /**
  67 + * Sets the valor value for this AtributoAndamento.
  68 + *
  69 + * @param valor
  70 + */
  71 + public void setValor(java.lang.String valor) {
  72 + this.valor = valor;
  73 + }
  74 +
  75 + /**
  76 + * Gets the idOrigem value for this AtributoAndamento.
  77 + *
  78 + * @return idOrigem
  79 + */
  80 + public java.lang.String getIdOrigem() {
  81 + return idOrigem;
  82 + }
  83 +
  84 + /**
  85 + * Sets the idOrigem value for this AtributoAndamento.
  86 + *
  87 + * @param idOrigem
  88 + */
  89 + public void setIdOrigem(java.lang.String idOrigem) {
  90 + this.idOrigem = idOrigem;
  91 + }
  92 +
  93 + private java.lang.Object __equalsCalc = null;
  94 +
  95 + public boolean equals(java.lang.Object obj) {
  96 + if (!(obj instanceof AtributoAndamento))
  97 + return false;
  98 + AtributoAndamento other = (AtributoAndamento) obj;
  99 + if (obj == null)
  100 + return false;
  101 + if (this == obj)
  102 + return true;
  103 + if (__equalsCalc != null) {
  104 + return (__equalsCalc == obj);
  105 + }
  106 + __equalsCalc = obj;
  107 + boolean _equals;
  108 + _equals = true
  109 + && ((this.nome == null && other.getNome() == null)
  110 + || (this.nome != null && this.nome.equals(other.getNome())))
  111 + && ((this.valor == null && other.getValor() == null)
  112 + || (this.valor != null && this.valor.equals(other.getValor())))
  113 + && ((this.idOrigem == null && other.getIdOrigem() == null)
  114 + || (this.idOrigem != null && this.idOrigem.equals(other.getIdOrigem())));
  115 + __equalsCalc = null;
  116 + return _equals;
  117 + }
  118 +
  119 + private boolean __hashCodeCalc = false;
  120 +
  121 + public int hashCode() {
  122 + if (__hashCodeCalc) {
  123 + return 0;
  124 + }
  125 + __hashCodeCalc = true;
  126 + int _hashCode = 1;
  127 + if (getNome() != null) {
  128 + _hashCode += getNome().hashCode();
  129 + }
  130 + if (getValor() != null) {
  131 + _hashCode += getValor().hashCode();
  132 + }
  133 + if (getIdOrigem() != null) {
  134 + _hashCode += getIdOrigem().hashCode();
  135 + }
  136 + __hashCodeCalc = false;
  137 + return _hashCode;
  138 + }
  139 +
  140 + // Type metadata
  141 + private static org.apache.axis.description.TypeDesc typeDesc = new org.apache.axis.description.TypeDesc(
  142 + AtributoAndamento.class, true);
  143 +
  144 + static {
  145 + typeDesc.setXmlType(new javax.xml.namespace.QName("Sei", "AtributoAndamento"));
  146 + org.apache.axis.description.ElementDesc elemField = new org.apache.axis.description.ElementDesc();
  147 + elemField.setFieldName("nome");
  148 + elemField.setXmlName(new javax.xml.namespace.QName("", "Nome"));
  149 + elemField.setXmlType(new javax.xml.namespace.QName("http://www.w3.org/2001/XMLSchema", "string"));
  150 + elemField.setNillable(false);
  151 + typeDesc.addFieldDesc(elemField);
  152 + elemField = new org.apache.axis.description.ElementDesc();
  153 + elemField.setFieldName("valor");
  154 + elemField.setXmlName(new javax.xml.namespace.QName("", "Valor"));
  155 + elemField.setXmlType(new javax.xml.namespace.QName("http://www.w3.org/2001/XMLSchema", "string"));
  156 + elemField.setNillable(false);
  157 + typeDesc.addFieldDesc(elemField);
  158 + elemField = new org.apache.axis.description.ElementDesc();
  159 + elemField.setFieldName("idOrigem");
  160 + elemField.setXmlName(new javax.xml.namespace.QName("", "IdOrigem"));
  161 + elemField.setXmlType(new javax.xml.namespace.QName("http://www.w3.org/2001/XMLSchema", "string"));
  162 + elemField.setNillable(true);
  163 + typeDesc.addFieldDesc(elemField);
  164 + }
  165 +
  166 + /**
  167 + * Return type metadata object
  168 + */
  169 + public static org.apache.axis.description.TypeDesc getTypeDesc() {
  170 + return typeDesc;
  171 + }
  172 +
  173 + /**
  174 + * Get Custom Serializer
  175 + */
  176 + public static org.apache.axis.encoding.Serializer getSerializer(java.lang.String mechType,
  177 + java.lang.Class _javaType, javax.xml.namespace.QName _xmlType) {
  178 + return new org.apache.axis.encoding.ser.BeanSerializer(_javaType, _xmlType, typeDesc);
  179 + }
  180 +
  181 + /**
  182 + * Get Custom Deserializer
  183 + */
  184 + public static org.apache.axis.encoding.Deserializer getDeserializer(java.lang.String mechType,
  185 + java.lang.Class _javaType, javax.xml.namespace.QName _xmlType) {
  186 + return new org.apache.axis.encoding.ser.BeanDeserializer(_javaType, _xmlType, typeDesc);
  187 + }
198 188
199 } 189 }
src/main/java/br/gov/ans/integracao/sei/rest/ProcessoResource.java
@@ -1374,18 +1374,11 @@ public class ProcessoResource { @@ -1374,18 +1374,11 @@ public class ProcessoResource {
1374 if(map.isEmpty()){ 1374 if(map.isEmpty()){
1375 return null; 1375 return null;
1376 } 1376 }
1377 - 1377 +
1378 List<AtributoAndamento> atributos = new ArrayList<AtributoAndamento>(); 1378 List<AtributoAndamento> atributos = new ArrayList<AtributoAndamento>();
1379 - Set<String> keySet = map.keySet();  
1380 -  
1381 - for(String key : keySet){  
1382 - AtributoAndamento atributo = new AtributoAndamento();  
1383 - atributo.setNome(key);  
1384 - atributo.setValor(map.get(key));  
1385 -  
1386 - atributos.add(atributo);  
1387 - }  
1388 1379
  1380 + map.forEach((k, v) -> atributos.add(new AtributoAndamento(k, v)));
  1381 +
1389 return atributos.toArray(new AtributoAndamento[atributos.size()]); 1382 return atributos.toArray(new AtributoAndamento[atributos.size()]);
1390 } 1383 }
1391 1384
src/main/java/br/gov/ans/integracao/sei/utils/ContatoHelper.java
@@ -23,7 +23,7 @@ import br.gov.ans.integracao.sei.modelo.enums.TipoPessoa; @@ -23,7 +23,7 @@ import br.gov.ans.integracao.sei.modelo.enums.TipoPessoa;
23 23
24 public class ContatoHelper { 24 public class ContatoHelper {
25 25
26 - private static DateFormat formatter = new SimpleDateFormat("dd/MM/yyyy"); 26 + private DateFormat formatter = new SimpleDateFormat("dd/MM/yyyy");
27 27
28 @Inject 28 @Inject
29 private ContatoDAO contatoDAO; 29 private ContatoDAO contatoDAO;
@@ -109,23 +109,6 @@ public class ContatoHelper { @@ -109,23 +109,6 @@ public class ContatoHelper {
109 } 109 }
110 } 110 }
111 111
112 -// private void preencherEnderecoAssociado(Pessoa pessoa, Contato contato) throws RemoteException, BusinessException, Exception{  
113 -// Endereco endereco = pessoa.getAssociado().getEndereco();  
114 -//  
115 -// contato.setEnderecoAssociado(concatenarNumero(endereco.getLogradouro(), endereco.getNumero()));  
116 -// contato.setComplementoAssociado(endereco.getComplemento());  
117 -// contato.setBairroAssociado(endereco.getBairro());  
118 -// contato.setCep(endereco.getCEP());  
119 -//  
120 -// if(StringUtils.isNotBlank(endereco.getCidade())){  
121 -// Cidade cidade = getCidade(endereco.getCidade());  
122 -//  
123 -// contato.setIdCidadeAssociado(cidade.getId().toString());  
124 -// contato.setIdEstadoAssociado(cidade.getEstado().getId().toString());  
125 -// contato.setIdPaisAssociado(cidade.getEstado().getIdPais());  
126 -// }  
127 -// }  
128 -  
129 private void preencherDadosAssociado(Pessoa pessoa, Contato contato) throws RemoteException, BusinessException, Exception{ 112 private void preencherDadosAssociado(Pessoa pessoa, Contato contato) throws RemoteException, BusinessException, Exception{
130 if(pessoa.getAssociado() == null){ 113 if(pessoa.getAssociado() == null){
131 contato.setSinEnderecoAssociado("N"); 114 contato.setSinEnderecoAssociado("N");
src/main/java/br/gov/ans/integracao/sei/utils/PessoaHelper.java
@@ -41,7 +41,7 @@ public class PessoaHelper { @@ -41,7 +41,7 @@ public class PessoaHelper {
41 @Inject 41 @Inject
42 private MessageUtils messages; 42 private MessageUtils messages;
43 43
44 - private static DateFormat formatter = new SimpleDateFormat("dd/MM/yyyy"); 44 + private DateFormat formatter = new SimpleDateFormat("dd/MM/yyyy");
45 45
46 public List<Pessoa> buildPessoa(Contato[] contatos) throws ParseException, BusinessException, IllegalAccessException, ResourceNotFoundException{ 46 public List<Pessoa> buildPessoa(Contato[] contatos) throws ParseException, BusinessException, IllegalAccessException, ResourceNotFoundException{
47 if(ArrayUtils.isNotEmpty(contatos)){ 47 if(ArrayUtils.isNotEmpty(contatos)){
src/main/java/br/gov/ans/integracao/sei/utils/Util.java
@@ -21,12 +21,8 @@ import org.codehaus.jackson.type.TypeReference; @@ -21,12 +21,8 @@ import org.codehaus.jackson.type.TypeReference;
21 import br.gov.ans.exceptions.BusinessException; 21 import br.gov.ans.exceptions.BusinessException;
22 22
23 public class Util { 23 public class Util {
24 - private static SimpleDateFormat dateFormater = new SimpleDateFormat("dd/MM/yyyy");  
25 -  
26 private static final String REGEX_SOMENTE_NUMEROS = "\\D+"; 24 private static final String REGEX_SOMENTE_NUMEROS = "\\D+";
27 -  
28 - private static Pattern pattern_ = Pattern.compile(Constantes.REGEX_MASCARA_PROCESSO, Pattern.CASE_INSENSITIVE | Pattern.DOTALL);  
29 - 25 +
30 public static String getSOuN(String valor){ 26 public static String getSOuN(String valor){
31 if("S".equals(valor) || "s".equals(valor)){ 27 if("S".equals(valor) || "s".equals(valor)){
32 return "S"; 28 return "S";
@@ -44,6 +40,8 @@ public class Util { @@ -44,6 +40,8 @@ public class Util {
44 } 40 }
45 41
46 public static String formatarData(Date data){ 42 public static String formatarData(Date data){
  43 + SimpleDateFormat dateFormater = new SimpleDateFormat("dd/MM/yyyy");
  44 +
47 if(data != null){ 45 if(data != null){
48 return dateFormater.format(data); 46 return dateFormater.format(data);
49 } 47 }
@@ -98,7 +96,7 @@ public class Util { @@ -98,7 +96,7 @@ public class Util {
98 96
99 public static boolean trueOrFalse(String valor){ 97 public static boolean trueOrFalse(String valor){
100 if(valor != null && valor.length() > 1){ 98 if(valor != null && valor.length() > 1){
101 - new Boolean(valor); 99 + return Boolean.valueOf(valor);
102 } 100 }
103 101
104 return ("1".equals(valor)); 102 return ("1".equals(valor));
src/main/java/br/gov/ans/integracao/sip/client/SIPSoapClient.java
@@ -20,7 +20,7 @@ public class SIPSoapClient { @@ -20,7 +20,7 @@ public class SIPSoapClient {
20 20
21 public Boolean replicarUsuario(String operacao, String codigoUsuario, String codigoOrgao, String login, String nome) throws IOException{ 21 public Boolean replicarUsuario(String operacao, String codigoUsuario, String codigoOrgao, String login, String nome) throws IOException{
22 22
23 - String msgRetorno = ""; 23 + StringBuffer msgRetorno = new StringBuffer("");
24 24
25 URL url = new URL(SERVICE_URL); 25 URL url = new URL(SERVICE_URL);
26 URLConnection conn = url.openConnection(); 26 URLConnection conn = url.openConnection();
@@ -56,14 +56,14 @@ public class SIPSoapClient { @@ -56,14 +56,14 @@ public class SIPSoapClient {
56 56
57 String inputLine; 57 String inputLine;
58 while ((inputLine = rd.readLine()) != null){ 58 while ((inputLine = rd.readLine()) != null){
59 - msgRetorno += inputLine; 59 + msgRetorno.append(inputLine);
60 } 60 }
61 61
62 wr.close(); 62 wr.close();
63 rd.close(); 63 rd.close();
64 conn.getInputStream().close(); 64 conn.getInputStream().close();
65 65
66 - if(msgRetorno.contains("\"xsd:boolean\">true")){ 66 + if(msgRetorno.toString().contains("\"xsd:boolean\">true")){
67 return true; 67 return true;
68 } 68 }
69 69