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:

modules/uoa-monitor-service/trunk/src/main/java/eu/dnetlib/uoamonitorservice/controllers/IndicatorController.java
122 122
            if(indicator.getDescription() != null && !indicator.getDescription().equals(indicatorBasedOnDefault.getDescription())
123 123
                    && (oldIndicator.getDescription() == null || oldIndicator.getDescription().equals(indicatorBasedOnDefault.getDescription()))) {
124 124

  
125
                indicatorBasedOnDefault.setName(indicator.getName());
125
                indicatorBasedOnDefault.setDescription(indicator.getDescription());
126 126
                changed = true;
127 127
            }
128 128

  
modules/uoa-monitor-service/trunk/src/main/java/eu/dnetlib/uoamonitorservice/controllers/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) {
modules/uoa-monitor-service/trunk/src/main/java/eu/dnetlib/uoamonitorservice/controllers/TopicController.java
297 297
        return true;
298 298
    }
299 299

  
300
    @RequestMapping(value = "/{stakeholderId}/reorder", method = RequestMethod.POST)
301
    public List<Topic> reorderTopics(@PathVariable("stakeholderId") String stakeholderId,
302
                                     @RequestBody List<String> topics) {
303
        log.debug("reorder topics");
304
        log.debug("Stakeholder: "+stakeholderId);
305

  
306
        Stakeholder<String> stakeholder = stakeholderDAO.findById(stakeholderId);
307

  
308
        if(stakeholder != null) {
309
            stakeholder.setTopics(topics);
310

  
311
            stakeholderDAO.save(stakeholder);
312
            log.debug("Topics reordered!");
313

  
314
            List<Topic> topicsFull = new ArrayList<>();
315
            for (String topicId : topics) {
316
                topicsFull.add(topicDAO.findById(topicId));
317
            }
318
            return topicsFull;
319
        } else {
320
            // EXCEPTION - Stakeholder not found
321
            throw new EntityNotFoundException("Reorder topics: Stakeholder with id: "+stakeholderId+" not found");
322
        }
323
    }
324

  
300 325
    @RequestMapping(value = "/{stakeholderId}/{topicId}/toggle-status", method = RequestMethod.POST)
301 326
    public Boolean toggleTopicStatus(@PathVariable("stakeholderId") String stakeholderId,
302 327
                                     @PathVariable("topicId") String topicId) {
modules/uoa-monitor-service/trunk/src/main/java/eu/dnetlib/uoamonitorservice/controllers/SubCategoryController.java
297 297
        return true;
298 298
    }
299 299

  
300
    @RequestMapping(value = "/{stakeholderId}/{topicId}/{categoryId}/reorder", method = RequestMethod.POST)
301
    public List<SubCategory> reorderSubCategories(@PathVariable("stakeholderId") String stakeholderId,
302
                                            @PathVariable("topicId") String topicId,
303
                                            @PathVariable("categoryId") String categoryId,
304
                                            @RequestBody List<String> subCategories) {
305
        log.debug("reorder subCategories");
306
        log.debug("Stakeholder: "+stakeholderId + " - Topic: "+topicId + " - Category: "+categoryId);
307

  
308
        Category<String> category = checkForExceptions(stakeholderId, topicId, categoryId);
309

  
310
        category.setSubCategories(subCategories);
311

  
312
        categoryDAO.save(category);
313
        log.debug("SubCategories reordered!");
314

  
315
        List<SubCategory> subCategoriesFull = new ArrayList<>();
316
        for(String subCategoryId : subCategories) {
317
            subCategoriesFull.add(subCategoryDAO.findById(subCategoryId));
318
        }
319
        return subCategoriesFull;
320
    }
321

  
300 322
    @RequestMapping(value = "/{stakeholderId}/{topicId}/{categoryId}/{subcategoryId}/toggle-status", method = RequestMethod.POST)
301 323
    public Boolean toggleSubCategoryStatus(@PathVariable("stakeholderId") String stakeholderId,
302 324
                                           @PathVariable("topicId") String topicId,

Also available in: Unified diff