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;
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;
@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
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{
widgetCatalog = widgetCatalogService.getWidgetCatalog();
logger.debug("WidgetsCatalogController.getWidgetCatalog: getting widget list {}", widgetCatalog);
} catch (Exception e) {
- logger.error("Exception occurred while performing WidgetsCatalogController.getWidgetCatalog in widget microservices. Details:" + e.getMessage());
+ logger.error("Exception occurred while performing WidgetsCatalogController.getWidgetCatalog in widget microservices. Details:", e);
}
return widgetCatalog;
}
@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;
widgetCatalog = widgetCatalogService.getUserWidgetCatalog(loginName);
logger.debug("WidgetsCatalogController.getUserWidgetCatalog: getting widget list {}", widgetCatalog);
} catch (Exception e) {
- logger.error("Exception occurred while performing WidgetsCatalogController.getUserWidgetCatalog in widget microservices. Details:" + e.getMessage());
+ logger.error("Exception occurred while performing WidgetsCatalogController.getUserWidgetCatalog in widget microservices. Details:", e);
}
return widgetCatalog;
}
@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 {
widgetCatalogService.updateWidgetCatalog(widgetId, newWidgetCatalog);
logger.debug("WidgetsCatalogController.updateWidgetCatalog: updating widget {}", newWidgetCatalog);
} catch (Exception e) {
- logger.error("Exception occurred while performing WidgetsCatalogController.updateWidgetCatalog in widget microservices. Details:" + e.getMessage());
- e.printStackTrace();
+ logger.error("Exception occurred while performing WidgetsCatalogController.updateWidgetCatalog in widget microservices. Details:", e);
}
}
@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 {
}
@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 {
- System.out.println("microserivces updating with files" + widgetId);
+ logger.debug("microserivces updating with files {}", widgetId);
ValidationRespond respond = null;
if(!util.authorization(auth, security_user, security_pass)){
response.sendError(HttpServletResponse.SC_UNAUTHORIZED);
storageService.update(file, newWidget, widgetId);
}
} catch (Exception e) {
- logger.error("Exception occurred while performing WidgetsCatalogController.saveWidgetCatalog in widget microservices. Details:" + e.getMessage());
- e.printStackTrace();
+ logger.error("Exception occurred while performing WidgetsCatalogController.saveWidgetCatalog in widget microservices. Details:", e);
}
return respond;
}
@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)){
widgetCatalogService.deleteWidgetCatalog(widgetId);
storageService.deleteWidgetFile(widgetId);
} catch (Exception e) {
- logger.error("Exception occurred while performing WidgetsCatalogController.deleteOnboardingWidget in widget microservices. Details:" + e.getMessage());
+ logger.error("Exception occurred while performing WidgetsCatalogController.deleteOnboardingWidget in widget microservices. Details:", e);
}
}
@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 {
logger.debug("WidgetsCatalogController.getServiceIdByWidget: getting service Id for widget {}", widgetId);
serviceId = widgetCatalogService.getServiceIdByWidget(widgetId);
}catch(Exception e){
- logger.error("Exception occurred while performing WidgetsCatalogController.getServiceIdByWidget in widget microservices. Details:" + e.getMessage());
+ logger.error("Exception occurred while performing WidgetsCatalogController.getServiceIdByWidget in widget microservices. Details:", e);
}
return serviceId;
}
@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<WidgetCatalog>();
+ List<WidgetCatalog> list = new ArrayList<>();
if(!util.authorization(auth, security_user, security_pass)){
response.sendError(HttpServletResponse.SC_UNAUTHORIZED);
logger.error("Basic Authentication Error while performing WidgetsCatalogController.getWidgetByServiceId in widget microserivce. Please check your username and password.");
logger.debug("WidgetsCatalogController.getWidgetByServiceId: getting service Id for widget {}", serviceId);
list = widgetCatalogService.getWidgetsByServiceId(serviceId);
}catch(Exception e){
- logger.error("Exception occurred while performing WidgetsCatalogController.getWidgetByServiceId in widget microservices. Details:" + e.getMessage());
+ logger.error("Exception occurred while performing WidgetsCatalogController.getWidgetByServiceId in widget microservices. Details:", e);
}
return list;
}
@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;
byteFile = storageService.getWidgetCatalogContent(widgetId);
logger.debug("WidgetsCatalogController.getWidgetZipFile: getting widget zip file for widget with id {}", widgetId);
} catch (Exception e) {
- logger.error("Exception occurred while performing WidgetsCatalogController.getWidgetZipFile in widget microservices. Details:" + e.getMessage());
+ logger.error("Exception occurred while performing WidgetsCatalogController.getWidgetZipFile in widget microservices. Details:", e);
}
return byteFile;
}