Project

General

Profile

« Previous | Next » 

Revision 60107

[Trunk | Monitor Service]:
1. StakeholderController.java & TopicController.java & CategoryController.java & SubCategoryController.java && SectionController.java && IndicatorController.java:
a. Comment logs for get requests.
b. Use "ForbiddenException" instead of "AccessDeniedException"
c. On /save, if full entity has id (already in DB), if not found in DB throw EntityNotFoundException.
d. Get children (e.g. when saving a Topic, get its categories) from DB.
2. TopicController.java & CategoryController.java & SubCategoryController.java & SectionController.java:
In /reorder, if there are in DB, ids that are missing from reordered list, do reordering and add in the end of list the missing ids.
3. ReorderEvent.java: [NEW] Added class ReorderEvent with fields "action" (String), "target" (String), "ids" (List<String>) (used in IndicatorController.java).
4. IndicatorController.java:
a. In /reorder, @RequestBody changed from List<String> indicators to ReorderEvent reorderEvent.
b. If there are in DB, ids that are missing from reordered list AND missing id is not moved to other section (action = removed and target = missing id), do reordering and add in the end of list the missing ids.
5. ExceptionsHandler.java: exception handler methods "invalidInput()", "nullPointerException()", "notFoundException()" moved to "Admin Tools Library" - "accessDeniedException()" is removed.
6. responses/ExceptionResponse.java: File and folder deleted (moved to "Admin Tools Library").
7. RolesUtils.java: Added method "isLoggedIn()" (checks if no roles for user, or user has role "ROLE_ANONYMOUS").

View differences:

SubCategoryController.java
3 3
import eu.dnetlib.uoamonitorservice.dao.*;
4 4
import eu.dnetlib.uoamonitorservice.entities.*;
5 5
import eu.dnetlib.uoamonitorservice.handlers.EntityNotFoundException;
6
import eu.dnetlib.uoaadmintoolslibrary.handlers.ForbiddenException;
6 7
import eu.dnetlib.uoamonitorservice.handlers.PathNotValidException;
7 8
import eu.dnetlib.uoamonitorservice.handlers.utils.RolesUtils;
8 9
import org.apache.log4j.Logger;
......
101 102
        subCategory.setUpdateDate(date);
102 103
        subcategoryFull.setUpdateDate(date);
103 104

  
105
        List<String> chartSections = new ArrayList<>();
106
        List<String> numberSections = new ArrayList<>();
107

  
104 108
        SubCategory<String> oldSubcategory = null;
105 109
        if(subcategoryFull.getId() != null) {
106 110
            oldSubcategory = subCategoryDAO.findById(subcategoryFull.getId());
111
            if(oldSubcategory == null) {
112
                // EXCEPTION - SubCategory not found
113
                throw new EntityNotFoundException("save subcategory: SubCategory with id: " + subcategoryFull.getId() + " not found");
114
            }
115

  
116
            for(String chartSectionId : oldSubcategory.getCharts()) {
117
                Section section = sectionDAO.findById(chartSectionId);
118
                if (section == null) {
119
                    // EXCEPTION - Section not found
120
                    throw new EntityNotFoundException("Save subcategory: Chart section with id: "+chartSectionId+" not found (section exists in subcategory: "+subCategory.getId()+")");
121
                }
122
                chartSections.add(section.getId());
123
            }
124

  
125
            for(String numberSectionId : oldSubcategory.getNumbers()) {
126
                Section section = sectionDAO.findById(numberSectionId);
127
                if (section == null) {
128
                    // EXCEPTION - Section not found
129
                    throw new EntityNotFoundException("Save subcategory: Number section with id: "+numberSectionId+" not found (section exists in subcategory: "+subCategory.getId()+")");
130
                }
131
                numberSections.add(section.getId());
132
            }
107 133
        } else { // subcategory does not exist in DB
108 134
            subCategory.setCreationDate(date);
109 135
            subcategoryFull.setCreationDate(date);
136

  
137
            for(Section chartSection : subcategoryFull.getCharts()) {
138
                chartSections.add(chartSection.getId());
139
            }
140

  
141
            for(Section numberSection : subcategoryFull.getNumbers()) {
142
                numberSections.add(numberSection.getId());
143
            }
110 144
        }
111 145

  
112 146
//        List<String> charts = new ArrayList<>();
......
121 155
//        }
122 156
//        subCategory.setNumbers(numbers);
123 157

  
124
        List<String> chartSections = new ArrayList<>();
125
        for(Section chartSection : subcategoryFull.getCharts()) {
126
            chartSections.add(chartSection.getId());
127
        }
158

  
128 159
        subCategory.setCharts(chartSections);
129

  
130
        List<String> numberSections = new ArrayList<>();
131
        for(Section numberSection : subcategoryFull.getNumbers()) {
132
            numberSections.add(numberSection.getId());
133
        }
134 160
        subCategory.setNumbers(numberSections);
135 161

  
136 162
        Stakeholder<String> stakeholder = stakeholderDAO.findById(stakeholderId);
......
231 257
            List<String> roles = rolesUtils.getRoles();
232 258
            if(subcategory.getDefaultId() != null && !rolesUtils.hasCreateAndDeleteAuthority(roles, stakeholder.getType())) {
233 259
                // EXCEPTION - Access denied
234
                throw new AccessDeniedException("Delete subcategory: You are not authorized to delete a default SubCategory in stakeholder with id: "+stakeholderId);
260
                throw new ForbiddenException("Delete subcategory: You are not authorized to delete a default SubCategory in stakeholder with id: "+stakeholderId);
235 261
            }
236 262

  
237 263
            List<String> subcategories = category.getSubCategories();
......
344 370

  
345 371
        Category<String> category = checkForExceptions(stakeholderId, topicId, categoryId);
346 372

  
373
        List<String> oldSubcategories = category.getSubCategories();
374
        for (String subcategoryId : oldSubcategories) {
375
            if (!subCategories.contains(subcategoryId)) {
376
                subCategories.add(subcategoryId);
377
            }
378
        }
347 379
        category.setSubCategories(subCategories);
348 380

  
381
        List<SubCategory> subCategoriesFull = new ArrayList<>();
382
        for(String subCategoryId : subCategories) {
383
            SubCategory subCategory = subCategoryDAO.findById(subCategoryId);
384
            if(subCategory == null) {
385
                // EXCEPTION - SubCategory not found
386
                throw new EntityNotFoundException("Reorder subCategories: subCategory with id: " + subCategoryId + " not found");
387
            }
388
            subCategoriesFull.add(subCategory);
389
        }
390

  
349 391
        categoryDAO.save(category);
350 392
        log.debug("SubCategories reordered!");
351 393

  
352
        List<SubCategory> subCategoriesFull = new ArrayList<>();
353
        for(String subCategoryId : subCategories) {
354
            subCategoriesFull.add(subCategoryDAO.findById(subCategoryId));
355
        }
356 394
        return subCategoriesFull;
357 395
    }
358 396

  
......
443 481
        List<String> roles = rolesUtils.getRoles();
444 482
        if(!rolesUtils.hasUpdateAuthority(roles, stakeholder.getType(), stakeholder.getAlias())) {
445 483
            // EXCEPTION - Access denied
446
            throw new AccessDeniedException("CheckForExceptions SubCategory: You are not authorized to update stakeholder with id: "+stakeholderId);
484
            throw new ForbiddenException("CheckForExceptions SubCategory: You are not authorized to update stakeholder with id: "+stakeholderId);
447 485
        }
448 486

  
449 487
        Topic<String> topic = topicDAO.findById(topicId);

Also available in: Unified diff