summaryrefslogtreecommitdiffstats
path: root/ecomp-portal-widget-ms/widget-ms
diff options
context:
space:
mode:
Diffstat (limited to 'ecomp-portal-widget-ms/widget-ms')
-rw-r--r--ecomp-portal-widget-ms/widget-ms/pom.xml20
-rw-r--r--ecomp-portal-widget-ms/widget-ms/src/main/java/org/onap/portalapp/widget/controller/DatabaseFileUploadController.java11
-rw-r--r--ecomp-portal-widget-ms/widget-ms/src/main/java/org/onap/portalapp/widget/controller/HealthController.java7
-rw-r--r--ecomp-portal-widget-ms/widget-ms/src/main/java/org/onap/portalapp/widget/controller/WidgetsCatalogController.java36
-rw-r--r--ecomp-portal-widget-ms/widget-ms/src/main/java/org/onap/portalapp/widget/domain/App.java2
-rw-r--r--ecomp-portal-widget-ms/widget-ms/src/main/java/org/onap/portalapp/widget/domain/MicroserviceData.java2
-rw-r--r--ecomp-portal-widget-ms/widget-ms/src/main/java/org/onap/portalapp/widget/domain/MicroserviceParameter.java2
-rw-r--r--ecomp-portal-widget-ms/widget-ms/src/main/java/org/onap/portalapp/widget/domain/RoleApp.java2
-rw-r--r--ecomp-portal-widget-ms/widget-ms/src/main/java/org/onap/portalapp/widget/domain/WidgetCatalog.java2
-rw-r--r--ecomp-portal-widget-ms/widget-ms/src/main/java/org/onap/portalapp/widget/hibernate/HibernateConfiguration.java2
-rw-r--r--ecomp-portal-widget-ms/widget-ms/src/main/java/org/onap/portalapp/widget/service/StorageService.java2
-rw-r--r--ecomp-portal-widget-ms/widget-ms/src/main/java/org/onap/portalapp/widget/service/impl/MicroserviceServiceImpl.java6
-rw-r--r--ecomp-portal-widget-ms/widget-ms/src/main/java/org/onap/portalapp/widget/service/impl/StorageServiceImpl.java135
-rw-r--r--ecomp-portal-widget-ms/widget-ms/src/main/java/org/onap/portalapp/widget/service/impl/WidgetCatalogServiceImpl.java13
-rw-r--r--ecomp-portal-widget-ms/widget-ms/src/main/java/org/onap/portalapp/widget/utils/UnzipUtil.java3
-rw-r--r--ecomp-portal-widget-ms/widget-ms/src/main/resources/application.properties12
-rw-r--r--ecomp-portal-widget-ms/widget-ms/src/test/java/org/onap/portalapp/widget/service/impl/WidgetCatalogServiceImplTest.java3
-rw-r--r--ecomp-portal-widget-ms/widget-ms/src/test/java/org/onap/portalapp/widget/test/controller/WidgetsCatalogControllerTest.java16
18 files changed, 161 insertions, 115 deletions
diff --git a/ecomp-portal-widget-ms/widget-ms/pom.xml b/ecomp-portal-widget-ms/widget-ms/pom.xml
index 4095388c..2cdf13f3 100644
--- a/ecomp-portal-widget-ms/widget-ms/pom.xml
+++ b/ecomp-portal-widget-ms/widget-ms/pom.xml
@@ -7,13 +7,13 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
- <version>1.5.11.RELEASE</version>
+ <version>2.2.5.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<groupId>org.onap.portal</groupId>
<artifactId>widget-ms</artifactId>
- <version>3.3.0</version>
+ <version>3.4.0</version>
<packaging>jar</packaging>
<name>widget-microservice</name>
@@ -22,10 +22,10 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
- <hibernate.version>4.3.11.Final</hibernate.version>
+ <hibernate.version>5.4.14.Final</hibernate.version>
<skipTests>false</skipTests>
<!-- Replicate this from OParent -->
- <jacocoVersion>0.7.6.201602180812</jacocoVersion>
+ <jacocoVersion>0.8.2</jacocoVersion>
</properties>
<dependencies>
@@ -68,7 +68,7 @@
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
- <!-- <version>${hibernate.version}</version> -->
+ <version>${hibernate.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
@@ -91,12 +91,12 @@
<dependency>
<groupId>org.mariadb.jdbc</groupId>
<artifactId>mariadb-java-client</artifactId>
- <!-- <version>1.5.8</version> -->
+ <version>1.5.8</version>
</dependency>
<dependency>
<groupId>com.github.ulisesbocchio</groupId>
<artifactId>jasypt-spring-boot-starter</artifactId>
- <version>1.9</version>
+ <version>2.1.0</version>
</dependency>
<dependency>
<groupId>org.jsoup</groupId>
@@ -109,7 +109,7 @@
<dependency>
<groupId>dom4j</groupId>
<artifactId>dom4j</artifactId>
- <!-- <version>1.6.1</version> -->
+ <version>1.6.1</version>
<exclusions>
<exclusion>
<groupId>jaxme</groupId>
@@ -151,7 +151,7 @@
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-core</artifactId>
- <version>8.5.28</version>
+ <version>9.0.33</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
@@ -181,7 +181,7 @@
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-web</artifactId>
- <version>4.2.13.RELEASE</version>
+ <version>5.2.3.RELEASE</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
diff --git a/ecomp-portal-widget-ms/widget-ms/src/main/java/org/onap/portalapp/widget/controller/DatabaseFileUploadController.java b/ecomp-portal-widget-ms/widget-ms/src/main/java/org/onap/portalapp/widget/controller/DatabaseFileUploadController.java
index acdde23b..dc8cb20d 100644
--- a/ecomp-portal-widget-ms/widget-ms/src/main/java/org/onap/portalapp/widget/controller/DatabaseFileUploadController.java
+++ b/ecomp-portal-widget-ms/widget-ms/src/main/java/org/onap/portalapp/widget/controller/DatabaseFileUploadController.java
@@ -11,8 +11,7 @@ import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller
@@ -24,7 +23,7 @@ public class DatabaseFileUploadController {
private static final Logger logger = LoggerFactory.getLogger(DatabaseFileUploadController.class);
@ResponseBody
- @RequestMapping(value = "/microservices/markup/{widgetId}", method = RequestMethod.GET)
+ @GetMapping(value = "/microservices/markup/{widgetId}")
public String getWidgetMarkup(HttpServletRequest request, HttpServletResponse response, @PathVariable("widgetId") long widgetId){
String markup = null;
try{
@@ -37,7 +36,7 @@ public class DatabaseFileUploadController {
}
@ResponseBody
- @RequestMapping(value = "/microservices/{widgetId}/controller.js", method = RequestMethod.GET)
+ @GetMapping(value = "/microservices/{widgetId}/controller.js")
public String getWidgetController(HttpServletRequest request, HttpServletResponse response, @PathVariable("widgetId") long widgetId){
String controller = null;
try{
@@ -50,7 +49,7 @@ public class DatabaseFileUploadController {
}
@ResponseBody
- @RequestMapping(value = "/microservices/{widgetId}/framework.js", method = RequestMethod.GET)
+ @GetMapping(value = "/microservices/{widgetId}/framework.js")
public String getWidgetFramework(HttpServletRequest request, HttpServletResponse response,
@PathVariable("widgetId") long widgetId){
String framework = null;
@@ -64,7 +63,7 @@ public class DatabaseFileUploadController {
}
@ResponseBody
- @RequestMapping(value = "/microservices/{widgetId}/styles.css", method = RequestMethod.GET)
+ @GetMapping(value = "/microservices/{widgetId}/styles.css")
public String getWidgetCSS(HttpServletRequest request, HttpServletResponse response,
@PathVariable("widgetId") long widgetId){
String css = null;
diff --git a/ecomp-portal-widget-ms/widget-ms/src/main/java/org/onap/portalapp/widget/controller/HealthController.java b/ecomp-portal-widget-ms/widget-ms/src/main/java/org/onap/portalapp/widget/controller/HealthController.java
index 6814f75a..1eb2c966 100644
--- a/ecomp-portal-widget-ms/widget-ms/src/main/java/org/onap/portalapp/widget/controller/HealthController.java
+++ b/ecomp-portal-widget-ms/widget-ms/src/main/java/org/onap/portalapp/widget/controller/HealthController.java
@@ -3,14 +3,13 @@ package org.onap.portalapp.widget.controller;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
-
+
@RestController
public class HealthController {
- @RequestMapping(value = { "/health" }, method = RequestMethod.GET, produces = "application/json")
+ @GetMapping(value = { "/health" }, produces = "application/json")
public HealthStatus getWidgetCatalog(HttpServletRequest request, HttpServletResponse response) {
return new HealthStatus("ok");
}
diff --git a/ecomp-portal-widget-ms/widget-ms/src/main/java/org/onap/portalapp/widget/controller/WidgetsCatalogController.java b/ecomp-portal-widget-ms/widget-ms/src/main/java/org/onap/portalapp/widget/controller/WidgetsCatalogController.java
index b1450b6d..e6c1c0ac 100644
--- a/ecomp-portal-widget-ms/widget-ms/src/main/java/org/onap/portalapp/widget/controller/WidgetsCatalogController.java
+++ b/ecomp-portal-widget-ms/widget-ms/src/main/java/org/onap/portalapp/widget/controller/WidgetsCatalogController.java
@@ -4,7 +4,7 @@ import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
-import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.onap.portalapp.widget.domain.ValidationRespond;
@@ -21,8 +21,10 @@ import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PutMapping;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.client.RestTemplate;
@@ -37,12 +39,12 @@ public class WidgetsCatalogController {
@Value("${server.port}")
String port;
- @Value("${server.contextPath}")
+ @Value("${server.servlet.context-path}")
String context;
- @Value("${security.user.name}")
+ @Value("${spring.security.user.name}")
String security_user;
- @Value("${security.user.password}")
+ @Value("${spring.security.user.password}")
String security_pass;
@Autowired
@@ -59,7 +61,7 @@ public class WidgetsCatalogController {
private static final Logger logger = LoggerFactory.getLogger(WidgetsCatalogController.class);
@ResponseBody
- @RequestMapping(value = { "/microservices/widgetCatalog" }, method = RequestMethod.GET, produces = "application/json")
+ @GetMapping(value = { "/microservices/widgetCatalog" }, produces = "application/json")
public List<WidgetCatalog> getWidgetCatalog(HttpServletRequest request, HttpServletResponse response
,@RequestHeader(value="Authorization") String auth) throws IOException{
@@ -79,7 +81,7 @@ public class WidgetsCatalogController {
}
@ResponseBody
- @RequestMapping(value = { "/microservices/widgetCatalog/{loginName}" }, method = RequestMethod.GET, produces = "application/json")
+ @GetMapping(value = { "/microservices/widgetCatalog/{loginName}" }, produces = "application/json")
public List<WidgetCatalog> getUserWidgetCatalog(HttpServletRequest request, HttpServletResponse response,
@PathVariable("loginName") String loginName, @RequestHeader(value="Authorization") String auth) throws IOException {
List<WidgetCatalog> widgetCatalog = null;
@@ -98,7 +100,7 @@ public class WidgetsCatalogController {
}
@ResponseBody
- @RequestMapping(value = { "/microservices/widgetCatalog/{widgetId}" }, method = RequestMethod.PUT, produces = "application/json")
+ @PutMapping(value = { "/microservices/widgetCatalog/{widgetId}" }, produces = "application/json")
public void updateWidgetCatalog(HttpServletRequest request, HttpServletResponse response,
@RequestBody WidgetCatalog newWidgetCatalog, @PathVariable("widgetId") long widgetId,
@RequestHeader(value="Authorization") String auth) throws IOException {
@@ -117,7 +119,7 @@ public class WidgetsCatalogController {
}
@ResponseBody
- @RequestMapping(value = { "/microservices/widgetCatalog" }, method = RequestMethod.POST, produces = "application/json")
+ @PostMapping(value = { "/microservices/widgetCatalog" }, produces = "application/json")
public ValidationRespond saveWidgetCatalog(HttpServletRequest request, HttpServletResponse response, @RequestHeader(value="Authorization") String auth,
@RequestParam("file") MultipartFile file, @RequestParam("widget") String widget) throws IOException {
@@ -148,7 +150,7 @@ public class WidgetsCatalogController {
}
@ResponseBody
- @RequestMapping(value = { "/microservices/widgetCatalog/{widgetId}" }, method = RequestMethod.POST, produces = "application/json")
+ @PostMapping(value = { "/microservices/widgetCatalog/{widgetId}" }, produces = "application/json")
public ValidationRespond updateWidgetCatalogwithFiles(HttpServletRequest request, HttpServletResponse response, @RequestHeader(value="Authorization") String auth,
@RequestParam("file") MultipartFile file, @RequestParam("widget") String widget, @PathVariable("widgetId") long widgetId) throws IOException {
logger.debug("microserivces updating with files {}", widgetId);
@@ -161,13 +163,14 @@ public class WidgetsCatalogController {
try {
//check the zip file structure first
respond = storageService.checkZipFile(file);
+ logger.debug("Check file validity"+respond.isValid()+respond.getError());
if(respond.isValid()){
//update the widget catalog
WidgetCatalog newWidget = new ObjectMapper().readValue(widget, WidgetCatalog.class);
widgetCatalogService.updateWidgetCatalog(widgetId, newWidget);
logger.debug("WidgetsCatalogController.saveWidgetCatalog: updating widget with widgetId={}", widgetId);
//update the widget zip file
- storageService.update(file, newWidget, widgetId);
+ storageService.updateJsFile(file, newWidget, widgetId);
}
} catch (Exception e) {
logger.error("Exception occurred while performing WidgetsCatalogController.saveWidgetCatalog in widget microservices. Details:", e);
@@ -176,8 +179,7 @@ public class WidgetsCatalogController {
}
@ResponseBody
- @RequestMapping(value = { "/microservices/widgetCatalog/{widgetId}" }, method = {
- RequestMethod.DELETE }, produces = "application/json")
+ @DeleteMapping(value = { "/microservices/widgetCatalog/{widgetId}" }, produces = "application/json")
public void deleteOnboardingWidget(HttpServletRequest request, HttpServletResponse response,
@PathVariable("widgetId") long widgetId, @RequestHeader(value="Authorization") String auth) throws IOException{
if(!util.authorization(auth, security_user, security_pass)){
@@ -196,7 +198,7 @@ public class WidgetsCatalogController {
}
@ResponseBody
- @RequestMapping(value = { "/microservices/widgetCatalog/parameters/{widgetId}" }, method = RequestMethod.GET, produces = "application/json")
+ @GetMapping(value = { "/microservices/widgetCatalog/parameters/{widgetId}" }, produces = "application/json")
public Long getServiceIdByWidget(HttpServletRequest request, HttpServletResponse response,
@PathVariable("widgetId") Long widgetId, @RequestHeader(value="Authorization") String auth) throws IOException {
@@ -217,7 +219,7 @@ public class WidgetsCatalogController {
@ResponseBody
- @RequestMapping(value = { "/microservices/widgetCatalog/service/{serviceId}" }, method = RequestMethod.GET, produces = "application/json")
+ @GetMapping(value = { "/microservices/widgetCatalog/service/{serviceId}" }, produces = "application/json")
public List<WidgetCatalog> getWidgetByServiceId(HttpServletRequest request, HttpServletResponse response,
@PathVariable("serviceId") Long serviceId, @RequestHeader(value="Authorization") String auth) throws IOException {
List<WidgetCatalog> list = new ArrayList<>();
@@ -237,7 +239,7 @@ public class WidgetsCatalogController {
@ResponseBody
- @RequestMapping(value = { "/microservices/download/{widgetId}" }, method = RequestMethod.GET, produces = "application/json")
+ @GetMapping(value = { "/microservices/download/{widgetId}" }, produces = "application/json")
public byte[] getWidgetZipFile(HttpServletRequest request, HttpServletResponse response,
@PathVariable("widgetId") long widgetId, @RequestHeader(value="Authorization") String auth) throws Exception {
byte[] byteFile = null;
diff --git a/ecomp-portal-widget-ms/widget-ms/src/main/java/org/onap/portalapp/widget/domain/App.java b/ecomp-portal-widget-ms/widget-ms/src/main/java/org/onap/portalapp/widget/domain/App.java
index 212826cd..46ee814c 100644
--- a/ecomp-portal-widget-ms/widget-ms/src/main/java/org/onap/portalapp/widget/domain/App.java
+++ b/ecomp-portal-widget-ms/widget-ms/src/main/java/org/onap/portalapp/widget/domain/App.java
@@ -21,7 +21,7 @@ public class App implements Serializable{
@Id
@Column(name = "APP_ID")
- @GeneratedValue(strategy=GenerationType.AUTO)
+ @GeneratedValue(strategy=GenerationType.IDENTITY)
@Digits(integer = 11, fraction = 0)
private Long appId;
diff --git a/ecomp-portal-widget-ms/widget-ms/src/main/java/org/onap/portalapp/widget/domain/MicroserviceData.java b/ecomp-portal-widget-ms/widget-ms/src/main/java/org/onap/portalapp/widget/domain/MicroserviceData.java
index 43e7b2b0..2ed49ab4 100644
--- a/ecomp-portal-widget-ms/widget-ms/src/main/java/org/onap/portalapp/widget/domain/MicroserviceData.java
+++ b/ecomp-portal-widget-ms/widget-ms/src/main/java/org/onap/portalapp/widget/domain/MicroserviceData.java
@@ -26,7 +26,7 @@ public class MicroserviceData {
@Id
@Column(name = "id")
@Digits(integer = 11, fraction = 0)
- @GeneratedValue(strategy=GenerationType.AUTO)
+ @GeneratedValue(strategy=GenerationType.IDENTITY)
private Long id;
@Column(name = "name")
diff --git a/ecomp-portal-widget-ms/widget-ms/src/main/java/org/onap/portalapp/widget/domain/MicroserviceParameter.java b/ecomp-portal-widget-ms/widget-ms/src/main/java/org/onap/portalapp/widget/domain/MicroserviceParameter.java
index 7207d0ae..cd9236da 100644
--- a/ecomp-portal-widget-ms/widget-ms/src/main/java/org/onap/portalapp/widget/domain/MicroserviceParameter.java
+++ b/ecomp-portal-widget-ms/widget-ms/src/main/java/org/onap/portalapp/widget/domain/MicroserviceParameter.java
@@ -24,7 +24,7 @@ public class MicroserviceParameter {
@Id
@Column(name = "id")
- @GeneratedValue(strategy=GenerationType.AUTO)
+ @GeneratedValue(strategy=GenerationType.IDENTITY)
@Digits(integer = 11, fraction = 0)
private Long id;
diff --git a/ecomp-portal-widget-ms/widget-ms/src/main/java/org/onap/portalapp/widget/domain/RoleApp.java b/ecomp-portal-widget-ms/widget-ms/src/main/java/org/onap/portalapp/widget/domain/RoleApp.java
index aae9bfed..173a1430 100644
--- a/ecomp-portal-widget-ms/widget-ms/src/main/java/org/onap/portalapp/widget/domain/RoleApp.java
+++ b/ecomp-portal-widget-ms/widget-ms/src/main/java/org/onap/portalapp/widget/domain/RoleApp.java
@@ -33,7 +33,7 @@ public class RoleApp implements Serializable{
@Id
@Column(name = "ROLE_ID")
- @GeneratedValue(strategy=GenerationType.AUTO)
+ @GeneratedValue(strategy=GenerationType.IDENTITY)
@Digits(integer = 11, fraction = 0)
private Long roleId;
diff --git a/ecomp-portal-widget-ms/widget-ms/src/main/java/org/onap/portalapp/widget/domain/WidgetCatalog.java b/ecomp-portal-widget-ms/widget-ms/src/main/java/org/onap/portalapp/widget/domain/WidgetCatalog.java
index 1dc0582c..a822c5a2 100644
--- a/ecomp-portal-widget-ms/widget-ms/src/main/java/org/onap/portalapp/widget/domain/WidgetCatalog.java
+++ b/ecomp-portal-widget-ms/widget-ms/src/main/java/org/onap/portalapp/widget/domain/WidgetCatalog.java
@@ -30,7 +30,7 @@ public class WidgetCatalog{
@Id
@Column(name = "widget_id")
- @GeneratedValue(strategy=GenerationType.AUTO)
+ @GeneratedValue(strategy=GenerationType.IDENTITY)
@Digits(integer = 11, fraction = 0)
private long id;
diff --git a/ecomp-portal-widget-ms/widget-ms/src/main/java/org/onap/portalapp/widget/hibernate/HibernateConfiguration.java b/ecomp-portal-widget-ms/widget-ms/src/main/java/org/onap/portalapp/widget/hibernate/HibernateConfiguration.java
index b52631f1..ac25077b 100644
--- a/ecomp-portal-widget-ms/widget-ms/src/main/java/org/onap/portalapp/widget/hibernate/HibernateConfiguration.java
+++ b/ecomp-portal-widget-ms/widget-ms/src/main/java/org/onap/portalapp/widget/hibernate/HibernateConfiguration.java
@@ -6,7 +6,7 @@ import javax.sql.DataSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
-import org.springframework.orm.hibernate4.LocalSessionFactoryBean;
+import org.springframework.orm.hibernate5.LocalSessionFactoryBean;
import org.springframework.orm.jpa.JpaTransactionManager;
import org.springframework.transaction.PlatformTransactionManager;
diff --git a/ecomp-portal-widget-ms/widget-ms/src/main/java/org/onap/portalapp/widget/service/StorageService.java b/ecomp-portal-widget-ms/widget-ms/src/main/java/org/onap/portalapp/widget/service/StorageService.java
index fbd0f963..d8b56422 100644
--- a/ecomp-portal-widget-ms/widget-ms/src/main/java/org/onap/portalapp/widget/service/StorageService.java
+++ b/ecomp-portal-widget-ms/widget-ms/src/main/java/org/onap/portalapp/widget/service/StorageService.java
@@ -30,5 +30,7 @@ public interface StorageService {
void update(MultipartFile file, WidgetCatalog newWidget, long widgetId);
+ void updateJsFile(MultipartFile file, WidgetCatalog newWidget, long widgetId);
+
byte[] getWidgetCatalogContent(long widgetId) throws Exception;
}
diff --git a/ecomp-portal-widget-ms/widget-ms/src/main/java/org/onap/portalapp/widget/service/impl/MicroserviceServiceImpl.java b/ecomp-portal-widget-ms/widget-ms/src/main/java/org/onap/portalapp/widget/service/impl/MicroserviceServiceImpl.java
index fed70ad9..a02667de 100644
--- a/ecomp-portal-widget-ms/widget-ms/src/main/java/org/onap/portalapp/widget/service/impl/MicroserviceServiceImpl.java
+++ b/ecomp-portal-widget-ms/widget-ms/src/main/java/org/onap/portalapp/widget/service/impl/MicroserviceServiceImpl.java
@@ -41,7 +41,7 @@ public class MicroserviceServiceImpl implements MicroserviceService{
Transaction tx = session.beginTransaction();
session.save(newService);
tx.commit();
- session.flush();
+// session.flush();
session.close();
}
catch(Exception e){
@@ -58,7 +58,7 @@ public class MicroserviceServiceImpl implements MicroserviceService{
Transaction tx = session.beginTransaction();
session.save(newParameter);
tx.commit();
- session.flush();
+// session.flush();
session.close();
}
catch(Exception e){
@@ -77,7 +77,7 @@ public class MicroserviceServiceImpl implements MicroserviceService{
List<MicroserviceData> services = criteria.list();
logger.debug("MicroserviceServiceImpl.getMicroserviceByName: result={}", services);
- session.flush();
+// session.flush();
session.close();
return (services.size() > 0) ? services.get(0).getId() : null;
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 7a35ba4e..3bb41b6b 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
@@ -73,7 +73,7 @@ public class StorageServiceImpl implements StorageService {
Criteria criteria = session.createCriteria(WidgetFile.class);
criteria.add(Restrictions.eq("widgetId", widgetId));
List<WidgetFile> widgetFiles = criteria.list();
- session.flush();
+ //session.flush();
session.close();
if (widgetFiles.size() > 0)
widgetFile = widgetFiles.get(0);
@@ -148,7 +148,7 @@ public class StorageServiceImpl implements StorageService {
logger.error("StorageServiceImpl.save: Failed to store file " + file.getOriginalFilename(), e);
throw new StorageException("Failed to store file " + file.getOriginalFilename(), e);
}
- saveHelper(newWidget, widgetId, map);
+ saveJsHelper(newWidget, widgetId, map);
}
@Override
@@ -167,7 +167,7 @@ public class StorageServiceImpl implements StorageService {
throw new StorageException("Failed to store file " + file.getName(), e);
}
- saveHelper(newWidget, widgetId, map);
+ saveJsHelper(newWidget, widgetId, map);
}
/**
@@ -259,6 +259,90 @@ public class StorageServiceImpl implements StorageService {
widgetId);
}
+
+ /**
+ * Helper method to UnZip File
+ *
+ * @param file
+ */
+ private Map<String, byte[]> unZipFile(MultipartFile file) {
+ UnzipUtil unzipper = new UnzipUtil();
+ Map<String, byte[]> map;
+ File convFile;
+ try {
+ if (file.isEmpty()) {
+ logger.error("StorageServiceImpl.update: Failed to store empty file " + file.getOriginalFilename());
+ throw new StorageException("Failed to store empty file " + file.getOriginalFilename());
+ }
+ String fileLocation = file.getOriginalFilename();
+ logger.debug("StorageServiceImpl.update: store the widget to:" + fileLocation);
+ convFile = new File(fileLocation);
+ try(FileOutputStream fos = new FileOutputStream(convFile)){
+ fos.write(file.getBytes());
+ }
+ map = unzipper.unzip_db(fileLocation, ".", "tempWidgets");
+ convFile.delete();
+ return map;
+ } catch (IOException e) {
+ logger.error("StorageServiceImpl.update: Failed to store file " + file.getOriginalFilename(), e);
+ throw new StorageException("StorageServiceImpl.update: Failed to store file " + file.getOriginalFilename(),
+ e);
+ }
+ }
+
+ /**
+ * Helper method for saving widget file (controller.js) to ep_widget_catalog_files table in database
+ *
+ * @param newWidget
+ * @param widgetId
+ * @param map
+ */
+ private void saveJsHelper(WidgetCatalog newWidget, long widgetId, Map<String, byte[]> map) {
+
+ logger.debug("Going to save controller.js " + newWidget);
+ WidgetFile widgetFile = new WidgetFile();
+ widgetFile.setName(newWidget.getName());
+ widgetFile.setWidgetId(widgetId);
+ final byte[] controllerLoc = map.get(WidgetConstant.WIDGET_CONTROLLER_LOCATION);
+ if (controllerLoc == null || controllerLoc.length == 0)
+ throw new IllegalArgumentException(
+ "Map is missing required key " + WidgetConstant.WIDGET_CONTROLLER_LOCATION);
+ String javascript = new String(controllerLoc);
+
+ widgetFile.setController(javascript.getBytes());
+ Session session = sessionFactory.openSession();
+ session.save(widgetFile);
+ session.flush();
+ session.close();
+ logger.debug(
+ "StorageServiceImpl.save: saved controller.js file to the database for widget {}",
+ widgetId);
+
+ }
+
+ @Override
+ public void updateJsFile(MultipartFile file, WidgetCatalog newWidget, long widgetId) {
+ Map<String, byte[]> map;
+ map = unZipFile(file);
+ //Get existing widget file from DB
+ WidgetFile widgetFile = getWidgetFile(widgetId);
+
+ String javascript = new String(map.get(WidgetConstant.WIDGET_CONTROLLER_LOCATION));
+ widgetFile.setController(javascript.getBytes());
+ Session session = sessionFactory.openSession();
+ Transaction tx = session.beginTransaction();
+ session.update(widgetFile);
+ tx.commit();
+ session.flush();
+ session.close();
+ logger.debug(
+ "StorageServiceImpl.save: updated controller.js file to the database for widget {}",
+ widgetId);
+ }
+
+
+
+
@Override
public void update(MultipartFile file, WidgetCatalog newWidget, long widgetId) {
@@ -424,53 +508,14 @@ public class StorageServiceImpl implements StorageService {
public byte[] getWidgetCatalogContent(long widgetId) throws Exception {
WidgetCatalog widget = widgetCatalogService.getWidgetCatalog(widgetId);
- String namespace = "Portal" + widgetId + "Widget";
- String controllerName = "Portal" + widgetId + "Ctrl";
- String cssName = "portal" + widgetId + "-css-ready";
-
- String styles = getWidgetCSS(widgetId).replaceAll(cssName, widget.getName() + "-css-ready");
File f = File.createTempFile("temp", ".zip");
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<String> 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(), "");
+ String javascript = getWidgetController(widgetId);
- e = new ZipEntry(widget.getName() + "/js/controller.js");
+ ZipEntry 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();
+ byte[] data = javascript.getBytes();
out.write(data, 0, data.length);
out.closeEntry();
byte[] result = Files.readAllBytes(Paths.get(f.getPath()));
diff --git a/ecomp-portal-widget-ms/widget-ms/src/main/java/org/onap/portalapp/widget/service/impl/WidgetCatalogServiceImpl.java b/ecomp-portal-widget-ms/widget-ms/src/main/java/org/onap/portalapp/widget/service/impl/WidgetCatalogServiceImpl.java
index 59180d37..d71356fb 100644
--- a/ecomp-portal-widget-ms/widget-ms/src/main/java/org/onap/portalapp/widget/service/impl/WidgetCatalogServiceImpl.java
+++ b/ecomp-portal-widget-ms/widget-ms/src/main/java/org/onap/portalapp/widget/service/impl/WidgetCatalogServiceImpl.java
@@ -148,14 +148,13 @@ public class WidgetCatalogServiceImpl implements WidgetCatalogService {
@Override
public WidgetCatalog getWidgetCatalog(Long widgetCatalogId) {
Session session = sessionFactory.getCurrentSession();
- Transaction tx = session.beginTransaction();
WidgetCatalog widget = (WidgetCatalog) session.get(WidgetCatalog.class, widgetCatalogId);
- tx.commit();
logger.debug("WidgetCatalogServiceImpl.getWidgetCatalog: getting widget={}", widget);
return widget;
}
@Override
+ @Transactional
public void deleteWidgetCatalog(long widgetCatalogId) {
logger.debug("WidgetCatalogServiceImpl.deleteWidgetCatalog: deleting the widget with widgetId={}", widgetCatalogId);
WidgetCatalog widget = getWidgetCatalog(widgetCatalogId);
@@ -164,7 +163,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);
@@ -174,7 +173,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
@@ -191,7 +190,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());
}
@@ -217,7 +216,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){
@@ -268,7 +267,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;
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 f20ed1b5..164a6983 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
@@ -51,8 +51,7 @@ public class UnzipUtil {
ZipEntry entry = zipIn.getNextEntry();
Map<String, byte[]> map = new HashMap<>();
- String[] requiredKeys = { WidgetConstant.WIDGET_CONTROLLER_LOCATION, WidgetConstant.WIDGET_MARKUP_LOCATION,
- WidgetConstant.WIDGET_STYLE_LOCATION };
+ String[] requiredKeys = { WidgetConstant.WIDGET_CONTROLLER_LOCATION };
for (String k : requiredKeys)
map.put(k, null);
diff --git a/ecomp-portal-widget-ms/widget-ms/src/main/resources/application.properties b/ecomp-portal-widget-ms/widget-ms/src/main/resources/application.properties
index 42483b7f..82b26d6e 100644
--- a/ecomp-portal-widget-ms/widget-ms/src/main/resources/application.properties
+++ b/ecomp-portal-widget-ms/widget-ms/src/main/resources/application.properties
@@ -1,22 +1,22 @@
## General App Properties
-server.contextPath=/widget
+server.servlet.context-path=/widget
server.port=9082
-spring.http.multipart.max-file-size=128MB
-spring.http.multipart.max-request-size=128MB
+spring.servlet.multipart.max-file-size=128MB
+spring.servlet.multipart.max-request-size=128MB
microservice.widget.location=/tmp
## App DB Properties
spring.datasource.url=jdbc:mariadb://localhost:3306/portal
spring.datasource.username=root
-spring.datasource.password=root
+spring.datasource.password=welcome2ibm
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQLDialect
spring.database.driver.classname=org.mariadb.jdbc.Driver
spring.jpa.show-sql=false
spring.jpa.properties.hibernate.format_sql=false
## Basic Authentication Properties
-security.user.name=widget_user
-security.user.password=ENC(IjywcRnI9+nuVEh9+OFFiRWAjBT1n718)
+spring.security.user.name=widget_user
+spring.security.user.password=ENC(IjywcRnI9+nuVEh9+OFFiRWAjBT1n718)
account.user.name=portal
account.user.password=6APqvG4AU2rfLgCvMdySwQ==
diff --git a/ecomp-portal-widget-ms/widget-ms/src/test/java/org/onap/portalapp/widget/service/impl/WidgetCatalogServiceImplTest.java b/ecomp-portal-widget-ms/widget-ms/src/test/java/org/onap/portalapp/widget/service/impl/WidgetCatalogServiceImplTest.java
index 933710d2..2d1fd273 100644
--- a/ecomp-portal-widget-ms/widget-ms/src/test/java/org/onap/portalapp/widget/service/impl/WidgetCatalogServiceImplTest.java
+++ b/ecomp-portal-widget-ms/widget-ms/src/test/java/org/onap/portalapp/widget/service/impl/WidgetCatalogServiceImplTest.java
@@ -59,6 +59,7 @@ import org.mockito.MockitoAnnotations;
import org.onap.portalapp.widget.domain.App;
import org.onap.portalapp.widget.domain.RoleApp;
import org.onap.portalapp.widget.domain.WidgetCatalog;
+import org.hibernate.query.NativeQuery;
public class WidgetCatalogServiceImplTest {
@@ -75,7 +76,7 @@ public class WidgetCatalogServiceImplTest {
Criteria criteria;
@Mock
- SQLQuery query;
+ NativeQuery query;
@Before
public void init() {
diff --git a/ecomp-portal-widget-ms/widget-ms/src/test/java/org/onap/portalapp/widget/test/controller/WidgetsCatalogControllerTest.java b/ecomp-portal-widget-ms/widget-ms/src/test/java/org/onap/portalapp/widget/test/controller/WidgetsCatalogControllerTest.java
index d3dc1cbf..0d01ee50 100644
--- a/ecomp-portal-widget-ms/widget-ms/src/test/java/org/onap/portalapp/widget/test/controller/WidgetsCatalogControllerTest.java
+++ b/ecomp-portal-widget-ms/widget-ms/src/test/java/org/onap/portalapp/widget/test/controller/WidgetsCatalogControllerTest.java
@@ -134,7 +134,7 @@ public class WidgetsCatalogControllerTest {
List<WidgetCatalog> list = new ArrayList<WidgetCatalog>();
WidgetCatalog widget = new WidgetCatalog();
list.add(widget);
- Mockito.when(widgetService.getWidgetCatalog()).thenReturn(list);
+ Mockito.lenient().when(widgetService.getWidgetCatalog()).thenReturn(list);
mockMvc.perform(get("/microservices/widgetCatalog/"))
.andExpect(status().isBadRequest());
@@ -148,7 +148,7 @@ public class WidgetsCatalogControllerTest {
widget.setId(1);
widget.setName("junit");
list.add(widget);
- Mockito.when(widgetService.getUserWidgetCatalog("test")).thenReturn(list);
+ Mockito.lenient().when(widgetService.getUserWidgetCatalog("test")).thenReturn(list);
String security_user = "user";
String security_pass = "password";
@@ -170,7 +170,7 @@ public class WidgetsCatalogControllerTest {
widget.setId(1);
widget.setName("junit");
list.add(widget);
- Mockito.when(widgetService.getUserWidgetCatalog("test")).thenReturn(list);
+ Mockito.lenient().when(widgetService.getUserWidgetCatalog("test")).thenReturn(list);
String security_user = "user";
String security_pass = "password";
@@ -190,7 +190,7 @@ public class WidgetsCatalogControllerTest {
@Test
public void saveWidgetCatalog_ValidAuthorization_NoError() throws Exception {
ValidationRespond respond = new ValidationRespond(true, null);
- Mockito.when(storageService.checkZipFile(any(MultipartFile.class))).thenReturn(respond);
+ Mockito.lenient().when(storageService.checkZipFile(any(MultipartFile.class))).thenReturn(respond);
String security_user = "user";
String security_pass = "password";
@@ -211,7 +211,7 @@ public class WidgetsCatalogControllerTest {
@Test
public void saveWidgetCatalog_Authorization_Error() throws Exception {
ValidationRespond respond = new ValidationRespond(true, null);
- Mockito.when(storageService.checkZipFile(any(MultipartFile.class))).thenReturn(respond);
+ Mockito.lenient().when(storageService.checkZipFile(any(MultipartFile.class))).thenReturn(respond);
String security_user = "user";
String security_pass = "password";
@@ -270,7 +270,7 @@ public class WidgetsCatalogControllerTest {
@Test
public void updateWidgetCatalogwithFiles_ValidAuthorization_NoError() throws Exception {
ValidationRespond respond = new ValidationRespond(true, null);
- Mockito.when(storageService.checkZipFile(any(MultipartFile.class))).thenReturn(respond);
+ Mockito.lenient().when(storageService.checkZipFile(any(MultipartFile.class))).thenReturn(respond);
String security_user = "user";
String security_pass = "password";
@@ -420,7 +420,7 @@ public class WidgetsCatalogControllerTest {
widget.setId(1);
widget.setName("junit");
list.add(widget);
- Mockito.when(widgetService.getWidgetsByServiceId(serviceId)).thenReturn(list);
+ Mockito.lenient().when(widgetService.getWidgetsByServiceId(serviceId)).thenReturn(list);
String security_user = "user";
String security_pass = "password";
@@ -462,7 +462,7 @@ public class WidgetsCatalogControllerTest {
String wrong_pass = "wrong";
Long widgetId = new Long(1);
byte[] bytes="Test".getBytes();
- Mockito.when(storageService.getWidgetCatalogContent(widgetId)).thenReturn(bytes);
+ Mockito.lenient().when(storageService.getWidgetCatalogContent(widgetId)).thenReturn(bytes);
ReflectionTestUtils.setField(controller, "security_user", security_user, String.class);
ReflectionTestUtils.setField(controller, "security_pass", security_pass, String.class);