diff --git a/src/main/java/br/ufpr/c3sl/participatorio/Projeto.java b/src/main/java/br/ufpr/c3sl/participatorio/Projeto.java index fe2be42b3d58b51eb4d2ec4d4e302326c98147d0..4d1a37990095eeb3bd793640ddaeb96013e4f53c 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 fa8d398d2dbf8a1df0d46c8d7ab8fb40b8955462..c2758a58854c10b070d94c806c04510c44fa9b9a 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 802de39f66379665372a2e37fdbcf42cecd6168a..a95a8bf68156175032763ac58607899e0783f6ca 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 77a4cf11d912087349fb47dd7063207ad806cba0..07d1be4121ed271c43ff3006f1c9807a072fc085 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 42e79c3d9ec66c287305660ee5a73322c25e10b9..9464850c1008653244831128a29c5c28dc5a7dec 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 15b250bae23dfcbb8dae2f8f5cd2fc2179f326ba..1b51c1188f5560925b89e4d4fa46e70ea5e6c442 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 cea6b9b3fe13b9389e415899f098031626da978c..f94b92fdd49bba0e02c858360b8a03968d4c9072 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 11ad7c83594bc6332bdcb25717bd476955dba7d9..edebc77a0aef78962f071e26c3b3b0877e40a259 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>