오픈서치 인덱싱, 검색 프로젝트 추가.

thkim
강석 최 2024-04-05 16:09:26 +09:00
parent 10a2b0da22
commit 182186dc26
34 changed files with 1372 additions and 0 deletions

37
kcsc-opensearch/.gitignore vendored Normal file
View File

@ -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/

View File

@ -0,0 +1,35 @@
plugins {
id 'java'
id 'org.springframework.boot' version '3.2.4'
id 'io.spring.dependency-management' version '1.1.4'
}
group = 'com.dbnt'
version = '0.0.1-SNAPSHOT'
java {
sourceCompatibility = '17'
}
repositories {
mavenCentral()
}
dependencies {
compileOnly 'org.projectlombok:lombok:1.18.24'
annotationProcessor 'org.projectlombok:lombok:1.18.24'
annotationProcessor 'org.springframework.boot:spring-boot-configuration-processor'
implementation 'org.springframework.boot:spring-boot-starter'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-actuator'
// https://mvnrepository.com/artifact/org.opensearch.client/spring-data-opensearch-starter
implementation (group: 'org.opensearch.client', name: 'spring-data-opensearch-starter', version: '1.3.0'){
exclude group: 'org.opensearch.client', module: 'opensearch-rest-client-sniffer'
}
runtimeOnly 'org.postgresql:postgresql:42.3.6'
}

Binary file not shown.

View File

@ -0,0 +1,7 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

249
kcsc-opensearch/gradlew vendored Normal file
View File

@ -0,0 +1,249 @@
#!/bin/sh
#
# Copyright © 2015-2021 the original authors.
#
# 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
#
# https://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.
#
##############################################################################
#
# Gradle start up script for POSIX generated by Gradle.
#
# Important for running:
#
# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is
# noncompliant, but you have some other compliant shell such as ksh or
# bash, then to run this script, type that shell name before the whole
# command line, like:
#
# ksh Gradle
#
# Busybox and similar reduced shells will NOT work, because this script
# requires all of these POSIX shell features:
# * functions;
# * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
# «${var#prefix}», «${var%suffix}», and «$( cmd )»;
# * compound commands having a testable exit status, especially «case»;
# * various built-in commands including «command», «set», and «ulimit».
#
# Important for patching:
#
# (2) This script targets any POSIX shell, so it avoids extensions provided
# by Bash, Ksh, etc; in particular arrays are avoided.
#
# The "traditional" practice of packing multiple parameters into a
# space-separated string is a well documented source of bugs and security
# problems, so this is (mostly) avoided, by progressively accumulating
# options in "$@", and eventually passing that to Java.
#
# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS,
# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly;
# see the in-line comments for details.
#
# There are tweaks for specific operating systems such as AIX, CygWin,
# Darwin, MinGW, and NonStop.
#
# (3) This script is generated from the Groovy template
# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# within the Gradle project.
#
# You can find Gradle at https://github.com/gradle/gradle/.
#
##############################################################################
# Attempt to set APP_HOME
# Resolve links: $0 may be a link
app_path=$0
# Need this for daisy-chained symlinks.
while
APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path
[ -h "$app_path" ]
do
ls=$( ls -ld "$app_path" )
link=${ls#*' -> '}
case $link in #(
/*) app_path=$link ;; #(
*) app_path=$APP_HOME$link ;;
esac
done
# This is normally unused
# shellcheck disable=SC2034
APP_BASE_NAME=${0##*/}
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit
# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum
warn () {
echo "$*"
} >&2
die () {
echo
echo "$*"
echo
exit 1
} >&2
# OS specific support (must be 'true' or 'false').
cygwin=false
msys=false
darwin=false
nonstop=false
case "$( uname )" in #(
CYGWIN* ) cygwin=true ;; #(
Darwin* ) darwin=true ;; #(
MSYS* | MINGW* ) msys=true ;; #(
NONSTOP* ) nonstop=true ;;
esac
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
# Determine the Java command to use to start the JVM.
if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
# IBM's JDK on AIX uses strange locations for the executables
JAVACMD=$JAVA_HOME/jre/sh/java
else
JAVACMD=$JAVA_HOME/bin/java
fi
if [ ! -x "$JAVACMD" ] ; then
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
else
JAVACMD=java
if ! command -v java >/dev/null 2>&1
then
die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
fi
# Increase the maximum file descriptors if we can.
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
case $MAX_FD in #(
max*)
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC2039,SC3045
MAX_FD=$( ulimit -H -n ) ||
warn "Could not query maximum file descriptor limit"
esac
case $MAX_FD in #(
'' | soft) :;; #(
*)
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC2039,SC3045
ulimit -n "$MAX_FD" ||
warn "Could not set maximum file descriptor limit to $MAX_FD"
esac
fi
# Collect all arguments for the java command, stacking in reverse order:
# * args from the command line
# * the main class name
# * -classpath
# * -D...appname settings
# * --module-path (only if needed)
# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables.
# For Cygwin or MSYS, switch paths to Windows format before running java
if "$cygwin" || "$msys" ; then
APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" )
JAVACMD=$( cygpath --unix "$JAVACMD" )
# Now convert the arguments - kludge to limit ourselves to /bin/sh
for arg do
if
case $arg in #(
-*) false ;; # don't mess with options #(
/?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath
[ -e "$t" ] ;; #(
*) false ;;
esac
then
arg=$( cygpath --path --ignore --mixed "$arg" )
fi
# Roll the args list around exactly as many times as the number of
# args, so each arg winds up back in the position where it started, but
# possibly modified.
#
# NB: a `for` loop captures its iteration list before it begins, so
# changing the positional parameters here affects neither the number of
# iterations, nor the values presented in `arg`.
shift # remove old arg
set -- "$@" "$arg" # push replacement arg
done
fi
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
# Collect all arguments for the java command:
# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
# and any embedded shellness will be escaped.
# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
# treated as '${Hostname}' itself on the command line.
set -- \
"-Dorg.gradle.appname=$APP_BASE_NAME" \
-classpath "$CLASSPATH" \
org.gradle.wrapper.GradleWrapperMain \
"$@"
# Stop when "xargs" is not available.
if ! command -v xargs >/dev/null 2>&1
then
die "xargs is not available"
fi
# Use "xargs" to parse quoted args.
#
# With -n1 it outputs one arg per line, with the quotes and backslashes removed.
#
# In Bash we could simply go:
#
# readarray ARGS < <( xargs -n1 <<<"$var" ) &&
# set -- "${ARGS[@]}" "$@"
#
# but POSIX shell has neither arrays nor command substitution, so instead we
# post-process each arg (as a line of input to sed) to backslash-escape any
# character that might be a shell metacharacter, then use eval to reverse
# that process (while maintaining the separation between arguments), and wrap
# the whole thing up as a single "set" statement.
#
# This will of course break if any of these variables contains a newline or
# an unmatched quote.
#
eval "set -- $(
printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" |
xargs -n1 |
sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' |
tr '\n' ' '
)" '"$@"'
exec "$JAVACMD" "$@"

92
kcsc-opensearch/gradlew.bat vendored Normal file
View File

@ -0,0 +1,92 @@
@rem
@rem Copyright 2015 the original author or authors.
@rem
@rem Licensed under the Apache License, Version 2.0 (the "License");
@rem you may not use this file except in compliance with the License.
@rem You may obtain a copy of the License at
@rem
@rem https://www.apache.org/licenses/LICENSE-2.0
@rem
@rem Unless required by applicable law or agreed to in writing, software
@rem distributed under the License is distributed on an "AS IS" BASIS,
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@rem See the License for the specific language governing permissions and
@rem limitations under the License.
@rem
@if "%DEBUG%"=="" @echo off
@rem ##########################################################################
@rem
@rem Gradle startup script for Windows
@rem
@rem ##########################################################################
@rem Set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" setlocal
set DIRNAME=%~dp0
if "%DIRNAME%"=="" set DIRNAME=.
@rem This is normally unused
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%
@rem Resolve any "." and ".." in APP_HOME to make it shorter.
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome
set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if %ERRORLEVEL% equ 0 goto execute
echo. 1>&2
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
echo. 1>&2
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
echo location of your Java installation. 1>&2
goto fail
:findJavaFromJavaHome
set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
if exist "%JAVA_EXE%" goto execute
echo. 1>&2
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
echo. 1>&2
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
echo location of your Java installation. 1>&2
goto fail
:execute
@rem Setup the command line
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
@rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
:end
@rem End local scope for the variables with windows NT shell
if %ERRORLEVEL% equ 0 goto mainEnd
:fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
set EXIT_CODE=%ERRORLEVEL%
if %EXIT_CODE% equ 0 set EXIT_CODE=1
if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
exit /b %EXIT_CODE%
:mainEnd
if "%OS%"=="Windows_NT" endlocal
:omega

View File

@ -0,0 +1 @@
rootProject.name = 'kcsc-opensearch'

View File

@ -0,0 +1,16 @@
package com.dbnt.kcscopensearch;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.data.elasticsearch.ElasticsearchDataAutoConfiguration;
import org.springframework.scheduling.annotation.EnableScheduling;
@EnableScheduling
@SpringBootApplication(exclude = ElasticsearchDataAutoConfiguration.class)
public class KcscOpensearchApplication {
public static void main(String[] args) {
SpringApplication.run(KcscOpensearchApplication.class, args);
}
}

View File

@ -0,0 +1,61 @@
package com.dbnt.kcscopensearch.config;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.jdbc.DataSourceBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.orm.jpa.JpaTransactionManager;
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter;
import org.springframework.transaction.PlatformTransactionManager;
import javax.sql.DataSource;
import java.util.HashMap;
@Configuration
@EnableJpaRepositories(
basePackages = "com.dbnt.kcscopensearch.kcsc.**.repository",
entityManagerFactoryRef = "kcscEntityManager",
transactionManagerRef = "kcscTransactionManager"
)
@ComponentScan(basePackageClasses = KcscDatabaseConfig.class)
public class KcscDatabaseConfig {
@Bean
public LocalContainerEntityManagerFactoryBean kcscEntityManager(){
LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean();
em.setDataSource(kcscDataSource());
//Entity 패키지 경로
em.setPackagesToScan(new String[] { "com.dbnt.kcscopensearch.kcsc.**.model" });
HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
em.setJpaVendorAdapter(vendorAdapter);
//Hibernate 설정
HashMap<String, Object> properties = new HashMap<>();
properties.put("hibernate.hbm2ddl.auto", "none");
properties.put("hibernate.dialect", "org.hibernate.dialect.PostgreSQLDialect");
em.setJpaPropertyMap(properties);
return em;
}
@Primary
@Bean
@ConfigurationProperties(prefix="spring.datasource-kcsc")
public DataSource kcscDataSource() {
return DataSourceBuilder.create().build();
}
@Primary
@Bean
public PlatformTransactionManager kcscTransactionManager() {
JpaTransactionManager transactionManager = new JpaTransactionManager();
transactionManager.setEntityManagerFactory(kcscEntityManager().getObject());
return transactionManager;
}
}

View File

@ -0,0 +1,43 @@
package com.dbnt.kcscopensearch.config;
import org.apache.http.conn.ssl.TrustSelfSignedStrategy;
import org.apache.http.impl.nio.client.HttpAsyncClientBuilder;
import org.apache.http.ssl.SSLContextBuilder;
import org.opensearch.client.RestClientBuilder;
import org.opensearch.spring.boot.autoconfigure.RestClientBuilderCustomizer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.elasticsearch.repository.config.EnableElasticsearchRepositories;
import java.security.KeyManagementException;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
@Configuration
@EnableElasticsearchRepositories(
basePackages = "com.dbnt.kcscopensearch.opensearch.**.repository"
)
@ComponentScan(basePackageClasses = OpensearchConfig.class)
public class OpensearchConfig {
@Bean
RestClientBuilderCustomizer customizer(){
return new RestClientBuilderCustomizer() {
@Override
public void customize(HttpAsyncClientBuilder builder){
try {
builder.setSSLContext(new SSLContextBuilder()
.loadTrustMaterial(null, new TrustSelfSignedStrategy())
.build());
} catch (final KeyManagementException | NoSuchAlgorithmException | KeyStoreException ex) {
throw new RuntimeException("Failed to initialize SSL Context instance", ex);
}
}
@Override
public void customize(RestClientBuilder builder) {
}
};
}
}

View File

@ -0,0 +1,30 @@
package com.dbnt.kcscopensearch.kcsc.docView.model;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import jakarta.persistence.Table;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.Immutable;
@Data
@Entity
@Immutable
@NoArgsConstructor
@Table(name = "doc_content")
public class DocContentView {
@Id
@Column(name = "content_id")
private Integer contentId;
@Column(name = "kcsc_cd")
private String kcscCd;
@Column(name = "doc_nm")
private String docNm;
@Column(name = "doc_yr")
private String docYr;
@Column(name = "group_title")
private String groupTitle;
@Column(name = "table_content")
private String tableContent;
}

View File

@ -0,0 +1,28 @@
package com.dbnt.kcscopensearch.kcsc.docView.model;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import jakarta.persistence.Table;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.Immutable;
@Data
@Entity
@Immutable
@NoArgsConstructor
@Table(name = "doc_index")
public class DocIndexView {
@Id
@Column(name = "index_id")
private Integer indexId;
@Column(name = "kcsc_cd")
private String kcscCd;
@Column(name = "doc_nm")
private String docNm;
@Column(name = "doc_yr")
private String docYr;
@Column(name = "group_title")
private String groupTitle;
}

View File

@ -0,0 +1,22 @@
package com.dbnt.kcscopensearch.kcsc.docView.model;
import jakarta.persistence.*;
import lombok.*;
import org.hibernate.annotations.Immutable;
@Data
@Entity
@Immutable
@NoArgsConstructor
@Table(name = "doc_title")
public class DocTitleView {
@Id
@Column(name = "title_id")
private Integer titleId;
@Column(name = "kcsc_cd")
private String kcscCd;
@Column(name = "doc_nm")
private String docNm;
@Column(name = "doc_yr")
private String docYr;
}

View File

@ -0,0 +1,10 @@
package com.dbnt.kcscopensearch.kcsc.docView.repository;
import com.dbnt.kcscopensearch.kcsc.docView.model.DocContentView;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
@Repository
public interface DocContentViewRepository extends JpaRepository<DocContentView, Integer> {
}

View File

@ -0,0 +1,10 @@
package com.dbnt.kcscopensearch.kcsc.docView.repository;
import com.dbnt.kcscopensearch.kcsc.docView.model.DocIndexView;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
@Repository
public interface DocIndexViewRepository extends JpaRepository<DocIndexView, Integer> {
}

View File

@ -0,0 +1,10 @@
package com.dbnt.kcscopensearch.kcsc.docView.repository;
import com.dbnt.kcscopensearch.kcsc.docView.model.DocTitleView;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
@Repository
public interface DocTitleViewRepository extends JpaRepository<DocTitleView, Integer> {
}

View File

@ -0,0 +1,42 @@
package com.dbnt.kcscopensearch.kcsc.docView.service;
import com.dbnt.kcscopensearch.kcsc.docView.model.DocContentView;
import com.dbnt.kcscopensearch.kcsc.docView.model.DocIndexView;
import com.dbnt.kcscopensearch.kcsc.docView.model.DocTitleView;
import com.dbnt.kcscopensearch.kcsc.docView.repository.DocContentViewRepository;
import com.dbnt.kcscopensearch.kcsc.docView.repository.DocIndexViewRepository;
import com.dbnt.kcscopensearch.kcsc.docView.repository.DocTitleViewRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Service
@RequiredArgsConstructor
public class DocViewService {
private final DocTitleViewRepository titleRepository;
private final DocIndexViewRepository indexRepository;
private final DocContentViewRepository contentRepository;
public Map<String, List<?>> selectAllView(){
Map<String, List<?>> viewDataMap = new HashMap<>();
viewDataMap.put("docTitle", titleRepository.findAll());
viewDataMap.put("docIndex", indexRepository.findAll());
viewDataMap.put("docContent", contentRepository.findAll());
return viewDataMap;
}
public List<DocTitleView> selectAllDocTitle(){
return titleRepository.findAll();
}
public List<DocIndexView> selectAllDocIndex(){
return indexRepository.findAll();
}
public List<DocContentView> selectAllDocContent(){
return contentRepository.findAll();
}
}

View File

@ -0,0 +1,61 @@
package com.dbnt.kcscopensearch.kcsc.tnDocumentGroup.model;
import jakarta.persistence.*;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.springframework.format.annotation.DateTimeFormat;
import java.time.LocalDateTime;
@Getter
@Setter
@Entity
@NoArgsConstructor
@DynamicInsert
@DynamicUpdate
@Table(name = "tn_document_group")
public class TnDocumentGroup {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "group_seq")
private Integer groupSeq;
@Column(name = "group_full_cd")
private String groupFullCd;
@Column(name = "kcsc_cd")
private String kcscCd;
@Column(name = "group_cur_cd")
private String groupCurCd;
@Column(name = "group_nm")
private String groupNm;
@Column(name = "group_type")
private String groupType;
@Column(name = "item_cd")
private String itemCd;
@Column(name = "doc_type")
private Integer docType;
@Column(name = "doc_level")
private Integer docLevel;
@Column(name = "doc_order")
private Integer docOrder;
@Column(name = "parent_group_seq")
private Integer parentGroupSeq;
@Column(name = "rvsn_remark")
private String rvsnRemark;
@Column(name = "frst_crt_id")
private String frstCrtId;
@Column(name = "frst_crt_dt")
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private LocalDateTime frstCrtDt;
@Column(name = "last_chg_id")
private String lastChgId;
@Column(name = "last_chg_dt")
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private LocalDateTime lastChgDt;
@Column(name = "use_yn")
private String useYn;
@Column(name = "old_seq")
private Integer oldSeq;
}

View File

@ -0,0 +1,16 @@
package com.dbnt.kcscopensearch.kcsc.tnDocumentGroup.repository;
import com.dbnt.kcscopensearch.kcsc.tnDocumentGroup.model.TnDocumentGroup;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
import java.util.List;
@Repository
public interface TnDocumentGroupRepository extends JpaRepository<TnDocumentGroup, Integer> {
Integer countBy();
List<TnDocumentGroup> findByOrderByGroupSeqAsc(Pageable pageable);
}

View File

@ -0,0 +1,27 @@
package com.dbnt.kcscopensearch.kcsc.tnDocumentGroup.service;
import com.dbnt.kcscopensearch.kcsc.tnDocumentGroup.repository.TnDocumentGroupRepository;
import com.dbnt.kcscopensearch.kcsc.tnDocumentGroup.model.TnDocumentGroup;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
@RequiredArgsConstructor
public class TnDocumentGroupService {
private final TnDocumentGroupRepository tnDocumentGroupRepository;
public List<TnDocumentGroup> selectAll(){
/*List<TnDocumentGroup> documentGroupList = new ArrayList<>();
Integer totalCnt = tnDocumentGroupRepository.countBy();
Integer pageCnt = 0;
while (pageCnt < totalCnt){
List<TnDocumentGroup> temp = tnDocumentGroupRepository.findByOrderByGroupSeqAsc(PageRequest.of(pageCnt, pageCnt+100));
documentGroupList.addAll(temp);
pageCnt += 100;
}
return documentGroupList;*/
return tnDocumentGroupRepository.findAll();
}
}

View File

@ -0,0 +1,34 @@
package com.dbnt.kcscopensearch.opensearch.docSearch;
import com.dbnt.kcscopensearch.opensearch.docSearch.model.DocContent;
import com.dbnt.kcscopensearch.opensearch.docSearch.model.DocIndex;
import com.dbnt.kcscopensearch.opensearch.docSearch.model.DocTitle;
import com.dbnt.kcscopensearch.opensearch.docSearch.service.DocSearchService;
import lombok.RequiredArgsConstructor;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
@RestController
@RequiredArgsConstructor
@RequestMapping("/doc-search")
public class DocSearchController {
private final DocSearchService docSearchService;
@GetMapping(value="/doc-title", produces = MediaType.APPLICATION_JSON_VALUE)
public List<DocTitle> searchTitle (@RequestParam(value="searchText", required = true) String text){
return docSearchService.selectDocTitle(text);
}
@GetMapping(value="/doc-index", produces = MediaType.APPLICATION_JSON_VALUE)
public List<DocIndex> searchIndex (@RequestParam(value="searchText", required = true) String text){
return docSearchService.selectDocIndex(text);
}
@GetMapping(value="/doc-content", produces = MediaType.APPLICATION_JSON_VALUE)
public List<DocContent> searchContent (@RequestParam(value="searchText", required = true) String text){
return docSearchService.selectDocContent(text);
}
}

View File

@ -0,0 +1,39 @@
package com.dbnt.kcscopensearch.opensearch.docSearch.model;
import com.dbnt.kcscopensearch.kcsc.docView.model.DocContentView;
import jakarta.persistence.Id;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldType;
@Getter
@Setter
@NoArgsConstructor
@Document(indexName = "doc_content")
public class DocContent {
@Id
private Integer id;
@Field(type = FieldType.Text, name = "kcsc_cd")
private String kcscCd;
@Field(type = FieldType.Text, name = "doc_nm")
private String docNm;
@Field(type = FieldType.Text, name = "doc_yr")
private String docYr;
@Field(type = FieldType.Text, name = "group_title")
private String groupTitle;
@Field(type = FieldType.Text, name = "table_content")
private String tableContent;
public DocContent(DocContentView view){
this.id = view.getContentId();
this.kcscCd = view.getKcscCd();
this.docNm = view.getDocNm();
this.docYr = view.getDocYr();
this.groupTitle = view.getGroupTitle();
this.tableContent = view.getTableContent();
}
}

View File

@ -0,0 +1,36 @@
package com.dbnt.kcscopensearch.opensearch.docSearch.model;
import com.dbnt.kcscopensearch.kcsc.docView.model.DocIndexView;
import jakarta.persistence.Id;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldType;
@Getter
@Setter
@NoArgsConstructor
@Document(indexName = "doc_index")
public class DocIndex {
@Id
private Integer id;
@Field(type = FieldType.Text, name = "kcsc_cd")
private String kcscCd;
@Field(type = FieldType.Text, name = "doc_nm")
private String docNm;
@Field(type = FieldType.Text, name = "doc_yr")
private String docYr;
@Field(type = FieldType.Text, name = "group_title")
private String groupTitle;
public DocIndex(DocIndexView view){
this.id = view.getIndexId();
this.kcscCd = view.getKcscCd();
this.docNm = view.getDocNm();
this.docYr = view.getDocYr();
this.groupTitle = view.getGroupTitle();
}
}

View File

@ -0,0 +1,33 @@
package com.dbnt.kcscopensearch.opensearch.docSearch.model;
import com.dbnt.kcscopensearch.kcsc.docView.model.DocTitleView;
import jakarta.persistence.*;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldType;
@Getter
@Setter
@NoArgsConstructor
@Document(indexName = "doc_title")
public class DocTitle {
@Id
private Integer id;
@Field(type = FieldType.Text, name = "kcsc_cd")
private String kcscCd;
@Field(type = FieldType.Text, name = "doc_nm")
private String docNm;
@Field(type = FieldType.Text, name = "doc_yr")
private String docYr;
public DocTitle(DocTitleView view){
this.id= view.getTitleId();
this.kcscCd = view.getKcscCd();
this.docNm = view.getDocNm();
this.docYr = view.getDocYr();
}
}

View File

@ -0,0 +1,13 @@
package com.dbnt.kcscopensearch.opensearch.docSearch.repository;
import com.dbnt.kcscopensearch.opensearch.docSearch.model.DocContent;
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
import org.springframework.stereotype.Repository;
import java.util.List;
@Repository
public interface DocContentRepository extends ElasticsearchRepository<DocContent, Integer> {
List<DocContent> findByTableContentContains(String text);
}

View File

@ -0,0 +1,13 @@
package com.dbnt.kcscopensearch.opensearch.docSearch.repository;
import com.dbnt.kcscopensearch.opensearch.docSearch.model.DocIndex;
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
import org.springframework.stereotype.Repository;
import java.util.List;
@Repository
public interface DocIndexRepository extends ElasticsearchRepository<DocIndex, Integer> {
List<DocIndex> findByGroupTitleContains(String text);
}

View File

@ -0,0 +1,13 @@
package com.dbnt.kcscopensearch.opensearch.docSearch.repository;
import com.dbnt.kcscopensearch.opensearch.docSearch.model.DocTitle;
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
import org.springframework.stereotype.Repository;
import java.util.List;
@Repository
public interface DocTitleRepository extends ElasticsearchRepository<DocTitle, Integer> {
List<DocTitle> findByDocNmContains(String text);
}

View File

@ -0,0 +1,136 @@
package com.dbnt.kcscopensearch.opensearch.docSearch.service;
import com.dbnt.kcscopensearch.opensearch.docSearch.model.DocContent;
import com.dbnt.kcscopensearch.opensearch.docSearch.model.DocIndex;
import com.dbnt.kcscopensearch.opensearch.docSearch.model.DocTitle;
import com.dbnt.kcscopensearch.opensearch.docSearch.repository.DocContentRepository;
import com.dbnt.kcscopensearch.opensearch.docSearch.repository.DocIndexRepository;
import com.dbnt.kcscopensearch.opensearch.docSearch.repository.DocTitleRepository;
import lombok.RequiredArgsConstructor;
import org.slf4j.LoggerFactory;
import org.slf4j.Logger;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
@Service
@RequiredArgsConstructor
public class DocSearchService {
private final DocTitleRepository titleRepository;
private final DocIndexRepository indexRepository;
private final DocContentRepository contentRepository;
private final Logger log = LoggerFactory.getLogger(this.getClass().getSimpleName());
@Transactional
public void save(Map<String, List<?>> indexingDataMap){
Iterator<String> keys = indexingDataMap.keySet().iterator();
while(keys.hasNext()) {
int i = 0;
String key = keys.next();
List<?> dataList = indexingDataMap.get(key);
if (!dataList.isEmpty()) {
switch (key) {
case "docTitle":
List<DocTitle> titleList = (List<DocTitle>) dataList;
while (i<=titleList.size()){
int endNum = i+1000;
if(endNum>titleList.size()){
endNum = titleList.size();
}
titleRepository.saveAll(titleList.subList(i, endNum));
i+=1000;
}
break;
case "docIndex":
List<DocIndex> indexList = (List<DocIndex>) dataList;
while (i<=indexList.size()){
int endNum = i+1000;
if(endNum>indexList.size()){
endNum = indexList.size();
}
indexRepository.saveAll(indexList.subList(i, endNum));
i+=1000;
}
break;
case "docContent":
List<DocContent> contentList = (List<DocContent>) dataList;
while (i<=contentList.size()){
int endNum = i+1000;
if(endNum>contentList.size()){
endNum = contentList.size();
}
contentRepository.saveAll(contentList.subList(i, endNum));
i+=1000;
}
break;
}
}
}
System.out.println("indexing end");
}
@Transactional
public void saveDocTitle(List<DocTitle> titleList) {
log.info("title indexing start listSize: "+titleList.size());
int i = 0;
while (i<=titleList.size()){
int endNum = i+1000;
if(endNum>titleList.size()){
endNum = titleList.size();
}
log.info("startNUm: "+i+" , endNum: "+endNum);
titleRepository.saveAll(titleList.subList(i, endNum));
i+=1000;
}
log.info("titleIndexing end");
}
@Transactional
public void saveDocIndex(List<DocIndex> indexList) {
log.info("index indexing start listSize: "+indexList.size());
int i = 0;
while (i<=indexList.size()){
int endNum = i+1000;
if(endNum>indexList.size()){
endNum = indexList.size();
}
log.info("startNUm: "+i+" , endNum: "+endNum);
indexRepository.saveAll(indexList.subList(i, endNum));
i+=1000;
}
log.info("indexIndexing end");
}
@Transactional
public void saveDocContent(List<DocContent> contentList) {
log.info("content indexing start listSize: "+contentList.size());
int i = 0;
while (i<=contentList.size()){
int endNum = i+1000;
if(endNum>contentList.size()){
endNum = contentList.size();
}
log.info("startNUm: "+i+" , endNum: "+endNum);
contentRepository.saveAll(contentList.subList(i, endNum));
i+=1000;
}
log.info("contentIndexing end");
}
public List<DocTitle> selectDocTitle(String text) {
return titleRepository.findByDocNmContains(text);
}
public List<DocIndex> selectDocIndex(String text){
return indexRepository.findByGroupTitleContains(text);
}
public List<DocContent> selectDocContent(String text){
return contentRepository.findByTableContentContains(text);
}
}

View File

@ -0,0 +1,26 @@
package com.dbnt.kcscopensearch.opensearch.documentGroup;
import com.dbnt.kcscopensearch.opensearch.documentGroup.model.DocumentGroup;
import com.dbnt.kcscopensearch.opensearch.documentGroup.service.DocumentGroupService;
import lombok.RequiredArgsConstructor;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
@RestController
@RequiredArgsConstructor
@RequestMapping("/documentGroup")
public class DocumentGroupController {
private final DocumentGroupService documentGroupService;
/*@GetMapping(value = "/search", produces = MediaType.APPLICATION_JSON_VALUE)
public List<DocumentGroup> search(@RequestParam(value="groupNm", required = true) String groupNm){
return documentGroupService.search(groupNm);
}*/
}

View File

@ -0,0 +1,87 @@
package com.dbnt.kcscopensearch.opensearch.documentGroup.model;
import com.dbnt.kcscopensearch.kcsc.tnDocumentGroup.model.TnDocumentGroup;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.springframework.data.annotation.Id;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldType;
import org.springframework.format.annotation.DateTimeFormat;
import java.time.LocalDateTime;
@Getter
@Setter
@NoArgsConstructor
@Document(indexName = "document_group")
public class DocumentGroup {
@Id
private Integer id;
@Field(type = FieldType.Integer, name = "group_seq")
private Integer groupSeq;
@Field(type = FieldType.Text, name = "group_full_cd")
private String groupFullCd;
@Field(type = FieldType.Text, name = "kcsc_cd")
private String kcscCd;
@Field(type = FieldType.Text, name = "group_cur_cd")
private String groupCurCd;
@Field(type = FieldType.Text, name = "group_nm")
private String groupNm;
@Field(type = FieldType.Text, name = "group_type")
private String groupType;
@Field(type = FieldType.Text, name = "item_cd")
private String itemCd;
@Field(type = FieldType.Integer, name = "doc_type")
private Integer docType;
@Field(type = FieldType.Integer, name = "doc_level")
private Integer docLevel;
@Field(type = FieldType.Integer, name = "doc_order")
private Integer docOrder;
@Field(type = FieldType.Integer, name = "parent_group_seq")
private Integer parentGroupSeq;
@Field(type = FieldType.Text, name = "rvsn_remark")
private String rvsnRemark;
@Field(type = FieldType.Text, name = "frst_crt_id")
private String frstCrtId;
@Field(type = FieldType.Date, name = "frst_crt_dt")
@DateTimeFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS")
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS", timezone = "Asia/Seoul")
private LocalDateTime frstCrtDt;
@Field(type = FieldType.Text, name = "last_chg_id")
private String lastChgId;
@Field(type = FieldType.Date, name = "last_chg_dt")
@DateTimeFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS")
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS", timezone = "Asia/Seoul")
private LocalDateTime lastChgDt;
@Field(type = FieldType.Text, name = "use_yn")
private String useYn;
@Field(type = FieldType.Integer, name = "old_seq")
private Integer oldSeq;
public DocumentGroup(TnDocumentGroup documentGroup){
this.id = documentGroup.getGroupSeq();
this.groupSeq = documentGroup.getGroupSeq();
this.groupFullCd = documentGroup.getGroupCurCd();
this.kcscCd = documentGroup.getKcscCd();
this.groupCurCd = documentGroup.getGroupCurCd();
this.groupNm = documentGroup.getGroupNm();
this.groupType = documentGroup.getGroupNm();
this.itemCd = documentGroup.getItemCd();
this.docType = documentGroup.getDocType();
this.docLevel = documentGroup.getDocLevel();
this.docOrder = documentGroup.getDocOrder();
this.parentGroupSeq = documentGroup.getParentGroupSeq();
this.rvsnRemark = documentGroup.getRvsnRemark();
this.frstCrtId = documentGroup.getFrstCrtId();
this.frstCrtDt = documentGroup.getFrstCrtDt();
this.lastChgId = documentGroup.getLastChgId();
this.lastChgDt = documentGroup.getLastChgDt();
this.useYn = documentGroup.getUseYn();
this.oldSeq = documentGroup.getOldSeq();
}
}

View File

@ -0,0 +1,13 @@
package com.dbnt.kcscopensearch.opensearch.documentGroup.repository;
import com.dbnt.kcscopensearch.opensearch.documentGroup.model.DocumentGroup;
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
import org.springframework.stereotype.Repository;
import java.util.List;
@Repository
public interface DocumentGroupRepository extends ElasticsearchRepository<DocumentGroup, Integer> {
List<DocumentGroup> findByGroupNmLike(String groupNm);
}

View File

@ -0,0 +1,25 @@
package com.dbnt.kcscopensearch.opensearch.documentGroup.service;
import com.dbnt.kcscopensearch.opensearch.documentGroup.model.DocumentGroup;
import com.dbnt.kcscopensearch.opensearch.documentGroup.repository.DocumentGroupRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
@Service
@RequiredArgsConstructor
public class DocumentGroupService {
private final DocumentGroupRepository documentGroupRepository;
public List<DocumentGroup> search(String groupNm){
return documentGroupRepository.findByGroupNmLike(groupNm);
}
@Transactional
public void save(List<DocumentGroup> documentGroupList) {
documentGroupRepository.saveAll(documentGroupList);
}
}

View File

@ -0,0 +1,91 @@
package com.dbnt.kcscopensearch.scheduler;
import com.dbnt.kcscopensearch.kcsc.docView.model.DocContentView;
import com.dbnt.kcscopensearch.kcsc.docView.model.DocIndexView;
import com.dbnt.kcscopensearch.kcsc.docView.model.DocTitleView;
import com.dbnt.kcscopensearch.opensearch.docSearch.model.DocContent;
import com.dbnt.kcscopensearch.opensearch.docSearch.model.DocIndex;
import com.dbnt.kcscopensearch.opensearch.docSearch.model.DocTitle;
import com.dbnt.kcscopensearch.opensearch.docSearch.service.DocSearchService;
import com.dbnt.kcscopensearch.kcsc.docView.service.DocViewService;
import lombok.RequiredArgsConstructor;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import java.util.*;
@Component
@RequiredArgsConstructor
public class IndexingScheduler {
private final DocViewService docViewService;
private final DocSearchService docSearchService;
@Scheduled(cron = "40 18 23 * * *")
public void viewIndexing(){
Map<String, List<?>> viewDataMap = docViewService.selectAllView();
Map<String, List<?>> indexingDataMap = new HashMap<>();
Iterator<String> keys = viewDataMap.keySet().iterator();
while(keys.hasNext()){
String key = keys.next();
List<?> viewDataList = viewDataMap.get(key);
if(!viewDataList.isEmpty()){
switch (key){
case "docTitle":
List<DocTitle> titleList = new ArrayList<>();
for(Object obj: viewDataList){
titleList.add(new DocTitle((DocTitleView) obj));
}
indexingDataMap.put("docTitle", titleList);
break;
case "docIndex":
List<DocIndex> indexList = new ArrayList<>();
for(Object obj: viewDataList){
indexList.add(new DocIndex((DocIndexView) obj));
}
indexingDataMap.put("docIndex", indexList);
break;
case "docContent":
List<DocContent> contentList = new ArrayList<>();
for(Object obj: viewDataList){
contentList.add(new DocContent((DocContentView) obj));
}
indexingDataMap.put("docContent", contentList);
break;
}
}
}
docSearchService.save(indexingDataMap);
//docSearchService.save(indexingDataMap);
}
@Scheduled(cron = "40 20 23 * * *")
public void titleIndexing(){
List<DocTitleView> titleViewList = docViewService.selectAllDocTitle();
List<DocTitle> titleList = new ArrayList<>();
for(DocTitleView view: titleViewList){
titleList.add(new DocTitle(view));
}
docSearchService.saveDocTitle(titleList);
}
@Scheduled(cron = "40 21 23 * * *")
public void indexIndexing(){
List<DocIndexView> indexViewList = docViewService.selectAllDocIndex();
List<DocIndex> indexList = new ArrayList<>();
for(DocIndexView view: indexViewList){
indexList.add(new DocIndex(view));
}
docSearchService.saveDocIndex(indexList);
}
@Scheduled(cron = "40 25 23 * * *")
public void contentIndexing(){
List<DocContentView> contentViewList = docViewService.selectAllDocContent();
List<DocContent> contentList = new ArrayList<>();
for(DocContentView view: contentViewList){
contentList.add(new DocContent(view));
}
docSearchService.saveDocContent(contentList);
}
}

View File

@ -0,0 +1,16 @@
spring.application.name=kcsc-opensearch
opensearch.uris=https://localhost:9200
opensearch.username=admin
opensearch.password=kpbP7ECsaTlgvfmaGNBtORH75QHf7TmJhHZdW7Z7
spring.datasource-kcsc.driverClassName=org.postgresql.Driver
spring.datasource-kcsc.jdbcUrl=jdbc:postgresql://118.219.150.34:50503/kcsc
spring.datasource-kcsc.username=dbnt0031
spring.datasource-kcsc.password=dbnt0928!
spring.jpa.show-sql=true
spring.jpa.generate-ddl=false
spring.jpa.hibernate.naming.physical-strategy = org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
spring.jackson.serialization.INDENT_OUTPUT=true