├── .gitignore ├── LICENSE ├── README.md ├── build.gradle ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── src ├── main ├── java │ └── paasta │ │ └── delivery │ │ └── pipeline │ │ └── common │ │ └── api │ │ ├── Application.java │ │ ├── common │ │ ├── AES256Util.java │ │ ├── AspectService.java │ │ ├── CommonService.java │ │ ├── Constants.java │ │ ├── ListRequest.java │ │ └── RestTemplateService.java │ │ ├── config │ │ ├── DataSourceConfig.java │ │ ├── RestTemplateConfig.java │ │ ├── ServletConfig.java │ │ └── WebMvcConfig.java │ │ ├── domain │ │ └── common │ │ │ ├── authority │ │ │ ├── Authority.java │ │ │ ├── AuthorityController.java │ │ │ ├── AuthorityRepository.java │ │ │ ├── AuthorityService.java │ │ │ ├── AuthorizeController.java │ │ │ ├── GrantedAuthority.java │ │ │ ├── GrantedAuthorityRepository.java │ │ │ └── GrantedAuthorityService.java │ │ │ ├── cf │ │ │ ├── info │ │ │ │ ├── CfInfo.java │ │ │ │ ├── CfInfoController.java │ │ │ │ ├── CfInfoList.java │ │ │ │ ├── CfInfoRepository.java │ │ │ │ └── CfInfoService.java │ │ │ └── url │ │ │ │ ├── CfUrl.java │ │ │ │ ├── CfUrlController.java │ │ │ │ ├── CfUrlRepository.java │ │ │ │ └── CfUrlService.java │ │ │ ├── code │ │ │ ├── Code.java │ │ │ ├── CodeController.java │ │ │ ├── CodeRepository.java │ │ │ └── CodeService.java │ │ │ ├── file │ │ │ ├── FileController.java │ │ │ ├── FileInfo.java │ │ │ ├── FileInfoRepository.java │ │ │ └── FileService.java │ │ │ ├── init │ │ │ └── CiInfoController.java │ │ │ ├── job │ │ │ ├── Job.java │ │ │ ├── JobController.java │ │ │ ├── JobRepository.java │ │ │ ├── JobService.java │ │ │ └── history │ │ │ │ ├── JobHistory.java │ │ │ │ ├── JobHistoryController.java │ │ │ │ ├── JobHistoryRepository.java │ │ │ │ └── JobHistoryService.java │ │ │ ├── pipeline │ │ │ ├── Pipeline.java │ │ │ ├── PipelineController.java │ │ │ ├── PipelineList.java │ │ │ ├── PipelineRepository.java │ │ │ └── PipelineService.java │ │ │ ├── project │ │ │ ├── Project.java │ │ │ ├── ProjectController.java │ │ │ ├── ProjectRepository.java │ │ │ └── ProjectService.java │ │ │ ├── qualityGate │ │ │ ├── QualityGate.java │ │ │ ├── QualityGateController.java │ │ │ ├── QualityGateRepository.java │ │ │ └── QualityGateService.java │ │ │ ├── qualityProfile │ │ │ ├── QualityProfile.java │ │ │ ├── QualityProfileController.java │ │ │ ├── QualityProfileRepository.java │ │ │ └── QualityProfileService.java │ │ │ ├── serviceInstance │ │ │ ├── CiInfo.java │ │ │ ├── CiInfoRepository.java │ │ │ ├── CiInfoService.java │ │ │ ├── InstanceUse.java │ │ │ ├── InstanceUseController.java │ │ │ ├── InstanceUseList.java │ │ │ ├── InstanceUseRepository.java │ │ │ ├── InstanceUseService.java │ │ │ ├── ServiceInstances.java │ │ │ ├── ServiceInstancesController.java │ │ │ ├── ServiceInstancesRepository.java │ │ │ └── ServiceInstancesService.java │ │ │ └── user │ │ │ ├── User.java │ │ │ ├── UserController.java │ │ │ ├── UserList.java │ │ │ ├── UserRepository.java │ │ │ ├── UserService.java │ │ │ └── UserSpecifications.java │ │ └── exception │ │ └── CustomException.java └── resources │ ├── application.yml │ └── logback-spring.xml └── test └── java └── paasta └── delivery └── pipeline └── common └── api └── domain └── common ├── authority ├── AuthorityServiceTest.java └── GrantedAuthorityServiceTest.java ├── cf ├── info │ └── CfInfoServiceTest.java └── url │ └── CfUrlServiceTest.java ├── file └── FileServiceTest.java ├── job ├── JobServiceTest.java └── history │ └── JobHistoryServiceTest.java ├── pipeline └── PipelineServiceTest.java ├── project └── ProjectServiceTest.java ├── qualityGate └── QualityGateServiceTest.java ├── qualityProfile └── QualityProfileServiceTest.java ├── serviceInstance ├── CiInfoServiceTest.java ├── InstanceUseServiceTest.java └── ServiceInstancesServiceTest.java └── user └── UserServiceTest.java /.gitignore: -------------------------------------------------------------------------------- 1 | /logs/ 2 | *.log 3 | .gradle 4 | /build/ 5 | /out/ 6 | !gradle/wrapper/gradle-wrapper.jar 7 | 8 | ### STS ### 9 | .apt_generated 10 | .classpath 11 | .factorypath 12 | .project 13 | .settings 14 | .springBeans 15 | 16 | ### IntelliJ IDEA ### 17 | .idea 18 | *.iws 19 | *.iml 20 | *.ipr 21 | 22 | ### NetBeans ### 23 | nbproject/private/ 24 | build/ 25 | nbbuild/ 26 | dist/ 27 | nbdist/ 28 | .nb-gradle/ -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## Common API 2 | 3 | ### 1. 개요 4 | 5 | 배포파이프라인에서 필요한 공통 기능과 DBMS 메타 데이터 제어에 필요한 REST API를 제공한다. 6 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | ext { 3 | springBootVersion = '1.5.3.RELEASE' 4 | } 5 | repositories { 6 | mavenCentral() 7 | } 8 | dependencies { 9 | classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}") 10 | } 11 | } 12 | 13 | apply plugin: 'java' 14 | apply plugin: 'idea' 15 | apply plugin: 'org.springframework.boot' 16 | //apply plugin: 'war' 17 | 18 | ext { 19 | springBootVersion = '1.5.3.RELEASE' 20 | mysqlConnectorJavaVersion = '6.0.6' 21 | commonsCodecVersion = '1.10' 22 | appVersion = "1.0.3" 23 | } 24 | 25 | jar { 26 | baseName = "delivery-pipeline-common-api-${appVersion}" 27 | } 28 | 29 | sourceCompatibility = 1.8 30 | targetCompatibility = 1.8 31 | 32 | repositories { 33 | mavenCentral() 34 | } 35 | 36 | dependencies { 37 | compile("org.springframework.boot:spring-boot-starter-web:${springBootVersion}") 38 | compile("org.springframework.boot:spring-boot-starter-aop:${springBootVersion}") 39 | compile("org.springframework.boot:spring-boot-starter-jdbc:${springBootVersion}") 40 | compile("org.springframework.boot:spring-boot-starter-data-jpa:${springBootVersion}") 41 | compile("commons-codec:commons-codec:${commonsCodecVersion}") 42 | 43 | //runtime("mysql:mysql-connector-java:${mysqlConnectorJavaVersion}") 44 | runtime("org.mariadb.jdbc:mariadb-java-client:2.2.6") 45 | testCompile("org.springframework.boot:spring-boot-starter-test:${springBootVersion}") 46 | } 47 | 48 | apply plugin: 'jacoco' 49 | 50 | jacoco { 51 | toolVersion = "0.7.9+" 52 | } 53 | 54 | test { 55 | ignoreFailures=true 56 | jacoco { 57 | destinationFile = file("$buildDir/jacoco/jacoco-overall.exec") 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PaaS-TA/DELIVERY-PIPELINE-COMMON-API/6c6264d3756b8679e7f2b5cd2b9c7d1396a5835a/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | zipStoreBase=GRADLE_USER_HOME 4 | zipStorePath=wrapper/dists 5 | distributionUrl=https\://services.gradle.org/distributions/gradle-3.4.1-bin.zip 6 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Attempt to set APP_HOME 10 | # Resolve links: $0 may be a link 11 | PRG="$0" 12 | # Need this for relative symlinks. 13 | while [ -h "$PRG" ] ; do 14 | ls=`ls -ld "$PRG"` 15 | link=`expr "$ls" : '.*-> \(.*\)$'` 16 | if expr "$link" : '/.*' > /dev/null; then 17 | PRG="$link" 18 | else 19 | PRG=`dirname "$PRG"`"/$link" 20 | fi 21 | done 22 | SAVED="`pwd`" 23 | cd "`dirname \"$PRG\"`/" >/dev/null 24 | APP_HOME="`pwd -P`" 25 | cd "$SAVED" >/dev/null 26 | 27 | APP_NAME="Gradle" 28 | APP_BASE_NAME=`basename "$0"` 29 | 30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 31 | DEFAULT_JVM_OPTS="" 32 | 33 | # Use the maximum available, or set MAX_FD != -1 to use that value. 34 | MAX_FD="maximum" 35 | 36 | warn ( ) { 37 | echo "$*" 38 | } 39 | 40 | die ( ) { 41 | echo 42 | echo "$*" 43 | echo 44 | exit 1 45 | } 46 | 47 | # OS specific support (must be 'true' or 'false'). 48 | cygwin=false 49 | msys=false 50 | darwin=false 51 | nonstop=false 52 | case "`uname`" in 53 | CYGWIN* ) 54 | cygwin=true 55 | ;; 56 | Darwin* ) 57 | darwin=true 58 | ;; 59 | MINGW* ) 60 | msys=true 61 | ;; 62 | NONSTOP* ) 63 | nonstop=true 64 | ;; 65 | esac 66 | 67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 68 | 69 | # Determine the Java command to use to start the JVM. 70 | if [ -n "$JAVA_HOME" ] ; then 71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 72 | # IBM's JDK on AIX uses strange locations for the executables 73 | JAVACMD="$JAVA_HOME/jre/sh/java" 74 | else 75 | JAVACMD="$JAVA_HOME/bin/java" 76 | fi 77 | if [ ! -x "$JAVACMD" ] ; then 78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 79 | 80 | Please set the JAVA_HOME variable in your environment to match the 81 | location of your Java installation." 82 | fi 83 | else 84 | JAVACMD="java" 85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 86 | 87 | Please set the JAVA_HOME variable in your environment to match the 88 | location of your Java installation." 89 | fi 90 | 91 | # Increase the maximum file descriptors if we can. 92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 93 | MAX_FD_LIMIT=`ulimit -H -n` 94 | if [ $? -eq 0 ] ; then 95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 96 | MAX_FD="$MAX_FD_LIMIT" 97 | fi 98 | ulimit -n $MAX_FD 99 | if [ $? -ne 0 ] ; then 100 | warn "Could not set maximum file descriptor limit: $MAX_FD" 101 | fi 102 | else 103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 104 | fi 105 | fi 106 | 107 | # For Darwin, add options to specify how the application appears in the dock 108 | if $darwin; then 109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 110 | fi 111 | 112 | # For Cygwin, switch paths to Windows format before running java 113 | if $cygwin ; then 114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 116 | JAVACMD=`cygpath --unix "$JAVACMD"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a userRepository-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Escape application args 158 | save ( ) { 159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 160 | echo " " 161 | } 162 | APP_ARGS=$(save "$@") 163 | 164 | # Collect all arguments for the java command, following the shell quoting and substitution rules 165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 166 | 167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong 168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then 169 | cd "$(dirname "$0")" 170 | fi 171 | 172 | exec "$JAVACMD" "$@" 173 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | set DIRNAME=%~dp0 12 | if "%DIRNAME%" == "" set DIRNAME=. 13 | set APP_BASE_NAME=%~n0 14 | set APP_HOME=%DIRNAME% 15 | 16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 17 | set DEFAULT_JVM_OPTS= 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | 53 | :win9xME_args 54 | @rem Slurp the command line arguments. 55 | set CMD_LINE_ARGS= 56 | set _SKIP=2 57 | 58 | :win9xME_args_slurp 59 | if "x%~1" == "x" goto execute 60 | 61 | set CMD_LINE_ARGS=%* 62 | 63 | :execute 64 | @rem Setup the command line 65 | 66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 67 | 68 | @rem Execute Gradle 69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 70 | 71 | :end 72 | @rem End local scope for the variables with windows NT shell 73 | if "%ERRORLEVEL%"=="0" goto mainEnd 74 | 75 | :fail 76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 77 | rem the _cmd.exe /c_ return code! 78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 79 | exit /b 1 80 | 81 | :mainEnd 82 | if "%OS%"=="Windows_NT" endlocal 83 | 84 | :omega 85 | -------------------------------------------------------------------------------- /src/main/java/paasta/delivery/pipeline/common/api/Application.java: -------------------------------------------------------------------------------- 1 | package paasta.delivery.pipeline.common.api; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | /** 7 | * The type Application. 8 | */ 9 | @SpringBootApplication 10 | public class Application { 11 | 12 | /** 13 | * The entry point of application. 14 | * 15 | * @param args the input arguments 16 | */ 17 | public static void main(String[] args) { 18 | SpringApplication.run(Application.class, args); 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/paasta/delivery/pipeline/common/api/common/AES256Util.java: -------------------------------------------------------------------------------- 1 | package paasta.delivery.pipeline.common.api.common; 2 | 3 | import org.apache.commons.codec.binary.Base64; 4 | import org.slf4j.Logger; 5 | import org.slf4j.LoggerFactory; 6 | 7 | import javax.crypto.BadPaddingException; 8 | import javax.crypto.Cipher; 9 | import javax.crypto.IllegalBlockSizeException; 10 | import javax.crypto.NoSuchPaddingException; 11 | import javax.crypto.spec.IvParameterSpec; 12 | import javax.crypto.spec.SecretKeySpec; 13 | import java.io.UnsupportedEncodingException; 14 | import java.security.InvalidAlgorithmParameterException; 15 | import java.security.InvalidKeyException; 16 | import java.security.Key; 17 | import java.security.NoSuchAlgorithmException; 18 | 19 | /** 20 | * paastaDeliveryPipelineApi 21 | * paasta.delivery.pipeline.common.api.common 22 | * 23 | * @author REX 24 | * @version 1.0 25 | * @since 7 /27/2017 26 | */ 27 | class AES256Util { 28 | 29 | private static final Logger LOGGER = LoggerFactory.getLogger(AES256Util.class); 30 | private static final String CHAR_SET_NAME = "UTF-8"; 31 | private static final String AES256_KEY = "AES256-KEY-MORE-THAN-16-LETTERS"; 32 | private String ivParameterSpec; 33 | private Key secretKeySpec; 34 | 35 | 36 | /** 37 | * Instantiates a new Aes 256 util. 38 | */ 39 | AES256Util() { 40 | try { 41 | String key = AES256_KEY; 42 | this.ivParameterSpec = key.substring(0, 16); 43 | 44 | byte[] keyBytes = new byte[16]; 45 | byte[] aes256KeyBytes = key.getBytes(CHAR_SET_NAME); 46 | int aes256KeyBytesLength = aes256KeyBytes.length; 47 | 48 | if (aes256KeyBytesLength > keyBytes.length) { 49 | aes256KeyBytesLength = keyBytes.length; 50 | } 51 | 52 | System.arraycopy(aes256KeyBytes, 0, keyBytes, 0, aes256KeyBytesLength); 53 | this.secretKeySpec = new SecretKeySpec(keyBytes, "AES"); 54 | 55 | } catch (UnsupportedEncodingException e) { 56 | LOGGER.error("Exception :: AES256Util :: UnsupportedEncodingException :: {}", e); 57 | } 58 | } 59 | 60 | 61 | /** 62 | * Aes encode string. 63 | * 64 | * @param requestString the request string 65 | * @return the string 66 | */ 67 | String aesEncode(String requestString) { 68 | String resultString = ""; 69 | 70 | try { 71 | Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding"); 72 | cipher.init(Cipher.ENCRYPT_MODE, secretKeySpec, new IvParameterSpec(ivParameterSpec.getBytes())); 73 | byte[] encrypted = cipher.doFinal(requestString.getBytes(CHAR_SET_NAME)); 74 | 75 | resultString = new String(Base64.encodeBase64(encrypted)); 76 | } catch (NoSuchAlgorithmException e) { 77 | LOGGER.error("Exception :: NoSuchAlgorithmException :: {}", e); 78 | } catch (NoSuchPaddingException e) { 79 | LOGGER.error("Exception :: NoSuchPaddingException :: {}", e); 80 | } catch (InvalidAlgorithmParameterException e) { 81 | LOGGER.error("Exception :: InvalidAlgorithmParameterException :: {}", e); 82 | } catch (InvalidKeyException e) { 83 | LOGGER.error("Exception :: InvalidKeyException :: {}", e); 84 | } catch (BadPaddingException e) { 85 | LOGGER.error("Exception :: BadPaddingException :: {}", e); 86 | } catch (UnsupportedEncodingException e) { 87 | LOGGER.error("Exception :: UnsupportedEncodingException :: {}", e); 88 | } catch (IllegalBlockSizeException e) { 89 | LOGGER.error("Exception :: IllegalBlockSizeException :: {}", e); 90 | } 91 | 92 | return resultString; 93 | } 94 | 95 | 96 | /** 97 | * Aes decode string. 98 | * 99 | * @param requestString the request string 100 | * @return the string 101 | */ 102 | String aesDecode(String requestString) { 103 | String resultString = ""; 104 | 105 | try { 106 | Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding"); 107 | cipher.init(Cipher.DECRYPT_MODE, secretKeySpec, new IvParameterSpec(ivParameterSpec.getBytes(CHAR_SET_NAME))); 108 | byte[] decodeBase64Bytes = Base64.decodeBase64(requestString.getBytes()); 109 | 110 | resultString = new String(cipher.doFinal(decodeBase64Bytes), CHAR_SET_NAME); 111 | } catch (NoSuchAlgorithmException e) { 112 | LOGGER.error("Exception :: NoSuchAlgorithmException :: {}", e); 113 | } catch (NoSuchPaddingException e) { 114 | LOGGER.error("Exception :: NoSuchPaddingException :: {}", e); 115 | } catch (InvalidAlgorithmParameterException e) { 116 | LOGGER.error("Exception :: InvalidAlgorithmParameterException :: {}", e); 117 | } catch (InvalidKeyException e) { 118 | LOGGER.error("Exception :: InvalidKeyException :: {}", e); 119 | } catch (BadPaddingException e) { 120 | LOGGER.error("Exception :: BadPaddingException :: {}", e); 121 | } catch (UnsupportedEncodingException e) { 122 | LOGGER.error("Exception :: UnsupportedEncodingException :: {}", e); 123 | } catch (IllegalBlockSizeException e) { 124 | LOGGER.error("Exception :: IllegalBlockSizeException :: {}", e); 125 | } 126 | 127 | return resultString; 128 | } 129 | 130 | } 131 | -------------------------------------------------------------------------------- /src/main/java/paasta/delivery/pipeline/common/api/common/AspectService.java: -------------------------------------------------------------------------------- 1 | package paasta.delivery.pipeline.common.api.common; 2 | 3 | import org.aspectj.lang.JoinPoint; 4 | import org.aspectj.lang.annotation.Aspect; 5 | import org.aspectj.lang.annotation.Before; 6 | import org.slf4j.Logger; 7 | import org.slf4j.LoggerFactory; 8 | import org.springframework.stereotype.Service; 9 | import org.springframework.web.context.request.RequestContextHolder; 10 | import org.springframework.web.context.request.ServletRequestAttributes; 11 | 12 | import javax.servlet.http.HttpServletRequest; 13 | import java.util.Arrays; 14 | import java.util.Enumeration; 15 | 16 | /** 17 | * paastaDeliveryPipelineApi 18 | * paasta.delivery.pipeline.common.api.common 19 | * 20 | * @author REX 21 | * @version 1.0 22 | * @since 5 /10/2017 23 | */ 24 | @Aspect 25 | @Service 26 | public class AspectService { 27 | 28 | private static final Logger LOGGER = LoggerFactory.getLogger(AspectService.class); 29 | 30 | 31 | /** 32 | * On before log service access. 33 | * 34 | * @param joinPoint the join point 35 | */ 36 | @Before("execution(* paasta.delivery..*Service.*(..))") 37 | public void onBeforeLogServiceAccess(JoinPoint joinPoint) { 38 | LOGGER.warn("######## ON BEFORE SERVICE ACCESS :: {}", joinPoint); 39 | } 40 | 41 | 42 | /** 43 | * On before log controller access. 44 | * 45 | * @param joinPoint the join point 46 | */ 47 | @Before("execution(public * paasta.delivery..*Controller.*(..))") 48 | public void onBeforeLogControllerAccess(JoinPoint joinPoint) { 49 | LOGGER.warn("#### ON BEFORE CONTROLLER ACCESS :: {}", joinPoint); 50 | HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest(); 51 | 52 | LOGGER.warn("## Entering in Method: {}", joinPoint.getSignature().getName()); 53 | LOGGER.warn("## Class Name: {}", joinPoint.getSignature().getDeclaringTypeName()); 54 | LOGGER.warn("## Arguments: {}", Arrays.toString(joinPoint.getArgs())); 55 | LOGGER.warn("## Target class: {}", joinPoint.getTarget().getClass().getName()); 56 | 57 | if (null != request) { 58 | LOGGER.warn("## Request Path info: {}", request.getServletPath()); 59 | LOGGER.warn("## Method Type: {}", request.getMethod()); 60 | LOGGER.warn("================================================================================"); 61 | LOGGER.warn("Start Header Section of request"); 62 | Enumeration headerNames = request.getHeaderNames(); 63 | while (headerNames.hasMoreElements()) { 64 | String headerName = (String) headerNames.nextElement(); 65 | String headerValue = request.getHeader(headerName); 66 | LOGGER.warn(" Header Name: {} || Header Value: {}", headerName, headerValue); 67 | } 68 | LOGGER.warn("End Header Section of request"); 69 | LOGGER.warn("================================================================================"); 70 | } 71 | } 72 | 73 | } 74 | -------------------------------------------------------------------------------- /src/main/java/paasta/delivery/pipeline/common/api/common/CommonService.java: -------------------------------------------------------------------------------- 1 | package paasta.delivery.pipeline.common.api.common; 2 | 3 | import org.apache.commons.codec.DecoderException; 4 | import org.apache.commons.codec.EncoderException; 5 | import org.apache.commons.codec.net.URLCodec; 6 | import org.slf4j.Logger; 7 | import org.slf4j.LoggerFactory; 8 | import org.springframework.data.domain.Page; 9 | import org.springframework.stereotype.Service; 10 | 11 | import java.lang.reflect.InvocationTargetException; 12 | import java.lang.reflect.Method; 13 | 14 | /** 15 | * paastaDeliveryPipelineApi 16 | * paasta.delivery.pipeline.common.api.common 17 | * 18 | * @author REX 19 | * @version 1.0 20 | * @since 7 /7/2017 21 | */ 22 | @Service 23 | public class CommonService { 24 | 25 | private static final Logger LOGGER = LoggerFactory.getLogger(CommonService.class); 26 | 27 | 28 | /** 29 | * Sets page info. 30 | * 31 | * @param reqPage the req page 32 | * @param reqObject the req object 33 | * @return the page info 34 | */ 35 | public Object setPageInfo(Page reqPage, Object reqObject) { 36 | Object resultObject = null; 37 | 38 | try { 39 | Class aClass; 40 | 41 | if (reqObject instanceof Class) { 42 | aClass = (Class) reqObject; 43 | resultObject = ((Class) reqObject).newInstance(); 44 | } else { 45 | aClass = reqObject.getClass(); 46 | resultObject = reqObject; 47 | } 48 | 49 | Method methodSetPage = aClass.getMethod("setPage", Integer.TYPE); 50 | Method methodSetSize = aClass.getMethod("setSize", Integer.TYPE); 51 | Method methodSetTotalPages = aClass.getMethod("setTotalPages", Integer.TYPE); 52 | Method methodSetTotalElements = aClass.getMethod("setTotalElements", Long.TYPE); 53 | Method methodSetLast = aClass.getMethod("setLast", Boolean.TYPE); 54 | 55 | methodSetPage.invoke(resultObject, reqPage.getNumber()); 56 | methodSetSize.invoke(resultObject, reqPage.getSize()); 57 | methodSetTotalPages.invoke(resultObject, reqPage.getTotalPages()); 58 | methodSetTotalElements.invoke(resultObject, reqPage.getTotalElements()); 59 | methodSetLast.invoke(resultObject, reqPage.isLast()); 60 | 61 | } catch (NoSuchMethodException e) { 62 | LOGGER.error("NoSuchMethodException :: {}", e); 63 | } catch (IllegalAccessException e1) { 64 | LOGGER.error("IllegalAccessException :: {}", e1); 65 | } catch (InvocationTargetException e2) { 66 | LOGGER.error("InvocationTargetException :: {}", e2); 67 | } catch (InstantiationException e3) { 68 | LOGGER.error("InstantiationException :: {}", e3); 69 | } 70 | 71 | return resultObject; 72 | } 73 | 74 | 75 | /** 76 | * Sets password by aes 256. 77 | * 78 | * @param reqProcess the req process 79 | * @param reqString the req string 80 | * @return the password by aes 256 81 | */ 82 | public String setPasswordByAES256(Enum reqProcess, String reqString) { 83 | String resultString = ""; 84 | 85 | try { 86 | AES256Util aes256 = new AES256Util(); 87 | URLCodec codec = new URLCodec(); 88 | resultString = reqString; 89 | 90 | // ENCODE 91 | if (reqProcess.equals(Constants.AES256Type.ENCODE)) { 92 | resultString = codec.encode(aes256.aesEncode(reqString)); 93 | } 94 | 95 | // DECODE 96 | if (reqProcess.equals(Constants.AES256Type.DECODE)) { 97 | resultString = aes256.aesDecode(codec.decode(reqString)); 98 | } 99 | 100 | } catch (EncoderException e) { 101 | LOGGER.error("Exception :: EncoderException :: {}", e); 102 | } catch (DecoderException e) { 103 | LOGGER.error("Exception :: DecoderException :: {}", e); 104 | } 105 | 106 | return resultString; 107 | } 108 | 109 | } 110 | -------------------------------------------------------------------------------- /src/main/java/paasta/delivery/pipeline/common/api/common/Constants.java: -------------------------------------------------------------------------------- 1 | package paasta.delivery.pipeline.common.api.common; 2 | 3 | /** 4 | * paastaDeliveryPipelineApi 5 | * paasta.delivery.pipeline.common.api.common 6 | * 7 | * @author REX 8 | * @version 1.0 9 | * @since 5 /17/2017 10 | */ 11 | public class Constants { 12 | 13 | public static final String RESULT_STATUS_SUCCESS = "SUCCESS"; 14 | public static final String STRING_DATE_TYPE = "yyyy-MM-dd HH:mm:ss"; 15 | public static final String EMPTY_VALUE = "EMPTY_VALUE"; 16 | 17 | /** 18 | * The constant TARGET_DELIVERY_PIPELINE_API. 19 | */ 20 | public static final String TARGET_DELIVERY_PIPELINE_API = "deliveryPipelineApi"; 21 | 22 | 23 | /** 24 | * The enum Aes 256 type. 25 | */ 26 | public enum AES256Type { 27 | /** 28 | * Encode aes 256 type. 29 | */ 30 | ENCODE, 31 | /** 32 | * Decode aes 256 type. 33 | */ 34 | DECODE; 35 | } 36 | 37 | 38 | /** 39 | * The enum Job type. 40 | */ 41 | public enum JobType { 42 | /** 43 | * Build job type. 44 | */ 45 | BUILD, 46 | /** 47 | * Test job type. 48 | */ 49 | TEST, 50 | /** 51 | * Deploy job type. 52 | */ 53 | DEPLOY; 54 | } 55 | 56 | } 57 | -------------------------------------------------------------------------------- /src/main/java/paasta/delivery/pipeline/common/api/common/ListRequest.java: -------------------------------------------------------------------------------- 1 | package paasta.delivery.pipeline.common.api.common; 2 | 3 | /** 4 | * Created by hrjin on 2017-05-24. 5 | */ 6 | public class ListRequest { 7 | private String name; 8 | 9 | 10 | public String getName() { 11 | return name; 12 | } 13 | 14 | public void setName(String name) { 15 | this.name = name; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/paasta/delivery/pipeline/common/api/config/DataSourceConfig.java: -------------------------------------------------------------------------------- 1 | package paasta.delivery.pipeline.common.api.config; 2 | 3 | import org.springframework.context.annotation.Bean; 4 | import org.springframework.context.annotation.Configuration; 5 | import org.springframework.jdbc.datasource.DataSourceTransactionManager; 6 | import org.springframework.transaction.PlatformTransactionManager; 7 | import org.springframework.transaction.annotation.EnableTransactionManagement; 8 | 9 | import javax.sql.DataSource; 10 | 11 | /** 12 | * paastaDeliveryPipelineApi 13 | * paasta.delivery.pipeline.common.api.config 14 | * 15 | * @author REX 16 | * @version 1.0 17 | * @since 9/19/2017 18 | */ 19 | @Configuration 20 | @EnableTransactionManagement 21 | public class DataSourceConfig { 22 | 23 | /** 24 | * Transaction manager platform transaction manager. 25 | * 26 | * @param dataSource the data source 27 | * @return the platform transaction manager 28 | */ 29 | @Bean 30 | PlatformTransactionManager transactionManager(DataSource dataSource) { 31 | return new DataSourceTransactionManager(dataSource); 32 | } 33 | 34 | } 35 | 36 | 37 | -------------------------------------------------------------------------------- /src/main/java/paasta/delivery/pipeline/common/api/config/RestTemplateConfig.java: -------------------------------------------------------------------------------- 1 | package paasta.delivery.pipeline.common.api.config; 2 | 3 | import org.springframework.context.annotation.Bean; 4 | import org.springframework.context.annotation.Configuration; 5 | import org.springframework.web.client.RestTemplate; 6 | 7 | /** 8 | * paastaDeliveryPipelineApi 9 | * paasta.delivery.pipeline.common.api.config 10 | * 11 | * @author REX 12 | * @version 1.0 13 | * @since 5 /10/2017 14 | */ 15 | @Configuration 16 | public class RestTemplateConfig { 17 | 18 | /** 19 | * Rest template rest template. 20 | * 21 | * @return the rest template 22 | */ 23 | @Bean 24 | public RestTemplate restTemplate() { 25 | return new RestTemplate(); 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/paasta/delivery/pipeline/common/api/config/ServletConfig.java: -------------------------------------------------------------------------------- 1 | package paasta.delivery.pipeline.common.api.config; 2 | 3 | import org.springframework.boot.builder.SpringApplicationBuilder; 4 | import org.springframework.boot.web.support.SpringBootServletInitializer; 5 | import org.springframework.context.annotation.Configuration; 6 | import paasta.delivery.pipeline.common.api.Application; 7 | 8 | /** 9 | * paastaDeliveryPipelineApi 10 | * paasta.delivery.pipeline.common.api.config 11 | * 12 | * @author REX 13 | * @version 1.0 14 | * @since 5 /10/2017 15 | */ 16 | @Configuration 17 | public class ServletConfig extends SpringBootServletInitializer { 18 | 19 | @Override 20 | protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { 21 | return application.sources(Application.class); 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/paasta/delivery/pipeline/common/api/config/WebMvcConfig.java: -------------------------------------------------------------------------------- 1 | package paasta.delivery.pipeline.common.api.config; 2 | 3 | import org.springframework.context.annotation.Configuration; 4 | import org.springframework.web.servlet.config.annotation.EnableWebMvc; 5 | import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; 6 | import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; 7 | 8 | /** 9 | * paastaDeliveryPipelineApi 10 | * paasta.delivery.pipeline.common.api.config 11 | * 12 | * @author REX 13 | * @version 1.0 14 | * @since 5 /10/2017 15 | */ 16 | @Configuration 17 | @EnableWebMvc 18 | public class WebMvcConfig extends WebMvcConfigurerAdapter { 19 | 20 | @Override 21 | public void addResourceHandlers(ResourceHandlerRegistry registry) { 22 | registry.addResourceHandler("/resources/**").addResourceLocations("/resources/"); 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/paasta/delivery/pipeline/common/api/domain/common/authority/Authority.java: -------------------------------------------------------------------------------- 1 | package paasta.delivery.pipeline.common.api.domain.common.authority; 2 | 3 | import com.fasterxml.jackson.annotation.JsonInclude; 4 | 5 | import javax.persistence.*; 6 | import java.util.List; 7 | 8 | /** 9 | * Created by Mingu on 2017-05-31. 10 | */ 11 | 12 | @Entity 13 | @JsonInclude(JsonInclude.Include.NON_NULL) 14 | @Table(name = "authority") 15 | public class Authority { 16 | @Id 17 | @Column(name = "id") 18 | private String id; 19 | 20 | @Column(name = "display_name") 21 | private String displayName; 22 | 23 | @Column(name = "description") 24 | private String description; 25 | 26 | @Column(name = "auth_type") 27 | private String authType; 28 | 29 | @Column(name = "code") 30 | private String code; 31 | 32 | @Column(name = "auth_code") 33 | private String authCode; 34 | 35 | 36 | @OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL) 37 | @JoinColumn(name = "authority_id") 38 | @Transient 39 | private List grantedAuthorities; 40 | 41 | public Authority() { 42 | // DO NOTHING 43 | } 44 | 45 | public Authority(String id) { 46 | this.id = id; 47 | } 48 | 49 | public Authority(String id, String displayName) { 50 | this.id = id; 51 | this.displayName = displayName; 52 | } 53 | 54 | public String getId() { 55 | return id; 56 | } 57 | 58 | public void setId(String id) { 59 | this.id = id; 60 | } 61 | 62 | public String getDisplayName() { 63 | return displayName; 64 | } 65 | 66 | public void setDisplayName(String displayName) { 67 | this.displayName = displayName; 68 | } 69 | 70 | public String getDescription() { 71 | return description; 72 | } 73 | 74 | public void setDescription(String description) { 75 | this.description = description; 76 | } 77 | 78 | public List getGrantedAuthorities() { 79 | return grantedAuthorities; 80 | } 81 | 82 | public void setGrantedAuthorities(List grantedAuthorities) { 83 | this.grantedAuthorities = grantedAuthorities; 84 | } 85 | 86 | public String getAuthType() { 87 | return authType; 88 | } 89 | 90 | public void setAuthType(String authType) { 91 | this.authType = authType; 92 | } 93 | 94 | public String getCode() { 95 | return code; 96 | } 97 | 98 | public void setCode(String code) { 99 | this.code = code; 100 | } 101 | 102 | public String getAuthCode() { 103 | return authCode; 104 | } 105 | 106 | public void setAuthCode(String authCode) { 107 | this.authCode = authCode; 108 | } 109 | 110 | } 111 | -------------------------------------------------------------------------------- /src/main/java/paasta/delivery/pipeline/common/api/domain/common/authority/AuthorityController.java: -------------------------------------------------------------------------------- 1 | package paasta.delivery.pipeline.common.api.domain.common.authority; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import org.springframework.http.HttpStatus; 6 | import org.springframework.web.bind.annotation.*; 7 | 8 | import javax.servlet.http.HttpServletResponse; 9 | import java.io.IOException; 10 | import java.util.List; 11 | import java.util.UUID; 12 | 13 | /** 14 | * Created by Mingu on 2017-06-01. 15 | */ 16 | @RestController 17 | @RequestMapping(value = "/authorities") 18 | public class AuthorityController { 19 | private static final Logger LOGGER = LoggerFactory.getLogger(AuthorityController.class); 20 | private final AuthorityService authorityService; 21 | 22 | public AuthorityController(AuthorityService authorityService) { 23 | this.authorityService = authorityService; 24 | } 25 | 26 | /** 27 | * @apiVersion 0.1.0 28 | * @api {POST} /authorities Regist Authority 29 | * @apiDescription 권한을 등록한다. 30 | * @apiGroup Authorities 31 | * @apiExample {curl} Example usage: 32 | * curl 'http://localhost/authorities' -i -X POST \ 33 | * -H 'Authorization: Basic YWRtaW46Y2xvdWR==' \ 34 | * -H 'Content-Type: application/json' \ 35 | * -d '{ "displayName": "dashboard.user", 36 | * "description": "dashboard user" 37 | * }' 38 | * @apiHeader {String} Authorization API 인증 토큰 (Basic) 39 | * @apiHeader {String} Content-Type Body 데이터 타입. 40 | * @apiParam {String} displayName 권한의 보여질 이름 41 | * @apiParam {String} [description] 권한 설명 42 | */ 43 | @RequestMapping(value = "", method = RequestMethod.POST) 44 | public Authority add(HttpServletResponse response, @RequestBody Authority newAuthority) throws IOException { 45 | LOGGER.info("Add Authority: {}", newAuthority); 46 | Authority result = null; 47 | 48 | Authority authority = authorityService.getAuthorityByName(newAuthority.getDisplayName()); 49 | if (authority != null) { 50 | LOGGER.info("Failed Add Authority: '{}' is already exist.", authority.getDisplayName()); 51 | response.sendError(HttpStatus.CONFLICT.value(), "Authority '" + authority.getDisplayName() + "' is already exist."); 52 | } else { 53 | newAuthority.setId(UUID.randomUUID().toString()); 54 | result = authorityService.createAuthority(newAuthority); 55 | } 56 | 57 | return result; 58 | } 59 | 60 | /** 61 | * @apiVersion 0.1.0 62 | * @api {GET} /authorities Get Authority List 63 | * @apiDescription 권한 목록을 조회한다. 64 | * @apiGroup Authorities 65 | * @apiExample {curl} Example usage: 66 | * curl 'http://localhost/authorities' -i -X GET \ 67 | * -H 'Authorization: Basic YWRtaW46Y2xvdWR==' 68 | * @apiHeader {String} Authorization API 인증 토큰 (Basic) 69 | * @apiParam {String} authority_id 권한의 고유 식별자 70 | */ 71 | @RequestMapping(value = "", method = RequestMethod.GET) 72 | public List getList() { 73 | LOGGER.info("Get Authority List"); 74 | List result = authorityService.getAll(); 75 | return result; 76 | } 77 | 78 | /** 79 | * @apiVersion 0.1.0 80 | * @api {GET} /authorities/{authority_id} Get Authority 81 | * @apiDescription 권한을 조회한다. 82 | * @apiGroup Authorities 83 | * @apiExample {curl} Example usage: 84 | * curl 'http://localhost/authorities/7f2b54f2-3c46-4fec-a8b4-242825fad8ed' -i -X GET \ 85 | * -H 'Authorization: Basic YWRtaW46Y2xvdWR==' 86 | * @apiHeader {String} Authorization API 인증 토큰 (Basic) 87 | * @apiParam {String} authority_id 권한의 고유 식별자 88 | */ 89 | @RequestMapping(value = "/{id}", method = RequestMethod.GET) 90 | public Authority get(@PathVariable("id") String id) { 91 | LOGGER.info("Get Authority: {}", id); 92 | return authorityService.getAuthority(id); 93 | } 94 | 95 | @RequestMapping(value = "/code/{code}", method = RequestMethod.GET) 96 | public Authority getAuthByAuthCode(@PathVariable("code") String code) { 97 | return authorityService.getAuthorityByCode(code); 98 | } 99 | 100 | @RequestMapping(value = "/authType/{authType}", method = RequestMethod.GET) 101 | public List getAuthorityByAuthType(@PathVariable("authType") String authType) { 102 | return authorityService.getAuthorityByAuthType(authType); 103 | } 104 | 105 | /** 106 | * @apiVersion 0.1.0 107 | * @api {Delete} /authorities/{authority_id} Delete Authority 108 | * @apiDescription 권한을 삭제한다. 109 | * @apiGroup Authorities 110 | * @apiExample {curl} Example usage: 111 | * curl 'http://localhost/authorities/7f2b54f2-3c46-4fec-a8b4-242825fad8ed' -i -X Delete \ 112 | * -H 'Authorization: Basic YWRtaW46Y2xvdWR==' 113 | * @apiHeader {String} Authorization API 인증 토큰 (Basic) 114 | * @apiParam {String} authority_id 권한의 고유 식별자 115 | */ 116 | @RequestMapping(value = "/{id}", method = RequestMethod.DELETE) 117 | public void delete(@PathVariable("id") String id) { 118 | LOGGER.info("Delete Authority: {}", id); 119 | authorityService.deleteAuthority(id); 120 | } 121 | 122 | // not supported 123 | // @RequestMapping(value = "/{id}", method = RequestMethod.PUT) 124 | // public Authority update(@PathVariable("id") String id, 125 | // @RequestBody Authority updateAuthority) { 126 | // return authorityService.updateAuthority(id, updateAuthority); 127 | // } 128 | } 129 | -------------------------------------------------------------------------------- /src/main/java/paasta/delivery/pipeline/common/api/domain/common/authority/AuthorityRepository.java: -------------------------------------------------------------------------------- 1 | package paasta.delivery.pipeline.common.api.domain.common.authority; 2 | 3 | import org.springframework.data.jpa.repository.JpaRepository; 4 | import org.springframework.stereotype.Repository; 5 | 6 | import java.util.List; 7 | 8 | /** 9 | * Created by Mingu on 2017-05-31. 10 | */ 11 | 12 | @Repository 13 | public interface AuthorityRepository extends JpaRepository { 14 | Authority findByDisplayName(String displayName); 15 | 16 | 17 | Authority findByAuthCode(String authCode); 18 | 19 | List findByAuthType(String authType); 20 | 21 | Authority findByCode(String code); 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/paasta/delivery/pipeline/common/api/domain/common/authority/AuthorityService.java: -------------------------------------------------------------------------------- 1 | package paasta.delivery.pipeline.common.api.domain.common.authority; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.stereotype.Service; 5 | import paasta.delivery.pipeline.common.api.common.Constants; 6 | 7 | import java.util.List; 8 | 9 | /** 10 | * Created by Mingu on 2017-05-31. 11 | */ 12 | 13 | @Service 14 | public class AuthorityService { 15 | 16 | private final AuthorityRepository authorityRepository; 17 | 18 | 19 | @Autowired 20 | public AuthorityService(AuthorityRepository authorityRepository) { 21 | this.authorityRepository = authorityRepository; 22 | } 23 | 24 | public Authority createAuthority(Authority authority) { 25 | return authorityRepository.save(authority); 26 | } 27 | 28 | public List getAll() { 29 | return authorityRepository.findAll(); 30 | } 31 | 32 | public Authority getAuthority(String id) { 33 | return authorityRepository.findOne(id); 34 | } 35 | 36 | public Authority getAuthorityByName(String displayName) { 37 | return authorityRepository.findByDisplayName(displayName); 38 | } 39 | 40 | public Authority updateAuthority(String id, Authority updateAuthority) { 41 | updateAuthority.setId(id); 42 | Authority authority = authorityRepository.save(updateAuthority); 43 | return authority; 44 | } 45 | 46 | public Authority getAuthorityByCode(String code) { 47 | return authorityRepository.findByCode(code); 48 | } 49 | 50 | public String deleteAuthority(String id) { 51 | authorityRepository.delete(id); 52 | return Constants.RESULT_STATUS_SUCCESS; 53 | } 54 | 55 | public List getAuthorityByAuthType(String authType) { 56 | return authorityRepository.findByAuthType(authType); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/main/java/paasta/delivery/pipeline/common/api/domain/common/authority/AuthorizeController.java: -------------------------------------------------------------------------------- 1 | package paasta.delivery.pipeline.common.api.domain.common.authority; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import org.springframework.web.bind.annotation.*; 6 | import paasta.delivery.pipeline.common.api.common.Constants; 7 | 8 | import javax.servlet.http.HttpServletResponse; 9 | import java.io.IOException; 10 | import java.util.List; 11 | import java.util.UUID; 12 | 13 | /** 14 | * Created by Mingu on 2017-06-01. 15 | */ 16 | @RestController 17 | @RequestMapping(value = "/authorize") 18 | public class AuthorizeController { 19 | private static final Logger LOGGER = LoggerFactory.getLogger(AuthorizeController.class); 20 | private final AuthorityService authorityService; 21 | private final GrantedAuthorityService grantedAuthorityService; 22 | 23 | public AuthorizeController(AuthorityService authorityService, GrantedAuthorityService grantedAuthorityService) { 24 | this.authorityService = authorityService; 25 | this.grantedAuthorityService = grantedAuthorityService; 26 | } 27 | 28 | /** 29 | * @apiVersion 0.1.0 30 | * @api {POST} /authorities Authorize 31 | * @apiDescription 사용자에게 권한을 부여한다. 32 | * @apiGroup Authorize 33 | * @apiExample {curl} Example usage: 34 | * curl 'http://localhost/authorize' -i -X POST \ 35 | * -H 'Authorization: Basic YWRtaW46Y2xvdWR==' \ 36 | * -H 'Content-Type: application/json' \ 37 | * -d '{ "instance_use_id": 1, 38 | * "authority_id": "7f2b54f2-3c46-4fec-a8b4-242825fad8ed" 39 | * }' 40 | * @apiHeader {String} Authorization API 인증 토큰 (Basic) 41 | * @apiHeader {String} Content-Type Body 데이터 타입. 42 | * @apiParam {Long} instance_use_id 서비스 인스턴스 사용자의 고유식별자 43 | * @apiParam {String} authority_id 권한의 고유식별자 44 | */ 45 | @RequestMapping(value = "", method = RequestMethod.POST) 46 | public GrantedAuthority authorize(HttpServletResponse response, @RequestBody GrantedAuthority newGrantedAuthority) throws IOException { 47 | 48 | LOGGER.info("############# newGrantedAuthority:::{}", newGrantedAuthority.getAuthCode()); 49 | 50 | newGrantedAuthority.setId(UUID.randomUUID().toString()); 51 | newGrantedAuthority.setAuthority(new Authority(newGrantedAuthority.getAuthorityId())); 52 | 53 | if(newGrantedAuthority.getAuthCode() == null) { 54 | newGrantedAuthority.setAuthCode((long) 0); 55 | } 56 | return grantedAuthorityService.createGrantedAuthority(newGrantedAuthority); 57 | } 58 | 59 | 60 | /** 61 | * @apiVersion 0.1.0 62 | * @api {GET} /authorities Get Authorize List 63 | * @apiDescription 권한 부여 목록을 조회한다. 64 | * @apiGroup Authorize 65 | * @apiExample {curl} Example usage: 66 | * curl 'http://localhost/authorize' -i -X GET \ 67 | * -H 'Authorization: Basic YWRtaW46Y2xvdWR==' 68 | * @apiHeader {String} Authorization API 인증 토큰 (Basic) 69 | */ 70 | @RequestMapping(value = "", method = RequestMethod.GET) 71 | public List getList() { 72 | return grantedAuthorityService.getGrantedAuthorityList(); 73 | } 74 | 75 | 76 | /** 77 | * @apiVersion 0.1.0 78 | * @api {GET} /authorize/{authorize_id} Get Authorize 79 | * @apiDescription 사용자에게 부여된 권한을 조회한다. 80 | * @apiGroup Authorize 81 | * @apiExample {curl} Example usage: 82 | * curl 'http://localhost/authorize/4ea73add-d702-4020-a549-5ee87b25ce65' -i -X GET \ 83 | * -H 'Authorization: Basic YWRtaW46Y2xvdWR==' 84 | * @apiHeader {String} Authorization API 인증 토큰 (Basic) 85 | * @apiParam {String} authorize_id 사용자에게 부여된 권한의 고유식별자 86 | */ 87 | @RequestMapping(value = "/{id}", method = RequestMethod.GET) 88 | public GrantedAuthority get(@PathVariable String id) { 89 | return grantedAuthorityService.getGrantedAuthority(id); 90 | } 91 | 92 | 93 | /** 94 | * @apiVersion 0.1.0 95 | * @api {DELETE} /authorize/{authorize_id} Delete Authorize 96 | * @apiDescription 사용자에게 부여된 권한을 해제한다. 97 | * @apiGroup Authorize 98 | * @apiExample {curl} Example usage: 99 | * curl 'http://localhost/authorize/4ea73add-d702-4020-a549-5ee87b25ce65' -i -X DELETE \ 100 | * -H 'Authorization: Basic YWRtaW46Y2xvdWR==' 101 | * @apiHeader {String} Authorization API 인증 토큰 (Basic) 102 | * @apiParam {String} authorize_id 사용자에게 부여된 권한의 고유식별자 103 | */ 104 | @RequestMapping(value = "/{id}", method = RequestMethod.DELETE) 105 | public String delete(@PathVariable String id) { 106 | grantedAuthorityService.deleteGrantedAuthority(id); 107 | return Constants.RESULT_STATUS_SUCCESS; 108 | } 109 | } 110 | -------------------------------------------------------------------------------- /src/main/java/paasta/delivery/pipeline/common/api/domain/common/authority/GrantedAuthority.java: -------------------------------------------------------------------------------- 1 | package paasta.delivery.pipeline.common.api.domain.common.authority; 2 | 3 | import com.fasterxml.jackson.annotation.JsonInclude; 4 | import com.fasterxml.jackson.annotation.JsonProperty; 5 | import org.hibernate.annotations.CreationTimestamp; 6 | 7 | import javax.persistence.*; 8 | import java.util.Date; 9 | 10 | 11 | /** 12 | * Created by Mingu on 2017-05-31. 13 | */ 14 | @Entity 15 | @JsonInclude(JsonInclude.Include.NON_NULL) 16 | @Table(name = "granted_authority") 17 | public class GrantedAuthority { 18 | @Id 19 | @Column(name = "id") 20 | private String id; 21 | 22 | @Column(name = "instance_use_id") 23 | @JsonProperty("instance_use_id") 24 | private Long instanceUseId; 25 | 26 | @Column(name = "auth_code") 27 | private Long authCode; 28 | 29 | @ManyToOne(targetEntity = Authority.class, optional = true, fetch = FetchType.EAGER) 30 | @JoinColumn(name = "authority_id", nullable = false, referencedColumnName = "id") 31 | private Authority authority; 32 | 33 | @Transient 34 | @JsonProperty("authority_id") 35 | private String authorityId; 36 | 37 | @CreationTimestamp 38 | @Column(name = "created", columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP", updatable = false) 39 | @Temporal(TemporalType.TIMESTAMP) 40 | private Date created; 41 | 42 | public GrantedAuthority() { 43 | // DO NOTHING 44 | } 45 | 46 | public GrantedAuthority(String id, Long instanceUseId, String authorityId) { 47 | this.id = id; 48 | this.instanceUseId = instanceUseId; 49 | this.authority = new Authority(authorityId); 50 | } 51 | 52 | public String getId() { 53 | return id; 54 | } 55 | 56 | public void setId(String id) { 57 | this.id = id; 58 | } 59 | 60 | public Long getInstanceUseId() { 61 | return instanceUseId; 62 | } 63 | 64 | public void setInstanceUseId(Long instanceUseId) { 65 | this.instanceUseId = instanceUseId; 66 | } 67 | 68 | public Long getAuthCode() { 69 | return authCode; 70 | } 71 | 72 | public void setAuthCode(Long authCode) { 73 | this.authCode = authCode; 74 | } 75 | 76 | public String getAuthorityId() { 77 | return authorityId; 78 | } 79 | 80 | public void setAuthorityId(String authorityId) { 81 | this.authorityId = authorityId; 82 | } 83 | 84 | public Authority getAuthority() { 85 | return authority; 86 | } 87 | 88 | public void setAuthority(Authority authority) { 89 | this.authority = authority; 90 | } 91 | 92 | public Date getCreated() { 93 | return created; 94 | } 95 | 96 | public void setCreated(Date created) { 97 | this.created = created; 98 | } 99 | 100 | 101 | } 102 | -------------------------------------------------------------------------------- /src/main/java/paasta/delivery/pipeline/common/api/domain/common/authority/GrantedAuthorityRepository.java: -------------------------------------------------------------------------------- 1 | package paasta.delivery.pipeline.common.api.domain.common.authority; 2 | 3 | import org.springframework.data.jpa.repository.JpaRepository; 4 | import org.springframework.stereotype.Repository; 5 | 6 | import java.util.List; 7 | 8 | /** 9 | * Created by Mingu on 2017-05-31. 10 | */ 11 | 12 | @Repository 13 | public interface GrantedAuthorityRepository extends JpaRepository { 14 | 15 | GrantedAuthority findTopByInstanceUseIdOrAuthority(Long instanceUseId, Authority authority); 16 | 17 | List findByInstanceUseId(Long instanceUseId); 18 | 19 | List findByAuthCode(Long pipelineId); 20 | 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/paasta/delivery/pipeline/common/api/domain/common/authority/GrantedAuthorityService.java: -------------------------------------------------------------------------------- 1 | package paasta.delivery.pipeline.common.api.domain.common.authority; 2 | 3 | import org.springframework.stereotype.Service; 4 | import paasta.delivery.pipeline.common.api.common.Constants; 5 | 6 | import java.util.List; 7 | 8 | /** 9 | * Created by Mingu on 2017-05-31. 10 | */ 11 | @Service 12 | public class GrantedAuthorityService { 13 | 14 | 15 | private final GrantedAuthorityRepository grantedAuthorityRepository; 16 | 17 | public GrantedAuthorityService(GrantedAuthorityRepository grantedAuthorityRepository) { 18 | this.grantedAuthorityRepository = grantedAuthorityRepository; 19 | 20 | } 21 | 22 | public GrantedAuthority createGrantedAuthority(GrantedAuthority grantedAuthority) { 23 | return grantedAuthorityRepository.save(grantedAuthority); 24 | } 25 | 26 | public GrantedAuthority getGrantedAuthority(String id) { 27 | return grantedAuthorityRepository.findOne(id); 28 | } 29 | 30 | public GrantedAuthority getGrantedAuthorityByInstanceUseIdAndAuthorityId(Long instanceUseId, String authorityId) { 31 | return grantedAuthorityRepository.findTopByInstanceUseIdOrAuthority(instanceUseId, new Authority(authorityId)); 32 | // return grantedAuthorityRepository.findByInstanceUseId(id); 33 | } 34 | 35 | public List findAll() { 36 | return grantedAuthorityRepository.findAll(); 37 | } 38 | 39 | 40 | public String deleteGrantedAuthority(String id) { 41 | grantedAuthorityRepository.delete(id); 42 | return Constants.RESULT_STATUS_SUCCESS; 43 | } 44 | 45 | 46 | public List getGrantedAuthorityList() { 47 | return grantedAuthorityRepository.findAll(); 48 | } 49 | 50 | 51 | 52 | public List findByInstanceUseId(Long instanceUseId) { 53 | return grantedAuthorityRepository.findByInstanceUseId(instanceUseId); 54 | } 55 | 56 | public void deleteGrantedAuthorityRows(List grantedAuthorities) { 57 | grantedAuthorityRepository.delete(grantedAuthorities); 58 | } 59 | 60 | public List findByAuthCode(Long pipelineId){ 61 | return grantedAuthorityRepository.findByAuthCode(pipelineId); 62 | } 63 | 64 | 65 | } 66 | -------------------------------------------------------------------------------- /src/main/java/paasta/delivery/pipeline/common/api/domain/common/cf/info/CfInfo.java: -------------------------------------------------------------------------------- 1 | package paasta.delivery.pipeline.common.api.domain.common.cf.info; 2 | 3 | import org.hibernate.annotations.CreationTimestamp; 4 | import org.hibernate.annotations.UpdateTimestamp; 5 | import paasta.delivery.pipeline.common.api.common.Constants; 6 | 7 | import javax.persistence.*; 8 | import java.text.SimpleDateFormat; 9 | import java.util.Date; 10 | import java.util.Locale; 11 | 12 | /** 13 | * paastaDeliveryPipelineApi 14 | * paasta.delivery.pipeline.common.api.cfInfo 15 | * 16 | * @author REX 17 | * @version 1.0 18 | * @since 7/25/2017 19 | */ 20 | @Entity 21 | @Table(name = "cf_info") 22 | public class CfInfo { 23 | 24 | @Id 25 | @GeneratedValue(strategy = GenerationType.IDENTITY) 26 | @Column(name = "id") 27 | private long id; 28 | 29 | @Column(name = "service_instances_id", nullable = false) 30 | private String serviceInstancesId; 31 | 32 | @Column(name = "cf_name", nullable = false) 33 | private String cfName; 34 | 35 | @Column(name = "cf_id", nullable = false) 36 | private String cfId; 37 | 38 | @Column(name = "cf_password", nullable = false) 39 | private String cfPassword; 40 | 41 | @Column(name = "cf_api_url") 42 | private String cfApiUrl; 43 | 44 | @Column(name = "description") 45 | private String description; 46 | 47 | @Column(name = "user_id", nullable = false) 48 | private String userId; 49 | 50 | @CreationTimestamp 51 | @Column(columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP", updatable = false) 52 | @Temporal(TemporalType.TIMESTAMP) 53 | private Date created; 54 | 55 | @UpdateTimestamp 56 | @Column(name = "last_modified", columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP") 57 | @Temporal(TemporalType.TIMESTAMP) 58 | private Date lastModified; 59 | 60 | @Transient 61 | private String createdString; 62 | 63 | @Transient 64 | private String lastModifiedString; 65 | 66 | public long getId() { 67 | return id; 68 | } 69 | 70 | public void setId(long id) { 71 | this.id = id; 72 | } 73 | 74 | public String getServiceInstancesId() { 75 | return serviceInstancesId; 76 | } 77 | 78 | public void setServiceInstancesId(String serviceInstancesId) { 79 | this.serviceInstancesId = serviceInstancesId; 80 | } 81 | 82 | public String getCfName() { 83 | return cfName; 84 | } 85 | 86 | public void setCfName(String cfName) { 87 | this.cfName = cfName; 88 | } 89 | 90 | public String getCfId() { 91 | return cfId; 92 | } 93 | 94 | public void setCfId(String cfId) { 95 | this.cfId = cfId; 96 | } 97 | 98 | public String getCfPassword() { 99 | return cfPassword; 100 | } 101 | 102 | public void setCfPassword(String cfPassword) { 103 | this.cfPassword = cfPassword; 104 | } 105 | 106 | public String getCfApiUrl() { 107 | return cfApiUrl; 108 | } 109 | 110 | public void setCfApiUrl(String cfApiUrl) { 111 | this.cfApiUrl = cfApiUrl; 112 | } 113 | 114 | public String getDescription() { 115 | return description; 116 | } 117 | 118 | public void setDescription(String description) { 119 | this.description = description; 120 | } 121 | 122 | public String getUserId() { 123 | return userId; 124 | } 125 | 126 | public void setUserId(String userId) { 127 | this.userId = userId; 128 | } 129 | 130 | public Date getCreated() { 131 | return created; 132 | } 133 | 134 | public void setCreated(Date created) { 135 | this.created = created; 136 | } 137 | 138 | public Date getLastModified() { 139 | return lastModified; 140 | } 141 | 142 | public void setLastModified(Date lastModified) { 143 | this.lastModified = lastModified; 144 | } 145 | 146 | public String getCreatedString() { 147 | return (created != null) ? new SimpleDateFormat(Constants.STRING_DATE_TYPE, Locale.KOREA).format(created) : null; 148 | } 149 | 150 | public void setCreatedString(String createdString) { 151 | this.createdString = createdString; 152 | } 153 | 154 | public String getLastModifiedString() { 155 | return (lastModified != null) ? new SimpleDateFormat(Constants.STRING_DATE_TYPE, Locale.KOREA).format(lastModified) : null; 156 | } 157 | 158 | public void setLastModifiedString(String lastModifiedString) { 159 | this.lastModifiedString = lastModifiedString; 160 | } 161 | 162 | } 163 | -------------------------------------------------------------------------------- /src/main/java/paasta/delivery/pipeline/common/api/domain/common/cf/info/CfInfoController.java: -------------------------------------------------------------------------------- 1 | package paasta.delivery.pipeline.common.api.domain.common.cf.info; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.data.domain.Pageable; 5 | import org.springframework.data.domain.Sort; 6 | import org.springframework.data.web.PageableDefault; 7 | import org.springframework.web.bind.annotation.*; 8 | 9 | /** 10 | * paastaDeliveryPipelineApi 11 | * paasta.delivery.pipeline.common.api.cfInfo 12 | * 13 | * @author REX 14 | * @version 1.0 15 | * @since 7 /25/2017 16 | */ 17 | @RestController 18 | public class CfInfoController { 19 | 20 | private static final String REQ_URL = "/cf-info"; 21 | private static final int PAGE_SIZE = 3; 22 | private final CfInfoService cfInfoService; 23 | 24 | 25 | /** 26 | * Instantiates a new Cf info controller. 27 | * 28 | * @param cfInfoService the cf info service 29 | */ 30 | @Autowired 31 | public CfInfoController(CfInfoService cfInfoService) {this.cfInfoService = cfInfoService;} 32 | 33 | 34 | /** 35 | * Gets cf info list pageable. 36 | * 37 | * @param pageable the pageable 38 | * @param serviceInstancesId the service instances id 39 | * @param cfName the cf name 40 | * @return the cf info list pageable 41 | */ 42 | @GetMapping(value = "/serviceInstances/{serviceInstancesId:.+}" + REQ_URL) 43 | public CfInfoList getCfInfoListPageable(@PageableDefault(sort = "created", direction = Sort.Direction.DESC, size = PAGE_SIZE) Pageable pageable, 44 | @PathVariable(value = "serviceInstancesId", required = false) String serviceInstancesId, 45 | @RequestParam(value = "cfName", required = false) String cfName) { 46 | return cfInfoService.getCfInfoListPageable(pageable, serviceInstancesId, cfName); 47 | } 48 | 49 | 50 | /** 51 | * Gets cf info by id. 52 | * 53 | * @param id the id 54 | * @return the cf info by id 55 | */ 56 | @GetMapping(value = REQ_URL + "/{id:.+}") 57 | public CfInfo getCfInfoById(@PathVariable("id") int id) { 58 | return cfInfoService.getCfInfoById(id); 59 | } 60 | 61 | 62 | /** 63 | * Gets cf info count by service instances id and cf name. 64 | * 65 | * @param serviceInstancesId the service instances id 66 | * @param cfName the cf name 67 | * @return the cf info count by service instances id and cf name 68 | */ 69 | @GetMapping(value = "/serviceInstances/{serviceInstancesId:.+}" + REQ_URL + "/cf-name/{cfName:.+}") 70 | public int getCfInfoCountByServiceInstancesIdAndCfName(@PathVariable("serviceInstancesId") String serviceInstancesId, @PathVariable("cfName") String cfName) { 71 | return cfInfoService.getCfInfoCountByServiceInstancesIdAndCfName(serviceInstancesId, cfName); 72 | } 73 | 74 | 75 | /** 76 | * Create cf info cf info. 77 | * 78 | * @param cfInfo the cf info 79 | * @return the cf info 80 | */ 81 | @PostMapping(value = REQ_URL) 82 | public CfInfo createCfInfo(@RequestBody CfInfo cfInfo) { 83 | return cfInfoService.createCfInfo(cfInfo); 84 | } 85 | 86 | 87 | /** 88 | * Update cf info cf info. 89 | * 90 | * @param cfInfo the cf info 91 | * @return the cf info 92 | */ 93 | @PutMapping(value = REQ_URL) 94 | public CfInfo updateCfInfo(@RequestBody CfInfo cfInfo) { 95 | return cfInfoService.updateCfInfo(cfInfo); 96 | } 97 | 98 | 99 | /** 100 | * Delete cf ino string. 101 | * 102 | * @param id the id 103 | * @return the string 104 | */ 105 | @DeleteMapping(value = REQ_URL + "/{id:.+}") 106 | public String deleteCfIno(@PathVariable("id") int id) { 107 | return cfInfoService.deleteCfInoById(id); 108 | } 109 | 110 | } 111 | -------------------------------------------------------------------------------- /src/main/java/paasta/delivery/pipeline/common/api/domain/common/cf/info/CfInfoList.java: -------------------------------------------------------------------------------- 1 | package paasta.delivery.pipeline.common.api.domain.common.cf.info; 2 | 3 | import java.util.List; 4 | 5 | /** 6 | * paastaDeliveryPipelineApi 7 | * paasta.delivery.pipeline.common.api.cfInfo 8 | * 9 | * @author REX 10 | * @version 1.0 11 | * @since 7/25/2017 12 | */ 13 | public class CfInfoList { 14 | 15 | private List cfInfos; 16 | 17 | private int page; 18 | private int size; 19 | private int totalPages; 20 | private long totalElements; 21 | private boolean isLast; 22 | 23 | public List getCfInfos() { 24 | return cfInfos; 25 | } 26 | 27 | public void setCfInfos(List cfInfos) { 28 | this.cfInfos = cfInfos; 29 | } 30 | 31 | public int getPage() { 32 | return page; 33 | } 34 | 35 | public void setPage(int page) { 36 | this.page = page; 37 | } 38 | 39 | public int getSize() { 40 | return size; 41 | } 42 | 43 | public void setSize(int size) { 44 | this.size = size; 45 | } 46 | 47 | public int getTotalPages() { 48 | return totalPages; 49 | } 50 | 51 | public void setTotalPages(int totalPages) { 52 | this.totalPages = totalPages; 53 | } 54 | 55 | public long getTotalElements() { 56 | return totalElements; 57 | } 58 | 59 | public void setTotalElements(long totalElements) { 60 | this.totalElements = totalElements; 61 | } 62 | 63 | public boolean isLast() { 64 | return isLast; 65 | } 66 | 67 | public void setLast(boolean last) { 68 | isLast = last; 69 | } 70 | 71 | } 72 | -------------------------------------------------------------------------------- /src/main/java/paasta/delivery/pipeline/common/api/domain/common/cf/info/CfInfoRepository.java: -------------------------------------------------------------------------------- 1 | package paasta.delivery.pipeline.common.api.domain.common.cf.info; 2 | 3 | import org.springframework.data.domain.Page; 4 | import org.springframework.data.domain.Pageable; 5 | import org.springframework.data.jpa.repository.JpaRepository; 6 | import org.springframework.stereotype.Repository; 7 | import org.springframework.transaction.annotation.Transactional; 8 | 9 | import java.util.List; 10 | 11 | /** 12 | * paastaDeliveryPipelineApi 13 | * paasta.delivery.pipeline.common.api.cfInfo 14 | * 15 | * @author REX 16 | * @version 1.0 17 | * @since 7 /25/2017 18 | */ 19 | @Repository 20 | @Transactional 21 | public interface CfInfoRepository extends JpaRepository { 22 | 23 | /** 24 | * Find all by service instances id page. 25 | * 26 | * @param pageable the pageable 27 | * @param serviceInstancesId the service instances id 28 | * @return the page 29 | */ 30 | Page findAllByServiceInstancesId(Pageable pageable, String serviceInstancesId); 31 | 32 | 33 | /** 34 | * Find all by service instances id and cf name containing page. 35 | * 36 | * @param pageable the pageable 37 | * @param serviceInstancesId the service instances id 38 | * @param cfName the cf name 39 | * @return the page 40 | */ 41 | Page findAllByServiceInstancesIdAndCfNameContaining(Pageable pageable, String serviceInstancesId, String cfName); 42 | 43 | 44 | /** 45 | * Count by service instances id and cf name int. 46 | * 47 | * @param serviceInstancesId the service instances id 48 | * @param cfName the cf name 49 | * @return the int 50 | */ 51 | int countByServiceInstancesIdAndCfName(String serviceInstancesId, String cfName); 52 | 53 | List findByServiceInstancesId(String id); 54 | 55 | void deleteCfInoById(long id); 56 | } 57 | -------------------------------------------------------------------------------- /src/main/java/paasta/delivery/pipeline/common/api/domain/common/cf/info/CfInfoService.java: -------------------------------------------------------------------------------- 1 | package paasta.delivery.pipeline.common.api.domain.common.cf.info; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.data.domain.Page; 7 | import org.springframework.data.domain.Pageable; 8 | import org.springframework.stereotype.Service; 9 | import paasta.delivery.pipeline.common.api.common.CommonService; 10 | import paasta.delivery.pipeline.common.api.common.Constants; 11 | 12 | /** 13 | * paastaDeliveryPipelineApi 14 | * paasta.delivery.pipeline.common.api.cfInfo 15 | * 16 | * @author REX 17 | * @version 1.0 18 | * @since 7 /25/2017 19 | */ 20 | @Service 21 | public class CfInfoService { 22 | 23 | private static final Logger LOGGER = LoggerFactory.getLogger(CfInfoService.class); 24 | private final CommonService commonService; 25 | private final CfInfoRepository cfInfoRepository; 26 | 27 | 28 | /** 29 | * Instantiates a new Cf info service. 30 | * 31 | * @param commonService the common service 32 | * @param cfInfoRepository the cf info repository 33 | */ 34 | @Autowired 35 | public CfInfoService(CommonService commonService, CfInfoRepository cfInfoRepository) { 36 | this.commonService = commonService; 37 | this.cfInfoRepository = cfInfoRepository; 38 | } 39 | 40 | 41 | /** 42 | * Gets cf info list pageable. 43 | * 44 | * @param pageable the pageable 45 | * @param serviceInstancesId the service instances id 46 | * @param cfName the cf name 47 | * @return the cf info list pageable 48 | */ 49 | CfInfoList getCfInfoListPageable(Pageable pageable, String serviceInstancesId, String cfName) { 50 | LOGGER.info("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"); 51 | LOGGER.info(" - PageNumber :: {}", pageable.getPageNumber()); 52 | LOGGER.info(" - PageSize :: {}", pageable.getPageSize()); 53 | LOGGER.info(" - Sort :: {}", pageable.getSort()); 54 | LOGGER.info(" - Offset :: {}", pageable.getOffset()); 55 | LOGGER.info(" - HasPrevious :: {}", pageable.hasPrevious()); 56 | LOGGER.info("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"); 57 | 58 | CfInfoList resultList; 59 | Page cfInfoListPage; 60 | 61 | if (serviceInstancesId == null || "".equals(serviceInstancesId)) { 62 | cfInfoListPage = cfInfoRepository.findAll(pageable); 63 | } else { 64 | if (cfName == null || "".equals(cfName)) { 65 | cfInfoListPage = cfInfoRepository.findAllByServiceInstancesId(pageable, serviceInstancesId); 66 | } else { 67 | cfInfoListPage = cfInfoRepository.findAllByServiceInstancesIdAndCfNameContaining(pageable, serviceInstancesId, cfName); 68 | } 69 | } 70 | 71 | resultList = (CfInfoList) commonService.setPageInfo(cfInfoListPage, CfInfoList.class); 72 | resultList.setCfInfos(cfInfoListPage.getContent()); 73 | 74 | return resultList; 75 | } 76 | 77 | 78 | /** 79 | * Gets cf info by id. 80 | * 81 | * @param id the id 82 | * @return the cf info by id 83 | */ 84 | CfInfo getCfInfoById(int id) { 85 | CfInfo resultModel = cfInfoRepository.findOne((long) id); 86 | resultModel.setCfPassword(commonService.setPasswordByAES256(Constants.AES256Type.DECODE, resultModel.getCfPassword())); 87 | return resultModel; 88 | } 89 | 90 | 91 | /** 92 | * Gets cf info count by service instances id and cf name. 93 | * 94 | * @param serviceInstancesId the service instances id 95 | * @param cfName the cf name 96 | * @return the cf info count by service instances id and cf name 97 | */ 98 | int getCfInfoCountByServiceInstancesIdAndCfName(String serviceInstancesId, String cfName) { 99 | return cfInfoRepository.countByServiceInstancesIdAndCfName(serviceInstancesId, cfName); 100 | } 101 | 102 | 103 | /** 104 | * Create cf info cf info. 105 | * 106 | * @param cfInfo the cf info 107 | * @return the cf info 108 | */ 109 | CfInfo createCfInfo(CfInfo cfInfo) { 110 | cfInfo.setCfPassword(commonService.setPasswordByAES256(Constants.AES256Type.ENCODE, cfInfo.getCfPassword())); 111 | return cfInfoRepository.save(cfInfo); 112 | } 113 | 114 | 115 | /** 116 | * Update cf info cf info. 117 | * 118 | * @param cfInfo the cf info 119 | * @return the cf info 120 | */ 121 | CfInfo updateCfInfo(CfInfo cfInfo) { 122 | cfInfo.setCfPassword(commonService.setPasswordByAES256(Constants.AES256Type.ENCODE, cfInfo.getCfPassword())); 123 | return cfInfoRepository.save(cfInfo); 124 | } 125 | 126 | 127 | /** 128 | * Delete cf ino by id string. 129 | * 130 | * @param id the id 131 | * @return the string 132 | */ 133 | String deleteCfInoById(int id) { 134 | cfInfoRepository.delete((long) id); 135 | return Constants.RESULT_STATUS_SUCCESS; 136 | } 137 | 138 | } 139 | -------------------------------------------------------------------------------- /src/main/java/paasta/delivery/pipeline/common/api/domain/common/cf/url/CfUrl.java: -------------------------------------------------------------------------------- 1 | package paasta.delivery.pipeline.common.api.domain.common.cf.url; 2 | 3 | import org.hibernate.annotations.CreationTimestamp; 4 | import org.hibernate.annotations.UpdateTimestamp; 5 | import paasta.delivery.pipeline.common.api.common.Constants; 6 | 7 | import javax.persistence.*; 8 | import java.text.SimpleDateFormat; 9 | import java.util.Date; 10 | import java.util.Locale; 11 | 12 | /** 13 | * deliveryPipelineApi 14 | * paasta.delivery.pipeline.common.api.domain.common.cf.url 15 | * 16 | * @author REX 17 | * @version 1.0 18 | * @since 11/6/2017 19 | */ 20 | @Entity 21 | @Table(name = "cf_url") 22 | public class CfUrl { 23 | 24 | @Id 25 | @GeneratedValue(strategy = GenerationType.IDENTITY) 26 | @Column(name = "id") 27 | private long id; 28 | 29 | @Column(name = "service_instances_id", nullable = false) 30 | private String serviceInstancesId; 31 | 32 | @Column(name = "cf_api_name", nullable = false) 33 | private String cfApiName; 34 | 35 | @Column(name = "cf_api_url") 36 | private String cfApiUrl; 37 | 38 | @Column(name = "user_id", nullable = false) 39 | private String userId; 40 | 41 | @CreationTimestamp 42 | @Column(columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP", updatable = false) 43 | @Temporal(TemporalType.TIMESTAMP) 44 | private Date created; 45 | 46 | @UpdateTimestamp 47 | @Column(name = "last_modified", columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP") 48 | @Temporal(TemporalType.TIMESTAMP) 49 | private Date lastModified; 50 | 51 | @Transient 52 | private String createdString; 53 | 54 | @Transient 55 | private String lastModifiedString; 56 | 57 | public long getId() { 58 | return id; 59 | } 60 | 61 | public void setId(long id) { 62 | this.id = id; 63 | } 64 | 65 | public String getServiceInstancesId() { 66 | return serviceInstancesId; 67 | } 68 | 69 | public void setServiceInstancesId(String serviceInstancesId) { 70 | this.serviceInstancesId = serviceInstancesId; 71 | } 72 | 73 | public String getCfApiName() { 74 | return cfApiName; 75 | } 76 | 77 | public void setCfApiName(String cfApiName) { 78 | this.cfApiName = cfApiName; 79 | } 80 | 81 | public String getCfApiUrl() { 82 | return cfApiUrl; 83 | } 84 | 85 | public void setCfApiUrl(String cfApiUrl) { 86 | this.cfApiUrl = cfApiUrl; 87 | } 88 | 89 | public String getUserId() { 90 | return userId; 91 | } 92 | 93 | public void setUserId(String userId) { 94 | this.userId = userId; 95 | } 96 | 97 | public Date getCreated() { 98 | return created; 99 | } 100 | 101 | public void setCreated(Date created) { 102 | this.created = created; 103 | } 104 | 105 | public Date getLastModified() { 106 | return lastModified; 107 | } 108 | 109 | public void setLastModified(Date lastModified) { 110 | this.lastModified = lastModified; 111 | } 112 | 113 | public String getCreatedString() { 114 | return (created != null) ? new SimpleDateFormat(Constants.STRING_DATE_TYPE, Locale.KOREA).format(created) : null; 115 | } 116 | 117 | public void setCreatedString(String createdString) { 118 | this.createdString = createdString; 119 | } 120 | 121 | public String getLastModifiedString() { 122 | return (lastModified != null) ? new SimpleDateFormat(Constants.STRING_DATE_TYPE, Locale.KOREA).format(lastModified) : null; 123 | } 124 | 125 | public void setLastModifiedString(String lastModifiedString) { 126 | this.lastModifiedString = lastModifiedString; 127 | } 128 | 129 | } 130 | -------------------------------------------------------------------------------- /src/main/java/paasta/delivery/pipeline/common/api/domain/common/cf/url/CfUrlController.java: -------------------------------------------------------------------------------- 1 | package paasta.delivery.pipeline.common.api.domain.common.cf.url; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.web.bind.annotation.*; 5 | 6 | import java.util.List; 7 | 8 | /** 9 | * deliveryPipelineApi 10 | * paasta.delivery.pipeline.common.api.domain.common.cf.url 11 | * 12 | * @author REX 13 | * @version 1.0 14 | * @since 11 /6/2017 15 | */ 16 | @RestController 17 | public class CfUrlController { 18 | 19 | private static final String REQ_URL = "/cf-urls"; 20 | private final CfUrlService cfUrlService; 21 | 22 | 23 | /** 24 | * Instantiates a new Cf url controller. 25 | * 26 | * @param cfUrlService the cf url service 27 | */ 28 | @Autowired 29 | public CfUrlController(CfUrlService cfUrlService) {this.cfUrlService = cfUrlService;} 30 | 31 | 32 | /** 33 | * Gets cf url list. 34 | * 35 | * @param serviceInstancesId the service instances id 36 | * @return the cf url list 37 | */ 38 | @GetMapping(value = "/serviceInstances/{serviceInstancesId:.+}" + REQ_URL) 39 | public List getCfUrlList(@PathVariable(value = "serviceInstancesId") String serviceInstancesId) { 40 | return cfUrlService.getCfUrlList(serviceInstancesId); 41 | } 42 | 43 | 44 | /** 45 | * Gets cf url by id. 46 | * 47 | * @param id the id 48 | * @return the cf url by id 49 | */ 50 | @GetMapping(value = REQ_URL + "/{id:.+}") 51 | public CfUrl getCfUrlById(@PathVariable("id") int id) { 52 | return cfUrlService.getCfUrlById(id); 53 | } 54 | 55 | 56 | /** 57 | * Create cf url cf url. 58 | * 59 | * @param cfUrl the cf url 60 | * @return the cf url 61 | */ 62 | @PostMapping(value = REQ_URL) 63 | public CfUrl createCfUrl(@RequestBody CfUrl cfUrl) { 64 | return cfUrlService.createCfUrl(cfUrl); 65 | } 66 | 67 | 68 | /** 69 | * Update cf url cf url. 70 | * 71 | * @param cfUrl the cf url 72 | * @return the cf url 73 | */ 74 | @PutMapping(value = REQ_URL) 75 | public CfUrl updateCfUrl(@RequestBody CfUrl cfUrl) { 76 | return cfUrlService.updateCfUrl(cfUrl); 77 | } 78 | 79 | 80 | /** 81 | * Delete cf ino string. 82 | * 83 | * @param id the id 84 | * @return the string 85 | */ 86 | @DeleteMapping(value = REQ_URL + "/{id:.+}") 87 | public String deleteCfIno(@PathVariable("id") int id) { 88 | return cfUrlService.deleteCfInoById(id); 89 | } 90 | 91 | } 92 | -------------------------------------------------------------------------------- /src/main/java/paasta/delivery/pipeline/common/api/domain/common/cf/url/CfUrlRepository.java: -------------------------------------------------------------------------------- 1 | package paasta.delivery.pipeline.common.api.domain.common.cf.url; 2 | 3 | import org.springframework.data.jpa.repository.JpaRepository; 4 | import org.springframework.stereotype.Repository; 5 | import org.springframework.transaction.annotation.Transactional; 6 | 7 | import java.util.List; 8 | 9 | /** 10 | * deliveryPipelineApi 11 | * paasta.delivery.pipeline.common.api.domain.common.cf.url 12 | * 13 | * @author REX 14 | * @version 1.0 15 | * @since 11 /6/2017 16 | */ 17 | @Repository 18 | @Transactional 19 | public interface CfUrlRepository extends JpaRepository { 20 | 21 | /** 22 | * Find all by service instances id order by created desc list. 23 | * 24 | * @param serviceInstancesId the service instances id 25 | * @return the list 26 | */ 27 | List findAllByServiceInstancesIdOrderByCreatedDesc(String serviceInstancesId); 28 | 29 | List findByServiceInstancesId(String id); 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/paasta/delivery/pipeline/common/api/domain/common/cf/url/CfUrlService.java: -------------------------------------------------------------------------------- 1 | package paasta.delivery.pipeline.common.api.domain.common.cf.url; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.stereotype.Service; 5 | import paasta.delivery.pipeline.common.api.common.Constants; 6 | 7 | import java.util.List; 8 | 9 | /** 10 | * deliveryPipelineApi 11 | * paasta.delivery.pipeline.common.api.domain.common.cf.url 12 | * 13 | * @author REX 14 | * @version 1.0 15 | * @since 11 /6/2017 16 | */ 17 | @Service 18 | public class CfUrlService { 19 | 20 | private final CfUrlRepository cfUrlRepository; 21 | 22 | 23 | /** 24 | * Instantiates a new Cf url service. 25 | * 26 | * @param cfUrlRepository the cf url repository 27 | */ 28 | @Autowired 29 | public CfUrlService(CfUrlRepository cfUrlRepository) {this.cfUrlRepository = cfUrlRepository;} 30 | 31 | 32 | /** 33 | * Gets cf url list. 34 | * 35 | * @param serviceInstancesId the service instances id 36 | * @return the cf url list 37 | */ 38 | List getCfUrlList(String serviceInstancesId) { 39 | return cfUrlRepository.findAllByServiceInstancesIdOrderByCreatedDesc(serviceInstancesId); 40 | } 41 | 42 | 43 | /** 44 | * Gets cf url by id. 45 | * 46 | * @param id the id 47 | * @return the cf url by id 48 | */ 49 | CfUrl getCfUrlById(int id) { 50 | return cfUrlRepository.findOne((long) id); 51 | } 52 | 53 | 54 | /** 55 | * Create cf url cf url. 56 | * 57 | * @param cfUrl the cf url 58 | * @return the cf url 59 | */ 60 | CfUrl createCfUrl(CfUrl cfUrl) { 61 | return cfUrlRepository.save(cfUrl); 62 | } 63 | 64 | 65 | /** 66 | * Update cf url cf url. 67 | * 68 | * @param cfUrl the cf url 69 | * @return the cf url 70 | */ 71 | CfUrl updateCfUrl(CfUrl cfUrl) { 72 | return cfUrlRepository.save(cfUrl); 73 | } 74 | 75 | 76 | /** 77 | * Delete cf ino by id string. 78 | * 79 | * @param id the id 80 | * @return the string 81 | */ 82 | String deleteCfInoById(int id) { 83 | cfUrlRepository.delete((long) id); 84 | return Constants.RESULT_STATUS_SUCCESS; 85 | } 86 | 87 | } 88 | -------------------------------------------------------------------------------- /src/main/java/paasta/delivery/pipeline/common/api/domain/common/code/Code.java: -------------------------------------------------------------------------------- 1 | package paasta.delivery.pipeline.common.api.domain.common.code; 2 | 3 | import org.hibernate.annotations.CreationTimestamp; 4 | import org.hibernate.annotations.UpdateTimestamp; 5 | import paasta.delivery.pipeline.common.api.common.Constants; 6 | 7 | import javax.persistence.*; 8 | import java.text.SimpleDateFormat; 9 | import java.util.Date; 10 | import java.util.Locale; 11 | 12 | /** 13 | * deliveryPipelineApi 14 | * paasta.delivery.pipeline.common.api.domain.common.code 15 | * 16 | * @author REX 17 | * @version 1.0 18 | * @since 11/6/2017 19 | */ 20 | @Entity 21 | @Table(name = "code") 22 | public class Code { 23 | 24 | @Id 25 | @GeneratedValue(strategy = GenerationType.IDENTITY) 26 | @Column(name = "id") 27 | private long id; 28 | 29 | @Column(name = "code_type") 30 | private String codeType; 31 | 32 | @Column(name = "code_group") 33 | private String codeGroup; 34 | 35 | @Column(name = "code_name", nullable = false) 36 | private String codeName; 37 | 38 | @Column(name = "code_value", nullable = false) 39 | private String codeValue; 40 | 41 | @Column(name = "code_order") 42 | private int codeOrder; 43 | 44 | @CreationTimestamp 45 | @Column(columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP", updatable = false) 46 | @Temporal(TemporalType.TIMESTAMP) 47 | private Date created; 48 | 49 | @UpdateTimestamp 50 | @Column(name = "last_modified", columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP") 51 | @Temporal(TemporalType.TIMESTAMP) 52 | private Date lastModified; 53 | 54 | @Transient 55 | private String createdString; 56 | 57 | @Transient 58 | private String lastModifiedString; 59 | 60 | public long getId() { 61 | return id; 62 | } 63 | 64 | public void setId(long id) { 65 | this.id = id; 66 | } 67 | 68 | public String getCodeType() { return codeType; } 69 | 70 | public void setCodeType(String codeType) { this.codeType = codeType; } 71 | 72 | public String getCodeGroup() { return codeGroup; } 73 | 74 | public void setCodeGroup(String codeGroup) { this.codeGroup = codeGroup; } 75 | 76 | public String getCodeName() { return codeName; } 77 | 78 | public void setCodeName(String codeName) { this.codeName = codeName; } 79 | 80 | public String getCodeValue() { return codeValue; } 81 | 82 | public void setCodeValue(String codeValue) { this.codeValue = codeValue; } 83 | 84 | public int getCodeOrder() { return codeOrder; } 85 | 86 | public void setCodeOrder(int codeOrder) { this.codeOrder = codeOrder; } 87 | 88 | public Date getCreated() { return created; } 89 | 90 | public void setCreated(Date created) { this.created = created; } 91 | 92 | public Date getLastModified() { return lastModified; } 93 | 94 | public void setLastModified(Date lastModified) { this.lastModified = lastModified; } 95 | 96 | public String getCreatedString() { 97 | return (created != null) ? new SimpleDateFormat(Constants.STRING_DATE_TYPE, Locale.KOREA).format(created) : null; 98 | } 99 | 100 | public void setCreatedString(String createdString) { 101 | this.createdString = createdString; 102 | } 103 | 104 | public String getLastModifiedString() { 105 | return (lastModified != null) ? new SimpleDateFormat(Constants.STRING_DATE_TYPE, Locale.KOREA).format(lastModified) : null; 106 | } 107 | 108 | public void setLastModifiedString(String lastModifiedString) { 109 | this.lastModifiedString = lastModifiedString; 110 | } 111 | 112 | } 113 | 114 | -------------------------------------------------------------------------------- /src/main/java/paasta/delivery/pipeline/common/api/domain/common/code/CodeController.java: -------------------------------------------------------------------------------- 1 | package paasta.delivery.pipeline.common.api.domain.common.code; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.data.domain.Sort; 5 | import org.springframework.web.bind.annotation.*; 6 | 7 | import java.util.List; 8 | 9 | /** 10 | * deliveryPipelineApi 11 | * paasta.delivery.pipeline.common.api.domain.common.code 12 | * 13 | * @author REX 14 | * @version 1.0 15 | * @since 11 /6/2017 16 | */ 17 | @RestController 18 | public class CodeController { 19 | 20 | private static final String REQ_URL = "/code"; 21 | private final CodeService codeService; 22 | 23 | 24 | /** 25 | * Instantiates a new Code controller. 26 | * 27 | * @param codeService the code service 28 | */ 29 | @Autowired 30 | public CodeController(CodeService codeService) {this.codeService = codeService;} 31 | 32 | 33 | /** 34 | * Gets code list. 35 | * 36 | * @return the code list 37 | * http:///code/list?sort=codeOrder,asc&codeName,asc 38 | */ 39 | @GetMapping(value = REQ_URL + "/list") 40 | public List getCodeListAll(Sort sort) { 41 | return codeService.getCodeListAll(sort); 42 | } 43 | 44 | /** 45 | * Gets code list. 46 | * 47 | * @param codeGroup the codeGroup 48 | * @return the code list 49 | */ 50 | @GetMapping(value = REQ_URL + "/list/{codeGroup:.+}") 51 | public List getCodeList(@PathVariable(value = "codeGroup") String codeGroup) { 52 | return codeService.getCodeList(codeGroup); 53 | } 54 | 55 | 56 | /** 57 | * Gets code by id. 58 | * 59 | * @param id the id 60 | * @return the code by id 61 | */ 62 | @GetMapping(value = REQ_URL + "/{id:.+}") 63 | public Code getCodeById(@PathVariable("id") int id) { 64 | return codeService.getCodeById(id); 65 | } 66 | 67 | 68 | /** 69 | * Create code code. 70 | * 71 | * @param code the code 72 | * @return the code 73 | */ 74 | @PostMapping(value = REQ_URL) 75 | public Code createCode(@RequestBody Code code) { 76 | return codeService.createCode(code); 77 | } 78 | 79 | 80 | /** 81 | * Update code code. 82 | * 83 | * @param code the code 84 | * @return the code 85 | */ 86 | @PutMapping(value = REQ_URL) 87 | public Code updateCode(@RequestBody Code code) { 88 | return codeService.updateCode(code); 89 | } 90 | 91 | 92 | /** 93 | * Delete cf ino string. 94 | * 95 | * @param id the id 96 | * @return the string 97 | */ 98 | @DeleteMapping(value = REQ_URL + "/{id:.+}") 99 | public String deleteCfIno(@PathVariable("id") int id) { 100 | return codeService.deleteCode(id); 101 | } 102 | 103 | } 104 | -------------------------------------------------------------------------------- /src/main/java/paasta/delivery/pipeline/common/api/domain/common/code/CodeRepository.java: -------------------------------------------------------------------------------- 1 | package paasta.delivery.pipeline.common.api.domain.common.code; 2 | 3 | import org.springframework.data.jpa.repository.JpaRepository; 4 | import org.springframework.stereotype.Repository; 5 | import org.springframework.transaction.annotation.Transactional; 6 | 7 | import java.util.List; 8 | 9 | /** 10 | * deliveryPipelineApi 11 | * paasta.delivery.pipeline.common.api.domain.common.code 12 | * 13 | * @author REX 14 | * @version 1.0 15 | * @since 11 /6/2017 16 | */ 17 | @Repository 18 | @Transactional 19 | public interface CodeRepository extends JpaRepository { 20 | 21 | /** 22 | * Find all by service instances id order by created desc list. 23 | * 24 | * @param codeGroup the codeGroup 25 | * @return the list 26 | */ 27 | List findAllByCodeGroupOrderByCodeOrderAsc(String codeGroup); 28 | 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/paasta/delivery/pipeline/common/api/domain/common/code/CodeService.java: -------------------------------------------------------------------------------- 1 | package paasta.delivery.pipeline.common.api.domain.common.code; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.data.domain.Sort; 5 | import org.springframework.stereotype.Service; 6 | import paasta.delivery.pipeline.common.api.common.Constants; 7 | 8 | import java.util.List; 9 | 10 | /** 11 | * deliveryPipelineApi 12 | * paasta.delivery.pipeline.common.api.domain.common.code 13 | * 14 | * @author REX 15 | * @version 1.0 16 | * @since 11 /6/2017 17 | */ 18 | @Service 19 | public class CodeService { 20 | 21 | private final CodeRepository codeRepository; 22 | 23 | 24 | /** 25 | * Instantiates a new Code service. 26 | * 27 | * @param codeRepository the code repository 28 | */ 29 | @Autowired 30 | public CodeService(CodeRepository codeRepository) {this.codeRepository = codeRepository;} 31 | 32 | 33 | /** 34 | * Gets code list All. 35 | * 36 | * @return the code list 37 | */ 38 | List getCodeListAll(Sort sort) { 39 | return codeRepository.findAll(sort); 40 | } 41 | 42 | /** 43 | * Gets code list. 44 | * 45 | * @param codeGroup the codeGroup 46 | * @return the code list 47 | */ 48 | List getCodeList(String codeGroup) { 49 | return codeRepository.findAllByCodeGroupOrderByCodeOrderAsc(codeGroup); 50 | } 51 | 52 | 53 | /** 54 | * Gets code by id. 55 | * 56 | * @param id the id 57 | * @return the code by id 58 | */ 59 | Code getCodeById(int id) { 60 | return codeRepository.findOne((long) id); 61 | } 62 | 63 | 64 | /** 65 | * Create code code. 66 | * 67 | * @param code the code 68 | * @return the code 69 | */ 70 | Code createCode(Code code) { 71 | return codeRepository.save(code); 72 | } 73 | 74 | 75 | /** 76 | * Update code code. 77 | * 78 | * @param code the code 79 | * @return the code 80 | */ 81 | Code updateCode(Code code) { 82 | return codeRepository.save(code); 83 | } 84 | 85 | 86 | /** 87 | * Delete cf ino by id string. 88 | * 89 | * @param id the id 90 | * @return the string 91 | */ 92 | String deleteCode(int id) { 93 | codeRepository.delete((long) id); 94 | return Constants.RESULT_STATUS_SUCCESS; 95 | } 96 | 97 | } 98 | -------------------------------------------------------------------------------- /src/main/java/paasta/delivery/pipeline/common/api/domain/common/file/FileController.java: -------------------------------------------------------------------------------- 1 | package paasta.delivery.pipeline.common.api.domain.common.file; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.web.bind.annotation.*; 5 | 6 | import java.util.List; 7 | 8 | /** 9 | * Created by Dojun on 2017-06-13. 10 | */ 11 | 12 | @RestController 13 | @RequestMapping("/file") 14 | public class FileController { 15 | 16 | private final FileService fileService; 17 | 18 | /** 19 | * Instantiates a new File controller. 20 | * 21 | * @param fileService the File service 22 | */ 23 | @Autowired 24 | public FileController(FileService fileService) { 25 | this.fileService = fileService; 26 | } 27 | 28 | 29 | /** 30 | * 파일 업로드 31 | * 32 | * @param fileInfo 33 | * @return 34 | */ 35 | @RequestMapping(value = "/upload", method = RequestMethod.POST) 36 | public FileInfo createFileInfo(@RequestBody FileInfo fileInfo) { 37 | return fileService.createFileInfo(fileInfo); 38 | } 39 | 40 | 41 | /** 42 | * 파일 상세 조회 43 | * 44 | * @param id 45 | * @return 46 | */ 47 | @RequestMapping(value = "/{id:.+}", method = RequestMethod.GET) 48 | public FileInfo getFileInfo(@PathVariable("id") long id) { 49 | 50 | return fileService.getFileInfo(id); 51 | } 52 | 53 | /** 54 | * 파일 목록 조회 55 | * 56 | * @return the file list 57 | */ 58 | @RequestMapping(value = "", method = RequestMethod.GET) 59 | public List getFileInfoList() { 60 | // NOT USE 61 | return fileService.getFileInfoList(); 62 | } 63 | 64 | 65 | /** 66 | * 파일 다운로드 67 | * 68 | * @param id 69 | * @return 70 | */ 71 | @RequestMapping(value = "/download/{id:.+}", method = RequestMethod.POST) 72 | public FileInfo downloadFile(@PathVariable("id") long id) { 73 | FileInfo downloadFile = fileService.getFileInfo(id); 74 | return downloadFile; 75 | } 76 | 77 | 78 | /** 79 | * 파일 삭제 80 | * 81 | * @param id 82 | * @return 83 | */ 84 | @RequestMapping(value = "/{id:.+}", method = RequestMethod.DELETE) 85 | public String deleteFile(@PathVariable("id") long id) { 86 | return fileService.deleteFile(id); 87 | } 88 | 89 | } 90 | -------------------------------------------------------------------------------- /src/main/java/paasta/delivery/pipeline/common/api/domain/common/file/FileInfo.java: -------------------------------------------------------------------------------- 1 | package paasta.delivery.pipeline.common.api.domain.common.file; 2 | 3 | import org.hibernate.annotations.CreationTimestamp; 4 | 5 | import javax.persistence.*; 6 | import java.util.Date; 7 | 8 | /** 9 | * paastaDeliveryPipelineCommonApi 10 | * paasta.delivery.pipeline.common.api.file 11 | * 12 | * @author kimdojun 13 | * @version 1.0 14 | * @since 6/13/2017 15 | */ 16 | @Entity 17 | @Table(name = "file_info") 18 | public class FileInfo { 19 | 20 | @Id 21 | @GeneratedValue(strategy = GenerationType.IDENTITY) 22 | @Column(name = "id") 23 | private long id; 24 | 25 | @Column(name = "original_file_name", nullable = false) 26 | private String originalFileName; 27 | 28 | @Column(name = "stored_file_name", nullable = false) 29 | private String storedFileName; 30 | 31 | @Column(name = "file_url", nullable = false) 32 | private String fileUrl; 33 | 34 | @CreationTimestamp 35 | @Column(columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP", updatable = false) 36 | @Temporal(TemporalType.TIMESTAMP) 37 | private Date created; 38 | 39 | public long getId() { 40 | return id; 41 | } 42 | 43 | public void setId(long id) { 44 | this.id = id; 45 | } 46 | 47 | public String getOriginalFileName() { 48 | return originalFileName; 49 | } 50 | 51 | public void setOriginalFileName(String originalFileName) { 52 | this.originalFileName = originalFileName; 53 | } 54 | 55 | public String getStoredFileName() { 56 | return storedFileName; 57 | } 58 | 59 | public void setStoredFileName(String storedFileName) { 60 | this.storedFileName = storedFileName; 61 | } 62 | 63 | public String getFileUrl() { 64 | return fileUrl; 65 | } 66 | 67 | public void setFileUrl(String fileUrl) { 68 | this.fileUrl = fileUrl; 69 | } 70 | 71 | public Date getCreated() { 72 | return created; 73 | } 74 | 75 | public void setCreated(Date created) { 76 | this.created = created; 77 | } 78 | 79 | } 80 | -------------------------------------------------------------------------------- /src/main/java/paasta/delivery/pipeline/common/api/domain/common/file/FileInfoRepository.java: -------------------------------------------------------------------------------- 1 | package paasta.delivery.pipeline.common.api.domain.common.file; 2 | 3 | import org.springframework.data.jpa.repository.JpaRepository; 4 | 5 | import javax.transaction.Transactional; 6 | 7 | /** 8 | * paastaDeliveryPipelineCommonApi 9 | * paasta.delivery.pipeline.common.api.file 10 | * 11 | * @author kimdojun 12 | * @version 1.0 13 | * @since 6 /13/2017 14 | */ 15 | @Transactional 16 | public interface FileInfoRepository extends JpaRepository { 17 | 18 | FileInfo findById(long id); 19 | 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/paasta/delivery/pipeline/common/api/domain/common/file/FileService.java: -------------------------------------------------------------------------------- 1 | package paasta.delivery.pipeline.common.api.domain.common.file; 2 | 3 | import org.springframework.stereotype.Service; 4 | import paasta.delivery.pipeline.common.api.common.Constants; 5 | 6 | import java.util.List; 7 | 8 | /** 9 | * paastaDeliveryPipelineCommonApi 10 | * paasta.delivery.pipeline.common.api.file 11 | * 12 | * @author kimdojun 13 | * @version 1.0 14 | * @since 6 /13/2017 15 | */ 16 | 17 | @Service 18 | public class FileService { 19 | 20 | private final FileInfoRepository fileInfoRepository; 21 | 22 | 23 | /** 24 | * Instantiates a new Job service. 25 | * 26 | * @param fileInfoRepository the file repository 27 | */ 28 | public FileService(FileInfoRepository fileInfoRepository) { 29 | this.fileInfoRepository = fileInfoRepository; 30 | } 31 | 32 | /** 33 | * Create FileInfo. 34 | * 35 | * @param fileInfo the fileInfo 36 | * @return the fileInfo 37 | */ 38 | FileInfo createFileInfo(FileInfo fileInfo) { 39 | return fileInfoRepository.save(fileInfo); 40 | } 41 | 42 | FileInfo getFileInfo(long id) { 43 | return fileInfoRepository.findById(id); 44 | } 45 | 46 | List getFileInfoList() { 47 | return fileInfoRepository.findAll(); 48 | } 49 | 50 | public String deleteFile(long id) { 51 | fileInfoRepository.delete(id); 52 | return Constants.RESULT_STATUS_SUCCESS; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/paasta/delivery/pipeline/common/api/domain/common/init/CiInfoController.java: -------------------------------------------------------------------------------- 1 | package paasta.delivery.pipeline.common.api.domain.common.init; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.web.bind.annotation.RequestBody; 7 | import org.springframework.web.bind.annotation.RequestMapping; 8 | import org.springframework.web.bind.annotation.RequestMethod; 9 | import org.springframework.web.bind.annotation.RestController; 10 | import paasta.delivery.pipeline.common.api.domain.common.serviceInstance.CiInfo; 11 | import paasta.delivery.pipeline.common.api.domain.common.serviceInstance.CiInfoService; 12 | 13 | import java.util.List; 14 | import java.util.Map; 15 | 16 | /** 17 | * Created by hrjin on 2017-05-29. 18 | */ 19 | @RestController 20 | @RequestMapping("/serviceinit") 21 | public class CiInfoController { 22 | 23 | private final CiInfoService ciInfoService; 24 | private Logger logger = LoggerFactory.getLogger(CiInfoController.class); 25 | 26 | @Autowired 27 | public CiInfoController(CiInfoService ciInfoService) { 28 | this.ciInfoService = ciInfoService; 29 | } 30 | 31 | /* 32 | * 서비스 생성에 필요한 데이터 초기화 33 | * 34 | * */ 35 | @RequestMapping(value = "/ciinfo", method = RequestMethod.POST) 36 | public Map initCiinfo(@RequestBody List ciInfos) { 37 | return ciInfoService.initCiinfo(ciInfos); 38 | } 39 | 40 | 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/paasta/delivery/pipeline/common/api/domain/common/job/JobController.java: -------------------------------------------------------------------------------- 1 | package paasta.delivery.pipeline.common.api.domain.common.job; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.data.domain.Pageable; 5 | import org.springframework.data.domain.Sort; 6 | import org.springframework.data.web.PageableDefault; 7 | import org.springframework.web.bind.annotation.*; 8 | 9 | import java.util.List; 10 | 11 | /** 12 | * paastaDeliveryPipelineApi 13 | * paasta.delivery.pipeline.common.api.job 14 | * 15 | * @author REX 16 | * @version 1.0 17 | * @since 5 /17/2017 18 | */ 19 | @RestController 20 | public class JobController { 21 | 22 | private static final String REQ_URL = "/jobs"; 23 | private static final int PAGE_SIZE = 1000; 24 | private final JobService jobService; 25 | 26 | 27 | /** 28 | * Instantiates a new Job controller. 29 | * 30 | * @param jobService the job service 31 | */ 32 | @Autowired 33 | public JobController(JobService jobService) {this.jobService = jobService;} 34 | 35 | 36 | /** 37 | * Gets job list. 38 | * 39 | * @param pipelineId the pipeline id 40 | * @return the job list 41 | */ 42 | @RequestMapping(value = "/pipelines/{pipelineId:.+}" + REQ_URL, method = RequestMethod.GET) 43 | public List getJobList(@PathVariable("pipelineId") int pipelineId) { 44 | return jobService.getJobListByPipelineIdOrderByGroupOrderAscJobOrderAsc(pipelineId); 45 | } 46 | 47 | 48 | /** 49 | * Gets job list pageable. 50 | * 51 | * @param pageable the pageable 52 | * @param pipelineId the pipeline id 53 | * @param jobType the job type 54 | * @return the job list pageable 55 | */ 56 | @RequestMapping(value = "/pipelines/{pipelineId:.+}" + REQ_URL + "/job-types/{jobType:.+}", method = RequestMethod.GET) 57 | public List getJobListPageable(@PageableDefault(sort = "created", direction = Sort.Direction.DESC, size = PAGE_SIZE) Pageable pageable, 58 | @PathVariable("pipelineId") int pipelineId, 59 | @PathVariable("jobType") String jobType) { 60 | return jobService.getJobListPageable(pageable, pipelineId, jobType); 61 | } 62 | 63 | 64 | /** 65 | * Gets job. 66 | * 67 | * @param id the id 68 | * @return the job 69 | */ 70 | @RequestMapping(value = REQ_URL + "/{id:.+}", method = RequestMethod.GET) 71 | public Job getJob(@PathVariable("id") int id) { 72 | return jobService.getJobById(id); 73 | } 74 | 75 | 76 | /** 77 | * Gets job count by job name. 78 | * 79 | * @param pipelineId the pipeline id 80 | * @param jobName the job name 81 | * @return the job count by job name 82 | */ 83 | @RequestMapping(value = "/pipelines/{pipelineId:.+}/job-names/{jobName:.+}", method = RequestMethod.GET) 84 | public int getJobCountByJobName(@PathVariable("pipelineId") int pipelineId, @PathVariable("jobName") String jobName) { 85 | return jobService.getJobCountByJobName(pipelineId, jobName); 86 | } 87 | 88 | 89 | /** 90 | * Gets job max group order by pipeline id. 91 | * 92 | * @param pipelineId the pipeline id 93 | * @return the job max group order by pipeline id 94 | */ 95 | @RequestMapping(value = "/pipelines/{pipelineId:.+}/max-job-group-order", method = RequestMethod.GET) 96 | public int getJobMaxGroupOrderByPipelineId(@PathVariable("pipelineId") int pipelineId) { 97 | return jobService.getJobMaxGroupOrderByPipelineId(pipelineId); 98 | } 99 | 100 | 101 | /** 102 | * Create job job. 103 | * 104 | * @param job the job 105 | * @return the job 106 | */ 107 | @PostMapping(value = REQ_URL) 108 | public Job createJob(@RequestBody Job job) { 109 | return jobService.createJob(job); 110 | } 111 | 112 | 113 | /** 114 | * Update job job. 115 | * 116 | * @param job the job 117 | * @return the job 118 | */ 119 | @PutMapping(value = REQ_URL) 120 | public Job updateJob(@RequestBody Job job) { 121 | return jobService.updateJob(job); 122 | } 123 | 124 | 125 | /** 126 | * Delete job string. 127 | * 128 | * @param id the id 129 | * @return the string 130 | */ 131 | @DeleteMapping(value = REQ_URL + "/{id:.+}") 132 | public String deleteJob(@PathVariable("id") int id) { 133 | return jobService.deleteJob(id); 134 | } 135 | 136 | } 137 | -------------------------------------------------------------------------------- /src/main/java/paasta/delivery/pipeline/common/api/domain/common/job/JobRepository.java: -------------------------------------------------------------------------------- 1 | package paasta.delivery.pipeline.common.api.domain.common.job; 2 | 3 | import org.springframework.data.domain.Pageable; 4 | import org.springframework.data.jpa.repository.JpaRepository; 5 | import org.springframework.stereotype.Repository; 6 | import org.springframework.transaction.annotation.Transactional; 7 | 8 | import java.util.List; 9 | 10 | /** 11 | * paastaDeliveryPipelineApi 12 | * paasta.delivery.pipeline.common.api.job 13 | * 14 | * @author REX 15 | * @version 1.0 16 | * @since 5 /17/2017 17 | */ 18 | @Repository 19 | @Transactional 20 | public interface JobRepository extends JpaRepository { 21 | 22 | 23 | /** 24 | * Find all by pipeline id order by created desc list. 25 | * 26 | * @param pageable the pageable 27 | * @param pipelineId the pipeline id 28 | * @return the list 29 | */ 30 | List findAllByPipelineId(Pageable pageable, int pipelineId); 31 | 32 | 33 | /** 34 | * Find all by service instances id and pipeline id order by group order asc job order asc list. 35 | * 36 | * @param pipelineId the pipeline id 37 | * @return the list 38 | */ 39 | List findAllByPipelineIdOrderByGroupOrderAscJobOrderAsc(int pipelineId); 40 | 41 | 42 | /** 43 | * Find all by service instances id and pipeline id and job type list. 44 | * 45 | * @param pageable the pageable 46 | * @param pipelineId the pipeline id 47 | * @param jobType the job type 48 | * @return the list 49 | */ 50 | List findAllByPipelineIdAndJobTypeOrderByJobOrderAsc(Pageable pageable, int pipelineId, String jobType); 51 | 52 | 53 | /** 54 | * Find all by job type order by job order asc list. 55 | * 56 | * @param jobType the job type 57 | * @return the list 58 | */ 59 | List findAllByJobTypeOrderByJobOrderAsc(String jobType); 60 | 61 | 62 | /** 63 | * Count by pipeline id and job name int. 64 | * 65 | * @param pipelineId the pipeline id 66 | * @param jobName the job name 67 | * @return the int 68 | */ 69 | int countByPipelineIdAndJobName(int pipelineId, String jobName); 70 | 71 | 72 | /** 73 | * Find distinct top by pipeline id job. 74 | * 75 | * @param pipelineId the pipeline id 76 | * @return the job 77 | */ 78 | Job findDistinctTopByPipelineId(int pipelineId); 79 | 80 | } 81 | -------------------------------------------------------------------------------- /src/main/java/paasta/delivery/pipeline/common/api/domain/common/job/JobService.java: -------------------------------------------------------------------------------- 1 | package paasta.delivery.pipeline.common.api.domain.common.job; 2 | 3 | import org.springframework.data.domain.Pageable; 4 | import org.springframework.stereotype.Service; 5 | import paasta.delivery.pipeline.common.api.common.CommonService; 6 | import paasta.delivery.pipeline.common.api.common.Constants; 7 | 8 | import java.util.List; 9 | 10 | /** 11 | * paastaDeliveryPipelineApi 12 | * paasta.delivery.pipeline.common.api.job 13 | * 14 | * @author REX 15 | * @version 1.0 16 | * @since 5 /17/2017 17 | */ 18 | @Service 19 | public class JobService { 20 | 21 | private final JobRepository jobRepository; 22 | private final CommonService commonService; 23 | 24 | 25 | /** 26 | * Instantiates a new Job service. 27 | * 28 | * @param jobRepository the job repository 29 | * @param commonService the common service 30 | */ 31 | public JobService(JobRepository jobRepository, CommonService commonService) { 32 | this.jobRepository = jobRepository; 33 | this.commonService = commonService; 34 | } 35 | 36 | 37 | /** 38 | * Gets job list by pipeline id order by group order asc job order asc. 39 | * 40 | * @param pipelineId the pipeline id 41 | * @return the job list by pipeline id order by group order asc job order asc 42 | */ 43 | public List getJobListByPipelineIdOrderByGroupOrderAscJobOrderAsc(int pipelineId) { 44 | return jobRepository.findAllByPipelineIdOrderByGroupOrderAscJobOrderAsc(pipelineId); 45 | } 46 | 47 | 48 | /** 49 | * Gets job list pageable. 50 | * 51 | * @param pageable the pageable 52 | * @param pipelineId the pipeline id 53 | * @param jobType the job type 54 | * @return the job list pageable 55 | */ 56 | public List getJobListPageable(Pageable pageable, int pipelineId, String jobType) { 57 | List resultList; 58 | 59 | if (pipelineId > 0) { 60 | resultList = jobRepository.findAllByPipelineIdAndJobTypeOrderByJobOrderAsc(pageable, pipelineId, jobType); 61 | } else { 62 | resultList = jobRepository.findAllByJobTypeOrderByJobOrderAsc(jobType); 63 | } 64 | 65 | return resultList; 66 | } 67 | 68 | 69 | /** 70 | * Gets job by id. 71 | * 72 | * @param id the id 73 | * @return the job by id 74 | */ 75 | Job getJobById(int id) { 76 | Job resultModel = jobRepository.findOne((long) id); 77 | String jobType; 78 | 79 | if (null != resultModel) { 80 | jobType = resultModel.getJobType(); 81 | 82 | if (!String.valueOf(Constants.JobType.DEPLOY).equals(jobType)) { 83 | resultModel.setRepositoryAccountPassword(commonService.setPasswordByAES256(Constants.AES256Type.DECODE, resultModel.getRepositoryAccountPassword())); 84 | } 85 | } 86 | 87 | return resultModel; 88 | } 89 | 90 | 91 | /** 92 | * Gets job count by job name. 93 | * 94 | * @param pipelineId the pipeline id 95 | * @param jobName the job name 96 | * @return the job count by job name 97 | */ 98 | int getJobCountByJobName(int pipelineId, String jobName) { 99 | return jobRepository.countByPipelineIdAndJobName(pipelineId, jobName); 100 | } 101 | 102 | 103 | /** 104 | * Gets job max group order by pipeline id. 105 | * 106 | * @param pipelineId the pipeline id 107 | * @return the job max group order by pipeline id 108 | */ 109 | int getJobMaxGroupOrderByPipelineId(int pipelineId) { 110 | Job tempModel = jobRepository.findDistinctTopByPipelineId(pipelineId); 111 | int resultCount = 0; 112 | 113 | if (null != tempModel) { 114 | resultCount = Integer.parseInt(tempModel.getLastGroupOrder()); 115 | } 116 | 117 | return resultCount; 118 | } 119 | 120 | 121 | /** 122 | * Create job custom job. 123 | * 124 | * @param job the custom job 125 | * @return the custom job 126 | */ 127 | Job createJob(Job job) { 128 | if (String.valueOf(Constants.JobType.BUILD).equals(job.getJobType())) { 129 | job.setRepositoryAccountPassword(commonService.setPasswordByAES256(Constants.AES256Type.ENCODE, job.getRepositoryAccountPassword())); 130 | } 131 | 132 | return jobRepository.save(job); 133 | } 134 | 135 | 136 | /** 137 | * Update job job. 138 | * 139 | * @param job the job 140 | * @return the job 141 | */ 142 | Job updateJob(Job job) { 143 | if (String.valueOf(Constants.JobType.BUILD).equals(job.getJobType())) { 144 | job.setRepositoryAccountPassword(commonService.setPasswordByAES256(Constants.AES256Type.ENCODE, job.getRepositoryAccountPassword())); 145 | } 146 | 147 | return jobRepository.save(job); 148 | } 149 | 150 | 151 | /** 152 | * Delete job string. 153 | * 154 | * @param id the id 155 | * @return the string 156 | */ 157 | String deleteJob(int id) { 158 | jobRepository.delete((long) id); 159 | return Constants.RESULT_STATUS_SUCCESS; 160 | } 161 | 162 | } 163 | -------------------------------------------------------------------------------- /src/main/java/paasta/delivery/pipeline/common/api/domain/common/job/history/JobHistory.java: -------------------------------------------------------------------------------- 1 | package paasta.delivery.pipeline.common.api.domain.common.job.history; 2 | 3 | import org.hibernate.annotations.CreationTimestamp; 4 | import org.hibernate.annotations.Formula; 5 | import org.hibernate.annotations.UpdateTimestamp; 6 | import paasta.delivery.pipeline.common.api.common.Constants; 7 | 8 | import javax.persistence.*; 9 | import java.text.SimpleDateFormat; 10 | import java.util.Date; 11 | import java.util.Locale; 12 | 13 | /** 14 | * paastaDeliveryPipelineApi 15 | * paasta.delivery.pipeline.common.api.job.history 16 | * 17 | * @author REX 18 | * @version 1.0 19 | * @since 6/29/2017 20 | */ 21 | @Entity 22 | @Table(name = "job_history") 23 | public class JobHistory { 24 | 25 | @Id 26 | @GeneratedValue(strategy = GenerationType.IDENTITY) 27 | @Column(name = "id") 28 | private long id; 29 | 30 | @Column(name = "job_id", nullable = false) 31 | private int jobId; 32 | 33 | @Column(name = "previous_job_number", nullable = false) 34 | private int previousJobNumber; 35 | 36 | @Column(name = "job_number", nullable = false) 37 | private int jobNumber; 38 | 39 | @Column(name = "duration") 40 | private long duration; 41 | 42 | @Column(name = "status", nullable = false) 43 | private String status; 44 | 45 | @Column(name = "file_id") 46 | private long fileId; 47 | 48 | @Column(name = "trigger_type") 49 | private String triggerType; 50 | 51 | @Column(name = "user_id", nullable = false) 52 | private String userId; 53 | 54 | @CreationTimestamp 55 | @Column(columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP", updatable = false) 56 | @Temporal(TemporalType.TIMESTAMP) 57 | private Date created; 58 | 59 | @UpdateTimestamp 60 | @Column(name = "last_modified", columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP") 61 | @Temporal(TemporalType.TIMESTAMP) 62 | private Date lastModified; 63 | 64 | @Transient 65 | private String createdString; 66 | 67 | @Transient 68 | private String lastModifiedString; 69 | 70 | @Formula("(SELECT j.job_name FROM job j WHERE j.pipeline_id = " + 71 | "(SELECT j1.pipeline_id FROM job j1 WHERE j1.id = " + 72 | "(SELECT jh1.job_id FROM job_history jh1 WHERE jh1.id = id))" + 73 | " AND j.group_order = (SELECT j3.group_order FROM job j3 WHERE j3.id = " + 74 | "(SELECT jh2.job_id FROM job_history jh2 WHERE jh2.id = id))" + 75 | " AND j.job_order = (SELECT j4.job_order - 1 FROM job j4 WHERE j4.id = " + 76 | "(SELECT jh3.job_id FROM job_history jh3 WHERE jh3.id = id)))") 77 | private String previousJobName; 78 | 79 | public long getId() { 80 | return id; 81 | } 82 | 83 | public void setId(long id) { 84 | this.id = id; 85 | } 86 | 87 | public int getJobId() { 88 | return jobId; 89 | } 90 | 91 | public void setJobId(int jobId) { 92 | this.jobId = jobId; 93 | } 94 | 95 | public int getPreviousJobNumber() { 96 | return previousJobNumber; 97 | } 98 | 99 | public void setPreviousJobNumber(int previousJobNumber) { 100 | this.previousJobNumber = previousJobNumber; 101 | } 102 | 103 | public int getJobNumber() { 104 | return jobNumber; 105 | } 106 | 107 | public void setJobNumber(int jobNumber) { 108 | this.jobNumber = jobNumber; 109 | } 110 | 111 | public long getDuration() { 112 | return duration; 113 | } 114 | 115 | public void setDuration(long duration) { 116 | this.duration = duration; 117 | } 118 | 119 | public String getStatus() { 120 | return status; 121 | } 122 | 123 | public void setStatus(String status) { 124 | this.status = status; 125 | } 126 | 127 | public long getFileId() { 128 | return fileId; 129 | } 130 | 131 | public void setFileId(long fileId) { 132 | this.fileId = fileId; 133 | } 134 | 135 | public String getTriggerType() { 136 | return triggerType; 137 | } 138 | 139 | public void setTriggerType(String triggerType) { 140 | this.triggerType = triggerType; 141 | } 142 | 143 | public String getUserId() { 144 | return userId; 145 | } 146 | 147 | public void setUserId(String userId) { 148 | this.userId = userId; 149 | } 150 | 151 | public Date getCreated() { 152 | return created; 153 | } 154 | 155 | public void setCreated(Date created) { 156 | this.created = created; 157 | } 158 | 159 | public Date getLastModified() { 160 | return lastModified; 161 | } 162 | 163 | public void setLastModified(Date lastModified) { 164 | this.lastModified = lastModified; 165 | } 166 | 167 | public String getCreatedString() { 168 | return new SimpleDateFormat(Constants.STRING_DATE_TYPE, Locale.KOREA).format(created); 169 | } 170 | 171 | public void setCreatedString(String createdString) { 172 | this.createdString = createdString; 173 | } 174 | 175 | public String getLastModifiedString() { 176 | return new SimpleDateFormat(Constants.STRING_DATE_TYPE, Locale.KOREA).format(lastModified); 177 | } 178 | 179 | public void setLastModifiedString(String lastModifiedString) { 180 | this.lastModifiedString = lastModifiedString; 181 | } 182 | 183 | public String getPreviousJobName() { 184 | return previousJobName; 185 | } 186 | 187 | public void setPreviousJobName(String previousJobName) { 188 | this.previousJobName = previousJobName; 189 | } 190 | 191 | } 192 | -------------------------------------------------------------------------------- /src/main/java/paasta/delivery/pipeline/common/api/domain/common/job/history/JobHistoryController.java: -------------------------------------------------------------------------------- 1 | package paasta.delivery.pipeline.common.api.domain.common.job.history; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.data.domain.Pageable; 5 | import org.springframework.data.domain.Sort; 6 | import org.springframework.data.web.PageableDefault; 7 | import org.springframework.web.bind.annotation.*; 8 | 9 | import java.util.List; 10 | 11 | /** 12 | * paastaDeliveryPipelineApi 13 | * paasta.delivery.pipeline.common.api.job.history 14 | * 15 | * @author REX 16 | * @version 1.0 17 | * @since 6 /29/2017 18 | */ 19 | @RestController 20 | public class JobHistoryController { 21 | 22 | private static final int PAGE_SIZE = 1000; 23 | private final JobHistoryService jobHistoryService; 24 | 25 | 26 | /** 27 | * Instantiates a new Job history controller. 28 | * 29 | * @param jobHistoryService the job history service 30 | */ 31 | @Autowired 32 | public JobHistoryController(JobHistoryService jobHistoryService) {this.jobHistoryService = jobHistoryService;} 33 | 34 | 35 | /** 36 | * Gets job history list by job id. 37 | * 38 | * @param pageable the pageable 39 | * @param jobId the job id 40 | * @return the job history list by job id 41 | */ 42 | @GetMapping(value = "/jobs/{jobId:.+}/histories") 43 | public List getJobHistoryListByJobId(@PageableDefault(sort = "created", direction = Sort.Direction.DESC, size = PAGE_SIZE) Pageable pageable, 44 | @PathVariable("jobId") int jobId) { 45 | return jobHistoryService.getJobHistoryListByJobId(pageable, jobId); 46 | } 47 | 48 | 49 | /** 50 | * Gets job history by id and status. 51 | * 52 | * @param jobId the job id 53 | * @param status the status 54 | * @return the job history by id and status 55 | */ 56 | @GetMapping(value = "/jobs/{jobId:.+}/histories/status/{status:.+}/first") 57 | public JobHistory getJobHistoryByIdAndStatus(@PathVariable("jobId") int jobId, @PathVariable("status") String status) { 58 | return jobHistoryService.getFirstJobHistoryByJobIdAndStatus(jobId, status); 59 | } 60 | 61 | 62 | /** 63 | * Gets job history by id. 64 | * 65 | * @param id the id 66 | * @return the job history by id 67 | */ 68 | @GetMapping(value = "/job-histories/{id:.+}") 69 | public JobHistory getJobHistoryById(@PathVariable("id") int id) { 70 | return jobHistoryService.getJobHistoryById(id); 71 | } 72 | 73 | 74 | /** 75 | * Create job history job history. 76 | * 77 | * @param jobHistory the job history 78 | * @return the job history 79 | */ 80 | @PostMapping(value = "/job-histories") 81 | public JobHistory createJobHistory(@RequestBody JobHistory jobHistory) { 82 | return jobHistoryService.createJobHistory(jobHistory); 83 | } 84 | 85 | 86 | /** 87 | * Update job history job history. 88 | * 89 | * @param jobHistory the job history 90 | * @return the job history 91 | */ 92 | @PutMapping(value = "/job-histories") 93 | public JobHistory updateJobHistory(@RequestBody JobHistory jobHistory) { 94 | return jobHistoryService.updateJobHistory(jobHistory); 95 | } 96 | 97 | 98 | /** 99 | * Delete job history by job id string. 100 | * 101 | * @param jobId the job id 102 | * @return the string 103 | */ 104 | @DeleteMapping(value = "/jobs/{jobId:.+}/histories") 105 | public String deleteJobHistoryByJobId(@PathVariable("jobId") int jobId) { 106 | return jobHistoryService.deleteJobHistoryByJobId(jobId); 107 | } 108 | 109 | } 110 | -------------------------------------------------------------------------------- /src/main/java/paasta/delivery/pipeline/common/api/domain/common/job/history/JobHistoryRepository.java: -------------------------------------------------------------------------------- 1 | package paasta.delivery.pipeline.common.api.domain.common.job.history; 2 | 3 | import org.springframework.data.domain.Page; 4 | import org.springframework.data.domain.Pageable; 5 | import org.springframework.data.jpa.repository.JpaRepository; 6 | import org.springframework.stereotype.Repository; 7 | import org.springframework.transaction.annotation.Transactional; 8 | 9 | /** 10 | * paastaDeliveryPipelineApi 11 | * paasta.delivery.pipeline.common.api.job.history 12 | * 13 | * @author REX 14 | * @version 1.0 15 | * @since 6 /29/2017 16 | */ 17 | @Repository 18 | @Transactional 19 | public interface JobHistoryRepository extends JpaRepository { 20 | 21 | /** 22 | * Find by job id list. 23 | * 24 | * @param pageable the pageable 25 | * @param jobId the job id 26 | * @return the list 27 | */ 28 | Page findByJobId(Pageable pageable, int jobId); 29 | 30 | 31 | /** 32 | * Find first by job id order by created desc job history. 33 | * 34 | * @param jobId the job id 35 | * @return the job history 36 | */ 37 | JobHistory findFirstByJobIdOrderByCreatedDesc(int jobId); 38 | 39 | 40 | /** 41 | * Find first by job id and status order by created desc job history. 42 | * 43 | * @param jobId the job id 44 | * @param status the status 45 | * @return the job history 46 | */ 47 | JobHistory findFirstByJobIdAndStatusOrderByCreatedDesc(int jobId, String status); 48 | 49 | 50 | /** 51 | * Delete by job id. 52 | * 53 | * @param jobId the job id 54 | */ 55 | void deleteByJobId(int jobId); 56 | } 57 | -------------------------------------------------------------------------------- /src/main/java/paasta/delivery/pipeline/common/api/domain/common/job/history/JobHistoryService.java: -------------------------------------------------------------------------------- 1 | package paasta.delivery.pipeline.common.api.domain.common.job.history; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.data.domain.Pageable; 5 | import org.springframework.stereotype.Service; 6 | import paasta.delivery.pipeline.common.api.common.Constants; 7 | 8 | import java.util.List; 9 | 10 | /** 11 | * paastaDeliveryPipelineApi 12 | * paasta.delivery.pipeline.common.api.job.history 13 | * 14 | * @author REX 15 | * @version 1.0 16 | * @since 6 /29/2017 17 | */ 18 | @Service 19 | public class JobHistoryService { 20 | 21 | private final JobHistoryRepository jobHistoryRepository; 22 | 23 | 24 | /** 25 | * Instantiates a new Job history service. 26 | * 27 | * @param jobHistoryRepository the job history repository 28 | */ 29 | @Autowired 30 | public JobHistoryService(JobHistoryRepository jobHistoryRepository) {this.jobHistoryRepository = jobHistoryRepository;} 31 | 32 | 33 | /** 34 | * Gets job history list by job id. 35 | * 36 | * @param pageable the pageable 37 | * @param jobId the job id 38 | * @return the job history list by job id 39 | */ 40 | List getJobHistoryListByJobId(Pageable pageable, int jobId) { 41 | return jobHistoryRepository.findByJobId(pageable, jobId).getContent(); 42 | } 43 | 44 | 45 | /** 46 | * Gets first job history by job id and status. 47 | * 48 | * @param jobId the job id 49 | * @param status the status 50 | * @return the first job history by job id and status 51 | */ 52 | JobHistory getFirstJobHistoryByJobIdAndStatus(int jobId, String status) { 53 | JobHistory jobHistory; 54 | JobHistory resultModel = new JobHistory(); 55 | 56 | if (Constants.EMPTY_VALUE.equals(status)) { 57 | jobHistory = jobHistoryRepository.findFirstByJobIdOrderByCreatedDesc(jobId); 58 | } else { 59 | jobHistory = jobHistoryRepository.findFirstByJobIdAndStatusOrderByCreatedDesc(jobId, status); 60 | } 61 | 62 | if (jobHistory != null) { 63 | resultModel = jobHistory; 64 | } 65 | 66 | return resultModel; 67 | } 68 | 69 | 70 | /** 71 | * Gets job history. 72 | * 73 | * @param id the id 74 | * @return the job history 75 | */ 76 | JobHistory getJobHistoryById(int id) { 77 | return jobHistoryRepository.findOne(Long.valueOf(id)); 78 | } 79 | 80 | 81 | /** 82 | * Create job history custom job history. 83 | * 84 | * @param jobHistory the custom job history 85 | * @return the custom job history 86 | */ 87 | JobHistory createJobHistory(JobHistory jobHistory) { 88 | return jobHistoryRepository.save(jobHistory); 89 | } 90 | 91 | 92 | /** 93 | * Update job history custom job history. 94 | * 95 | * @param jobHistory the custom job history 96 | * @return the custom job history 97 | */ 98 | JobHistory updateJobHistory(JobHistory jobHistory) { 99 | return jobHistoryRepository.save(jobHistory); 100 | } 101 | 102 | 103 | /** 104 | * Delete job history by job id string. 105 | * 106 | * @param jobId the job id 107 | * @return the string 108 | */ 109 | String deleteJobHistoryByJobId(int jobId) { 110 | jobHistoryRepository.deleteByJobId(jobId); 111 | return Constants.RESULT_STATUS_SUCCESS; 112 | } 113 | 114 | } 115 | -------------------------------------------------------------------------------- /src/main/java/paasta/delivery/pipeline/common/api/domain/common/pipeline/Pipeline.java: -------------------------------------------------------------------------------- 1 | package paasta.delivery.pipeline.common.api.domain.common.pipeline; 2 | 3 | import com.fasterxml.jackson.annotation.JsonIgnore; 4 | import org.hibernate.annotations.CreationTimestamp; 5 | import org.hibernate.annotations.UpdateTimestamp; 6 | import paasta.delivery.pipeline.common.api.common.Constants; 7 | import paasta.delivery.pipeline.common.api.domain.common.serviceInstance.ServiceInstances; 8 | 9 | import javax.persistence.*; 10 | import java.text.SimpleDateFormat; 11 | import java.util.Date; 12 | import java.util.Locale; 13 | 14 | /** 15 | * Created by user on 2017-05-16. 16 | */ 17 | @Entity 18 | @Table(name = "pipeline") 19 | public class Pipeline { 20 | 21 | @Id 22 | @GeneratedValue(strategy = GenerationType.IDENTITY) 23 | @Column(name = "id") 24 | private Long id; 25 | 26 | @Column(name = "name", nullable = false) 27 | private String name; 28 | 29 | @Column(name = "description") 30 | private String description; 31 | 32 | @ManyToOne(fetch = FetchType.LAZY) 33 | @JoinColumn(name = "service_instances_id", nullable = true) 34 | @JsonIgnore 35 | private ServiceInstances serviceInstances; 36 | 37 | @CreationTimestamp 38 | @Column(columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP", updatable = false) 39 | @Temporal(TemporalType.TIMESTAMP) 40 | private Date created; 41 | 42 | @UpdateTimestamp 43 | @Column(name = "last_modified", columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP") 44 | @Temporal(TemporalType.TIMESTAMP) 45 | private Date lastModified; 46 | 47 | @Transient 48 | private String createdString; 49 | 50 | @Transient 51 | private String lastModifiedString; 52 | 53 | public Pipeline() { 54 | // DO NOTHING 55 | } 56 | 57 | public Pipeline(String name, String description, ServiceInstances serviceInstances) { 58 | this.name = name; 59 | this.description = description; 60 | this.serviceInstances = serviceInstances; 61 | } 62 | 63 | public Long getId() { 64 | return id; 65 | } 66 | 67 | public void setId(Long id) { 68 | this.id = id; 69 | } 70 | 71 | public String getName() { 72 | return name; 73 | } 74 | 75 | public void setName(String name) { 76 | this.name = name; 77 | } 78 | 79 | public String getDescription() { 80 | return description; 81 | } 82 | 83 | public void setDescription(String description) { 84 | this.description = description; 85 | } 86 | 87 | public Date getCreated() { 88 | return created; 89 | } 90 | 91 | public void setCreated(Date created) { 92 | this.created = created; 93 | } 94 | 95 | public Date getLastModified() { 96 | return lastModified; 97 | } 98 | 99 | public void setLastModified(Date lastModified) { 100 | this.lastModified = lastModified; 101 | } 102 | 103 | public ServiceInstances getServiceInstances() { 104 | return serviceInstances; 105 | } 106 | 107 | public void setServiceInstances(ServiceInstances serviceInstances) { 108 | this.serviceInstances = serviceInstances; 109 | } 110 | 111 | public String getCreatedString() { 112 | return new SimpleDateFormat(Constants.STRING_DATE_TYPE, Locale.KOREA).format(created); 113 | } 114 | 115 | public void setCreatedString(String createdString) { 116 | this.createdString = createdString; 117 | } 118 | 119 | public String getLastModifiedString() { 120 | return new SimpleDateFormat(Constants.STRING_DATE_TYPE, Locale.KOREA).format(lastModified); 121 | } 122 | 123 | public void setLastModifiedString(String lastModifiedString) { 124 | this.lastModifiedString = lastModifiedString; 125 | } 126 | 127 | } 128 | -------------------------------------------------------------------------------- /src/main/java/paasta/delivery/pipeline/common/api/domain/common/pipeline/PipelineController.java: -------------------------------------------------------------------------------- 1 | package paasta.delivery.pipeline.common.api.domain.common.pipeline; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.data.domain.Pageable; 5 | import org.springframework.data.domain.Sort; 6 | import org.springframework.data.web.PageableDefault; 7 | import org.springframework.web.bind.annotation.*; 8 | import paasta.delivery.pipeline.common.api.domain.common.serviceInstance.ServiceInstances; 9 | import paasta.delivery.pipeline.common.api.domain.common.serviceInstance.ServiceInstancesRepository; 10 | 11 | /** 12 | * Created by user on 2017-05-16. 13 | */ 14 | @RestController 15 | @RequestMapping("/pipeline") 16 | public class PipelineController { 17 | 18 | private static final int PAGE_SIZE = 5; 19 | private final PipelineService pipelineService; 20 | private final ServiceInstancesRepository serviceInstancesRepository; 21 | 22 | 23 | @Autowired 24 | public PipelineController(PipelineService pipelineService, ServiceInstancesRepository serviceInstancesRepository) { 25 | this.pipelineService = pipelineService; 26 | this.serviceInstancesRepository = serviceInstancesRepository; 27 | } 28 | 29 | 30 | /** 31 | * 파이프라인 전체 목록 및 검색 목록 조회 32 | * 33 | * @param suid 34 | * @param name 35 | * @param pageable 36 | * @return 37 | */ 38 | @RequestMapping(value = "/{suid}/list", method = RequestMethod.GET) 39 | public PipelineList getPipelineList(@PathVariable String suid, 40 | @RequestParam(value = "name", required = false) String name, 41 | @PageableDefault(sort = "created", direction = Sort.Direction.DESC, size = PAGE_SIZE) Pageable pageable) { 42 | 43 | return pipelineService.getPipelineList(suid, name, pageable); 44 | } 45 | 46 | 47 | 48 | /** 49 | * 파이프라인 정보 조회 50 | * 51 | * @param id 52 | * @return 53 | */ 54 | @RequestMapping(value = "/{id}", method = RequestMethod.GET) 55 | public Pipeline getPipeline(@PathVariable Long id) { 56 | Pipeline pipeline = pipelineService.getPipeline(id); 57 | return pipeline; 58 | } 59 | 60 | 61 | 62 | /** 63 | * 파이프라인 생성 64 | * 65 | * @param serviceInstancesId 66 | * @param pipeline 67 | * @return 68 | */ 69 | @RequestMapping(value = "/{serviceInstancesId}", method = RequestMethod.POST) 70 | public Pipeline createPipeline(@PathVariable String serviceInstancesId, @RequestBody Pipeline pipeline) { 71 | 72 | ServiceInstances serviceInstances = serviceInstancesRepository.findOne(serviceInstancesId); 73 | 74 | if (serviceInstances != null) { 75 | String name = pipeline.getName(); 76 | String description = pipeline.getDescription(); 77 | Pipeline newPipeline = pipelineService.createPipeline(new Pipeline(name, description, serviceInstances)); 78 | 79 | return newPipeline; 80 | } 81 | return pipelineService.getPipeline(pipeline.getId()); 82 | } 83 | 84 | 85 | 86 | /** 87 | * 파이프라인 수정 88 | * 89 | * @param id 90 | * @param pipeline 91 | * @return 92 | */ 93 | @RequestMapping(value = "/{id}", method = RequestMethod.PUT) 94 | public Pipeline updatePipeline(@PathVariable Long id, @RequestBody Pipeline pipeline) { 95 | Pipeline modifyPipeline = pipelineService.updatePipeline(id, pipeline); 96 | return modifyPipeline; 97 | } 98 | 99 | 100 | 101 | /** 102 | * 파이프라인 삭제 103 | * 104 | * @param id 105 | * @return 106 | */ 107 | @RequestMapping(value = "/{id}", method = RequestMethod.DELETE) 108 | public String deletePipeline(@PathVariable Long id) { 109 | return pipelineService.deletePipeline(id); 110 | } 111 | 112 | } 113 | -------------------------------------------------------------------------------- /src/main/java/paasta/delivery/pipeline/common/api/domain/common/pipeline/PipelineList.java: -------------------------------------------------------------------------------- 1 | package paasta.delivery.pipeline.common.api.domain.common.pipeline; 2 | 3 | import java.util.List; 4 | 5 | /** 6 | * Created by hrjin on 2017-05-25. 7 | */ 8 | public class PipelineList { 9 | int total; 10 | int start; 11 | int display; 12 | List pipelines; 13 | 14 | int page; 15 | int size; 16 | int totalPages; 17 | long totalElements; 18 | boolean isLast; 19 | 20 | public PipelineList() { 21 | // DO NOTHING 22 | } 23 | 24 | public PipelineList(List pipelines) { 25 | this.pipelines = pipelines; 26 | } 27 | 28 | public PipelineList(int total, int start, int display, List pipelines) { 29 | this.total = total; 30 | this.start = start; 31 | this.display = display; 32 | this.pipelines = pipelines; 33 | } 34 | 35 | public List getPipelines() { 36 | return pipelines; 37 | } 38 | 39 | public void setPipelines(List pipelines) { 40 | this.pipelines = pipelines; 41 | } 42 | 43 | public int getDisplay() { 44 | return display; 45 | } 46 | 47 | public void setDisplay(int display) { 48 | this.display = display; 49 | } 50 | 51 | public int getTotal() { 52 | return total; 53 | } 54 | 55 | public void setTotal(int total) { 56 | this.total = total; 57 | } 58 | 59 | public int getStart() { 60 | return start; 61 | } 62 | 63 | public void setStart(int start) { 64 | this.start = start; 65 | } 66 | 67 | public int getPage() { 68 | return page; 69 | } 70 | 71 | public void setPage(int page) { 72 | this.page = page; 73 | } 74 | 75 | public int getSize() { 76 | return size; 77 | } 78 | 79 | public void setSize(int size) { 80 | this.size = size; 81 | } 82 | 83 | public int getTotalPages() { 84 | return totalPages; 85 | } 86 | 87 | public void setTotalPages(int totalPages) { 88 | this.totalPages = totalPages; 89 | } 90 | 91 | public long getTotalElements() { 92 | return totalElements; 93 | } 94 | 95 | public void setTotalElements(long totalElements) { 96 | this.totalElements = totalElements; 97 | } 98 | 99 | public boolean isLast() { 100 | return isLast; 101 | } 102 | 103 | public void setLast(boolean last) { 104 | isLast = last; 105 | } 106 | 107 | } 108 | -------------------------------------------------------------------------------- /src/main/java/paasta/delivery/pipeline/common/api/domain/common/pipeline/PipelineRepository.java: -------------------------------------------------------------------------------- 1 | package paasta.delivery.pipeline.common.api.domain.common.pipeline; 2 | 3 | import org.springframework.data.domain.Page; 4 | import org.springframework.data.domain.Pageable; 5 | import org.springframework.data.jpa.repository.JpaRepository; 6 | import org.springframework.data.jpa.repository.JpaSpecificationExecutor; 7 | import org.springframework.stereotype.Repository; 8 | 9 | import java.util.List; 10 | 11 | /** 12 | * Created by user on 2017-05-16. 13 | */ 14 | @Repository 15 | public interface PipelineRepository extends JpaRepository, JpaSpecificationExecutor { 16 | Page findByServiceInstancesId(String suid, Pageable pageable); 17 | 18 | Page findByServiceInstancesIdAndNameContaining(String suid, String reqName, Pageable pageable); 19 | 20 | List findByServiceInstancesId(String id); 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/paasta/delivery/pipeline/common/api/domain/common/pipeline/PipelineService.java: -------------------------------------------------------------------------------- 1 | package paasta.delivery.pipeline.common.api.domain.common.pipeline; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.data.domain.Page; 7 | import org.springframework.data.domain.Pageable; 8 | import org.springframework.http.HttpMethod; 9 | import org.springframework.stereotype.Service; 10 | import org.springframework.web.bind.annotation.RequestBody; 11 | import paasta.delivery.pipeline.common.api.common.CommonService; 12 | import paasta.delivery.pipeline.common.api.common.Constants; 13 | import paasta.delivery.pipeline.common.api.common.RestTemplateService; 14 | import paasta.delivery.pipeline.common.api.domain.common.authority.GrantedAuthority; 15 | import paasta.delivery.pipeline.common.api.domain.common.authority.GrantedAuthorityService; 16 | import paasta.delivery.pipeline.common.api.domain.common.job.Job; 17 | import paasta.delivery.pipeline.common.api.domain.common.job.JobService; 18 | 19 | import java.util.List; 20 | 21 | /** 22 | * Created by user on 2017-05-18. 23 | */ 24 | @Service 25 | public class PipelineService { 26 | 27 | private static final Logger LOGGER = LoggerFactory.getLogger(PipelineService.class); 28 | private final CommonService commonService; 29 | private final JobService jobService; 30 | private final PipelineRepository pipelineRepository; 31 | private final GrantedAuthorityService grantedAuthorityService; 32 | private final RestTemplateService restTemplateService; 33 | 34 | @Autowired 35 | public PipelineService(CommonService commonService, JobService jobService, PipelineRepository pipelineRepository, GrantedAuthorityService grantedAuthorityService, RestTemplateService restTemplateService) { 36 | this.commonService = commonService; 37 | this.jobService = jobService; 38 | this.pipelineRepository = pipelineRepository; 39 | this.grantedAuthorityService = grantedAuthorityService; 40 | this.restTemplateService = restTemplateService; 41 | } 42 | 43 | 44 | public PipelineList getPipelineList(String suid, String reqName, Pageable pageable) { 45 | LOGGER.info("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"); 46 | LOGGER.info(" - PageNumber :: {}", pageable.getPageNumber()); 47 | LOGGER.info(" - PageSize :: {}", pageable.getPageSize()); 48 | LOGGER.info(" - Sort :: {}", pageable.getSort()); 49 | LOGGER.info(" - Offset :: {}", pageable.getOffset()); 50 | LOGGER.info(" - HasPrevious :: {}", pageable.hasPrevious()); 51 | LOGGER.info("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"); 52 | 53 | PipelineList resultList; 54 | Page pipelineListPage; 55 | 56 | if (reqName == null || "".equals(reqName)) { 57 | pipelineListPage = pipelineRepository.findByServiceInstancesId(suid, pageable); 58 | } else { 59 | pipelineListPage = pipelineRepository.findByServiceInstancesIdAndNameContaining(suid, reqName, pageable); 60 | } 61 | 62 | resultList = (PipelineList) commonService.setPageInfo(pipelineListPage, new PipelineList()); 63 | resultList.setPipelines(pipelineListPage.getContent()); 64 | 65 | return resultList; 66 | } 67 | 68 | 69 | public Pipeline getPipeline(Long id) { 70 | Pipeline getPipeline = pipelineRepository.findOne(id); 71 | return getPipeline; 72 | } 73 | 74 | public Pipeline createPipeline(@RequestBody Pipeline reqPipeline) { 75 | Pipeline createPipeline = pipelineRepository.save(reqPipeline); 76 | return createPipeline; 77 | } 78 | 79 | public Pipeline updatePipeline(Long id, @RequestBody Pipeline pipeline) { 80 | Pipeline modifyPipeline = pipelineRepository.findOne(id); 81 | modifyPipeline.setName(pipeline.getName()); 82 | modifyPipeline.setDescription(pipeline.getDescription()); 83 | return pipelineRepository.save(modifyPipeline); 84 | } 85 | 86 | public String deletePipeline(Long id) { 87 | 88 | List deleteGrantedAuthorities = grantedAuthorityService.findByAuthCode(id); 89 | grantedAuthorityService.deleteGrantedAuthorityRows(deleteGrantedAuthorities); 90 | 91 | pipelineRepository.delete(id); 92 | return Constants.RESULT_STATUS_SUCCESS; 93 | } 94 | 95 | public String setDeletePipeline(int pipelineId) { 96 | 97 | deletePipeline((long) pipelineId); 98 | 99 | // GET JOB LIST BY PIPELINE ID 100 | Job job = new Job(); 101 | job.setPipelineId(pipelineId); 102 | String jobType = job.getJobType(); 103 | 104 | // GETS DB JOB LIST 105 | List jobList = null; 106 | if (job.getPipelineId() != 0) { 107 | jobList = jobService.getJobListByPipelineIdOrderByGroupOrderAscJobOrderAsc(job.getPipelineId()); 108 | 109 | if (null != jobType && !"".equals(jobType)) { 110 | jobList = jobService.getJobListPageable(null, job.getPipelineId(), jobType); 111 | } 112 | } 113 | 114 | // DELETE JOB INCLUDE JOB HISTORY 115 | for (int i = 0; i < jobList.size(); i++) { 116 | long jobId = jobList.get(i).getId(); 117 | Job reqJob = new Job(); 118 | reqJob.setId(jobId); 119 | 120 | restTemplateService.send(Constants.TARGET_DELIVERY_PIPELINE_API, "/jobs/" + reqJob.getId(), HttpMethod.DELETE, null, Job.class); 121 | } 122 | 123 | return Constants.RESULT_STATUS_SUCCESS; 124 | } 125 | 126 | } 127 | -------------------------------------------------------------------------------- /src/main/java/paasta/delivery/pipeline/common/api/domain/common/project/ProjectController.java: -------------------------------------------------------------------------------- 1 | package paasta.delivery.pipeline.common.api.domain.common.project; 2 | 3 | import org.slf4j.Logger; 4 | import org.springframework.beans.factory.annotation.Autowired; 5 | import org.springframework.web.bind.annotation.*; 6 | 7 | import java.util.List; 8 | 9 | import static org.slf4j.LoggerFactory.getLogger; 10 | 11 | /** 12 | * Created by hrjin on 2017-06-23. 13 | */ 14 | @RestController 15 | @RequestMapping("/project") 16 | public class ProjectController { 17 | private final ProjectService projectService; 18 | 19 | private final Logger LOGGER = getLogger(getClass()); 20 | 21 | @Autowired 22 | public ProjectController(ProjectService projectService) { 23 | this.projectService = projectService; 24 | } 25 | 26 | 27 | @RequestMapping(value = "/projectsList", method = RequestMethod.GET) 28 | public List getProjectsList(Project project) { 29 | return projectService.getProjectsList(project); 30 | } 31 | 32 | 33 | @RequestMapping(value = "/getProject", method = RequestMethod.POST) 34 | public List getProject(@RequestBody Project project) { 35 | return projectService.getProject(project); 36 | } 37 | 38 | 39 | /** 40 | * project create 41 | * 42 | * @param project 43 | * @return project 44 | */ 45 | @RequestMapping(value = "/projectsCreate", method = RequestMethod.POST) 46 | public Project createProjects(@RequestBody Project project) { 47 | return projectService.createProjects(project); 48 | } 49 | 50 | 51 | /** 52 | * project delete 53 | * 54 | * @param project 55 | * @return project 56 | */ 57 | @RequestMapping(value = "/projectsDelete", method = RequestMethod.DELETE) 58 | public Project deleteProjects(@RequestBody Project project) { 59 | return projectService.deleteProject(project); 60 | } 61 | 62 | /** 63 | * project update 64 | * 65 | * @param project 66 | * @return project 67 | */ 68 | @RequestMapping(value = "/projectsUpdate", method = RequestMethod.PUT) 69 | public Project updateProjects(@RequestBody Project project) { 70 | // TODO 71 | // return projectService.updateProject(project); 72 | return projectService.setUpdateProject(project); 73 | } 74 | 75 | /** 76 | * QualityGate project 연결 77 | * 78 | * @param project 79 | * @return 80 | */ 81 | @RequestMapping(value = "/qualityGateProjectLiked", method = RequestMethod.PUT) 82 | public Project qualityGateProjectLiked(@RequestBody Project project) { 83 | return projectService.setqualityGateProjectLiked(project); 84 | } 85 | 86 | 87 | /** 88 | * QualityProfile project 연결 89 | * 90 | * @param project 91 | * @return 92 | */ 93 | @RequestMapping(value = "/qualityProfileProjectLiked", method = RequestMethod.PUT) 94 | public Project qualityProfileProjectLiked(@RequestBody Project project) { 95 | return projectService.qualityProfileProjectLiked(project); 96 | } 97 | 98 | /** 99 | * QualityGate 연결된 project 수정 100 | * 101 | * @param project 102 | * @return 103 | */ 104 | @RequestMapping(value = "/qualityGateDelete", method = RequestMethod.PUT) 105 | public String qualityGateDelete(@RequestBody Project project) { 106 | return projectService.qualityGateDelete(project); 107 | } 108 | 109 | /** 110 | * QualityProfile 연결된 project 수정 111 | * 112 | * @param project 113 | * @return 114 | */ 115 | @RequestMapping(value = "/qualityProfileDelete", method = RequestMethod.PUT) 116 | public String qualityProfileDelete(@RequestBody Project project) { 117 | return projectService.qualityProfileDelete(project); 118 | } 119 | 120 | 121 | /** 122 | * getProjectKey 123 | * 124 | * @param project 125 | * @return Project 126 | */ 127 | @RequestMapping(value = "/projectKey", method = RequestMethod.POST) 128 | public Project getProjectKey(@RequestBody Project project) { 129 | return projectService.getProjectKey(project); 130 | } 131 | 132 | 133 | /** 134 | * Gets project by id. 135 | * 136 | * @param id the id 137 | * @return the project by id 138 | */ 139 | @GetMapping(value = "/{id:.+}") 140 | public Project getProjectById(@PathVariable("id") int id) { 141 | return projectService.getProjectById(id); 142 | } 143 | 144 | } 145 | -------------------------------------------------------------------------------- /src/main/java/paasta/delivery/pipeline/common/api/domain/common/project/ProjectRepository.java: -------------------------------------------------------------------------------- 1 | package paasta.delivery.pipeline.common.api.domain.common.project; 2 | 3 | import org.springframework.data.jpa.repository.JpaRepository; 4 | import org.springframework.stereotype.Repository; 5 | 6 | import java.util.List; 7 | 8 | /** 9 | * Created by hrjin on 2017-06-23. 10 | */ 11 | @Repository 12 | public interface ProjectRepository extends JpaRepository { 13 | List findByserviceInstancesId(String serviceInstancesId); 14 | 15 | 16 | /** 17 | * Find all by service instances id and quality profile id order by list. 18 | * 19 | * @param serviceInstancesId , qualityProfileId 20 | * @return the list 21 | */ 22 | List findByServiceInstancesIdAndQualityProfileKey(String serviceInstancesId, String qualityProfileKey); 23 | 24 | 25 | /** 26 | * Find all by service instances id and quality gate id order by list. 27 | * 28 | * @param serviceInstancesId , qualityGateId 29 | * @return the list 30 | */ 31 | List findByServiceInstancesIdAndQualityGateId(String serviceInstancesId, int qualityGateId); 32 | 33 | 34 | /** 35 | * Find all by service instances id and pipeline id order by project. 36 | * 37 | * @param serviceInstancesId , pipelineId, jobId 38 | * @return the Project 39 | */ 40 | List findByserviceInstancesIdAndPipelineId(String serviceInstancesId, int pipelineId); 41 | 42 | 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/paasta/delivery/pipeline/common/api/domain/common/project/ProjectService.java: -------------------------------------------------------------------------------- 1 | package paasta.delivery.pipeline.common.api.domain.common.project; 2 | 3 | import org.slf4j.Logger; 4 | import org.springframework.beans.factory.annotation.Autowired; 5 | import org.springframework.stereotype.Service; 6 | import paasta.delivery.pipeline.common.api.common.Constants; 7 | 8 | import java.util.ArrayList; 9 | import java.util.List; 10 | 11 | import static org.slf4j.LoggerFactory.getLogger; 12 | 13 | /** 14 | * Created by hrjin on 2017-06-23. 15 | */ 16 | @Service 17 | public class ProjectService { 18 | private final Logger LOGGER = getLogger(getClass()); 19 | 20 | private final ProjectRepository projectRepository; 21 | 22 | @Autowired 23 | public ProjectService(ProjectRepository projectRepository) { 24 | this.projectRepository = projectRepository; 25 | } 26 | 27 | 28 | //시연후 수정 29 | public List getProjectsList(Project project) { 30 | return projectRepository.findByserviceInstancesId(project.getServiceInstancesId()); 31 | } 32 | 33 | public List getProject(Project project) { 34 | return projectRepository.findByserviceInstancesIdAndPipelineId(project.getServiceInstancesId(), project.getPipelineId()); 35 | } 36 | 37 | public Project createProjects(Project project) { 38 | return projectRepository.save(project); 39 | } 40 | 41 | public Project deleteProject(Project project) { 42 | projectRepository.delete(project.getId()); 43 | project.setResultStatus(Constants.RESULT_STATUS_SUCCESS); 44 | return project; 45 | } 46 | 47 | // TODO 48 | // public Project updateProject(Project project) { 49 | // Project result = new Project(); 50 | // result = projectRepository.findOne(project.getId()); 51 | // 52 | // result.setProjectName(project.getProjectName()); 53 | // // TODO 54 | //// result.setQualityProfileId(project.getQualityProfileId()); 55 | // result.setQualityGateId(project.getQualityGateId()); 56 | // result.setJobId(project.getJobId()); 57 | // 58 | // return projectRepository.save(result); 59 | // } 60 | 61 | 62 | public Project setqualityGateProjectLiked(Project project) { 63 | 64 | Project result = projectRepository.findOne(project.getId()); 65 | if(!project.getLinked()){ 66 | LOGGER.info("GATE REMOVE"); 67 | result.setQualityGateId(0); 68 | }else{ 69 | LOGGER.info("GATE UPDATE"); 70 | result.setQualityGateId(project.getQualityGateId()); 71 | } 72 | return projectRepository.save(result); 73 | } 74 | 75 | 76 | 77 | public Project qualityGateProjectLiked(Project project) { 78 | Project result = new Project(); 79 | if (project.getLinked().equals(false)) { 80 | project.setQualityGateId(0); 81 | } 82 | 83 | result = projectRepository.findOne(project.getId()); 84 | 85 | return projectRepository.save(result); 86 | } 87 | 88 | 89 | 90 | public Project qualityProfileProjectLiked(Project project) { 91 | Project result = new Project(); 92 | LOGGER.info("COMMON : " + project.getId());; 93 | result = projectRepository.findOne(project.getId()); 94 | //result.setQualityProfileKey(project.getQualityProfileKey()); 95 | 96 | return projectRepository.save(result); 97 | } 98 | 99 | public String qualityProfileDelete(Project project) { 100 | // TODO 101 | project.setId(1L); 102 | // List result = new ArrayList<>(); 103 | // int profileId = (int)(long)project.getId(); 104 | // project.setQualityProfileId(profileId); 105 | // result = projectRepository.findByServiceInstancesIdAndQualityProfileId(project.getServiceInstancesId(), project.getQualityProfileId()); 106 | // 107 | // if(result.size() > 0){ 108 | // for(int i=0;i result = new ArrayList<>(); 119 | int gateId = (int) (long) project.getId(); 120 | project.setQualityGateId(gateId); 121 | 122 | result = projectRepository.findByServiceInstancesIdAndQualityGateId(project.getServiceInstancesId(), project.getQualityGateId()); 123 | 124 | if (result.size() > 0) { 125 | for (int i = 0; i < result.size(); i++) { 126 | result.get(i).setQualityGateId(0); 127 | projectRepository.save(result.get(i)); 128 | } 129 | } 130 | return Constants.RESULT_STATUS_SUCCESS; 131 | } 132 | 133 | //projectKey 값 가져오기 134 | public Project getProjectKey(Project project) { 135 | return projectRepository.findOne(project.getId()); 136 | } 137 | 138 | 139 | /** 140 | * Sets update project. 141 | * 142 | * @param project the project 143 | * @return the update project 144 | */ 145 | Project setUpdateProject(Project project) { 146 | Project projectDetail = projectRepository.findOne(project.getId()); 147 | 148 | projectDetail.setQualityProfileKey(project.getQualityProfileKey()); 149 | projectDetail.setQualityGateId(project.getQualityGateId()); 150 | projectDetail.setJobId(project.getJobId()); 151 | 152 | return projectRepository.save(projectDetail); 153 | } 154 | 155 | 156 | /** 157 | * Get project by id project. 158 | * 159 | * @param id the id 160 | * @return the project 161 | */ 162 | Project getProjectById(long id) { 163 | return projectRepository.findOne(id); 164 | } 165 | 166 | } 167 | -------------------------------------------------------------------------------- /src/main/java/paasta/delivery/pipeline/common/api/domain/common/qualityGate/QualityGate.java: -------------------------------------------------------------------------------- 1 | package paasta.delivery.pipeline.common.api.domain.common.qualityGate; 2 | 3 | import org.hibernate.annotations.CreationTimestamp; 4 | import org.hibernate.annotations.UpdateTimestamp; 5 | import paasta.delivery.pipeline.common.api.common.Constants; 6 | 7 | import javax.persistence.*; 8 | import java.text.SimpleDateFormat; 9 | import java.util.Date; 10 | import java.util.List; 11 | import java.util.Locale; 12 | 13 | /** 14 | * Created by hrjin on 2017-06-22. 15 | */ 16 | @Entity 17 | @Table(name = "quality_gate") 18 | public class QualityGate { 19 | 20 | @Id 21 | @GeneratedValue(strategy = GenerationType.IDENTITY) 22 | @Column(name = "id") 23 | private long id; // pid 24 | 25 | @Column(name = "service_instances_id", nullable = false) 26 | private String serviceInstancesId; 27 | 28 | // sonarqube에서 자동증가 되는 값을 리턴해주는데 이 값을 id 에 넣어줌. 29 | @Column(name = "quality_gate_id", nullable = false) 30 | private int qualityGateId; // id -> qualityGateId 31 | 32 | @Column(name = "quality_gate_name", nullable = false) 33 | private String qualityGateName; // name -> qualityGateName 34 | 35 | @Column(name = "gate_default_yn", nullable = false) 36 | private String gateDefaultYn; 37 | 38 | @CreationTimestamp 39 | @Column(columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP", updatable = false) 40 | @Temporal(TemporalType.TIMESTAMP) 41 | private Date created; 42 | 43 | @UpdateTimestamp 44 | @Column(name = "last_modified", columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP") 45 | @Temporal(TemporalType.TIMESTAMP) 46 | private Date lastModified; 47 | 48 | @Transient 49 | private String createdString; 50 | 51 | @Transient 52 | private String lastModifiedString; 53 | 54 | @Transient 55 | private List projectIdList; 56 | 57 | public long getId() { 58 | return id; 59 | } 60 | 61 | public void setId(long id) { 62 | this.id = id; 63 | } 64 | 65 | public String getServiceInstancesId() { 66 | return serviceInstancesId; 67 | } 68 | 69 | public void setServiceInstancesId(String serviceInstancesId) { 70 | this.serviceInstancesId = serviceInstancesId; 71 | } 72 | 73 | public int getQualityGateId() { 74 | return qualityGateId; 75 | } 76 | 77 | public void setQualityGateId(int qualityGateId) { 78 | this.qualityGateId = qualityGateId; 79 | } 80 | 81 | public String getQualityGateName() { 82 | return qualityGateName; 83 | } 84 | 85 | public void setQualityGateName(String qualityGateName) { 86 | this.qualityGateName = qualityGateName; 87 | } 88 | 89 | public String getGateDefaultYn() { 90 | return gateDefaultYn; 91 | } 92 | 93 | public void setGateDefaultYn(String gateDefaultYn) { 94 | this.gateDefaultYn = gateDefaultYn; 95 | } 96 | 97 | public Date getCreated() { 98 | return created; 99 | } 100 | 101 | public void setCreated(Date created) { 102 | this.created = created; 103 | } 104 | 105 | public Date getLastModified() { 106 | return lastModified; 107 | } 108 | 109 | public void setLastModified(Date lastModified) { 110 | this.lastModified = lastModified; 111 | } 112 | 113 | public String getCreatedString() { 114 | return (created != null) ? new SimpleDateFormat(Constants.STRING_DATE_TYPE, Locale.KOREA).format(created) : null; 115 | } 116 | 117 | public void setCreatedString(String createdString) { 118 | this.createdString = createdString; 119 | } 120 | 121 | public String getLastModifiedString() { 122 | return (lastModified != null) ? new SimpleDateFormat(Constants.STRING_DATE_TYPE, Locale.KOREA).format(lastModified) : null; 123 | } 124 | 125 | public void setLastModifiedString(String lastModifiedString) { 126 | this.lastModifiedString = lastModifiedString; 127 | } 128 | 129 | public List getProjectIdList() { 130 | return projectIdList; 131 | } 132 | 133 | public void setProjectIdList(List projectIdList) { 134 | this.projectIdList = projectIdList; 135 | } 136 | 137 | } 138 | -------------------------------------------------------------------------------- /src/main/java/paasta/delivery/pipeline/common/api/domain/common/qualityGate/QualityGateController.java: -------------------------------------------------------------------------------- 1 | package paasta.delivery.pipeline.common.api.domain.common.qualityGate; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.web.bind.annotation.*; 5 | 6 | 7 | import java.util.List; 8 | 9 | /** 10 | * Created by hrjin on 2017-06-22. 11 | */ 12 | 13 | @RestController 14 | @RequestMapping("/qualityGate") 15 | public class QualityGateController { 16 | private final QualityGateService qualityGateService; 17 | 18 | @Autowired 19 | public QualityGateController(QualityGateService qualityGateService) { 20 | this.qualityGateService = qualityGateService; 21 | } 22 | 23 | 24 | 25 | 26 | 27 | /** 28 | * QualityGate 목록 조회 -> sona에서 정보 추출로 변경 29 | * 30 | * @return QualityGate List 31 | */ 32 | // @RequestMapping(value = "/qualityGateList", method = RequestMethod.GET) 33 | // public List getQualityGateList(@RequestParam String serviceInstancesId) { 34 | // return qualityGateService.getQualityGateList(serviceInstancesId); 35 | // } 36 | 37 | 38 | /** 39 | * QualityGate 조건리스트 40 | * 41 | * @param qualityGate 42 | * @param qualityGate 43 | * @return 44 | */ 45 | // @RequestMapping(value = "", method = RequestMethod.GET) 46 | // public QualityGate getQualityGateCondition(@RequestBody QualityGate qualityGate){ 47 | // 48 | // } 49 | 50 | 51 | /** 52 | * QualityGate 복제 53 | * 54 | * @param qualityGate 55 | * @param qualityGate 56 | * @return 57 | */ 58 | @RequestMapping(value = "/qualityGateCopy", method = RequestMethod.POST) 59 | public QualityGate copyQualityGate(@RequestBody QualityGate qualityGate) { 60 | return qualityGateService.copyQualityGate(qualityGate); 61 | } 62 | 63 | 64 | /** 65 | * QualityGate 생성 66 | * 67 | * @param reqQualityGate 68 | * @return QualityGate 69 | */ 70 | @RequestMapping(value = "/qualityGateCreate", method = RequestMethod.POST) 71 | public QualityGate createQualityGate(@RequestBody QualityGate reqQualityGate) { 72 | QualityGate newQualityGate = qualityGateService.createQualityGate(reqQualityGate); 73 | return newQualityGate; 74 | } 75 | 76 | /** 77 | * QualityGate 수정 78 | * 79 | * @param 80 | * @param 81 | * @return 82 | */ 83 | @RequestMapping(value = "/qualityGateUpdate", method = RequestMethod.PUT) 84 | public QualityGate updateQualityGate(@RequestBody QualityGate qualityGate) { 85 | QualityGate updateQualityGate = qualityGateService.updateQualityGate(qualityGate); 86 | return updateQualityGate; 87 | } 88 | 89 | 90 | /** 91 | * QualityGate 삭제 92 | * 93 | * @param 94 | * @return delete success message 95 | */ 96 | @RequestMapping(value = "/qualityGateDelete", method = RequestMethod.DELETE) 97 | public String deleteQualityGate(@RequestBody QualityGate qualityGate) { 98 | return qualityGateService.deleteQualityGate(qualityGate); 99 | } 100 | 101 | /* @RequestMapping(value = "/qualityGateDefaultSetting", method = RequestMethod.PUT) 102 | public String qualityGateDefaultSetting(@RequestBody QualityGate qualityGate){ 103 | return qualityGateService.qualityGateDefaultSetting(qualityGate); 104 | }*/ 105 | 106 | @RequestMapping(value = "/getQualityGate" , method = RequestMethod.GET) 107 | public QualityGate getQualityGate(long id){ 108 | return qualityGateService.getQualityGate(id); 109 | } 110 | 111 | } 112 | -------------------------------------------------------------------------------- /src/main/java/paasta/delivery/pipeline/common/api/domain/common/qualityGate/QualityGateRepository.java: -------------------------------------------------------------------------------- 1 | package paasta.delivery.pipeline.common.api.domain.common.qualityGate; 2 | 3 | 4 | import org.springframework.data.jpa.repository.JpaRepository; 5 | import org.springframework.stereotype.Repository; 6 | 7 | import java.util.List; 8 | 9 | /** 10 | * Created by hrjin on 2017-06-22. 11 | */ 12 | @Repository 13 | public interface QualityGateRepository extends JpaRepository { 14 | 15 | /** 16 | * Find all by service instances id order by list. 17 | * 18 | * @param serviceInstancesId 19 | * @return the list 20 | */ 21 | List findByserviceInstancesIdOrGateDefaultYn(String serviceInstancesId,String defaultYn); 22 | 23 | /** 24 | * Find all by service instances id order by list. 25 | * 26 | * @param serviceInstancesId 27 | * @return the QualityGate 28 | */ 29 | QualityGate findByServiceInstancesIdAndGateDefaultYn(String serviceInstancesId,String defaultYn); 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/paasta/delivery/pipeline/common/api/domain/common/qualityGate/QualityGateService.java: -------------------------------------------------------------------------------- 1 | package paasta.delivery.pipeline.common.api.domain.common.qualityGate; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.stereotype.Service; 5 | import paasta.delivery.pipeline.common.api.common.Constants; 6 | 7 | import java.util.List; 8 | 9 | /** 10 | * Created by hrjin on 2017-06-22. 11 | */ 12 | @Service 13 | public class QualityGateService { 14 | 15 | private final QualityGateRepository qualityGateRepository; 16 | 17 | @Autowired 18 | public QualityGateService(QualityGateRepository qualityGateRepository) { 19 | this.qualityGateRepository = qualityGateRepository; 20 | 21 | } 22 | 23 | 24 | public QualityGate createQualityGate(QualityGate reqQualityGate) { 25 | return qualityGateRepository.save(reqQualityGate); 26 | } 27 | 28 | 29 | public QualityGate getQualityGate(long id) { 30 | return qualityGateRepository.findOne(id); 31 | } 32 | 33 | 34 | ////////////////////////////////////////////////// 35 | // public List getQualityGateList(String serviceInstancesId) { 36 | // return qualityGateRepository.findAllByserviceInstancesId(serviceInstancesId); 37 | // } 38 | 39 | public List getQualityGateList(String serviceInstancesId) { 40 | QualityGate param = new QualityGate(); 41 | param.setGateDefaultYn("Y"); 42 | return qualityGateRepository.findByserviceInstancesIdOrGateDefaultYn(serviceInstancesId, param.getGateDefaultYn()); 43 | } 44 | 45 | public QualityGate copyQualityGate(QualityGate qualityGate) { 46 | return qualityGateRepository.save(qualityGate); 47 | } 48 | 49 | public QualityGate updateQualityGate(QualityGate qualityGate) { 50 | /* QualityGate result = new QualityGate(); 51 | result = qualityGateRepository.findOne(qualityGate.getId()); 52 | result.setName(qualityGate.getName());*/ 53 | return qualityGateRepository.save(qualityGate); 54 | } 55 | 56 | 57 | public String deleteQualityGate(QualityGate qualityGate) { 58 | qualityGateRepository.delete(qualityGate.getId()); 59 | 60 | return Constants.RESULT_STATUS_SUCCESS; 61 | } 62 | 63 | //기본 셋팅은 쓰지 않는걸로 결정 64 | /* public String qualityGateDefaultSetting(QualityGate qualityGate){ 65 | //삭제예정 66 | QualityGate result = new QualityGate(); 67 | result.setGateDefaultYn("Y"); 68 | result.setServiceInstancesId(qualityGate.getServiceInstancesId()); 69 | result = qualityGateRepository.findByServiceInstancesIdAndGateDefaultYn(result.getServiceInstancesId(),result.getGateDefaultYn()); 70 | 71 | if(result != null){ 72 | result.setGateDefaultYn("N"); 73 | qualityGateRepository.save(result); 74 | } 75 | 76 | 77 | result = qualityGateRepository.findOne(qualityGate.getId()); 78 | result.setGateDefaultYn("Y"); 79 | qualityGateRepository.save(result); 80 | 81 | return Constants.RESULT_STATUS_SUCCESS; 82 | }*/ 83 | 84 | 85 | } 86 | -------------------------------------------------------------------------------- /src/main/java/paasta/delivery/pipeline/common/api/domain/common/qualityProfile/QualityProfileController.java: -------------------------------------------------------------------------------- 1 | package paasta.delivery.pipeline.common.api.domain.common.qualityProfile; 2 | 3 | 4 | import org.springframework.beans.factory.annotation.Autowired; 5 | import org.springframework.web.bind.annotation.*; 6 | import paasta.delivery.pipeline.common.api.domain.common.qualityGate.QualityGate; 7 | 8 | import java.util.List; 9 | 10 | /** 11 | * Created by hrjin on 2017-06-26. 12 | */ 13 | 14 | @RestController 15 | @RequestMapping("/qualityProfile") 16 | public class QualityProfileController { 17 | private final QualityProfileService qualityProfileService; 18 | 19 | 20 | @Autowired 21 | public QualityProfileController(QualityProfileService qualityProfileService) { 22 | this.qualityProfileService = qualityProfileService; 23 | 24 | } 25 | 26 | 27 | 28 | /** 29 | * QualityProfile 목록 조회 30 | * 31 | * @return 32 | */ 33 | @RequestMapping(value = "/qualityProfileList", method = RequestMethod.GET) 34 | public List getQualityProfileList(String serviceInstancesId) { 35 | return qualityProfileService.getQualityProfileList(serviceInstancesId); 36 | } 37 | 38 | 39 | /** 40 | * QualityProfile 생성 41 | * 42 | * @param qualityProfile 43 | * @return 44 | */ 45 | @RequestMapping(value = "/qualityProfilCreate", method = RequestMethod.POST) 46 | public QualityProfile createQualityProfile(@RequestBody QualityProfile qualityProfile) { 47 | QualityProfile newQualityProfile = qualityProfileService.createQualityProfile(qualityProfile); 48 | return newQualityProfile; 49 | } 50 | 51 | /** 52 | * QualityProfile 복제 53 | * 54 | * @return 55 | */ 56 | @RequestMapping(value = "/qualityProfileCopy", method = RequestMethod.POST) 57 | public QualityProfile qualityProfileCopy(@RequestBody QualityProfile qualityProfile) { 58 | return qualityProfileService.qualityProfileCopy(qualityProfile); 59 | } 60 | 61 | /** 62 | * QualityProfile 삭제 63 | * 64 | * @return 65 | */ 66 | @RequestMapping(value = "/qualityProfileDelete", method = RequestMethod.DELETE) 67 | public String deleteQualityProfile(@RequestBody QualityProfile qualityProfile) { 68 | return qualityProfileService.deleteQualityProfile(qualityProfile); 69 | } 70 | 71 | /** 72 | * QualityProfile 수정 73 | * 74 | * @return 75 | */ 76 | @RequestMapping(value = "/qualityProfileUpdate", method = RequestMethod.PUT) 77 | public QualityProfile updateQualityProfile(@RequestBody QualityProfile qualityProfile) { 78 | return qualityProfileService.updateQualityProfile(qualityProfile); 79 | } 80 | 81 | /** 82 | * QualityProfile default Setting 83 | * 84 | * @return 85 | */ 86 | /* 87 | @RequestMapping(value = "/qualityProfilDefaultSetting",method = RequestMethod.PUT) 88 | public String qualityProfileDefaultSetting(@RequestBody QualityProfile qualityProfile){ 89 | return qualityProfileService.qualityProfileDefaultSetting(qualityProfile); 90 | } 91 | */ 92 | 93 | 94 | @RequestMapping(value = "/getQualityProfile" ,method = RequestMethod.GET) 95 | public QualityProfile getQualityProfile(long id){ 96 | return qualityProfileService.getQualityProfile(id); 97 | } 98 | 99 | 100 | } 101 | -------------------------------------------------------------------------------- /src/main/java/paasta/delivery/pipeline/common/api/domain/common/qualityProfile/QualityProfileRepository.java: -------------------------------------------------------------------------------- 1 | package paasta.delivery.pipeline.common.api.domain.common.qualityProfile; 2 | 3 | import org.springframework.data.jpa.repository.JpaRepository; 4 | import org.springframework.stereotype.Repository; 5 | 6 | import java.util.List; 7 | 8 | 9 | /** 10 | * Created by hrjin on 2017-06-26. 11 | */ 12 | 13 | @Repository 14 | public interface QualityProfileRepository extends JpaRepository { 15 | 16 | 17 | /** 18 | * Find all by service instances id and quality profile default order by list. 19 | * 20 | * @param serviceInstancesId 21 | * @return the list 22 | */ 23 | List findAllByserviceInstancesIdOrProfileDefaultYn(String serviceInstancesId, String defaultYn); 24 | 25 | } 26 | 27 | -------------------------------------------------------------------------------- /src/main/java/paasta/delivery/pipeline/common/api/domain/common/qualityProfile/QualityProfileService.java: -------------------------------------------------------------------------------- 1 | package paasta.delivery.pipeline.common.api.domain.common.qualityProfile; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.stereotype.Service; 5 | import paasta.delivery.pipeline.common.api.common.Constants; 6 | 7 | import java.util.List; 8 | 9 | /** 10 | * Created by hrjin on 2017-06-26. 11 | */ 12 | @Service 13 | public class QualityProfileService { 14 | private final QualityProfileRepository qualityProfileRepository; 15 | 16 | 17 | @Autowired 18 | public QualityProfileService(QualityProfileRepository qualityProfileRepository) { 19 | this.qualityProfileRepository = qualityProfileRepository; 20 | } 21 | 22 | public QualityProfile createQualityProfile(QualityProfile qualityProfile) { 23 | return qualityProfileRepository.save(qualityProfile); 24 | } 25 | 26 | 27 | public List getQualityProfileList(String serviceInstancesId) { 28 | QualityProfile qualityProfile = new QualityProfile(); 29 | qualityProfile.setProfileDefaultYn("Y"); 30 | qualityProfile.setServiceInstancesId(serviceInstancesId); 31 | return qualityProfileRepository.findAllByserviceInstancesIdOrProfileDefaultYn(qualityProfile.getServiceInstancesId(), qualityProfile.getProfileDefaultYn()); 32 | } 33 | 34 | 35 | /** 36 | * QualityProfile 복제 37 | * 38 | * @return 39 | */ 40 | public QualityProfile qualityProfileCopy(QualityProfile qualityProfile) { 41 | return qualityProfileRepository.save(qualityProfile); 42 | } 43 | 44 | /** 45 | * QualityProfile 삭제 46 | * 47 | * @return 48 | */ 49 | public String deleteQualityProfile(QualityProfile qualityProfile) { 50 | 51 | qualityProfileRepository.delete(qualityProfile.getId()); 52 | return Constants.RESULT_STATUS_SUCCESS; 53 | } 54 | 55 | /** 56 | * QualityProfile 수정 57 | * 58 | * @return 59 | */ 60 | public QualityProfile updateQualityProfile(QualityProfile qualityProfile) { 61 | /* QualityProfile result = new QualityProfile(); 62 | result = qualityProfileRepository.findOne(qualityProfile.getId()); 63 | result.setName(qualityProfile.getName());*/ 64 | return qualityProfileRepository.save(qualityProfile); 65 | } 66 | 67 | /** 68 | * QualityProfile default Setting 69 | * 70 | * @return 71 | */ 72 | /* public String qualityProfileDefaultSetting(QualityProfile qualityProfile){ 73 | QualityProfile result = new QualityProfile(); 74 | 75 | result.setProfileDefaultYn("Y"); 76 | result.setServiceInstancesId(qualityProfile.getServiceInstancesId()); 77 | 78 | 79 | result = qualityProfileRepository.findOne(qualityProfile.getId()); 80 | result.setProfileDefaultYn("N"); 81 | qualityProfileRepository.save(result); 82 | return Constants.RESULT_STATUS_SUCCESS; 83 | }*/ 84 | public QualityProfile getQualityProfile(long id) { 85 | return qualityProfileRepository.findOne(id); 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /src/main/java/paasta/delivery/pipeline/common/api/domain/common/serviceInstance/CiInfo.java: -------------------------------------------------------------------------------- 1 | package paasta.delivery.pipeline.common.api.domain.common.serviceInstance; 2 | 3 | import javax.persistence.*; 4 | 5 | /** 6 | * Created by hrjin on 2017-05-29. 7 | */ 8 | @Entity 9 | @Table(name = "ci_info") 10 | public class CiInfo { 11 | 12 | @Id 13 | @GeneratedValue(strategy = GenerationType.IDENTITY) 14 | @Column(name = "id") 15 | private Long id; 16 | 17 | @Column(name = "server_url") 18 | private String serverUrl; 19 | 20 | @Column(name = "used_count") 21 | private int usedcount; 22 | 23 | @Column(name = "type") 24 | private String type; 25 | 26 | @Column(name = "status") 27 | private String status; 28 | 29 | public CiInfo() { 30 | // DO NOTHING 31 | } 32 | 33 | public Long getId() { 34 | return id; 35 | } 36 | 37 | public void setId(Long id) { 38 | this.id = id; 39 | } 40 | 41 | public String getServerUrl() { 42 | return serverUrl; 43 | } 44 | 45 | public void setServerUrl(String serverUrl) { 46 | this.serverUrl = serverUrl; 47 | } 48 | 49 | public int getUsedcount() { 50 | return usedcount; 51 | } 52 | 53 | public void setUsedcount(int usedcount) { 54 | this.usedcount = usedcount; 55 | } 56 | 57 | public String getType() { 58 | return type; 59 | } 60 | 61 | public void setType(String type) { 62 | this.type = type; 63 | } 64 | 65 | public String getStatus() { 66 | return status; 67 | } 68 | 69 | public void setStatus(String status) { 70 | this.status = status; 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /src/main/java/paasta/delivery/pipeline/common/api/domain/common/serviceInstance/CiInfoRepository.java: -------------------------------------------------------------------------------- 1 | package paasta.delivery.pipeline.common.api.domain.common.serviceInstance; 2 | 3 | import org.springframework.data.jpa.repository.JpaRepository; 4 | import org.springframework.stereotype.Repository; 5 | 6 | import java.util.List; 7 | 8 | /** 9 | * Created by hrjin on 2017-05-29. 10 | */ 11 | @Repository 12 | public interface CiInfoRepository extends JpaRepository { 13 | 14 | List findByStatusAndTypeOrderByUsedcount(String status, String type); 15 | 16 | List findByTypeOrderByUsedcount(String type); 17 | 18 | CiInfo findByServerUrl(String serverUrl); 19 | 20 | List findByServerUrlNotIn(List serverUrls); 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/paasta/delivery/pipeline/common/api/domain/common/serviceInstance/CiInfoService.java: -------------------------------------------------------------------------------- 1 | package paasta.delivery.pipeline.common.api.domain.common.serviceInstance; 2 | 3 | import org.slf4j.Logger; 4 | import org.springframework.beans.factory.annotation.Autowired; 5 | import org.springframework.stereotype.Service; 6 | 7 | import java.util.ArrayList; 8 | import java.util.HashMap; 9 | import java.util.List; 10 | import java.util.Map; 11 | 12 | import static org.slf4j.LoggerFactory.getLogger; 13 | 14 | /** 15 | * Created by hrjin on 2017-05-29. 16 | */ 17 | @Service 18 | public class CiInfoService { 19 | 20 | private final Logger logger = getLogger(getClass()); 21 | private static final String DEDICATED = "Dedicated"; 22 | private final CiInfoRepository ciInfoRepository; 23 | private static final String NOT_USED_SERVER = "N"; 24 | 25 | 26 | @Autowired 27 | public CiInfoService(CiInfoRepository ciInfoRepository) { 28 | this.ciInfoRepository = ciInfoRepository; 29 | } 30 | 31 | public Map initCiinfo(List ciInfos) { 32 | List register = new ArrayList<>(); 33 | List remove = new ArrayList<>(); 34 | List serverUrls = new ArrayList<>(); 35 | /* 36 | * 1. 등록 된 Ci정보가 있는 확인 37 | * 2. 있으면, 업데이트 38 | * 3. 없으면, 등록 39 | * 4. 그리고 남은 애들 삭제 40 | */ 41 | 42 | for (CiInfo data : ciInfos) { 43 | Map initStatus = new HashMap(); 44 | serverUrls.add(data.getServerUrl()); 45 | initStatus.put("serverUrl", data.getServerUrl()); 46 | initStatus.put("type", data.getType()); 47 | CiInfo ciInfo = null; 48 | try { 49 | ciInfo = ciInfoRepository.findByServerUrl(data.getServerUrl()); 50 | } catch (Exception e) { 51 | continue; 52 | } 53 | try { 54 | 55 | if (ciInfo != null) { 56 | initStatus.put("process", "Update"); 57 | ciInfo.setType(data.getType()); 58 | ciInfoRepository.save(ciInfo); 59 | } else { 60 | initStatus.put("process", "Insert"); 61 | data.setUsedcount(0); 62 | data.setStatus("N"); 63 | ciInfoRepository.save(data); 64 | } 65 | 66 | initStatus.put("status", "SUCCESS"); 67 | } catch (Exception e) { 68 | e.printStackTrace(); 69 | initStatus.put("status", "FAIL"); 70 | } 71 | register.add(initStatus); 72 | } 73 | /* 74 | * 전체 데이터 삭제.... 75 | */ 76 | if (serverUrls.size() == 0) { 77 | serverUrls.add(""); 78 | } 79 | 80 | List deleteServcerList = ciInfoRepository.findByServerUrlNotIn(serverUrls); 81 | for (CiInfo data : deleteServcerList) { 82 | Map removeStatus = new HashMap(); 83 | removeStatus.put("serverUrl", data.getServerUrl()); 84 | removeStatus.put("type", data.getType()); 85 | removeStatus.put("process", "Remove"); 86 | try { 87 | logger.info(data.getId() + " " + data.getServerUrl()); 88 | ciInfoRepository.delete(data.getId()); 89 | removeStatus.put("status", "SUCCESS"); 90 | } catch (Exception e) { 91 | e.printStackTrace(); 92 | removeStatus.put("status", "FAIL"); 93 | } 94 | remove.add(removeStatus); 95 | } 96 | 97 | Map result = new HashMap(); 98 | result.put("register", register); 99 | result.put("remove", remove); 100 | return result; 101 | } 102 | 103 | 104 | public CiInfo getNotUsedCfinfo(String type) { 105 | 106 | List ciInfos; 107 | if (type.equals(DEDICATED)) { 108 | ciInfos = ciInfoRepository.findByStatusAndTypeOrderByUsedcount(NOT_USED_SERVER, type); 109 | } else { 110 | ciInfos = ciInfoRepository.findByTypeOrderByUsedcount(type); 111 | } 112 | 113 | 114 | if (ciInfos.size() > 0) { 115 | return ciInfos.get(0); 116 | } else { 117 | return null; 118 | } 119 | } 120 | 121 | public boolean update(CiInfo ciInfo) { 122 | ciInfoRepository.save(ciInfo); 123 | return true; 124 | } 125 | 126 | public boolean recovery(String serverUrl) { 127 | try { 128 | CiInfo ciInfo = ciInfoRepository.findByServerUrl(serverUrl); 129 | if (ciInfo != null) { 130 | ciInfo.setStatus(NOT_USED_SERVER); 131 | ciInfoRepository.save(ciInfo); 132 | } 133 | } catch (Exception e) { 134 | logger.error("Exception :: {}", e); 135 | 136 | } 137 | return true; 138 | } 139 | 140 | } 141 | -------------------------------------------------------------------------------- /src/main/java/paasta/delivery/pipeline/common/api/domain/common/serviceInstance/InstanceUse.java: -------------------------------------------------------------------------------- 1 | package paasta.delivery.pipeline.common.api.domain.common.serviceInstance; 2 | 3 | import paasta.delivery.pipeline.common.api.domain.common.authority.GrantedAuthority; 4 | import paasta.delivery.pipeline.common.api.domain.common.user.User; 5 | 6 | import javax.persistence.*; 7 | import java.util.List; 8 | 9 | /** 10 | * Created by hrjin on 2017-05-29. 11 | */ 12 | @Entity 13 | @Table(name = "instance_use") 14 | public class InstanceUse { 15 | @Id 16 | @GeneratedValue(strategy = GenerationType.IDENTITY) 17 | @Column(name = "id") 18 | private Long id; 19 | 20 | @Transient 21 | private String userDescription; 22 | @Transient 23 | private String authListStr; 24 | 25 | @Transient 26 | private Long pipelineId; 27 | 28 | @ManyToOne 29 | @JoinColumn(name = "service_instances_id", nullable = false) 30 | private ServiceInstances serviceInstances; 31 | 32 | @ManyToOne 33 | @JoinColumn(name = "user_id", nullable = false) 34 | private User user; 35 | 36 | @OneToMany(targetEntity = GrantedAuthority.class) 37 | @JoinColumn(name = "instance_use_id") 38 | private List grantedAuthorities; 39 | 40 | public InstanceUse() { 41 | // DO NOTHING 42 | } 43 | 44 | public InstanceUse(ServiceInstances serviceInstances, User user) { 45 | this.serviceInstances = serviceInstances; 46 | this.user = user; 47 | } 48 | 49 | public List getGrantedAuthorities() { 50 | return grantedAuthorities; 51 | } 52 | 53 | public void setGrantedAuthorities(List grantedAuthorities) { 54 | this.grantedAuthorities = grantedAuthorities; 55 | } 56 | 57 | public ServiceInstances getServiceInstances() { 58 | return serviceInstances; 59 | } 60 | 61 | public void setServiceInstances(ServiceInstances serviceInstances) { 62 | this.serviceInstances = serviceInstances; 63 | } 64 | 65 | public User getUser() { 66 | return user; 67 | } 68 | 69 | public void setUser(User user) { 70 | this.user = user; 71 | } 72 | 73 | 74 | public Long getId() { 75 | return id; 76 | } 77 | 78 | public void setId(Long id) { 79 | this.id = id; 80 | } 81 | 82 | public String getUserDescription() { 83 | return userDescription; 84 | } 85 | 86 | public void setUserDescription(String userDescription) { 87 | this.userDescription = userDescription; 88 | } 89 | 90 | public String getAuthListStr() { 91 | return authListStr; 92 | } 93 | 94 | public void setAuthListStr(String authListStr) { 95 | this.authListStr = authListStr; 96 | } 97 | 98 | public Long getPipelineId() { 99 | return pipelineId; 100 | } 101 | 102 | public void setPipelineId(Long pipelineId) { 103 | this.pipelineId = pipelineId; 104 | } 105 | } 106 | -------------------------------------------------------------------------------- /src/main/java/paasta/delivery/pipeline/common/api/domain/common/serviceInstance/InstanceUseList.java: -------------------------------------------------------------------------------- 1 | package paasta.delivery.pipeline.common.api.domain.common.serviceInstance; 2 | 3 | import java.util.List; 4 | 5 | /** 6 | * Created by hrjin on 2017-07-19. 7 | */ 8 | public class InstanceUseList { 9 | 10 | List instanceUses; 11 | 12 | int page; 13 | int size; 14 | int totalPages; 15 | long totalElements; 16 | boolean isLast; 17 | 18 | public InstanceUseList() { 19 | // DO NOTHING 20 | } 21 | 22 | public List getInstanceUses() { 23 | return instanceUses; 24 | } 25 | 26 | public void setInstanceUses(List instanceUses) { 27 | this.instanceUses = instanceUses; 28 | } 29 | 30 | public int getPage() { 31 | return page; 32 | } 33 | 34 | public void setPage(int page) { 35 | this.page = page; 36 | } 37 | 38 | public int getSize() { 39 | return size; 40 | } 41 | 42 | public void setSize(int size) { 43 | this.size = size; 44 | } 45 | 46 | public int getTotalPages() { 47 | return totalPages; 48 | } 49 | 50 | public void setTotalPages(int totalPages) { 51 | this.totalPages = totalPages; 52 | } 53 | 54 | public long getTotalElements() { 55 | return totalElements; 56 | } 57 | 58 | public void setTotalElements(long totalElements) { 59 | this.totalElements = totalElements; 60 | } 61 | 62 | public boolean isLast() { 63 | return isLast; 64 | } 65 | 66 | public void setLast(boolean last) { 67 | isLast = last; 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /src/main/java/paasta/delivery/pipeline/common/api/domain/common/serviceInstance/InstanceUseRepository.java: -------------------------------------------------------------------------------- 1 | package paasta.delivery.pipeline.common.api.domain.common.serviceInstance; 2 | 3 | import org.springframework.data.domain.Page; 4 | import org.springframework.data.domain.Pageable; 5 | import org.springframework.data.jpa.repository.JpaRepository; 6 | import org.springframework.stereotype.Repository; 7 | 8 | import java.util.List; 9 | 10 | /** 11 | * Created by hrjin on 2017-05-29. 12 | */ 13 | @Repository 14 | public interface InstanceUseRepository extends JpaRepository { 15 | InstanceUse findByServiceInstancesIdAndUserId(String serviceInstancesId, String userId); 16 | 17 | List findByServiceInstancesId(String serviceInstanceId); 18 | 19 | Page findByServiceInstancesIdAndUserNameContaining(String serviceInstanceId, String userName, Pageable pageable); 20 | 21 | Page findByServiceInstancesId(String serviceInstanceId, Pageable pageable); 22 | 23 | Page findByServiceInstancesIdAndUserNameContainingAndGrantedAuthorities_Authority_Id(String serviceInstanceId, String userName, String id, Pageable pageable); 24 | 25 | Page findByServiceInstancesIdAndGrantedAuthorities_Authority_Id(String serviceInstanceId, String authName, Pageable pageable); 26 | 27 | Page findAllByServiceInstancesIdAndGrantedAuthoritiesAuthCode(String suid, Long pipelineId, Pageable pageable); 28 | 29 | Page findAllByServiceInstancesIdAndUserNameContainingAndGrantedAuthoritiesAuthCode(String suid, String reqName, Long pipelineId, Pageable pageable); 30 | 31 | //List findAllByServiceInstancesIdAndGrantedAuthorities_Authority_AuthTypeNotAndGrantedAuthoritiesAuthCode(String suid, String authType, Long pipelineId); 32 | 33 | //List findAllByServiceInstancesIdAndGrantedAuthoritiesAuthCode(String suid, Long pipelineId); 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/paasta/delivery/pipeline/common/api/domain/common/serviceInstance/InstanceUseService.java: -------------------------------------------------------------------------------- 1 | package paasta.delivery.pipeline.common.api.domain.common.serviceInstance; 2 | 3 | import org.slf4j.Logger; 4 | import org.springframework.beans.factory.annotation.Autowired; 5 | import org.springframework.data.domain.Page; 6 | import org.springframework.data.domain.Pageable; 7 | import org.springframework.stereotype.Service; 8 | import org.springframework.web.bind.annotation.RequestBody; 9 | import paasta.delivery.pipeline.common.api.common.CommonService; 10 | import paasta.delivery.pipeline.common.api.common.Constants; 11 | 12 | import java.util.List; 13 | 14 | import static org.slf4j.LoggerFactory.getLogger; 15 | 16 | /** 17 | * Created by hrjin on 2017-05-29. 18 | */ 19 | @Service 20 | public class InstanceUseService { 21 | 22 | private final Logger logger = getLogger(getClass()); 23 | private final CommonService commonService; 24 | private final InstanceUseRepository instanceUseRepository; 25 | 26 | @Autowired 27 | public InstanceUseService(CommonService commonService, InstanceUseRepository instanceUseRepository) { 28 | this.commonService = commonService; 29 | this.instanceUseRepository = instanceUseRepository; 30 | } 31 | 32 | 33 | public InstanceUse createInstanceUse(@RequestBody InstanceUse instanceUse) { 34 | InstanceUse newInstanceUse = instanceUseRepository.save(instanceUse); 35 | return newInstanceUse; 36 | } 37 | 38 | public List instanceServiceInstanceUseList() { 39 | List instanceServiceInstanceUseList = instanceUseRepository.findAll(); 40 | return instanceServiceInstanceUseList; 41 | } 42 | 43 | 44 | public InstanceUseList getInstanceUseList(String serviceInstanceId, String userName, String authName, Pageable pageable) { 45 | logger.info("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"); 46 | logger.info(" - PageNumber :: {}", pageable.getPageNumber()); 47 | logger.info(" - PageSize :: {}", pageable.getPageSize()); 48 | logger.info(" - Sort :: {}", pageable.getSort()); 49 | logger.info(" - Offset :: {}", pageable.getOffset()); 50 | logger.info(" - HasPrevious :: {}", pageable.hasPrevious()); 51 | logger.info("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"); 52 | 53 | InstanceUseList instanceUseList; 54 | Page pageList; 55 | 56 | 57 | if (userName == null && authName == null) { 58 | pageList = instanceUseRepository.findByServiceInstancesId(serviceInstanceId, pageable); 59 | } else if (userName != null && authName == null) { 60 | pageList = instanceUseRepository.findByServiceInstancesIdAndUserNameContaining(serviceInstanceId, userName, pageable); 61 | } else if (userName == null) { 62 | pageList = instanceUseRepository.findByServiceInstancesIdAndGrantedAuthorities_Authority_Id(serviceInstanceId, authName, pageable); 63 | } else { 64 | pageList = instanceUseRepository.findByServiceInstancesIdAndUserNameContainingAndGrantedAuthorities_Authority_Id(serviceInstanceId, userName, authName, pageable); 65 | } 66 | 67 | instanceUseList = (InstanceUseList) commonService.setPageInfo(pageList, InstanceUseList.class); 68 | instanceUseList.setInstanceUses(pageList.getContent()); 69 | 70 | return instanceUseList; 71 | } 72 | 73 | public InstanceUseList getInstanceUseListByPipelineContributor(String suid, Long pipelineId, String reqName, Pageable pageable) { 74 | 75 | InstanceUseList instanceUseList; 76 | Page instanceUsePage; 77 | 78 | 79 | if (reqName == null || "".equals(reqName)) { 80 | instanceUsePage = instanceUseRepository.findAllByServiceInstancesIdAndGrantedAuthoritiesAuthCode(suid, pipelineId, pageable); 81 | } else { 82 | instanceUsePage = instanceUseRepository.findAllByServiceInstancesIdAndUserNameContainingAndGrantedAuthoritiesAuthCode(suid, reqName, pipelineId, pageable); 83 | } 84 | 85 | instanceUseList = (InstanceUseList) commonService.setPageInfo(instanceUsePage, InstanceUseList.class); 86 | instanceUseList.setInstanceUses(instanceUsePage.getContent()); 87 | 88 | logger.info("###### getInstanceUseListByPipelineContributor {}", instanceUseList); 89 | return instanceUseList; 90 | } 91 | 92 | public InstanceUse getInstanceUse(String serviceInstancesId, String userId) { 93 | InstanceUse getInstanceUse = instanceUseRepository.findByServiceInstancesIdAndUserId(serviceInstancesId, userId); 94 | return getInstanceUse; 95 | } 96 | 97 | public String deleteInstanceUse(Long instanceUseId) { 98 | instanceUseRepository.delete(instanceUseId); 99 | return Constants.RESULT_STATUS_SUCCESS; 100 | } 101 | 102 | public InstanceUse updateInstanceUse(InstanceUse updateInstanceUse) { 103 | return instanceUseRepository.save(updateInstanceUse); 104 | } 105 | 106 | public List findByServiceInstancesId(String id) { 107 | return instanceUseRepository.findByServiceInstancesId(id); 108 | } 109 | } 110 | -------------------------------------------------------------------------------- /src/main/java/paasta/delivery/pipeline/common/api/domain/common/serviceInstance/ServiceInstances.java: -------------------------------------------------------------------------------- 1 | package paasta.delivery.pipeline.common.api.domain.common.serviceInstance; 2 | 3 | import com.fasterxml.jackson.annotation.JsonIgnore; 4 | import paasta.delivery.pipeline.common.api.domain.common.pipeline.Pipeline; 5 | 6 | import javax.persistence.*; 7 | import java.util.ArrayList; 8 | import java.util.List; 9 | 10 | /** 11 | * Created by hrjin on 2017-05-29. 12 | */ 13 | @Entity 14 | @Table(name = "service_instances") 15 | public class ServiceInstances { 16 | 17 | @Id 18 | @Column(name = "id") 19 | private String id; 20 | 21 | @OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL) 22 | @JoinColumn(name = "service_instances_id", referencedColumnName = "id") 23 | @JsonIgnore 24 | private List pipelineList; 25 | 26 | @OneToMany(mappedBy = "serviceInstances", fetch = FetchType.LAZY, cascade = CascadeType.ALL) 27 | @JsonIgnore 28 | private List instanceUseList = new ArrayList<>(); 29 | 30 | @Column(name = "owner") 31 | private String owner; 32 | 33 | @Column(name = "ci_server_url") 34 | private String ciServerUrl; 35 | 36 | @Transient 37 | private String serviceType; 38 | 39 | 40 | public String getId() { 41 | return id; 42 | } 43 | 44 | public void setId(String id) { 45 | this.id = id; 46 | } 47 | 48 | public List getInstanceUseList() { 49 | return instanceUseList; 50 | } 51 | 52 | public void setInstanceUseList(List instanceUseList) { 53 | this.instanceUseList = instanceUseList; 54 | } 55 | 56 | public List getPipelineList() { 57 | return pipelineList; 58 | } 59 | 60 | public void setPipelineList(List pipelineList) { 61 | this.pipelineList = pipelineList; 62 | } 63 | 64 | public String getOwner() { 65 | return owner; 66 | } 67 | 68 | public void setOwner(String owner) { 69 | this.owner = owner; 70 | } 71 | 72 | public String getCiServerUrl() { 73 | return ciServerUrl; 74 | } 75 | 76 | public void setCiServerUrl(String ciServerUrl) { 77 | this.ciServerUrl = ciServerUrl; 78 | } 79 | 80 | public String getServiceType() { 81 | return serviceType; 82 | } 83 | 84 | public void setServiceType(String serviceType) { 85 | this.serviceType = serviceType; 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /src/main/java/paasta/delivery/pipeline/common/api/domain/common/serviceInstance/ServiceInstancesController.java: -------------------------------------------------------------------------------- 1 | package paasta.delivery.pipeline.common.api.domain.common.serviceInstance; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.web.bind.annotation.*; 5 | 6 | import java.util.List; 7 | 8 | /** 9 | * Created by hrjin on 2017-05-29. 10 | */ 11 | @RestController 12 | @RequestMapping("/serviceInstance") 13 | public class ServiceInstancesController { 14 | 15 | private final ServiceInstancesService serviceInstancesService; 16 | 17 | 18 | @Autowired 19 | public ServiceInstancesController(ServiceInstancesService serviceInstancesService) { 20 | this.serviceInstancesService = serviceInstancesService; 21 | } 22 | 23 | /* 24 | * 서비스 인스턴스 생성 25 | * 26 | * */ 27 | @RequestMapping(value = "", method = RequestMethod.POST) 28 | public ServiceInstances createInstances(@RequestBody ServiceInstances serviceInstances) { 29 | ServiceInstances newInstances = serviceInstancesService.createInstances(serviceInstances); 30 | return newInstances; 31 | } 32 | 33 | 34 | /* 35 | * 인스턴스 삭제 36 | * 37 | * */ 38 | @RequestMapping(value = "/{id}", method = RequestMethod.DELETE) 39 | public String deleteInstances(@PathVariable String id) { 40 | return serviceInstancesService.deleteInstance(id); 41 | } 42 | 43 | /* 44 | * 인스턴스 목록 조회 45 | * 46 | * */ 47 | @RequestMapping(value = "", method = RequestMethod.GET) 48 | public List getServiceInstancesList() { 49 | List serviceInstancesList = serviceInstancesService.getServiceInstances(); 50 | return serviceInstancesList; 51 | } 52 | 53 | /* 54 | * 인스턴스 상세 조회 55 | * 56 | * */ 57 | @RequestMapping(value = "/{id}", method = RequestMethod.GET) 58 | public ServiceInstances getServiceInstance(@PathVariable String id) { 59 | ServiceInstances serviceInstance = serviceInstancesService.getServiceInstance(id); 60 | return serviceInstance; 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/main/java/paasta/delivery/pipeline/common/api/domain/common/serviceInstance/ServiceInstancesRepository.java: -------------------------------------------------------------------------------- 1 | package paasta.delivery.pipeline.common.api.domain.common.serviceInstance; 2 | 3 | import org.springframework.data.jpa.repository.JpaRepository; 4 | import org.springframework.stereotype.Repository; 5 | 6 | /** 7 | * Created by hrjin on 2017-05-29. 8 | */ 9 | @Repository 10 | public interface ServiceInstancesRepository extends JpaRepository { 11 | } 12 | -------------------------------------------------------------------------------- /src/main/java/paasta/delivery/pipeline/common/api/domain/common/user/User.java: -------------------------------------------------------------------------------- 1 | package paasta.delivery.pipeline.common.api.domain.common.user; 2 | 3 | import com.fasterxml.jackson.annotation.JsonIgnore; 4 | import org.hibernate.annotations.CreationTimestamp; 5 | import org.hibernate.annotations.UpdateTimestamp; 6 | import paasta.delivery.pipeline.common.api.common.Constants; 7 | import paasta.delivery.pipeline.common.api.domain.common.serviceInstance.InstanceUse; 8 | 9 | import javax.persistence.*; 10 | import java.text.SimpleDateFormat; 11 | import java.util.ArrayList; 12 | import java.util.Date; 13 | import java.util.List; 14 | import java.util.Locale; 15 | 16 | /** 17 | * paastaDeliveryPipelineApi 18 | * paasta.delivery.pipeline.common.api.user 19 | * 20 | * @author REX 21 | * @version 1.0 22 | * @since 5/11/2017 23 | */ 24 | @Entity 25 | @Table(name = "user") 26 | public class User { 27 | 28 | @Id 29 | @Column(name = "id") 30 | private String id; // UAA 와 연동 시 ID 자동생성이 아닌 UUID 가 등록되야하기 때문에 GeneratedType.AUTO 제거. 31 | 32 | @Column(name = "name", nullable = false) 33 | private String name; 34 | 35 | @OneToMany(mappedBy = "user", cascade = CascadeType.ALL) 36 | @JsonIgnore 37 | private List instanceUseList = new ArrayList<>(); 38 | 39 | @Column(name = "tell_phone") 40 | private String tellPhone; 41 | 42 | @Column(name = "cell_phone") 43 | private String cellPhone; 44 | 45 | @Column(name = "email", nullable = false) 46 | private String email; 47 | 48 | @Column(name = "company", nullable = false) 49 | private String company; 50 | 51 | @Column(name = "description") 52 | private String description; 53 | 54 | @CreationTimestamp 55 | @Column(columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP", updatable = false) 56 | @Temporal(TemporalType.TIMESTAMP) 57 | private Date created; 58 | 59 | @UpdateTimestamp 60 | @Column(name = "last_modified", columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP") 61 | @Temporal(TemporalType.TIMESTAMP) 62 | private Date lastModified; 63 | 64 | @Transient 65 | private String createdString; 66 | 67 | @Transient 68 | private String lastModifiedString; 69 | 70 | 71 | public User() { 72 | // DO NOTHING 73 | } 74 | 75 | 76 | public String getId() { 77 | return id; 78 | } 79 | 80 | public void setId(String id) { 81 | this.id = id; 82 | } 83 | 84 | public String getName() { 85 | return name; 86 | } 87 | 88 | public void setName(String name) { 89 | this.name = name; 90 | } 91 | 92 | public String getTellPhone() { 93 | return tellPhone; 94 | } 95 | 96 | public void setTellPhone(String tellPhone) { 97 | this.tellPhone = tellPhone; 98 | } 99 | 100 | public String getCellPhone() { 101 | return cellPhone; 102 | } 103 | 104 | public void setCellPhone(String cellPhone) { 105 | this.cellPhone = cellPhone; 106 | } 107 | 108 | public String getEmail() { 109 | return email; 110 | } 111 | 112 | public void setEmail(String email) { 113 | this.email = email; 114 | } 115 | 116 | public String getCompany() { 117 | return company; 118 | } 119 | 120 | public void setCompany(String company) { 121 | this.company = company; 122 | } 123 | 124 | public String getDescription() { 125 | return description; 126 | } 127 | 128 | public void setDescription(String description) { 129 | this.description = description; 130 | } 131 | 132 | public Date getCreated() { 133 | return created; 134 | } 135 | 136 | public void setCreated(Date created) { 137 | this.created = created; 138 | } 139 | 140 | public Date getLastModified() { 141 | return lastModified; 142 | } 143 | 144 | public void setLastModified(Date lastModified) { 145 | this.lastModified = lastModified; 146 | } 147 | 148 | public String getCreatedString() { 149 | return (created != null) ? new SimpleDateFormat(Constants.STRING_DATE_TYPE, Locale.KOREA).format(created) : null; 150 | } 151 | 152 | public void setCreatedString(String createdString) { 153 | this.createdString = createdString; 154 | } 155 | 156 | public String getLastModifiedString() { 157 | return (lastModified != null) ? new SimpleDateFormat(Constants.STRING_DATE_TYPE, Locale.KOREA).format(lastModified) : null; 158 | } 159 | 160 | public void setLastModifiedString(String lastModifiedString) { 161 | this.lastModifiedString = lastModifiedString; 162 | } 163 | 164 | public List getInstanceUseList() { 165 | return instanceUseList; 166 | } 167 | 168 | public void setInstanceUseList(List instanceUseList) { 169 | this.instanceUseList = instanceUseList; 170 | } 171 | 172 | @Override 173 | public String toString() { 174 | return "User{" + 175 | "id='" + id + '\'' + 176 | ", name='" + name + '\'' + 177 | ", instanceUseList=" + instanceUseList + 178 | ", tellPhone='" + tellPhone + '\'' + 179 | ", cellPhone='" + cellPhone + '\'' + 180 | ", email='" + email + '\'' + 181 | ", company='" + company + '\'' + 182 | ", created=" + created + 183 | ", lastModified=" + lastModified + 184 | ", createdString='" + createdString + '\'' + 185 | ", lastModifiedString='" + lastModifiedString + '\'' + 186 | '}'; 187 | } 188 | } 189 | -------------------------------------------------------------------------------- /src/main/java/paasta/delivery/pipeline/common/api/domain/common/user/UserController.java: -------------------------------------------------------------------------------- 1 | package paasta.delivery.pipeline.common.api.domain.common.user; 2 | 3 | import org.slf4j.Logger; 4 | import org.springframework.data.domain.Pageable; 5 | import org.springframework.data.domain.Sort; 6 | import org.springframework.data.web.PageableDefault; 7 | import org.springframework.web.bind.annotation.*; 8 | 9 | import static org.slf4j.LoggerFactory.getLogger; 10 | 11 | /** 12 | * paastaDeliveryPipelineApi 13 | * paasta.delivery.pipeline.common.api.userRepository 14 | * 15 | * @author REX 16 | * @version 1.0 17 | * @since 5 /11/2017 18 | */ 19 | @RestController 20 | @RequestMapping("/user") 21 | public class UserController { 22 | 23 | private static final int PAGE_SIZE = 5; 24 | private final Logger logger = getLogger(getClass()); 25 | private final UserService userService; 26 | 27 | /** 28 | * Instantiates a new User controller. 29 | * 30 | * @param userService the user repository 31 | */ 32 | public UserController(UserService userService) { 33 | this.userService = userService; 34 | } 35 | 36 | 37 | /** 38 | * 사용자 목록 조회 39 | * 40 | * @param name 41 | * @param pageable 42 | * @return 43 | */ 44 | @RequestMapping(value = "", method = RequestMethod.GET) 45 | public UserList getUserList(@RequestParam(value = "id", required = false) String name, @PageableDefault(sort = "name", direction = Sort.Direction.ASC, size = PAGE_SIZE) Pageable pageable) { 46 | return userService.getUserList(name, pageable); 47 | } 48 | 49 | 50 | /** 51 | *사용자 상세 조회 52 | * 53 | * @param id 54 | * @return 55 | */ 56 | @RequestMapping(value = "/{id}", method = RequestMethod.GET) 57 | public User getUser(@PathVariable String id) { 58 | User oneUser = userService.getUser(id); 59 | return oneUser; 60 | } 61 | 62 | 63 | /** 64 | * 사용자 등록 65 | * 66 | * @param reqUser 67 | * @return 68 | */ 69 | @RequestMapping(value = "", method = RequestMethod.POST) 70 | public User create(@RequestBody User reqUser) { 71 | User newUser = userService.createUser(reqUser); 72 | logger.info("####### add :: result ::{}", newUser.toString()); 73 | return newUser; 74 | } 75 | 76 | 77 | /** 78 | * 사용자 정보 수정 79 | * 80 | * @param id 81 | * @param reqUser 82 | * @return 83 | */ 84 | @RequestMapping(value = "/{id}", method = RequestMethod.PUT) 85 | public User update(@PathVariable String id, @RequestBody User reqUser) { 86 | User modifyUser = userService.getUser(id); 87 | // CHECK REQUEST ID 88 | modifyUser.setDescription(reqUser.getDescription()); 89 | return userService.updateUser(modifyUser); 90 | } 91 | 92 | 93 | /** 94 | * 사용자 정보 삭제 95 | * 96 | * @param id 97 | * @return 98 | */ 99 | @RequestMapping(value = "/{id}", method = RequestMethod.DELETE) 100 | public String delete(@PathVariable String id) { 101 | return userService.deleteUser(id); 102 | } 103 | 104 | 105 | } 106 | -------------------------------------------------------------------------------- /src/main/java/paasta/delivery/pipeline/common/api/domain/common/user/UserList.java: -------------------------------------------------------------------------------- 1 | package paasta.delivery.pipeline.common.api.domain.common.user; 2 | 3 | import java.util.List; 4 | 5 | /** 6 | * Created by hrjin on 2017-07-11. 7 | */ 8 | public class UserList { 9 | 10 | List users; 11 | 12 | int page; 13 | int size; 14 | int totalPages; 15 | long totalElements; 16 | boolean isLast; 17 | 18 | public UserList() { 19 | // DO NOTHING 20 | } 21 | 22 | public UserList(List users) { 23 | this.users = users; 24 | } 25 | 26 | public List getUsers() { 27 | return users; 28 | } 29 | 30 | public void setUsers(List users) { 31 | this.users = users; 32 | } 33 | 34 | public int getPage() { 35 | return page; 36 | } 37 | 38 | public void setPage(int page) { 39 | this.page = page; 40 | } 41 | 42 | public int getSize() { 43 | return size; 44 | } 45 | 46 | public void setSize(int size) { 47 | this.size = size; 48 | } 49 | 50 | public int getTotalPages() { 51 | return totalPages; 52 | } 53 | 54 | public void setTotalPages(int totalPages) { 55 | this.totalPages = totalPages; 56 | } 57 | 58 | public long getTotalElements() { 59 | return totalElements; 60 | } 61 | 62 | public void setTotalElements(long totalElements) { 63 | this.totalElements = totalElements; 64 | } 65 | 66 | public boolean isLast() { 67 | return isLast; 68 | } 69 | 70 | public void setLast(boolean last) { 71 | isLast = last; 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /src/main/java/paasta/delivery/pipeline/common/api/domain/common/user/UserRepository.java: -------------------------------------------------------------------------------- 1 | package paasta.delivery.pipeline.common.api.domain.common.user; 2 | 3 | import org.springframework.data.domain.Page; 4 | import org.springframework.data.domain.Pageable; 5 | import org.springframework.data.jpa.repository.JpaRepository; 6 | import org.springframework.data.jpa.repository.JpaSpecificationExecutor; 7 | import org.springframework.stereotype.Repository; 8 | 9 | /** 10 | * paastaDeliveryPipelineApi 11 | * paasta.delivery.pipeline.common.api.user 12 | * 13 | * @author REX 14 | * @version 1.0 15 | * @since 5/11/2017 16 | */ 17 | @Repository 18 | public interface UserRepository extends JpaRepository, JpaSpecificationExecutor { 19 | Page findByNameContaining(String reqName, Pageable pageable); 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/paasta/delivery/pipeline/common/api/domain/common/user/UserService.java: -------------------------------------------------------------------------------- 1 | package paasta.delivery.pipeline.common.api.domain.common.user; 2 | 3 | import org.slf4j.Logger; 4 | import org.springframework.beans.factory.annotation.Autowired; 5 | import org.springframework.data.domain.Page; 6 | import org.springframework.data.domain.Pageable; 7 | import org.springframework.stereotype.Service; 8 | import org.springframework.web.bind.annotation.RequestBody; 9 | import paasta.delivery.pipeline.common.api.common.CommonService; 10 | import paasta.delivery.pipeline.common.api.common.Constants; 11 | 12 | import static org.slf4j.LoggerFactory.getLogger; 13 | 14 | /** 15 | * Created by user on 2017-05-18. 16 | */ 17 | @Service 18 | public class UserService { 19 | 20 | private final Logger logger = getLogger(getClass()); 21 | private final CommonService commonService; 22 | private final UserRepository userRepository; 23 | 24 | @Autowired 25 | public UserService(CommonService commonService, UserRepository userRepository) { 26 | this.commonService = commonService; 27 | this.userRepository = userRepository; 28 | } 29 | 30 | 31 | public UserList getUserList(String reqName, Pageable pageable) { 32 | logger.info("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"); 33 | logger.info(" - PageNumber :: {}", pageable.getPageNumber()); 34 | logger.info(" - PageSize :: {}", pageable.getPageSize()); 35 | logger.info(" - Sort :: {}", pageable.getSort()); 36 | logger.info(" - Offset :: {}", pageable.getOffset()); 37 | logger.info(" - HasPrevious :: {}", pageable.hasPrevious()); 38 | logger.info("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"); 39 | 40 | UserList userList; 41 | Page userListPage; 42 | 43 | if (reqName == null || "".equals(reqName)) { 44 | userListPage = userRepository.findAll(pageable); 45 | } else { 46 | userListPage = userRepository.findAll(UserSpecifications.hasName(reqName), pageable); 47 | } 48 | 49 | userList = (UserList) commonService.setPageInfo(userListPage, new UserList()); 50 | userList.setUsers(userListPage.getContent()); 51 | 52 | logger.info("###### {}", userList); 53 | return userList; 54 | } 55 | 56 | 57 | public User getUser(String id) { 58 | User getUser = userRepository.findOne(id); 59 | return getUser; 60 | } 61 | 62 | 63 | public User createUser(@RequestBody User reqUser) { 64 | logger.info("####### add :: {}", reqUser.toString()); 65 | User newUser = userRepository.save(reqUser); 66 | logger.info("####### add :: result ::{}", newUser.toString()); 67 | return newUser; 68 | } 69 | 70 | 71 | public User updateUser(@RequestBody User reqUser) { 72 | //reqUser.setId(id); 73 | User modifyUser = userRepository.save(reqUser); 74 | return modifyUser; 75 | } 76 | 77 | 78 | public String deleteUser(String id) { 79 | userRepository.delete(id); 80 | return Constants.RESULT_STATUS_SUCCESS; 81 | } 82 | 83 | } 84 | -------------------------------------------------------------------------------- /src/main/java/paasta/delivery/pipeline/common/api/domain/common/user/UserSpecifications.java: -------------------------------------------------------------------------------- 1 | package paasta.delivery.pipeline.common.api.domain.common.user; 2 | 3 | import org.springframework.data.jpa.domain.Specification; 4 | 5 | /** 6 | * Created by hrjin on 2017-07-10. 7 | */ 8 | public class UserSpecifications { 9 | private UserSpecifications() {} 10 | 11 | static Specification hasName(final String name) { 12 | return (root, query, cb) -> cb.like(root.get("name"), "%" + name + "%"); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/main/java/paasta/delivery/pipeline/common/api/exception/CustomException.java: -------------------------------------------------------------------------------- 1 | package paasta.delivery.pipeline.common.api.exception; 2 | 3 | /** 4 | * paastaDeliveryPipelineApi 5 | * paasta.delivery.pipeline.ui.exception 6 | * 7 | * @author REX 8 | * @version 1.0 9 | * @since 5 /12/2017 10 | */ 11 | public class CustomException extends RuntimeException { 12 | 13 | /** 14 | * Instantiates a new Custom exception. 15 | * 16 | * @param msg the msg 17 | */ 18 | public CustomException(String msg) { 19 | super(msg); 20 | } 21 | 22 | 23 | /** 24 | * Instantiates a new Custom exception. 25 | * 26 | * @param msg the msg 27 | * @param t the t 28 | */ 29 | public CustomException(String msg, Throwable t) { 30 | super(msg, t); 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | application: 3 | name: paasta-delivery-pipeline-common-api 4 | 5 | --- 6 | spring: 7 | profiles: 8 | active: local 9 | datasource: 10 | url: jdbc:mariadb://SPRING-DATASOURCE-URL 11 | username: SPRING-DATASOURCE-USER-NAME 12 | password: SPRING-DATASOURCE-PASSWORD 13 | driver-class-name: org.mariadb.jdbc.Driver 14 | jpa: 15 | database: mysql 16 | show-sql: true 17 | hibernate: 18 | ddl-auto: none 19 | naming: 20 | strategy: org.hibernate.cfg.EJB3NamingStrategy 21 | generate-ddl: false 22 | 23 | server: 24 | port: {SERVER-PORT} 25 | 26 | logging: 27 | level: 28 | ROOT: INFO 29 | path: classpath:logback-spring.xml 30 | file: logs/application.log 31 | 32 | --- 33 | spring: 34 | profiles: dev 35 | datasource: 36 | url: jdbc:mariadb://SPRING-DATASOURCE-URL 37 | username: SPRING-DATASOURCE-USER-NAME 38 | password: SPRING-DATASOURCE-PASSWORD 39 | driver-class-name: org.mariadb.jdbc.Driver 40 | jpa: 41 | database: mysql 42 | show-sql: true 43 | hibernate: 44 | ddl-auto: none 45 | naming: 46 | strategy: org.hibernate.cfg.EJB3NamingStrategy 47 | generate-ddl: false 48 | 49 | server: 50 | port: {SERVER-PORT} 51 | 52 | logging: 53 | level: 54 | ROOT: DEBUG 55 | path: classpath:logback-spring.xml 56 | file: logs/application.log 57 | -------------------------------------------------------------------------------- /src/main/resources/logback-spring.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | true 7 | 8 | 9 | applicatoin.%d{yyyy-MM-dd}.log 10 | 30 11 | 12 | 13 | INFO 14 | 15 | 16 | 17 | %d{yyyy:MM:dd HH:mm:ss.SSS} %-5level --- [%thread] %logger{35} : %msg %n 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /src/test/java/paasta/delivery/pipeline/common/api/domain/common/file/FileServiceTest.java: -------------------------------------------------------------------------------- 1 | package paasta.delivery.pipeline.common.api.domain.common.file; 2 | 3 | import org.junit.Before; 4 | import org.junit.FixMethodOrder; 5 | import org.junit.Test; 6 | import org.junit.runner.RunWith; 7 | import org.junit.runners.MethodSorters; 8 | import org.mockito.InjectMocks; 9 | import org.mockito.Mock; 10 | import org.slf4j.Logger; 11 | import org.slf4j.LoggerFactory; 12 | import org.springframework.boot.test.context.SpringBootTest; 13 | import org.springframework.test.context.junit4.SpringRunner; 14 | import paasta.delivery.pipeline.common.api.common.Constants; 15 | 16 | import java.util.ArrayList; 17 | import java.util.Date; 18 | import java.util.List; 19 | 20 | import static org.assertj.core.api.Assertions.assertThat; 21 | import static org.junit.Assert.assertEquals; 22 | import static org.mockito.Matchers.anyLong; 23 | import static org.mockito.Mockito.doNothing; 24 | import static org.mockito.Mockito.when; 25 | 26 | /** 27 | * Created by Mingu on 2017-05-31. 28 | */ 29 | @RunWith(SpringRunner.class) 30 | @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) 31 | @FixMethodOrder(MethodSorters.NAME_ASCENDING) 32 | public class FileServiceTest { 33 | private static final Logger LOGGER = LoggerFactory.getLogger(FileServiceTest.class); 34 | 35 | @InjectMocks 36 | private FileService fileService; 37 | 38 | @Mock 39 | private FileInfoRepository fileInfoRepository; 40 | 41 | private long PARAM = 12345678; 42 | 43 | private FileInfo testfileInfo; 44 | private List testfileInfoList; 45 | 46 | /** 47 | * Sets up. 48 | * 49 | * @throws Exception the exception 50 | */ 51 | @Before 52 | public void setUp() throws Exception { 53 | fileService = new FileService(fileInfoRepository); 54 | 55 | testfileInfo = new FileInfo(); 56 | testfileInfo.setId(PARAM); 57 | testfileInfo.setFileUrl("fileUrl"); 58 | testfileInfo.setOriginalFileName("originalFileName"); 59 | testfileInfo.setStoredFileName("StoredFileName"); 60 | testfileInfo.setCreated(new Date()); 61 | 62 | testfileInfoList = getFileInfoList(); 63 | } 64 | 65 | private List getFileInfoList() { 66 | List fileInfos = new ArrayList<>(); 67 | for (int i = 0; i < 10; i++) { 68 | FileInfo returnValue = new FileInfo(); 69 | returnValue.setId(PARAM+i); 70 | returnValue.setFileUrl("fileUrl_"+i); 71 | returnValue.setOriginalFileName("originalFileName_"+i); 72 | returnValue.setStoredFileName("StoredFileName_"+i); 73 | returnValue.setCreated(new Date()); 74 | fileInfos.add(returnValue); 75 | } 76 | return fileInfos; 77 | } 78 | 79 | 80 | @Test 81 | public void test_getFileInfo() { 82 | 83 | when(fileInfoRepository.findById(anyLong())).thenReturn(testfileInfo); 84 | 85 | FileInfo result = fileService.getFileInfo(PARAM); 86 | 87 | assertEquals(testfileInfo.getId(), result.getId()); 88 | assertEquals(testfileInfo.getFileUrl(), result.getFileUrl()); 89 | assertEquals(testfileInfo.getOriginalFileName(), result.getOriginalFileName()); 90 | assertEquals(testfileInfo.getStoredFileName(), result.getStoredFileName()); 91 | assertEquals(testfileInfo.getCreated(), result.getCreated()); 92 | 93 | } 94 | 95 | @Test 96 | public void test_getFileInfoList() { 97 | when(fileInfoRepository.findAll()).thenReturn(testfileInfoList); 98 | 99 | List result = fileService.getFileInfoList(); 100 | 101 | assertEquals(testfileInfoList.get(0).getId(), result.get(0).getId()); 102 | assertEquals(testfileInfoList.get(0).getFileUrl(), result.get(0).getFileUrl()); 103 | assertEquals(testfileInfoList.get(0).getOriginalFileName(), result.get(0).getOriginalFileName()); 104 | assertEquals(testfileInfoList.get(0).getStoredFileName(), result.get(0).getStoredFileName()); 105 | assertEquals(testfileInfoList.get(0).getCreated(), result.get(0).getCreated()); 106 | } 107 | 108 | @Test 109 | public void test_createFileInfo() { 110 | when(fileInfoRepository.save(testfileInfo)).thenReturn(testfileInfo); 111 | FileInfo result = fileService.createFileInfo(testfileInfo); 112 | assertThat(result).isNotNull(); 113 | assertEquals(testfileInfo.getId(), result.getId()); 114 | } 115 | 116 | @Test 117 | public void test_deleteFile() { 118 | doNothing().when(fileInfoRepository).delete(PARAM); 119 | String result = fileService.deleteFile(PARAM); 120 | assertThat(result).isNotNull(); 121 | assertEquals(Constants.RESULT_STATUS_SUCCESS, result); 122 | } 123 | 124 | } 125 | --------------------------------------------------------------------------------