2  * ================================================================================
\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 
  11  *      http://www.apache.org/licenses/LICENSE-2.0
\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 
  20 package org.openecomp.portalapp.portal.service;
\r 
  22 import java.util.List;
\r 
  24 import org.springframework.beans.factory.annotation.Autowired;
\r 
  25 import org.springframework.context.annotation.EnableAspectJAutoProxy;
\r 
  26 import org.springframework.stereotype.Service;
\r 
  27 import org.springframework.transaction.annotation.Transactional;
\r 
  29 import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate;
\r 
  30 import org.openecomp.portalsdk.core.service.DataAccessService;
\r 
  31 import org.openecomp.portalapp.portal.domain.EPUser;
\r 
  32 import org.openecomp.portalapp.portal.domain.PersUserWidgetSelection;
\r 
  33 import org.openecomp.portalapp.portal.logging.aop.EPMetricsLog;
\r 
  35 @Service("persUserWidgetService")
\r 
  37 @org.springframework.context.annotation.Configuration
\r 
  38 @EnableAspectJAutoProxy
\r 
  40 public class PersUserWidgetServiceImpl implements PersUserWidgetService{
\r 
  42         private static EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(PersUserAppServiceImpl.class);
\r 
  45         private DataAccessService dataAccessService;
\r 
  48         public void setPersUserAppValue(EPUser user, Long widgetId, boolean select) {
\r 
  49                 if (user == null || widgetId == null)
\r 
  50                         throw new IllegalArgumentException("setPersUserAppValue: Null values");
\r 
  52                 String filter = " where user_id = " + Long.toString(user.getId()) + " and widget_id = "
\r 
  53                                 + Long.toString(widgetId);
\r 
  54                 @SuppressWarnings("unchecked")
\r 
  55                 List<PersUserWidgetSelection> persList = dataAccessService.getList(PersUserWidgetSelection.class, filter, null, null);
\r 
  57                 // Key constraint limits to 1 row
\r 
  58                 PersUserWidgetSelection persRow = null;
\r 
  59                 if (persList.size() == 1){
\r 
  60                         persRow = persList.get(0);
\r 
  63                         persRow = new PersUserWidgetSelection(null, user.getId(), widgetId, null);
\r 
  66                         if (persRow.getId() != null){
\r 
  67                                 dataAccessService.deleteDomainObject(persRow, null);                            
\r 
  69                         persRow.setStatusCode("S"); // show
\r 
  70                         dataAccessService.saveDomainObject(persRow, null);                      
\r 
  72                         if (persRow.getId() != null){
\r 
  73                                 dataAccessService.deleteDomainObject(persRow, null);
\r 
  75                         persRow.setStatusCode("H"); // Hide
\r 
  76                         dataAccessService.saveDomainObject(persRow, null);                      
\r