189b31079e5dadcd737437a368645db4ec2c59e2
[portal.git] / ecomp-portal-BE-common / src / main / java / org / openecomp / portalapp / portal / service / PersUserWidgetServiceImpl.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.List;
23
24 import org.springframework.beans.factory.annotation.Autowired;
25 import org.springframework.context.annotation.EnableAspectJAutoProxy;
26 import org.springframework.stereotype.Service;
27 import org.springframework.transaction.annotation.Transactional;
28
29 import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate;
30 import org.openecomp.portalsdk.core.service.DataAccessService;
31 import org.openecomp.portalapp.portal.domain.EPUser;
32 import org.openecomp.portalapp.portal.domain.PersUserWidgetSelection;
33 import org.openecomp.portalapp.portal.logging.aop.EPMetricsLog;
34
35 @Service("persUserWidgetService")
36 @Transactional
37 @org.springframework.context.annotation.Configuration
38 @EnableAspectJAutoProxy
39 @EPMetricsLog
40 public class PersUserWidgetServiceImpl implements PersUserWidgetService{
41         
42         private static EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(PersUserAppServiceImpl.class);
43
44         @Autowired
45         private DataAccessService dataAccessService;
46         
47         @Override
48         public void setPersUserAppValue(EPUser user, Long widgetId, boolean select) {
49                 if (user == null || widgetId == null)
50                         throw new IllegalArgumentException("setPersUserAppValue: Null values");
51
52                 String filter = " where user_id = " + Long.toString(user.getId()) + " and widget_id = "
53                                 + Long.toString(widgetId);
54                 @SuppressWarnings("unchecked")
55                 List<PersUserWidgetSelection> persList = dataAccessService.getList(PersUserWidgetSelection.class, filter, null, null);
56
57                 // Key constraint limits to 1 row
58                 PersUserWidgetSelection persRow = null;
59                 if (persList.size() == 1){
60                         persRow = persList.get(0);
61                 }
62                 else {
63                         persRow = new PersUserWidgetSelection(null, user.getId(), widgetId, null);
64                 }                       
65                 if(select){
66                         if (persRow.getId() != null){
67                                 dataAccessService.deleteDomainObject(persRow, null);                            
68                         }
69                         persRow.setStatusCode("S"); // show
70                         dataAccessService.saveDomainObject(persRow, null);                      
71                 } else{
72                         if (persRow.getId() != null){
73                                 dataAccessService.deleteDomainObject(persRow, null);
74                         } 
75                         persRow.setStatusCode("H"); // Hide
76                         dataAccessService.saveDomainObject(persRow, null);                      
77                 }
78                 
79         }
80
81 }