| Line 16... |
Line 16... |
| 16 |
import org.springframework.web.bind.annotation.RequestBody;
|
16 |
import org.springframework.web.bind.annotation.RequestBody;
|
| 17 |
import org.springframework.web.bind.annotation.RequestMapping;
|
17 |
import org.springframework.web.bind.annotation.RequestMapping;
|
| 18 |
import org.springframework.web.bind.annotation.RequestMethod;
|
18 |
import org.springframework.web.bind.annotation.RequestMethod;
|
| 19 |
import org.springframework.web.bind.annotation.RequestParam;
|
19 |
import org.springframework.web.bind.annotation.RequestParam;
|
| 20 |
|
20 |
|
| - |
|
21 |
import com.mongodb.DBObject;
|
| 21 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
22 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
| - |
|
23 |
import com.spice.profitmandi.dao.entity.catalog.Brand;
|
| - |
|
24 |
import com.spice.profitmandi.dao.entity.catalog.BrandCategory;
|
| 22 |
import com.spice.profitmandi.dao.entity.dtr.Api;
|
25 |
import com.spice.profitmandi.dao.entity.dtr.Api;
|
| 23 |
import com.spice.profitmandi.dao.entity.dtr.Role;
|
26 |
import com.spice.profitmandi.dao.entity.dtr.Role;
|
| 24 |
import com.spice.profitmandi.dao.entity.dtr.User;
|
27 |
import com.spice.profitmandi.dao.entity.dtr.User;
|
| 25 |
import com.spice.profitmandi.dao.enumuration.dtr.Method;
|
28 |
import com.spice.profitmandi.dao.enumuration.dtr.Method;
|
| - |
|
29 |
import com.spice.profitmandi.dao.repository.catalog.BrandCategoryRepository;
|
| - |
|
30 |
|
| - |
|
31 |
import com.spice.profitmandi.dao.repository.catalog.BrandsRepository;
|
| 26 |
import com.spice.profitmandi.dao.repository.dtr.ApiRepository;
|
32 |
import com.spice.profitmandi.dao.repository.dtr.ApiRepository;
|
| - |
|
33 |
import com.spice.profitmandi.dao.repository.dtr.Mongo;
|
| 27 |
import com.spice.profitmandi.dao.repository.dtr.RoleApiRepository;
|
34 |
import com.spice.profitmandi.dao.repository.dtr.RoleApiRepository;
|
| 28 |
import com.spice.profitmandi.dao.repository.dtr.RoleRepository;
|
35 |
import com.spice.profitmandi.dao.repository.dtr.RoleRepository;
|
| 29 |
import com.spice.profitmandi.dao.repository.dtr.UserRepository;
|
36 |
import com.spice.profitmandi.dao.repository.dtr.UserRepository;
|
| 30 |
import com.spice.profitmandi.dao.repository.dtr.UserRoleRepository;
|
37 |
import com.spice.profitmandi.dao.repository.dtr.UserRoleRepository;
|
| 31 |
import com.spice.profitmandi.service.authentication.RoleService;
|
38 |
import com.spice.profitmandi.service.authentication.RoleService;
|
| 32 |
|
39 |
|
| 33 |
@Controller
|
40 |
@Controller
|
| 34 |
@Transactional(rollbackFor=Throwable.class)
|
41 |
@Transactional(rollbackFor = Throwable.class)
|
| 35 |
public class RoleController {
|
42 |
public class RoleController {
|
| 36 |
|
43 |
|
| 37 |
private static final Logger LOGGER = LogManager.getLogger(RoleController.class);
|
44 |
private static final Logger LOGGER = LogManager.getLogger(RoleController.class);
|
| 38 |
|
45 |
|
| 39 |
@Autowired
|
46 |
@Autowired
|
| 40 |
@Qualifier("userRepository")
|
47 |
@Qualifier("userRepository")
|
| 41 |
private UserRepository userRepository;
|
48 |
private UserRepository userRepository;
|
| 42 |
|
49 |
|
| 43 |
@Autowired
|
50 |
@Autowired
|
| 44 |
private UserRoleRepository userRoleRepository;
|
51 |
private UserRoleRepository userRoleRepository;
|
| 45 |
|
52 |
|
| 46 |
@Autowired
|
53 |
@Autowired
|
| 47 |
private RoleRepository roleRepository;
|
54 |
private RoleRepository roleRepository;
|
| 48 |
|
55 |
|
| 49 |
@Autowired
|
56 |
@Autowired
|
| 50 |
private RoleApiRepository roleApiRepository;
|
57 |
private RoleApiRepository roleApiRepository;
|
| 51 |
|
58 |
|
| 52 |
@Autowired
|
59 |
@Autowired
|
| 53 |
private ApiRepository apiRepository;
|
60 |
private ApiRepository apiRepository;
|
| 54 |
|
61 |
|
| 55 |
@Autowired
|
62 |
@Autowired
|
| 56 |
private RoleService roleService;
|
63 |
private RoleService roleService;
|
| 57 |
|
64 |
|
| 58 |
@RequestMapping(value = "/createRole", method = RequestMethod.GET)
|
65 |
@RequestMapping(value = "/createRole", method = RequestMethod.GET)
|
| 59 |
public String createRole(HttpServletRequest request, Model model) throws Exception{
|
66 |
public String createRole(HttpServletRequest request, Model model) throws Exception {
|
| 60 |
return "create-role";
|
67 |
return "create-role";
|
| 61 |
}
|
68 |
}
|
| 62 |
|
69 |
|
| 63 |
@RequestMapping(value = "/createRole", method = RequestMethod.POST)
|
70 |
@RequestMapping(value = "/createRole", method = RequestMethod.POST)
|
| 64 |
public String createRole(HttpServletRequest request, @RequestParam(name = ProfitMandiConstants.NAME) String name, Model model) throws Exception{
|
71 |
public String createRole(HttpServletRequest request, @RequestParam(name = ProfitMandiConstants.NAME) String name,
|
| - |
|
72 |
Model model) throws Exception {
|
| 65 |
roleService.createRole(name);
|
73 |
roleService.createRole(name);
|
| 66 |
return "create-role";
|
74 |
return "create-role";
|
| 67 |
}
|
75 |
}
|
| 68 |
|
76 |
|
| 69 |
@RequestMapping(value = "/createDuplicateRole", method = RequestMethod.GET)
|
77 |
@RequestMapping(value = "/createDuplicateRole", method = RequestMethod.GET)
|
| 70 |
public String createDuplicateRole(HttpServletRequest request, Model model) throws Exception{
|
78 |
public String createDuplicateRole(HttpServletRequest request, Model model) throws Exception {
|
| 71 |
List<Role> roles = roleRepository.selectAll();
|
79 |
List<Role> roles = roleRepository.selectAll();
|
| 72 |
model.addAttribute("roles", roles);
|
80 |
model.addAttribute("roles", roles);
|
| 73 |
return "create-duplicate-role";
|
81 |
return "create-duplicate-role";
|
| 74 |
}
|
82 |
}
|
| 75 |
|
83 |
|
| 76 |
@RequestMapping(value = "/createDuplicateRole", method = RequestMethod.POST)
|
84 |
@RequestMapping(value = "/createDuplicateRole", method = RequestMethod.POST)
|
| - |
|
85 |
public String createDuplicateRole(HttpServletRequest request,
|
| - |
|
86 |
@RequestParam(name = ProfitMandiConstants.ROLE_ID) int roleId,
|
| 77 |
public String createDuplicateRole(HttpServletRequest request, @RequestParam(name = ProfitMandiConstants.ROLE_ID) int roleId, @RequestParam(name = ProfitMandiConstants.NAME) String name, Model model) throws Exception{
|
87 |
@RequestParam(name = ProfitMandiConstants.NAME) String name, Model model) throws Exception {
|
| 78 |
roleService.createDuplicateRole(roleId, name);
|
88 |
roleService.createDuplicateRole(roleId, name);
|
| 79 |
List<Role> roles = roleRepository.selectAll();
|
89 |
List<Role> roles = roleRepository.selectAll();
|
| 80 |
model.addAttribute("roles", roles);
|
90 |
model.addAttribute("roles", roles);
|
| 81 |
return "create-duplicate-role";
|
91 |
return "create-duplicate-role";
|
| 82 |
}
|
92 |
}
|
| 83 |
|
93 |
|
| 84 |
@RequestMapping(value = "/deleteRole", method = RequestMethod.GET)
|
94 |
@RequestMapping(value = "/deleteRole", method = RequestMethod.GET)
|
| 85 |
public String deleteRole(HttpServletRequest request, Model model) throws Exception{
|
95 |
public String deleteRole(HttpServletRequest request, Model model) throws Exception {
|
| 86 |
List<Role> roles = roleRepository.selectAll();
|
96 |
List<Role> roles = roleRepository.selectAll();
|
| 87 |
model.addAttribute("roles", roles);
|
97 |
model.addAttribute("roles", roles);
|
| 88 |
return "delete-role";
|
98 |
return "delete-role";
|
| 89 |
}
|
99 |
}
|
| 90 |
|
100 |
|
| 91 |
@RequestMapping(value = "/deleteRole", method = RequestMethod.DELETE)
|
101 |
@RequestMapping(value = "/deleteRole", method = RequestMethod.DELETE)
|
| 92 |
public String deleteRole(HttpServletRequest request, @RequestParam(name = ProfitMandiConstants.ROLE_ID) int roleId, Model model) throws Exception{
|
102 |
public String deleteRole(HttpServletRequest request, @RequestParam(name = ProfitMandiConstants.ROLE_ID) int roleId,
|
| - |
|
103 |
Model model) throws Exception {
|
| 93 |
roleService.deleteRole(roleId);
|
104 |
roleService.deleteRole(roleId);
|
| 94 |
List<Role> roles = roleRepository.selectAll();
|
105 |
List<Role> roles = roleRepository.selectAll();
|
| 95 |
model.addAttribute("roles", roles);
|
106 |
model.addAttribute("roles", roles);
|
| 96 |
return "delete-role";
|
107 |
return "delete-role";
|
| 97 |
}
|
108 |
}
|
| 98 |
|
109 |
|
| 99 |
@RequestMapping(value = "/renameRole", method = RequestMethod.GET)
|
110 |
@RequestMapping(value = "/renameRole", method = RequestMethod.GET)
|
| 100 |
public String renameRole(HttpServletRequest request, Model model) throws Exception{
|
111 |
public String renameRole(HttpServletRequest request, Model model) throws Exception {
|
| 101 |
List<Role> roles = roleRepository.selectAll();
|
112 |
List<Role> roles = roleRepository.selectAll();
|
| 102 |
model.addAttribute("roles", roles);
|
113 |
model.addAttribute("roles", roles);
|
| 103 |
return "rename-role";
|
114 |
return "rename-role";
|
| 104 |
}
|
115 |
}
|
| 105 |
|
116 |
|
| 106 |
@RequestMapping(value = "/renameRole", method = RequestMethod.PUT)
|
117 |
@RequestMapping(value = "/renameRole", method = RequestMethod.PUT)
|
| 107 |
public String renameRole(HttpServletRequest request, @RequestParam(name = ProfitMandiConstants.ROLE_ID) int roleId, @RequestParam(name = ProfitMandiConstants.NAME) String name, Model model) throws Exception{
|
118 |
public String renameRole(HttpServletRequest request, @RequestParam(name = ProfitMandiConstants.ROLE_ID) int roleId,
|
| - |
|
119 |
@RequestParam(name = ProfitMandiConstants.NAME) String name, Model model) throws Exception {
|
| 108 |
roleService.renameRole(roleId, name);
|
120 |
roleService.renameRole(roleId, name);
|
| 109 |
List<Role> roles = roleRepository.selectAll();
|
121 |
List<Role> roles = roleRepository.selectAll();
|
| 110 |
model.addAttribute("roles", roles);
|
122 |
model.addAttribute("roles", roles);
|
| 111 |
return "rename-role";
|
123 |
return "rename-role";
|
| 112 |
}
|
124 |
}
|
| 113 |
|
125 |
|
| 114 |
@RequestMapping(value = "/createApi", method = RequestMethod.GET)
|
126 |
@RequestMapping(value = "/createApi", method = RequestMethod.GET)
|
| 115 |
public String createApi(HttpServletRequest request, Model model) throws Exception{
|
127 |
public String createApi(HttpServletRequest request, Model model) throws Exception {
|
| 116 |
model.addAttribute("methods", Method.values());
|
128 |
model.addAttribute("methods", Method.values());
|
| 117 |
return "create-api";
|
129 |
return "create-api";
|
| 118 |
}
|
130 |
}
|
| 119 |
|
131 |
|
| 120 |
@RequestMapping(value = "/createApi", method = RequestMethod.POST)
|
132 |
@RequestMapping(value = "/createApi", method = RequestMethod.POST)
|
| 121 |
public String createApi(HttpServletRequest request, @RequestParam(name = ProfitMandiConstants.NAME) String name, @RequestParam(name = ProfitMandiConstants.URI) String uri, @RequestParam(name = ProfitMandiConstants.METHOD) Method method, Model model) throws Exception{
|
133 |
public String createApi(HttpServletRequest request, @RequestParam(name = ProfitMandiConstants.NAME) String name,
|
| - |
|
134 |
@RequestParam(name = ProfitMandiConstants.URI) String uri,
|
| - |
|
135 |
@RequestParam(name = ProfitMandiConstants.METHOD) Method method, Model model) throws Exception {
|
| 122 |
roleService.createApi(name, uri, method);
|
136 |
roleService.createApi(name, uri, method);
|
| 123 |
return "create-api";
|
137 |
return "create-api";
|
| 124 |
}
|
138 |
}
|
| 125 |
|
139 |
|
| 126 |
@RequestMapping(value = "/editApi", method = RequestMethod.GET)
|
140 |
@RequestMapping(value = "/editApi", method = RequestMethod.GET)
|
| 127 |
public String editApi(HttpServletRequest request, Model model) throws Exception{
|
141 |
public String editApi(HttpServletRequest request, Model model) throws Exception {
|
| 128 |
List<Api> apis = apiRepository.selectAll();
|
142 |
List<Api> apis = apiRepository.selectAll();
|
| 129 |
model.addAttribute("apis", apis);
|
143 |
model.addAttribute("apis", apis);
|
| 130 |
model.addAttribute("methods", Method.values());
|
144 |
model.addAttribute("methods", Method.values());
|
| 131 |
return "edit-api";
|
145 |
return "edit-api";
|
| 132 |
}
|
146 |
}
|
| 133 |
|
147 |
|
| 134 |
@RequestMapping(value = "/editApi", method = RequestMethod.PUT)
|
148 |
@RequestMapping(value = "/editApi", method = RequestMethod.PUT)
|
| 135 |
public String editApi(HttpServletRequest request, @RequestParam(name = ProfitMandiConstants.API_ID) int apiId, @RequestParam(name = ProfitMandiConstants.NAME) String name, @RequestParam(name = ProfitMandiConstants.URI) String uri, @RequestParam(name = ProfitMandiConstants.METHOD) Method method, Model model) throws Exception{
|
149 |
public String editApi(HttpServletRequest request, @RequestParam(name = ProfitMandiConstants.API_ID) int apiId,
|
| - |
|
150 |
@RequestParam(name = ProfitMandiConstants.NAME) String name,
|
| - |
|
151 |
@RequestParam(name = ProfitMandiConstants.URI) String uri,
|
| - |
|
152 |
@RequestParam(name = ProfitMandiConstants.METHOD) Method method, Model model) throws Exception {
|
| 136 |
roleService.editApi(apiId, name, uri, method);
|
153 |
roleService.editApi(apiId, name, uri, method);
|
| 137 |
List<Api> apis = apiRepository.selectAll();
|
154 |
List<Api> apis = apiRepository.selectAll();
|
| 138 |
model.addAttribute("apis", apis);
|
155 |
model.addAttribute("apis", apis);
|
| 139 |
model.addAttribute("methods", Method.values());
|
156 |
model.addAttribute("methods", Method.values());
|
| 140 |
return "edit-api";
|
157 |
return "edit-api";
|
| 141 |
}
|
158 |
}
|
| 142 |
|
159 |
|
| 143 |
@RequestMapping(value = "/deleteApi", method = RequestMethod.GET)
|
160 |
@RequestMapping(value = "/deleteApi", method = RequestMethod.GET)
|
| 144 |
public String deleteApi(HttpServletRequest request, Model model) throws Exception{
|
161 |
public String deleteApi(HttpServletRequest request, Model model) throws Exception {
|
| 145 |
List<Api> apis = apiRepository.selectAll();
|
162 |
List<Api> apis = apiRepository.selectAll();
|
| 146 |
model.addAttribute("apis", apis);
|
163 |
model.addAttribute("apis", apis);
|
| 147 |
model.addAttribute("methods", Method.values());
|
164 |
model.addAttribute("methods", Method.values());
|
| 148 |
return "delete-api";
|
165 |
return "delete-api";
|
| 149 |
}
|
166 |
}
|
| 150 |
|
167 |
|
| 151 |
@RequestMapping(value = "/deleteApi", method = RequestMethod.DELETE)
|
168 |
@RequestMapping(value = "/deleteApi", method = RequestMethod.DELETE)
|
| 152 |
public String deleteApi(HttpServletRequest request, @RequestParam(name = ProfitMandiConstants.API_ID) int apiId, Model model) throws Exception{
|
169 |
public String deleteApi(HttpServletRequest request, @RequestParam(name = ProfitMandiConstants.API_ID) int apiId,
|
| - |
|
170 |
Model model) throws Exception {
|
| 153 |
roleService.deleteApi(apiId);
|
171 |
roleService.deleteApi(apiId);
|
| 154 |
List<Api> apis = apiRepository.selectAll();
|
172 |
List<Api> apis = apiRepository.selectAll();
|
| 155 |
model.addAttribute("apis", apis);
|
173 |
model.addAttribute("apis", apis);
|
| 156 |
model.addAttribute("methods", Method.values());
|
174 |
model.addAttribute("methods", Method.values());
|
| 157 |
return "delete-api";
|
175 |
return "delete-api";
|
| 158 |
}
|
176 |
}
|
| 159 |
|
177 |
|
| 160 |
@RequestMapping(value = "/addRemoveRole", method = RequestMethod.GET)
|
178 |
@RequestMapping(value = "/addRemoveRole", method = RequestMethod.GET)
|
| 161 |
public String addRemoveRole(HttpServletRequest request, Model model) throws Exception{
|
179 |
public String addRemoveRole(HttpServletRequest request, Model model) throws Exception {
|
| 162 |
return "add-remove-role";
|
180 |
return "add-remove-role";
|
| 163 |
}
|
181 |
}
|
| 164 |
|
182 |
|
| 165 |
@RequestMapping(value = "/userRoles", method = RequestMethod.GET)
|
183 |
@RequestMapping(value = "/userRoles", method = RequestMethod.GET)
|
| - |
|
184 |
public String userRoles(HttpServletRequest request,
|
| 166 |
public String userRoles(HttpServletRequest request, @RequestParam(name = ProfitMandiConstants.EMAIL_ID_OR_MOBILE_NUMBER) String emailIdOrMobileNumber, Model model) throws Exception{
|
185 |
@RequestParam(name = ProfitMandiConstants.EMAIL_ID_OR_MOBILE_NUMBER) String emailIdOrMobileNumber,
|
| - |
|
186 |
Model model) throws Exception {
|
| 167 |
User user = userRepository.selectByEmailIdOrMobileNumber(emailIdOrMobileNumber);
|
187 |
User user = userRepository.selectByEmailIdOrMobileNumber(emailIdOrMobileNumber);
|
| 168 |
List<Integer> roleIds = userRoleRepository.selectRoleIdsByUserId(user.getId());
|
188 |
List<Integer> roleIds = userRoleRepository.selectRoleIdsByUserId(user.getId());
|
| 169 |
List<Role> roles = roleRepository.selectAll();
|
189 |
List<Role> roles = roleRepository.selectAll();
|
| 170 |
model.addAttribute("userRoleIds", roleIds);
|
190 |
model.addAttribute("userRoleIds", roleIds);
|
| 171 |
model.addAttribute("roles", roles);
|
191 |
model.addAttribute("roles", roles);
|
| 172 |
return "user-roles";
|
192 |
return "user-roles";
|
| 173 |
}
|
193 |
}
|
| 174 |
|
194 |
|
| 175 |
@RequestMapping(value = "/addRemoveRoles", method = RequestMethod.POST)
|
195 |
@RequestMapping(value = "/addRemoveRoles", method = RequestMethod.POST)
|
| - |
|
196 |
public String addRemoveRoles(HttpServletRequest request,
|
| 176 |
public String addRemoveRoles(HttpServletRequest request, @RequestParam(name = ProfitMandiConstants.EMAIL_ID_OR_MOBILE_NUMBER) String emailIdOrMobileNumber, @RequestBody List<Integer> roleIds, Model model) throws Exception{
|
197 |
@RequestParam(name = ProfitMandiConstants.EMAIL_ID_OR_MOBILE_NUMBER) String emailIdOrMobileNumber,
|
| - |
|
198 |
@RequestBody List<Integer> roleIds, Model model) throws Exception {
|
| 177 |
roleService.addRemoveRoles(emailIdOrMobileNumber, new HashSet<>(roleIds));
|
199 |
roleService.addRemoveRoles(emailIdOrMobileNumber, new HashSet<>(roleIds));
|
| 178 |
return "add-remove-role";
|
200 |
return "add-remove-role";
|
| 179 |
}
|
201 |
}
|
| 180 |
|
202 |
|
| 181 |
@RequestMapping(value = "/addRemoveApi", method = RequestMethod.GET)
|
203 |
@RequestMapping(value = "/addRemoveApi", method = RequestMethod.GET)
|
| 182 |
public String addRemoveApi(HttpServletRequest request, Model model) throws Exception{
|
204 |
public String addRemoveApi(HttpServletRequest request, Model model) throws Exception {
|
| 183 |
List<Role> roles = roleRepository.selectAll();
|
205 |
List<Role> roles = roleRepository.selectAll();
|
| 184 |
model.addAttribute("roles", roles);
|
206 |
model.addAttribute("roles", roles);
|
| 185 |
return "add-remove-api";
|
207 |
return "add-remove-api";
|
| 186 |
}
|
208 |
}
|
| 187 |
|
209 |
|
| 188 |
@RequestMapping(value = "/roleApis", method = RequestMethod.GET)
|
210 |
@RequestMapping(value = "/roleApis", method = RequestMethod.GET)
|
| 189 |
public String roleApis(HttpServletRequest request, @RequestParam(name = ProfitMandiConstants.ROLE_ID) int roleId, Model model) throws Exception{
|
211 |
public String roleApis(HttpServletRequest request, @RequestParam(name = ProfitMandiConstants.ROLE_ID) int roleId,
|
| - |
|
212 |
Model model) throws Exception {
|
| 190 |
Map<String, Object> map = roleService.getApisByRoleId(roleId);
|
213 |
Map<String, Object> map = roleService.getApisByRoleId(roleId);
|
| 191 |
model.addAllAttributes(map);
|
214 |
model.addAllAttributes(map);
|
| 192 |
return "role-apis";
|
215 |
return "role-apis";
|
| 193 |
}
|
216 |
}
|
| 194 |
|
217 |
|
| 195 |
@RequestMapping(value = "/addRemoveApis", method = RequestMethod.POST)
|
218 |
@RequestMapping(value = "/addRemoveApis", method = RequestMethod.POST)
|
| - |
|
219 |
public String addRemoveApi(HttpServletRequest request,
|
| 196 |
public String addRemoveApi(HttpServletRequest request, @RequestParam(name = ProfitMandiConstants.ROLE_ID) int roleId, @RequestBody List<Integer> apiIds, Model model) throws Exception{
|
220 |
@RequestParam(name = ProfitMandiConstants.ROLE_ID) int roleId, @RequestBody List<Integer> apiIds,
|
| - |
|
221 |
Model model) throws Exception {
|
| 197 |
roleService.addRemoveApis(roleId, new HashSet<>(apiIds));
|
222 |
roleService.addRemoveApis(roleId, new HashSet<>(apiIds));
|
| 198 |
List<Role> roles = roleRepository.selectAll();
|
223 |
List<Role> roles = roleRepository.selectAll();
|
| 199 |
model.addAttribute("roles", roles);
|
224 |
model.addAttribute("roles", roles);
|
| 200 |
return "add-remove-api";
|
225 |
return "add-remove-api";
|
| 201 |
}
|
226 |
}
|
| - |
|
227 |
|
| - |
|
228 |
@Autowired
|
| - |
|
229 |
private Mongo mongoClient;
|
| - |
|
230 |
|
| - |
|
231 |
@Autowired
|
| - |
|
232 |
private BrandsRepository brandsRepository;
|
| - |
|
233 |
|
| - |
|
234 |
@Autowired
|
| - |
|
235 |
private BrandCategoryRepository brandCategoryRepository;
|
| - |
|
236 |
|
| - |
|
237 |
@RequestMapping(value = "/addBrands", method = RequestMethod.POST)
|
| - |
|
238 |
public String addBrands(HttpServletRequest request, Model model) throws Exception {
|
| - |
|
239 |
|
| - |
|
240 |
List<DBObject> mobileBrands = mongoClient.getAllBrandsToDisplay(3);
|
| - |
|
241 |
for (DBObject mobileBrand : mobileBrands) {
|
| - |
|
242 |
String brandName = (String) mobileBrand.get("name");
|
| - |
|
243 |
Brand brand = brandsRepository.selectByBrand(brandName);
|
| - |
|
244 |
|
| - |
|
245 |
if (brand == null) {
|
| - |
|
246 |
|
| - |
|
247 |
brand = new Brand();
|
| - |
|
248 |
brand.setName(brandName);
|
| - |
|
249 |
brand.setLogoUrl((String) mobileBrand.get("url"));
|
| - |
|
250 |
brandsRepository.persist(brand);
|
| - |
|
251 |
}
|
| - |
|
252 |
|
| - |
|
253 |
BrandCategory brandCategory = new BrandCategory();
|
| - |
|
254 |
brandCategory.setActive((Boolean) mobileBrand.get("active"));
|
| - |
|
255 |
brandCategory.setCategoryId((int) mobileBrand.get("categoryId"));
|
| - |
|
256 |
brandCategory.setBrandId(brand.getId());
|
| - |
|
257 |
brandCategory.setRank((int) mobileBrand.get("rank"));
|
| - |
|
258 |
brandCategoryRepository.persist(brandCategory);
|
| - |
|
259 |
|
| - |
|
260 |
}
|
| - |
|
261 |
|
| - |
|
262 |
return "add-remove-api";
|
| 202 |
|
263 |
}
|
| - |
|
264 |
|
| 203 |
}
|
265 |
}
|
| 204 |
|
266 |
|