Skip to content
This repository has been archived by the owner on Oct 2, 2023. It is now read-only.

Commit

Permalink
Merge pull request #278 from dcanar9/master
Browse files Browse the repository at this point in the history
Added admin tag to endpoint, added logging, cleaned up code
  • Loading branch information
nameisaravind authored May 19, 2022
2 parents ce4b6b9 + 83a5e71 commit 18b0b44
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<artifactId>api</artifactId>
<packaging>jar</packaging>
<name>${project.groupId}:${project.artifactId}</name>
<version>3.4.37</version>
<version>3.4.38</version>
<description>Hygieia Rest API Layer</description>
<url>https://github.com/Hygieia/api</url>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

import javax.validation.Valid;

import com.capitalone.dashboard.auth.access.Admin;
import com.capitalone.dashboard.util.PaginationHeaderUtility;
import org.bson.types.ObjectId;
import org.slf4j.Logger;
Expand Down Expand Up @@ -482,9 +483,10 @@ public ResponseEntity<List<Dashboard>> myDashboardByTitlePage(@RequestParam(valu
.body(pageDashboardItems.getContent());
}

@Admin
@RequestMapping(value = "/dashboard/removeWidgetDuplicates", method = DELETE)
public ResponseEntity<String> removeWidgetDuplicates(@RequestParam(value="title", required = false)String title,
@RequestParam(value="dryRun", required = true) boolean dryRun){
@RequestParam(value="dryRun", required = true, defaultValue = "true") boolean dryRun){
String message = dashboardService.removeWidgetDuplicatesHelper(title, dryRun);
return ResponseEntity.ok().body(message);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1018,31 +1018,29 @@ public String removeWidgetDuplicatesHelper(String title, boolean dryRun){
pageable = pageable.next();
page = findDashboardsByPage("", pageable);
}
}
else{
List<Dashboard> dashboards = dashboardRepository.findByTitle(title);
if (CollectionUtils.isEmpty(dashboards)){return "No dashboards with that title";}
removeWidgetDuplicates(dashboards, dryRun);
}

// messages upon success
if(StringUtils.isEmpty(title)){
if(dryRun){
LOG.info("DRY_RUN: All Dashboard widgets cleaned");
return "DRY_RUN: All Dashboard widgets cleaned";
} else{
LOG.info("All Dashboard widgets cleaned");
return "All Dashboard widgets cleaned";
}
}
else {
else{
List<Dashboard> dashboards = dashboardRepository.findByTitle(title);
if (CollectionUtils.isEmpty(dashboards)){return "No dashboards with that title";}
removeWidgetDuplicates(dashboards, dryRun);

if(dryRun){
return "DRY_RUN: Cleaned widgets for dashboard " + title;
} else{
return "Cleaned widgets for dashboard " + title;
}
}

}


@Override
public void removeWidgetDuplicates(List<Dashboard> dashboards, boolean dryRun) {

Expand Down

0 comments on commit 18b0b44

Please sign in to comment.