@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()); } }
@Delete @Path("/reports/{errorEntry.id}") @LoggedIn public void remove(ErrorEntry errorEntry) { errorEntry = errorEntryDAO.retrieve(errorEntry.getId()); if (loggedUser.getUser().equals(errorEntry.getSubmitter()) || loggedUser.getUser().getRole().getCanDeleteOtherUserErrorReport()) { if (LOG.isDebugEnabled()) { LOG.debug("errorEntry: " + errorEntry); } errorEntryLogic.remove(errorEntry); } else { LOG.info( "Unauthorized user tried to delete errorEntry: " + loggedUser.getUser() + " : " + errorEntry); } }
@Get @Path("/reports/{errorEntry.id}") public void details(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) { result.notFound(); return; } result .include("errorEntry", errorEntryFromDB) .include("processResultList", cogrooFacade.cachedProcessText(errorEntryFromDB.getText())) .include("priorities", Priority.values()) .include("states", State.values()); String title = "Problema Nº. " + errorEntryFromDB.getId() + ": " + errorEntryFromDB.getText(); String sender = "Enviado por: " + errorEntryFromDB.getSubmitter().getName(); String version = "Versão: " + errorEntryFromDB.getVersion().getVersion(); String creationDate = "Criado em: " + DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG) .format(errorEntryFromDB.getCreation()); String changeDate = "Modificado em: " + DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG) .format(errorEntryFromDB.getModified()); String type = "Tipo: "; String details = null; if (errorEntryFromDB.getOmission() == null) { type += "Intervenção indevida"; String rule = "Regra: " + errorEntryFromDB.getBadIntervention().getRule(); String classification = "Erro: " + messages.getString( errorEntryFromDB.getBadIntervention().getClassification().toString()); details = rule + "; " + classification; } else { type += "Omissão"; String category = "Categoria" + (errorEntryFromDB.getOmission().getCategory() == null ? " (personalizada): " + errorEntryFromDB.getOmission().getCustomCategory() : ": " + errorEntryFromDB.getOmission().getCategory()); String replaceBy = "Substituir por: " + errorEntryFromDB.getOmission().getReplaceBy(); details = category + "; " + replaceBy; } String description = sender + "; " + version + "; " + type + "; " + details + "; " + creationDate + "; " + changeDate; result .include("headerTitle", StringEscapeUtils.escapeHtml(title)) .include("headerDescription", StringEscapeUtils.escapeHtml(description)); }