2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2018 Ericsson. All rights reserved.
4 * ================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
20 package org.onap.so.monitoring.db.service;
22 import static org.onap.so.monitoring.configuration.rest.HttpServiceProviderConfiguration.DATABASE_HTTP_REST_SERVICE_PROVIDER;
23 import java.util.ArrayList;
24 import java.util.Collections;
25 import java.util.List;
27 import org.onap.so.monitoring.camunda.model.SoActiveInfraRequests;
28 import org.onap.so.monitoring.configuration.database.DatabaseUrlProvider;
29 import org.onap.so.monitoring.model.SoInfraRequest;
30 import org.onap.so.monitoring.model.SoInfraRequestBuilder;
31 import org.onap.so.rest.service.HttpRestServiceProvider;
32 import org.springframework.beans.factory.annotation.Autowired;
33 import org.springframework.beans.factory.annotation.Qualifier;
34 import org.springframework.stereotype.Service;
35 import com.google.common.base.Optional;
38 * @author waqas.ikram@ericsson.com
41 public class DatabaseServiceProviderImpl implements DatabaseServiceProvider {
43 private final DatabaseUrlProvider urlProvider;
45 private final HttpRestServiceProvider httpRestServiceProvider;
48 public DatabaseServiceProviderImpl(final DatabaseUrlProvider urlProvider,
49 @Qualifier(DATABASE_HTTP_REST_SERVICE_PROVIDER) @Autowired final HttpRestServiceProvider httpRestServiceProvider) {
50 this.urlProvider = urlProvider;
51 this.httpRestServiceProvider = httpRestServiceProvider;
55 public List<SoInfraRequest> getSoInfraRequest(final Map<String, String[]> filters, final long startTime,
56 final long endTime, final Integer maxResult) {
57 final String url = urlProvider.getSearchUrl(startTime, endTime, maxResult);
59 final Optional<SoActiveInfraRequests[]> optionalRequests =
60 httpRestServiceProvider.post(filters, url, SoActiveInfraRequests[].class);
61 if (optionalRequests.isPresent()) {
62 return getSoInfraRequest(optionalRequests.get());
64 return Collections.emptyList();
68 private List<SoInfraRequest> getSoInfraRequest(final SoActiveInfraRequests[] requests) {
69 final List<SoInfraRequest> result = new ArrayList<>(requests.length);
70 for (final SoActiveInfraRequests activeRequests : requests) {
71 final SoInfraRequest soInfraRequest =
72 new SoInfraRequestBuilder().setRequestId(activeRequests.getRequestId())
73 .setServiceInstanceId(activeRequests.getServiceInstanceId())
74 .setNetworkId(activeRequests.getNetworkId()).setEndTime(activeRequests.getEndTime())
75 .setRequestStatus(activeRequests.getRequestStatus())
76 .setServiceInstanceName(activeRequests.getServiceInstanceName())
77 .setServiceType(activeRequests.getServiceType()).setStartTime(activeRequests.getStartTime())
79 result.add(soInfraRequest);