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