X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=ecomp-portal-widget-ms%2Fwidget-ms%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Fportalapp%2Fwidget%2Fcontroller%2FWidgetsCatalogController.java;h=e6c1c0ac225b3c0fbff2acdb4e15cfd576f1b468;hb=0547751f8b0b8b5a3e96fb04c266e23884f97b85;hp=b1450b6d4233ba7e47cd792f94b378c0459eef75;hpb=ac6160ed5e61dafc2435bbf58e2e2de5d4726487;p=portal.git 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 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 getUserWidgetCatalog(HttpServletRequest request, HttpServletResponse response, @PathVariable("loginName") String loginName, @RequestHeader(value="Authorization") String auth) throws IOException { List 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 getWidgetByServiceId(HttpServletRequest request, HttpServletResponse response, @PathVariable("serviceId") Long serviceId, @RequestHeader(value="Authorization") String auth) throws IOException { List 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;