[PORTAL-7] Rebase
[portal.git] / ecomp-portal-BE-common / src / main / java / org / openecomp / portalapp / portal / service / WidgetParameterServiceImpl.java
1 /*-\r
2  * ================================================================================\r
3  * ECOMP Portal\r
4  * ================================================================================\r
5  * Copyright (C) 2017 AT&T Intellectual Property\r
6  * ================================================================================\r
7  * Licensed under the Apache License, Version 2.0 (the "License");\r
8  * you may not use this file except in compliance with the License.\r
9  * You may obtain a copy of the License at\r
10  * \r
11  *      http://www.apache.org/licenses/LICENSE-2.0\r
12  * \r
13  * Unless required by applicable law or agreed to in writing, software\r
14  * distributed under the License is distributed on an "AS IS" BASIS,\r
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
16  * See the License for the specific language governing permissions and\r
17  * limitations under the License.\r
18  * ================================================================================\r
19  */\r
20 package org.openecomp.portalapp.portal.service;\r
21 \r
22 import java.util.ArrayList;\r
23 import java.util.HashMap;\r
24 import java.util.List;\r
25 import java.util.Map;\r
26 \r
27 import org.hibernate.SessionFactory;\r
28 import org.hibernate.criterion.Criterion;\r
29 import org.hibernate.criterion.Restrictions;\r
30 import org.openecomp.portalapp.portal.domain.WidgetCatalogParameter;\r
31 import org.openecomp.portalapp.portal.logging.aop.EPMetricsLog;\r
32 import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate;\r
33 import org.openecomp.portalsdk.core.service.DataAccessService;\r
34 import org.springframework.beans.factory.annotation.Autowired;\r
35 import org.springframework.context.annotation.EnableAspectJAutoProxy;\r
36 import org.springframework.stereotype.Service;\r
37 \r
38 @Service("widgetParameterService")\r
39 @EnableAspectJAutoProxy\r
40 @EPMetricsLog\r
41 public class WidgetParameterServiceImpl implements WidgetParameterService{\r
42         EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(WidgetParameterServiceImpl.class);\r
43 \r
44         @Autowired\r
45         private DataAccessService dataAccessService;\r
46 \r
47         @SuppressWarnings("unchecked")\r
48         @Override\r
49         public WidgetCatalogParameter getUserParamById(Long widgetId, Long userId, Long paramId) {\r
50                 List<Criterion> restrictionsList = new ArrayList<Criterion>();\r
51                 Criterion widgetIdCrit = Restrictions.eq("widgetId", widgetId);\r
52                 restrictionsList.add(widgetIdCrit);\r
53                 Criterion attIdCrit = Restrictions.eq("userId", userId);\r
54                 restrictionsList.add(attIdCrit);\r
55                 Criterion paramIdCrit = Restrictions.eq("paramId", paramId);\r
56                 restrictionsList.add(paramIdCrit);\r
57                 \r
58                 \r
59                 WidgetCatalogParameter widgetParam = null;\r
60                 List<WidgetCatalogParameter> list = (List<WidgetCatalogParameter>) dataAccessService\r
61                                 .getList(WidgetCatalogParameter.class, null, restrictionsList, null);\r
62                 if(list.size() != 0)\r
63                         widgetParam = list.get(0);\r
64                 logger.debug(EELFLoggerDelegate.debugLogger,\r
65                                 "getUserParamById: widget parameters: " + widgetParam);\r
66                 return widgetParam;\r
67         }\r
68 \r
69         @Override\r
70         public void saveUserParameter(WidgetCatalogParameter newParameter) {\r
71                 dataAccessService.saveDomainObject(newParameter, null);\r
72         }\r
73         \r
74         @SuppressWarnings("unchecked")\r
75         @Override\r
76         public List<WidgetCatalogParameter> getUserParameterById(Long paramId) {\r
77                 List<Criterion> restrictionsList = new ArrayList<Criterion>();\r
78                 Criterion paramIdCrit = Restrictions.eq("paramId", paramId);\r
79                 restrictionsList.add(paramIdCrit);\r
80                 List<WidgetCatalogParameter> list = (List<WidgetCatalogParameter>) dataAccessService\r
81                                 .getList(WidgetCatalogParameter.class, null, restrictionsList, null);\r
82                 return list;\r
83         }\r
84 \r
85         @Override\r
86         public void deleteUserParameterById(Long paramId) {\r
87                 Map<String, String> params = new HashMap<String, String>();\r
88                 params.put("paramId", Long.toString(paramId));\r
89                 dataAccessService.executeNamedQuery("deleteWidgetCatalogParameter", params, null);\r
90                 dataAccessService.executeNamedQuery("deleteMicroserviceParameterById", params, null);\r
91         }\r
92 }\r