Project

General

Profile

« Previous | Next » 

Revision 60499

[Trunk | Admin Tools]:
1. SubscriberController.java & PortalSubscribersController.java: Commented POST/ DELETE methods from controllers related to subscribers (these files will be deleted after migration of roles to AAI).
2. StatisticsController.java: Commented all methods (file and statistics schema in general need update - currently not working).

View differences:

modules/uoa-admin-tools/trunk/src/main/java/eu/dnetlib/uoaadmintools/controllers/SubscriberController.java
34 34
        }
35 35
        return subscriber;
36 36
    }
37
    @RequestMapping(value = "/subscriber", method = RequestMethod.POST)
38
    public Subscriber saveSubscriber(@RequestBody Subscriber subscriber) {
39
        return subscriberDAO.save(subscriber);
40
    }
41
    @RequestMapping(value = "/subscriber/{email}", method = RequestMethod.DELETE)
42
    public void deleteSubscriber(@PathVariable(value="email", required = true) String email) throws ContentNotFoundException {
43
        Subscriber subscriber = subscriberDAO.findByEmail(email);
44
        if(subscriber == null){
45
            throw new ContentNotFoundException("Subscribers not found");
46
        }
47
        subscriberDAO.delete(subscriber.getId());
37
//    @RequestMapping(value = "/subscriber", method = RequestMethod.POST)
38
//    public Subscriber saveSubscriber(@RequestBody Subscriber subscriber) {
39
//        return subscriberDAO.save(subscriber);
40
//    }
41
//    @RequestMapping(value = "/subscriber/{email}", method = RequestMethod.DELETE)
42
//    public void deleteSubscriber(@PathVariable(value="email", required = true) String email) throws ContentNotFoundException {
43
//        Subscriber subscriber = subscriberDAO.findByEmail(email);
44
//        if(subscriber == null){
45
//            throw new ContentNotFoundException("Subscribers not found");
46
//        }
47
//        subscriberDAO.delete(subscriber.getId());
48
//
49
//    }
48 50

  
49
    }
50

  
51 51
}
modules/uoa-admin-tools/trunk/src/main/java/eu/dnetlib/uoaadmintools/controllers/PortalSubscribersController.java
1 1
package eu.dnetlib.uoaadmintools.controllers;
2 2

  
3
import eu.dnetlib.uoaadmintools.configuration.properties.SecurityConfig;
3
//import eu.dnetlib.uoaadmintools.configuration.properties.SecurityConfig;
4 4
import eu.dnetlib.uoaadmintools.dao.PortalSubscribersDAO;
5 5
import eu.dnetlib.uoaadmintools.dao.SubscriberDAO;
6 6
import eu.dnetlib.uoaadmintools.entities.subscriber.PortalSubscribers;
......
8 8
import eu.dnetlib.uoaadmintoolslibrary.handlers.ContentNotFoundException;
9 9
import eu.dnetlib.uoaadmintools.handlers.utils.AuthorizationUtils;
10 10
import eu.dnetlib.uoaadmintools.handlers.utils.UserInfo;
11
import eu.dnetlib.uoaadmintools.responses.SingleValueWrapperResponse;
11
import eu.dnetlib.uoaadmintoolslibrary.responses.SingleValueWrapperResponse;
12 12
import eu.dnetlib.uoaadmintoolslibrary.dao.PortalDAO;
13 13
import org.apache.log4j.Logger;
14 14
import org.springframework.beans.factory.annotation.Autowired;
......
31 31
    @Autowired
32 32
    PortalDAO portalDAO;
33 33

  
34
    @Autowired
35
    private SecurityConfig securityConfig;
34
//    @Autowired
35
//    private SecurityConfig securityConfig;
36 36

  
37 37
    private final Logger log = Logger.getLogger(this.getClass());
38 38

  
......
91 91
//
92 92
//    }
93 93

  
94
    @RequestMapping(value = "/community/{pid}/is-subscriber", method = RequestMethod.GET)
95
    public Boolean getIsSubscribedToPortal(@PathVariable(value="pid", required = true) String pid,
96
                                              //@RequestBody String email,
97
                                              @RequestHeader("X-XSRF-TOKEN") String token) throws ContentNotFoundException {
98
        AuthorizationUtils helper = new AuthorizationUtils();
99
        helper.setUserInfoUrl(securityConfig.getUserInfoUrl());
100
        UserInfo userInfo = helper.getUserInfo(token);
101

  
102
        if(userInfo != null) {
103
            String email = userInfo.getEmail();
104
            PortalSubscribers communitySubscribers = portalSubscribersDAO.findByPid(pid);
105
            if (communitySubscribers != null) {
106
                if (communitySubscribers.getSubscribers() != null) {
107
                    for (Subscriber subscriber : communitySubscribers.getSubscribers()) {
108
                        if (subscriber.getEmail().equals(email)) {
109
                            return true;
110
                        }
111
                    }
112
                }
113
            } else {
114
                throw new ContentNotFoundException("Portal Subscribers not found");
115

  
116
            }
117
        }
118
        return false;
119
    }
120

  
121
    @RequestMapping(value = "/community/{pid}/subscriber", method = RequestMethod.POST)
122
    public Boolean addSubscriberInPortal(@PathVariable(value="pid", required = true) String pid,
123
                                         @RequestHeader("X-XSRF-TOKEN") String token) throws ContentNotFoundException {
124
        AuthorizationUtils helper = new AuthorizationUtils();
125
        helper.setUserInfoUrl(securityConfig.getUserInfoUrl());
126
        UserInfo userInfo = helper.getUserInfo(token);
127

  
128
        if(userInfo != null) {
129
            String email = userInfo.getEmail();
130
            Subscriber subscriber = new Subscriber(email);
131

  
132
            PortalSubscribers communitySubscribers = portalSubscribersDAO.findByPid(pid);
133
            if (communitySubscribers == null) {
134
                throw new ContentNotFoundException("Community Subscribers not found");
135
            }
136

  
137
            Subscriber savedSubscriber = subscriberDAO.findByEmail(email);
138
            if (savedSubscriber == null) {
139
                savedSubscriber = subscriberDAO.save(subscriber);
140
            }
141
            for (Subscriber sub : communitySubscribers.getSubscribers()) {
142
                if (sub.getEmail().equals(subscriber.getEmail())) {
143
                    //already subscribed
144
                    return false;
145
                }
146
            }
147
            //not subscribed yet
148
            communitySubscribers.getSubscribers().add(savedSubscriber);
149
            portalSubscribersDAO.save(communitySubscribers);
150
            return true;
151
        }
152
        return false;
153

  
154
    }
155
    @RequestMapping(value = "/community/{pid}/subscriber/delete", method = RequestMethod.POST)
156
    public Boolean deleteSubscriberFromPortal(@PathVariable(value="pid", required = true) String pid,
157
                                                 @RequestHeader("X-XSRF-TOKEN") String token) throws ContentNotFoundException {
158
        AuthorizationUtils helper = new AuthorizationUtils();
159
        helper.setUserInfoUrl(securityConfig.getUserInfoUrl());
160
        UserInfo userInfo = helper.getUserInfo(token);
161

  
162
        if(userInfo != null) {
163
            String email = userInfo.getEmail();
164

  
165
            PortalSubscribers communitySubscribers = portalSubscribersDAO.findByPid(pid);
166
            if (communitySubscribers == null) {
167
                throw new ContentNotFoundException("Community Subscribers not found");
168
            }
169

  
170
            Iterator<Subscriber> subscriberIterator = communitySubscribers.getSubscribers().iterator();
171
            while(subscriberIterator.hasNext()) {
172
                Subscriber subscriber = subscriberIterator.next();
173
                if(subscriber.getEmail().equals(email)) {
174
                    subscriberIterator.remove();
175
                    portalSubscribersDAO.save(communitySubscribers);
176
                    return true;
177
                }
178
            }
179
        }
180
        return false;
181
    }
182

  
183
    @RequestMapping(value = "/community/{pid}/subscribers", method = RequestMethod.POST)
184
    public PortalSubscribers addSubscriberInPortalByEmail(@PathVariable(value="pid", required = true) String pid, @RequestBody Subscriber subscriber) throws ContentNotFoundException {
185
        PortalSubscribers communitySubscribers = portalSubscribersDAO.findByPid(pid);
186
        if(communitySubscribers == null){
187
            throw new ContentNotFoundException("Community Subscribers not found");
188
        }
189

  
190
        Subscriber savedSubscriber = subscriberDAO.findByEmail(subscriber.getEmail());
191
        if(savedSubscriber==null){
192
            savedSubscriber = subscriberDAO.save(subscriber);
193
        }
194
        for(Subscriber sub:communitySubscribers.getSubscribers()){
195
            if(sub.getEmail().equals(subscriber.getEmail())){
196
                //already subscribed
197
                return communitySubscribers;
198
            }
199
        }
200
        //not subscribed yet
201
        communitySubscribers.getSubscribers().add(savedSubscriber);
202
        return portalSubscribersDAO.save(communitySubscribers);
203

  
204
    }
205
    @RequestMapping(value = "/community/{pid}/subscribers/delete", method = RequestMethod.POST)
206
    public PortalSubscribers deleteSubscriberFromPortalByEmail(@PathVariable(value="pid", required = true) String pid, @RequestBody List<String> emails) throws ContentNotFoundException {
207
        PortalSubscribers communitySubscribers = portalSubscribersDAO.findByPid(pid);
208
        if(communitySubscribers == null){
209
            throw new ContentNotFoundException("Community Subscribers not found");
210
        }
211
        List<Subscriber> list = new ArrayList<>();
212
        for(Subscriber s:communitySubscribers.getSubscribers()){
213
            if(emails.indexOf(s.getEmail())==-1){
214
                list.add(s);
215
            }
216
        }
217
        communitySubscribers.setSubscribers(list);
218
        return portalSubscribersDAO.save(communitySubscribers);
219
    }
220

  
221
    @RequestMapping(value = "/subscriber/communities", method = RequestMethod.GET)
222
    public List<String> getPortalsPerSubcriber(//@RequestParam(value="email", required = true) String email,
223
                                                   @RequestHeader("X-XSRF-TOKEN") String token) {
224
        AuthorizationUtils helper = new AuthorizationUtils();
225
        helper.setUserInfoUrl(securityConfig.getUserInfoUrl());
226
        UserInfo userInfo = helper.getUserInfo(token);
227

  
228
        List<String> list = new ArrayList<>();
229

  
230
        if (userInfo != null) {
231
            String email = userInfo.getEmail();
232
            List<PortalSubscribers> communitySubscribers = portalSubscribersDAO.findAll();
233

  
234
            for (PortalSubscribers s : communitySubscribers) {
235
                for (Subscriber sub : s.getSubscribers()) {
236
                    if (sub.getEmail().equals(email)) {
237
                        list.add(s.getPid());
238
                        break;
239
                    }
240
                }
241
            }
242
        }
243
        return list;
244
    }
94
//    @RequestMapping(value = "/community/{pid}/is-subscriber", method = RequestMethod.GET)
95
//    public Boolean getIsSubscribedToPortal(@PathVariable(value="pid", required = true) String pid,
96
//                                              //@RequestBody String email,
97
//                                              @RequestHeader("X-XSRF-TOKEN") String token) throws ContentNotFoundException {
98
//        AuthorizationUtils helper = new AuthorizationUtils();
99
//        helper.setUserInfoUrl(securityConfig.getUserInfoUrl());
100
//        UserInfo userInfo = helper.getUserInfo(token);
101
//
102
//        if(userInfo != null) {
103
//            String email = userInfo.getEmail();
104
//            PortalSubscribers communitySubscribers = portalSubscribersDAO.findByPid(pid);
105
//            if (communitySubscribers != null) {
106
//                if (communitySubscribers.getSubscribers() != null) {
107
//                    for (Subscriber subscriber : communitySubscribers.getSubscribers()) {
108
//                        if (subscriber.getEmail().equals(email)) {
109
//                            return true;
110
//                        }
111
//                    }
112
//                }
113
//            } else {
114
//                throw new ContentNotFoundException("Portal Subscribers not found");
115
//
116
//            }
117
//        }
118
//        return false;
119
//    }
120
//
121
//    @RequestMapping(value = "/community/{pid}/subscriber", method = RequestMethod.POST)
122
//    public Boolean addSubscriberInPortal(@PathVariable(value="pid", required = true) String pid,
123
//                                         @RequestHeader("X-XSRF-TOKEN") String token) throws ContentNotFoundException {
124
//        AuthorizationUtils helper = new AuthorizationUtils();
125
//        helper.setUserInfoUrl(securityConfig.getUserInfoUrl());
126
//        UserInfo userInfo = helper.getUserInfo(token);
127
//
128
//        if(userInfo != null) {
129
//            String email = userInfo.getEmail();
130
//            Subscriber subscriber = new Subscriber(email);
131
//
132
//            PortalSubscribers communitySubscribers = portalSubscribersDAO.findByPid(pid);
133
//            if (communitySubscribers == null) {
134
//                throw new ContentNotFoundException("Community Subscribers not found");
135
//            }
136
//
137
//            Subscriber savedSubscriber = subscriberDAO.findByEmail(email);
138
//            if (savedSubscriber == null) {
139
//                savedSubscriber = subscriberDAO.save(subscriber);
140
//            }
141
//            for (Subscriber sub : communitySubscribers.getSubscribers()) {
142
//                if (sub.getEmail().equals(subscriber.getEmail())) {
143
//                    //already subscribed
144
//                    return false;
145
//                }
146
//            }
147
//            //not subscribed yet
148
//            communitySubscribers.getSubscribers().add(savedSubscriber);
149
//            portalSubscribersDAO.save(communitySubscribers);
150
//            return true;
151
//        }
152
//        return false;
153
//
154
//    }
155
//    @RequestMapping(value = "/community/{pid}/subscriber/delete", method = RequestMethod.POST)
156
//    public Boolean deleteSubscriberFromPortal(@PathVariable(value="pid", required = true) String pid,
157
//                                                 @RequestHeader("X-XSRF-TOKEN") String token) throws ContentNotFoundException {
158
//        AuthorizationUtils helper = new AuthorizationUtils();
159
//        helper.setUserInfoUrl(securityConfig.getUserInfoUrl());
160
//        UserInfo userInfo = helper.getUserInfo(token);
161
//
162
//        if(userInfo != null) {
163
//            String email = userInfo.getEmail();
164
//
165
//            PortalSubscribers communitySubscribers = portalSubscribersDAO.findByPid(pid);
166
//            if (communitySubscribers == null) {
167
//                throw new ContentNotFoundException("Community Subscribers not found");
168
//            }
169
//
170
//            Iterator<Subscriber> subscriberIterator = communitySubscribers.getSubscribers().iterator();
171
//            while(subscriberIterator.hasNext()) {
172
//                Subscriber subscriber = subscriberIterator.next();
173
//                if(subscriber.getEmail().equals(email)) {
174
//                    subscriberIterator.remove();
175
//                    portalSubscribersDAO.save(communitySubscribers);
176
//                    return true;
177
//                }
178
//            }
179
//        }
180
//        return false;
181
//    }
182
//
183
//    @RequestMapping(value = "/community/{pid}/subscribers", method = RequestMethod.POST)
184
//    public PortalSubscribers addSubscriberInPortalByEmail(@PathVariable(value="pid", required = true) String pid, @RequestBody Subscriber subscriber) throws ContentNotFoundException {
185
//        PortalSubscribers communitySubscribers = portalSubscribersDAO.findByPid(pid);
186
//        if(communitySubscribers == null){
187
//            throw new ContentNotFoundException("Community Subscribers not found");
188
//        }
189
//
190
//        Subscriber savedSubscriber = subscriberDAO.findByEmail(subscriber.getEmail());
191
//        if(savedSubscriber==null){
192
//            savedSubscriber = subscriberDAO.save(subscriber);
193
//        }
194
//        for(Subscriber sub:communitySubscribers.getSubscribers()){
195
//            if(sub.getEmail().equals(subscriber.getEmail())){
196
//                //already subscribed
197
//                return communitySubscribers;
198
//            }
199
//        }
200
//        //not subscribed yet
201
//        communitySubscribers.getSubscribers().add(savedSubscriber);
202
//        return portalSubscribersDAO.save(communitySubscribers);
203
//
204
//    }
205
//    @RequestMapping(value = "/community/{pid}/subscribers/delete", method = RequestMethod.POST)
206
//    public PortalSubscribers deleteSubscriberFromPortalByEmail(@PathVariable(value="pid", required = true) String pid, @RequestBody List<String> emails) throws ContentNotFoundException {
207
//        PortalSubscribers communitySubscribers = portalSubscribersDAO.findByPid(pid);
208
//        if(communitySubscribers == null){
209
//            throw new ContentNotFoundException("Community Subscribers not found");
210
//        }
211
//        List<Subscriber> list = new ArrayList<>();
212
//        for(Subscriber s:communitySubscribers.getSubscribers()){
213
//            if(emails.indexOf(s.getEmail())==-1){
214
//                list.add(s);
215
//            }
216
//        }
217
//        communitySubscribers.setSubscribers(list);
218
//        return portalSubscribersDAO.save(communitySubscribers);
219
//    }
220
//
221
//    @RequestMapping(value = "/subscriber/communities", method = RequestMethod.GET)
222
//    public List<String> getPortalsPerSubcriber(//@RequestParam(value="email", required = true) String email,
223
//                                                   @RequestHeader("X-XSRF-TOKEN") String token) {
224
//        AuthorizationUtils helper = new AuthorizationUtils();
225
//        helper.setUserInfoUrl(securityConfig.getUserInfoUrl());
226
//        UserInfo userInfo = helper.getUserInfo(token);
227
//
228
//        List<String> list = new ArrayList<>();
229
//
230
//        if (userInfo != null) {
231
//            String email = userInfo.getEmail();
232
//            List<PortalSubscribers> communitySubscribers = portalSubscribersDAO.findAll();
233
//
234
//            for (PortalSubscribers s : communitySubscribers) {
235
//                for (Subscriber sub : s.getSubscribers()) {
236
//                    if (sub.getEmail().equals(email)) {
237
//                        list.add(s.getPid());
238
//                        break;
239
//                    }
240
//                }
241
//            }
242
//        }
243
//        return list;
244
//    }
245 245
}
modules/uoa-admin-tools/trunk/src/main/java/eu/dnetlib/uoaadmintools/controllers/StatisticsController.java
1
package eu.dnetlib.uoaadmintools.controllers;
2

  
3
import eu.dnetlib.uoaadmintools.dao.*;
4
import eu.dnetlib.uoaadmintools.entities.statistics.*;
5
import eu.dnetlib.uoaadmintoolslibrary.handlers.ContentNotFoundException;
6
import org.apache.log4j.Logger;
7
import org.springframework.beans.factory.annotation.Autowired;
8
import org.springframework.web.bind.annotation.*;
9

  
10
import java.util.*;
11

  
12
@RestController
13
@CrossOrigin(origins = "*")
14
public class StatisticsController {
15
    private final Logger log = Logger.getLogger(this.getClass());
16

  
17
    @Autowired
18
    private StatisticsDAO statisticsDAO;
19

  
20
    @RequestMapping(value = "/statistics", method = RequestMethod.GET)
21
    public List<Statistics> getAllStatistics() throws ContentNotFoundException {
22
        log.info("getAllStatistics");
23
            List<Statistics> statistics = statisticsDAO.findAll();
24
         if(statistics == null){
25
            throw new ContentNotFoundException("Statistics not found");
26
        }
27
            return statistics;
28
    }
29

  
30

  
31

  
32
    @RequestMapping(value = "/statistics/{pid}", method = RequestMethod.GET)
33
    public Statistics getStatistics(@PathVariable(value = "pid") String pid) throws ContentNotFoundException {
34
        Statistics statistics = statisticsDAO.findByPid(pid);
35
        if(statistics == null){
36
            throw new ContentNotFoundException("Statistics not found");
37
        }
38
        return statistics;
39
    }
40

  
41
    @RequestMapping(value = "/statistics/{id}/toggle", method = RequestMethod.POST)
42
    public Boolean toggleStatistics(@PathVariable String id) throws Exception {
43
        Statistics statistics = statisticsDAO.findById(id);
44
        boolean status = statistics.getIsActive();
45
        statistics.setIsActive(!status);
46
        statisticsDAO.save(statistics);
47
        return statistics.getIsActive();
48
    }
49

  
50
    @RequestMapping(value = "/statistics/save", method = RequestMethod.POST)
51
    public Statistics insertStatistics(@RequestBody Statistics statistics) {
52
        Statistics savedStatistics = statisticsDAO.save(statistics);
53
        return savedStatistics;
54
    }
55

  
56

  
57

  
58
    @RequestMapping(value = "/statistics/delete", method = RequestMethod.POST)
59
    public Boolean deleteStatistics(@RequestBody List<String> statistics) throws Exception {
60
        for (String id: statistics) {
61
            statisticsDAO.delete(id);
62
         }
63
        return true;
64
    }
65

  
66

  
67

  
68

  
69
    @RequestMapping(value = "statistics/{pid}/{entity}/charts", method = RequestMethod.POST)
70
    public Statistics toggleCharts(@PathVariable(value = "pid") String pid, @PathVariable(value = "entity") String entity, @RequestBody String key, @RequestParam String status, @RequestParam String monitor) throws ContentNotFoundException {
71
        Statistics statistics = statisticsDAO.findByPid(pid);
72
        if(statistics == null){
73
            throw new ContentNotFoundException("Statistics not found  for portal");
74
        }
75
        StatisticsEntity statisticsEntity = statistics.getEntities().get(entity);
76
        if(statisticsEntity == null ){
77
            throw new ContentNotFoundException("Statistics not found for entity");
78
        }
79
        ChartsMap charts = statisticsEntity.getCharts();
80
        if(charts == null){
81
            throw new ContentNotFoundException("Statistics not found - no charts");
82
        }
83
        StatisticsStatus statisticsStatus= charts.getMap().get(key);
84
        if(statisticsStatus == null){
85
            throw new ContentNotFoundException("Statistics not found for key");
86
        }
87
        if(Boolean.parseBoolean(monitor)){
88
            statisticsStatus.setShowInMonitor(Boolean.parseBoolean(status));
89
        }else{
90
            statisticsStatus.setShowInDashboard(Boolean.parseBoolean(status));
91
        }
92
//        stats.put(key,statisticsStatus);
93
        return statisticsDAO.save(statistics);
94
    }
95
    @RequestMapping(value = "statistics/{pid}/{entity}/numbers", method = RequestMethod.POST)
96
    public Statistics toggleNumber(@PathVariable(value = "pid") String pid, @PathVariable(value = "entity") String entity, @RequestBody String key, @RequestParam String status, @RequestParam String monitor) throws ContentNotFoundException {
97
        Statistics statistics = statisticsDAO.findByPid(pid);
98
        if(statistics == null){
99
            throw new ContentNotFoundException("Statistics not found  for portal");
100
        }
101
        StatisticsEntity statisticsEntity = statistics.getEntities().get(entity);
102
        if(statisticsEntity == null ){
103
            throw new ContentNotFoundException("Statistics not found for entity");
104
        }
105
        NumbersMap numbers = statisticsEntity.getNumbers();
106
        if(numbers == null){
107
            throw new ContentNotFoundException("Statistics not found - no numbers");
108
        }
109
        StatisticsStatus statisticsStatus= numbers.getMap().get(key);
110
        if(statisticsStatus == null){
111
            throw new ContentNotFoundException("Statistics not found for key");
112
        }
113
        if(Boolean.parseBoolean(monitor)){
114
            statisticsStatus.setShowInMonitor(Boolean.parseBoolean(status));
115
        }else{
116
            statisticsStatus.setShowInDashboard(Boolean.parseBoolean(status));
117
        }
118
//        stats.put(key,statisticsStatus);
119
        return statisticsDAO.save(statistics);
120
    }
121

  
122

  
123
}
1
//package eu.dnetlib.uoaadmintools.controllers;
2
//
3
//import eu.dnetlib.uoaadmintools.dao.*;
4
//import eu.dnetlib.uoaadmintools.entities.statistics.*;
5
//import eu.dnetlib.uoaadmintoolslibrary.handlers.ContentNotFoundException;
6
//import org.apache.log4j.Logger;
7
//import org.springframework.beans.factory.annotation.Autowired;
8
//import org.springframework.web.bind.annotation.*;
9
//
10
//import java.util.*;
11
//
12
//@RestController
13
//@CrossOrigin(origins = "*")
14
//public class StatisticsController {
15
//    private final Logger log = Logger.getLogger(this.getClass());
16
//
17
//    @Autowired
18
//    private StatisticsDAO statisticsDAO;
19
//
20
//    @RequestMapping(value = "/statistics", method = RequestMethod.GET)
21
//    public List<Statistics> getAllStatistics() throws ContentNotFoundException {
22
//        log.info("getAllStatistics");
23
//            List<Statistics> statistics = statisticsDAO.findAll();
24
//         if(statistics == null){
25
//            throw new ContentNotFoundException("Statistics not found");
26
//        }
27
//            return statistics;
28
//    }
29
//
30
//
31
//
32
//    @RequestMapping(value = "/statistics/{pid}", method = RequestMethod.GET)
33
//    public Statistics getStatistics(@PathVariable(value = "pid") String pid) throws ContentNotFoundException {
34
//        Statistics statistics = statisticsDAO.findByPid(pid);
35
//        if(statistics == null){
36
//            throw new ContentNotFoundException("Statistics not found");
37
//        }
38
//        return statistics;
39
//    }
40
//
41
//    @RequestMapping(value = "/statistics/{id}/toggle", method = RequestMethod.POST)
42
//    public Boolean toggleStatistics(@PathVariable String id) throws Exception {
43
//        Statistics statistics = statisticsDAO.findById(id);
44
//        boolean status = statistics.getIsActive();
45
//        statistics.setIsActive(!status);
46
//        statisticsDAO.save(statistics);
47
//        return statistics.getIsActive();
48
//    }
49
//
50
//    @RequestMapping(value = "/statistics/save", method = RequestMethod.POST)
51
//    public Statistics insertStatistics(@RequestBody Statistics statistics) {
52
//        Statistics savedStatistics = statisticsDAO.save(statistics);
53
//        return savedStatistics;
54
//    }
55
//
56
//
57
//
58
//    @RequestMapping(value = "/statistics/delete", method = RequestMethod.POST)
59
//    public Boolean deleteStatistics(@RequestBody List<String> statistics) throws Exception {
60
//        for (String id: statistics) {
61
//            statisticsDAO.delete(id);
62
//         }
63
//        return true;
64
//    }
65
//
66
//
67
//
68
//
69
//    @RequestMapping(value = "statistics/{pid}/{entity}/charts", method = RequestMethod.POST)
70
//    public Statistics toggleCharts(@PathVariable(value = "pid") String pid, @PathVariable(value = "entity") String entity, @RequestBody String key, @RequestParam String status, @RequestParam String monitor) throws ContentNotFoundException {
71
//        Statistics statistics = statisticsDAO.findByPid(pid);
72
//        if(statistics == null){
73
//            throw new ContentNotFoundException("Statistics not found  for portal");
74
//        }
75
//        StatisticsEntity statisticsEntity = statistics.getEntities().get(entity);
76
//        if(statisticsEntity == null ){
77
//            throw new ContentNotFoundException("Statistics not found for entity");
78
//        }
79
//        ChartsMap charts = statisticsEntity.getCharts();
80
//        if(charts == null){
81
//            throw new ContentNotFoundException("Statistics not found - no charts");
82
//        }
83
//        StatisticsStatus statisticsStatus= charts.getMap().get(key);
84
//        if(statisticsStatus == null){
85
//            throw new ContentNotFoundException("Statistics not found for key");
86
//        }
87
//        if(Boolean.parseBoolean(monitor)){
88
//            statisticsStatus.setShowInMonitor(Boolean.parseBoolean(status));
89
//        }else{
90
//            statisticsStatus.setShowInDashboard(Boolean.parseBoolean(status));
91
//        }
92
////        stats.put(key,statisticsStatus);
93
//        return statisticsDAO.save(statistics);
94
//    }
95
//    @RequestMapping(value = "statistics/{pid}/{entity}/numbers", method = RequestMethod.POST)
96
//    public Statistics toggleNumber(@PathVariable(value = "pid") String pid, @PathVariable(value = "entity") String entity, @RequestBody String key, @RequestParam String status, @RequestParam String monitor) throws ContentNotFoundException {
97
//        Statistics statistics = statisticsDAO.findByPid(pid);
98
//        if(statistics == null){
99
//            throw new ContentNotFoundException("Statistics not found  for portal");
100
//        }
101
//        StatisticsEntity statisticsEntity = statistics.getEntities().get(entity);
102
//        if(statisticsEntity == null ){
103
//            throw new ContentNotFoundException("Statistics not found for entity");
104
//        }
105
//        NumbersMap numbers = statisticsEntity.getNumbers();
106
//        if(numbers == null){
107
//            throw new ContentNotFoundException("Statistics not found - no numbers");
108
//        }
109
//        StatisticsStatus statisticsStatus= numbers.getMap().get(key);
110
//        if(statisticsStatus == null){
111
//            throw new ContentNotFoundException("Statistics not found for key");
112
//        }
113
//        if(Boolean.parseBoolean(monitor)){
114
//            statisticsStatus.setShowInMonitor(Boolean.parseBoolean(status));
115
//        }else{
116
//            statisticsStatus.setShowInDashboard(Boolean.parseBoolean(status));
117
//        }
118
////        stats.put(key,statisticsStatus);
119
//        return statisticsDAO.save(statistics);
120
//    }
121
//
122
//
123
//}

Also available in: Unified diff