Skip to content

Commit

Permalink
release: 2.0.0-alpha-003 (#7)
Browse files Browse the repository at this point in the history
* refactor: improve builder pattern (#4)

* chore: add CI for build verfication on multiple java versions

* refactor: improve builder pattern

* feat: 상품 호출 메소드 (requestProduct) (#6)

* feat: requestProduct 초기 버전

* feat: EasyCodefResponse 파싱 버그 개선

* feat: EasyCodef 파라미터 단일화

* docs: update README.md

* docs: update README.md

* docs: update README.md

* docs: update README.md

* docs: update README.md

* release: 2.0.0-alpha-003
  • Loading branch information
h-beeen authored Nov 13, 2024
1 parent 7202f5b commit f5c130d
Show file tree
Hide file tree
Showing 26 changed files with 533 additions and 200 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Build Verification

on:
push:

jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
java-version: [17, 21, 23]

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Set up JDK ${{ matrix.java-version }}
uses: actions/setup-java@v2
with:
java-version: ${{ matrix.java-version }}
distribution: 'temurin'

- name: Grant execute permission for gradlew
run: chmod +x gradlew

- name: Build with JDK ${{ matrix.java-version }}
run: ./gradlew build
10 changes: 6 additions & 4 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
name: Publish to Maven Central Repository

on:
push:
branches:
- master
workflow_run:
workflows: ["Verify"]
types:
- completed

jobs:
publish:
runs-on: ubuntu-latest
if: ${{ github.event.workflow_run.conclusion == 'success' && github.ref == 'refs/heads/master' }}

steps:
- name: Checkout code
Expand Down Expand Up @@ -52,4 +54,4 @@ jobs:
GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}
GPG_KEY_ID: ${{ secrets.GPG_KEY_ID }}
run: |
./gradlew publishAllPublicationsToMavenCentralRepository --stacktrace --debug
./gradlew publishAllPublicationsToMavenCentralRepository --stacktrace --debug
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,4 @@ out
test-output
atlassian-ide-plugin.xml
.gradletasknamecache
/src/test/java/io/codef/api/EasyCodefTokenTest.java
55 changes: 42 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
<h1 align="center">EasyCodef Java V2</h1>
<br>
<p align="center">
<a title="코드에프" href="https://codef.io/">
<picture>
Expand All @@ -9,44 +11,71 @@

<br>

# easycodef-java-v2

`easycodef-java-v2`는 codef API를 더욱 더 편리하게 연동할 수 있도록 돕는 오픈소스 라이브러리입니다.
`easycodef-java-v2`는 codef API를 JDK 환경에서 더욱 더 편리하게 연동할 수 있도록 돕는 오픈소스 라이브러리입니다.

현재 알파 버전 개발중으로 v2.0.0-ALPHA-002 버전으로 Maven Central Repository를 통해 배포중입니다.

## Release
2024년 상반기 실제 고객사 대상으로 릴리즈 예정입니다.

<a href="https://central.sonatype.com/artifact/io.codef.api/easycodef-java-v2"/><img src=https://github.com/user-attachments/assets/91bc4d3d-c971-43d8-b6a1-2798c68d82eb width="100px"></a><br><br>
<br><br>

## Release

[![Build Status](https://img.shields.io/github/actions/workflow/status/codef-io/easycodef-java-v2/publish.yml?style=for-the-badge&logo=gradle&color=02303A)](https://github.com/codef-io/easycodef-java-v2/actions?query=branch%3Amaster)<br>
[![Last Commit](https://img.shields.io/github/last-commit/codef-io/easycodef-java-v2/master?style=for-the-badge&label=LAST%20BUILD&logo=Github&color=181717)](https://github.com/codef-io/easycodef-java-v2)<br>
[![Maven Central](https://img.shields.io/maven-central/v/io.codef.api/easycodef-java-v2.svg?style=for-the-badge&label=Maven%20Central&logo=apache-maven&color=C71A36)](https://central.sonatype.com/artifact/io.codef.api/easycodef-java-v2)<br>


### Snippets
## Snippets

- Gradle(Kotlin)
```gradle
implementation("io.codef.api:easycodef-java-v2:2.0.0-alpha-002")
implementation("io.codef.api:easycodef-java-v2:2.0.0-alpha-003")
```
- Gradle(short)
```gradle
implementation 'io.codef.api:easycodef-java-v2:2.0.0-alpha-002'
implementation 'io.codef.api:easycodef-java-v2:2.0.0-alpha-003'
```
- Maven
```xml
<dependency>
<groupId>io.codef.api</groupId>
<artifactId>easycodef-java-v2</artifactId>
<version>2.0.0-alpha-002</version>
<version>2.0.0-alpha-003</version>
</dependency>
```
## LISENCE
## Get It !
<img alt="헥토데이터" src="https://github.com/user-attachments/assets/ac6b7a7d-33f1-4b1e-9fbb-8231d56e7f33" width="100">
- 예제 코드
```java
EasyCodef easyCodef = EasyCodefBuilder.builder()
.clientType(CodefClientType.DEMO)
.clientId("your-client-id")
.clientSecret("your-client-secret")
.publicKey("your-public-key")
.build();
EasyCodefRequest request = EasyCodefRequestBuilder.builder()
.path("/v1/kr/public/hw/nip-cdc-list/my-vaccination")
.organization("0011")
.requestBody("loginType", "1")
.requestBody("userId", "your-nhis-id")
.secureRequestBody("userPassword", "your-nhis-password")
.secureWith(easyCodef)
.build();
EasyCodefResponse easyCodefResponse = easyCodef.requestProduct(request);
final EasyCodefResponse.Result result = easyCodefResponse.result();
final Object data = easyCodefResponse.data();
```

---

<p align="center">
<img alt="헥토데이터" src="https://github.com/user-attachments/assets/ac6b7a7d-33f1-4b1e-9fbb-8231d56e7f33" height="20"><br>
<span>MIT © | <a href="https://github.com/codef-io/easycodef-java-v2/blob/master/LICENSE" target="_blank">LICENSE</a></span>
</p>

MIT © Hectodata Co,. Ltd [LICENSE](https://github.com/codef-io/easycodef-java-v2/blob/master/LICENSE) 파일을 참고하세요.
7 changes: 6 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ plugins {


group = "io.codef.api"
version = "2.0.0-alpha-002"
version = "2.0.0-alpha-003"

signing {
useInMemoryPgpKeys(
Expand Down Expand Up @@ -72,6 +72,11 @@ dependencies {
*/
implementation("com.fasterxml.jackson.core:jackson-databind:2.18.1")

/**
* 2024-10-17 Latest
*/
implementation("com.alibaba:fastjson:2.0.53")

/**
* 2024-06-12 Latest
* https://mvnrepository.com/artifact/commons-codec/commons-codec
Expand Down
45 changes: 0 additions & 45 deletions src/main/java/io/codef/api/CodefError.java

This file was deleted.

5 changes: 0 additions & 5 deletions src/main/java/io/codef/api/CodefUrl.java

This file was deleted.

5 changes: 4 additions & 1 deletion src/main/java/io/codef/api/CodefValidator.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package io.codef.api;

import io.codef.api.error.CodefError;
import io.codef.api.error.CodefException;

import java.util.Optional;
import java.util.UUID;

public class CodefValidator {
final class CodefValidator {

private CodefValidator() {
}
Expand Down
34 changes: 28 additions & 6 deletions src/main/java/io/codef/api/EasyCodef.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,38 @@
package io.codef.api;

import io.codef.api.constants.CodefClientType;
import io.codef.api.dto.EasyCodefRequest;
import io.codef.api.dto.EasyCodefResponse;
import io.codef.api.util.RsaUtil;

public class EasyCodef {
import java.security.PublicKey;

private EasyCodefToken easyCodefToken;
private EasyCodefProperty property;
public class EasyCodef {
private final PublicKey publicKey;
private final CodefClientType clientType;
private final EasyCodefToken easyCodefToken;

protected EasyCodef(
EasyCodefToken easyCodefToken,
EasyCodefProperty property
EasyCodefBuilder builder,
EasyCodefToken easyCodefToken
) {
this.publicKey = RsaUtil.generatePublicKey(builder.getPublicKey());
this.clientType = builder.getClientType();
this.easyCodefToken = easyCodefToken;
this.property = property;
}

public EasyCodefResponse requestProduct(EasyCodefRequest request) {
final String requestUrl = generateRequestUrl(request);
easyCodefToken.validateAndRefreshToken();

return EasyCodefConnector.requestProduct(request, easyCodefToken, requestUrl);
}

private String generateRequestUrl(EasyCodefRequest request) {
return clientType.getHost() + request.path();
}

public PublicKey getPublicKey() {
return publicKey;
}
}
79 changes: 79 additions & 0 deletions src/main/java/io/codef/api/EasyCodefBuilder.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package io.codef.api;

import io.codef.api.constants.CodefClientType;
import io.codef.api.error.CodefError;
import io.codef.api.error.CodefException;

import java.util.UUID;

public class EasyCodefBuilder {
private String publicKey;
private UUID clientId;
private UUID clientSecret;
private CodefClientType clientType;

public static EasyCodefBuilder builder() {
return new EasyCodefBuilder();
}

public EasyCodefBuilder publicKey(String publicKey) {
this.publicKey = CodefValidator.requireNonNullElseThrow(publicKey, CodefError.INVALID_PUBLIC_KEY);
return this;
}

public EasyCodefBuilder clientId(String clientId) {
this.clientId = parseUUID(clientId, CodefError.INVALID_CLIENT_ID);
return this;
}

public EasyCodefBuilder clientSecret(String clientSecret) {
this.clientSecret = parseUUID(clientSecret, CodefError.INVALID_CLIENT_SECRET);
return this;
}

public EasyCodefBuilder clientType(CodefClientType clientType) {
this.clientType = clientType;
return this;
}

public EasyCodef build() {
validatePropertyArguments();
EasyCodefToken easyCodefToken = new EasyCodefToken(this);

return new EasyCodef(this, easyCodefToken);
}

private void validatePropertyArguments() {
CodefValidator.requireNonNullElseThrow(publicKey, CodefError.NULL_PUBLIC_KEY);
CodefValidator.requireNonNullElseThrow(clientId, CodefError.NULL_CLIENT_ID);
CodefValidator.requireNonNullElseThrow(clientSecret, CodefError.NULL_CLIENT_SECRET);
CodefValidator.requireNonNullElseThrow(clientType, CodefError.NULL_CLIENT_TYPE);
}

private UUID parseUUID(String value, CodefError error) {
CodefValidator.requireNonNullElseThrow(value, error);
CodefValidator.requireValidUUIDPattern(value, error);

try {
return UUID.fromString(value);
} catch (Exception exception) {
throw CodefException.of(error, exception);
}
}

protected String getPublicKey() {
return publicKey;
}

protected UUID getClientId() {
return clientId;
}

protected UUID getClientSecret() {
return clientSecret;
}

protected CodefClientType getClientType() {
return clientType;
}
}
Loading

0 comments on commit f5c130d

Please sign in to comment.