NonRT-RIC A1 Northbound API
[nonrtric.git] / sdnc-a1-controller / oam / SdncReports / SdncReportsApi / src / main / java / com / onap / sdnc / reports / service / ReportServiceImpl.java
1 /*
2 * ============LICENSE_START=======================================================
3 * ONAP : SDNC-FEATURES
4 * ================================================================================
5 * Copyright 2018 TechMahindra
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
10 *
11 *     http://www.apache.org/licenses/LICENSE-2.0
12 *
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=========================================================
19 */
20 package com.onap.sdnc.reports.service;
21
22 import java.util.ArrayList;
23 import java.util.Date;
24 import java.util.List;
25
26 import org.apache.logging.log4j.LogManager;
27 import org.apache.logging.log4j.Logger;
28 import org.springframework.beans.factory.annotation.Autowired;
29 import org.springframework.stereotype.Service;
30 import com.onap.sdnc.reports.model.PreTestConfig;
31 import com.onap.sdnc.reports.repository.DeviceRepository;
32 import com.onap.sdnc.reports.repository.PreTestConfigRepository;
33 import com.onap.sdnc.reports.rest.model.PreTestModel;
34
35 @Service
36 public class ReportServiceImpl implements IReportService {
37
38         private static final Logger logger = LogManager.getLogger(ReportServiceImpl.class);
39         
40         @Autowired
41         DeviceRepository deviceRepository;
42         
43         @Autowired 
44         PreTestConfigRepository preTestConfigRepository;
45         
46         
47         @Override
48         public List<PreTestModel> findReportByDeviceIP(Date startDate, Date endDate, String deviceIP) throws Exception{
49                 
50                 try{
51
52                         List<PreTestConfig> resultSet= preTestConfigRepository.findReportByDeviceIP(startDate, endDate, deviceIP);
53
54                         if(logger.isDebugEnabled())
55                                 logger.debug("Received Output From Repository Is: "+resultSet);
56                         
57                         List<PreTestModel> preTestList=new ArrayList<PreTestModel>();
58                         for(PreTestConfig config : resultSet)
59                         {
60                                 try{
61                                         long deviceid=config.getDevice().getId();
62                                         long testid=config.getTestId();
63                                         String testName=config.getTestName();
64                                         String deviceIp=config.getDevice().getDeviceIP();
65                                         String execuationDetails=config.getExecuationDetails();
66                                         String result=config.getResult();
67                                         Date timeStamp=config.getTimestamp();
68                                         
69                                         PreTestModel model=new PreTestModel(testid, deviceid, testName, deviceIp, execuationDetails, result, timeStamp);
70                                         preTestList.add(model);
71                                 }
72                                 catch(Exception ex)
73                                 {
74                                         logger.info("Exception Occured : "+ex.getLocalizedMessage());
75                                         logger.error(ex);
76                                 }                               
77                         }
78                         logger.info("Final PreTestConfig List Size : "+preTestList.size());             
79                         logger.info("findReportByDeviceIP Finished Working..");
80                         return preTestList;
81                 }
82                 catch(Exception ex)
83                 {
84                         logger.info("Exception Occured : "+ex.getLocalizedMessage());
85                         logger.error(ex);
86                         throw new Exception("Exception occurred while processing findReportByDeviceIP ",ex);
87                 }               
88         }
89 }