Project

General

Profile

« Previous | Next » 

Revision 57934

StakeholderController.java & TopicController.java & CategoryController.java & SubCategoryController.java: toggle methods for status and access added.

View differences:

CategoryController.java
234 234
        }
235 235
        return true;
236 236
    }
237

  
238
    @RequestMapping(value = "/{stakeholderId}/{topicId}/{categoryId}/toggle-status", method = RequestMethod.POST)
239
    public Boolean toggleCategoryStatus(@PathVariable("stakeholderId") String stakeholderId,
240
                                        @PathVariable("topicId") String topicId,
241
                                        @PathVariable("categoryId") String categoryId) {
242
        log.debug("toggle category status (isActive)");
243
        log.debug("Stakeholder: "+stakeholderId + " - Topic: "+topicId + " - Category: "+categoryId);
244

  
245
        Category category = categoryDAO.findById(categoryId);
246
        if (category == null) {
247
            // EXCEPTION - Category not found
248
            throw new EntityNotFoundException("Toggle category status: Category with id: "+categoryId+" not found");
249
        }
250
        category.setIsActive(!category.getIsActive());
251

  
252
        this.toggleCategory(stakeholderId, topicId, category);
253

  
254
        return category.getIsActive();
255
    }
256

  
257
    @RequestMapping(value = "/{stakeholderId}/{topicId}/{categoryId}/toggle-access", method = RequestMethod.POST)
258
    public Boolean toggleCategoryAccess(@PathVariable("stakeholderId") String stakeholderId,
259
                                        @PathVariable("topicId") String topicId,
260
                                        @PathVariable("categoryId") String categoryId) {
261
        log.debug("toggle category access (isPublic)");
262
        log.debug("Stakeholder: "+stakeholderId + " - Topic: "+topicId + " - Category: "+categoryId);
263

  
264
        Category category = categoryDAO.findById(categoryId);
265
        if (category == null) {
266
            // EXCEPTION - Category not found
267
            throw new EntityNotFoundException("Toggle category access: Category with id: "+categoryId+" not found");
268
        }
269
        category.setIsPublic(!category.getIsPublic());
270

  
271
        this.toggleCategory(stakeholderId, topicId, category);
272

  
273
        return category.getIsPublic();
274
    }
275

  
276
    public void toggleCategory(String stakeholderId, String topicId, Category category) {
277
        Stakeholder<String> stakeholder = stakeholderDAO.findById(stakeholderId);
278

  
279
        if (stakeholder != null) {
280

  
281
            Topic<String> topic = topicDAO.findById(topicId);
282
            if (topic != null) {
283
                if (stakeholder.getTopics().contains(topicId)) {
284
                    if (topic.getCategories().contains(category.getId())) {
285
                        categoryDAO.save(category);
286
                        log.debug("Category toggled!");
287
                    } else {
288
                        // EXCEPTION - Category not found in Stakeholder: stakeholder.getAlias(); -> Topic: topic.getAlias();
289
                        throw new PathNotValidException("Toggle category: Category with id: "+category.getId()+" not found in Topic: "+topicId);
290
                    }
291
                } else {
292
                    // EXCEPTION - Topic not found in Stakeholder: stakeholder.getAlias();
293
                    throw new PathNotValidException("Toggle category: Topic with id: "+topicId+" not found in Stakeholder: "+stakeholderId);
294
                }
295
            } else {
296
                // EXCEPTION - Topic not found
297
                throw new EntityNotFoundException("Toggle category: Topic with id: "+topicId+" not found");
298
            }
299
        } else {
300
            // EXCEPTION - Stakeholder not found
301
            throw new EntityNotFoundException("Toggle category: Stakeholder with id: "+stakeholderId+" not found");
302
        }
303
    }
237 304
}

Also available in: Unified diff