Skip to content

Commit

Permalink
Merge pull request 9oorm-Oreum#2 from 9oorm-Oreum/feat/batch
Browse files Browse the repository at this point in the history
add: crossorigin 어노테이션 추가
  • Loading branch information
Song-EunJu authored Nov 17, 2022
2 parents b9e644d + 96adc9e commit a9e0a94
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 25 deletions.
33 changes: 18 additions & 15 deletions src/main/java/com/example/goorm/FileItemReaderJobConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
//import com.example.goorm.oreum.CsvReader;
//import com.example.goorm.oreum.CsvWriter;
//import com.example.goorm.oreum.Oreum;
//import com.example.goorm.oreum.Test;
//import com.example.goorm.oreum.repository.OreumRepository;
//import com.example.goorm.oreum.repository.TestRepository;
//import lombok.RequiredArgsConstructor;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.batch.core.Job;
Expand All @@ -21,7 +23,7 @@
// private final JobBuilderFactory jobBuilderFactory;
// private final StepBuilderFactory stepBuilderFactory;
//
// private final OreumRepository oreumRepository;
// private final TestRepository testRepository;
// private final CsvReader csvReader;
// private final CsvWriter csvWriter;
//
Expand All @@ -38,9 +40,21 @@
// .build();
// }
//
// // csvFileItemReaderStep 이라는 이름의 Step 생성
// @Bean
// public Step csvFileItemReaderStep() {
// return stepBuilderFactory.get("csvFileItemReaderStep")
// .<String, Oreum>chunk(chunkSize)
// // Reader 에서 읽어올 타입 - String, Writer에 넘겨줄 타입이 Oreum
// .reader(csvReader.csvFileItemReader()) // 일단 csv에서 String 읽기
// .processor(csvProcessor()) // String을 가공
// .writer(csvWriter)
// .build();
// }
// @Bean
// public ItemProcessor<String, Oreum> csvProcessor() {
// public ItemProcessor<String, Test> csvProcessor() {
// return oreumStr -> {
// System.out.println(oreumStr);
// String[] lineArr = oreumStr.split(",");
// String name = lineArr[0];
// String type = lineArr[1].split("/")[1];
Expand All @@ -50,7 +64,7 @@
// double y = Double.parseDouble(pos.split(" ")[1]);
// double z = Double.parseDouble(pos.split(" ")[2]);
//
// Oreum oreum = Oreum.builder()
// Test oreum = Test.builder()
// .name(name)
// .xPos(x)
// .yPos(y)
Expand All @@ -60,7 +74,7 @@
// .build();
//
// oreum.toTypeEnum(type);
// oreumRepository.save(oreum);
// testRepository.save(oreum);
// if((monthCheck == 1 || monthCheck == 3 || monthCheck == 5 || monthCheck == 7
// || monthCheck == 8 || monthCheck == 10 || monthCheck ==12) && dayCheck == 31) {
// monthCheck++;
Expand All @@ -79,15 +93,4 @@
// };
// }
//
// // csvFileItemReaderStep 이라는 이름의 Step 생성
// @Bean
// public Step csvFileItemReaderStep() {
// return stepBuilderFactory.get("csvFileItemReaderStep")
// .<String, Oreum>chunk(chunkSize)
// // Reader 에서 읽어올 타입 - String, Writer에 넘겨줄 타입이 Oreum
// .reader(csvReader.csvFileItemReader()) // 일단 csv에서 String 읽기
// .processor(csvProcessor()) // String을 가공
// .writer(csvWriter)
// .build();
// }
//}
4 changes: 1 addition & 3 deletions src/main/java/com/example/goorm/oreum/CsvReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
//
//import lombok.RequiredArgsConstructor;
//import org.springframework.batch.item.file.FlatFileItemReader;
//import org.springframework.batch.item.file.mapping.DefaultLineMapper;
//import org.springframework.batch.item.file.transform.DelimitedLineTokenizer;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.core.io.ClassPathResource;
Expand All @@ -16,7 +14,7 @@
// /* file read */
// FlatFileItemReader<String> flatFileItemReader = new FlatFileItemReader<>();
// flatFileItemReader.setResource(new ClassPathResource("C:\\Users\\Windows10\\Desktop\\오름.txt"));
// flatFileItemReader.setEncoding("UTF-8"); // encoding
// flatFileItemReader.setEncoding("UTF-8");
// return flatFileItemReader;
// }
//}
4 changes: 3 additions & 1 deletion src/main/java/com/example/goorm/oreum/CsvWriter.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//package com.example.goorm.oreum;
//
//import com.example.goorm.oreum.repository.OreumRepository;
//import com.example.goorm.oreum.repository.TestRepository;
//import lombok.RequiredArgsConstructor;
//import org.springframework.batch.item.ItemWriter;
//import org.springframework.context.annotation.Configuration;
Expand All @@ -11,8 +12,9 @@
//@Configuration
//@RequiredArgsConstructor
//public class CsvWriter implements ItemWriter<Oreum> {
//// private final OreumRepository oreumRepository;
//
// private final OreumRepository oreumRepository;
// private final TestRepository testRepository;
//
// @Override
// public void write(List<? extends Oreum> list) throws Exception {
Expand Down
8 changes: 2 additions & 6 deletions src/main/java/com/example/goorm/oreum/OreumController.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,11 @@
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;

import java.util.List;
import org.springframework.web.bind.annotation.*;


@Controller
@CrossOrigin(origins = "*")
@RequiredArgsConstructor
public class OreumController {

Expand Down
39 changes: 39 additions & 0 deletions src/main/java/com/example/goorm/oreum/Test.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.example.goorm.oreum;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

import javax.persistence.*;
import java.time.LocalDateTime;
import java.util.Arrays;

@Entity
@Getter
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class Test {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private String name;

@Enumerated(EnumType.STRING)
private OreumType type;
private double xPos;
private double yPos;
private double zPos;
private int month;
private int day;

// 랜덤 색상값 추가해줘야 함
public void toTypeEnum(String type) {
this.type = Arrays.stream(OreumType.values())
.filter(o1 -> o1.getTitle().equals(type))
.findFirst()
.get();
}

}

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.example.goorm.oreum.repository;

import com.example.goorm.oreum.Oreum;
import com.example.goorm.oreum.Test;
import org.springframework.data.jpa.repository.JpaRepository;

public interface TestRepository extends JpaRepository<Test, Long> {
}

0 comments on commit a9e0a94

Please sign in to comment.