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.vid.model.errorReport.ReportCreationParameters;
26 import org.onap.vid.reports.ReportGenerator;
27 import org.springframework.beans.factory.annotation.Autowired;
28 import org.springframework.web.bind.annotation.PostMapping;
29 import org.springframework.web.bind.annotation.RequestBody;
30 import org.springframework.web.bind.annotation.RestController;
32 import javax.servlet.http.HttpServletRequest;
33 import java.util.Collection;
34 import java.util.HashMap;
35 import java.util.List;
37 import java.util.function.BinaryOperator;
40 public class ErrorReportController extends RestrictedBaseController {
42 private final List<ReportGenerator> providers;
45 public ErrorReportController(List<ReportGenerator> reportGenerators) {
46 providers = reportGenerators;
49 @PostMapping(value = "error-report")
50 public Map<String, Object> getErrorReport(HttpServletRequest request,
51 @RequestBody ReportCreationParameters creationParameters) {
52 return generateReportsData(request, creationParameters);
56 HashMap<String, Object> generateReportsData(HttpServletRequest request, ReportCreationParameters creationParameters) {
59 .filter(provider -> provider.canGenerate(creationParameters))
60 .map(provider -> provider.apply(request, creationParameters))
62 .flatMap(Collection::parallelStream)
63 .reduce(new HashMap<>(), this::putAndGet, concatenateMap());
67 private HashMap<String, Object> putAndGet(HashMap<String, Object> map, Map.Entry<String, Object> entry) {
68 map.put(entry.getKey(), entry.getValue());
73 private BinaryOperator<HashMap<String, Object>> concatenateMap() {
74 return (map1, map2) -> {