Revision 60107
Added by Konstantina Galouni over 3 years ago
SectionController.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; |
... | ... | |
91 | 92 |
section.setUpdateDate(date); |
92 | 93 |
sectionFull.setUpdateDate(date); |
93 | 94 |
|
95 |
List<String> indicators = new ArrayList<>(); |
|
96 |
|
|
94 | 97 |
Section<String> oldSection = null; |
95 | 98 |
if(sectionFull.getId() != null) { |
96 | 99 |
oldSection = sectionDAO.findById(sectionFull.getId()); |
100 |
if(oldSection == null) { |
|
101 |
// EXCEPTION - Section not found |
|
102 |
throw new EntityNotFoundException("save section: Section with id: " + sectionFull.getId() + " not found"); |
|
103 |
} |
|
104 |
|
|
105 |
for(String indicatorId : oldSection.getIndicators()) { |
|
106 |
Indicator indicator = indicatorDAO.findById(indicatorId); |
|
107 |
if (indicator == null) { |
|
108 |
// EXCEPTION - Indicator not found |
|
109 |
throw new EntityNotFoundException("Save section: Indicator with id: "+indicatorId+" not found (indicator exists in section: "+section.getId()+")"); |
|
110 |
} |
|
111 |
indicators.add(indicator.getId()); |
|
112 |
} |
|
97 | 113 |
} else { // section does not exist in DB |
98 | 114 |
section.setCreationDate(date); |
99 | 115 |
sectionFull.setCreationDate(date); |
116 |
|
|
117 |
for(Indicator indicator : sectionFull.getIndicators()) { |
|
118 |
indicators.add(indicator.getId()); |
|
119 |
} |
|
100 | 120 |
} |
101 | 121 |
|
102 | 122 |
String sectionId = sectionFull.getId(); |
103 |
List<String> indicators = new ArrayList<>(); |
|
104 |
for(Indicator indicator : sectionFull.getIndicators()) { |
|
105 |
indicators.add(indicator.getId()); |
|
106 |
} |
|
123 |
|
|
107 | 124 |
section.setIndicators(indicators); |
108 | 125 |
|
109 | 126 |
Stakeholder<String> stakeholder = stakeholderDAO.findById(stakeholderId); |
... | ... | |
223 | 240 |
List<String> roles = rolesUtils.getRoles(); |
224 | 241 |
if(section.getDefaultId() != null && !rolesUtils.hasCreateAndDeleteAuthority(roles, stakeholder.getType())) { |
225 | 242 |
// EXCEPTION - Access denied |
226 |
throw new AccessDeniedException("Delete section: You are not authorized to delete a default Section in stakeholder with id: "+stakeholderId);
|
|
243 |
throw new ForbiddenException("Delete section: You are not authorized to delete a default Section in stakeholder with id: "+stakeholderId);
|
|
227 | 244 |
} |
228 | 245 |
|
229 | 246 |
String type = ""; |
... | ... | |
321 | 338 |
SubCategory<String> subCategory = checkForExceptions(stakeholderId, topicId, categoryId, subcategoryId); |
322 | 339 |
|
323 | 340 |
if (type.equals("chart")) { |
341 |
List<String> oldSections = subCategory.getCharts(); |
|
342 |
for (String sectionId : oldSections) { |
|
343 |
if (!sections.contains(sectionId)) { |
|
344 |
sections.add(sectionId); |
|
345 |
} |
|
346 |
} |
|
324 | 347 |
subCategory.setCharts(sections); |
325 | 348 |
} else if (type.equals("number")) { |
349 |
List<String> oldSections = subCategory.getNumbers(); |
|
350 |
for (String sectionId : oldSections) { |
|
351 |
if (!sections.contains(sectionId)) { |
|
352 |
sections.add(sectionId); |
|
353 |
} |
|
354 |
} |
|
326 | 355 |
subCategory.setNumbers(sections); |
327 | 356 |
} |
328 | 357 |
|
358 |
List<Section> sectionsFull = new ArrayList<>(); |
|
359 |
for(String sectionId : sections) { |
|
360 |
Section section = sectionDAO.findById(sectionId); |
|
361 |
if(section == null) { |
|
362 |
// EXCEPTION - Section not found |
|
363 |
throw new EntityNotFoundException("Reorder sections: Section with id: " + sectionId + " not found"); |
|
364 |
} |
|
365 |
sectionsFull.add(section); |
|
366 |
} |
|
367 |
|
|
329 | 368 |
subCategoryDAO.save(subCategory); |
330 | 369 |
log.debug("Sections reordered!"); |
331 | 370 |
|
332 |
List<Section> sectionsFull = new ArrayList<>(); |
|
333 |
for(String sectionId : sections) { |
|
334 |
sectionsFull.add(sectionDAO.findById(sectionId)); |
|
335 |
} |
|
336 | 371 |
return sectionsFull; |
337 | 372 |
} |
338 | 373 |
|
... | ... | |
411 | 446 |
List<String> roles = rolesUtils.getRoles(); |
412 | 447 |
if(!rolesUtils.hasUpdateAuthority(roles, stakeholder.getType(), stakeholder.getAlias())) { |
413 | 448 |
// EXCEPTION - Access denied |
414 |
throw new AccessDeniedException("CheckForExceptions Section: You are not authorized to update stakeholder with id: "+stakeholderId);
|
|
449 |
throw new ForbiddenException("CheckForExceptions Section: You are not authorized to update stakeholder with id: "+stakeholderId);
|
|
415 | 450 |
} |
416 | 451 |
|
417 | 452 |
Topic<String> topic = topicDAO.findById(topicId); |
Also available in: Unified diff
[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").