From: Manoop Talasila Date: Wed, 12 Sep 2018 16:29:23 +0000 (+0000) Subject: Merge "LoginStrategy.java : Fixed sonar issue" X-Git-Tag: 2.3.0~20 X-Git-Url: https://gerrit.onap.org/r/gitweb?p=portal.git;a=commitdiff_plain;h=d0082750f86e9bfa70e2ae9ad2694342df87f968;hp=f545127f41380b51175b639386ae20437a607b0e Merge "LoginStrategy.java : Fixed sonar issue" --- diff --git a/deliveries/.env b/deliveries/.env index 73259592..3b2fa140 100644 --- a/deliveries/.env +++ b/deliveries/.env @@ -14,11 +14,11 @@ CLI_IMG_NAME=onap/cli # This is the first portion of the Docker image tag # that is published to the ONAP registry. -PORTAL_VERSION=v2.3.0 +PORTAL_VERSION=2.3.0 # This is used during builds and in docker-compose; # it is never published to the ONAP registry. -PORTAL_TAG=beijing +PORTAL_TAG=casablanca # Name of directory in apps container (NOT host) WEBAPPS_DIR=/opt/apache-tomcat-8.0.37/webapps diff --git a/deliveries/Apps_Users_OnBoarding_Script.sql b/deliveries/Apps_Users_OnBoarding_Script.sql index 0232a1f4..af3edbaa 100644 --- a/deliveries/Apps_Users_OnBoarding_Script.sql +++ b/deliveries/Apps_Users_OnBoarding_Script.sql @@ -13,7 +13,7 @@ INSERT INTO `fn_app` (`app_id`, `app_name`, `app_image_url`, `app_description`, (6, 'Virtual Infrastructure Deployment', 'images/cache/portal-345993588_92550.png', NULL, NULL, 'http://vid.api.simpledemo.onap.org:8080/vid/welcome.htm', NULL, 'http://vid.api.simpledemo.onap.org:8080/vid/api/v2', '', '', NULL, 'okYTaDrhzibcbGVq5mjkVQ==', 'N', 'Y', NULL, 'Default', '2Re7Pvdkgw5aeAUD', 'S31PrbOzGgL4hg4owgtx47Da', 'ECOMP-PORTAL-OUTBOX-90', 1,'N',NULL), (7, 'A&AI UI', 'images/cache/portal-345993588_92550.png', NULL, NULL, 'http://aai.api.simpledemo.onap.org:9517/services/aai/webapp/index.html#/viewInspect', NULL, 'http://aai.api.simpledemo.onap.org:9517/api/v2', '', '', NULL, 't1oqm6wCXrGUXUSL8mS7pQ==', 'N', 'Y', NULL, 'aaiui', 'ueb_key', 'ueb_secret', 'ECOMP-PORTAL-OUTBOX', 1,'N',NULL), (8, 'CLI', 'images/cache/portal-345993588_92550.png', NULL, NULL, 'http://portal.api.simpledemo.onap.org:8080/', NULL, NULL, '', '', NULL, '', 'Y', 'Y', NULL, '', '', '', '', 1,'N',NULL), -(9, 'MSB', 'images/cache/portal-345993588_92550.png', NULL, NULL, 'http://msb-discovery:8080/iui/microservices/default.html', NULL, NULL, '', '', NULL, '', 'Y', 'Y', NULL, '', '', '', '', 2,'N',NULL); +(9, 'MSB', 'images/cache/portal-345993588_92550.png', NULL, NULL, 'http://msb-iag:80/iui/microservices/index.html', NULL, NULL, '', '', NULL, '', 'Y', 'Y', NULL, '', '', '', '', 2,'N',NULL); -- insert SDC users user id2-8 diff --git a/docs/release-notes.rst b/docs/release-notes.rst index 43803ad0..b0c3f33c 100644 --- a/docs/release-notes.rst +++ b/docs/release-notes.rst @@ -6,6 +6,37 @@ Portal Platform Release Notes ============================= +Version: 2.3.0 +-------------- +:Release Date: XXXX-XX-XX + +.. toctree:: + :maxdepth: 1 + +We worked on SDK upgrade to integrate with AAF. + +**New Features** + * Portal SDK (2.4.0) + * Use of Semantic Versioning - V3 is the supported version + * Integration with AAF via REST; Supports both SDK and Framework Applicaitons + +**Bug Fixes** + + +**Known Issues** + +**Security Issues** + +**Security Notes** + +**Upgrade Notes** + +**Deprecation Notes** + +**Other** + * portal/sdk - (Release branch: "release-2.4.0") + + Version: 2.2.0 -------------- diff --git a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/command/PostSearchBean.java b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/command/PostSearchBean.java index c3837621..f5453a75 100644 --- a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/command/PostSearchBean.java +++ b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/command/PostSearchBean.java @@ -3,6 +3,8 @@ * ONAP Portal * =================================================================== * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * + * Modifications Copyright (C) 2018 IBM. * =================================================================== * * Unless otherwise specified, all software contained herein is licensed @@ -372,20 +374,21 @@ public class PostSearchBean extends SearchBase { public boolean isCriteriaUpdated() { + final boolean flag = true; if(user==null&&userOrig==null) return false; else if(user==null||userOrig==null) return true; - else - return (! ( - Utilities.nvl(user.getFirstName()).equals(Utilities.nvl(userOrig.getFirstName()))&& - Utilities.nvl(user.getLastName()).equals(Utilities.nvl(userOrig.getLastName()))&& - //Utilities.nvl(user.getHrid()).equals(Utilities.nvl(userOrig.getHrid()))&& - Utilities.nvl(user.getOrgUserId()).equals(Utilities.nvl(userOrig.getOrgUserId()))&& - Utilities.nvl(user.getOrgCode()).equals(Utilities.nvl(userOrig.getOrgCode()))&& - Utilities.nvl(user.getEmail()).equals(Utilities.nvl(userOrig.getEmail()))&& - Utilities.nvl(user.getOrgManagerUserId()).equals(Utilities.nvl(userOrig.getOrgManagerUserId()))&& - true)); + else { + boolean value = Utilities.nvl(user.getFirstName()).equals(Utilities.nvl(userOrig.getFirstName()))&& + Utilities.nvl(user.getLastName()).equals(Utilities.nvl(userOrig.getLastName()))&& + //Utilities.nvl(user.getHrid()).equals(Utilities.nvl(userOrig.getHrid()))&& + Utilities.nvl(user.getOrgUserId()).equals(Utilities.nvl(userOrig.getOrgUserId()))&& + Utilities.nvl(user.getOrgCode()).equals(Utilities.nvl(userOrig.getOrgCode()))&& + Utilities.nvl(user.getEmail()).equals(Utilities.nvl(userOrig.getEmail()))&& + Utilities.nvl(user.getOrgManagerUserId()).equals(Utilities.nvl(userOrig.getOrgManagerUserId())); + return (!(value && flag)); + } } // isCriteriaUpdated } // PostSearchBean diff --git a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/config/NotificationCleanupConfig.java b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/config/NotificationCleanupConfig.java index 13b86995..b9f46492 100644 --- a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/config/NotificationCleanupConfig.java +++ b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/config/NotificationCleanupConfig.java @@ -3,6 +3,8 @@ * ONAP Portal * =================================================================== * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * + * Modifications Copyright (C) 2018 IBM. * =================================================================== * * Unless otherwise specified, all software contained herein is licensed @@ -52,11 +54,11 @@ import org.springframework.context.annotation.Configuration; public class NotificationCleanupConfig implements ApplicationContextAware { // Once every 10 minutes should be adequate - public final static int CLEANUP_PERIOD_MINUTES = 10; + public static final int CLEANUP_PERIOD_MINUTES = 10; private static ApplicationContext applicationContext; - public void setApplicationContext(ApplicationContext context) throws BeansException { + public void setApplicationContext(ApplicationContext context) { applicationContext = context; } @@ -69,7 +71,7 @@ public class NotificationCleanupConfig implements ApplicationContextAware { public void StartSchedular() { TimerTask task = new NotificationCleanup(); Timer timer = new Timer(); - timer.schedule(task, 1000, CLEANUP_PERIOD_MINUTES * 60 * 1000); + timer.schedule(task, 1000, (long) CLEANUP_PERIOD_MINUTES * 60 * 1000); } @Bean diff --git a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/model/Result.java b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/model/Result.java index 216ae3af..8b099970 100644 --- a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/model/Result.java +++ b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/model/Result.java @@ -3,6 +3,8 @@ * ONAP Portal * =================================================================== * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * + * Modifications Copyright (C) 2018 IBM. * =================================================================== * * Unless otherwise specified, all software contained herein is licensed @@ -38,18 +40,18 @@ package org.onap.portalapp.model; public class Result { - private String result; + private String results; public Result(String result) { - this.result = result; + this.results = result; } public String getResult() { - return result; + return results; } public void setResult(String result) { - this.result = result; + this.results = result; } } diff --git a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/music/util/MusicUtil.java b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/music/util/MusicUtil.java index 308528d5..9667bfef 100644 --- a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/music/util/MusicUtil.java +++ b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/music/util/MusicUtil.java @@ -115,7 +115,8 @@ public class MusicUtil { oos.flush(); } } catch (IOException e) { - logger.error(EELFLoggerDelegate.errorLogger, "Failed to serialize "); + String message="Failed to serialize "; + logger.error(EELFLoggerDelegate.errorLogger, message, e); } return ByteBuffer.wrap(bo.toByteArray()); } diff --git a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/interceptor/PortalResourceInterceptor.java b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/interceptor/PortalResourceInterceptor.java index 3160032f..ab88dd6e 100644 --- a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/interceptor/PortalResourceInterceptor.java +++ b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/interceptor/PortalResourceInterceptor.java @@ -3,6 +3,8 @@ * ONAP Portal * =================================================================== * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. + * + * Modification Copyright (C) 2018 IBM. * =================================================================== * * Unless otherwise specified, all software contained herein is licensed @@ -320,7 +322,7 @@ public class PortalResourceInterceptor extends ResourceInterceptor { @SuppressWarnings("unused") private String decrypted(String encrypted) throws Exception { String result = ""; - if (encrypted != null & encrypted.length() > 0) { + if (encrypted != null && encrypted.length() > 0) { try { result = CipherUtil.decryptPKC(encrypted, SystemProperties.getProperty(SystemProperties.Decryption_Key)); } catch (Exception e) { @@ -333,7 +335,7 @@ public class PortalResourceInterceptor extends ResourceInterceptor { private String encrypted(String decryptedPwd) throws Exception { String result = ""; - if (decryptedPwd != null & decryptedPwd.length() > 0) { + if (decryptedPwd != null && decryptedPwd.length() > 0) { try { result = CipherUtil.encryptPKC(decryptedPwd, SystemProperties.getProperty(SystemProperties.Decryption_Key)); diff --git a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/scheduler/SchedulerRestInterface.java b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/scheduler/SchedulerRestInterface.java index 825d33a2..1886b8b5 100644 --- a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/scheduler/SchedulerRestInterface.java +++ b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/scheduler/SchedulerRestInterface.java @@ -157,7 +157,7 @@ public class SchedulerRestInterface implements SchedulerRestInterfaceIfc { client = HttpsBasicClient.getClient(); } } catch (Exception e) { - logger.debug(EELFLoggerDelegate.debugLogger, "Unable to initialize rest client"); + logger.debug(EELFLoggerDelegate.debugLogger, "Unable to initialize rest client",e.getMessage()); } logger.debug(EELFLoggerDelegate.debugLogger, "Client Initialized"); diff --git a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/BasicAuthAccountServiceImpl.java b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/BasicAuthAccountServiceImpl.java index a2ff3149..74cf1726 100644 --- a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/BasicAuthAccountServiceImpl.java +++ b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/BasicAuthAccountServiceImpl.java @@ -221,7 +221,7 @@ public class BasicAuthAccountServiceImpl implements BasicAuthAccountService{ private String decryptedPassword(String encryptedPwd) throws Exception { String result = ""; - if (encryptedPwd != null & encryptedPwd.length() > 0) { + if (encryptedPwd != null && encryptedPwd.length() > 0) { try { result = CipherUtil.decryptPKC(encryptedPwd, SystemProperties.getProperty(SystemProperties.Decryption_Key)); @@ -235,7 +235,7 @@ public class BasicAuthAccountServiceImpl implements BasicAuthAccountService{ private String encryptedPassword(String decryptedPwd) throws Exception { String result = ""; - if (decryptedPwd != null & decryptedPwd.length() > 0) { + if (decryptedPwd != null && decryptedPwd.length() > 0) { try { result = CipherUtil.encryptPKC(decryptedPwd, SystemProperties.getProperty(SystemProperties.Decryption_Key)); diff --git a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/ExternalAccessRolesServiceImpl.java b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/ExternalAccessRolesServiceImpl.java index 4c68fc9c..4197d232 100644 --- a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/ExternalAccessRolesServiceImpl.java +++ b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/ExternalAccessRolesServiceImpl.java @@ -897,8 +897,8 @@ public class ExternalAccessRolesServiceImpl implements ExternalAccessRolesServic * @throws Exception */ @SuppressWarnings("unchecked") - @Transactional(rollbackFor = Exception.class) - private boolean addRoleInEcompDB(Role addRoleInDB, EPApp app) throws Exception { + @Transactional(rollbackFor = Exception.class) + public boolean addRoleInEcompDB(Role addRoleInDB, EPApp app) throws Exception { boolean result = false; EPRole epRole = null; Set roleFunctionList = addRoleInDB.getRoleFunctions(); diff --git a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/UserRolesCommonServiceImpl.java b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/UserRolesCommonServiceImpl.java index e3ce07ff..2eb7c948 100644 --- a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/UserRolesCommonServiceImpl.java +++ b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/UserRolesCommonServiceImpl.java @@ -887,7 +887,8 @@ public class UserRolesCommonServiceImpl { addRemoteUser(roleInAppForUserList, userId, app, mapper, searchService, applicationsRestClientService); } catch (Exception e) { - logger.debug(EELFLoggerDelegate.debugLogger, e.getMessage()); + String message=e.getMessage(); + logger.error(EELFLoggerDelegate.errorLogger, message, e); } } diff --git a/ecomp-portal-BE-os/src/main/java/org/onap/portalapp/portal/interceptor/SessionTimeoutInterceptor.java b/ecomp-portal-BE-os/src/main/java/org/onap/portalapp/portal/interceptor/SessionTimeoutInterceptor.java index dd201edd..689b25f2 100644 --- a/ecomp-portal-BE-os/src/main/java/org/onap/portalapp/portal/interceptor/SessionTimeoutInterceptor.java +++ b/ecomp-portal-BE-os/src/main/java/org/onap/portalapp/portal/interceptor/SessionTimeoutInterceptor.java @@ -92,6 +92,8 @@ public class SessionTimeoutInterceptor extends HandlerInterceptorAdapter { CollaborateList.addUserName(user.getOrgUserId()); } } catch (SessionExpiredException e) { + String message=e.getMessage(); + logger.error(EELFLoggerDelegate.errorLogger,message, e); response.sendRedirect(SystemProperties.getProperty(EPSystemProperties.LOGIN_URL_NO_RET_VAL)); return false; } catch (Exception e) { diff --git a/ecomp-portal-widget-ms/widget-ms/src/main/java/org/onap/portalapp/widget/service/impl/StorageServiceImpl.java b/ecomp-portal-widget-ms/widget-ms/src/main/java/org/onap/portalapp/widget/service/impl/StorageServiceImpl.java index c2633948..18611728 100644 --- a/ecomp-portal-widget-ms/widget-ms/src/main/java/org/onap/portalapp/widget/service/impl/StorageServiceImpl.java +++ b/ecomp-portal-widget-ms/widget-ms/src/main/java/org/onap/portalapp/widget/service/impl/StorageServiceImpl.java @@ -101,9 +101,9 @@ public class StorageServiceImpl implements StorageService { String fileLocation = file.getOriginalFilename(); logger.debug("StorageServiceImpl.checkZipFile: store the widget to:" + fileLocation); convFile = new File(fileLocation); - FileOutputStream fos = new FileOutputStream(convFile); - fos.write(file.getBytes()); - fos.close(); + try(FileOutputStream fos = new FileOutputStream(convFile)){ + fos.write(file.getBytes()); + } map = unzipper.unzip_db(fileLocation, ".", "tempWidgets"); convFile.delete(); } catch (IOException e) { @@ -137,9 +137,9 @@ public class StorageServiceImpl implements StorageService { String fileLocation = file.getOriginalFilename(); logger.debug("StorageServiceImpl.save: store the widget to:" + fileLocation); convFile = new File(fileLocation); - FileOutputStream fos = new FileOutputStream(convFile); - fos.write(file.getBytes()); - fos.close(); + try(FileOutputStream fos = new FileOutputStream(convFile)){ + fos.write(file.getBytes()); + } map = unzipper.unzip_db(fileLocation, ".", "tempWidgets"); convFile.delete(); } catch (IOException e) { @@ -183,35 +183,29 @@ public class StorageServiceImpl implements StorageService { widgetFile.setName(newWidget.getName()); widgetFile.setWidgetId(widgetId); - InputStream fileInputStream = this.getClass().getClassLoader().getResourceAsStream("framework-template.js"); + String sb = null; - try { + try(InputStream fileInputStream = this.getClass().getClassLoader().getResourceAsStream("framework-template.js")) { byte[] bytes = new byte[fileInputStream.available()]; - fileInputStream.read(bytes); - sb = new String(bytes, "UTF-8"); + if(fileInputStream.read(bytes) > 0) { + sb = new String(bytes, "UTF-8"); + } } catch (IOException e) { logger.error("StorageServiceImpl.save: Failed to load framework-template.js file ", e); - e.printStackTrace(); - } finally { - if (fileInputStream != null) { - try { - fileInputStream.close(); - } catch (IOException e) { - logger.error("StorageServiceImpl.update: Failed to close the fileInputStream ", e); - } - } } String namespace = "Portal" + widgetId + "Widget"; String controllerName = "Portal" + widgetId + "Ctrl"; String cssName = "portal" + widgetId + "-css-ready"; String colorArg1 = "color: #fff"; - String framework = sb.replaceAll("ARGUMENT1", namespace).replaceAll("ARGUMENT2", controllerName) - .replaceAll("ARGUMENT3", cssName).replaceAll("CSS_ARG1", colorArg1) - .replaceAll("MICROSERVICE_ID", newWidget.getServiceId().toString()) - .replaceAll("WIDGET_ID", Long.toString(widgetId)); - + String framework=""; + if(sb!=null) { + framework = sb.replaceAll("ARGUMENT1", namespace).replaceAll("ARGUMENT2", controllerName) + .replaceAll("ARGUMENT3", cssName).replaceAll("CSS_ARG1", colorArg1) + .replaceAll("MICROSERVICE_ID", newWidget.getServiceId().toString()) + .replaceAll("WIDGET_ID", Long.toString(widgetId)); + } widgetFile.setFramework(framework.getBytes()); final byte[] controllerLoc = map.get(WidgetConstant.WIDGET_CONTROLLER_LOCATION); @@ -277,9 +271,9 @@ public class StorageServiceImpl implements StorageService { String fileLocation = file.getOriginalFilename(); logger.debug("StorageServiceImpl.update: store the widget to:" + fileLocation); convFile = new File(fileLocation); - FileOutputStream fos = new FileOutputStream(convFile); - fos.write(file.getBytes()); - fos.close(); + try(FileOutputStream fos = new FileOutputStream(convFile)){ + fos.write(file.getBytes()); + } map = unzipper.unzip_db(fileLocation, ".", "tempWidgets"); convFile.delete(); } catch (IOException e) { @@ -289,34 +283,27 @@ public class StorageServiceImpl implements StorageService { } WidgetFile widgetFile = getWidgetFile(widgetId); - InputStream fileInputStream = this.getClass().getClassLoader().getResourceAsStream("framework-template.js"); String sb = null; - try { + try(InputStream fileInputStream = this.getClass().getClassLoader().getResourceAsStream("framework-template.js")){ byte[] bytes = new byte[fileInputStream.available()]; - fileInputStream.read(bytes); - sb = new String(bytes, "UTF-8"); + if(fileInputStream.read(bytes) > 0) { + sb = new String(bytes, "UTF-8"); + } } catch (IOException e) { logger.error("StorageServiceImpl.save: Failed to load framework-template.js file ", e); - e.printStackTrace(); - } finally { - if (fileInputStream != null) { - try { - fileInputStream.close(); - } catch (IOException e) { - logger.error("StorageServiceImpl.update: Failed to close the fileInputStream ", e); - e.printStackTrace(); - } - } } String namespace = "Portal" + widgetId + "Widget"; String controllerName = "Portal" + widgetId + "Ctrl"; String cssName = "portal" + widgetId + "-css-ready"; String colorArg1 = "color: #fff"; - String framework = sb.replaceAll("ARGUMENT1", namespace).replaceAll("ARGUMENT2", controllerName) - .replaceAll("ARGUMENT3", cssName).replaceAll("CSS_ARG1", colorArg1) - .replaceAll("MICROSERVICE_ID", newWidget.getServiceId().toString()) - .replaceAll("WIDGET_ID", Long.toString(widgetId)); + String framework=""; + if(sb!=null) { + framework = sb.replaceAll("ARGUMENT1", namespace).replaceAll("ARGUMENT2", controllerName) + .replaceAll("ARGUMENT3", cssName).replaceAll("CSS_ARG1", colorArg1) + .replaceAll("MICROSERVICE_ID", newWidget.getServiceId().toString()) + .replaceAll("WIDGET_ID", Long.toString(widgetId)); + } widgetFile.setFramework(framework.getBytes()); String javascript = new String(map.get(WidgetConstant.WIDGET_CONTROLLER_LOCATION)); @@ -441,53 +428,53 @@ public class StorageServiceImpl implements StorageService { String styles = getWidgetCSS(widgetId).replaceAll(cssName, widget.getName() + "-css-ready"); File f = File.createTempFile("temp", ".zip"); - ZipOutputStream out = new ZipOutputStream(new FileOutputStream(f)); - ZipEntry e = new ZipEntry(widget.getName() + "/styles/styles.css"); - out.putNextEntry(new ZipEntry(widget.getName() + "/")); - out.putNextEntry(new ZipEntry(widget.getName() + "/styles/")); - out.putNextEntry(e); - byte[] data = styles.getBytes(); - out.write(data, 0, data.length); - - String widgetData = namespace + "=" + namespace + "||{};" + "var res = " + namespace + ".widgetData;"; - String javascript = getWidgetController(widgetId).replace(widgetData, "").replace(namespace + ".controller =", - ""); - - String functionHeader = javascript.substring(javascript.indexOf("function"), javascript.indexOf(")") + 1); - javascript = javascript.replaceFirst(controllerName, widget.getName() + "Ctrl"); - String functionParam = functionHeader.substring(functionHeader.indexOf("(") + 1, functionHeader.indexOf(")")); - StringBuilder injectStr = new StringBuilder().append("["); - List paramList = Arrays.asList(functionParam.split(",")); - for (int i = 0; i < paramList.size(); i++) { - if (i == paramList.size() - 1) - injectStr.append("'" + paramList.get(i).trim() + "'];"); - else - injectStr.append("'" + paramList.get(i).trim() + "',"); + try(ZipOutputStream out = new ZipOutputStream(new FileOutputStream(f))){ + ZipEntry e = new ZipEntry(widget.getName() + "/styles/styles.css"); + out.putNextEntry(new ZipEntry(widget.getName() + "/")); + out.putNextEntry(new ZipEntry(widget.getName() + "/styles/")); + out.putNextEntry(e); + byte[] data = styles.getBytes(); + out.write(data, 0, data.length); + + String widgetData = namespace + "=" + namespace + "||{};" + "var res = " + namespace + ".widgetData;"; + String javascript = getWidgetController(widgetId).replace(widgetData, "").replace(namespace + ".controller =", + ""); + + String functionHeader = javascript.substring(javascript.indexOf("function"), javascript.indexOf(")") + 1); + javascript = javascript.replaceFirst(controllerName, widget.getName() + "Ctrl"); + String functionParam = functionHeader.substring(functionHeader.indexOf("(") + 1, functionHeader.indexOf(")")); + StringBuilder injectStr = new StringBuilder().append("["); + List paramList = Arrays.asList(functionParam.split(",")); + for (int i = 0; i < paramList.size(); i++) { + if (i == paramList.size() - 1) + injectStr.append("'" + paramList.get(i).trim() + "'];"); + else + injectStr.append("'" + paramList.get(i).trim() + "',"); + } + javascript = javascript.replace(";" + namespace + ".controller.$inject = " + injectStr.toString(), ""); + + e = new ZipEntry(widget.getName() + "/js/controller.js"); + out.putNextEntry(new ZipEntry(widget.getName() + "/js/")); + out.putNextEntry(e); + data = javascript.getBytes(); + out.write(data, 0, data.length); + + String html = getWidgetMarkup(widgetId).replaceFirst(controllerName, widget.getName() + "Ctrl"); + + // new + // String(map.get(WidgetConstant.WIDGET_MARKUP_LOCATION)).replaceFirst(functionName, + // controllerName);; + + e = new ZipEntry(widget.getName() + "/markup/markup.html"); + out.putNextEntry(new ZipEntry(widget.getName() + "/markup/")); + out.putNextEntry(e); + data = html.getBytes(); + out.write(data, 0, data.length); + out.closeEntry(); + byte[] result = Files.readAllBytes(Paths.get(f.getPath())); + f.delete(); + return result; } - javascript = javascript.replace(";" + namespace + ".controller.$inject = " + injectStr.toString(), ""); - - e = new ZipEntry(widget.getName() + "/js/controller.js"); - out.putNextEntry(new ZipEntry(widget.getName() + "/js/")); - out.putNextEntry(e); - data = javascript.getBytes(); - out.write(data, 0, data.length); - - String html = getWidgetMarkup(widgetId).replaceFirst(controllerName, widget.getName() + "Ctrl"); - - // new - // String(map.get(WidgetConstant.WIDGET_MARKUP_LOCATION)).replaceFirst(functionName, - // controllerName);; - - e = new ZipEntry(widget.getName() + "/markup/markup.html"); - out.putNextEntry(new ZipEntry(widget.getName() + "/markup/")); - out.putNextEntry(e); - data = html.getBytes(); - out.write(data, 0, data.length); - out.closeEntry(); - out.close(); - byte[] result = Files.readAllBytes(Paths.get(f.getPath())); - f.delete(); - return result; } } diff --git a/ecomp-portal-widget-ms/widget-ms/src/main/java/org/onap/portalapp/widget/utils/UnzipUtil.java b/ecomp-portal-widget-ms/widget-ms/src/main/java/org/onap/portalapp/widget/utils/UnzipUtil.java index d699e5da..f20ed1b5 100644 --- a/ecomp-portal-widget-ms/widget-ms/src/main/java/org/onap/portalapp/widget/utils/UnzipUtil.java +++ b/ecomp-portal-widget-ms/widget-ms/src/main/java/org/onap/portalapp/widget/utils/UnzipUtil.java @@ -46,49 +46,51 @@ public class UnzipUtil { File destDir = new File(destDirectory); if (!destDir.exists()) destDir.mkdir(); - ZipInputStream zipIn = new ZipInputStream(new FileInputStream(zipFilePath)); - ZipEntry entry = zipIn.getNextEntry(); - Map map = new HashMap<>(); - - String[] requiredKeys = { WidgetConstant.WIDGET_CONTROLLER_LOCATION, WidgetConstant.WIDGET_MARKUP_LOCATION, - WidgetConstant.WIDGET_STYLE_LOCATION }; - for (String k : requiredKeys) - map.put(k, null); - - // iterates over entries in the zip file - Stack stack = new Stack<>(); - while (entry != null) { - String filePath = destDirectory + File.separator + widgetName + File.separator - + entry.getName().substring(entry.getName().indexOf("/") + 1); - final String entryShortName = entry.getName().substring(entry.getName().indexOf("/") + 1); - logger.debug("UnzipUtil.unzip_db: file path {}, short name {}", filePath, entryShortName); - if (!entry.isDirectory()) { - // if the entry is a file, extracts it - logger.debug("UnzipUtil.unzip_db: unzip and save widget file {}", filePath); - stack.push(new File(filePath)); - extractFile(zipIn, filePath); - } else { - // if the entry is a directory, make the directory - logger.debug("UnzipUtil.unzip_db: unzip and create widget folder {}", filePath); - File dir = new File(filePath); - stack.push(new File(filePath)); - dir.mkdir(); + try(ZipInputStream zipIn = new ZipInputStream(new FileInputStream(zipFilePath))) + { + ZipEntry entry = zipIn.getNextEntry(); + Map map = new HashMap<>(); + + String[] requiredKeys = { WidgetConstant.WIDGET_CONTROLLER_LOCATION, WidgetConstant.WIDGET_MARKUP_LOCATION, + WidgetConstant.WIDGET_STYLE_LOCATION }; + for (String k : requiredKeys) + map.put(k, null); + + // iterates over entries in the zip file + Stack stack = new Stack<>(); + while (entry != null) { + String filePath = destDirectory + File.separator + widgetName + File.separator + + entry.getName().substring(entry.getName().indexOf("/") + 1); + final String entryShortName = entry.getName().substring(entry.getName().indexOf("/") + 1); + logger.debug("UnzipUtil.unzip_db: file path {}, short name {}", filePath, entryShortName); + if (!entry.isDirectory()) { + // if the entry is a file, extracts it + logger.debug("UnzipUtil.unzip_db: unzip and save widget file {}", filePath); + stack.push(new File(filePath)); + extractFile(zipIn, filePath); + } else { + // if the entry is a directory, make the directory + logger.debug("UnzipUtil.unzip_db: unzip and create widget folder {}", filePath); + File dir = new File(filePath); + stack.push(new File(filePath)); + dir.mkdir(); + } + // Is this one we need? + if (map.containsKey(entryShortName)) + map.put(entryShortName, Files.readAllBytes(Paths.get(filePath))); + zipIn.closeEntry(); + entry = zipIn.getNextEntry(); } - // Is this one we need? - if (map.containsKey(entryShortName)) - map.put(entryShortName, Files.readAllBytes(Paths.get(filePath))); - zipIn.closeEntry(); - entry = zipIn.getNextEntry(); + + while (!stack.isEmpty()) + stack.pop().delete(); + + for (String k : requiredKeys) + if (!map.containsKey(k)) + logger.warn("UnzipUtil.unzip_db: no zip archive entry found for required key {}", k); + + return map; } - zipIn.close(); - while (!stack.isEmpty()) - stack.pop().delete(); - - for (String k : requiredKeys) - if (!map.containsKey(k)) - logger.warn("UnzipUtil.unzip_db: no zip archive entry found for required key {}", k); - - return map; } /** @@ -99,12 +101,12 @@ public class UnzipUtil { * @throws IOException */ private void extractFile(ZipInputStream zipIn, String filePath) throws IOException { - BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(filePath)); - byte[] bytesIn = new byte[BUFFER_SIZE]; - int read = 0; - while ((read = zipIn.read(bytesIn)) != -1) { - bos.write(bytesIn, 0, read); + try(BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(filePath))){ + byte[] bytesIn = new byte[BUFFER_SIZE]; + int read = 0; + while ((read = zipIn.read(bytesIn)) != -1) { + bos.write(bytesIn, 0, read); + } } - bos.close(); } } \ No newline at end of file