diff options
Diffstat (limited to 'sdnc_report_api_sdnc_253_story/sdnc_reports_service/src/main/java/com/onap/sdnc')
7 files changed, 540 insertions, 0 deletions
diff --git a/sdnc_report_api_sdnc_253_story/sdnc_reports_service/src/main/java/com/onap/sdnc/reports/Application.java b/sdnc_report_api_sdnc_253_story/sdnc_reports_service/src/main/java/com/onap/sdnc/reports/Application.java new file mode 100644 index 0000000..f0707c0 --- /dev/null +++ b/sdnc_report_api_sdnc_253_story/sdnc_reports_service/src/main/java/com/onap/sdnc/reports/Application.java @@ -0,0 +1,84 @@ +/* +* ============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 java.util.Collections; + +import javax.xml.datatype.XMLGregorianCalendar; + +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.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Profile; +import org.springframework.data.jpa.repository.config.EnableJpaRepositories; +import org.springframework.web.servlet.config.annotation.EnableWebMvc; + +import com.fasterxml.jackson.annotation.JsonIgnore; +import springfox.documentation.builders.ApiInfoBuilder; +import springfox.documentation.builders.PathSelectors; +import springfox.documentation.builders.RequestHandlerSelectors; +import springfox.documentation.service.ApiInfo; +import springfox.documentation.spi.DocumentationType; +import springfox.documentation.spring.web.plugins.Docket; +import springfox.documentation.swagger2.annotations.EnableSwagger2; + +import static springfox.documentation.builders.PathSelectors.regex; + +@SpringBootApplication +//@EnableAutoConfiguration(exclude={DataSourceAutoConfiguration.class,HibernateJpaAutoConfiguration.class}) +//@EnableSwagger2 +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 SWAGGER API Has Started.."); + } + + + /*@Bean + public Docket api() { + return new Docket(DocumentationType.SWAGGER_2) + .select() + .apis(RequestHandlerSelectors.any()) + .paths(PathSelectors.any()) + .build(); + }*/ + + + + /* private ApiInfo apiInfo() { + return new ApiInfo( + "My REST API", + "Some custom description of API.", + "API TOS", + "Terms of service", + new Contact("John Doe", "www.example.com", "myeaddress@company.com"), + "License of API", "API license URL", Collections.emptyList()); + }*/ +} + + diff --git a/sdnc_report_api_sdnc_253_story/sdnc_reports_service/src/main/java/com/onap/sdnc/reports/ServletInitializer.java b/sdnc_report_api_sdnc_253_story/sdnc_reports_service/src/main/java/com/onap/sdnc/reports/ServletInitializer.java new file mode 100644 index 0000000..80d5eae --- /dev/null +++ b/sdnc_report_api_sdnc_253_story/sdnc_reports_service/src/main/java/com/onap/sdnc/reports/ServletInitializer.java @@ -0,0 +1,27 @@ +/* +* ============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 { + +} diff --git a/sdnc_report_api_sdnc_253_story/sdnc_reports_service/src/main/java/com/onap/sdnc/reports/config/JpaApplicationConfig.java b/sdnc_report_api_sdnc_253_story/sdnc_reports_service/src/main/java/com/onap/sdnc/reports/config/JpaApplicationConfig.java new file mode 100644 index 0000000..d6d9aec --- /dev/null +++ b/sdnc_report_api_sdnc_253_story/sdnc_reports_service/src/main/java/com/onap/sdnc/reports/config/JpaApplicationConfig.java @@ -0,0 +1,62 @@ +/* +* ============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_service/src/main/java/com/onap/sdnc/reports/config/SwaggerConfig.java b/sdnc_report_api_sdnc_253_story/sdnc_reports_service/src/main/java/com/onap/sdnc/reports/config/SwaggerConfig.java new file mode 100644 index 0000000..5117102 --- /dev/null +++ b/sdnc_report_api_sdnc_253_story/sdnc_reports_service/src/main/java/com/onap/sdnc/reports/config/SwaggerConfig.java @@ -0,0 +1,61 @@ +package com.onap.sdnc.reports.config; + +import static springfox.documentation.builders.PathSelectors.regex; + +import javax.xml.datatype.XMLGregorianCalendar; + +import org.springframework.boot.autoconfigure.domain.EntityScan; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Profile; +import org.springframework.data.jpa.repository.config.EnableJpaRepositories; + +import com.fasterxml.jackson.annotation.JsonIgnore; + +import springfox.documentation.builders.ApiInfoBuilder; +import springfox.documentation.service.ApiInfo; +import springfox.documentation.spi.DocumentationType; +import springfox.documentation.spring.web.plugins.Docket; +import springfox.documentation.swagger2.annotations.EnableSwagger2; + +@Configuration +@EnableJpaRepositories("com.onap.sdnc.reports.repository") +@EntityScan("com.onap.sdnc.reports.*") +@EnableSwagger2 +//@Profile("!test") +public class SwaggerConfig { + + @Bean + public Docket newsApi() { + return new Docket(DocumentationType.SWAGGER_2) + .groupName("sdncreport") + .apiInfo(apiInfo()) + .select() + .paths(regex("/sdnc/report/.*")) + // .paths(PathSelectors.any()) + .build() + .directModelSubstitute(XMLGregorianCalendar.class, MixIn.class); + } + + public static interface MixIn { + @JsonIgnore + public void setYear(int year); + } + + /** + * + * @return + */ + private ApiInfo apiInfo() { + return new ApiInfoBuilder() + .title("SDNC Report Service REST APIs") + .description("SDNC Report Microservice REST APIs") + .termsOfServiceUrl("http://....") + .contact("TechMahindra") + .license("TechMahindra Licensed") + .licenseUrl("https://techmahindra.com") + .version("2.0") + .build(); + } + +} diff --git a/sdnc_report_api_sdnc_253_story/sdnc_reports_service/src/main/java/com/onap/sdnc/reports/controller/PreTestController.java b/sdnc_report_api_sdnc_253_story/sdnc_reports_service/src/main/java/com/onap/sdnc/reports/controller/PreTestController.java new file mode 100644 index 0000000..cd3fdd3 --- /dev/null +++ b/sdnc_report_api_sdnc_253_story/sdnc_reports_service/src/main/java/com/onap/sdnc/reports/controller/PreTestController.java @@ -0,0 +1,147 @@ +/* +* ============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.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.MediaType; +import org.springframework.web.bind.annotation.GetMapping; +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.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; +import com.onap.sdnc.reports.service.ReportServiceImpl; + +import io.swagger.annotations.ApiOperation; +import io.swagger.annotations.ApiResponses; +import io.swagger.annotations.ApiResponse; + +@RestController +@RequestMapping("/sdnc/report") +//@RequestMapping("/") +public class PreTestController { + + private static final Logger logger = LogManager.getLogger(PreTestController.class); + @Autowired + IReportService reportService; + + @ApiOperation(value = "findReportByDeviceName/{startDate}/{endDate}/{deviceName}", notes = "findReportByDeviceName from specified start date and end date with given deviceName") + @ApiResponses(value = { @ApiResponse(code = 200, message = "got successfull"), + @ApiResponse(code = 500, message = "Internal Server Error") + }) + //@RequestMapping(value="/findReportByDeviceName/{startDate}/{endDate}/{deviceName}",produces=MediaType.APPLICATION_JSON_VALUE,method=RequestMethod.GET,consumes=("text/plain")) + @RequestMapping(value="/findReportByDeviceName/{startDate}/{endDate}/{deviceName}",method=RequestMethod.GET) + public List<PreTestModel> findReportByDeviceName(@PathVariable("startDate") long startDate,@PathVariable("endDate") long endDate,@PathVariable("deviceName") String deviceName) { + + try{ + logger.info("findReportByDeviceName Started Working.."); + Date sDate=new Date(startDate); + Date eDate=new Date(endDate); + + if(sDate.after(eDate) || eDate.before(sDate)) + { + // need to handle this condition + } + logger.info("findReportByDeviceName Finished Working.."); + return reportService.findReportByDeviceName(sDate,eDate,deviceName); + } + catch(Exception ex) + { + logger.info("Exception Occured : "+ex.getLocalizedMessage()); + return java.util.Collections.EMPTY_LIST; + } + + } + +/* @ApiOperation(value = "save users", notes = "save single report at a time") + @ApiResponses(value = { @ApiResponse(code = 200, message = "got successfull"), + @ApiResponse(code = 500, message = "Internal Server Error") + }) + @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())); + } + + @ApiOperation(value = "findAllReports", notes = "findAllReports from specified start date and end date") + @ApiResponses(value = { @ApiResponse(code = 200, message = "got successfull"), + @ApiResponse(code = 500, message = "Internal Server Error") + }) + @RequestMapping(value="/findAllReports/{startDate}/{endDate}",produces=MediaType.APPLICATION_JSON_VALUE) + public Response findAllReports(@PathVariable("startDate") Date startDate,@PathVariable("endDate") Date endDate) { + + //Iterable<Report> Reports = repository.findAll(); + + //return new Response("Done", Reports); + + return reportService.findAllReports(startDate,endDate); + } + + @ApiOperation(value = "findReportByTestName", notes = "findReportByTestName from specified start date and end date with given testName") + @ApiResponses(value = { @ApiResponse(code = 200, message = "got successfull"), + @ApiResponse(code = 500, message = "Internal Server Error") + }) + @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="/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); + }*/ + + + + /*@ApiOperation(value = "findReportByDeviceName/{startDate}/{endDate}/{deviceName}", notes = "findReportByDeviceName from specified start date and end date with given deviceName") + @ApiResponses(value = { @ApiResponse(code = 200, message = "got successfull"), + @ApiResponse(code = 500, message = "Internal Server Error") + }) + //@RequestMapping(value="/findReportByDeviceName/{startDate}/{endDate}/{deviceName}",produces=MediaType.APPLICATION_JSON_VALUE,method=RequestMethod.GET,consumes=("text/plain")) + @RequestMapping(value="/findReportByDeviceName/{startDate}/{endDate}/{deviceName}",method=RequestMethod.GET) + public List<PreTestModel> findReportByDeviceName(@PathVariable("startDate") Date startDate,@PathVariable("endDate") Date endDate,@PathVariable("deviceName") String deviceName) { + + System.out.println("findReportByDeviceName Got Called"); + //List<Report> Reports = null;//repository.findByLastName(lastName); + + //return new Response("Done", Reports); + + return reportService.findReportByDeviceName(startDate,endDate,deviceName); + }*/ + + +} diff --git a/sdnc_report_api_sdnc_253_story/sdnc_reports_service/src/main/java/com/onap/sdnc/reports/service/IReportService.java b/sdnc_report_api_sdnc_253_story/sdnc_reports_service/src/main/java/com/onap/sdnc/reports/service/IReportService.java new file mode 100644 index 0000000..f67c2e4 --- /dev/null +++ b/sdnc_report_api_sdnc_253_story/sdnc_reports_service/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 List<PreTestModel> findReportByDeviceName(@PathVariable("startDate") Date startDate,@PathVariable("endDate") Date endDate,@RequestParam("deviceName") String deviceName) throws Exception; + + public Response findReportsByDeviceNamdAndTestName(@PathVariable("startDate") Date startDate,@PathVariable("endDate") Date endDate,@PathVariable("deviceName") String deviceName,@PathVariable("testName") String testName); + +} diff --git a/sdnc_report_api_sdnc_253_story/sdnc_reports_service/src/main/java/com/onap/sdnc/reports/service/ReportServiceImpl.java b/sdnc_report_api_sdnc_253_story/sdnc_reports_service/src/main/java/com/onap/sdnc/reports/service/ReportServiceImpl.java new file mode 100644 index 0000000..522c8c8 --- /dev/null +++ b/sdnc_report_api_sdnc_253_story/sdnc_reports_service/src/main/java/com/onap/sdnc/reports/service/ReportServiceImpl.java @@ -0,0 +1,112 @@ +/* +* ============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.log4j.Logger; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import com.onap.sdnc.reports.controller.PreTestController; +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 Logger logger=Logger.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("findReportByDeviceName Received Output : "+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()); + } + } + Response r=new Response("Pass", resultSet); + logger.info("Final PreTestConfig List Size : "+preTestList.size()); + 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) { + + return null; + } + +} |