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.controller;
23 import org.jetbrains.annotations.NotNull;
24 import org.onap.portalsdk.core.controller.RestrictedBaseController;
25 import org.onap.portalsdk.core.controller.UnRestrictedBaseController;
26 import org.onap.vid.model.errorReport.ReportCreationParameters;
27 import org.onap.vid.reports.ReportGenerator;
28 import org.springframework.beans.factory.annotation.Autowired;
29 import org.springframework.web.bind.annotation.PostMapping;
30 import org.springframework.web.bind.annotation.RequestBody;
31 import org.springframework.web.bind.annotation.RestController;
33 import javax.servlet.http.HttpServletRequest;
34 import java.util.Collection;
35 import java.util.HashMap;
36 import java.util.List;
38 import java.util.function.BinaryOperator;
41 public class ErrorReportController extends RestrictedBaseController {
43 private final List<ReportGenerator> providers;
46 public ErrorReportController(List<ReportGenerator> reportGenerators) {
47 providers = reportGenerators;
50 @PostMapping(value = "error-report")
51 public Map<String, Object> getErrorReport(HttpServletRequest request,
52 @RequestBody ReportCreationParameters creationParameters) {
53 return generateReportsData(request, creationParameters);
57 HashMap<String, Object> generateReportsData(HttpServletRequest request, ReportCreationParameters creationParameters) {
60 .filter(provider -> provider.canGenerate(creationParameters))
61 .map(provider -> provider.apply(request, creationParameters))
63 .flatMap(Collection::parallelStream)
64 .reduce(new HashMap<>(), this::putAndGet, concatenateMap());
68 private HashMap<String, Object> putAndGet(HashMap<String, Object> map, Map.Entry<String, Object> entry) {
69 map.put(entry.getKey(), entry.getValue());
74 private BinaryOperator<HashMap<String, Object>> concatenateMap() {
75 return (map1, map2) -> {