public void adiciona(Pessoa pessoa, Endereco endereco, List<NumeroTelefone> telefone) { if (pessoa.getNome() == null || pessoa.getNome().length() < 3) { validator.add( new ValidationMessage( "Nome é obrigatório e precisa ter mais de 3 letras", "pessoa.nome")); } if (telefone.get(0).getNumero() == null) { validator.add( new ValidationMessage("Pelo menos um telefone deverá ser cadastrado", "telefone.numero")); } validator.onErrorUsePageOf(PessoaController.class).formulario(); pessoa.setEndereco(endereco); enderecoBanco.inserirEnderecoBanco(endereco); pessoaBanco.inserirPessoaBanco(pessoa); for (NumeroTelefone tel : telefone) { if (tel != null) { tel.setPessoa(pessoa); telefoneBanco.inserirTelefoneBanco(tel); } } result.redirectTo(this).listaContatos(); }
private void CodeValidation(Code code, boolean create) { List<Code> codeList; validator.validate(code); code = WithoutBlankChar(code); if (code.getName().isEmpty()) validator.add(new ValidationMessage("Erro", "O campo Nome nao pode ser deixado em branco")); if (code.getTags().isEmpty()) validator.add(new ValidationMessage("Erro", "O campo Tags não pode ser deixado em branco")); if (code.getLang().isEmpty()) validator.add( new ValidationMessage("Erro", "Escolha uma linguagem para o codigo a ser cadastrado")); if (code.getSnippet().isEmpty()) validator.add( new ValidationMessage( "Erro", "O campo de texto do codigo não pode ser deixado em branco")); if (create) { codeList = repository.findByName(code.getName()); if (!codeList.isEmpty()) validator.add( new ValidationMessage( "Erro", "Nao pode haver dois codigos com o mesmo nome, insira um nome diferente")); } }
@Post @Path("/reports/{errorEntry.id}/comments") public void addComment(ErrorEntry errorEntry, String newComment) { newComment = sanitizer.sanitize(newComment, true); ErrorEntry errorEntryFromDB = errorEntryDAO.retrieve(new Long(errorEntry.getId())); LOG.debug("errorEntry: " + errorEntryFromDB); LOG.debug("newComment: " + newComment); if (newComment.trim().isEmpty()) { validator.add( new ValidationMessage( ExceptionMessages.COMMENT_SHOULD_NOT_BE_EMPTY, ExceptionMessages.ERROR)); validator .onErrorUse(Results.logic()) .redirectTo(ErrorReportController.class) .details(errorEntryFromDB); } else if (newComment.trim().length() > COMMENT_MAX_SIZE) { validator.add( new ValidationMessage( ExceptionMessages.COMMENT_SHOULD_NOT_EXCEED_CHAR, ExceptionMessages.ERROR)); validator .onErrorUse(Results.logic()) .redirectTo(ErrorReportController.class) .details(errorEntryFromDB); } else { errorEntryLogic.addCommentToErrorEntry( errorEntryFromDB.getId(), loggedUser.getUser().getId(), newComment); } result.include("gaEventCommentAdded", true); result.redirectTo(ErrorReportController.class).details(errorEntryFromDB); }
@Get @Path("/reports/{errorEntry.id}/edit") @LoggedIn public void editDetails(ErrorEntry errorEntry) { if (errorEntry == null) { result.redirectTo(getClass()).list(); return; } ErrorEntry errorEntryFromDB = errorEntryDAO.retrieve(new Long(errorEntry.getId())); LOG.debug("Details for: " + errorEntryFromDB); if (errorEntryFromDB == null) { validator.add( new ValidationMessage(ExceptionMessages.PAGE_NOT_FOUND, ExceptionMessages.ERROR)); validator.onErrorUse(Results.logic()).redirectTo(ErrorReportController.class).list(); } else if (!loggedUser.isLogged() || !loggedUser.getUser().getRole().getCanEditErrorReport()) { validator.add( new ValidationMessage(ExceptionMessages.USER_UNAUTHORIZED, ExceptionMessages.ERROR)); validator .onErrorUse(Results.logic()) .redirectTo(ErrorReportController.class) .details(errorEntryFromDB); } else { List<ProcessResult> procRes = cogrooFacade.processText(errorEntryFromDB.getText()); boolean hasError = false; for (ProcessResult processResult : procRes) { if (processResult.getMistakes().size() > 0) { hasError = true; break; } } result .include("errorEntry", errorEntryFromDB) .include("hasError", hasError) .include("processResultList", procRes) .include( "singleGrammarErrorList", cogrooFacade.asSingleGrammarErrorList(errorEntryFromDB.getText(), procRes)) .include("omissionCategoriesList", this.errorEntryLogic.getErrorCategoriesForUser()); } }
@Post("/login") public void login(Usuario usuario) { Usuario carrega = dao.carrega(usuario); if (carrega == null) { validator.add(new ValidationMessage("Login e/ou senha inválidos", "usuario.login")); } validator.onErrorUsePageOf(UsuariosController.class).loginForm(); usuarioWeb.login(carrega); result.redirectTo(ProdutosController.class).lista(); }
@Post("/login") public void login(Administrador usuario) { Administrador carregado = dao.carregar(usuario); if (carregado == null) { validator.add(new ValidationMessage("Login ou Senha Incorretos", "usuario")); } validator.onErrorUsePageOf(this).loginForm(); userinfo.login(carregado); result.redirectTo(UsertwitterController.class).lista(); }
@Post("/usuarios") public void adiciona(Usuario usuario) { if (dao.existeUsuario(usuario)) { validator.add(new ValidationMessage("Login já existe", "usuario.login")); } validator.onErrorUsePageOf(UsuariosController.class).novo(); dao.adiciona(usuario); result.redirectTo(ProdutosController.class).lista(); }
@Put @Path("/reports/{reportId}") @LoggedIn public void updateErrorReport( Long reportId, String type, String badintIndex, String badintType, List<String> badintStart, List<String> badintEnd, List<String> badintRule, String omissionCategory, String omissionCustom, String omissionReplaceBy, String omissionStart, String omissionEnd) { LOG.debug( "reportId: " + reportId + "\n" + "type: " + type + "\n" + "badintIndex: " + badintIndex + "\n" + "badintType: " + badintType + "\n" + "badintStart: " + badintStart + "\n" + "badintEnd: " + badintEnd + "\n" + "badintRule: " + badintRule + "\n" + "omissionCategory: " + omissionCategory + "\n" + "omissionCustom: " + omissionCustom + "\n" + "omissionReplaceBy: " + omissionReplaceBy + "\n" + "omissionStart: " + omissionStart + "\n" + "omissionEnd: " + omissionEnd); ErrorEntry errorEntryFromDB = this.errorEntryDAO.retrieve(reportId); ErrorEntry originalErrorEntry = null; try { originalErrorEntry = (ErrorEntry) errorEntryFromDB.clone(); } catch (CloneNotSupportedException e) { LOG.error("Error cloning ErrorEntry object: ", e); } if (type == null) { if (errorEntryFromDB.getBadIntervention() != null) { type = "BADINT"; } else { type = "OMISSION"; } } if (type.equals("BADINT")) { GrammarCheckerBadIntervention newBadIntervention = null; if (errorEntryFromDB.getBadIntervention() == null) { newBadIntervention = new GrammarCheckerBadIntervention(); errorEntryFromDB.setBadIntervention(newBadIntervention); } else { newBadIntervention = errorEntryFromDB.getBadIntervention(); } newBadIntervention.setClassification( Enum.valueOf(BadInterventionClassification.class, badintType)); newBadIntervention.setErrorEntry(errorEntryFromDB); newBadIntervention.setRule(badintRule.get(Integer.valueOf(badintIndex) - 1)); errorEntryFromDB.setSpanStart( Integer.valueOf(badintStart.get(Integer.valueOf(badintIndex) - 1))); errorEntryFromDB.setSpanEnd(Integer.valueOf(badintEnd.get(Integer.valueOf(badintIndex) - 1))); this.errorEntryLogic.updateBadIntervention(errorEntryFromDB, originalErrorEntry); } else { int start = -1; int end = -1; if (omissionStart != null && omissionEnd != null) { start = Integer.parseInt(omissionStart); end = Integer.parseInt(omissionEnd); } GrammarCheckerOmission o = null; if (errorEntryFromDB.getOmission() == null) { o = new GrammarCheckerOmission(); errorEntryFromDB.setOmission(o); } else { o = errorEntryFromDB.getOmission(); } o.setCategory(omissionCategory); if (omissionCategory.equals(ErrorEntryLogic.CUSTOM)) { o.setCustomCategory(sanitizer.sanitize(omissionCustom, false)); } else { o.setCustomCategory(null); } o.setErrorEntry(errorEntryFromDB); o.setReplaceBy(sanitizer.sanitize(omissionReplaceBy, false)); errorEntryFromDB.setSpanStart(start); errorEntryFromDB.setSpanEnd(end); if (!(end > 0 && end > start)) { validator.add( new ValidationMessage( ExceptionMessages.ERROR_REPORT_OMISSION_INVALID_SELECTION, ExceptionMessages.ERROR)); } if (omissionCategory.equals("custom") && (omissionCustom == null || omissionCustom.length() == 0)) { validator.add( new ValidationMessage( ExceptionMessages.ERROR_REPORT_OMISSION_MISSING_CUSTOM_CATEGORY, ExceptionMessages.ERROR)); } if ((omissionReplaceBy == null || omissionReplaceBy.length() == 0)) { validator.add( new ValidationMessage( ExceptionMessages.ERROR_REPORT_OMISSION_MISSING_REPLACE, ExceptionMessages.ERROR)); } if (validator.hasErrors()) { validator .onErrorUse(Results.logic()) .redirectTo(ErrorReportController.class) .editDetails(errorEntryFromDB); return; } this.errorEntryLogic.updateOmission(errorEntryFromDB, originalErrorEntry); } result.include("gaEventErrorChanged", true); result.redirectTo(getClass()).details(errorEntryFromDB); }