Skip to content

Commit

Permalink
Merge pull request #28 from 9oormthonUniv-seoultech/develop
Browse files Browse the repository at this point in the history
Develop to Main #2
  • Loading branch information
Jeongh00 authored Oct 3, 2024
2 parents 779e0f8 + 322411a commit 404cb4d
Show file tree
Hide file tree
Showing 104 changed files with 2,392 additions and 43 deletions.
14 changes: 14 additions & 0 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,20 @@ jobs:
echo "${{ secrets.APPLICATION_OAUTH }}" > ./application-oauth.yml
shell: bash

- name: make application-s3 yml file
run: |
cd ./core/src/main/resources
touch ./application-s3.yml
echo "${{ secrets.APPLICATION_S3 }}" > ./application-s3.yml
shell: bash

- name: make application-batch yml file
run: |
cd ./batch/src/main/resources
touch ./application-batch.yml
echo "${{ secrets.APPLICATION_BATCH }}" > ./application-batch.yml
shell: bash

- name: Gradlew 권한 부여
run: chmod +x ./gradlew

Expand Down
37 changes: 37 additions & 0 deletions batch/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
HELP.md
.gradle
build/
!gradle/wrapper/gradle-wrapper.jar
!**/src/main/**/build/
!**/src/test/**/build/

### STS ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
bin/
!**/src/main/**/bin/
!**/src/test/**/bin/

### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr
out/
!**/src/main/**/out/
!**/src/test/**/out/

### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/

### VS Code ###
.vscode/
31 changes: 31 additions & 0 deletions batch/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
dependencies {

implementation project(':core')
implementation project(':domain')
implementation project(':outbound')

implementation 'org.springframework.boot:spring-boot-starter-validation'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-security'
implementation 'org.springframework.boot:spring-boot-starter-oauth2-client'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'

runtimeOnly 'com.mysql:mysql-connector-j'

testImplementation 'io.rest-assured:rest-assured'

implementation 'org.springframework.boot:spring-boot-starter-batch' // batch
testImplementation 'org.springframework.batch:spring-batch-test'

}

bootJar {
enabled = false
}

jar {
enabled = true
}

tasks.register("prepareKotlinBuildScriptModel") {}
Binary file added batch/gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
7 changes: 7 additions & 0 deletions batch/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.1-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
17 changes: 17 additions & 0 deletions batch/src/main/java/com/pocket/batch/BatchApplication.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.pocket.batch;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.context.annotation.ComponentScan;

@SpringBootApplication
@EntityScan(basePackages = "com.pocket")
@ComponentScan(basePackages = "com.pocket")
public class BatchApplication {

public static void main(String[] args) {
SpringApplication.run(BatchApplication.class, args);
}

}
20 changes: 20 additions & 0 deletions batch/src/main/java/com/pocket/batch/config/BatchConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.pocket.batch.config;

import org.springframework.batch.core.configuration.JobRegistry;
import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing;
import org.springframework.batch.core.configuration.support.JobRegistryBeanPostProcessor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@EnableBatchProcessing
@Configuration
public class BatchConfig {

@Bean
public JobRegistryBeanPostProcessor jobRegistryBeanPostProcessor(JobRegistry jobRegistry) {
JobRegistryBeanPostProcessor jobRegistryBeanPostProcessor = new JobRegistryBeanPostProcessor();
jobRegistryBeanPostProcessor.setJobRegistry(jobRegistry);
return jobRegistryBeanPostProcessor;

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.pocket.batch.controller;

import org.springframework.batch.core.ExitStatus;
import org.springframework.batch.core.Job;
import org.springframework.batch.core.configuration.JobRegistry;
import org.springframework.batch.core.launch.JobLauncher;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("job")
public class JobLauncherController {

private final JobLauncher jobLauncher;

private final JobRegistry jobRegistry;

public JobLauncherController(JobLauncher jobLauncher, JobRegistry jobRegistry) {
this.jobLauncher = jobLauncher;
this.jobRegistry = jobRegistry;
}

@PostMapping("/launcher")
public ExitStatus launchJob(@RequestBody JobLauncherRequest request) throws Exception {
Job job = jobRegistry.getJob(request.getName());
return this.jobLauncher.run(job, request.getJobParameters()).getExitStatus();

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.pocket.batch.controller;

import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import org.springframework.batch.core.JobParameters;
import org.springframework.batch.core.JobParametersBuilder;

import java.util.Properties;

@Getter
@Setter
@ToString
public class JobLauncherRequest {
private String name;
private Properties jobParameters;

public JobParameters getJobParameters() {
JobParametersBuilder builder = new JobParametersBuilder();
for (String key : jobParameters.stringPropertyNames()) {
String value = jobParameters.getProperty(key);
builder.addString(key, value);
}
return builder.toJobParameters();
}
}
19 changes: 19 additions & 0 deletions batch/src/main/java/com/pocket/batch/dto/KakaoDocument.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.pocket.batch.dto;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class KakaoDocument {

private String place_name;
private String road_address_name;
private String x;
private String y;
private String category_name;
}
16 changes: 16 additions & 0 deletions batch/src/main/java/com/pocket/batch/dto/KakaoLocalResponse.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.pocket.batch.dto;

import java.util.List;

public class KakaoLocalResponse {

private List<KakaoDocument> documents;

public List<KakaoDocument> getDocuments() {
return documents;
}

public void setDocuments(List<KakaoDocument> documents) {
this.documents = documents;
}
}
51 changes: 51 additions & 0 deletions batch/src/main/java/com/pocket/batch/job/AddPlacesJobConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package com.pocket.batch.job;

import com.pocket.batch.step.AddPlacesProcessor;
import com.pocket.batch.step.AddPlacesReader;
import com.pocket.batch.step.AddPlacesWriter;
import com.pocket.domain.dto.photobooth.PhotoBoothFindResponseDto;
import com.pocket.outbound.entity.JpaPhotoBooth;
import lombok.RequiredArgsConstructor;
import org.springframework.batch.core.Job;
import org.springframework.batch.core.Step;
import org.springframework.batch.core.job.builder.JobBuilder;
import org.springframework.batch.core.repository.JobRepository;
import org.springframework.batch.core.step.builder.StepBuilder;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.transaction.PlatformTransactionManager;

@Configuration
@RequiredArgsConstructor
public class AddPlacesJobConfig {

private final JobRepository jobRepository;
private final PlatformTransactionManager transactionManager;
private final AddPlacesReader addPlacesReader;
private final AddPlacesProcessor addPlacesProcessor;
private final AddPlacesWriter addPlacesWriter;

@Value("${batch.kakao.chunk-size}")
private int chunkSize;

@Bean
public Job addPlacesJob() {
return new JobBuilder("addPlacesJob", jobRepository)
.start(addPlacesStep())
.build();
}

@Bean
public Step addPlacesStep() {
return new StepBuilder("addPlacesStep", jobRepository)
// 제네릭 타입을 List 대신 PhotoBoothFindResponseDto와 JpaPhotoBooth로 변경
.<PhotoBoothFindResponseDto, JpaPhotoBooth>chunk(chunkSize, transactionManager)
.reader(addPlacesReader)
.processor(addPlacesProcessor)
.writer(addPlacesWriter)
.allowStartIfComplete(true)
.build();
}

}
29 changes: 29 additions & 0 deletions batch/src/main/java/com/pocket/batch/step/AddPlacesProcessor.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.pocket.batch.step;

import com.pocket.domain.dto.photobooth.PhotoBoothFindResponseDto;
import com.pocket.domain.entity.photobooth.PhotoBooth;
import com.pocket.outbound.entity.JpaPhotoBooth;
import org.springframework.batch.item.ItemProcessor;
import org.springframework.stereotype.Component;

@Component
public class AddPlacesProcessor implements ItemProcessor<PhotoBoothFindResponseDto, JpaPhotoBooth> {

@Override
public JpaPhotoBooth process(PhotoBoothFindResponseDto dto) throws Exception {
// DTO를 사용하여 PhotoBooth 객체 생성
PhotoBooth photoBooth = PhotoBooth.create(
dto.name(),
dto.road(),
dto.x(),
dto.y(),
dto.photoBoothBrand()
);

// JpaPhotoBooth 객체 생성 및 PhotoBooth 설정
JpaPhotoBooth jpaPhotoBooth = new JpaPhotoBooth();
jpaPhotoBooth.setPhotoBooth(photoBooth);

return jpaPhotoBooth; // 변환된 객체 반환
}
}
Loading

0 comments on commit 404cb4d

Please sign in to comment.