Widget MS startup fix and Onboarding changes
[portal.git] / ecomp-portal-widget-ms / widget-ms / src / main / java / org / onap / portalapp / widget / service / impl / WidgetCatalogServiceImpl.java
index 8dd8628..4554ab5 100644 (file)
@@ -1,3 +1,40 @@
+/*-
+ * ============LICENSE_START==========================================
+ * ONAP Portal
+ * ===================================================================
+ * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
+ * ===================================================================
+ *
+ * Unless otherwise specified, all software contained herein is licensed
+ * under the Apache License, Version 2.0 (the "License");
+ * you may not use this software 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.
+ *
+ * Unless otherwise specified, all documentation contained herein is licensed
+ * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
+ * you may not use this documentation except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *             https://creativecommons.org/licenses/by/4.0/
+ *
+ * Unless required by applicable law or agreed to in writing, documentation
+ * 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.portalapp.widget.service.impl;
 
 import java.util.List;
@@ -119,6 +156,7 @@ public class WidgetCatalogServiceImpl implements WidgetCatalogService {
        }
        
        @Override
+       @Transactional
        public void deleteWidgetCatalog(long widgetCatalogId) {
                logger.debug("WidgetCatalogServiceImpl.deleteWidgetCatalog: deleting the widget with widgetId={}", widgetCatalogId);
                WidgetCatalog widget = getWidgetCatalog(widgetCatalogId);
@@ -127,7 +165,7 @@ public class WidgetCatalogServiceImpl implements WidgetCatalogService {
                        return;
                }
                Session session = sessionFactory.getCurrentSession();
-               Transaction tx = session.beginTransaction();
+               //Transaction tx = session.beginTransaction();
                Query query = session.createSQLQuery("delete from ep_pers_user_widget_sel where widget_id = :widgetId ").setParameter("widgetId", widgetCatalogId);
                query.executeUpdate();
                query = session.createSQLQuery("delete from ep_pers_user_widget_placement where widget_id = :widgetId ").setParameter("widgetId", widgetCatalogId);
@@ -137,7 +175,7 @@ public class WidgetCatalogServiceImpl implements WidgetCatalogService {
                query = session.createSQLQuery("delete from ep_widget_catalog_parameter where widget_id = :widgetId ").setParameter("widgetId", widgetCatalogId);
                query.executeUpdate();
                session.delete(widget);
-               tx.commit();
+               //tx.commit();
        }
        
        @Override
@@ -154,7 +192,7 @@ public class WidgetCatalogServiceImpl implements WidgetCatalogService {
                        Transaction tx = session.beginTransaction();            
                        session.save(newWidgetCatalog);
                        tx.commit();
-                       session.flush();
+                       //session.flush();
                        session.close();
                        updateAppId(newWidgetCatalog.getId(), newWidgetCatalog.getWidgetRoles());
                }
@@ -180,7 +218,7 @@ public class WidgetCatalogServiceImpl implements WidgetCatalogService {
                        Transaction tx = session.beginTransaction();
                        session.update(newWidgetCatalog);
                        tx.commit();
-                       session.flush();
+                       //session.flush();
                        session.close();
                        updateAppId(newWidgetCatalog.getId(), newWidgetCatalog.getWidgetRoles());
                }catch(Exception e){
@@ -207,16 +245,15 @@ public class WidgetCatalogServiceImpl implements WidgetCatalogService {
                logger.debug("WidgetCatalogServiceImpl.getWidgetCatalog: result={}", widgets);
                return widgets;
        }
-       
-       
-       
-       
-       
+
        private void updateAppId(long widgetId, Set<RoleApp> roles){
                Session session = sessionFactory.openSession();
                for(RoleApp role: roles){
-                       String sql = "UPDATE ep_widget_catalog_role SET app_id = " + role.getApp().getAppId() + " WHERE widget_id = " + widgetId + " AND ROLE_ID = " + role.getRoleId() ;
+                       String sql = "UPDATE ep_widget_catalog_role SET app_id = :appId WHERE widget_id = :widgetId AND ROLE_ID = :roleId" ;
                        Query query = session.createSQLQuery(sql);
+                       query.setParameter("appId", role.getApp().getAppId());
+                       query.setParameter("widgetId", widgetId);
+                       query.setParameter("roleId", role.getRoleId());
                        query.executeUpdate();
                }
                session.flush();
@@ -232,7 +269,7 @@ public class WidgetCatalogServiceImpl implements WidgetCatalogService {
                
                List<MicroserviceData> widgets = criteria.list();
                logger.debug("WidgetCatalogServiceImpl.getWidgetIdByName: result={}", widgets);
-               session.flush();
+//             session.flush();
                session.close();
                
                return (widgets.size() > 0) ? true : false;