diff options
Diffstat (limited to 'vid-app-common/src/main/java/org/onap/vid/controllers')
4 files changed, 219 insertions, 289 deletions
diff --git a/vid-app-common/src/main/java/org/onap/vid/controllers/HealthCheckController.java b/vid-app-common/src/main/java/org/onap/vid/controllers/HealthCheckController.java index 03dc8083e..86e832ba7 100644 --- a/vid-app-common/src/main/java/org/onap/vid/controllers/HealthCheckController.java +++ b/vid-app-common/src/main/java/org/onap/vid/controllers/HealthCheckController.java @@ -25,6 +25,7 @@ import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; import org.onap.portalsdk.core.util.SystemProperties; import org.onap.vid.dao.FnAppDoaImpl; import org.onap.vid.model.GitRepositoryState; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.MediaType; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; @@ -37,6 +38,9 @@ import java.text.SimpleDateFormat; import java.util.Date; import java.util.Properties; +import static org.springframework.http.HttpStatus.INTERNAL_SERVER_ERROR; +import static org.springframework.http.HttpStatus.OK; + /** * Controller for user profile view. The view is restricted to authenticated * users. The view name resolves to page user_profile.jsp which uses Angular. @@ -46,158 +50,86 @@ import java.util.Properties; @RequestMapping("/") public class HealthCheckController extends UnRestrictedBaseController { - - /** - * The logger. - */ private static final EELFLoggerDelegate LOGGER = EELFLoggerDelegate.getLogger(HealthCheckController.class); + private static final DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss:SSSS"); + private static final String GIT_PROPERTIES_FILENAME = "git.properties"; + private FnAppDoaImpl fnAppDoaImpl; - /** - * The Constant dateFormat. - */ - final static DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss:SSSS"); - - private static final String HEALTH_CHECK_PATH = "/healthCheck"; - - /** - * Model for JSON response with health-check results. - */ - public class HealthStatus { - // Either 200 or 500 - public int statusCode; - - // Additional detail in case of error, empty in case of success. - public String message; - - public String date; - - public HealthStatus(int code, String msg) { - this.statusCode = code; - this.message = msg; - } - - public HealthStatus(int code, String date, String msg) { - this.statusCode = code; - this.message = msg; - this.date = date; - } - - public int getStatusCode() { - return statusCode; - } - - public void setStatusCode(int code) { - this.statusCode = code; - } - - public String getMessage() { - return message; - } - - public void setMessage(String msg) { - this.message = msg; - } - - public String getDate() { - return date; - } - - public void setDate(String date) { - this.date = date; - } - - } - - @SuppressWarnings("unchecked") - public int getProfileCount(String driver, String URL, String username, String password) { - FnAppDoaImpl doa = new FnAppDoaImpl(); - int count = doa.getProfileCount(driver, URL, username, password); - return count; + @Autowired + public HealthCheckController(FnAppDoaImpl fnAppDoaImpl) { + this.fnAppDoaImpl = fnAppDoaImpl; } - /** * Obtain the HealthCheck Status from the System.Properties file. * Used by IDNS for redundancy * * @return ResponseEntity The response entity - * @throws IOException Signals that an I/O exception has occurred. */ @RequestMapping(value = "/healthCheck", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) - public HealthStatus gethealthCheckStatusforIDNS() { - - String driver = SystemProperties.getProperty("db.driver"); - String URL = SystemProperties.getProperty("db.connectionURL"); - String username = SystemProperties.getProperty("db.userName"); - String password = SystemProperties.getProperty("db.password"); - - LOGGER.debug(EELFLoggerDelegate.debugLogger, "driver ::" + driver); - LOGGER.debug(EELFLoggerDelegate.debugLogger, "URL::" + URL); - LOGGER.debug(EELFLoggerDelegate.debugLogger, "username::" + username); - LOGGER.debug(EELFLoggerDelegate.debugLogger, "password::" + password); - - - HealthStatus healthStatus = null; - try { - LOGGER.debug(EELFLoggerDelegate.debugLogger, "Performing health check"); - int count = getProfileCount(driver, URL, username, password); - LOGGER.debug(EELFLoggerDelegate.debugLogger, "count:::" + count); - healthStatus = new HealthStatus(200, "health check succeeded"); - } catch (Exception ex) { - - LOGGER.error(EELFLoggerDelegate.errorLogger, "Failed to perform health check", ex); - healthStatus = new HealthStatus(500, "health check failed: " + ex.toString()); - } - return healthStatus; + public HealthStatus getHealthCheckStatusForIDNS() { + return createCorrespondingStatus(); } /** * Obtain the HealthCheck Status from the System.Properties file. * * @return ResponseEntity The response entity - * @throws IOException Signals that an I/O exception has occurred. - * Project : */ @RequestMapping(value = "rest/healthCheck/{User-Agent}/{X-ECOMP-RequestID}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) public HealthStatus getHealthCheck( @PathVariable("User-Agent") String UserAgent, @PathVariable("X-ECOMP-RequestID") String ECOMPRequestID) { + LOGGER.debug(EELFLoggerDelegate.debugLogger, "User-Agent ", UserAgent); + LOGGER.debug(EELFLoggerDelegate.debugLogger, "X-ECOMP-RequestID ", ECOMPRequestID); + return createCorrespondingStatus(); + } - String driver = SystemProperties.getProperty("db.driver"); - String URL = SystemProperties.getProperty("db.connectionURL"); - String username = SystemProperties.getProperty("db.userName"); - String password = SystemProperties.getProperty("db.password"); - - LOGGER.debug(EELFLoggerDelegate.debugLogger, "driver ::" + driver); - LOGGER.debug(EELFLoggerDelegate.debugLogger, "URL::" + URL); - LOGGER.debug(EELFLoggerDelegate.debugLogger, "username::" + username); - LOGGER.debug(EELFLoggerDelegate.debugLogger, "password::" + password); - + @RequestMapping(value = "/commitInfo", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) + public GitRepositoryState getCommitInfo() throws IOException { + Properties properties = new Properties(); + properties.load(getClass().getClassLoader().getResourceAsStream(GIT_PROPERTIES_FILENAME)); + return new GitRepositoryState(properties); + } - HealthStatus healthStatus = null; + private HealthStatus createCorrespondingStatus() { + logData(); try { - LOGGER.debug(EELFLoggerDelegate.debugLogger, "Performing health check"); - LOGGER.debug(EELFLoggerDelegate.debugLogger, "User-Agent" + UserAgent); - LOGGER.debug(EELFLoggerDelegate.debugLogger, "X-ECOMP-RequestID" + ECOMPRequestID); + int count = fnAppDoaImpl.getProfileCount(getUrl(), getUsername(), getPassword()); + LOGGER.debug(EELFLoggerDelegate.debugLogger, "count:::", count); + return okStatus(); + } catch (Exception ex) { + String errorMsg = ex.getMessage(); + LOGGER.error(EELFLoggerDelegate.errorLogger, errorMsg); + return errorStatus(errorMsg); + } + } + private void logData() { + LOGGER.debug(EELFLoggerDelegate.debugLogger, "Performing health check"); + LOGGER.debug(EELFLoggerDelegate.debugLogger, "URL::", getUrl()); + LOGGER.debug(EELFLoggerDelegate.debugLogger, "username::", getUsername()); + } - int count = getProfileCount(driver, URL, username, password); + private HealthStatus okStatus() { + return new HealthStatus(OK, dateFormat.format(new Date()), "health check succeeded"); + } - LOGGER.debug(EELFLoggerDelegate.debugLogger, "count:::" + count); - healthStatus = new HealthStatus(200, dateFormat.format(new Date()), "health check succeeded"); - } catch (Exception ex) { + private HealthStatus errorStatus(String msg) { + return new HealthStatus(INTERNAL_SERVER_ERROR, dateFormat.format( + new Date()), "health check failed: " + msg); + } - LOGGER.error(EELFLoggerDelegate.errorLogger, "Failed to perform health check", ex); - healthStatus = new HealthStatus(500, dateFormat.format(new Date()), "health check failed: " + ex.toString()); - } - return healthStatus; + private String getUrl() { + return SystemProperties.getProperty("db.connectionURL"); } - @RequestMapping(value = "/version", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) - public GitRepositoryState getCommitInfo() throws IOException { - Properties properties = new Properties(); - properties.load(getClass().getClassLoader().getResourceAsStream("git.properties")); - return new GitRepositoryState(properties); + private String getUsername() { + return SystemProperties.getProperty("db.userName"); + } + + private String getPassword() { + return SystemProperties.getProperty("db.password"); } } diff --git a/vid-app-common/src/main/java/org/onap/vid/controllers/HealthStatus.java b/vid-app-common/src/main/java/org/onap/vid/controllers/HealthStatus.java new file mode 100644 index 000000000..6056c2898 --- /dev/null +++ b/vid-app-common/src/main/java/org/onap/vid/controllers/HealthStatus.java @@ -0,0 +1,31 @@ +package org.onap.vid.controllers; + +import org.springframework.http.HttpStatus; + +/** + * Model for JSON response with health-check results. + */ +public final class HealthStatus { + + private final int statusCode; + private final String detailedMsg; + private final String date; + + public HealthStatus(HttpStatus code, String date, String detailedMsg) { + this.statusCode = code.value(); + this.detailedMsg = detailedMsg; + this.date = date; + } + + public int getStatusCode() { + return statusCode; + } + + public String getDetailedMsg() { + return detailedMsg; + } + + public String getDate() { + return date; + } +} diff --git a/vid-app-common/src/main/java/org/onap/vid/controllers/MaintenanceController.java b/vid-app-common/src/main/java/org/onap/vid/controllers/MaintenanceController.java index 0976f4039..1a3eb42fa 100644 --- a/vid-app-common/src/main/java/org/onap/vid/controllers/MaintenanceController.java +++ b/vid-app-common/src/main/java/org/onap/vid/controllers/MaintenanceController.java @@ -1,6 +1,30 @@ package org.onap.vid.controllers; +/*- + * ============LICENSE_START======================================================= + * VID + * ================================================================================ + * Copyright © 2018 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Modifications Copyright 2018 Nokia + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +import static org.onap.vid.utils.Logging.getMethodCallerName; +import javax.ws.rs.ForbiddenException; import org.onap.portalsdk.core.controller.UnRestrictedBaseController; import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; import org.onap.vid.category.AddCategoryOptionResponse; @@ -14,124 +38,114 @@ import org.onap.vid.services.CategoryParameterServiceImpl; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.*; - -import javax.servlet.http.HttpServletRequest; -import javax.ws.rs.ForbiddenException; -import java.util.Arrays; -import java.util.Collections; - -import static org.onap.vid.utils.Logging.getMethodCallerName; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; /** * Controler for APIs that are used only by vid operators */ @RestController -@RequestMapping(MaintenanceController.MAINTENANCE) +@RequestMapping("maintenance") public class MaintenanceController extends UnRestrictedBaseController { - public static final String MAINTENANCE = "maintenance"; + private static final EELFLoggerDelegate LOGGER = EELFLoggerDelegate.getLogger(MaintenanceController.class); + private CategoryParameterService categoryParameterService; @Autowired - protected CategoryParameterService categoryParameterService; - private static final EELFLoggerDelegate LOGGER = EELFLoggerDelegate.getLogger(MaintenanceController.class); + public MaintenanceController(CategoryParameterService categoryParameterService) { + this.categoryParameterService = categoryParameterService; + } /** * Add list of options to one category parameter - * @param request the request - * @return the new option - * @throws Exception the exception */ @RequestMapping(value = "/category_parameter/{categoryName}", method = RequestMethod.POST) - public ResponseEntity addCategoryOptions ( - HttpServletRequest request, @PathVariable String categoryName, @RequestBody AddCategoryOptionsRequest option) { + public ResponseEntity addCategoryOptions(@PathVariable String categoryName, + @RequestBody AddCategoryOptionsRequest option) { debugStartLog(); try { - AddCategoryOptionResponse response = categoryParameterService.createCategoryParameterOptions(categoryName, option); - HttpStatus httpStatus = response.getErrors().size()>0 ? HttpStatus.MULTI_STATUS : HttpStatus.OK; + AddCategoryOptionResponse response = categoryParameterService + .createCategoryParameterOptions(categoryName, option); + HttpStatus httpStatus = response.getErrors().isEmpty() ? HttpStatus.OK : HttpStatus.MULTI_STATUS; debugEndLog(response); - return new ResponseEntity<>(response, httpStatus); - } - catch (CategoryParameterServiceImpl.UnfoundedCategoryException exception) { - return new ResponseEntity<>(new AddCategoryOptionResponse(Collections.singletonList(exception.getMessage())), HttpStatus.NOT_FOUND); - } - catch (Exception exception) { + return createResponseWithBody(httpStatus, response); + } catch (CategoryParameterServiceImpl.UnfoundedCategoryException exception) { + return createResponseWithBody(HttpStatus.NOT_FOUND, new AddCategoryOptionResponse(exception.getMessage())); + } catch (RuntimeException exception) { LOGGER.error("failed to add option to parameter category " + categoryName, exception); - return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR); + return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build(); } } @RequestMapping(value = "/category_parameter/{categoryName}", method = RequestMethod.PUT) - public ResponseEntity updateNameForOption ( - HttpServletRequest request, @PathVariable String categoryName, @RequestBody CategoryParameterOptionRep option) { + public ResponseEntity updateNameForOption(@PathVariable String categoryName, + @RequestBody CategoryParameterOptionRep option) { debugStartLog(); try { - AddCategoryOptionResponse response = categoryParameterService.updateCategoryParameterOption(categoryName, option); - HttpStatus httpStatus = response.getErrors().size()>0 ? HttpStatus.MULTI_STATUS : HttpStatus.OK; + AddCategoryOptionResponse response = categoryParameterService + .updateCategoryParameterOption(categoryName, option); + HttpStatus httpStatus = response.getErrors().isEmpty() ? HttpStatus.OK : HttpStatus.MULTI_STATUS; debugEndLog(response); - return new ResponseEntity<>(response, httpStatus); - } - catch (ForbiddenException exception) { - return new ResponseEntity<>(new AddCategoryOptionResponse(Collections.singletonList(exception.getMessage())), HttpStatus.FORBIDDEN); - } - catch (CategoryParameterServiceImpl.UnfoundedCategoryException|CategoryParameterServiceImpl.UnfoundedCategoryOptionException exception) { - return new ResponseEntity<>(new AddCategoryOptionResponse(Collections.singletonList(exception.getMessage())), HttpStatus.NOT_FOUND); - } - catch (CategoryParameterServiceImpl.AlreadyExistOptionNameException exception) { - return new ResponseEntity<>(new AddCategoryOptionResponse(Collections.singletonList(exception.getMessage())), HttpStatus.CONFLICT); - } - catch (Exception exception) { + return createResponseWithBody(httpStatus, response); + } catch (ForbiddenException exception) { + return createResponseWithBody(HttpStatus.FORBIDDEN, new AddCategoryOptionResponse(exception.getMessage())); + } catch (CategoryParameterServiceImpl.UnfoundedCategoryException | CategoryParameterServiceImpl.UnfoundedCategoryOptionException exception) { + return createResponseWithBody(HttpStatus.NOT_FOUND, new AddCategoryOptionResponse(exception.getMessage())); + + } catch (CategoryParameterServiceImpl.AlreadyExistOptionNameException exception) { + return createResponseWithBody(HttpStatus.CONFLICT, new AddCategoryOptionResponse(exception.getMessage())); + + } catch (RuntimeException exception) { LOGGER.error("failed to update option to parameter category " + categoryName, exception); - return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR); + return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build(); } } /** * Gets the owning entity properties. - * @param request the request - * @return the property - * @throws Exception the exception */ @RequestMapping(value = "/category_parameter", method = RequestMethod.GET) - public ResponseEntity getCategoryParameter(HttpServletRequest request, @RequestParam(value="familyName", required = true) Family familyName) { + public ResponseEntity getCategoryParameter(@RequestParam(value = "familyName", required = true) Family familyName) { debugStartLog(); try { CategoryParametersResponse response = categoryParameterService.getCategoryParameters(familyName); debugEndLog(response); - return new ResponseEntity<>(response, HttpStatus.OK); - } - catch (Exception exception) { + return ResponseEntity.ok().body(response); + } catch (RuntimeException exception) { LOGGER.error("failed to retrieve category parameter list from DB.", exception); - return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR); + return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build(); } } - /** * Delete option of the category. - * @param request the request - * @throws Exception the exception */ - @RequestMapping(value = "/delete_category_parameter/{categoryName}", method = RequestMethod.POST) - public ResponseEntity deleteCategoryOption ( - HttpServletRequest request, @PathVariable String categoryName, @RequestBody CategoryParameterOption option) { + @RequestMapping(value = "/delete_category_parameter/{categoryName}", method = RequestMethod.DELETE) + public ResponseEntity deleteCategoryOption(@PathVariable String categoryName, + @RequestBody CategoryParameterOption option) { debugStartLog(); try { categoryParameterService.deleteCategoryOption(categoryName, option); debugEndLog(HttpStatus.OK); - return new ResponseEntity<>(HttpStatus.OK); - } - catch (CategoryParameterServiceImpl.UnfoundedCategoryException exception) { - return new ResponseEntity<>(new AddCategoryOptionResponse(Arrays.asList(exception.getMessage())), HttpStatus.NOT_FOUND); - } - catch (Exception exception) { + return ResponseEntity.status(HttpStatus.OK).build(); + } catch (CategoryParameterServiceImpl.UnfoundedCategoryException exception) { + return createResponseWithBody(HttpStatus.NOT_FOUND, new AddCategoryOptionResponse(exception.getMessage())); + } catch (RuntimeException exception) { LOGGER.error("failed to add/update owning entity option", exception); - return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR); + return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build(); } } + private ResponseEntity createResponseWithBody(HttpStatus status, AddCategoryOptionResponse response) { + return ResponseEntity.status(status).body(response); + } + private void debugStartLog() { LOGGER.debug(EELFLoggerDelegate.debugLogger, "start {}({})", getMethodCallerName()); } diff --git a/vid-app-common/src/main/java/org/onap/vid/controllers/VidController.java b/vid-app-common/src/main/java/org/onap/vid/controllers/VidController.java index 6d6ffb31b..b9d67b6df 100644 --- a/vid-app-common/src/main/java/org/onap/vid/controllers/VidController.java +++ b/vid-app-common/src/main/java/org/onap/vid/controllers/VidController.java @@ -4,12 +4,14 @@ * ================================================================================ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. * ================================================================================ + * Modifications Copyright 2018 Nokia + * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -40,122 +42,73 @@ import org.springframework.web.servlet.ModelAndView; import javax.servlet.http.HttpServletRequest; import java.util.List; -//import org.onap.vid.model.Service; - @RestController public class VidController extends RestrictedBaseController { - private static final EELFLoggerDelegate LOG = EELFLoggerDelegate.getLogger(VidController.class); - - private final VidService service; + private static final EELFLoggerDelegate LOG = EELFLoggerDelegate.getLogger(VidController.class); - @Autowired - public VidController(VidService vidService) { - service = vidService; - } - - @Autowired - private AaiService aaiService; - - @Autowired - RoleProvider roleProvider; + private final VidService vidService; + private final AaiService aaiService; + private final RoleProvider roleProvider; + private final PombaService pombaService; @Autowired - private PombaService pombaService; - -// /** -// * Gets the services. -// * -// * @param request the request -// * @return the services -// * @throws VidServiceUnavailableException the vid service unavailable exception -// */ -// @RequestMapping(value={"/rest/models/services"}, method = RequestMethod.GET) -// public SecureServices getServices(HttpServletRequest request) throws VidServiceUnavailableException { -// try { -// AaiService aaiService = new AaiServiceImpl(); -// LOG.info("Start API for browse ASDC was called"); -// SecureServices secureServices = new SecureServices(); -// Map<String, String[]> requestParams = request.getParameterMap(); -// List<Role> roles = roleProvider.getUserRoles(request); -// secureServices.setServices(aaiService.getServicesByDistributionStatus()); -// secureServices.setServices(service.getServices(requestParams)); -// secureServices.setReadOnly(roleProvider.userPermissionIsReadOnly(roles)); -// return secureServices; -// } catch (AsdcCatalogException e) { -// LOG.error("Failed to retrieve service definitions from SDC", e); -// throw new VidServiceUnavailableException("Failed to retrieve service definitions from SDC", e); -// } catch (Throwable t) { -// LOG.debug("Unexpected error while retrieving service definitions from SDC: " + t.getMessage() + ":", t); -// t.printStackTrace(); -// throw new VidServiceUnavailableException("Unexpected error while retrieving service definitions from SDC: " + t.getMessage(), t); -// } -// } - - /** - * Gets the services. - * - * @param request the request - * @return the services - * @throws VidServiceUnavailableException the vid service unavailable exception - */ - @RequestMapping(value={"/rest/models/services"}, method = RequestMethod.GET) - public SecureServices getServices(HttpServletRequest request) throws VidServiceUnavailableException { - try { - LOG.info("Start API for browse ASDC was called"); - SecureServices secureServices = new SecureServices(); - List<Role> roles = roleProvider.getUserRoles(request); - secureServices.setServices(aaiService.getServicesByDistributionStatus()); - //Disable roles until AAF integration finishes - //secureServices.setReadOnly(roleProvider.userPermissionIsReadOnly(roles)); - secureServices.setReadOnly(false); - return secureServices; - } - catch (Exception t) { - LOG.debug("Unexpected error while retrieving service definitions from A&AI: " + t.getMessage() + ":", t); - throw new VidServiceUnavailableException("Unexpected error while retrieving service definitions from A&AI: " + t.getMessage(), t); - } - } + public VidController(VidService vidService, AaiService aaiService, RoleProvider roleProvider, + PombaService pombaService) { + this.vidService = vidService; + this.aaiService = aaiService; + this.roleProvider = roleProvider; + this.pombaService = pombaService; + } + /** + * @param request the request + * @return the services + */ + @RequestMapping(value = {"/rest/models/services"}, method = RequestMethod.GET) + public SecureServices getServices(HttpServletRequest request) { + LOG.info("Start API for browse ASDC was called"); + SecureServices secureServices = new SecureServices(); + List<Role> roles = roleProvider.getUserRoles(request); + secureServices.setServices(aaiService.getServicesByDistributionStatus()); + secureServices.setReadOnly(roleProvider.userPermissionIsReadOnly(roles)); + return secureServices; + } - /** - * Gets the services. - * - * @param uuid the uuid - * @return the services - * @throws VidServiceUnavailableException the vid service unavailable exception - */ - @RequestMapping(value={"/rest/models/services/{uuid}"}, method = RequestMethod.GET) - public ServiceModel getServices(@PathVariable("uuid") String uuid, HttpServletRequest request) throws VidServiceUnavailableException { - try { - return service.getService(uuid); - } catch (AsdcCatalogException e) { - LOG.error("Failed to retrieve service definitions from SDC. Error: "+e.getMessage() , e); - throw new VidServiceUnavailableException("Failed to retrieve service definitions from SDC", e); - } - } + /** + * @param uuid the uuid + * @return the services + * @throws VidServiceUnavailableException the vid service unavailable exception + */ + @RequestMapping(value = {"/rest/models/services/{uuid}"}, method = RequestMethod.GET) + public ServiceModel getService(@PathVariable("uuid") String uuid) throws VidServiceUnavailableException { + try { + return vidService.getService(uuid); + } catch (AsdcCatalogException e) { + LOG.error("Failed to retrieve service definitions from SDC. Error: " + e.getMessage(), e); + throw new VidServiceUnavailableException("Failed to retrieve service definitions from SDC", e); + } + } - @RequestMapping(value = "/rest/models/reset", method = RequestMethod.POST) - @ResponseStatus(HttpStatus.ACCEPTED) - public void invalidateServiceModelCache(HttpServletRequest request) { - service.invalidateServiceCache(); - } + @RequestMapping(value = "/rest/models/reset", method = RequestMethod.POST) + @ResponseStatus(HttpStatus.ACCEPTED) + public void invalidateServiceModelCache() { + vidService.invalidateServiceCache(); + } - /** - * Gets the services view. - * - * @param request the request - * @return the services view - * @throws VidServiceUnavailableException the vid service unavailable exception - */ - @RequestMapping(value={"/serviceModels"}, method=RequestMethod.GET) - public ModelAndView getServicesView(HttpServletRequest request) { + /** + * @return the services view + * @throws VidServiceUnavailableException the vid service unavailable exception + */ + // FIX ME: Circular view path [serviceModels]: would dispatch back to the current handler URL [/serviceModels] again. + @RequestMapping(value = {"/serviceModels"}, method = RequestMethod.GET) + public ModelAndView getServicesView() { return new ModelAndView("serviceModels"); } @RequestMapping(value = {"/rest/models/services/verifyService"}, method = RequestMethod.POST) - public void verifyServiceInstance(HttpServletRequest request, @RequestBody PombaRequest pombaRequest) { - pombaService.verify(pombaRequest); + public void verifyServiceInstance(@RequestBody PombaRequest pombaRequest) { + pombaService.verify(pombaRequest); } } |