Merge "Added Functional Menu Entries, del bad thumbnail"
authorManoop Talasila <talasila@research.att.com>
Fri, 10 May 2019 12:29:46 +0000 (12:29 +0000)
committerGerrit Code Review <gerrit@onap.org>
Fri, 10 May 2019 12:29:46 +0000 (12:29 +0000)
.gitignore
docs/tutorials/portal-sdk/your-angular-app.rst
ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/controller/ExternalAppsRestfulController.java
ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/ApplicationsRestClientServiceImpl.java
ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/AuxApiRequestMapperControllerTest.java
ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/ExternalAppsRestfulControllerTest.java
pom.xml
version.properties

index 44c6935..a237ad3 100644 (file)
@@ -1,4 +1,6 @@
 /.idea/*
+*.iml
+*/*.iml
 /.project
 /.settings
 /dmaapbc
index fd155eb..cc96712 100644 (file)
@@ -1,55 +1,55 @@
-Your Angular app
-=========================
-Now that you have the existing anuglarJS application working source code, it's time to migrate to the angular latest version.
-The portal SDK application kick stated the migration process from angularJS to angular (v6) using the method angular ngUpgrade.
-
-SDK angular application
------------------------
-To start migration, locate the current SDK angular application in :code:`sdk/ecomp-sdk/epsdk-app-overlay/src/main/webapp/ngapp`.
-
-Setup Steps
------------
-1. Install Node.js and angularCLI. Refer https://angular.io/guide/quickstart
-2. npm install in the directory `sdk/ecomp-sdk/epsdk-app-overlay/src/main/webapp/ngapp`
-3. ng serve should bring you the welcome.html page in your local machine
-
-firstpage.html
---------------
-1. template: the existing welcome.html in `sdk/ecomp-sdk/epsdk-app-overlay/src/main/webapp/app/fusion/scripts/DS2-view-models` is the landing page which will be migrated first.
-The content of this file will be copied to angular landling page (index.html) in `sdk/ecomp-sdk/epsdk-app-overlay/src/main/webapp/ngapp/src`. But in SDK the default page name index.html renamed to welcome.html, refer the file angular.json in ngapp.
-2. style: the existing css content will be copied to the styles.css in `sdk/ecomp-sdk/epsdk-app-overlay/src/main/webapp/ngapp/src`
-
-Boot the angularJS from angular application
----------------------------------------------------
-Each of the menu module (ex: admin, report) can separate angularJS application, so scan the entire *.html files in angularJS source for "ng-app" directive and remove them since the angularJS will be booted from angular application
-Refer the https://angular.io/guide/ajs-quick-reference to bootstrap steps. ex: SDK ngapp `this.upgrade.bootstrap(document.body, ['abs']);` in app.component.ts
-
-Controller
--------------
-The controller controller.js will be migrated to Type Script. When you create a angular component, by default the controller.ts will be created. So need to copy the content of existing controller.js function to controller.ts
-Refer the usage.component.ts `sdk/ecomp-sdk/epsdk-app-overlay/src/main/webapp/ngapp/src/app/admin/components/usage`
-
-Data Service
-------------
-The existing data service data-service.js will be migrated to Type Script. When you create a angular service, the data-service.ts will be created.
-Refer the app-http-client.service.ts `sdk/ecomp-sdk/epsdk-app-overlay/src/main/webapp/ngapp/src/app/admin/services`
-
-
-Template
--------------
-All the HTML file should be scanned and replace with angular directives. ex: "ng-if" in angular "*ngIf"
-Refer the https://angular.io/guide/ajs-quick-reference to migrate angularJs to angular directives in the static html should be scanned for
-
-
-Migrationg existing page to the SDK navigatio
----------------------------------------------
-TBD
-
-
-Adding your new page to the SDK navigation
-------------------------------------------
-TBD
-
-Rollback to angularJs incase if there is blocker
-------------------------------------------------
-TBD
+Your Angular app\r
+=========================\r
+Now that you have the existing anuglarJS application working source code, it's time to migrate to the angular latest version.\r
+The portal SDK application kick stated the migration process from angularJS to angular (v6) using the method angular ngUpgrade.\r
+\r
+SDK angular application\r
+-----------------------\r
+To start migration, locate the current SDK angular application in :code:`sdk/ecomp-sdk/epsdk-app-overlay/src/main/webapp/ngapp`.\r
+\r
+Setup Steps\r
+-----------\r
+1. Install Node.js and angularCLI. Refer https://angular.io/guide/quickstart\r
+2. npm install in the directory `sdk/ecomp-sdk/epsdk-app-overlay/src/main/webapp/ngapp`\r
+3. ng serve should bring you the welcome.html page in your local machine\r
+\r
+firstpage.html\r
+--------------\r
+1. template: the existing welcome.html in `sdk/ecomp-sdk/epsdk-app-overlay/src/main/webapp/app/fusion/scripts/DS2-view-models` is the landing page which will be migrated first.\r
+The content of this file will be copied to angular landling page (index.html) in `sdk/ecomp-sdk/epsdk-app-overlay/src/main/webapp/ngapp/src`. But in SDK the default page name index.html renamed to welcome.html, refer the file angular.json in ngapp.\r
+2. style: the existing css content will be copied to the styles.css in `sdk/ecomp-sdk/epsdk-app-overlay/src/main/webapp/ngapp/src`\r
+\r
+Boot the angularJS from angular application\r
+---------------------------------------------------\r
+Each of the menu module (ex: admin, report) can separate angularJS application, so scan the entire *.html files in angularJS source for "ng-app" directive and remove them since the angularJS will be booted from angular application\r
+Refer the https://angular.io/guide/ajs-quick-reference to bootstrap steps. ex: SDK ngapp `this.upgrade.bootstrap(document.body, ['abs']);` in app.component.ts\r
+\r
+Controller\r
+-------------\r
+The controller controller.js will be migrated to Type Script. When you create a angular component, by default the controller.ts will be created. So need to copy the content of existing controller.js function to controller.ts\r
+Refer the usage.component.ts `sdk/ecomp-sdk/epsdk-app-overlay/src/main/webapp/ngapp/src/app/admin/components/usage`\r
+\r
+Data Service\r
+------------\r
+The existing data service data-service.js will be migrated to Type Script. When you create a angular service, the data-service.ts will be created.\r
+Refer the app-http-client.service.ts `sdk/ecomp-sdk/epsdk-app-overlay/src/main/webapp/ngapp/src/app/admin/services`\r
+\r
+\r
+Template\r
+-------------\r
+All the HTML file should be scanned and replace with angular directives. ex: "ng-if" in angular "*ngIf"\r
+Refer the https://angular.io/guide/ajs-quick-reference to migrate angularJs to angular directives in the static html should be scanned for\r
+\r
+\r
+Migrationg existing page to the SDK navigatio\r
+---------------------------------------------\r
+TBD\r
+\r
+\r
+Adding your new page to the SDK navigation\r
+------------------------------------------\r
+TBD\r
+\r
+Rollback to angularJs incase if there is blocker\r
+------------------------------------------------\r
+TBD\r
index fb0c269..15ce305 100644 (file)
@@ -4,6 +4,8 @@
  * ===================================================================
  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
  * ===================================================================
+ *  Modifications Copyright (c) 2019 Samsung
+ * ===================================================================
  *
  * Unless otherwise specified, all software contained herein is licensed
  * under the Apache License, Version 2.0 (the "License");
@@ -112,11 +114,13 @@ public class ExternalAppsRestfulController extends EPRestrictedRESTfulBaseContro
                String appKey = request.getHeader("uebkey");
                EPApp app = findEpApp(appKey);
                List<Long> postRoleIds = new ArrayList<Long>();
-               for (Long roleId : notificationItem.getRoleIds()) {
-                       EPRole role = epRoleService.getRole(app.getId(), roleId);
-                       if (role != null)
-                               postRoleIds.add(role.getId());
-               }
+               if (app != null) {
+        for (Long roleId : notificationItem.getRoleIds()) {
+            EPRole role = epRoleService.getRole(app.getId(), roleId);
+            if (role != null)
+                postRoleIds.add(role.getId());
+        }
+    }
 
                // --- recreate the user notification object with the POrtal Role Ids
                EpNotificationItem postItem = new EpNotificationItem();
@@ -151,10 +155,10 @@ public class ExternalAppsRestfulController extends EPRestrictedRESTfulBaseContro
                try {
                        list = this.getDataAccessService().executeNamedQuery("getMyAppDetailsByUebKey", params, null);
                } catch (Exception e) {
-                       logger.error(EELFLoggerDelegate.errorLogger, "getMyAppDetailsByUebKey failed", e);                      
+                       logger.error(EELFLoggerDelegate.errorLogger, "getMyAppDetailsByUebKey failed", e);
                }
                        
-               return (list == null || list.size() == 0) ? null : (EPApp) list.get(0);
+               return (list == null || list.isEmpty()) ? null : (EPApp) list.get(0);
        }
 
        @ApiOperation(value = "Gets favorite items within the functional menu for the current user.", response = FavoritesFunctionalMenuItemJson.class, responseContainer="List")
index fd6610c..18dabfb 100644 (file)
@@ -4,6 +4,8 @@
  * ===================================================================
  * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
  * ===================================================================
+ *  Modifications Copyright (c) 2019 Samsung
+ * ===================================================================
  *
  * Unless otherwise specified, all software contained herein is licensed
  * under the Apache License, Version 2.0 (the "License");
@@ -378,7 +380,7 @@ public class ApplicationsRestClientServiceImpl implements ApplicationsRestClient
                                String str = ((ResponseImpl)response).readEntity(String.class);
                                EcompPortalUtils.logAndSerializeObject(logger, restPath, "POST result =", str);
                                try {
-                                       t = (T) gson.fromJson(str, t.getClass());
+                                       t = (T) gson.fromJson(str, clazz);
 
                                        //t = gson.fromJson(str, clazz);
                                } catch (Exception e) {
index 9d3ac1e..e730331 100644 (file)
@@ -639,7 +639,7 @@ public class AuxApiRequestMapperControllerTest {
                Mockito.when(AopUtils.isAopProxy(Matchers.anyObject())).thenReturn(false);
                Mockito.when(mockedRequest.getMethod()).thenReturn("POST");
                EpNotificationItem notificationItem = new EpNotificationItem();
-               assertNull(auxApiRequestMapperController.publishNotification(mockedRequest, notificationItem, mockedResponse));
+               assertNotNull(auxApiRequestMapperController.publishNotification(mockedRequest, notificationItem, mockedResponse));
        }
 
        @Test
index 73978a3..d8f98bb 100644 (file)
@@ -4,6 +4,8 @@
  * ===================================================================
  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
  * ===================================================================
+ *  Modifications Copyright (c) 2019 Samsung
+ * ===================================================================
  *
  * Unless otherwise specified, all software contained herein is licensed
  * under the Apache License, Version 2.0 (the "License");
@@ -38,8 +40,9 @@
 package org.onap.portalapp.portal.controller;
 
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
+import static org.mockito.Matchers.any;
 
 import java.util.ArrayList;
 import java.util.Calendar;
@@ -54,18 +57,15 @@ import javax.servlet.http.HttpServletResponse;
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
+import org.mockito.ArgumentCaptor;
 import org.mockito.InjectMocks;
-import org.mockito.Matchers;
 import org.mockito.Mock;
 import org.mockito.Mockito;
 import org.mockito.MockitoAnnotations;
-import org.onap.portalapp.portal.controller.ExternalAppsRestfulController;
 import org.onap.portalapp.portal.core.MockEPUser;
 import org.onap.portalapp.portal.domain.EPApp;
+import org.onap.portalapp.portal.domain.EPRole;
 import org.onap.portalapp.portal.domain.EPUser;
-import org.onap.portalapp.portal.domain.UserRole;
-import org.onap.portalapp.portal.ecomp.model.PortalRestResponse;
-import org.onap.portalapp.portal.ecomp.model.PortalRestStatusEnum;
 import org.onap.portalapp.portal.framework.MockitoTestSuite;
 import org.onap.portalapp.portal.service.AdminRolesService;
 import org.onap.portalapp.portal.service.AdminRolesServiceImpl;
@@ -82,7 +82,6 @@ import org.onap.portalapp.portal.transport.FavoritesFunctionalMenuItemJson;
 import org.onap.portalapp.portal.transport.FunctionalMenuItem;
 import org.onap.portalapp.portal.utils.EPCommonSystemProperties;
 import org.onap.portalapp.portal.utils.EcompPortalUtils;
-import org.onap.portalsdk.core.menu.MenuBuilder;
 import org.onap.portalsdk.core.onboarding.crossapi.PortalAPIResponse;
 import org.onap.portalsdk.core.service.DataAccessService;
 import org.onap.portalsdk.core.service.DataAccessServiceImpl;
@@ -247,88 +246,124 @@ public class ExternalAppsRestfulControllerTest {
                                .getFavoritesForUser(mockedRequest, mockedResponse);
                assertEquals(actaulFavorites.size(), 1);
        }
-       
-       @Test(expected=NullPointerException.class)
-       public void publishNotificationTest() throws Exception{
-               EPApp appTest=new EPApp();
-               Mockito.when(mockedRequest.getHeader("uebkey")).thenReturn("RxH3983AHiyBOQmj");
-               appTest.setUebKey("123456");
-               String appKey="123456";
-               EpNotificationItem notificationItem=new EpNotificationItem();
-               List<Long> roleList = new ArrayList<Long>();
-               Long role1 = (long) 1;
-               roleList.add(role1);
-               notificationItem.setRoleIds(roleList);
-               notificationItem.setIsForAllRoles("N");
-               notificationItem.setIsForOnlineUsers("N");
-               notificationItem.setActiveYn("Y");
-               notificationItem.setPriority(1L);
-               notificationItem.setMsgHeader("testHeader");
-               notificationItem.setMsgDescription("Test Description");
-               Date currentDate = new Date();
-               Calendar c = Calendar.getInstance();
-               c.setTime(currentDate);
-               c.add(Calendar.DATE, 1);
-               Date currentDatePlusOne = c.getTime();
-               notificationItem.setStartTime(currentDate);
-               notificationItem.setEndTime(currentDatePlusOne);
-               notificationItem.setCreatedDate(c.getTime());
-               
-               PortalAPIResponse actualPortalRestResponse = new PortalAPIResponse(true, appKey);
-               PortalAPIResponse expectedPortalRestResponse = new PortalAPIResponse(true, appKey);
-               expectedPortalRestResponse.setMessage("SUCCESS");
-               expectedPortalRestResponse.setStatus("ok");
-               Map<String, String> params = new HashMap<>();
-               params.put("appKey", "1234567");
-               
-               Mockito.when(DataAccessService.executeNamedQuery("getMyAppDetailsByUebKey", params, null)).thenReturn(null);
 
-               Mockito.when(userNotificationService.saveNotification(notificationItem)).thenReturn("Test");
-               actualPortalRestResponse = externalAppsRestfulController.publishNotification(mockedRequest, notificationItem);
-               assertTrue(actualPortalRestResponse.equals(expectedPortalRestResponse));
-               
-       }
-       
-       @Test(expected=NullPointerException.class)
-       public void publishNotificationTest1() throws Exception{
-               EpNotificationItem notificationItem=new EpNotificationItem();
-               List<Long> roleList = new ArrayList<Long>();
-               Long role1 = (long) 1;
-               roleList.add(role1);
-               notificationItem.setRoleIds(roleList);
-               notificationItem.setIsForAllRoles("N");
-               notificationItem.setIsForOnlineUsers("N");
-               notificationItem.setActiveYn("Y");
-               notificationItem.setPriority(1L);
-               notificationItem.setMsgHeader("testHeader");
-               notificationItem.setMsgDescription("Test Description");
-               Date currentDate = new Date();
-               Calendar c = Calendar.getInstance();
-               c.setTime(currentDate);
-               c.add(Calendar.DATE, 1);
-               Date currentDatePlusOne = c.getTime();
-               notificationItem.setStartTime(currentDate);
-               notificationItem.setEndTime(currentDatePlusOne);
-               notificationItem.setCreatedDate(c.getTime());
-               
-               //PowerMockito.mockStatic(EPApp.class);
 
-               
-               List<EPApp> appList = new ArrayList<>();
-               EPApp app = mockApp();
-               app.setId((long) 1);
-               appList.add(app);
-               
-               final Map<String, String> appUebkeyParams = new HashMap<>();
-               appUebkeyParams.put("appKey", "test-ueb-key");
-               
-               Mockito.when(DataAccessService.executeNamedQuery("getMyAppDetailsByUebKey", appUebkeyParams, null))
-               .thenReturn(appList);
-               //EPApp epApp=new EPApp();
-               
-               Mockito.when(mockedRequest.getHeader("uebkey")).thenReturn("RxH3983AHiyBOQmj");
+    @Test
+    public void publishNotificationTest_Success() throws Exception {
+        // input
+        EpNotificationItem notificationItem = new EpNotificationItem();
+        List<Long> roleList = new ArrayList<Long>();
+        Long role1 = 1L;
+        roleList.add(role1);
+        notificationItem.setRoleIds(roleList);
+        notificationItem.setPriority(1L);
+        notificationItem.setMsgHeader("testHeader");
+        notificationItem.setMsgDescription("Test Description");
+        Date currentDate = new Date();
+        Calendar c = Calendar.getInstance();
+        c.setTime(currentDate);
+        c.add(Calendar.DATE, 1);
+        Date currentDatePlusOne = c.getTime();
+        notificationItem.setStartTime(currentDate);
+        notificationItem.setEndTime(currentDatePlusOne);
 
-                externalAppsRestfulController.publishNotification(mockedRequest, notificationItem);
+        // mock calls
+        Mockito.when(mockedRequest.getHeader("uebkey")).thenReturn("RxH3983AHiyBOQmj");
+        Map<String, String> params = new HashMap<>();
+        params.put("appKey", "RxH3983AHiyBOQmj");
+        List<EPApp> apps = new ArrayList<>();
+        EPApp app = new EPApp();
+        app.setId(123L);
+        apps.add(app);
+        Mockito.when(DataAccessService.executeNamedQuery("getMyAppDetailsByUebKey", params, null)).thenReturn(apps);
+        EPRole role = new EPRole();
+        role.setId(543L);
+        Mockito.when(epRoleService.getRole(123L, 1L)).thenReturn(role);
+
+        // run
+        Mockito.when(userNotificationService.saveNotification(notificationItem)).thenReturn("Test");
+        PortalAPIResponse response = externalAppsRestfulController.publishNotification(mockedRequest, notificationItem);
+        // verify answer
+        assertNotNull(response);
+        assertEquals("ok", response.getStatus());
+        assertEquals("success", response.getMessage());
+        ArgumentCaptor<EpNotificationItem> capture = ArgumentCaptor.forClass(EpNotificationItem.class);
+        Mockito.verify(userNotificationService).saveNotification(capture.capture());
+        assertNotNull(capture.getValue());
+        EpNotificationItem createdNofification = capture.getValue();
+        assertNotNull(createdNofification.getRoleIds());
+        assertEquals(1, createdNofification.getRoleIds().size());
+        assertEquals(543L, createdNofification.getRoleIds().get(0).longValue());
+    }
+
+    @Test
+    public void publishNotificationTest_EmptyAppHeader() throws Exception {
+        // input
+        EpNotificationItem notificationItem = new EpNotificationItem();
+        List<Long> roleList = new ArrayList<Long>();
+        Long role1 = 1L;
+        roleList.add(role1);
+        notificationItem.setRoleIds(roleList);
+        notificationItem.setPriority(1L);
+        notificationItem.setMsgHeader("testHeader");
+        notificationItem.setMsgDescription("Test Description");
+        Date currentDate = new Date();
+        Calendar c = Calendar.getInstance();
+        c.setTime(currentDate);
+        c.add(Calendar.DATE, 1);
+        Date currentDatePlusOne = c.getTime();
+        notificationItem.setStartTime(currentDate);
+        notificationItem.setEndTime(currentDatePlusOne);
+
+        Mockito.when(mockedRequest.getHeader("uebkey")).thenReturn(null);
+        final Map<String, String> params = new HashMap<>();
+        params.put("appKey", null);
+        Mockito.when(DataAccessService.executeNamedQuery("getMyAppDetailsByUebKey", params, null))
+            .thenThrow(NullPointerException.class);
+
+        PortalAPIResponse response = externalAppsRestfulController.publishNotification(mockedRequest, notificationItem);
+        assertNotNull(response);
+        assertEquals("ok", response.getStatus());
+        assertEquals("success", response.getMessage());
+        ArgumentCaptor<EpNotificationItem> capture = ArgumentCaptor.forClass(EpNotificationItem.class);
+        Mockito.verify(userNotificationService).saveNotification(capture.capture());
+        assertNotNull(capture.getValue());
+        EpNotificationItem createdNofification = capture.getValue();
+        assertNotNull(createdNofification.getRoleIds());
+        assertEquals(0, createdNofification.getRoleIds().size());
+    }
+
+    @Test
+    public void publishNotificationTest_ErrorResponse() throws Exception {
+        // input
+        EpNotificationItem notificationItem = new EpNotificationItem();
+        List<Long> roleList = new ArrayList<Long>();
+        Long role1 = 1L;
+        roleList.add(role1);
+        notificationItem.setRoleIds(roleList);
+        notificationItem.setPriority(1L);
+        notificationItem.setMsgHeader("testHeader");
+        notificationItem.setMsgDescription("Test Description");
+        Date currentDate = new Date();
+        Calendar c = Calendar.getInstance();
+        c.setTime(currentDate);
+        c.add(Calendar.DATE, 1);
+        Date currentDatePlusOne = c.getTime();
+        notificationItem.setStartTime(currentDate);
+        notificationItem.setEndTime(currentDatePlusOne);
+
+        Mockito.when(mockedRequest.getHeader("uebkey")).thenReturn(null);
+        final Map<String, String> params = new HashMap<>();
+        params.put("appKey", null);
+        Mockito.when(DataAccessService.executeNamedQuery("getMyAppDetailsByUebKey", params, null))
+            .thenThrow(NullPointerException.class);
+        Mockito.when(userNotificationService.saveNotification(any(EpNotificationItem.class))).
+            thenThrow(new NullPointerException("expected message"));
+
+        PortalAPIResponse response = externalAppsRestfulController.publishNotification(mockedRequest, notificationItem);
+        assertNotNull(response);
+        assertEquals("error", response.getStatus());
+        assertEquals("expected message", response.getMessage());
+    }
 
-       }
 }
diff --git a/pom.xml b/pom.xml
index ec24920..31b8266 100644 (file)
--- a/pom.xml
+++ b/pom.xml
@@ -6,7 +6,7 @@
        <parent>
                <groupId>org.onap.oparent</groupId>
                <artifactId>oparent</artifactId>
-               <version>2.0.0</version>
+               <version>1.2.0</version>
                <relativePath />
        </parent>
 
index ee5d4d0..756f8a3 100644 (file)
@@ -3,7 +3,7 @@
 # because they are used in Jenkins, whose plug-in doesn't support
 
 major=2
-minor=4
+minor=5
 patch=0
 
 base_version=${major}.${minor}.${patch}