aboutsummaryrefslogtreecommitdiffstats
path: root/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/PolicyScopeDictionaryController.java
blob: c0e7729db28ffc5a6320dbcb20cabcaf818b495c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
/*-
 * ============LICENSE_START=======================================================
 * ONAP-PAP-REST
 * ================================================================================
 * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved.
 * ================================================================================
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * ============LICENSE_END=========================================================
 */

package org.onap.policy.pap.xacml.rest.controller;

import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.lang.StringUtils;
import org.onap.policy.common.logging.flexlogger.FlexLogger;
import org.onap.policy.common.logging.flexlogger.Logger;
import org.onap.policy.pap.xacml.rest.util.DictionaryUtils;
import org.onap.policy.rest.dao.CommonClassDao;
import org.onap.policy.rest.jpa.GroupPolicyScopeList;
import org.onap.policy.rest.jpa.OnapName;
import org.onap.policy.rest.jpa.PolicyScopeClosedLoop;
import org.onap.policy.rest.jpa.PolicyScopeResource;
import org.onap.policy.rest.jpa.PolicyScopeService;
import org.onap.policy.rest.jpa.PolicyScopeType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

@Controller
public class PolicyScopeDictionaryController {

    private static final Logger LOGGER =
            FlexLogger.getLogger(PolicyScopeDictionaryController.class);

    private static CommonClassDao commonClassDao;
    private static String operation = "operation";
    private static String groupPolicyScopeListData1 = "groupPolicyScopeListData1";
    private static String policyScope = "PolicyScope";
    private static String duplicateResponseString = "Duplicate";
    private static String groupPolicyScopeDatas = "groupPolicyScopeListDatas";
    private static String dictionaryFields = "dictionaryFields";
    private static String psCLDatas = "psClosedLoopDictionaryDatas";
    private static String psServiceDatas = "psServiceDictionaryDatas";
    private static String psTypeDatas = "psTypeDictionaryDatas";
    private static String psResourceDatas = "psResourceDictionaryDatas";

    public PolicyScopeDictionaryController() {
        super();
    }

    private DictionaryUtils getDictionaryUtilsInstance() {
        return DictionaryUtils.getDictionaryUtils();
    }

    @Autowired
    public PolicyScopeDictionaryController(CommonClassDao commonClassDao) {
        PolicyScopeDictionaryController.commonClassDao = commonClassDao;
    }

    public void setCommonClassDao(CommonClassDao commonClassDao) {
        PolicyScopeDictionaryController.commonClassDao = commonClassDao;
    }

    @RequestMapping(value = {"/get_GroupPolicyScopeDataByName"}, method = {RequestMethod.GET},
            produces = MediaType.APPLICATION_JSON_VALUE)
    public void getGroupPolicyScopeEntityDataByName(HttpServletResponse response) {
        DictionaryUtils utils = getDictionaryUtilsInstance();
        utils.getDataByEntity(response, groupPolicyScopeDatas, "name", GroupPolicyScopeList.class);
    }

    @RequestMapping(value = {"/get_GroupPolicyScopeData"}, method = {RequestMethod.GET},
            produces = MediaType.APPLICATION_JSON_VALUE)
    public void getGroupPolicyScopeEntityData(HttpServletResponse response) {
        DictionaryUtils utils = getDictionaryUtilsInstance();
        utils.getData(response, groupPolicyScopeDatas, GroupPolicyScopeList.class);
    }

    @RequestMapping(value = {"/ps_dictionary/save_psGroupPolicyScope"},
            method = {RequestMethod.POST})
    public ModelAndView savePSGroupScopeDictionary(HttpServletRequest request,
            HttpServletResponse response) throws IOException {
        DictionaryUtils utils = getDictionaryUtilsInstance();
        try {
            boolean fromAPI = utils.isRequestFromAPI(request);
            ObjectMapper mapper = new ObjectMapper();
            mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
            JsonNode root = mapper.readTree(request.getReader());
            GroupPolicyScopeList gpdata = null;
            GroupPolicyScope groupData = null;
            boolean duplicateGroupFlag = false;
            if (fromAPI) {
                gpdata = mapper.readValue(root.get(dictionaryFields).toString(),
                        GroupPolicyScopeList.class);
                try {
                    groupData = mapper.readValue(root.get(groupPolicyScopeListData1).toString(),
                            GroupPolicyScope.class);
                } catch (Exception e) {
                    groupData = new GroupPolicyScope();
                    groupData.setResource(root.get(dictionaryFields).get("resource").toString()
                            .replace("\"", ""));
                    groupData.setClosedloop(root.get(dictionaryFields).get("closedloop").toString()
                            .replace("\"", ""));
                    groupData.setService(
                            root.get(dictionaryFields).get("service").toString().replace("\"", ""));
                    groupData.setType(
                            root.get(dictionaryFields).get("type").toString().replace("\"", ""));
                    LOGGER.error(e);
                }
            } else {
                gpdata = mapper.readValue(root.get("groupPolicyScopeListData").toString(),
                        GroupPolicyScopeList.class);
                try {
                    groupData = mapper.readValue(root.get(groupPolicyScopeListData1).toString(),
                            GroupPolicyScope.class);
                } catch (Exception e) {
                    LOGGER.error(e);
                    groupData = new GroupPolicyScope();
                    groupData.setResource(root.get(groupPolicyScopeListData1).get("resource")
                            .toString().replace("\"", ""));
                    groupData.setClosedloop(root.get(groupPolicyScopeListData1).get("closedloop")
                            .toString().replace("\"", ""));
                    groupData.setService(root.get(groupPolicyScopeListData1).get("service")
                            .toString().replace("\"", ""));
                    groupData.setType(root.get(groupPolicyScopeListData1).get("type").toString()
                            .replace("\"", ""));
                }
            }
            if (!gpdata.getGroupName().startsWith(policyScope)) {
                String name = "PolicyScope_" + gpdata.getGroupName();
                gpdata.setGroupName(name);
            }
            ArrayList<String> valueList = new ArrayList<>();
            String resourceValue = groupData.getResource();
            String typeValue = groupData.getType();
            String serviceValue = groupData.getService();
            String closedLoopValue = groupData.getClosedloop();
            valueList.add("resource=" + resourceValue);
            valueList.add("service=" + serviceValue);
            valueList.add("type=" + typeValue);
            valueList.add("closedLoopControlName=" + closedLoopValue);
            String list = StringUtils.replaceEach(valueList.toString(),
                    new String[] {"[", "]", " "}, new String[] {"", "", ""});
            gpdata.setGroupList(list);

            List<Object> duplicateData = commonClassDao.checkDuplicateEntry(gpdata.getGroupName(),
                    "name", GroupPolicyScopeList.class);
            if (duplicateData.isEmpty()) {
                duplicateData = commonClassDao.checkDuplicateEntry(gpdata.getGroupList(),
                        "groupList", GroupPolicyScopeList.class);
                if (duplicateData.isEmpty()) {
                    duplicateGroupFlag = true;
                }
            }
            boolean duplicateflag = false;
            if (!duplicateData.isEmpty()) {
                GroupPolicyScopeList data = (GroupPolicyScopeList) duplicateData.get(0);
                if (request.getParameter(operation) != null
                        && "update".equals(request.getParameter(operation))) {
                    gpdata.setId(data.getId());
                } else if ((request.getParameter(operation) != null
                        && !"update".equals(request.getParameter(operation)))
                        || (request.getParameter(operation) == null
                                && (data.getId() != gpdata.getId()))) {
                    duplicateflag = true;
                }
            }
            String responseString = null;
            if (!duplicateflag && !duplicateGroupFlag) {
                if (gpdata.getId() == 0) {
                    commonClassDao.save(gpdata);
                } else {
                    commonClassDao.update(gpdata);
                }
                responseString = mapper
                        .writeValueAsString(commonClassDao.getData(GroupPolicyScopeList.class));
            } else if (duplicateGroupFlag) {
                responseString = "DuplicateGroup";
            } else {
                responseString = duplicateResponseString;
            }
            if (fromAPI) {
                return utils.getResultForApi(responseString);
            } else {
                utils.setResponseData(response, groupPolicyScopeDatas, responseString);
            }
        } catch (Exception e) {
            utils.setErrorResponseData(response, e);
        }
        return null;
    }

    @RequestMapping(value = {"/ps_dictionary/remove_GroupPolicyScope"},
            method = {RequestMethod.POST})
    public void removePSGroupScopeDictionary(HttpServletRequest request,
            HttpServletResponse response) throws IOException {
        DictionaryUtils utils = getDictionaryUtilsInstance();
        utils.removeData(request, response, groupPolicyScopeDatas, GroupPolicyScopeList.class);
    }

    @RequestMapping(value = {"/get_PSClosedLoopDataByName"}, method = {RequestMethod.GET},
            produces = MediaType.APPLICATION_JSON_VALUE)
    public void getPSClosedLoopEntityDataByName(HttpServletResponse response) {
        DictionaryUtils utils = getDictionaryUtilsInstance();
        utils.getDataByEntity(response, psCLDatas, "name", OnapName.class);
    }

    @RequestMapping(value = {"/get_PSClosedLoopData"}, method = {RequestMethod.GET},
            produces = MediaType.APPLICATION_JSON_VALUE)
    public void getPSClosedLoopEntityData(HttpServletResponse response) {
        DictionaryUtils utils = getDictionaryUtilsInstance();
        utils.getData(response, psCLDatas, PolicyScopeClosedLoop.class);
    }

    @RequestMapping(value = {"/ps_dictionary/save_psClosedLoop"}, method = {RequestMethod.POST})
    public ModelAndView savePSClosedLoopDictionary(HttpServletRequest request,
            HttpServletResponse response) throws IOException {
        DictionaryUtils utils = getDictionaryUtilsInstance();
        try {
            boolean fromAPI = utils.isRequestFromAPI(request);
            ObjectMapper mapper = new ObjectMapper();
            mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
            JsonNode root = mapper.readTree(request.getReader());
            PolicyScopeClosedLoop onapData;
            if (fromAPI) {
                onapData = mapper.readValue(root.get(dictionaryFields).toString(),
                        PolicyScopeClosedLoop.class);
            } else {
                onapData = mapper.readValue(root.get("psClosedLoopDictionaryData").toString(),
                        PolicyScopeClosedLoop.class);
            }

            List<Object> duplicateData = commonClassDao.checkDuplicateEntry(onapData.getName(),
                    "name", PolicyScopeClosedLoop.class);
            boolean duplicateflag = false;
            if (!duplicateData.isEmpty()) {
                PolicyScopeClosedLoop data = (PolicyScopeClosedLoop) duplicateData.get(0);
                if (request.getParameter(operation) != null
                        && "update".equals(request.getParameter(operation))) {
                    onapData.setId(data.getId());
                } else if ((request.getParameter(operation) != null
                        && !"update".equals(request.getParameter(operation)))
                        || (request.getParameter(operation) == null
                                && (data.getId() != onapData.getId()))) {
                    duplicateflag = true;
                }
            }
            String responseString = null;
            if (!duplicateflag) {
                if (onapData.getId() == 0) {
                    commonClassDao.save(onapData);
                } else {
                    commonClassDao.update(onapData);
                }
                responseString = mapper
                        .writeValueAsString(commonClassDao.getData(PolicyScopeClosedLoop.class));
            } else {
                responseString = duplicateResponseString;
            }
            if (fromAPI) {
                return utils.getResultForApi(responseString);
            } else {
                utils.setResponseData(response, psCLDatas, responseString);
            }
        } catch (Exception e) {
            utils.setErrorResponseData(response, e);
        }
        return null;
    }

    @RequestMapping(value = {"/ps_dictionary/remove_PSClosedLoop"}, method = {RequestMethod.POST})
    public void removePSClosedLoopDictionary(HttpServletRequest request,
            HttpServletResponse response) throws IOException {
        DictionaryUtils utils = getDictionaryUtilsInstance();
        utils.removeData(request, response, psCLDatas, PolicyScopeClosedLoop.class);
    }

    @RequestMapping(value = {"/get_PSServiceDataByName"}, method = {RequestMethod.GET},
            produces = MediaType.APPLICATION_JSON_VALUE)
    public void getPSServiceEntityDataByName(HttpServletResponse response) {
        DictionaryUtils utils = getDictionaryUtilsInstance();
        utils.getDataByEntity(response, psServiceDatas, "name", PolicyScopeService.class);
    }

    @RequestMapping(value = {"/get_PSServiceData"}, method = {RequestMethod.GET},
            produces = MediaType.APPLICATION_JSON_VALUE)
    public void getPSServiceEntityData(HttpServletResponse response) {
        DictionaryUtils utils = getDictionaryUtilsInstance();
        utils.getData(response, psServiceDatas, PolicyScopeService.class);
    }

    @RequestMapping(value = {"/ps_dictionary/save_psService"}, method = {RequestMethod.POST})
    public ModelAndView savePSServiceDictionary(HttpServletRequest request,
            HttpServletResponse response) throws IOException {
        DictionaryUtils utils = getDictionaryUtilsInstance();
        try {
            boolean fromAPI = utils.isRequestFromAPI(request);
            ObjectMapper mapper = new ObjectMapper();
            mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
            JsonNode root = mapper.readTree(request.getReader());
            PolicyScopeService onapData;
            if (fromAPI) {
                onapData = mapper.readValue(root.get(dictionaryFields).toString(),
                        PolicyScopeService.class);
            } else {
                onapData = mapper.readValue(root.get("psServiceDictionaryData").toString(),
                        PolicyScopeService.class);
            }

            List<Object> duplicateData = commonClassDao.checkDuplicateEntry(onapData.getName(),
                    "name", PolicyScopeService.class);
            boolean duplicateflag = false;
            if (!duplicateData.isEmpty()) {
                PolicyScopeService data = (PolicyScopeService) duplicateData.get(0);
                if (request.getParameter(operation) != null
                        && "update".equals(request.getParameter(operation))) {
                    onapData.setId(data.getId());
                } else if ((request.getParameter(operation) != null
                        && !"update".equals(request.getParameter(operation)))
                        || (request.getParameter(operation) == null
                                && (data.getId() != onapData.getId()))) {
                    duplicateflag = true;
                }
            }
            String responseString = null;
            if (!duplicateflag) {
                if (onapData.getId() == 0) {
                    commonClassDao.save(onapData);
                } else {
                    commonClassDao.update(onapData);
                }
                responseString =
                        mapper.writeValueAsString(commonClassDao.getData(PolicyScopeService.class));
            } else {
                responseString = duplicateResponseString;
            }
            if (fromAPI) {
                return utils.getResultForApi(responseString);
            } else {
                utils.setResponseData(response, psServiceDatas, responseString);
            }
        } catch (Exception e) {
            utils.setErrorResponseData(response, e);
        }
        return null;
    }

    @RequestMapping(value = {"/ps_dictionary/remove_PSService"}, method = {RequestMethod.POST})
    public void removePSServiceDictionary(HttpServletRequest request, HttpServletResponse response)
            throws IOException {
        DictionaryUtils utils = getDictionaryUtilsInstance();
        utils.removeData(request, response, psServiceDatas, PolicyScopeService.class);
    }

    @RequestMapping(value = {"/get_PSTypeDataByName"}, method = {RequestMethod.GET},
            produces = MediaType.APPLICATION_JSON_VALUE)
    public void getPSTypeEntityDataByName(HttpServletResponse response) {
        DictionaryUtils utils = getDictionaryUtilsInstance();
        utils.getDataByEntity(response, psTypeDatas, "name", PolicyScopeType.class);
    }

    @RequestMapping(value = {"/get_PSTypeData"}, method = {RequestMethod.GET},
            produces = MediaType.APPLICATION_JSON_VALUE)
    public void getPSTypeEntityData(HttpServletResponse response) {
        DictionaryUtils utils = getDictionaryUtilsInstance();
        utils.getData(response, psTypeDatas, PolicyScopeType.class);
    }

    @RequestMapping(value = {"/ps_dictionary/save_psType"}, method = {RequestMethod.POST})
    public ModelAndView savePSTypeDictionary(HttpServletRequest request,
            HttpServletResponse response) throws IOException {
        DictionaryUtils utils = getDictionaryUtilsInstance();
        try {
            boolean fromAPI = utils.isRequestFromAPI(request);
            ObjectMapper mapper = new ObjectMapper();
            mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
            JsonNode root = mapper.readTree(request.getReader());
            PolicyScopeType onapData;
            if (fromAPI) {
                onapData = mapper.readValue(root.get(dictionaryFields).toString(),
                        PolicyScopeType.class);
            } else {
                onapData = mapper.readValue(root.get("psTypeDictionaryData").toString(),
                        PolicyScopeType.class);
            }

            List<Object> duplicateData = commonClassDao.checkDuplicateEntry(onapData.getName(),
                    "name", PolicyScopeType.class);
            boolean duplicateflag = false;
            if (!duplicateData.isEmpty()) {
                PolicyScopeType data = (PolicyScopeType) duplicateData.get(0);
                if (request.getParameter(operation) != null
                        && "update".equals(request.getParameter(operation))) {
                    onapData.setId(data.getId());
                } else if ((request.getParameter(operation) != null
                        && !"update".equals(request.getParameter(operation)))
                        || (request.getParameter(operation) == null
                                && (data.getId() != onapData.getId()))) {
                    duplicateflag = true;
                }
            }
            String responseString = null;
            if (!duplicateflag) {
                if (onapData.getId() == 0) {
                    commonClassDao.save(onapData);
                } else {
                    commonClassDao.update(onapData);
                }
                responseString =
                        mapper.writeValueAsString(commonClassDao.getData(PolicyScopeType.class));
            } else {
                responseString = duplicateResponseString;
            }
            if (fromAPI) {
                return utils.getResultForApi(responseString);
            } else {
                utils.setResponseData(response, psTypeDatas, responseString);
            }
        } catch (Exception e) {
            utils.setErrorResponseData(response, e);
        }
        return null;
    }

    @RequestMapping(value = {"/ps_dictionary/remove_PSType"}, method = {RequestMethod.POST})
    public void removePSTypeDictionary(HttpServletRequest request, HttpServletResponse response)
            throws IOException {
        DictionaryUtils utils = getDictionaryUtilsInstance();
        utils.removeData(request, response, psTypeDatas, PolicyScopeType.class);
    }

    @RequestMapping(value = {"/get_PSResourceDataByName"}, method = {RequestMethod.GET},
            produces = MediaType.APPLICATION_JSON_VALUE)
    public void getPSResourceEntityDataByName(HttpServletResponse response) {
        DictionaryUtils utils = getDictionaryUtilsInstance();
        utils.getDataByEntity(response, psResourceDatas, "name", PolicyScopeResource.class);
    }

    @RequestMapping(value = {"/get_PSResourceData"}, method = {RequestMethod.GET},
            produces = MediaType.APPLICATION_JSON_VALUE)
    public void getPSResourceEntityData(HttpServletResponse response) {
        DictionaryUtils utils = getDictionaryUtilsInstance();
        utils.getData(response, psResourceDatas, PolicyScopeResource.class);
    }

    @RequestMapping(value = {"/ps_dictionary/save_psResource"}, method = {RequestMethod.POST})
    public ModelAndView savePSResourceDictionary(HttpServletRequest request,
            HttpServletResponse response) throws IOException {
        DictionaryUtils utils = getDictionaryUtilsInstance();
        try {
            boolean fromAPI = utils.isRequestFromAPI(request);
            ObjectMapper mapper = new ObjectMapper();
            mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
            JsonNode root = mapper.readTree(request.getReader());
            PolicyScopeResource onapData;
            if (fromAPI) {
                onapData = mapper.readValue(root.get(dictionaryFields).toString(),
                        PolicyScopeResource.class);
            } else {
                onapData = mapper.readValue(root.get("psResourceDictionaryData").toString(),
                        PolicyScopeResource.class);
            }

            List<Object> duplicateData = commonClassDao.checkDuplicateEntry(onapData.getName(),
                    "name", PolicyScopeResource.class);
            boolean duplicateflag = false;
            if (!duplicateData.isEmpty()) {
                PolicyScopeResource data = (PolicyScopeResource) duplicateData.get(0);
                if (request.getParameter(operation) != null
                        && "update".equals(request.getParameter(operation))) {
                    onapData.setId(data.getId());
                } else if ((request.getParameter(operation) != null
                        && !"update".equals(request.getParameter(operation)))
                        || (request.getParameter(operation) == null
                                && (data.getId() != onapData.getId()))) {
                    duplicateflag = true;
                }
            }
            String responseString = null;
            if (!duplicateflag) {
                if (onapData.getId() == 0) {
                    commonClassDao.save(onapData);
                } else {
                    commonClassDao.update(onapData);
                }
                responseString = mapper
                        .writeValueAsString(commonClassDao.getData(PolicyScopeResource.class));
            } else {
                responseString = duplicateResponseString;
            }
            if (fromAPI) {
                return utils.getResultForApi(responseString);
            } else {
                utils.setResponseData(response, psResourceDatas, responseString);
            }
        } catch (Exception e) {
            utils.setErrorResponseData(response, e);
        }
        return null;
    }

    @RequestMapping(value = {"/ps_dictionary/remove_PSResource"}, method = {RequestMethod.POST})
    public void removePSResourceDictionary(HttpServletRequest request, HttpServletResponse response)
            throws IOException {
        DictionaryUtils utils = getDictionaryUtilsInstance();
        utils.removeData(request, response, psResourceDatas, PolicyScopeResource.class);
    }
}


class GroupPolicyScope {
    String resource;
    String type;
    String service;
    String closedloop;

    public String getResource() {
        return resource;
    }

    public void setResource(String resource) {
        this.resource = resource;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public String getService() {
        return service;
    }

    public void setService(String service) {
        this.service = service;
    }

    public String getClosedloop() {
        return closedloop;
    }

    public void setClosedloop(String closedloop) {
        this.closedloop = closedloop;
    }

}