+/*-
+ * ============LICENSE_START=======================================================
+ * VID
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2018 Nokia. All rights reserved.
+ * ================================================================================
+ * 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=========================================================
+ */
package org.onap.vid.controller;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.common.base.MoreObjects;
+import io.joshworks.restclient.http.HttpResponse;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.exception.ExceptionUtils;
-import org.openecomp.portalsdk.core.controller.RestrictedBaseController;
-import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate;
+import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
import org.onap.vid.changeManagement.RequestDetailsWrapper;
import org.onap.vid.model.ExceptionResponse;
import org.onap.vid.model.RequestReferencesContainer;
import org.onap.vid.mso.MsoBusinessLogic;
+import org.onap.vid.mso.MsoInterface;
import org.onap.vid.mso.MsoResponseWrapper2;
-import org.onap.vid.mso.RestMsoImplementation;
-import org.onap.vid.mso.RestObject;
import org.onap.vid.mso.model.OperationalEnvironmentActivateInfo;
import org.onap.vid.mso.model.OperationalEnvironmentDeactivateInfo;
-import org.onap.vid.mso.rest.MsoRestClientNew;
import org.onap.vid.mso.rest.OperationalEnvironment.OperationEnvironmentRequestDetails;
import org.onap.vid.mso.rest.RequestDetails;
import org.springframework.beans.factory.annotation.Autowired;
import static org.onap.vid.utils.Logging.getMethodCallerName;
import static org.onap.vid.utils.Logging.getMethodName;
-import static org.springframework.http.HttpStatus.INTERNAL_SERVER_ERROR;
@RestController
@RequestMapping("operationalEnvironment")
-public class OperationalEnvironmentController extends RestrictedBaseController {
+public class OperationalEnvironmentController extends VidRestrictedBaseController {
- private static final EELFLoggerDelegate LOGGER = EELFLoggerDelegate.getLogger(OperationalEnvironmentController.class);
- private final RestMsoImplementation restMso;
+ private final MsoInterface restMso;
private final MsoBusinessLogic msoBusinessLogic;
- private static final Pattern RECOVERY_ACTION_MESSAGE_PATTERN = Pattern.compile("String value \'(.*)\': value not");
+ private static final Pattern RECOVERY_ACTION_MESSAGE_PATTERN = Pattern.compile("from String \"(.*)\": value not");
@Autowired
- public OperationalEnvironmentController(MsoBusinessLogic msoBusinessLogic, MsoRestClientNew msoClientInterface) {
+ public OperationalEnvironmentController(MsoBusinessLogic msoBusinessLogic, MsoInterface msoClientInterface) {
this.restMso = msoClientInterface;
this.msoBusinessLogic = msoBusinessLogic;
}
@RequestMapping(value = "/create", method = RequestMethod.POST)
- public MsoResponseWrapper2 createOperationalEnvironment(HttpServletRequest request, @RequestBody OperationalEnvironmentCreateBody operationalEnvironment) throws Exception {
- LOGGER.debug(EELFLoggerDelegate.debugLogger, "start {}({})", getMethodName(), operationalEnvironment);
+ public MsoResponseWrapper2 createOperationalEnvironment(HttpServletRequest request, @RequestBody OperationalEnvironmentCreateBody operationalEnvironment) {
+ debugStart(operationalEnvironment);
String userId = ControllersUtils.extractUserId(request);
RequestDetailsWrapper<OperationEnvironmentRequestDetails> requestDetailsWrapper = msoBusinessLogic.convertParametersToRequestDetails(operationalEnvironment, userId);
String path = msoBusinessLogic.getOperationalEnvironmentCreationPath();
- RestObject<RequestReferencesContainer> msoResponse = restMso.PostForObject(requestDetailsWrapper, "",
- path, RequestReferencesContainer.class);
+
+ HttpResponse<RequestReferencesContainer> msoResponse = restMso.post(path, requestDetailsWrapper, RequestReferencesContainer.class);
debugEnd(msoResponse);
return new MsoResponseWrapper2<>(msoResponse);
}
@RequestMapping(value = "/activate", method = RequestMethod.POST)
public MsoResponseWrapper2 activate(HttpServletRequest request,
@RequestParam("operationalEnvironment") String operationalEnvironmentId,
- @RequestBody OperationalEnvironmentActivateBody activateRequest) throws Exception {
+ @RequestBody OperationalEnvironmentActivateBody activateRequest) throws MissingServletRequestParameterException {
verifyIsNotEmpty(operationalEnvironmentId, "operationalEnvironment");
String path = msoBusinessLogic.getOperationalEnvironmentActivationPath(activateInfo);
RequestDetailsWrapper<RequestDetails> requestDetailsWrapper = msoBusinessLogic.createOperationalEnvironmentActivationRequestDetails(activateInfo);
- RestObject<RequestReferencesContainer> msoResponse = restMso.PostForObject(requestDetailsWrapper, "",
- path, RequestReferencesContainer.class);
+ HttpResponse<RequestReferencesContainer> msoResponse = restMso.post(path, requestDetailsWrapper, RequestReferencesContainer.class);
debugEnd(msoResponse);
return new MsoResponseWrapper2<>(msoResponse);
@RequestMapping(value = "/deactivate", method = RequestMethod.POST)
public MsoResponseWrapper2 deactivate(HttpServletRequest request,
@RequestParam("operationalEnvironment") String operationalEnvironmentId,
- @RequestBody Map deactivationRequest) throws Exception {
+ @RequestBody Map deactivationRequest) throws MissingServletRequestParameterException {
verifyIsNotEmpty(operationalEnvironmentId, "operationalEnvironment");
String path = msoBusinessLogic.getOperationalEnvironmentDeactivationPath(deactivateInfo);
RequestDetailsWrapper<RequestDetails> requestDetailsWrapper = msoBusinessLogic.createOperationalEnvironmentDeactivationRequestDetails(deactivateInfo);
- RestObject<RequestReferencesContainer> msoResponse = restMso.PostForObject(requestDetailsWrapper, "",
- path, RequestReferencesContainer.class);
+ HttpResponse<RequestReferencesContainer> msoResponse = restMso.post(path, requestDetailsWrapper, RequestReferencesContainer.class);
debugEnd(msoResponse);
return new MsoResponseWrapper2<>(msoResponse);
}
@RequestMapping(value = "/requestStatus", method = RequestMethod.GET)
- public MsoResponseWrapper2 status(HttpServletRequest request, @RequestParam("requestId") String requestId) throws Exception {
+ public MsoResponseWrapper2 status(HttpServletRequest request, @RequestParam("requestId") String requestId) throws MissingServletRequestParameterException {
- LOGGER.debug(EELFLoggerDelegate.debugLogger, "start {}({})", getMethodName(), requestId);
+ debugStart(requestId);
verifyIsNotEmpty(requestId, "requestId");
String path = msoBusinessLogic.getCloudResourcesRequestsStatusPath(requestId);
- final RestObject<HashMap> msoResponse = restMso.GetForObject("", path, HashMap.class);
+ HttpResponse<HashMap> msoResponse = restMso.get(path, HashMap.class);
LOGGER.debug(EELFLoggerDelegate.debugLogger, "end {}() => {}", getMethodName(), msoResponse);
return new MsoResponseWrapper2<>(msoResponse);
}
- @ExceptionHandler(Exception.class)
- @ResponseStatus(value=INTERNAL_SERVER_ERROR)
- private ExceptionResponse exceptionHandler(Exception e) {
- return ControllersUtils.handleException(e, LOGGER);
- }
-
@ExceptionHandler({
org.springframework.web.bind.MissingServletRequestParameterException.class,
BadManifestException.class
}
}
- private void debugEnd(RestObject<RequestReferencesContainer> msoResponse) {
+ private void debugEnd(HttpResponse<RequestReferencesContainer> msoResponse) {
LOGGER.debug(EELFLoggerDelegate.debugLogger, "end {}() => {}", getMethodCallerName(), msoResponse);
}