Commit 3f73b7a09e90c52dced54d376585d89b5bdea7fe
1 parent
dbc1f32c
Exists in
master
WebService para avaliação de url a consimir pelo eselo.
Showing
4 changed files
with
320 additions
and
3 deletions
Show diff stats
src/main/java/br/com/ases/business/AvaliacaoBusiness.java
... | ... | @@ -17,6 +17,7 @@ import br.com.checker.emag.SummarizedOccurrence; |
17 | 17 | public interface AvaliacaoBusiness { |
18 | 18 | Nota obterNota(List<SummarizedOccurrence> occurrences,String url, List<Entry<OccurrenceKey,List<Occurrence>>> mapaListaOcorrencias); |
19 | 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); | |
20 | 21 | Map<OccurrenceKey,Map<String,List<Occurrence>>> retornarCriterios(Map<OccurrenceClassification,List<Occurrence>> resultadoAvaliacao); |
21 | 22 | List<Entry<OccurrenceKey,List<Occurrence>>> retornarCriteriosTeste(Map<OccurrenceClassification,List<Occurrence>> resultadoAvaliacao); |
22 | 23 | void initEseloProperties(ServletContext servletContext); | ... | ... |
src/main/java/br/com/ases/business/impl/AvaliacaoBusinessImpl.java
... | ... | @@ -143,6 +143,234 @@ public class AvaliacaoBusinessImpl implements AvaliacaoBusiness { |
143 | 143 | } |
144 | 144 | |
145 | 145 | |
146 | + public Nota obterNotaEseloSalvandoAvaliacao(Source documento, String url, List<Entry<OccurrenceKey, List<Occurrence>>> mapaListaOcorrencias) { | |
147 | + Nota nota = null; | |
148 | + | |
149 | + List<String> elementosBuscar; | |
150 | + List<String> atributosBuscar; | |
151 | + | |
152 | + List<RecomendacaoCriterios> lsRecomendacaoCriterios = new ArrayList<RecomendacaoCriterios>(); | |
153 | + RecomendacaoCriterios recomendacaoAdd; | |
154 | + | |
155 | + BufferedReader reader = testeEseloProperties.getListaTesteEselo(); | |
156 | + String linha = ""; | |
157 | + String[] chaveValor; | |
158 | + String recomendacaoProperties = ""; | |
159 | + String recomendacaoAntiga = ""; // Serve identificar a mudan�a de recomenda��o | |
160 | + //String recomendacao = ""; | |
161 | + String criterioProperties = ""; | |
162 | + //String criterio = ""; | |
163 | + //String criterioAntido = ""; | |
164 | + String recomendacaoCriterio[]; | |
165 | + String tipoTeste = ""; | |
166 | + String tipoBusca = ""; | |
167 | + Integer totalLinhas = (documento != null? documento.toString().split("\n").length: 0); | |
168 | + Integer qtdErrosAvisos = 0; | |
169 | + Integer countReq = 0; | |
170 | + Integer countCriterio = 0; | |
171 | + Integer countChave = 0; | |
172 | + Integer qtdItens = 0; | |
173 | + Integer totalErros = 0; | |
174 | + Integer totalAvisos = 0; | |
175 | + Boolean isErro; | |
176 | + //Boolean recomendacaoTemCriterio = false; | |
177 | + | |
178 | + try { | |
179 | + | |
180 | + WebChecker.PostParams postParams = WebChecker.from(this.eseloProperties.getUrl("urlServicoSalvandoAvaliacao")).withPostRequest(); | |
181 | + | |
182 | + // 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); | |
363 | + | |
364 | + | |
365 | + } catch (IOException e) { | |
366 | + | |
367 | + e.printStackTrace(); | |
368 | + } | |
369 | + | |
370 | + return nota; | |
371 | + | |
372 | + } | |
373 | + | |
146 | 374 | |
147 | 375 | public Nota obterNotaEselo(Source documento, String url, List<Entry<OccurrenceKey, List<Occurrence>>> mapaListaOcorrencias) { |
148 | 376 | Nota nota = null; | ... | ... |
src/main/java/br/com/ases/controller/AvaliacaoController.java
... | ... | @@ -958,7 +958,94 @@ public class AvaliacaoController { |
958 | 958 | .setAttribute("mensagem_avaliacao", mensagem_avaliacao); |
959 | 959 | } |
960 | 960 | |
961 | + @Get("/servico-avaliacao-acessibilidade-salvando") | |
962 | + @Post("/servico-avaliacao-acessibilidade-salvando") | |
963 | + public void servicoAvaliacaoAcessibilidadeSalvando(@QueryParam("url") String url, | |
964 | + String codigoHash) { | |
965 | + | |
966 | + Boolean retornoNota = false; | |
967 | + ErroWs erroWs = new ErroWs(); | |
968 | + this.dataHoraAvaliacao = (String) DateUtil.dataHoraAtual(); | |
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 | + | |
977 | + Boolean usuarioAutorizado = g.fromJson(postParams.execute().getContent(), Boolean.class); | |
978 | +*/ | |
979 | + try { | |
980 | + | |
981 | + Validate validate = new Validate(this.validator); | |
982 | + | |
983 | + if (validate.url(url)) { | |
984 | + | |
985 | + if (url.startsWith("www")) { | |
986 | + url = "http://" + url; | |
987 | + } | |
988 | + | |
989 | + | |
990 | + WebChecker pagina = WebChecker.from(url).withGetRequest().execute(); | |
991 | + | |
992 | + int[] errorsWarningsCss = avaliacaoBusiness.getErrorCount(true, url); | |
993 | + int[] errorsWarningsHtml = avaliacaoBusiness.getErrorCount(false, url); | |
994 | + | |
995 | + Checker checker = from(pagina.getContent(), url); | |
996 | + | |
997 | + checker.with(marking()); | |
998 | + checker.with(content()); | |
999 | + checker.with(presentation()); | |
1000 | + checker.with(multimedia()); | |
1001 | + checker.with(form()); | |
1002 | + checker.with(behavior()); | |
961 | 1003 | |
1004 | + Pattern pp = Pattern.compile("(http://www.)?([a-z]*)(.)?"); | |
1005 | + Matcher mm = pp.matcher(url.toLowerCase().replace("https", "http")); | |
1006 | + | |
1007 | + if (mm.find()) { | |
1008 | + this.tituloSite = ""; | |
1009 | + } | |
1010 | + | |
1011 | + ContentEvaluation conteudo = new ContentEvaluation(checker.getDocument()); | |
1012 | + | |
1013 | + this.tituloSite = conteudo.retornarTituloSiteAvaliado(); | |
1014 | + | |
1015 | + Nota nota = null; | |
1016 | + | |
1017 | + List<Entry<OccurrenceKey, List<Occurrence>>> mapaListaOcorrencias = | |
1018 | + avaliacaoBusiness.retornarCriteriosTeste(checker.check()); | |
1019 | + | |
1020 | + nota = | |
1021 | + avaliacaoBusiness.obterNotaEseloSalvandoAvaliacao(checker.getDocument(), url, mapaListaOcorrencias); | |
1022 | + | |
1023 | + | |
1024 | + | |
1025 | + if(nota != null) | |
1026 | + { | |
1027 | + retornoNota = true; | |
1028 | + } | |
1029 | + | |
1030 | + | |
1031 | + | |
1032 | + } | |
1033 | + | |
1034 | + } catch (Exception e) { | |
1035 | + | |
1036 | + e.printStackTrace(); | |
1037 | + | |
1038 | + erroWs.setUrl(url); | |
1039 | + erroWs.setDataHora(this.dataHoraAvaliacao); | |
1040 | + | |
1041 | + List<String> mensagensErros = new ArrayList<String>(); | |
1042 | + | |
1043 | + mensagensErros.add(e.getMessage()); | |
1044 | + erroWs.setMensagem(mensagensErros); | |
1045 | + | |
1046 | + } | |
1047 | + result.use(Results.json()).withoutRoot().from(retornoNota).serialize(); | |
1048 | + } | |
962 | 1049 | |
963 | 1050 | @Get("/servico-avaliacao-acessibilidade") |
964 | 1051 | @Post("/servico-avaliacao-acessibilidade") | ... | ... |
src/main/webapp/WEB-INF/eselo.properties
1 | 1 | #url=https://sistemas-treinamento.ifbaiano.edu.br/intg_ases_selo/calcular-nota |
2 | -url=http://189.9.137.162:8080/eselo/calcular-nota | |
3 | -#urlAutenticacaoServico=http://189.9.137.162:8080/eselo//existe_usuario_servico_web | |
2 | +#url=http://189.9.137.162:8080/eselo/calcular-nota | |
3 | +url=http://localhost:18080/eselo/calcular-nota | |
4 | +urlServicoSalvandoAvaliacao=http://localhost:18080/eselo/calcular-nota-salvando-avaliacao | |
4 | 5 | urlAutenticacaoServico=http://localhost:18080/eselo/existe_usuario_servico_web |
5 | -#url=http://localhost:18080/eselo/calcular-nota | |
6 | +#urlAutenticacaoServico=http://localhost:18080/eselo/existe_usuario_servico_web | |
6 | 7 | |
7 | 8 | #Esconde a nota caso não esteja usando o ESELO |
8 | 9 | #Se atribuir o valor "sem_nota" na chave 'sem_nota', não exibirá a nota | ... | ... |