Project

General

Profile

« Previous | Next » 

Revision 58992

[Trunk | Monitor Service]:
1. TopicController.java & CategoryController.java & SubCategoryController.java: New methods for reorder added.
2. CategoryController.java: Method "checkForExceptions()" added.
3. IndicatorController.java: [Bug Fix] When updating a default indicator and all indicators based on that are updated too, set description field when needed (not name again).

View differences:

CategoryController.java
320 320
        return true;
321 321
    }
322 322

  
323
    @RequestMapping(value = "/{stakeholderId}/{topicId}/reorder", method = RequestMethod.POST)
324
    public List<Category> reorderCategories(@PathVariable("stakeholderId") String stakeholderId,
325
                                             @PathVariable("topicId") String topicId,
326
                                             @RequestBody List<String> categories) {
327
        log.debug("reorder categories");
328
        log.debug("Stakeholder: "+stakeholderId + " - Topic: "+topicId);
329

  
330
        Topic<String> topic = checkForExceptions(stakeholderId, topicId);
331

  
332
        topic.setCategories(categories);
333

  
334
        topicDAO.save(topic);
335
        log.debug("Categories reordered!");
336

  
337
        List<Category> categoriesFull = new ArrayList<>();
338
        for(String categoryId : categories) {
339
            categoriesFull.add(categoryDAO.findById(categoryId));
340
        }
341
        return categoriesFull;
342
    }
343

  
323 344
    @RequestMapping(value = "/{stakeholderId}/{topicId}/{categoryId}/toggle-status", method = RequestMethod.POST)
324 345
    public Boolean toggleCategoryStatus(@PathVariable("stakeholderId") String stakeholderId,
325 346
                                        @PathVariable("topicId") String topicId,
......
387 408
        }
388 409
    }
389 410

  
411

  
412
    private Topic checkForExceptions(String stakeholderId, String topicId) {
413

  
414
        Stakeholder<String> stakeholder = stakeholderDAO.findById(stakeholderId);
415

  
416
        if(stakeholder == null) {
417
            // EXCEPTION - Stakeholder not found
418
            throw new EntityNotFoundException("checkForExceptions category: Stakeholder with id: " + stakeholderId + " not found");
419
        }
420

  
421
        Topic<String> topic = topicDAO.findById(topicId);
422
        if(topic == null) {
423
            // EXCEPTION - Topic not found
424
            throw new EntityNotFoundException("checkForExceptions category: Topic with id: "+topicId+" not found");
425
        }
426

  
427
        if(!stakeholder.getTopics().contains(topicId)) {
428
            // EXCEPTION - Topic not found in Stakeholder: stakeholder.getAlias();
429
            throw new PathNotValidException("checkForExceptions category: Topic with id: "+topicId+" not found in Stakeholder: "+stakeholderId);
430
        }
431

  
432
        return  topic;
433
    }
434

  
390 435
    public void deleteTree(Topic topic) {
391 436
        List<String> categories = topic.getCategories();
392 437
        for(String categoryId : categories) {

Also available in: Unified diff