Commit 0575e85f457ee94cbb02622c4c11dcba86e02fb7
1 parent
33d9e022
Exists in
master
[Redmine Atendimento #4698]Grupo ADM menu
Showing
1 changed file
with
59 additions
and
0 deletions
Show diff stats
citgrp-patrimonio-api/src/main/java/br/com/centralit/api/service/impl/InicializarPatrimonioServiceImpl.java
... | ... | @@ -13,14 +13,19 @@ import br.com.centralit.api.model.EstruturaOrganizacionalPatrimonio; |
13 | 13 | import br.com.centralit.api.service.DominioService; |
14 | 14 | import br.com.centralit.api.service.EstruturaOrganizacionalPatrimonioService; |
15 | 15 | import br.com.centralit.api.service.EstruturaOrganizacionalService; |
16 | +import br.com.centralit.api.service.GrupoService; | |
16 | 17 | import br.com.centralit.api.service.MenuFileService; |
18 | +import br.com.centralit.api.service.MenuGrupoService; | |
17 | 19 | import br.com.centralit.api.service.MenuService; |
18 | 20 | import br.com.centralit.api.service.ModuloService; |
19 | 21 | import br.com.centralit.api.service.PaginaService; |
20 | 22 | import br.com.centralit.framework.model.UtilStartup; |
23 | +import br.com.centralit.framework.model.Grupo; | |
21 | 24 | import br.com.centralit.framework.model.Menu; |
22 | 25 | import br.com.centralit.framework.model.MenuFile; |
26 | +import br.com.centralit.framework.model.MenuGrupo; | |
23 | 27 | import br.com.centralit.framework.model.Pagina; |
28 | +import br.com.centralit.framework.util.UtilColecao; | |
24 | 29 | import br.com.centralit.framework.util.UtilObjeto; |
25 | 30 | |
26 | 31 | @SuppressWarnings("unused") |
... | ... | @@ -48,6 +53,12 @@ public class InicializarPatrimonioServiceImpl extends UtilStartup{ |
48 | 53 | @Autowired |
49 | 54 | private ModuloService moduloService; |
50 | 55 | |
56 | + @Autowired | |
57 | + private GrupoService grupoService; | |
58 | + | |
59 | + @Autowired | |
60 | + private MenuGrupoService menuGrupoService; | |
61 | + | |
51 | 62 | private Menu menuAdmMaterial; |
52 | 63 | |
53 | 64 | private Menu menuPatrimonio; |
... | ... | @@ -61,6 +72,54 @@ public class InicializarPatrimonioServiceImpl extends UtilStartup{ |
61 | 72 | public void gerarCarga() { |
62 | 73 | //TODO criarEstruturasPatrimonio(); |
63 | 74 | criarPaginasMenus(); |
75 | + | |
76 | + if(UtilColecao.isVazio(menuAdmMaterial.getMenuGrupos())){ | |
77 | + menuAdmMaterial.setMenuGrupos(gerarGrupoMaster(menuAdmMaterial)); | |
78 | + this.menuService.merge(menuAdmMaterial); | |
79 | + }else{ | |
80 | + boolean grupoMasterPresente = false; | |
81 | + for (MenuGrupo menuGrupo : menuAdmMaterial.getMenuGrupos()) { | |
82 | + if(menuGrupo.getGrupo().getIsMaster()){ | |
83 | + grupoMasterPresente = true; | |
84 | + break; | |
85 | + } | |
86 | + } | |
87 | + if(!grupoMasterPresente){ | |
88 | + menuAdmMaterial.getMenuGrupos().addAll(gerarGrupoMaster(menuAdmMaterial)); | |
89 | + this.menuService.merge(menuAdmMaterial); | |
90 | + } | |
91 | + } | |
92 | + | |
93 | + if(UtilColecao.isVazio(menuPatrimonio.getMenuGrupos())){ | |
94 | + menuPatrimonio.setMenuGrupos(gerarGrupoMaster(menuPatrimonio)); | |
95 | + this.menuService.merge(menuAdmMaterial); | |
96 | + }else{ | |
97 | + boolean grupoMasterPresente = false; | |
98 | + for (MenuGrupo menuGrupo : menuPatrimonio.getMenuGrupos()) { | |
99 | + if(menuGrupo.getGrupo().getIsMaster()){ | |
100 | + grupoMasterPresente = true; | |
101 | + break; | |
102 | + } | |
103 | + } | |
104 | + if(!grupoMasterPresente){ | |
105 | + menuPatrimonio.getMenuGrupos().addAll(gerarGrupoMaster(menuPatrimonio)); | |
106 | + this.menuService.merge(menuPatrimonio); | |
107 | + } | |
108 | + } | |
109 | + } | |
110 | + | |
111 | + private List<MenuGrupo> gerarGrupoMaster(Menu menu) { | |
112 | + List<MenuGrupo> menuGrupos = new ArrayList<>(); | |
113 | + Collection<Grupo> gruposMaster = this.grupoService.findGruposMaster(); | |
114 | + for (Grupo grupo : gruposMaster) { | |
115 | + MenuGrupo menuGrupo = new MenuGrupo(); | |
116 | + menuGrupo.setOrganizacao(grupo.getOrganizacao()); | |
117 | + menuGrupo.setMenu(menu); | |
118 | + menuGrupo.setGrupo(grupo); | |
119 | + this.menuGrupoService.save(menuGrupo); | |
120 | + menuGrupos.add(menuGrupo); | |
121 | + } | |
122 | + return menuGrupos; | |
64 | 123 | } |
65 | 124 | |
66 | 125 | /** | ... | ... |