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;
24 import java.util.ArrayList;
25 import java.util.Collections;
26 import java.util.List;
29 import org.onap.so.monitoring.camunda.model.SoActiveInfraRequests;
30 import org.onap.so.monitoring.configuration.database.DatabaseUrlProvider;
31 import org.onap.so.monitoring.model.SoInfraRequest;
32 import org.onap.so.monitoring.model.SoInfraRequestBuilder;
33 import org.onap.so.monitoring.rest.service.HttpRestServiceProvider;
34 import org.springframework.beans.factory.annotation.Autowired;
35 import org.springframework.beans.factory.annotation.Qualifier;
36 import org.springframework.stereotype.Service;
38 import com.google.common.base.Optional;
41 * @author waqas.ikram@ericsson.com
44 public class DatabaseServiceProviderImpl implements DatabaseServiceProvider {
46 private final DatabaseUrlProvider urlProvider;
48 private final HttpRestServiceProvider httpRestServiceProvider;
51 public DatabaseServiceProviderImpl(final DatabaseUrlProvider urlProvider,
52 @Qualifier(DATABASE_HTTP_REST_SERVICE_PROVIDER) @Autowired final HttpRestServiceProvider httpRestServiceProvider) {
53 this.urlProvider = urlProvider;
54 this.httpRestServiceProvider = httpRestServiceProvider;
58 public List<SoInfraRequest> getSoInfraRequest(final Map<String, String[]> filters, final long startTime,
59 final long endTime, final Integer maxResult) {
60 final String url = urlProvider.getSearchUrl(startTime, endTime, maxResult);
62 final Optional<SoActiveInfraRequests[]> optionalRequests =
63 httpRestServiceProvider.postHttpRequest(filters, url, SoActiveInfraRequests[].class);
64 if (optionalRequests.isPresent()) {
65 return getSoInfraRequest(optionalRequests.get());
67 return Collections.emptyList();
71 private List<SoInfraRequest> getSoInfraRequest(final SoActiveInfraRequests[] requests) {
72 final List<SoInfraRequest> result = new ArrayList<>(requests.length);
73 for (final SoActiveInfraRequests activeRequests : requests) {
74 final SoInfraRequest soInfraRequest =
75 new SoInfraRequestBuilder().setRequestId(activeRequests.getRequestId())
76 .setServiceInstanceId(activeRequests.getServiceInstanceId())
77 .setNetworkId(activeRequests.getNetworkId()).setEndTime(activeRequests.getEndTime())
78 .setRequestStatus(activeRequests.getRequestStatus())
79 .setServiceIstanceName(activeRequests.getServiceInstanceName())
80 .setServiceType(activeRequests.getServiceType()).setStartTime(activeRequests.getStartTime())
82 result.add(soInfraRequest);