[Trunk | Admin Tools service]:

1. Statistics.java: Added "isActive" field (default value: true).
2. StatisticsController.java: Added toggleStatistics method (/statistics/{id}/toggle) for activating/ deactivating statistics.
This commit is contained in:
Konstantina Galouni 2020-04-01 12:52:09 +00:00
parent a642920ba7
commit 3e494fd665
2 changed files with 20 additions and 0 deletions

View File

@ -38,6 +38,15 @@ public class StatisticsController {
return statistics;
}
@RequestMapping(value = "/statistics/{id}/toggle", method = RequestMethod.POST)
public Boolean toggleStatistics(@PathVariable String id) throws Exception {
Statistics statistics = statisticsDAO.findById(id);
boolean status = statistics.getIsActive();
statistics.setIsActive(!status);
statisticsDAO.save(statistics);
return statistics.getIsActive();
}
@RequestMapping(value = "/statistics/save", method = RequestMethod.POST)
public Statistics insertStatistics(@RequestBody Statistics statistics) {
Statistics savedStatistics = statisticsDAO.save(statistics);

View File

@ -14,9 +14,11 @@ public class Statistics {
@JsonProperty("_id")
private String id;
private String pid;
private boolean isActive = true;
Map<String,StatisticsEntity> entities = new HashMap<String, StatisticsEntity>();
public Statistics(String pid){
this.pid = pid;
this.isActive = true;
entities.put("publication",new StatisticsEntity());
entities.put("dataset",new StatisticsEntity());
entities.put("software",new StatisticsEntity());
@ -38,6 +40,14 @@ public class Statistics {
this.pid = pid;
}
public boolean getIsActive() {
return isActive;
}
public void setIsActive(boolean isActive) {
this.isActive = isActive;
}
public Map<String, StatisticsEntity> getEntities() {
return entities;
}
@ -51,6 +61,7 @@ public class Statistics {
return "Statistics{" +
"id='" + id + '\'' +
", pid='" + pid + '\'' +
", isActive= "+isActive +
", entities=" + entities +
'}';
}