NonRT-RIC A1 Northbound API
[nonrtric.git] / sdnc-a1-controller / oam / SdncReports / SdncReportsApi / src / main / java / com / onap / sdnc / reports / service / LayerTestServiceImpl.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * openECOMP : SDN-C
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights
6  *                             reserved.
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END=========================================================
20  */ 
21 package com.onap.sdnc.reports.service;
22
23 import java.util.ArrayList;
24 import java.util.List;
25 import org.apache.log4j.Logger;
26 import org.springframework.beans.factory.annotation.Autowired;
27 import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
28 import org.springframework.boot.autoconfigure.domain.EntityScan;
29 import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
30 import org.springframework.stereotype.Service;
31 import com.onap.sdnc.reports.model.CertificationInputs;
32 import com.onap.sdnc.reports.model.Input;
33 import com.onap.sdnc.reports.model.PreTestResponse;
34 import com.onap.sdnc.reports.model.Request;
35 import com.onap.sdnc.reports.model.Response;
36 import com.onap.sdnc.reports.model.ValidationTestType;
37 import com.onap.sdnc.reports.model.VnfList;
38 import com.onap.sdnc.reports.repository.DeviceRepository;
39 import com.onap.sdnc.reports.repository.PreTestConfigRepository;
40
41
42 @EnableJpaRepositories("com.onap.sdnc.reports.repository")
43 @EntityScan("com.onap.sdnc.*")
44 @EnableAutoConfiguration
45 @Service
46 public class LayerTestServiceImpl implements LayerTestService {
47
48         private static final Logger logger = Logger.getLogger(CertificationClientService.class);
49         
50         @Autowired
51         CertificationClientService certificationClientservice;
52         
53         @Autowired
54         DeviceRepository deviceRepository;
55         
56         @Autowired
57         PreTestConfigRepository preTestRepo;
58         
59         @Override
60         public Response networkCertification(Request restReq) {
61                 
62                 String testType = "network";            
63                 
64                 VnfList[] vnf = restReq.getVnfList();
65                 
66                 ValidationTestType[] validationType = restReq.getValidationTestType();
67
68                 CertificationInputs vnfRequestParams = new CertificationInputs();
69
70                 Response resOutput = new Response();
71                 
72                 Input input = new Input();
73
74                 List<PreTestResponse> preTestNew = new ArrayList<PreTestResponse>();
75                 for (ValidationTestType validationTestType : validationType) {
76                         if (validationTestType.getValidationType().equalsIgnoreCase("Network Layer")) {
77                                 testType = "network";
78                         }
79                         if (validationTestType.getValidationType().equalsIgnoreCase("Protocol Layer")) {
80                                 testType = "protocol";
81                         }
82                         for (VnfList vnfList : vnf) {
83                                 input.setIpaddress(vnfList.getIpAddress());
84                                 input.setHostname(vnfList.getHostName());
85                                 vnfRequestParams.setInput(input);
86                                 certificationClientservice.restClient(vnfRequestParams, preTestNew, testType);
87                         }
88                 }               
89                 resOutput.setPreTestResponse(preTestNew);               
90                 return resOutput;
91         }
92
93 }