fixed code formatting issue

This commit is contained in:
akeshri 2020-07-05 21:33:50 +05:30
parent 18894f5c03
commit b59f4d32b4
9 changed files with 193 additions and 191 deletions

View File

@ -9,10 +9,8 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
*/ */
@SpringBootApplication @SpringBootApplication
public class App public class App {
{ public static void main(String[] args) {
public static void main( String[] args )
{
SpringApplication.run(App.class, args); SpringApplication.run(App.class, args);
} }
} }

View File

@ -20,7 +20,7 @@ import com.fasterxml.jackson.dataformat.csv.CsvSchema;
* *
*/ */
@SpringBootApplication(exclude = {EmbeddedServletContainerAutoConfiguration.class,WebMvcAutoConfiguration.class}) @SpringBootApplication(exclude = { EmbeddedServletContainerAutoConfiguration.class, WebMvcAutoConfiguration.class })
public class ConsoleApp implements CommandLineRunner { public class ConsoleApp implements CommandLineRunner {
@Autowired @Autowired
private ProductService productService; private ProductService productService;
@ -32,13 +32,15 @@ public class ConsoleApp implements CommandLineRunner {
@Override @Override
public void run(String... args) throws Exception { public void run(String... args) throws Exception {
String filePath = ""; String filePath = "";
if (args != null && args.length == 2 && "Product".equalsIgnoreCase(args[0]) if (args != null && args.length == 2 && "Product".equalsIgnoreCase(args[0]) && (filePath = args[1]).length() > 0) {
&& (filePath = args[1]).length() > 0) {
File sourceFile = new File(filePath); File sourceFile = new File(filePath);
if (sourceFile.exists()) { if (sourceFile.exists()) {
CsvMapper mapper = new CsvMapper(); CsvMapper mapper = new CsvMapper();
List<Product> products = mapper.readerFor(Product.class).with(CsvSchema.emptySchema().withHeader()) List<Product> products = mapper.readerFor(Product.class)
.<Product>readValues(sourceFile).readAll(); .with(CsvSchema.emptySchema()
.withHeader())
.<Product> readValues(sourceFile)
.readAll();
productService.saveAll(products); productService.saveAll(products);
} }

View File

@ -28,7 +28,10 @@ public class ProductController {
@RequestMapping(value = "/all", method = RequestMethod.GET) @RequestMapping(value = "/all", method = RequestMethod.GET)
public List<ProductDto> list() { public List<ProductDto> list() {
return productService.findAll().stream().map(p -> new ProductDto(p)).collect(Collectors.toList()); return productService.findAll()
.stream()
.map(p -> new ProductDto(p))
.collect(Collectors.toList());
} }
@RequestMapping(value = "/{productId}", method = RequestMethod.GET) @RequestMapping(value = "/{productId}", method = RequestMethod.GET)

View File

@ -1,6 +1,7 @@
package com.baeldung.hexagonal.architecture.dtos; package com.baeldung.hexagonal.architecture.dtos;
import com.baeldung.hexagonal.architecture.model.Product; import com.baeldung.hexagonal.architecture.model.Product;
/** /**
* @author AshwiniKeshri * @author AshwiniKeshri
* *
@ -17,7 +18,8 @@ public class ProductDto {
private String description; private String description;
public ProductDto() {} public ProductDto() {
}
public ProductDto(Product product) { public ProductDto(Product product) {
this.description = product.getDescription(); this.description = product.getDescription();
@ -67,5 +69,4 @@ public class ProductDto {
this.description = description; this.description = description;
} }
} }

View File

@ -19,7 +19,7 @@ import javax.persistence.Table;
@Entity @Entity
@Table(name = "PRODUCT") @Table(name = "PRODUCT")
public class Product implements Serializable{ public class Product implements Serializable {
/** /**
* *
@ -30,7 +30,7 @@ public class Product implements Serializable{
@GeneratedValue(strategy = GenerationType.AUTO) @GeneratedValue(strategy = GenerationType.AUTO)
private Long id; private Long id;
@Column(name="NAME") @Column(name = "NAME")
private String name; private String name;
@Column(name = "QUANTITY") @Column(name = "QUANTITY")
@ -82,6 +82,4 @@ public class Product implements Serializable{
this.description = description; this.description = description;
} }
} }

View File

@ -9,6 +9,6 @@ import com.baeldung.hexagonal.architecture.model.Product;
* *
*/ */
public interface ProductRepository extends JpaRepository<Product,Long>{ public interface ProductRepository extends JpaRepository<Product, Long> {
} }

View File

@ -37,7 +37,7 @@ public class ProductServiceTest {
product.setPrice(10.0); product.setPrice(10.0);
product.setQuantity(100l); product.setQuantity(100l);
Long id = productService.create(product); Long id = productService.create(product);
Assert.assertTrue(id >0); Assert.assertTrue(id > 0);
} }
} }