diff options
Diffstat (limited to 'sdnc_report_api_sdnc_253_story/sdnc_reports_api/src/main/java/com/onap/sdnc')
7 files changed, 445 insertions, 0 deletions
diff --git a/sdnc_report_api_sdnc_253_story/sdnc_reports_api/src/main/java/com/onap/sdnc/reports/Application.java b/sdnc_report_api_sdnc_253_story/sdnc_reports_api/src/main/java/com/onap/sdnc/reports/Application.java new file mode 100644 index 0000000..f6a5355 --- /dev/null +++ b/sdnc_report_api_sdnc_253_story/sdnc_reports_api/src/main/java/com/onap/sdnc/reports/Application.java @@ -0,0 +1,48 @@ +/* +* ============LICENSE_START======================================================= +* ONAP : SDNC-FEATURES +* ================================================================================ +* Copyright 2018 TechMahindra +*================================================================================= +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* ============LICENSE_END========================================================= +*/ + +package com.onap.sdnc.reports; + + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.autoconfigure.domain.EntityScan; +import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; +import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration; +import org.springframework.data.jpa.repository.config.EnableJpaRepositories; + +@SpringBootApplication +//@EnableAutoConfiguration(exclude={DataSourceAutoConfiguration.class,HibernateJpaAutoConfiguration.class}) +@EnableJpaRepositories("com.onap.sdnc.reports.repository") +@EnableAutoConfiguration +@EntityScan("com.onap.sdnc.reports.*") +public class Application { + private static final Logger logger = LogManager.getLogger(Application.class); + public static void main(String[] args) { + + SpringApplication.run(Application.class, args); + logger.info("SDNC REPORTS API Has Started.."); + } +} + + diff --git a/sdnc_report_api_sdnc_253_story/sdnc_reports_api/src/main/java/com/onap/sdnc/reports/ServletInitializer.java b/sdnc_report_api_sdnc_253_story/sdnc_reports_api/src/main/java/com/onap/sdnc/reports/ServletInitializer.java new file mode 100644 index 0000000..45ab303 --- /dev/null +++ b/sdnc_report_api_sdnc_253_story/sdnc_reports_api/src/main/java/com/onap/sdnc/reports/ServletInitializer.java @@ -0,0 +1,34 @@ +/* +* ============LICENSE_START======================================================= +* ONAP : SDNC-FEATURES +* ================================================================================ +* Copyright 2018 TechMahindra +*================================================================================= +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* ============LICENSE_END========================================================= +*/ +package com.onap.sdnc.reports; + +import org.springframework.boot.builder.SpringApplicationBuilder; +import org.springframework.boot.web.support.SpringBootServletInitializer; + + + +public class ServletInitializer extends SpringBootServletInitializer { + + @Override + protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { + return application.sources(Application.class); + } + +} diff --git a/sdnc_report_api_sdnc_253_story/sdnc_reports_api/src/main/java/com/onap/sdnc/reports/config/JpaApplicationConfig.java b/sdnc_report_api_sdnc_253_story/sdnc_reports_api/src/main/java/com/onap/sdnc/reports/config/JpaApplicationConfig.java new file mode 100644 index 0000000..cdd2916 --- /dev/null +++ b/sdnc_report_api_sdnc_253_story/sdnc_reports_api/src/main/java/com/onap/sdnc/reports/config/JpaApplicationConfig.java @@ -0,0 +1,61 @@ +/* +* ============LICENSE_START======================================================= +* ONAP : SDNC-FEATURES +* ================================================================================ +* Copyright 2018 TechMahindra +*================================================================================= +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* ============LICENSE_END========================================================= +*/ +package com.onap.sdnc.reports.config; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.dao.support.PersistenceExceptionTranslator; +import org.springframework.data.jpa.repository.config.EnableJpaRepositories; +import org.springframework.orm.jpa.AbstractEntityManagerFactoryBean; +import org.springframework.orm.jpa.JpaTransactionManager; +import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean; +import org.springframework.orm.jpa.vendor.OpenJpaDialect; +import org.springframework.transaction.PlatformTransactionManager; +import org.springframework.transaction.annotation.EnableTransactionManagement; + +//@Configuration +//@EnableJpaRepositories("com.onap.sdnc.reports.repository") +//@EnableTransactionManagement +public class JpaApplicationConfig { + + /*@Bean + public AbstractEntityManagerFactoryBean entityManagerFactory() + { + LocalContainerEntityManagerFactoryBean factory=new LocalContainerEntityManagerFactoryBean(); + factory.setPackagesToScan("com.onap.sdnc.reports.repository"); + //factory.setPersistenceUnitName("name"); + //factory.setPersistenceUnitName("transactions-optional"); + return factory; + } + + @Bean + public PlatformTransactionManager transactionManager() + { + JpaTransactionManager jpaTransactionManager=new JpaTransactionManager(); + jpaTransactionManager.setEntityManagerFactory(entityManagerFactory().getObject()); + return jpaTransactionManager; + } + + @Bean + public PersistenceExceptionTranslator persistenceExceptionTranslator() + { + return new OpenJpaDialect(); + }*/ +} diff --git a/sdnc_report_api_sdnc_253_story/sdnc_reports_api/src/main/java/com/onap/sdnc/reports/controller/ReportController.java b/sdnc_report_api_sdnc_253_story/sdnc_reports_api/src/main/java/com/onap/sdnc/reports/controller/ReportController.java new file mode 100644 index 0000000..0106031 --- /dev/null +++ b/sdnc_report_api_sdnc_253_story/sdnc_reports_api/src/main/java/com/onap/sdnc/reports/controller/ReportController.java @@ -0,0 +1,104 @@ +/* +* ============LICENSE_START======================================================= +* ONAP : SDNC-FEATURES +* ================================================================================ +* Copyright 2018 TechMahindra +*================================================================================= +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* ============LICENSE_END========================================================= +*/ +package com.onap.sdnc.reports.controller; + +import java.util.Date; +import java.util.List; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.hibernate.engine.internal.Collections; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.MediaType; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.onap.sdnc.reports.Application; +import com.onap.sdnc.reports.model.PreTestConfig; +import com.onap.sdnc.reports.model.Report; +import com.onap.sdnc.reports.model.Response; +import com.onap.sdnc.reports.repository.DeviceRepository; +import com.onap.sdnc.reports.rest.model.PreTestModel; +import com.onap.sdnc.reports.service.IReportService; + +@RestController +public class ReportController { + + private static final Logger logger = LogManager.getLogger(ReportController.class); + + @Autowired + IReportService reportService; + + /*@RequestMapping(value = "/saveReport", method = RequestMethod.POST,consumes=MediaType.APPLICATION_JSON_VALUE) + public void saveReport(@RequestBody Report Report) { + + //repository.save(new Report(Report.getFirstName(), Report.getLastName())); + } + + @RequestMapping(value="/findAllReports/{startDate}/{endDate}",produces=MediaType.APPLICATION_JSON_VALUE) + public Response findAllReports(@PathVariable("startDate") Date startDate,@PathVariable("endDate") Date endDate) { + + return reportService.findAllReports(startDate,endDate); + } + + // produces = "application/json" + @RequestMapping(value="/findReportByTestName/{startDate}/{endDate}/{testName}",produces=MediaType.APPLICATION_JSON_VALUE) + public Response findReportByTestName(@PathVariable("startDate") Date startDate,@PathVariable("endDate") Date endDate,@PathVariable("testName") String testName) { + + return reportService.findReportByTestName(startDate,endDate,testName); + }*/ + + @RequestMapping(value="/findReportByDeviceName/{startDate}/{endDate}/{deviceName}", produces = "application/json",method=RequestMethod.GET) + public List<PreTestModel> findReportByDeviceName(@PathVariable("startDate") Date startDate,@PathVariable("endDate") Date endDate,@PathVariable("deviceName") String deviceName) { + + try{ + logger.info("findReportByDeviceName Started Working.."); + logger.info("Received StartDate : "+startDate+" ,EndDate : "+endDate+" ,DeviceName : "+deviceName); + /*ObjectMapper mapper=new ObjectMapper(); + String jsonVal=""; + try { + jsonVal = mapper.writeValueAsString(reportService.findReportByDeviceName(startDate,endDate,deviceName)); + logger.info("JSON "+jsonVal); + } catch (JsonProcessingException e) { + + }*/ + logger.info("findReportByDeviceName Finished Working.."); + return reportService.findReportByDeviceName(startDate,endDate,deviceName.trim()); + } + catch(Exception ex) + { + logger.info("Exception Occured : "+ex.getLocalizedMessage()); + return java.util.Collections.EMPTY_LIST; + } + + } + + /*@RequestMapping(value="/findReportsByDeviceNamdAndTestName/{startDate}/{endDate}",produces=MediaType.APPLICATION_JSON_VALUE) + public Response findReportsByDeviceNamdAndTestName(@PathVariable("startDate") Date startDate,@PathVariable("endDate") Date endDate,@PathVariable("deviceName") String deviceName,@PathVariable("testName") String testName) { + + return reportService.findReportsByDeviceNamdAndTestName(startDate,endDate,deviceName,testName); + }*/ +} diff --git a/sdnc_report_api_sdnc_253_story/sdnc_reports_api/src/main/java/com/onap/sdnc/reports/controller/WebController.java b/sdnc_report_api_sdnc_253_story/sdnc_reports_api/src/main/java/com/onap/sdnc/reports/controller/WebController.java new file mode 100644 index 0000000..a2311fe --- /dev/null +++ b/sdnc_report_api_sdnc_253_story/sdnc_reports_api/src/main/java/com/onap/sdnc/reports/controller/WebController.java @@ -0,0 +1,36 @@ +/* +* ============LICENSE_START======================================================= +* ONAP : SDNC-FEATURES +* ================================================================================ +* Copyright 2018 TechMahindra +*================================================================================= +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* ============LICENSE_END========================================================= +*/ +package com.onap.sdnc.reports.controller; + +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.servlet.ModelAndView; + +@Controller +public class WebController { + + @RequestMapping("/") + ModelAndView home(ModelAndView modelAndView) { + + modelAndView.setViewName("index"); + + return modelAndView; + } +} diff --git a/sdnc_report_api_sdnc_253_story/sdnc_reports_api/src/main/java/com/onap/sdnc/reports/service/IReportService.java b/sdnc_report_api_sdnc_253_story/sdnc_reports_api/src/main/java/com/onap/sdnc/reports/service/IReportService.java new file mode 100644 index 0000000..b4afaf6 --- /dev/null +++ b/sdnc_report_api_sdnc_253_story/sdnc_reports_api/src/main/java/com/onap/sdnc/reports/service/IReportService.java @@ -0,0 +1,47 @@ +/* +* ============LICENSE_START======================================================= +* ONAP : SDNC-FEATURES +* ================================================================================ +* Copyright 2018 TechMahindra +*================================================================================= +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* ============LICENSE_END========================================================= +*/ +package com.onap.sdnc.reports.service; + +import java.util.Date; +import java.util.List; + +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestParam; + +import com.onap.sdnc.reports.model.PreTestConfig; +import com.onap.sdnc.reports.model.Report; +import com.onap.sdnc.reports.model.Response; +import com.onap.sdnc.reports.rest.model.PreTestModel; + +public interface IReportService { + +/* public void saveReport(@RequestBody Report Report); + + public Response findAllReports(@PathVariable("startDate") Date startDate,@PathVariable("endDate") Date endDate); + + + public Response findReportByTestName(@PathVariable("startDate") Date startDate,@PathVariable("endDate") Date endDate,@PathVariable("testName") String testName); + + public Response findReportsByDeviceNamdAndTestName(@PathVariable("startDate") Date startDate,@PathVariable("endDate") Date endDate,@PathVariable("deviceName") String deviceName,@PathVariable("testName") String testName); +*/ + public List<PreTestModel> findReportByDeviceName(@PathVariable("startDate") Date startDate,@PathVariable("endDate") Date endDate,@RequestParam("deviceName") String deviceName) throws Exception; + +} diff --git a/sdnc_report_api_sdnc_253_story/sdnc_reports_api/src/main/java/com/onap/sdnc/reports/service/ReportServiceImpl.java b/sdnc_report_api_sdnc_253_story/sdnc_reports_api/src/main/java/com/onap/sdnc/reports/service/ReportServiceImpl.java new file mode 100644 index 0000000..73d040e --- /dev/null +++ b/sdnc_report_api_sdnc_253_story/sdnc_reports_api/src/main/java/com/onap/sdnc/reports/service/ReportServiceImpl.java @@ -0,0 +1,115 @@ +/* +* ============LICENSE_START======================================================= +* ONAP : SDNC-FEATURES +* ================================================================================ +* Copyright 2018 TechMahindra +*================================================================================= +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* ============LICENSE_END========================================================= +*/ +package com.onap.sdnc.reports.service; + +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import com.onap.sdnc.reports.controller.ReportController; +import com.onap.sdnc.reports.model.PreTestConfig; +import com.onap.sdnc.reports.model.Report; +import com.onap.sdnc.reports.model.Response; +import com.onap.sdnc.reports.repository.DeviceRepository; +import com.onap.sdnc.reports.repository.PreTestConfigRepository; +import com.onap.sdnc.reports.rest.model.PreTestModel; + +@Service +public class ReportServiceImpl implements IReportService { + + private static final Logger logger = LogManager.getLogger(ReportServiceImpl.class); + + @Autowired + DeviceRepository deviceRepository; + + @Autowired + PreTestConfigRepository preTestConfigRepository; + + /*@Override + public void saveReport(Report Report) { + // TODO Auto-generated method stub + + } + + @Override + public Response findAllReports(Date startDate, Date endDate) { + // TODO Auto-generated method stub + return null; + } + + @Override + public Response findReportByTestName(Date startDate, Date endDate, String testName) { + // TODO Auto-generated method stub + return null; + }*/ + + @Override + public List<PreTestModel> findReportByDeviceName(Date startDate, Date endDate, String deviceName) throws Exception{ + + try{ + + List<PreTestConfig> resultSet= preTestConfigRepository.findReportByDeviceName(startDate, endDate, deviceName); + logger.info("Received Output From Repository Is: "+resultSet); + + List<PreTestModel> preTestList=new ArrayList<PreTestModel>(); + for(PreTestConfig config : resultSet) + { + try{ + long deviceid=config.getDevice().getId(); + long testid=config.getTestId(); + String testName=config.getTestName(); + String deviName=config.getDevice().getDeviceName(); + String execuationDetails=config.getExecuationDetails(); + String result=config.getResult(); + Date timeStamp=config.getTimestamp(); + + PreTestModel model=new PreTestModel(testid, deviceid, testName, deviName, execuationDetails, result, timeStamp); + preTestList.add(model); + } + catch(Exception ex) + { + logger.info("Exception Occured : "+ex.getLocalizedMessage()); + } + } + logger.info("Final PreTestConfig List Size : "+preTestList.size()); + Response r=new Response("Pass", resultSet); + return preTestList; + } + catch(Exception ex) + { + logger.info("Exception Occured : "+ex.getLocalizedMessage()); + throw new Exception(ex); + } + + } + + /*@Override + public Response findReportsByDeviceNamdAndTestName(Date startDate, Date endDate, String deviceName, + String testName) { + // TODO Auto-generated method stub + return null; + }*/ + +} |