Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
7512e12
feat: add exhibition crawler
ddnjs Oct 31, 2023
aacb01f
reset db, kms, ssh values
cheolwon1994 Nov 10, 2023
8f91931
remove unneeded code
cheolwon1994 Nov 10, 2023
f7d11ed
add regions and apply ssh tunneling
dev-khg Nov 11, 2023
4c9121e
Merge pull request #21 from Project-Catcher/refactor-cw-modify-db
cheolwon1994 Nov 11, 2023
29bc0a4
Merge branch 'feat-dw-crawling-job' of https://github.com/Project-Cat…
ddnjs Nov 12, 2023
9c3313c
feat: 배치 관련 entity 구현
inyoung0215 Nov 7, 2023
93bfef4
feat: camping property 구현
inyoung0215 Nov 7, 2023
e0fe909
feat: camping feign 호출
inyoung0215 Nov 7, 2023
7eb6f2c
test: camping feign 호출 test 코드
inyoung0215 Nov 7, 2023
5f5c795
feat: 캠핑 아이템 db 저장 구현
inyoung0215 Nov 7, 2023
56efafe
fix: test 코드 오류 수정
inyoung0215 Nov 7, 2023
f5b3817
fix: test 코드에 MockBean 추가
inyoung0215 Nov 7, 2023
e861f47
fix: test 코드에 MockBean 추가
inyoung0215 Nov 7, 2023
bd27fd4
fix: @SpringBootTest 주석처리
inyoung0215 Nov 7, 2023
39b9957
fix: @SpringBootTest 제거
inyoung0215 Nov 7, 2023
386ce4c
fix: security 비활성화
inyoung0215 Nov 7, 2023
9b5f246
refactor: hashValue 암호화
inyoung0215 Nov 8, 2023
bdd0902
chore: 사용하지 않는 import문 제거
inyoung0215 Nov 8, 2023
99768e5
fix: 병합충돌해결
inyoung0215 Nov 8, 2023
813d235
refactor: localdatetime을 zone으로 변경
inyoung0215 Nov 12, 2023
036fa0e
refactor: 위도, 경도 변수명 변경
inyoung0215 Nov 12, 2023
5fe1875
Merge pull request #20 from Project-Catcher/feat-ny-save-camping-data
inyoung0215 Nov 12, 2023
0ad0fa6
Merge branch 'dev' of https://github.com/Project-Catcher/batch-servic…
ddnjs Nov 12, 2023
c514345
전시회 db 저장
ddnjs Nov 12, 2023
1bbecf7
refactor: stream으로 리팩토링
inyoung0215 Nov 12, 2023
6646392
feat: header 설정 구현
inyoung0215 Nov 12, 2023
aebfe89
feat: 음식점 db 저장 구현
inyoung0215 Nov 12, 2023
16f6768
chore: @Where 주석 처리
inyoung0215 Nov 12, 2023
70b7e95
test: 음식점 저장 성공 테스트
inyoung0215 Nov 12, 2023
cb43ed1
refactor: hashKey 중복 검사 로직 리팩토링
inyoung0215 Nov 13, 2023
b5900d4
chore: delete 컬럼명 수정, @Where 수정
inyoung0215 Nov 13, 2023
325eddb
test: 음식점 단위 테스트 코드 리팩토링
inyoung0215 Nov 13, 2023
0ebd09e
refactor: category repository 구조 변경
inyoung0215 Nov 14, 2023
9ae0da7
refactor: saveAll() 대신 save() 사용하도록 변경
inyoung0215 Nov 14, 2023
d49d1b4
test: 음식점 단위 테스트 - 중복 객체 검사 코드 리팩토링
inyoung0215 Nov 14, 2023
76d885c
feat: 키값 중복 검사 로직 추가 구현
inyoung0215 Nov 14, 2023
2ed9747
test: 코드 변경으로 인한 수정
inyoung0215 Nov 14, 2023
ca49bdb
change datasource
dev-khg Nov 14, 2023
290459a
style: 필요없는 괄호 제거
inyoung0215 Nov 15, 2023
24d160d
Merge pull request #22 from Project-Catcher/feat-ny-save-restaurant-data
inyoung0215 Nov 15, 2023
ff002e1
Merge pull request #23 from Project-Catcher/refactor-hg-datasource
dev-khg Nov 15, 2023
ecccfd4
Merge branch 'dev' of https://github.com/Project-Catcher/batch-servic…
ddnjs Nov 17, 2023
c5ccd3c
전시회 DB저장 데이터 수정
ddnjs Nov 17, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ dependencies {
//swagger
implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.2.0'

//crawling
implementation 'org.seleniumhq.selenium:selenium-java:4.14.1'
implementation 'com.opencsv:opencsv:5.7.1'
}

dependencyManagement {
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/catcher/batch/BatchApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;

@SpringBootApplication
@EnableFeignClients(basePackages = "com.catcher.batch.resource.external")
@EnableJpaAuditing
public class BatchApplication {

public static void main(String[] args) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

import com.catcher.batch.core.converter.CatcherConverter;
import com.catcher.batch.core.properties.PropertyBase;
import com.catcher.batch.core.properties.HeaderSupport;
import com.catcher.batch.resource.external.ExternalFeign;
import jakarta.annotation.PostConstruct;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.ApplicationContext;
import org.springframework.http.HttpHeaders;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

Expand Down Expand Up @@ -40,6 +42,13 @@ public <T> T parseService(Map<String, Object> params, Class<T> requestType) {
property.setParams(params);
URI uri = property.getURI();

// 헤더가 있는 경우
HttpHeaders headers;
if (property instanceof HeaderSupport headerSupport) {
headers = headerSupport.addHeaders();
return catcherConverter.parse(externalFeign.getInfoWithHeader(headers.getFirst("Authorization"), uri), requestType);
}

return catcherConverter.parse(externalFeign.getInfo(uri), requestType);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.catcher.batch.common.utils;

import org.apache.commons.codec.digest.DigestUtils;

public class HashCodeGenerator {
public static String hashString(String category, String input) {
return DigestUtils.sha256Hex(category + "-" + input);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.catcher.batch.annotation.CatcherJson;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.commons.lang3.StringUtils;
import org.json.JSONObject;
import org.springframework.stereotype.Component;

Expand Down Expand Up @@ -33,6 +34,8 @@ private <T> String getPath(Class<T> responseType) {
private JSONObject getJsonObject(String json, String jsonPath) {
if(jsonPath == null) {
throw new IllegalStateException();
} else if (StringUtils.isBlank(jsonPath)) {
return new JSONObject(json);
}

JSONObject jsonObject = new JSONObject(json);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.catcher.batch.core.database;

import com.catcher.batch.core.domain.entity.CatcherItem;
import com.catcher.batch.core.domain.entity.Category;

import java.util.List;
import java.util.Optional;

public interface CatcherItemRepository {
void saveAll(List<CatcherItem> catcherItems);

void save(CatcherItem catcherItem);

Optional<CatcherItem> findByItemHashValue(String hashKey);

List<CatcherItem> findByCategory(Category category);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.catcher.batch.core.database;

import com.catcher.batch.core.domain.entity.Category;

import java.util.Optional;

public interface CategoryRepository {
Optional<Category> findByName(String name);

Category save(Category category);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.catcher.batch.core.database;

import com.catcher.batch.core.domain.entity.Location;

import java.util.Optional;

public interface LocationRepository {
Optional<Location> findByDescription(String province, String city);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.catcher.batch.core.domain;

import com.catcher.batch.core.domain.command.Command;
import org.springframework.stereotype.Component;

@Component
public class CatcherItemExecutor implements CommandExecutor {
@Override
public <T> T run(Command<T> command) {
return command.execute();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.catcher.batch.core.domain;

import com.catcher.batch.core.domain.command.Command;

public interface CommandExecutor {
<T> T run(Command<T> command);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.catcher.batch.core.domain.command;

public interface Command<T> {
T execute();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.catcher.batch.core.domain.command;

import com.catcher.batch.core.dto.CampingApiResponse;
import com.catcher.batch.core.service.CampingService;
import lombok.RequiredArgsConstructor;


@RequiredArgsConstructor
public class RegisterCampingDataCommand implements Command<Void> {
private final CampingService campingService;
private final CampingApiResponse campingApiResponse;

@Override
public Void execute() {
campingService.batch(campingApiResponse);
return null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.catcher.batch.core.domain.command;

import com.catcher.batch.core.dto.RestaurantApiResponse;
import com.catcher.batch.core.service.RestaurantService;
import lombok.RequiredArgsConstructor;

@RequiredArgsConstructor
public class RegisterRestaurantDataCommand implements Command<Void> {
private final RestaurantService restaurantService;
private final RestaurantApiResponse restaurantApiResponse;

@Override
public Void execute() {
restaurantService.batch(restaurantApiResponse);
return null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.catcher.batch.core.domain.entity;

import jakarta.persistence.*;
import lombok.Getter;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import java.time.LocalDateTime;
import java.time.ZonedDateTime;

@EntityListeners(AuditingEntityListener.class)
@MappedSuperclass
@Getter
public class BaseTimeEntity {
@Column(name = "created_at")
private ZonedDateTime createdAt;

@Column(name = "updated_at")
private ZonedDateTime updatedAt;

@PrePersist
private void prePersist() {
this.createdAt = ZonedDateTime.now();
this.updatedAt = ZonedDateTime.now();
}

@PreUpdate
private void preUpdate() {
this.updatedAt = ZonedDateTime.now();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package com.catcher.batch.core.domain.entity;

import jakarta.persistence.*;
import lombok.*;
import org.hibernate.annotations.Where;

import java.time.ZonedDateTime;

@Entity
@Builder
@Getter
@AllArgsConstructor(access = AccessLevel.PROTECTED)
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@Where(clause = "deleted_at IS NULL")
@Table(name = "catcher_item")
public class CatcherItem extends BaseTimeEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "category_id", nullable = false)
private Category category;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "location_id")
private Location location;

@Column(unique = true, nullable = false)
private String itemHashValue;

@Column(nullable = false)
private String title;

private String description;

private String thumbnailUrl;

private String resourceUrl;

@Column(name = "start_at")
private ZonedDateTime startAt;

@Column(name = "end_at")
private ZonedDateTime endAt;

@Column(name = "deleted_at")
private ZonedDateTime deletedAt;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.catcher.batch.core.domain.entity;

import jakarta.persistence.*;
import lombok.AccessLevel;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Entity
@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@Table(name = "category")
public class Category {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@Column(nullable = false)
private String name;

public static Category create(String name) {
Category category = new Category();
category.name = name;
return category;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.catcher.batch.core.domain.entity;

import jakarta.persistence.*;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Entity
@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@Table(name = "location")
public class Location {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

private String areaCode;

private String latitude;

private String longitude;

private String description;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package com.catcher.batch.core.dto;

import com.catcher.batch.annotation.CatcherJson;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Getter;

import java.util.List;

@Getter
@JsonIgnoreProperties(ignoreUnknown = true)
@CatcherJson(path = "response.body")
public class CampingApiResponse {

@JsonProperty("items")
private CampingItems items;

@JsonProperty("totalCount")
private Integer totalCount;

@JsonProperty("numOfRows")
private Integer numOfRows;

@JsonProperty("pageNo")
private Integer pageNo;

@Getter
@JsonIgnoreProperties(ignoreUnknown = true)
public static class CampingItems {
@JsonProperty("item")
private List<CampingItem> item;
}

@Getter
@JsonIgnoreProperties(ignoreUnknown = true)
public static class CampingItem {

@JsonProperty("facltNm")
private String name;

@JsonProperty("contentId")
private String key;

@JsonProperty("lineIntro")
private String description;

@JsonProperty("doNm")
private String province;

@JsonProperty("sigunguNm")
private String city;

@JsonProperty("addr1")
private String address;

@JsonProperty("induty")
private String category;

@JsonProperty("zipcode")
private String zipcode;

@JsonProperty("homepage")
private String homepage;

@JsonProperty("mapX")
private String latitude;

@JsonProperty("mapY")
private String longitude;

@JsonProperty("firstImageUrl")
private String thumbnailUrl;
}
}
Loading