Revision 57934
Added by Konstantina Galouni over 4 years ago
SubCategoryController.java | ||
---|---|---|
252 | 252 |
return true; |
253 | 253 |
} |
254 | 254 |
|
255 |
@RequestMapping(value = "/{stakeholderId}/{topicId}/{categoryId}/{subcategoryId}/toggle-status", method = RequestMethod.POST) |
|
256 |
public Boolean toggleSubCategoryStatus(@PathVariable("stakeholderId") String stakeholderId, |
|
257 |
@PathVariable("topicId") String topicId, |
|
258 |
@PathVariable("categoryId") String categoryId, |
|
259 |
@PathVariable("subcategoryId") String subcategoryId) { |
|
260 |
log.debug("toggle subCategory status (isActive)"); |
|
261 |
log.debug("Stakeholder: "+stakeholderId + " - Topic: "+topicId + " - Category: "+categoryId+ " - SubCategory: "+subcategoryId); |
|
262 |
|
|
263 |
SubCategory subCategory = subCategoryDAO.findById(subcategoryId); |
|
264 |
if (subCategory == null) { |
|
265 |
// EXCEPTION - SubCategory not found |
|
266 |
throw new EntityNotFoundException("Toggle subCategory status: SubCategory with id: "+subcategoryId+" not found"); |
|
267 |
} |
|
268 |
subCategory.setIsActive(!subCategory.getIsActive()); |
|
269 |
|
|
270 |
this.toggleSubCategory(stakeholderId, topicId, categoryId, subCategory); |
|
271 |
|
|
272 |
return subCategory.getIsActive(); |
|
273 |
} |
|
274 |
|
|
275 |
@RequestMapping(value = "/{stakeholderId}/{topicId}/{categoryId}/{subcategoryId}/toggle-access", method = RequestMethod.POST) |
|
276 |
public Boolean toggleSubCategoryAccess(@PathVariable("stakeholderId") String stakeholderId, |
|
277 |
@PathVariable("topicId") String topicId, |
|
278 |
@PathVariable("categoryId") String categoryId, |
|
279 |
@PathVariable("subcategoryId") String subcategoryId) { |
|
280 |
log.debug("toggle subCategory access (isPublic)"); |
|
281 |
log.debug("Stakeholder: "+stakeholderId + " - Topic: "+topicId + " - Category: "+categoryId+ " - SubCategory: "+subcategoryId); |
|
282 |
|
|
283 |
SubCategory subCategory = subCategoryDAO.findById(subcategoryId); |
|
284 |
if (subCategory == null) { |
|
285 |
// EXCEPTION - SubCategory not found |
|
286 |
throw new EntityNotFoundException("Toggle subCategory access: SubCategory with id: "+subcategoryId+" not found"); |
|
287 |
} |
|
288 |
subCategory.setIsPublic(!subCategory.getIsPublic()); |
|
289 |
|
|
290 |
this.toggleSubCategory(stakeholderId, topicId, categoryId, subCategory); |
|
291 |
|
|
292 |
return subCategory.getIsPublic(); |
|
293 |
} |
|
294 |
|
|
295 |
public void toggleSubCategory(String stakeholderId, String topicId, String categoryId, SubCategory subcategory) { |
|
296 |
Stakeholder<String> stakeholder = stakeholderDAO.findById(stakeholderId); |
|
297 |
|
|
298 |
if (stakeholder != null) { |
|
299 |
|
|
300 |
Topic<String> topic = topicDAO.findById(topicId); |
|
301 |
if (topic != null) { |
|
302 |
if (stakeholder.getTopics().contains(topicId)) { |
|
303 |
|
|
304 |
Category<String> category = categoryDAO.findById(categoryId); |
|
305 |
if (category != null) { |
|
306 |
if (topic.getCategories().contains(categoryId)) { |
|
307 |
if (category.getSubCategories().contains(subcategory.getId())) { |
|
308 |
subCategoryDAO.save(subcategory); |
|
309 |
log.debug("SubCategory toggled!"); |
|
310 |
} else { |
|
311 |
// EXCEPTION - SubCategory not found in Stakeholder: stakeholder.getAlias(); -> Topic: topic.getAlias(); -> Category: category.getAlias(); |
|
312 |
throw new PathNotValidException("Toggle subCategory: SubCategory with id: "+subcategory.getId()+" not found in Category: "+categoryId); |
|
313 |
} |
|
314 |
} else { |
|
315 |
// EXCEPTION - Category not found in Stakeholder: stakeholder.getAlias(); -> Topic: topic.getAlias(); |
|
316 |
throw new PathNotValidException("Toggle subCategory: Category with id: "+categoryId+" not found in Topic: "+topicId); |
|
317 |
} |
|
318 |
} else { |
|
319 |
// EXCEPTION - Category not found |
|
320 |
throw new EntityNotFoundException("Toggle subCategory: Category with id: "+categoryId+" not found"); |
|
321 |
} |
|
322 |
} else { |
|
323 |
// EXCEPTION - Topic not found in Stakeholder: stakeholder.getAlias(); |
|
324 |
throw new PathNotValidException("Toggle subCategory: Topic with id: "+topicId+" not found in Stakeholder: "+stakeholderId); |
|
325 |
} |
|
326 |
} else { |
|
327 |
// EXCEPTION - Topic not found |
|
328 |
throw new EntityNotFoundException("Toggle subCategory: Topic with id: "+topicId+" not found"); |
|
329 |
} |
|
330 |
} else { |
|
331 |
// EXCEPTION - Stakeholder not found |
|
332 |
throw new EntityNotFoundException("Toggle subCategory: Stakeholder with id: "+stakeholderId+" not found"); |
|
333 |
} |
|
334 |
} |
|
335 |
|
|
255 | 336 |
} |
Also available in: Unified diff
StakeholderController.java & TopicController.java & CategoryController.java & SubCategoryController.java: toggle methods for status and access added.