2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019 Nokia Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.onap.vid.reports;
23 import com.google.common.collect.ImmutableMap;
24 import org.onap.vid.asdc.AsdcCatalogException;
25 import org.onap.vid.model.errorReport.ReportCreationParameters;
26 import org.onap.vid.mso.MsoBusinessLogic;
27 import org.onap.vid.mso.MsoResponseWrapper;
28 import org.onap.vid.services.VidService;
29 import org.springframework.beans.factory.annotation.Autowired;
30 import org.springframework.stereotype.Service;
32 import javax.servlet.http.HttpServletRequest;
33 import java.util.HashMap;
37 public class DeploymentReportGenerator implements ReportGenerator {
39 private final VidService vidService;
40 private final MsoBusinessLogic msoBusinessLogic;
43 public DeploymentReportGenerator(VidService vidService, MsoBusinessLogic msoBusinessLogic) {
44 this.vidService = vidService;
45 this.msoBusinessLogic = msoBusinessLogic;
49 public Map<String, Object> apply(HttpServletRequest request, ReportCreationParameters creationParameters) {
50 return ImmutableMap.<String, Object>builder()
51 .put("serviceInstanceInfo", getOrchestrationRequestFromMso(creationParameters.getRequestId()))
52 .put("serviceDetails", getServiceDetails(creationParameters.getServiceUuid()))
57 public boolean canGenerate(ReportCreationParameters creationParameters) {
58 return creationParameters.getRequestId() != null && creationParameters.getServiceUuid() != null;
61 MsoResponseWrapper getOrchestrationRequestFromMso(String requestId) {
62 return msoBusinessLogic.getOrchestrationRequest(requestId);
65 Map<String, Object> getServiceDetails(String serviceUuid) {
66 Map<String, Object> serviceDetails;
68 org.onap.vid.model.Service serviceModel = vidService.getService(serviceUuid).getService();
69 serviceDetails = ImmutableMap.of("details", serviceModel);
70 } catch (AsdcCatalogException | NullPointerException e) {
71 serviceDetails = generateServiceDetailsExceptionResponse(serviceUuid, e);
73 return serviceDetails;
76 Map<String, Object> generateServiceDetailsExceptionResponse(String serviceUuid, Exception e) {
77 Map<String, Object> result = new HashMap<>();
78 if (e.getClass() == NullPointerException.class) {
79 result.put("message", "Service details for given uuid were not found");
81 result.put("exception", e.toString());
82 result.put("serviceUuid", serviceUuid);