Commit c4573b7dcad057bf794da74e7a91a457f6757f14
1 parent
3f73b7a0
Exists in
master
Serviço para avaliar url e salvar a avaliação.
Showing
5 changed files
with
12 additions
and
254 deletions
Show diff stats
src/main/java/br/com/ases/business/AvaliacaoBusiness.java
... | ... | @@ -16,8 +16,7 @@ import br.com.checker.emag.SummarizedOccurrence; |
16 | 16 | |
17 | 17 | public interface AvaliacaoBusiness { |
18 | 18 | Nota obterNota(List<SummarizedOccurrence> occurrences,String url, List<Entry<OccurrenceKey,List<Occurrence>>> mapaListaOcorrencias); |
19 | - Nota obterNotaEselo(Source html, String url, List<Entry<OccurrenceKey,List<Occurrence>>> mapaListaOcorrencias); | |
20 | - Nota obterNotaEseloSalvandoAvaliacao(Source html, String url, List<Entry<OccurrenceKey,List<Occurrence>>> mapaListaOcorrencias); | |
19 | + Nota obterNotaEselo(Source html, String url, List<Entry<OccurrenceKey,List<Occurrence>>> mapaListaOcorrencias, Boolean salvarAvaliacao); | |
21 | 20 | Map<OccurrenceKey,Map<String,List<Occurrence>>> retornarCriterios(Map<OccurrenceClassification,List<Occurrence>> resultadoAvaliacao); |
22 | 21 | List<Entry<OccurrenceKey,List<Occurrence>>> retornarCriteriosTeste(Map<OccurrenceClassification,List<Occurrence>> resultadoAvaliacao); |
23 | 22 | void initEseloProperties(ServletContext servletContext); | ... | ... |
src/main/java/br/com/ases/business/impl/AvaliacaoBusinessImpl.java
... | ... | @@ -142,8 +142,7 @@ public class AvaliacaoBusinessImpl implements AvaliacaoBusiness { |
142 | 142 | return qtdItens; |
143 | 143 | } |
144 | 144 | |
145 | - | |
146 | - public Nota obterNotaEseloSalvandoAvaliacao(Source documento, String url, List<Entry<OccurrenceKey, List<Occurrence>>> mapaListaOcorrencias) { | |
145 | + public Nota obterNotaEselo(Source documento, String url, List<Entry<OccurrenceKey, List<Occurrence>>> mapaListaOcorrencias, Boolean salvarAvaliacao) { | |
147 | 146 | Nota nota = null; |
148 | 147 | |
149 | 148 | List<String> elementosBuscar; |
... | ... | @@ -177,240 +176,12 @@ public class AvaliacaoBusinessImpl implements AvaliacaoBusiness { |
177 | 176 | |
178 | 177 | try { |
179 | 178 | |
180 | - WebChecker.PostParams postParams = WebChecker.from(this.eseloProperties.getUrl("urlServicoSalvandoAvaliacao")).withPostRequest(); | |
179 | + WebChecker.PostParams postParams = WebChecker.from(this.eseloProperties.getUrl("url")).withPostRequest(); | |
181 | 180 | |
182 | 181 | // Relatorio de Avaliacao |
183 | - postParams.addParam("relatorioAvaliacao.date", new Date().toString()).addParam("relatorioAvaliacao.url", url); | |
184 | - | |
185 | - while ((linha = reader.readLine()) != null) { | |
186 | - | |
187 | - elementosBuscar = new ArrayList<String>(); | |
188 | - atributosBuscar = new ArrayList<String>(); | |
189 | - | |
190 | - | |
191 | - //Separa a chave do valor (tipo de teste) | |
192 | - chaveValor = linha.split("\\="); | |
193 | - | |
194 | - //chave do arquivo testeEselo.properties sendo (x.y.z) | |
195 | - recomendacaoCriterio = chaveValor[0].split("\\."); | |
196 | - | |
197 | - //Separa a recomenda��o do crit�rio sendo (x.y) de (x.y.z) | |
198 | - recomendacaoProperties = recomendacaoCriterio[0].toString() + "." + recomendacaoCriterio[1].toString(); | |
199 | - | |
200 | - //Separa a crit�rio da recomenda��o sendo (z) de (x.y.z) | |
201 | - criterioProperties = recomendacaoCriterio[2]; | |
202 | - | |
203 | - | |
204 | - if (!recomendacaoProperties.equalsIgnoreCase(recomendacaoAntiga) || recomendacaoAntiga.equalsIgnoreCase("")) { | |
205 | - | |
206 | - if(lsRecomendacaoCriterios.size() > 0) | |
207 | - { | |
208 | - countReq++; | |
209 | - countCriterio = 0; | |
210 | - postParams.addParam("relatorioAvaliacao.recomendacoes["+ countReq + "].idRecomendacao", retornaRecomendacaoEselo(recomendacaoAntiga)); | |
211 | - | |
212 | - for (RecomendacaoCriterios recCriterio : lsRecomendacaoCriterios) { | |
213 | - countCriterio++; | |
214 | - postParams.addParam("relatorioAvaliacao.recomendacoes["+countReq+"].criterios["+countCriterio+"].idCriterio",recCriterio.criterio) | |
215 | - .addParam("relatorioAvaliacao.recomendacoes["+ countReq +"].criterios["+countCriterio+"].qtdeErros", Integer.toString(recCriterio.qtdErros)) | |
216 | - .addParam("relatorioAvaliacao.recomendacoes["+ countReq +"].criterios["+countCriterio+"].qtdeItens",Integer.toString(recCriterio.qtdItens)); | |
217 | - } | |
218 | - | |
219 | - postParams.addParam("relatorioAvaliacao.recomendacoes[" + countReq + "].totalErros", Integer.toString(totalErros)); | |
220 | - postParams.addParam("relatorioAvaliacao.recomendacoes[" + countReq + "].totalAvisos", Integer.toString(totalAvisos)); | |
221 | - | |
222 | - totalAvisos = 0; | |
223 | - totalErros = 0; | |
224 | - lsRecomendacaoCriterios = new ArrayList<RecomendacaoCriterios>(); | |
225 | - } | |
226 | - else | |
227 | - { | |
228 | - totalAvisos = 0; | |
229 | - totalErros = 0; | |
230 | - } | |
231 | - | |
232 | - | |
233 | - | |
234 | - recomendacaoAntiga = recomendacaoProperties; | |
235 | - | |
236 | - } | |
237 | - | |
238 | - // Fim adiciona a recomenda��o da lista do properties | |
239 | - | |
240 | - | |
241 | - //Cria lista a ser pesquisada e retorna a quantidade de itens | |
242 | - tipoTeste = chaveValor[1].toString(); | |
243 | - tipoBusca = chaveValor[3].toString(); | |
244 | - isErro = Boolean.parseBoolean(chaveValor[2]); | |
245 | - | |
246 | - if(!tipoTeste.equalsIgnoreCase("proporcional")) | |
247 | - { | |
248 | - tipoBusca = "startTag"; | |
249 | - } | |
250 | - else | |
251 | - { | |
252 | - | |
253 | - if(tipoBusca.equalsIgnoreCase("e")) | |
254 | - { | |
255 | - countChave= 0; | |
256 | - | |
257 | - for (String chave : chaveValor) { | |
258 | - if(countChave >= 3) | |
259 | - { | |
260 | - elementosBuscar.add(chave); | |
261 | - } | |
262 | - countChave++; | |
263 | - } | |
264 | - }else if(tipoBusca.equalsIgnoreCase("a")) | |
265 | - { | |
266 | - countChave= 0; | |
267 | - for (String chave : chaveValor) { | |
268 | - if(countChave >= 3) | |
269 | - { | |
270 | - atributosBuscar.add(chave); | |
271 | - } | |
272 | - countChave++; | |
273 | - } | |
274 | - }else if(tipoBusca.equalsIgnoreCase("ea")) | |
275 | - { | |
276 | - countChave= 0; | |
277 | - for (String chave : chaveValor) { | |
278 | - if(countChave >= 3) | |
279 | - { | |
280 | - if(chave.substring(0,1).equalsIgnoreCase("e")) | |
281 | - { | |
282 | - elementosBuscar.add(chave.substring(1,(chave.length()))); | |
283 | - } | |
284 | - else if(chave.substring(0,1).equalsIgnoreCase("a")) | |
285 | - { | |
286 | - atributosBuscar.add(chave.substring(1,(chave.length()))); | |
287 | - } | |
288 | - } | |
289 | - | |
290 | - countChave++; | |
291 | - } | |
292 | - } | |
293 | - } | |
294 | - //Fim Cria lista a ser pesquisada e retorna a quantidade de itens | |
295 | - | |
296 | - if(!tipoBusca.equalsIgnoreCase("1") && !tipoTeste.equalsIgnoreCase("decrescente")) | |
297 | - { | |
298 | - qtdItens = retornarQuantidadeItens(documento, elementosBuscar, atributosBuscar,tipoBusca); | |
299 | - }else if(!tipoBusca.equalsIgnoreCase("1") && tipoTeste.equalsIgnoreCase("decrescente")) | |
300 | - { | |
301 | - qtdItens = totalLinhas; | |
302 | - } | |
303 | - else | |
304 | - { | |
305 | - qtdItens = 1; | |
306 | - } | |
307 | - | |
308 | - | |
309 | - | |
310 | - qtdErrosAvisos = retornaQuantidadeErrosAvisos(mapaListaOcorrencias, recomendacaoProperties, criterioProperties); | |
311 | - | |
312 | - | |
313 | - if(isErro) | |
314 | - { | |
315 | - totalErros = totalErros + qtdErrosAvisos; | |
316 | - } | |
317 | - else | |
318 | - { | |
319 | - totalAvisos = totalAvisos + qtdErrosAvisos; | |
320 | - } | |
321 | - | |
322 | - recomendacaoAdd = new RecomendacaoCriterios(); | |
323 | - | |
324 | - if(qtdItens > 0 || !tipoTeste.equalsIgnoreCase("proporcional")) | |
325 | - { | |
326 | - | |
327 | - recomendacaoAdd.setCriterio(criterioProperties); | |
328 | - recomendacaoAdd.setQtdErros(qtdErrosAvisos); | |
329 | - recomendacaoAdd.setQtdItens(qtdItens); | |
330 | - lsRecomendacaoCriterios.add(recomendacaoAdd); | |
331 | - } | |
332 | - | |
333 | - } | |
334 | - | |
335 | - if(lsRecomendacaoCriterios.size() > 0) | |
336 | - { | |
337 | - countReq++; | |
338 | - countCriterio = 0; | |
339 | - postParams.addParam("relatorioAvaliacao.recomendacoes["+ countReq + "].idRecomendacao", retornaRecomendacaoEselo(recomendacaoAntiga)); | |
340 | - | |
341 | - for (RecomendacaoCriterios recCriterio : lsRecomendacaoCriterios) { | |
342 | - countCriterio++; | |
343 | - postParams.addParam("relatorioAvaliacao.recomendacoes["+countReq+"].criterios["+countCriterio+"].idCriterio",recCriterio.criterio) | |
344 | - .addParam("relatorioAvaliacao.recomendacoes["+countReq+"].criterios["+countCriterio+"].qtdeErros", Integer.toString(recCriterio.qtdErros)) | |
345 | - .addParam("relatorioAvaliacao.recomendacoes["+countReq+"].criterios["+countCriterio+"].qtdeItens",Integer.toString(recCriterio.qtdItens)); | |
346 | - | |
347 | - } | |
348 | - | |
349 | - postParams.addParam("relatorioAvaliacao.recomendacoes[" + countReq+ "].totalErros", Integer.toString(totalErros)); | |
350 | - postParams.addParam("relatorioAvaliacao.recomendacoes[" + countReq+ "].totalAvisos", Integer.toString(totalAvisos)); | |
351 | - | |
352 | - totalAvisos = 0; | |
353 | - totalErros = 0; | |
354 | - lsRecomendacaoCriterios = new ArrayList<RecomendacaoCriterios>(); | |
355 | - | |
356 | - } | |
357 | - //postParams.addParam("relatorioAvaliacao.recomendacoes[" + countReq+ "].totalErros", Integer.toString(totalErros)); | |
358 | - //postParams.addParam("relatorioAvaliacao.recomendacoes[" + countReq+ "].totalAvisos", Integer.toString(totalAvisos)); | |
359 | - postParams.addParam("relatorioAvaliacao.qtdeLinhas", Integer.toString(totalLinhas)); | |
360 | - | |
361 | - Gson g = new GsonBuilder().create(); | |
362 | - nota = g.fromJson(postParams.execute().getContent(), Nota.class); | |
182 | + postParams.addParam("relatorioAvaliacao.date", new Date().toString()).addParam("relatorioAvaliacao.url", url).addParam("salvarAvaliacao", salvarAvaliacao.toString()); | |
363 | 183 | |
364 | 184 | |
365 | - } catch (IOException e) { | |
366 | - | |
367 | - e.printStackTrace(); | |
368 | - } | |
369 | - | |
370 | - return nota; | |
371 | - | |
372 | - } | |
373 | - | |
374 | - | |
375 | - public Nota obterNotaEselo(Source documento, String url, List<Entry<OccurrenceKey, List<Occurrence>>> mapaListaOcorrencias) { | |
376 | - Nota nota = null; | |
377 | - | |
378 | - List<String> elementosBuscar; | |
379 | - List<String> atributosBuscar; | |
380 | - | |
381 | - List<RecomendacaoCriterios> lsRecomendacaoCriterios = new ArrayList<RecomendacaoCriterios>(); | |
382 | - RecomendacaoCriterios recomendacaoAdd; | |
383 | - | |
384 | - BufferedReader reader = testeEseloProperties.getListaTesteEselo(); | |
385 | - String linha = ""; | |
386 | - String[] chaveValor; | |
387 | - String recomendacaoProperties = ""; | |
388 | - String recomendacaoAntiga = ""; // Serve identificar a mudan�a de recomenda��o | |
389 | - //String recomendacao = ""; | |
390 | - String criterioProperties = ""; | |
391 | - //String criterio = ""; | |
392 | - //String criterioAntido = ""; | |
393 | - String recomendacaoCriterio[]; | |
394 | - String tipoTeste = ""; | |
395 | - String tipoBusca = ""; | |
396 | - Integer totalLinhas = (documento != null? documento.toString().split("\n").length: 0); | |
397 | - Integer qtdErrosAvisos = 0; | |
398 | - Integer countReq = 0; | |
399 | - Integer countCriterio = 0; | |
400 | - Integer countChave = 0; | |
401 | - Integer qtdItens = 0; | |
402 | - Integer totalErros = 0; | |
403 | - Integer totalAvisos = 0; | |
404 | - Boolean isErro; | |
405 | - //Boolean recomendacaoTemCriterio = false; | |
406 | - | |
407 | - try { | |
408 | - | |
409 | - WebChecker.PostParams postParams = WebChecker.from(this.eseloProperties.getUrl("url")).withPostRequest(); | |
410 | - | |
411 | - // Relatorio de Avaliacao | |
412 | - postParams.addParam("relatorioAvaliacao.date", new Date().toString()).addParam("relatorioAvaliacao.url", url); | |
413 | - | |
414 | 185 | while ((linha = reader.readLine()) != null) { |
415 | 186 | |
416 | 187 | elementosBuscar = new ArrayList<String>(); | ... | ... |
src/main/java/br/com/ases/controller/AvaliacaoController.java
... | ... | @@ -207,7 +207,7 @@ public class AvaliacaoController { |
207 | 207 | // mapaListaOcorrencias); |
208 | 208 | nota = |
209 | 209 | avaliacaoBusiness.obterNotaEselo(checker.getDocument(), file.getFileName(), |
210 | - mapaListaOcorrencias); | |
210 | + mapaListaOcorrencias, false); | |
211 | 211 | // Altera a cor de webaxscore de acordo a pontuacao |
212 | 212 | |
213 | 213 | if (nota.getValor() != null) { |
... | ... | @@ -379,7 +379,7 @@ public class AvaliacaoController { |
379 | 379 | // Altera a cor de webaxscore de acordo a pontuacao |
380 | 380 | // nota = avaliacaoBusiness.obterNota(checker.checkSumarized(), url, mapaListaOcorrencias); |
381 | 381 | |
382 | - nota = avaliacaoBusiness.obterNotaEselo(checker.getDocument(), url, mapaListaOcorrencias); | |
382 | + nota = avaliacaoBusiness.obterNotaEselo(checker.getDocument(), url, mapaListaOcorrencias, false); | |
383 | 383 | |
384 | 384 | if (nota.getValor() != null) { |
385 | 385 | DefinirCorWebaxscore(nota.getValor()); |
... | ... | @@ -640,7 +640,7 @@ public class AvaliacaoController { |
640 | 640 | avaliacaoBusiness.retornarCriteriosTeste(checker.check()); |
641 | 641 | nota = |
642 | 642 | avaliacaoBusiness.obterNotaEselo(checker.getDocument(), |
643 | - tituloSite + " - " + sdf.format(new Date()), mapaListaOcorrencias); | |
643 | + tituloSite + " - " + sdf.format(new Date()), mapaListaOcorrencias, false); | |
644 | 644 | // Altera a cor de webaxscore de acordo a pontuacao |
645 | 645 | |
646 | 646 | if (nota.getValor() != null) { |
... | ... | @@ -967,15 +967,7 @@ public class AvaliacaoController { |
967 | 967 | ErroWs erroWs = new ErroWs(); |
968 | 968 | this.dataHoraAvaliacao = (String) DateUtil.dataHoraAtual(); |
969 | 969 | |
970 | - /* | |
971 | - WebChecker.PostParams postParams = | |
972 | - WebChecker.from(this.eseloProperties.getUrl("urlAutenticacaoServico")).withPostRequest(); | |
973 | - postParams.addParam("codigoHash", codigoHash); | |
974 | - | |
975 | - Gson g = new GsonBuilder().create(); | |
976 | 970 | |
977 | - Boolean usuarioAutorizado = g.fromJson(postParams.execute().getContent(), Boolean.class); | |
978 | -*/ | |
979 | 971 | try { |
980 | 972 | |
981 | 973 | Validate validate = new Validate(this.validator); |
... | ... | @@ -1018,16 +1010,11 @@ public class AvaliacaoController { |
1018 | 1010 | avaliacaoBusiness.retornarCriteriosTeste(checker.check()); |
1019 | 1011 | |
1020 | 1012 | nota = |
1021 | - avaliacaoBusiness.obterNotaEseloSalvandoAvaliacao(checker.getDocument(), url, mapaListaOcorrencias); | |
1022 | - | |
1023 | - | |
1024 | - | |
1013 | + avaliacaoBusiness.obterNotaEselo(checker.getDocument(), url, mapaListaOcorrencias, true); | |
1025 | 1014 | if(nota != null) |
1026 | 1015 | { |
1027 | 1016 | retornoNota = true; |
1028 | 1017 | } |
1029 | - | |
1030 | - | |
1031 | 1018 | |
1032 | 1019 | } |
1033 | 1020 | |
... | ... | @@ -1147,7 +1134,7 @@ public class AvaliacaoController { |
1147 | 1134 | avaliacaoBusiness.retornarCriteriosTeste(checker.check()); |
1148 | 1135 | |
1149 | 1136 | nota = |
1150 | - avaliacaoBusiness.obterNotaEselo(checker.getDocument(), url, mapaListaOcorrencias); | |
1137 | + avaliacaoBusiness.obterNotaEselo(checker.getDocument(), url, mapaListaOcorrencias, false); | |
1151 | 1138 | |
1152 | 1139 | this.sumarizarResultasNoResponse(checker.checkSumarized(), result); |
1153 | 1140 | ... | ... |
src/main/java/br/com/ases/infra/WebChecker.java
src/main/java/br/com/ases/model/utilities/Validate.java
... | ... | @@ -116,7 +116,7 @@ public class Validate { |
116 | 116 | |
117 | 117 | try { |
118 | 118 | |
119 | - UrlConvertida = new URL(campo); | |
119 | + //UrlConvertida = new URL(campo); | |
120 | 120 | |
121 | 121 | clienteHTTPJakartaCommons = new HttpClient(); |
122 | 122 | clienteHTTPJakartaCommons.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, |
... | ... | @@ -124,7 +124,7 @@ public class Validate { |
124 | 124 | clienteHTTPJakartaCommons.getParams().setParameter("http.protocol.allow-circular-redirects", |
125 | 125 | true); |
126 | 126 | |
127 | - metodoRequisicaoGET = new GetMethod(UrlConvertida.toExternalForm()); | |
127 | + metodoRequisicaoGET = new GetMethod(campo);//UrlConvertida.toExternalForm()); | |
128 | 128 | |
129 | 129 | metodoRequisicaoGET.setRequestHeader(usuario, agente); |
130 | 130 | metodoRequisicaoGET.setFollowRedirects(true); | ... | ... |