Revision 60107
Added by Konstantina Galouni over 3 years ago
IndicatorController.java | ||
---|---|---|
4 | 4 |
import eu.dnetlib.uoamonitorservice.dao.*; |
5 | 5 |
import eu.dnetlib.uoamonitorservice.entities.*; |
6 | 6 |
import eu.dnetlib.uoamonitorservice.handlers.EntityNotFoundException; |
7 |
import eu.dnetlib.uoaadmintoolslibrary.handlers.ForbiddenException; |
|
7 | 8 |
import eu.dnetlib.uoamonitorservice.handlers.PathNotValidException; |
8 | 9 |
import eu.dnetlib.uoamonitorservice.handlers.utils.RolesUtils; |
9 | 10 |
import org.apache.log4j.Logger; |
... | ... | |
13 | 14 |
import org.springframework.web.bind.annotation.*; |
14 | 15 |
|
15 | 16 |
import java.io.UnsupportedEncodingException; |
17 |
import java.lang.reflect.Field; |
|
16 | 18 |
import java.net.URLEncoder; |
17 | 19 |
import java.util.*; |
18 | 20 |
|
... | ... | |
62 | 64 |
Indicator oldIndicator = null; |
63 | 65 |
if(indicator.getId() != null) { |
64 | 66 |
oldIndicator = indicatorDAO.findById(indicator.getId()); |
67 |
if(oldIndicator == null) { |
|
68 |
// EXCEPTION - Indicator not found |
|
69 |
throw new EntityNotFoundException("save indicator: Indicator with id: " + indicator.getId() + " not found"); |
|
70 |
} |
|
65 | 71 |
} else { // indicator does not exist in DB |
66 | 72 |
indicator.setCreationDate(date); |
67 | 73 |
} |
... | ... | |
387 | 393 |
List<String> roles = rolesUtils.getRoles(); |
388 | 394 |
if(indicator.getDefaultId() != null && !rolesUtils.hasCreateAndDeleteAuthority(roles, stakeholder.getType())) { |
389 | 395 |
// EXCEPTION - Access denied |
390 |
throw new AccessDeniedException("Delete indicator: You are not authorized to delete a default Indicator in stakeholder with id: "+stakeholderId);
|
|
396 |
throw new ForbiddenException("Delete indicator: You are not authorized to delete a default Indicator in stakeholder with id: "+stakeholderId);
|
|
391 | 397 |
} |
392 | 398 |
|
393 | 399 |
List<String> indicators = section.getIndicators(); |
... | ... | |
568 | 574 |
@PathVariable("subcategoryId") String subcategoryId, |
569 | 575 |
@PathVariable("sectionId") String sectionId, |
570 | 576 |
@PathVariable("type") String type, |
571 |
@RequestBody List<String> indicators) {
|
|
577 |
@RequestBody ReorderEvent reorderEvent) {
|
|
572 | 578 |
log.debug("reorder indicators of type: "+type); |
573 | 579 |
log.debug("Stakeholder: "+stakeholderId + " - Topic: "+topicId + " - Category: "+categoryId+ " - SubCategory: "+subcategoryId + " - Section: "+sectionId); |
574 | 580 |
|
581 |
List<String> indicators = reorderEvent.getIds(); |
|
582 |
String actionType = reorderEvent.getAction(); |
|
583 |
String targetId = reorderEvent.getTarget(); |
|
584 |
|
|
575 | 585 |
Section<String> section = checkForExceptions(stakeholderId, topicId, categoryId, subcategoryId, sectionId, type); |
576 | 586 |
|
587 |
List<String> oldIndicators = section.getIndicators(); |
|
588 |
for (String indicatorId : oldIndicators) { |
|
589 |
if ((!actionType.equals("removed") || !targetId.equals(indicatorId)) && !indicators.contains(indicatorId)) { |
|
590 |
indicators.add(indicatorId); |
|
591 |
} |
|
592 |
} |
|
577 | 593 |
section.setIndicators(indicators); |
578 | 594 |
|
595 |
List<Indicator> indicatorsFull = new ArrayList<>(); |
|
596 |
for(String indicatorId : indicators) { |
|
597 |
Indicator indicator = indicatorDAO.findById(indicatorId); |
|
598 |
if(indicator == null) { |
|
599 |
// EXCEPTION - Indicator not found |
|
600 |
throw new EntityNotFoundException("Reorder indicators: Indicator with id: " + indicatorId + " not found"); |
|
601 |
} |
|
602 |
indicatorsFull.add(indicator); |
|
603 |
} |
|
604 |
|
|
579 | 605 |
sectionDAO.save(section); |
580 | 606 |
log.debug("Indicators reordered!"); |
581 | 607 |
|
582 |
List<Indicator> indicatorsFull = new ArrayList<>(); |
|
583 |
for(String indicatorId : indicators) { |
|
584 |
indicatorsFull.add(indicatorDAO.findById(indicatorId)); |
|
585 |
} |
|
586 | 608 |
return indicatorsFull; |
587 | 609 |
} |
588 | 610 |
|
... | ... | |
680 | 702 |
List<String> roles = rolesUtils.getRoles(); |
681 | 703 |
if(!rolesUtils.hasUpdateAuthority(roles, stakeholder.getType(), stakeholder.getAlias())) { |
682 | 704 |
// EXCEPTION - Access denied |
683 |
throw new AccessDeniedException("CheckForExceptions Indicator: You are not authorized to update stakeholder with id: "+stakeholderId);
|
|
705 |
throw new ForbiddenException("CheckForExceptions Indicator: You are not authorized to update stakeholder with id: "+stakeholderId);
|
|
684 | 706 |
} |
685 | 707 |
|
686 | 708 |
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").