From cdccba566aa6b5187adb59a2b841cb034a8d89cd Mon Sep 17 00:00:00 2001 From: Fabiano Sluzarski <fs09@inf.ufpr.br> Date: Wed, 6 Feb 2013 11:46:31 -0200 Subject: [PATCH] =?UTF-8?q?seguran=C3=A7a=20adicionada?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../br/ufpr/c3sl/participatorio/Projeto.java | 7 +++ .../participatorio/web/ProjetoController.java | 45 +++++++++++++++++-- .../web/ProjetoController_Roo_Controller.aj | 13 ------ .../WEB-INF/i18n/application.properties | 2 +- .../webapp/WEB-INF/i18n/messages.properties | 2 + src/main/webapp/WEB-INF/views/menu.jspx | 2 + .../WEB-INF/views/projetoes/create.jspx | 2 +- .../WEB-INF/views/projetoes/update.jspx | 2 +- 8 files changed, 56 insertions(+), 19 deletions(-) diff --git a/src/main/java/br/ufpr/c3sl/participatorio/Projeto.java b/src/main/java/br/ufpr/c3sl/participatorio/Projeto.java index fe2be42..4d1a379 100644 --- a/src/main/java/br/ufpr/c3sl/participatorio/Projeto.java +++ b/src/main/java/br/ufpr/c3sl/participatorio/Projeto.java @@ -15,6 +15,7 @@ import org.springframework.format.annotation.DateTimeFormat; import org.springframework.roo.addon.javabean.RooJavaBean; import org.springframework.roo.addon.jpa.activerecord.RooJpaActiveRecord; import org.springframework.roo.addon.tostring.RooToString; +import org.springframework.security.core.context.SecurityContextHolder; import br.ufpr.c3sl.participatorio.enums.TipoAcao; import br.ufpr.c3sl.participatorio.enums.TipoDemanda; @@ -144,4 +145,10 @@ public class Projeto { public static List<Projeto> findAllProjetosRejeitados() { return entityManager().createNativeQuery("SELECT * FROM Projeto WHERE estado = 'Rejeitado'", Projeto.class).getResultList(); } + + public static List<Projeto> findMeusProjetos() { + String login = SecurityContextHolder.getContext().getAuthentication().getName(); + + return entityManager().createNativeQuery("SELECT * FROM Projeto p, Usuario u WHERE p.usuario = u.id and p.estado = 'Candidato' and u.login = '"+login+"'", Projeto.class).getResultList(); + } } diff --git a/src/main/java/br/ufpr/c3sl/participatorio/web/ProjetoController.java b/src/main/java/br/ufpr/c3sl/participatorio/web/ProjetoController.java index fa8d398..c2758a5 100644 --- a/src/main/java/br/ufpr/c3sl/participatorio/web/ProjetoController.java +++ b/src/main/java/br/ufpr/c3sl/participatorio/web/ProjetoController.java @@ -1,10 +1,10 @@ package br.ufpr.c3sl.participatorio.web; -import br.ufpr.c3sl.participatorio.Projeto; -import br.ufpr.c3sl.participatorio.enums.TipoStatus; import javax.servlet.http.HttpServletRequest; import javax.validation.Valid; + import org.springframework.roo.addon.web.mvc.controller.scaffold.RooWebScaffold; +import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.validation.BindingResult; @@ -13,6 +13,10 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; +import br.ufpr.c3sl.participatorio.Projeto; +import br.ufpr.c3sl.participatorio.Usuario; +import br.ufpr.c3sl.participatorio.enums.TipoStatus; + @RequestMapping("/projetoes") @Controller @RooWebScaffold(path = "projetoes", formBackingObject = Projeto.class) @@ -24,11 +28,31 @@ public class ProjetoController { populateEditForm(uiModel, projeto); return "projetoes/create"; } - uiModel.asMap().clear(); + projeto.setEstado(TipoStatus.Candidato); + + Usuario u = (Usuario) Usuario.entityManager().createNativeQuery("select * from usuario where login='"+SecurityContextHolder.getContext().getAuthentication().getName()+"'", Usuario.class).getSingleResult(); + projeto.setUsuario(u); + + uiModel.asMap().clear(); projeto.persist(); return "redirect:/projetoes/" + encodeUrlPathSegment(projeto.getId().toString(), httpServletRequest); } + + @RequestMapping(method = RequestMethod.PUT, produces = "text/html") + public String update(@Valid Projeto projeto, BindingResult bindingResult, Model uiModel, HttpServletRequest httpServletRequest) { + if (bindingResult.hasErrors()) { + populateEditForm(uiModel, projeto); + return "projetoes/update"; + } + + Projeto p = (Projeto) Projeto.entityManager().createNativeQuery("select * from projeto where id = "+projeto.getId(), Projeto.class).getSingleResult(); + projeto.setUsuario(p.getUsuario()); + + uiModel.asMap().clear(); + projeto.merge(); + return "redirect:/projetoes/" + encodeUrlPathSegment(projeto.getId().toString(), httpServletRequest); + } @RequestMapping(value = "/{id}", produces = "text/html") public String show(@PathVariable("id") Long id, Model uiModel) { @@ -84,6 +108,21 @@ public class ProjetoController { addDateTimeFormatPatterns(uiModel); return "projetoes/list"; } + + @RequestMapping(value = "meusprojetos", produces = "text/html") + public String listMeusProjetos(@RequestParam(value = "page", required = false) Integer page, @RequestParam(value = "size", required = false) Integer size, Model uiModel) { + if (page != null || size != null) { + int sizeNo = size == null ? 10 : size.intValue(); + final int firstResult = page == null ? 0 : (page.intValue() - 1) * sizeNo; + uiModel.addAttribute("projetoes", Projeto.findProjetoEntries(firstResult, sizeNo)); + float nrOfPages = (float) Projeto.countProjetoes() / sizeNo; + uiModel.addAttribute("maxPages", (int) ((nrOfPages > (int) nrOfPages || nrOfPages == 0.0) ? nrOfPages + 1 : nrOfPages)); + } else { + uiModel.addAttribute("projetoes", Projeto.findMeusProjetos()); + } + addDateTimeFormatPatterns(uiModel); + return "projetoes/list"; + } @RequestMapping(value = "/{id}", params = "status", method = RequestMethod.POST, produces = "text/html") public String updateStatus(@PathVariable("id") Long id, @RequestParam(value = "status", required = true) String status, HttpServletRequest httpServletRequest) { diff --git a/src/main/java/br/ufpr/c3sl/participatorio/web/ProjetoController_Roo_Controller.aj b/src/main/java/br/ufpr/c3sl/participatorio/web/ProjetoController_Roo_Controller.aj index 802de39..a95a8bf 100644 --- a/src/main/java/br/ufpr/c3sl/participatorio/web/ProjetoController_Roo_Controller.aj +++ b/src/main/java/br/ufpr/c3sl/participatorio/web/ProjetoController_Roo_Controller.aj @@ -15,11 +15,9 @@ import br.ufpr.c3sl.participatorio.web.ProjetoController; import java.io.UnsupportedEncodingException; import java.util.Arrays; import javax.servlet.http.HttpServletRequest; -import javax.validation.Valid; import org.joda.time.format.DateTimeFormat; import org.springframework.context.i18n.LocaleContextHolder; import org.springframework.ui.Model; -import org.springframework.validation.BindingResult; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; @@ -50,17 +48,6 @@ privileged aspect ProjetoController_Roo_Controller { return "projetoes/list"; } - @RequestMapping(method = RequestMethod.PUT, produces = "text/html") - public String ProjetoController.update(@Valid Projeto projeto, BindingResult bindingResult, Model uiModel, HttpServletRequest httpServletRequest) { - if (bindingResult.hasErrors()) { - populateEditForm(uiModel, projeto); - return "projetoes/update"; - } - uiModel.asMap().clear(); - projeto.merge(); - return "redirect:/projetoes/" + encodeUrlPathSegment(projeto.getId().toString(), httpServletRequest); - } - @RequestMapping(value = "/{id}", params = "form", produces = "text/html") public String ProjetoController.updateForm(@PathVariable("id") Long id, Model uiModel) { populateEditForm(uiModel, Projeto.findProjeto(id)); diff --git a/src/main/webapp/WEB-INF/i18n/application.properties b/src/main/webapp/WEB-INF/i18n/application.properties index 77a4cf1..07d1be4 100644 --- a/src/main/webapp/WEB-INF/i18n/application.properties +++ b/src/main/webapp/WEB-INF/i18n/application.properties @@ -9,7 +9,7 @@ label_br_ufpr_c3sl_participatorio_ministerio_plural=Ministérios label_br_ufpr_c3sl_participatorio_ministerio_version=Versão label_br_ufpr_c3sl_participatorio_projeto=Projeto -label_br_ufpr_c3sl_participatorio_projeto_acao=Tipo de Açãoo +label_br_ufpr_c3sl_participatorio_projeto_acao=Tipo de Ação label_br_ufpr_c3sl_participatorio_projeto_bairro=Bairro label_br_ufpr_c3sl_participatorio_projeto_cep=Cep label_br_ufpr_c3sl_participatorio_projeto_comofunciona=Como Funciona (Descrição da Ação) diff --git a/src/main/webapp/WEB-INF/i18n/messages.properties b/src/main/webapp/WEB-INF/i18n/messages.properties index 42e79c3..9464850 100644 --- a/src/main/webapp/WEB-INF/i18n/messages.properties +++ b/src/main/webapp/WEB-INF/i18n/messages.properties @@ -13,6 +13,8 @@ global_theme_alt=Alt global_theme_standard=Padrão global_generic={0} +my_projects=Meus Projetos + #welcome page welcome_titlepane=Bem vindo ao {0} welcome_h3=Bem vindo ao {0} diff --git a/src/main/webapp/WEB-INF/views/menu.jspx b/src/main/webapp/WEB-INF/views/menu.jspx index 15b250b..1b51c11 100644 --- a/src/main/webapp/WEB-INF/views/menu.jspx +++ b/src/main/webapp/WEB-INF/views/menu.jspx @@ -9,6 +9,8 @@ <menu:item id="i_projeto_list" messageCode="global_menu_list_candidato" url="/projetoes/listCandidatos" z="user-managed"/> <menu:item id="i_projeto_list" messageCode="global_menu_list_efetivo" url="/projetoes/listEfetivos" z="x1vvsZFRYLoITzX2jIKG93Z4DWM="/> <menu:item id="i_projeto_list" messageCode="global_menu_list_rejeitado" url="/projetoes/listRejeitados" z="x1vvsZFRYLoITzX2jIKG93Z4DWM="/> + + <menu:item id="i_projeto_list" messageCode="my_projects" url="/projetoes/meusprojetos" z="x1vvsZFRYLoITzX2jIKG93Z4DWM="/> </menu:category> <sec:authorize ifAnyGranted="Administrador"> diff --git a/src/main/webapp/WEB-INF/views/projetoes/create.jspx b/src/main/webapp/WEB-INF/views/projetoes/create.jspx index cea6b9b..f94b92f 100644 --- a/src/main/webapp/WEB-INF/views/projetoes/create.jspx +++ b/src/main/webapp/WEB-INF/views/projetoes/create.jspx @@ -43,7 +43,7 @@ <field:input field="descLegislacao" id="c_br_ufpr_c3sl_participatorio_Projeto_descLegislacao" z="Y9X3/A7OHfh+T5M4c7uRjtx2Uak="/> <field:input field="obs" id="c_br_ufpr_c3sl_participatorio_Projeto_obs" z="5b+Wjz0npE5n2wk2R6g1fJZD0VA="/> <field:select field="estado" id="c_br_ufpr_c3sl_participatorio_Projeto_estado" items="${tipostatuses}" path="tipostatuses" render="false" z="user-managed"/> - <field:select field="usuario" id="c_br_ufpr_c3sl_participatorio_Projeto_usuario" itemValue="id" items="${usuarios}" path="/usuarios" z="4oZg5yvLrUjv5RaOV1LbaRAdauo="/> + <field:select field="usuario" id="c_br_ufpr_c3sl_participatorio_Projeto_usuario" itemValue="id" items="${usuarios}" path="/usuarios" render="false" z="user-managed"/> </form:create> <form:dependency dependencies="${dependencies}" id="d_br_ufpr_c3sl_participatorio_Projeto" render="${not empty dependencies}" z="nyMkb0MYQtlthVlj4JcyqCQYyRg="/> </div> diff --git a/src/main/webapp/WEB-INF/views/projetoes/update.jspx b/src/main/webapp/WEB-INF/views/projetoes/update.jspx index 11ad7c8..edebc77 100644 --- a/src/main/webapp/WEB-INF/views/projetoes/update.jspx +++ b/src/main/webapp/WEB-INF/views/projetoes/update.jspx @@ -43,6 +43,6 @@ <field:input field="descLegislacao" id="c_br_ufpr_c3sl_participatorio_Projeto_descLegislacao" z="Y9X3/A7OHfh+T5M4c7uRjtx2Uak="/> <field:input field="obs" id="c_br_ufpr_c3sl_participatorio_Projeto_obs" z="5b+Wjz0npE5n2wk2R6g1fJZD0VA="/> <field:select field="estado" id="c_br_ufpr_c3sl_participatorio_Projeto_estado" items="${tipostatuses}" path="tipostatuses" z="K+kNv0Ov3Ulu6LiKPBQ71hczlOA="/> - <field:select field="usuario" id="c_br_ufpr_c3sl_participatorio_Projeto_usuario" itemValue="id" items="${usuarios}" path="/usuarios" z="4oZg5yvLrUjv5RaOV1LbaRAdauo="/> + <field:select field="usuario" id="c_br_ufpr_c3sl_participatorio_Projeto_usuario" itemValue="id" items="${usuarios}" path="/usuarios" render="false" z="user-managed"/> </form:update> </div> -- GitLab