From 006286da0c3f09c0a90c14cfa23572170369e702 Mon Sep 17 00:00:00 2001 From: lensferno Date: Fri, 7 Jul 2023 20:11:08 +0800 Subject: [PATCH] all --- .flattened-pom.xml | 42 +++++ .gitignore | 38 +++++ .gitmodules | 3 + .idea/.gitignore | 8 + .idea/encodings.xml | 42 +++++ .idea/misc.xml | 15 ++ .idea/uiDesigner.xml | 124 ++++++++++++++ .idea/vcs.xml | 7 + backend-main/.flattened-pom.xml | 42 +++++ backend-main/.gitignore | 38 +++++ backend-main/pom.xml | 24 +++ .../src/main/java/cn/wustlinghang/Main.java | 7 + backend-main/web/.flattened-pom.xml | 41 +++++ backend-main/web/.gitignore | 38 +++++ backend-main/web/pom.xml | 20 +++ .../src/main/java/cn/wustlinghang/Main.java | 7 + common/.flattened-pom.xml | 41 +++++ common/.gitignore | 38 +++++ common/pom.xml | 20 +++ .../wusthelper/rpc/request/RpcRequest.java | 20 +++ .../wusthelper/rpc/response/ResponseCode.java | 63 +++++++ .../wusthelper/rpc/response/RpcResponse.java | 19 +++ external-library/.flattened-pom.xml | 42 +++++ external-library/.gitignore | 38 +++++ external-library/mywust | 1 + external-library/pom.xml | 24 +++ pom.xml | 117 +++++++++++++ sub-services/.flattened-pom.xml | 60 +++++++ sub-services/.gitignore | 38 +++++ sub-services/graduate/.flattened-pom.xml | 59 +++++++ sub-services/graduate/.gitignore | 38 +++++ sub-services/graduate/pom.xml | 20 +++ .../src/main/java/cn/wustlinghang/Main.java | 7 + sub-services/library/.flattened-pom.xml | 59 +++++++ sub-services/library/.gitignore | 38 +++++ sub-services/library/pom.xml | 20 +++ .../src/main/java/cn/wustlinghang/Main.java | 7 + sub-services/physics/.flattened-pom.xml | 59 +++++++ sub-services/physics/.gitignore | 38 +++++ sub-services/physics/pom.xml | 20 +++ .../src/main/java/cn/wustlinghang/Main.java | 7 + sub-services/pom.xml | 45 +++++ sub-services/undergrad/.flattened-pom.xml | 101 +++++++++++ sub-services/undergrad/.gitignore | 38 +++++ sub-services/undergrad/pom.xml | 160 ++++++++++++++++++ .../undergrad/src/main/docker/Dockerfile.jvm | 54 ++++++ .../src/main/docker/Dockerfile.legacy-jar | 51 ++++++ .../src/main/docker/Dockerfile.native | 27 +++ .../src/main/docker/Dockerfile.native-micro | 23 +++ .../undergrad/api/json/CookieApi.java | 32 ++++ .../undergrad/api/json/CourseTableApi.java | 52 ++++++ .../undergrad/api/json/CreditStatusApi.java | 51 ++++++ .../internal/undergrad/api/json/ScoreApi.java | 51 ++++++ .../undergrad/api/json/StudentInfoApi.java | 47 +++++ .../undergrad/api/json/TrainingPlanApi.java | 51 ++++++ .../api/json/handler/ApiExceptionHandler.java | 15 ++ .../json/handler/DefaultExceptionHandler.java | 21 +++ .../json/handler/ExceptionHandlerBase.java | 33 ++++ .../api/json/handler/IOExceptionHandler.java | 23 +++ .../json/handler/ParseExceptionHandler.java | 22 +++ .../handler/ValidationExceptionHandler.java | 23 +++ .../ResponseWrapperInterceptor.java | 36 ++++ .../internal/undergrad/bean/JacksonBean.java | 12 ++ .../undergrad/bean/MywustParserBeans.java | 36 ++++ .../bean/MywustRequestAgentBeans.java | 63 +++++++ .../exception/InternalException.java | 4 + .../undergrad/services/LoginService.java | 32 ++++ .../undergrad/services/ParseService.java | 60 +++++++ .../services/RequestAgentService.java | 62 +++++++ .../resources/META-INF/resources/index.html | 152 +++++++++++++++++ .../src/main/resources/application.properties | 5 + 71 files changed, 2771 insertions(+) create mode 100644 .flattened-pom.xml create mode 100644 .gitignore create mode 100644 .gitmodules create mode 100644 .idea/.gitignore create mode 100644 .idea/encodings.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/uiDesigner.xml create mode 100644 .idea/vcs.xml create mode 100644 backend-main/.flattened-pom.xml create mode 100644 backend-main/.gitignore create mode 100644 backend-main/pom.xml create mode 100644 backend-main/src/main/java/cn/wustlinghang/Main.java create mode 100644 backend-main/web/.flattened-pom.xml create mode 100644 backend-main/web/.gitignore create mode 100644 backend-main/web/pom.xml create mode 100644 backend-main/web/src/main/java/cn/wustlinghang/Main.java create mode 100644 common/.flattened-pom.xml create mode 100644 common/.gitignore create mode 100644 common/pom.xml create mode 100644 common/src/main/java/cn/wustlinghang/wusthelper/rpc/request/RpcRequest.java create mode 100644 common/src/main/java/cn/wustlinghang/wusthelper/rpc/response/ResponseCode.java create mode 100644 common/src/main/java/cn/wustlinghang/wusthelper/rpc/response/RpcResponse.java create mode 100644 external-library/.flattened-pom.xml create mode 100644 external-library/.gitignore create mode 160000 external-library/mywust create mode 100644 external-library/pom.xml create mode 100644 pom.xml create mode 100644 sub-services/.flattened-pom.xml create mode 100644 sub-services/.gitignore create mode 100644 sub-services/graduate/.flattened-pom.xml create mode 100644 sub-services/graduate/.gitignore create mode 100644 sub-services/graduate/pom.xml create mode 100644 sub-services/graduate/src/main/java/cn/wustlinghang/Main.java create mode 100644 sub-services/library/.flattened-pom.xml create mode 100644 sub-services/library/.gitignore create mode 100644 sub-services/library/pom.xml create mode 100644 sub-services/library/src/main/java/cn/wustlinghang/Main.java create mode 100644 sub-services/physics/.flattened-pom.xml create mode 100644 sub-services/physics/.gitignore create mode 100644 sub-services/physics/pom.xml create mode 100644 sub-services/physics/src/main/java/cn/wustlinghang/Main.java create mode 100644 sub-services/pom.xml create mode 100644 sub-services/undergrad/.flattened-pom.xml create mode 100644 sub-services/undergrad/.gitignore create mode 100644 sub-services/undergrad/pom.xml create mode 100644 sub-services/undergrad/src/main/docker/Dockerfile.jvm create mode 100644 sub-services/undergrad/src/main/docker/Dockerfile.legacy-jar create mode 100644 sub-services/undergrad/src/main/docker/Dockerfile.native create mode 100644 sub-services/undergrad/src/main/docker/Dockerfile.native-micro create mode 100644 sub-services/undergrad/src/main/java/cn/wustlinghang/wusthelper/internal/undergrad/api/json/CookieApi.java create mode 100644 sub-services/undergrad/src/main/java/cn/wustlinghang/wusthelper/internal/undergrad/api/json/CourseTableApi.java create mode 100644 sub-services/undergrad/src/main/java/cn/wustlinghang/wusthelper/internal/undergrad/api/json/CreditStatusApi.java create mode 100644 sub-services/undergrad/src/main/java/cn/wustlinghang/wusthelper/internal/undergrad/api/json/ScoreApi.java create mode 100644 sub-services/undergrad/src/main/java/cn/wustlinghang/wusthelper/internal/undergrad/api/json/StudentInfoApi.java create mode 100644 sub-services/undergrad/src/main/java/cn/wustlinghang/wusthelper/internal/undergrad/api/json/TrainingPlanApi.java create mode 100644 sub-services/undergrad/src/main/java/cn/wustlinghang/wusthelper/internal/undergrad/api/json/handler/ApiExceptionHandler.java create mode 100644 sub-services/undergrad/src/main/java/cn/wustlinghang/wusthelper/internal/undergrad/api/json/handler/DefaultExceptionHandler.java create mode 100644 sub-services/undergrad/src/main/java/cn/wustlinghang/wusthelper/internal/undergrad/api/json/handler/ExceptionHandlerBase.java create mode 100644 sub-services/undergrad/src/main/java/cn/wustlinghang/wusthelper/internal/undergrad/api/json/handler/IOExceptionHandler.java create mode 100644 sub-services/undergrad/src/main/java/cn/wustlinghang/wusthelper/internal/undergrad/api/json/handler/ParseExceptionHandler.java create mode 100644 sub-services/undergrad/src/main/java/cn/wustlinghang/wusthelper/internal/undergrad/api/json/handler/ValidationExceptionHandler.java create mode 100644 sub-services/undergrad/src/main/java/cn/wustlinghang/wusthelper/internal/undergrad/api/json/interceptor/ResponseWrapperInterceptor.java create mode 100644 sub-services/undergrad/src/main/java/cn/wustlinghang/wusthelper/internal/undergrad/bean/JacksonBean.java create mode 100644 sub-services/undergrad/src/main/java/cn/wustlinghang/wusthelper/internal/undergrad/bean/MywustParserBeans.java create mode 100644 sub-services/undergrad/src/main/java/cn/wustlinghang/wusthelper/internal/undergrad/bean/MywustRequestAgentBeans.java create mode 100644 sub-services/undergrad/src/main/java/cn/wustlinghang/wusthelper/internal/undergrad/exception/InternalException.java create mode 100644 sub-services/undergrad/src/main/java/cn/wustlinghang/wusthelper/internal/undergrad/services/LoginService.java create mode 100644 sub-services/undergrad/src/main/java/cn/wustlinghang/wusthelper/internal/undergrad/services/ParseService.java create mode 100644 sub-services/undergrad/src/main/java/cn/wustlinghang/wusthelper/internal/undergrad/services/RequestAgentService.java create mode 100644 sub-services/undergrad/src/main/resources/META-INF/resources/index.html create mode 100644 sub-services/undergrad/src/main/resources/application.properties diff --git a/.flattened-pom.xml b/.flattened-pom.xml new file mode 100644 index 0000000..8d7a637 --- /dev/null +++ b/.flattened-pom.xml @@ -0,0 +1,42 @@ + + + 4.0.0 + cn.wustlinghang.wusthelper + wusthelper-backend + 0.0.1-SNAPSHOT + pom + + + jakarta.annotation + jakarta.annotation-api + 2.1.1 + compile + + + javax.annotation + javax.annotation-api + 1.3.2 + compile + + + org.projectlombok + lombok + 1.18.26 + provided + + + + + central + https://repo1.maven.org/maven2 + + + + true + + github + https://maven.pkg.github.com/LingHangStudio/mywust + + + diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5ff6309 --- /dev/null +++ b/.gitignore @@ -0,0 +1,38 @@ +target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ + +### IntelliJ IDEA ### +.idea/modules.xml +.idea/jarRepositories.xml +.idea/compiler.xml +.idea/libraries/ +*.iws +*.iml +*.ipr + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store \ No newline at end of file diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..7a20a58 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "external-library/mywust"] + path = external-library/mywust + url = https://github.com/LingHangStudio/mywust.git diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000..f4e9c15 --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,42 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..2c9b06b --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,15 @@ + + + + + + + + + + \ No newline at end of file diff --git a/.idea/uiDesigner.xml b/.idea/uiDesigner.xml new file mode 100644 index 0000000..6d50cd4 --- /dev/null +++ b/.idea/uiDesigner.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..90d78de --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/backend-main/.flattened-pom.xml b/backend-main/.flattened-pom.xml new file mode 100644 index 0000000..bd164ed --- /dev/null +++ b/backend-main/.flattened-pom.xml @@ -0,0 +1,42 @@ + + + 4.0.0 + cn.wustlinghang.wusthelper + backend-main + 0.0.1-SNAPSHOT + pom + + + jakarta.annotation + jakarta.annotation-api + 2.1.1 + compile + + + javax.annotation + javax.annotation-api + 1.3.2 + compile + + + org.projectlombok + lombok + 1.18.26 + provided + + + + + central + https://repo1.maven.org/maven2 + + + + true + + github + https://maven.pkg.github.com/LingHangStudio/mywust + + + diff --git a/backend-main/.gitignore b/backend-main/.gitignore new file mode 100644 index 0000000..5ff6309 --- /dev/null +++ b/backend-main/.gitignore @@ -0,0 +1,38 @@ +target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ + +### IntelliJ IDEA ### +.idea/modules.xml +.idea/jarRepositories.xml +.idea/compiler.xml +.idea/libraries/ +*.iws +*.iml +*.ipr + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store \ No newline at end of file diff --git a/backend-main/pom.xml b/backend-main/pom.xml new file mode 100644 index 0000000..40a31ca --- /dev/null +++ b/backend-main/pom.xml @@ -0,0 +1,24 @@ + + + 4.0.0 + + cn.wustlinghang.wusthelper + wusthelper-backend + ${revision} + + + backend-main + pom + + web + + + + 17 + 17 + UTF-8 + + + \ No newline at end of file diff --git a/backend-main/src/main/java/cn/wustlinghang/Main.java b/backend-main/src/main/java/cn/wustlinghang/Main.java new file mode 100644 index 0000000..5841a4a --- /dev/null +++ b/backend-main/src/main/java/cn/wustlinghang/Main.java @@ -0,0 +1,7 @@ +package cn.wustlinghang; + +public class Main { + public static void main(String[] args) { + System.out.println("Hello world!"); + } +} \ No newline at end of file diff --git a/backend-main/web/.flattened-pom.xml b/backend-main/web/.flattened-pom.xml new file mode 100644 index 0000000..5ea72be --- /dev/null +++ b/backend-main/web/.flattened-pom.xml @@ -0,0 +1,41 @@ + + + 4.0.0 + cn.wustlinghang.wusthelper + web + 0.0.1-SNAPSHOT + + + jakarta.annotation + jakarta.annotation-api + 2.1.1 + compile + + + javax.annotation + javax.annotation-api + 1.3.2 + compile + + + org.projectlombok + lombok + 1.18.26 + provided + + + + + central + https://repo1.maven.org/maven2 + + + + true + + github + https://maven.pkg.github.com/LingHangStudio/mywust + + + diff --git a/backend-main/web/.gitignore b/backend-main/web/.gitignore new file mode 100644 index 0000000..5ff6309 --- /dev/null +++ b/backend-main/web/.gitignore @@ -0,0 +1,38 @@ +target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ + +### IntelliJ IDEA ### +.idea/modules.xml +.idea/jarRepositories.xml +.idea/compiler.xml +.idea/libraries/ +*.iws +*.iml +*.ipr + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store \ No newline at end of file diff --git a/backend-main/web/pom.xml b/backend-main/web/pom.xml new file mode 100644 index 0000000..dc67f63 --- /dev/null +++ b/backend-main/web/pom.xml @@ -0,0 +1,20 @@ + + + 4.0.0 + + cn.wustlinghang.wusthelper + backend-main + ${revision} + + + web + + + 17 + 17 + UTF-8 + + + \ No newline at end of file diff --git a/backend-main/web/src/main/java/cn/wustlinghang/Main.java b/backend-main/web/src/main/java/cn/wustlinghang/Main.java new file mode 100644 index 0000000..5841a4a --- /dev/null +++ b/backend-main/web/src/main/java/cn/wustlinghang/Main.java @@ -0,0 +1,7 @@ +package cn.wustlinghang; + +public class Main { + public static void main(String[] args) { + System.out.println("Hello world!"); + } +} \ No newline at end of file diff --git a/common/.flattened-pom.xml b/common/.flattened-pom.xml new file mode 100644 index 0000000..9c94544 --- /dev/null +++ b/common/.flattened-pom.xml @@ -0,0 +1,41 @@ + + + 4.0.0 + cn.wustlinghang.wusthelper + common + 0.0.1-SNAPSHOT + + + jakarta.annotation + jakarta.annotation-api + 2.1.1 + compile + + + javax.annotation + javax.annotation-api + 1.3.2 + compile + + + org.projectlombok + lombok + 1.18.26 + provided + + + + + central + https://repo1.maven.org/maven2 + + + + true + + github + https://maven.pkg.github.com/LingHangStudio/mywust + + + diff --git a/common/.gitignore b/common/.gitignore new file mode 100644 index 0000000..5ff6309 --- /dev/null +++ b/common/.gitignore @@ -0,0 +1,38 @@ +target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ + +### IntelliJ IDEA ### +.idea/modules.xml +.idea/jarRepositories.xml +.idea/compiler.xml +.idea/libraries/ +*.iws +*.iml +*.ipr + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store \ No newline at end of file diff --git a/common/pom.xml b/common/pom.xml new file mode 100644 index 0000000..46b923c --- /dev/null +++ b/common/pom.xml @@ -0,0 +1,20 @@ + + + 4.0.0 + + cn.wustlinghang.wusthelper + wusthelper-backend + ${revision} + + + common + + + 17 + 17 + UTF-8 + + + \ No newline at end of file diff --git a/common/src/main/java/cn/wustlinghang/wusthelper/rpc/request/RpcRequest.java b/common/src/main/java/cn/wustlinghang/wusthelper/rpc/request/RpcRequest.java new file mode 100644 index 0000000..9eabf59 --- /dev/null +++ b/common/src/main/java/cn/wustlinghang/wusthelper/rpc/request/RpcRequest.java @@ -0,0 +1,20 @@ +package cn.wustlinghang.wusthelper.rpc.request; + +import lombok.Data; + +import java.util.HashMap; +import java.util.Map; + +@Data +public class RpcRequest { + private final Map arg; + + public RpcRequest() { + this.arg = new HashMap<>(); + } + + public RpcRequest addArg(String key, String value) { + this.arg.put(key, value); + return this; + } +} \ No newline at end of file diff --git a/common/src/main/java/cn/wustlinghang/wusthelper/rpc/response/ResponseCode.java b/common/src/main/java/cn/wustlinghang/wusthelper/rpc/response/ResponseCode.java new file mode 100644 index 0000000..1c30660 --- /dev/null +++ b/common/src/main/java/cn/wustlinghang/wusthelper/rpc/response/ResponseCode.java @@ -0,0 +1,63 @@ +/* + * Class created by lensfrex. + */ + +package cn.wustlinghang.wusthelper.rpc.response; + +public enum ResponseCode { + SUCCESS(20000, "成功"), + REQUEST_TOO_FAST(20001, "技能冷却中..."), + INVALID_REQUEST(30000, "非法请求"), + PARAM_WRONG(30001, "参数错误"), + PERMISSION_DENIED(40000, "权限不足"), + TOKEN_EXPIRED(40001, "token过期"), + TOKEN_INVALID(40002, "token无效"), + SERVER_INTERNAL_ERROR(50000, "服务器内部错误"), + API_NOT_IMPLEMENT(0, "接口未实现"), + + STUDENT_ID_DOES_NOT_EXISTS(60001,"学生学号不存在"), + USER_WAS_BANNED_PUBLISH(60201, "用户被禁止发布告示信息"), + IMAGE_FORMAT_WORN(60202, "上传的图片格式有误"), + NOTICE_WAS_INTERCEPT(60203, "消息被系统拦截发布"), + + USER_DOES_NOT_MATCH_PUBLISHER(60301, "请求用户与告示发表者不匹配"), + + REQUEST_FILE_DOES_NOT_EXIST(60701, "请求的文件不存在"); + + private final int code; + + private final String message; + + ResponseCode(int code, String message) { + this.code = code; + this.message = message; + } + + public int getCode() { + return code; + } + + public String getMessage() { + return message; + } +} + + +enum Code { + Success, Fail, Wron +} + +class Singleton { + private static Singleton instance; + + private Singleton() { + } + + public static Singleton getInstance() { + if (instance == null) { + instance = new Singleton(); + } + + return instance; + } +} \ No newline at end of file diff --git a/common/src/main/java/cn/wustlinghang/wusthelper/rpc/response/RpcResponse.java b/common/src/main/java/cn/wustlinghang/wusthelper/rpc/response/RpcResponse.java new file mode 100644 index 0000000..8d89dfa --- /dev/null +++ b/common/src/main/java/cn/wustlinghang/wusthelper/rpc/response/RpcResponse.java @@ -0,0 +1,19 @@ +package cn.wustlinghang.wusthelper.rpc.response; + +public record RpcResponse(int code, String msg, T data) { + public static RpcResponse success(T data) { + return new RpcResponse<>(ResponseCode.SUCCESS.getCode(), "ok", data); + } + + public static RpcResponse success() { + return success(null); + } + + public static RpcResponse error(int code, String message) { + return new RpcResponse<>(code, message, null); + } + + public static RpcResponse error(ResponseCode code) { + return error(code.getCode(), code.getMessage()); + } +} \ No newline at end of file diff --git a/external-library/.flattened-pom.xml b/external-library/.flattened-pom.xml new file mode 100644 index 0000000..40f6d06 --- /dev/null +++ b/external-library/.flattened-pom.xml @@ -0,0 +1,42 @@ + + + 4.0.0 + cn.wustlinghang.wusthelper + external-library + 0.0.1-SNAPSHOT + pom + + + jakarta.annotation + jakarta.annotation-api + 2.1.1 + compile + + + javax.annotation + javax.annotation-api + 1.3.2 + compile + + + org.projectlombok + lombok + 1.18.26 + provided + + + + + central + https://repo1.maven.org/maven2 + + + + true + + github + https://maven.pkg.github.com/LingHangStudio/mywust + + + diff --git a/external-library/.gitignore b/external-library/.gitignore new file mode 100644 index 0000000..5ff6309 --- /dev/null +++ b/external-library/.gitignore @@ -0,0 +1,38 @@ +target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ + +### IntelliJ IDEA ### +.idea/modules.xml +.idea/jarRepositories.xml +.idea/compiler.xml +.idea/libraries/ +*.iws +*.iml +*.ipr + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store \ No newline at end of file diff --git a/external-library/mywust b/external-library/mywust new file mode 160000 index 0000000..4b32c58 --- /dev/null +++ b/external-library/mywust @@ -0,0 +1 @@ +Subproject commit 4b32c584249bffec4767d4b6a075af842127d5d2 diff --git a/external-library/pom.xml b/external-library/pom.xml new file mode 100644 index 0000000..0dc7650 --- /dev/null +++ b/external-library/pom.xml @@ -0,0 +1,24 @@ + + + 4.0.0 + + cn.wustlinghang.wusthelper + wusthelper-backend + ${revision} + + + external-library + pom + + mywust + + + + 17 + 17 + UTF-8 + + + \ No newline at end of file diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..afb8ad4 --- /dev/null +++ b/pom.xml @@ -0,0 +1,117 @@ + + + 4.0.0 + + cn.wustlinghang.wusthelper + wusthelper-backend + ${revision} + + pom + + backend-main + sub-services + common + external-library + + + + 0.0.1-SNAPSHOT + + + 17 + 17 + UTF-8 + + 0.0.2-SNAPSHOT + 1.18.26 + 5.8.20 + + + + + + jakarta.annotation + jakarta.annotation-api + 2.1.1 + + + javax.annotation + javax.annotation-api + 1.3.2 + + + + org.projectlombok + lombok + ${lombok.version} + + provided + + + + org.junit.jupiter + junit-jupiter + RELEASE + test + + + + + + + cn.hutool + hutool-bom + ${hutool.version} + pom + import + + + + + + + central + https://repo1.maven.org/maven2 + + + + + github + https://maven.pkg.github.com/LingHangStudio/mywust + + true + + + + + + + + org.codehaus.mojo + flatten-maven-plugin + 1.3.0 + + + + + flatten + process-resources + + flatten + + + + flatten.clean + clean + + clean + + + + + + + + \ No newline at end of file diff --git a/sub-services/.flattened-pom.xml b/sub-services/.flattened-pom.xml new file mode 100644 index 0000000..2429d0d --- /dev/null +++ b/sub-services/.flattened-pom.xml @@ -0,0 +1,60 @@ + + + 4.0.0 + cn.wustlinghang.wusthelper + sub-services + 0.0.1-SNAPSHOT + pom + + + cn.wustlinghang + mywust-core + 0.0.2-SNAPSHOT + compile + + + cn.wustlinghang + mywust-network-okhttp + 0.0.2-SNAPSHOT + compile + + + cn.wustlinghang.wusthelper + common + 0.0.1-SNAPSHOT + compile + + + jakarta.annotation + jakarta.annotation-api + 2.1.1 + compile + + + javax.annotation + javax.annotation-api + 1.3.2 + compile + + + org.projectlombok + lombok + 1.18.26 + provided + + + + + central + https://repo1.maven.org/maven2 + + + + true + + github + https://maven.pkg.github.com/LingHangStudio/mywust + + + diff --git a/sub-services/.gitignore b/sub-services/.gitignore new file mode 100644 index 0000000..5ff6309 --- /dev/null +++ b/sub-services/.gitignore @@ -0,0 +1,38 @@ +target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ + +### IntelliJ IDEA ### +.idea/modules.xml +.idea/jarRepositories.xml +.idea/compiler.xml +.idea/libraries/ +*.iws +*.iml +*.ipr + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store \ No newline at end of file diff --git a/sub-services/graduate/.flattened-pom.xml b/sub-services/graduate/.flattened-pom.xml new file mode 100644 index 0000000..6521878 --- /dev/null +++ b/sub-services/graduate/.flattened-pom.xml @@ -0,0 +1,59 @@ + + + 4.0.0 + cn.wustlinghang.wusthelper + graduate + 0.0.1-SNAPSHOT + + + cn.wustlinghang + mywust-core + 0.0.2-SNAPSHOT + compile + + + cn.wustlinghang + mywust-network-okhttp + 0.0.2-SNAPSHOT + compile + + + cn.wustlinghang.wusthelper + common + 0.0.1-SNAPSHOT + compile + + + jakarta.annotation + jakarta.annotation-api + 2.1.1 + compile + + + javax.annotation + javax.annotation-api + 1.3.2 + compile + + + org.projectlombok + lombok + 1.18.26 + provided + + + + + central + https://repo1.maven.org/maven2 + + + + true + + github + https://maven.pkg.github.com/LingHangStudio/mywust + + + diff --git a/sub-services/graduate/.gitignore b/sub-services/graduate/.gitignore new file mode 100644 index 0000000..5ff6309 --- /dev/null +++ b/sub-services/graduate/.gitignore @@ -0,0 +1,38 @@ +target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ + +### IntelliJ IDEA ### +.idea/modules.xml +.idea/jarRepositories.xml +.idea/compiler.xml +.idea/libraries/ +*.iws +*.iml +*.ipr + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store \ No newline at end of file diff --git a/sub-services/graduate/pom.xml b/sub-services/graduate/pom.xml new file mode 100644 index 0000000..e04b53a --- /dev/null +++ b/sub-services/graduate/pom.xml @@ -0,0 +1,20 @@ + + + 4.0.0 + + cn.wustlinghang.wusthelper + sub-services + ${revision} + + + graduate + + + 17 + 17 + UTF-8 + + + \ No newline at end of file diff --git a/sub-services/graduate/src/main/java/cn/wustlinghang/Main.java b/sub-services/graduate/src/main/java/cn/wustlinghang/Main.java new file mode 100644 index 0000000..5841a4a --- /dev/null +++ b/sub-services/graduate/src/main/java/cn/wustlinghang/Main.java @@ -0,0 +1,7 @@ +package cn.wustlinghang; + +public class Main { + public static void main(String[] args) { + System.out.println("Hello world!"); + } +} \ No newline at end of file diff --git a/sub-services/library/.flattened-pom.xml b/sub-services/library/.flattened-pom.xml new file mode 100644 index 0000000..74a5aeb --- /dev/null +++ b/sub-services/library/.flattened-pom.xml @@ -0,0 +1,59 @@ + + + 4.0.0 + cn.wustlinghang.wusthelper + library + 0.0.1-SNAPSHOT + + + cn.wustlinghang + mywust-core + 0.0.2-SNAPSHOT + compile + + + cn.wustlinghang + mywust-network-okhttp + 0.0.2-SNAPSHOT + compile + + + cn.wustlinghang.wusthelper + common + 0.0.1-SNAPSHOT + compile + + + jakarta.annotation + jakarta.annotation-api + 2.1.1 + compile + + + javax.annotation + javax.annotation-api + 1.3.2 + compile + + + org.projectlombok + lombok + 1.18.26 + provided + + + + + central + https://repo1.maven.org/maven2 + + + + true + + github + https://maven.pkg.github.com/LingHangStudio/mywust + + + diff --git a/sub-services/library/.gitignore b/sub-services/library/.gitignore new file mode 100644 index 0000000..5ff6309 --- /dev/null +++ b/sub-services/library/.gitignore @@ -0,0 +1,38 @@ +target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ + +### IntelliJ IDEA ### +.idea/modules.xml +.idea/jarRepositories.xml +.idea/compiler.xml +.idea/libraries/ +*.iws +*.iml +*.ipr + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store \ No newline at end of file diff --git a/sub-services/library/pom.xml b/sub-services/library/pom.xml new file mode 100644 index 0000000..4fb962c --- /dev/null +++ b/sub-services/library/pom.xml @@ -0,0 +1,20 @@ + + + 4.0.0 + + cn.wustlinghang.wusthelper + sub-services + ${revision} + + + library + + + 17 + 17 + UTF-8 + + + \ No newline at end of file diff --git a/sub-services/library/src/main/java/cn/wustlinghang/Main.java b/sub-services/library/src/main/java/cn/wustlinghang/Main.java new file mode 100644 index 0000000..5841a4a --- /dev/null +++ b/sub-services/library/src/main/java/cn/wustlinghang/Main.java @@ -0,0 +1,7 @@ +package cn.wustlinghang; + +public class Main { + public static void main(String[] args) { + System.out.println("Hello world!"); + } +} \ No newline at end of file diff --git a/sub-services/physics/.flattened-pom.xml b/sub-services/physics/.flattened-pom.xml new file mode 100644 index 0000000..0255900 --- /dev/null +++ b/sub-services/physics/.flattened-pom.xml @@ -0,0 +1,59 @@ + + + 4.0.0 + cn.wustlinghang.wusthelper + physics + 0.0.1-SNAPSHOT + + + cn.wustlinghang + mywust-core + 0.0.2-SNAPSHOT + compile + + + cn.wustlinghang + mywust-network-okhttp + 0.0.2-SNAPSHOT + compile + + + cn.wustlinghang.wusthelper + common + 0.0.1-SNAPSHOT + compile + + + jakarta.annotation + jakarta.annotation-api + 2.1.1 + compile + + + javax.annotation + javax.annotation-api + 1.3.2 + compile + + + org.projectlombok + lombok + 1.18.26 + provided + + + + + central + https://repo1.maven.org/maven2 + + + + true + + github + https://maven.pkg.github.com/LingHangStudio/mywust + + + diff --git a/sub-services/physics/.gitignore b/sub-services/physics/.gitignore new file mode 100644 index 0000000..5ff6309 --- /dev/null +++ b/sub-services/physics/.gitignore @@ -0,0 +1,38 @@ +target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ + +### IntelliJ IDEA ### +.idea/modules.xml +.idea/jarRepositories.xml +.idea/compiler.xml +.idea/libraries/ +*.iws +*.iml +*.ipr + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store \ No newline at end of file diff --git a/sub-services/physics/pom.xml b/sub-services/physics/pom.xml new file mode 100644 index 0000000..584ed7f --- /dev/null +++ b/sub-services/physics/pom.xml @@ -0,0 +1,20 @@ + + + 4.0.0 + + cn.wustlinghang.wusthelper + sub-services + ${revision} + + + physics + + + 17 + 17 + UTF-8 + + + \ No newline at end of file diff --git a/sub-services/physics/src/main/java/cn/wustlinghang/Main.java b/sub-services/physics/src/main/java/cn/wustlinghang/Main.java new file mode 100644 index 0000000..5841a4a --- /dev/null +++ b/sub-services/physics/src/main/java/cn/wustlinghang/Main.java @@ -0,0 +1,7 @@ +package cn.wustlinghang; + +public class Main { + public static void main(String[] args) { + System.out.println("Hello world!"); + } +} \ No newline at end of file diff --git a/sub-services/pom.xml b/sub-services/pom.xml new file mode 100644 index 0000000..8f1f734 --- /dev/null +++ b/sub-services/pom.xml @@ -0,0 +1,45 @@ + + + 4.0.0 + + cn.wustlinghang.wusthelper + wusthelper-backend + ${revision} + + + sub-services + pom + + undergrad + graduate + library + physics + + + + 17 + 17 + UTF-8 + + + + + cn.wustlinghang + mywust-core + 0.0.2-SNAPSHOT + + + cn.wustlinghang + mywust-network-okhttp + ${mywust.version} + + + + cn.wustlinghang.wusthelper + common + ${revision} + + + \ No newline at end of file diff --git a/sub-services/undergrad/.flattened-pom.xml b/sub-services/undergrad/.flattened-pom.xml new file mode 100644 index 0000000..aff758f --- /dev/null +++ b/sub-services/undergrad/.flattened-pom.xml @@ -0,0 +1,101 @@ + + + 4.0.0 + cn.wustlinghang.wusthelper + undergrad + 0.0.1-SNAPSHOT + + + io.quarkus + quarkus-resteasy-reactive + 3.1.3.Final + compile + + + io.quarkus + quarkus-resteasy-reactive-jackson + 3.1.3.Final + compile + + + io.quarkus + quarkus-resteasy-deployment + 3.1.3.Final + compile + + + io.quarkus + quarkus-core-deployment + 3.1.3.Final + compile + + + io.quarkus + quarkus-hibernate-validator + 3.1.3.Final + compile + + + org.hibernate.validator + hibernate-validator + 8.0.1.Final + compile + + + cn.hutool + hutool-core + 5.8.20 + compile + + + cn.wustlinghang + mywust-core + 0.0.2-SNAPSHOT + compile + + + cn.wustlinghang + mywust-network-okhttp + 0.0.2-SNAPSHOT + compile + + + cn.wustlinghang.wusthelper + common + 0.0.1-SNAPSHOT + compile + + + jakarta.annotation + jakarta.annotation-api + 2.1.1 + compile + + + javax.annotation + javax.annotation-api + 1.3.2 + compile + + + org.projectlombok + lombok + 1.18.26 + provided + + + + + central + https://repo1.maven.org/maven2 + + + + true + + github + https://maven.pkg.github.com/LingHangStudio/mywust + + + diff --git a/sub-services/undergrad/.gitignore b/sub-services/undergrad/.gitignore new file mode 100644 index 0000000..5ff6309 --- /dev/null +++ b/sub-services/undergrad/.gitignore @@ -0,0 +1,38 @@ +target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ + +### IntelliJ IDEA ### +.idea/modules.xml +.idea/jarRepositories.xml +.idea/compiler.xml +.idea/libraries/ +*.iws +*.iml +*.ipr + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store \ No newline at end of file diff --git a/sub-services/undergrad/pom.xml b/sub-services/undergrad/pom.xml new file mode 100644 index 0000000..e8783ad --- /dev/null +++ b/sub-services/undergrad/pom.xml @@ -0,0 +1,160 @@ + + + 4.0.0 + + cn.wustlinghang.wusthelper + sub-services + ${revision} + + + undergrad + + + quarkus-bom + io.quarkus + 3.1.3.Final + 3.8.1 + 3.0.0-M7 + UTF-8 + + 17 + 17 + true + + 8.0.1.Final + + + + + + io.quarkus + quarkus-bom + ${quarkus.platform.version} + pom + import + + + + + + + io.quarkus + quarkus-resteasy-reactive + + + io.quarkus + quarkus-resteasy-reactive-jackson + + + io.quarkus + quarkus-resteasy-deployment + + + io.quarkus + quarkus-core-deployment + + + + + io.quarkus + quarkus-hibernate-validator + + + org.hibernate.validator + hibernate-validator + ${hibernate-validator.version} + + + + io.quarkus + quarkus-junit5 + test + + + io.rest-assured + rest-assured + test + + + + cn.hutool + hutool-core + + + + + + + maven-compiler-plugin + ${compiler-plugin.version} + + + maven-surefire-plugin + ${surefire-plugin.version} + + + org.jboss.logmanager.LogManager + ${maven.home} + UTF-8 + + + + + ${quarkus.platform.group-id} + quarkus-maven-plugin + ${quarkus.platform.version} + + + UTF-8 + + + + + + build + + + + + + + + + + native + + + native + + + + native + + + + + maven-failsafe-plugin + ${surefire-plugin.version} + + + + integration-test + verify + + + + ${project.build.directory}/${project.build.finalName}-runner + org.jboss.logmanager.LogManager + ${maven.home} + + + + + + + + + + \ No newline at end of file diff --git a/sub-services/undergrad/src/main/docker/Dockerfile.jvm b/sub-services/undergrad/src/main/docker/Dockerfile.jvm new file mode 100644 index 0000000..120590a --- /dev/null +++ b/sub-services/undergrad/src/main/docker/Dockerfile.jvm @@ -0,0 +1,54 @@ +#### +# This Dockerfile is used in order to build a container that runs the Quarkus application in JVM mode +# +# Before building the container image run: +# +# ./mvnw package +# +# Then, build the image with: +# +# docker build -f src/main/docker/Dockerfile.jvm -t quarkus/getting-started-jvm . +# +# Then run the container using: +# +# docker run -i --rm -p 8080:8080 quarkus/getting-started-jvm +# +# If you want to include the debug port into your docker image +# you will have to expose the debug port (default 5005) like this : EXPOSE 8080 5050 +# +# Then run the container using : +# +# docker run -i --rm -p 8080:8080 -p 5005:5005 -e JAVA_ENABLE_DEBUG="true" quarkus/getting-started-jvm +# +### +FROM registry.access.redhat.com/ubi8/ubi-minimal:8.3 + +ARG JAVA_PACKAGE=java-11-openjdk-headless +ARG RUN_JAVA_VERSION=1.3.8 +ENV LANG='en_US.UTF-8' LANGUAGE='en_US:en' +# Install java and the run-java script +# Also set up permissions for user `1001` +RUN microdnf install curl ca-certificates ${JAVA_PACKAGE} \ + && microdnf update \ + && microdnf clean all \ + && mkdir /deployments \ + && chown 1001 /deployments \ + && chmod "g+rwX" /deployments \ + && chown 1001:root /deployments \ + && curl https://repo1.maven.org/maven2/io/fabric8/run-java-sh/${RUN_JAVA_VERSION}/run-java-sh-${RUN_JAVA_VERSION}-sh.sh -o /deployments/run-java.sh \ + && chown 1001 /deployments/run-java.sh \ + && chmod 540 /deployments/run-java.sh \ + && echo "securerandom.source=file:/dev/urandom" >> /etc/alternatives/jre/lib/security/java.security + +# Configure the JAVA_OPTIONS, you can add -XshowSettings:vm to also display the heap size. +ENV JAVA_OPTIONS="-Dquarkus.http.host=0.0.0.0 -Djava.util.logging.manager=org.jboss.logmanager.LogManager" +# We make four distinct layers so if there are application changes the library layers can be re-used +COPY --chown=1001 target/quarkus-app/lib/ /deployments/lib/ +COPY --chown=1001 target/quarkus-app/*.jar /deployments/ +COPY --chown=1001 target/quarkus-app/app/ /deployments/app/ +COPY --chown=1001 target/quarkus-app/quarkus/ /deployments/quarkus/ + +EXPOSE 8080 +USER 1001 + +ENTRYPOINT [ "/deployments/run-java.sh" ] diff --git a/sub-services/undergrad/src/main/docker/Dockerfile.legacy-jar b/sub-services/undergrad/src/main/docker/Dockerfile.legacy-jar new file mode 100644 index 0000000..aab6080 --- /dev/null +++ b/sub-services/undergrad/src/main/docker/Dockerfile.legacy-jar @@ -0,0 +1,51 @@ +#### +# This Dockerfile is used in order to build a container that runs the Quarkus application in JVM mode +# +# Before building the container image run: +# +# ./mvnw package -Dquarkus.package.type=legacy-jar +# +# Then, build the image with: +# +# docker build -f src/main/docker/Dockerfile.legacy-jar -t quarkus/getting-started-legacy-jar . +# +# Then run the container using: +# +# docker run -i --rm -p 8080:8080 quarkus/getting-started-legacy-jar +# +# If you want to include the debug port into your docker image +# you will have to expose the debug port (default 5005) like this : EXPOSE 8080 5050 +# +# Then run the container using : +# +# docker run -i --rm -p 8080:8080 -p 5005:5005 -e JAVA_ENABLE_DEBUG="true" quarkus/getting-started-legacy-jar +# +### +FROM registry.access.redhat.com/ubi8/ubi-minimal:8.3 + +ARG JAVA_PACKAGE=java-11-openjdk-headless +ARG RUN_JAVA_VERSION=1.3.8 +ENV LANG='en_US.UTF-8' LANGUAGE='en_US:en' +# Install java and the run-java script +# Also set up permissions for user `1001` +RUN microdnf install curl ca-certificates ${JAVA_PACKAGE} \ + && microdnf update \ + && microdnf clean all \ + && mkdir /deployments \ + && chown 1001 /deployments \ + && chmod "g+rwX" /deployments \ + && chown 1001:root /deployments \ + && curl https://repo1.maven.org/maven2/io/fabric8/run-java-sh/${RUN_JAVA_VERSION}/run-java-sh-${RUN_JAVA_VERSION}-sh.sh -o /deployments/run-java.sh \ + && chown 1001 /deployments/run-java.sh \ + && chmod 540 /deployments/run-java.sh \ + && echo "securerandom.source=file:/dev/urandom" >> /etc/alternatives/jre/lib/security/java.security + +# Configure the JAVA_OPTIONS, you can add -XshowSettings:vm to also display the heap size. +ENV JAVA_OPTIONS="-Dquarkus.http.host=0.0.0.0 -Djava.util.logging.manager=org.jboss.logmanager.LogManager" +COPY target/lib/* /deployments/lib/ +COPY target/*-runner.jar /deployments/app.jar + +EXPOSE 8080 +USER 1001 + +ENTRYPOINT [ "/deployments/run-java.sh" ] diff --git a/sub-services/undergrad/src/main/docker/Dockerfile.native b/sub-services/undergrad/src/main/docker/Dockerfile.native new file mode 100644 index 0000000..7400c00 --- /dev/null +++ b/sub-services/undergrad/src/main/docker/Dockerfile.native @@ -0,0 +1,27 @@ +#### +# This Dockerfile is used in order to build a container that runs the Quarkus application in native (no JVM) mode +# +# Before building the container image run: +# +# ./mvnw package -Pnative +# +# Then, build the image with: +# +# docker build -f src/main/docker/Dockerfile.native -t quarkus/getting-started . +# +# Then run the container using: +# +# docker run -i --rm -p 8080:8080 quarkus/getting-started +# +### +FROM registry.access.redhat.com/ubi8/ubi-minimal:8.3 +WORKDIR /work/ +RUN chown 1001 /work \ + && chmod "g+rwX" /work \ + && chown 1001:root /work +COPY --chown=1001:root target/*-runner /work/application + +EXPOSE 8080 +USER 1001 + +CMD ["./application", "-Dquarkus.http.host=0.0.0.0"] diff --git a/sub-services/undergrad/src/main/docker/Dockerfile.native-micro b/sub-services/undergrad/src/main/docker/Dockerfile.native-micro new file mode 100644 index 0000000..df34168 --- /dev/null +++ b/sub-services/undergrad/src/main/docker/Dockerfile.native-micro @@ -0,0 +1,23 @@ +#### +# This Dockerfile is used in order to build a distroless container that runs the Quarkus application in native (no JVM) mode +# +# Before building the container image run: +# +# ./mvnw package -Pnative +# +# Then, build the image with: +# +# docker build -f src/main/docker/Dockerfile.native-micro -t quarkus/getting-started . +# +# Then run the container using: +# +# docker run -i --rm -p 8080:8080 quarkus/getting-started +# +### +FROM quay.io/quarkus/quarkus-micro-image:1.0 +COPY target/*-runner /application + +EXPOSE 8080 +USER 1001 + +CMD ["./application", "-Dquarkus.http.host=0.0.0.0"] diff --git a/sub-services/undergrad/src/main/java/cn/wustlinghang/wusthelper/internal/undergrad/api/json/CookieApi.java b/sub-services/undergrad/src/main/java/cn/wustlinghang/wusthelper/internal/undergrad/api/json/CookieApi.java new file mode 100644 index 0000000..3c88d95 --- /dev/null +++ b/sub-services/undergrad/src/main/java/cn/wustlinghang/wusthelper/internal/undergrad/api/json/CookieApi.java @@ -0,0 +1,32 @@ +package cn.wustlinghang.wusthelper.internal.undergrad.api.json; + +import cn.wustlinghang.mywust.exception.ApiException; +import cn.wustlinghang.wusthelper.internal.undergrad.services.LoginService; +import jakarta.validation.constraints.NotNull; +import jakarta.ws.rs.GET; +import jakarta.ws.rs.Path; +import jakarta.ws.rs.QueryParam; + +import java.io.IOException; + +@Path("/cookie") +public class CookieApi { + private final LoginService loginService; + + public CookieApi(LoginService loginService) { + this.loginService = loginService; + } + + @GET + @Path("/") + public String login(@QueryParam("username") @NotNull String username, + @QueryParam("password") @NotNull String password) throws IOException, ApiException { + return loginService.login(username, password, false); + } + + @GET + @Path("/verify") + public Boolean verify(@QueryParam("cookie") @NotNull String cookie) throws IOException { + return loginService.verify(cookie); + } +} diff --git a/sub-services/undergrad/src/main/java/cn/wustlinghang/wusthelper/internal/undergrad/api/json/CourseTableApi.java b/sub-services/undergrad/src/main/java/cn/wustlinghang/wusthelper/internal/undergrad/api/json/CourseTableApi.java new file mode 100644 index 0000000..0ea3310 --- /dev/null +++ b/sub-services/undergrad/src/main/java/cn/wustlinghang/wusthelper/internal/undergrad/api/json/CourseTableApi.java @@ -0,0 +1,52 @@ +package cn.wustlinghang.wusthelper.internal.undergrad.api.json; + +import cn.wustlinghang.mywust.core.parser.undergraduate.UndergradCourseTableParser; +import cn.wustlinghang.mywust.core.request.service.undergraduate.UndergradCourseTableApiService; +import cn.wustlinghang.mywust.data.global.Course; +import cn.wustlinghang.mywust.data.global.StudentInfo; +import cn.wustlinghang.mywust.exception.ApiException; +import cn.wustlinghang.mywust.exception.ParseException; +import cn.wustlinghang.wusthelper.rpc.response.RpcResponse; +import jakarta.enterprise.context.ApplicationScoped; +import jakarta.validation.constraints.NotNull; +import jakarta.ws.rs.GET; +import jakarta.ws.rs.POST; +import jakarta.ws.rs.Path; +import jakarta.ws.rs.QueryParam; + +import java.io.IOException; +import java.util.List; + +@Path("/course_table") +@ApplicationScoped +public class CourseTableApi { + private final UndergradCourseTableApiService studentInfoApiService; + private final UndergradCourseTableParser studentInfoPageParser; + + public CourseTableApi(UndergradCourseTableApiService studentInfoApiService, + UndergradCourseTableParser studentInfoPageParser) { + this.studentInfoApiService = studentInfoApiService; + this.studentInfoPageParser = studentInfoPageParser; + } + + @GET + @Path("/") + public List get(@QueryParam("cookie") @NotNull String cookie, @QueryParam("term") String term) + throws IOException, ApiException, ParseException { + String html = studentInfoApiService.getPage(term, cookie); + return this.parse(html); + } + + @GET + @Path("/agent") + public String agent(@QueryParam("cookie") @NotNull String cookie, @QueryParam("term") String term) + throws IOException, ApiException { + return studentInfoApiService.getPage(term, cookie); + } + + @POST + @Path("/parse") + public List parse(String html) throws ParseException { + return studentInfoPageParser.parse(html); + } +} diff --git a/sub-services/undergrad/src/main/java/cn/wustlinghang/wusthelper/internal/undergrad/api/json/CreditStatusApi.java b/sub-services/undergrad/src/main/java/cn/wustlinghang/wusthelper/internal/undergrad/api/json/CreditStatusApi.java new file mode 100644 index 0000000..d2e2ed0 --- /dev/null +++ b/sub-services/undergrad/src/main/java/cn/wustlinghang/wusthelper/internal/undergrad/api/json/CreditStatusApi.java @@ -0,0 +1,51 @@ +package cn.wustlinghang.wusthelper.internal.undergrad.api.json; + +import cn.wustlinghang.mywust.core.parser.undergraduate.UndergradStudentInfoPageParser; +import cn.wustlinghang.mywust.core.request.service.undergraduate.UndergradStudentInfoApiService; +import cn.wustlinghang.mywust.data.global.StudentInfo; +import cn.wustlinghang.mywust.exception.ApiException; +import cn.wustlinghang.mywust.exception.ParseException; +import cn.wustlinghang.wusthelper.rpc.response.RpcResponse; +import jakarta.enterprise.context.ApplicationScoped; +import jakarta.validation.constraints.NotNull; +import jakarta.ws.rs.GET; +import jakarta.ws.rs.POST; +import jakarta.ws.rs.Path; +import jakarta.ws.rs.QueryParam; + +import java.io.IOException; + +@Path("/credit_status") +@ApplicationScoped +public class CreditStatusApi { + private final UndergradStudentInfoApiService studentInfoApiService; + private final UndergradStudentInfoPageParser studentInfoPageParser; + + public CreditStatusApi(UndergradStudentInfoApiService studentInfoApiService, + UndergradStudentInfoPageParser studentInfoPageParser) { + this.studentInfoApiService = studentInfoApiService; + this.studentInfoPageParser = studentInfoPageParser; + } + + @GET + @Path("/") + public RpcResponse get(String cookie) throws IOException, ApiException, ParseException { + String html = studentInfoApiService.getPage(cookie); + return this.parse(html); + } + + @GET + @Path("/agent") + public RpcResponse agent(@QueryParam("cookie") @NotNull String cookie) + throws IOException, ApiException { + String html = studentInfoApiService.getPage(cookie); + return RpcResponse.success(html); + } + + @POST + @Path("/parse") + public RpcResponse parse(String html) throws ParseException { + StudentInfo result = studentInfoPageParser.parse(html); + return RpcResponse.success(result); + } +} diff --git a/sub-services/undergrad/src/main/java/cn/wustlinghang/wusthelper/internal/undergrad/api/json/ScoreApi.java b/sub-services/undergrad/src/main/java/cn/wustlinghang/wusthelper/internal/undergrad/api/json/ScoreApi.java new file mode 100644 index 0000000..73708ee --- /dev/null +++ b/sub-services/undergrad/src/main/java/cn/wustlinghang/wusthelper/internal/undergrad/api/json/ScoreApi.java @@ -0,0 +1,51 @@ +package cn.wustlinghang.wusthelper.internal.undergrad.api.json; + +import cn.wustlinghang.mywust.core.parser.undergraduate.UndergradStudentInfoPageParser; +import cn.wustlinghang.mywust.core.request.service.undergraduate.UndergradStudentInfoApiService; +import cn.wustlinghang.mywust.data.global.StudentInfo; +import cn.wustlinghang.mywust.exception.ApiException; +import cn.wustlinghang.mywust.exception.ParseException; +import cn.wustlinghang.wusthelper.rpc.response.RpcResponse; +import jakarta.enterprise.context.ApplicationScoped; +import jakarta.validation.constraints.NotNull; +import jakarta.ws.rs.GET; +import jakarta.ws.rs.POST; +import jakarta.ws.rs.Path; +import jakarta.ws.rs.QueryParam; + +import java.io.IOException; + +@Path("/score") +@ApplicationScoped +public class ScoreApi { + private final UndergradStudentInfoApiService studentInfoApiService; + private final UndergradStudentInfoPageParser studentInfoPageParser; + + public ScoreApi(UndergradStudentInfoApiService studentInfoApiService, + UndergradStudentInfoPageParser studentInfoPageParser) { + this.studentInfoApiService = studentInfoApiService; + this.studentInfoPageParser = studentInfoPageParser; + } + + @GET + @Path("/") + public RpcResponse get(String cookie) throws IOException, ApiException, ParseException { + String html = studentInfoApiService.getPage(cookie); + return this.parse(html); + } + + @GET + @Path("/agent") + public RpcResponse agent(@QueryParam("cookie") @NotNull String cookie) + throws IOException, ApiException { + String html = studentInfoApiService.getPage(cookie); + return RpcResponse.success(html); + } + + @POST + @Path("/parse") + public RpcResponse parse(String html) throws ParseException { + StudentInfo result = studentInfoPageParser.parse(html); + return RpcResponse.success(result); + } +} diff --git a/sub-services/undergrad/src/main/java/cn/wustlinghang/wusthelper/internal/undergrad/api/json/StudentInfoApi.java b/sub-services/undergrad/src/main/java/cn/wustlinghang/wusthelper/internal/undergrad/api/json/StudentInfoApi.java new file mode 100644 index 0000000..33c4c43 --- /dev/null +++ b/sub-services/undergrad/src/main/java/cn/wustlinghang/wusthelper/internal/undergrad/api/json/StudentInfoApi.java @@ -0,0 +1,47 @@ +package cn.wustlinghang.wusthelper.internal.undergrad.api.json; + +import cn.wustlinghang.mywust.core.parser.undergraduate.UndergradStudentInfoPageParser; +import cn.wustlinghang.mywust.core.request.service.undergraduate.UndergradStudentInfoApiService; +import cn.wustlinghang.mywust.data.global.StudentInfo; +import cn.wustlinghang.mywust.exception.ApiException; +import cn.wustlinghang.mywust.exception.ParseException; +import jakarta.enterprise.context.ApplicationScoped; +import jakarta.validation.constraints.NotNull; +import jakarta.ws.rs.GET; +import jakarta.ws.rs.POST; +import jakarta.ws.rs.Path; +import jakarta.ws.rs.QueryParam; + +import java.io.IOException; + +@Path("/student_info") +@ApplicationScoped +public class StudentInfoApi { + private final UndergradStudentInfoApiService studentInfoApiService; + private final UndergradStudentInfoPageParser studentInfoPageParser; + + public StudentInfoApi(UndergradStudentInfoApiService studentInfoApiService, + UndergradStudentInfoPageParser studentInfoPageParser) { + this.studentInfoApiService = studentInfoApiService; + this.studentInfoPageParser = studentInfoPageParser; + } + + @GET + @Path("/") + public StudentInfo get(@QueryParam("cookie") @NotNull String cookie) throws IOException, ApiException, ParseException { + return this.parse(this.agent(cookie)); + } + + @GET + @Path("/agent") + public String agent(@QueryParam("cookie") @NotNull String cookie) + throws IOException, ApiException { + return studentInfoApiService.getPage(cookie); + } + + @POST + @Path("/parse") + public StudentInfo parse(String html) throws ParseException { + return studentInfoPageParser.parse(html); + } +} diff --git a/sub-services/undergrad/src/main/java/cn/wustlinghang/wusthelper/internal/undergrad/api/json/TrainingPlanApi.java b/sub-services/undergrad/src/main/java/cn/wustlinghang/wusthelper/internal/undergrad/api/json/TrainingPlanApi.java new file mode 100644 index 0000000..ed8af51 --- /dev/null +++ b/sub-services/undergrad/src/main/java/cn/wustlinghang/wusthelper/internal/undergrad/api/json/TrainingPlanApi.java @@ -0,0 +1,51 @@ +package cn.wustlinghang.wusthelper.internal.undergrad.api.json; + +import cn.wustlinghang.mywust.core.parser.undergraduate.UndergradStudentInfoPageParser; +import cn.wustlinghang.mywust.core.request.service.undergraduate.UndergradStudentInfoApiService; +import cn.wustlinghang.mywust.data.global.StudentInfo; +import cn.wustlinghang.mywust.exception.ApiException; +import cn.wustlinghang.mywust.exception.ParseException; +import cn.wustlinghang.wusthelper.rpc.response.RpcResponse; +import jakarta.enterprise.context.ApplicationScoped; +import jakarta.validation.constraints.NotNull; +import jakarta.ws.rs.GET; +import jakarta.ws.rs.POST; +import jakarta.ws.rs.Path; +import jakarta.ws.rs.QueryParam; + +import java.io.IOException; + +@Path("/training_plan") +@ApplicationScoped +public class TrainingPlanApi { + private final UndergradStudentInfoApiService studentInfoApiService; + private final UndergradStudentInfoPageParser studentInfoPageParser; + + public TrainingPlanApi(UndergradStudentInfoApiService studentInfoApiService, + UndergradStudentInfoPageParser studentInfoPageParser) { + this.studentInfoApiService = studentInfoApiService; + this.studentInfoPageParser = studentInfoPageParser; + } + + @GET + @Path("/") + public RpcResponse get(String cookie) throws IOException, ApiException, ParseException { + String html = studentInfoApiService.getPage(cookie); + return this.parse(html); + } + + @GET + @Path("/agent") + public RpcResponse agent(@QueryParam("cookie") @NotNull String cookie) + throws IOException, ApiException { + String html = studentInfoApiService.getPage(cookie); + return RpcResponse.success(html); + } + + @POST + @Path("/parse") + public RpcResponse parse(String html) throws ParseException { + StudentInfo result = studentInfoPageParser.parse(html); + return RpcResponse.success(result); + } +} diff --git a/sub-services/undergrad/src/main/java/cn/wustlinghang/wusthelper/internal/undergrad/api/json/handler/ApiExceptionHandler.java b/sub-services/undergrad/src/main/java/cn/wustlinghang/wusthelper/internal/undergrad/api/json/handler/ApiExceptionHandler.java new file mode 100644 index 0000000..e507e1b --- /dev/null +++ b/sub-services/undergrad/src/main/java/cn/wustlinghang/wusthelper/internal/undergrad/api/json/handler/ApiExceptionHandler.java @@ -0,0 +1,15 @@ +package cn.wustlinghang.wusthelper.internal.undergrad.api.json.handler; + +import cn.wustlinghang.mywust.exception.ApiException; +import cn.wustlinghang.wusthelper.rpc.response.ResponseCode; +import jakarta.ws.rs.core.Response; +import jakarta.ws.rs.ext.ExceptionMapper; +import jakarta.ws.rs.ext.Provider; + +@Provider +public class ApiExceptionHandler extends ExceptionHandlerBase implements ExceptionMapper { + @Override + public Response toResponse(ApiException e) { + return super.toResponse(e.getCodeValue(), e.toString(), "ApiExceptionHandler"); + } +} diff --git a/sub-services/undergrad/src/main/java/cn/wustlinghang/wusthelper/internal/undergrad/api/json/handler/DefaultExceptionHandler.java b/sub-services/undergrad/src/main/java/cn/wustlinghang/wusthelper/internal/undergrad/api/json/handler/DefaultExceptionHandler.java new file mode 100644 index 0000000..eb82227 --- /dev/null +++ b/sub-services/undergrad/src/main/java/cn/wustlinghang/wusthelper/internal/undergrad/api/json/handler/DefaultExceptionHandler.java @@ -0,0 +1,21 @@ +package cn.wustlinghang.wusthelper.internal.undergrad.api.json.handler; + +import cn.wustlinghang.wusthelper.rpc.response.ResponseCode; +import jakarta.ws.rs.core.Response; +import jakarta.ws.rs.ext.ExceptionMapper; +import jakarta.ws.rs.ext.Provider; +import lombok.extern.slf4j.Slf4j; + +@Slf4j +@Provider +public class DefaultExceptionHandler extends ExceptionHandlerBase implements ExceptionMapper { + @Override + public Response toResponse(Exception e) { + log.error("未知异常:", e); + return super.toResponse( + ResponseCode.SERVER_INTERNAL_ERROR, + e.toString(), + "DefaultExceptionHandler" + ); + } +} diff --git a/sub-services/undergrad/src/main/java/cn/wustlinghang/wusthelper/internal/undergrad/api/json/handler/ExceptionHandlerBase.java b/sub-services/undergrad/src/main/java/cn/wustlinghang/wusthelper/internal/undergrad/api/json/handler/ExceptionHandlerBase.java new file mode 100644 index 0000000..a875ca6 --- /dev/null +++ b/sub-services/undergrad/src/main/java/cn/wustlinghang/wusthelper/internal/undergrad/api/json/handler/ExceptionHandlerBase.java @@ -0,0 +1,33 @@ +package cn.wustlinghang.wusthelper.internal.undergrad.api.json.handler; + +import cn.wustlinghang.wusthelper.rpc.response.ResponseCode; +import cn.wustlinghang.wusthelper.rpc.response.RpcResponse; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import jakarta.ws.rs.core.MediaType; +import jakarta.ws.rs.core.Response; + +public abstract class ExceptionHandlerBase { + public static final String EXCEPTION_HEADER_KEY = "X-exception-handler"; + + private static final ObjectMapper objectMapper = new ObjectMapper(); + + public Response toResponse(ResponseCode code, String msg, String handlerName) { + return toResponse(code.getCode(), msg, handlerName); + } + + public Response toResponse(int code, String msg, String handlerName) { + Object response; + try { + response = objectMapper.writeValueAsString(RpcResponse.error(code, msg)); + } catch (JsonProcessingException e) { + response = RpcResponse.error(ResponseCode.SERVER_INTERNAL_ERROR); + } + + return Response.status(Response.Status.INTERNAL_SERVER_ERROR) + .entity(response) + .header(EXCEPTION_HEADER_KEY, handlerName) + .type(MediaType.APPLICATION_JSON) + .build(); + } +} diff --git a/sub-services/undergrad/src/main/java/cn/wustlinghang/wusthelper/internal/undergrad/api/json/handler/IOExceptionHandler.java b/sub-services/undergrad/src/main/java/cn/wustlinghang/wusthelper/internal/undergrad/api/json/handler/IOExceptionHandler.java new file mode 100644 index 0000000..e6c0815 --- /dev/null +++ b/sub-services/undergrad/src/main/java/cn/wustlinghang/wusthelper/internal/undergrad/api/json/handler/IOExceptionHandler.java @@ -0,0 +1,23 @@ +package cn.wustlinghang.wusthelper.internal.undergrad.api.json.handler; + +import cn.wustlinghang.wusthelper.rpc.response.ResponseCode; +import jakarta.ws.rs.core.Response; +import jakarta.ws.rs.ext.ExceptionMapper; +import jakarta.ws.rs.ext.Provider; +import lombok.extern.slf4j.Slf4j; + +import java.io.IOException; + +@Slf4j +@Provider +public class IOExceptionHandler extends ExceptionHandlerBase implements ExceptionMapper { + @Override + public Response toResponse(IOException e) { + log.error("IO异常:", e); + return super.toResponse( + ResponseCode.SERVER_INTERNAL_ERROR, + e.toString(), + "IOExceptionHandler" + ); + } +} diff --git a/sub-services/undergrad/src/main/java/cn/wustlinghang/wusthelper/internal/undergrad/api/json/handler/ParseExceptionHandler.java b/sub-services/undergrad/src/main/java/cn/wustlinghang/wusthelper/internal/undergrad/api/json/handler/ParseExceptionHandler.java new file mode 100644 index 0000000..66e77b1 --- /dev/null +++ b/sub-services/undergrad/src/main/java/cn/wustlinghang/wusthelper/internal/undergrad/api/json/handler/ParseExceptionHandler.java @@ -0,0 +1,22 @@ +package cn.wustlinghang.wusthelper.internal.undergrad.api.json.handler; + +import cn.wustlinghang.mywust.exception.ParseException; +import cn.wustlinghang.wusthelper.rpc.response.ResponseCode; +import jakarta.ws.rs.core.Response; +import jakarta.ws.rs.ext.ExceptionMapper; +import jakarta.ws.rs.ext.Provider; +import lombok.extern.slf4j.Slf4j; + +@Slf4j +@Provider +public class ParseExceptionHandler extends ExceptionHandlerBase implements ExceptionMapper { + @Override + public Response toResponse(ParseException e) { + log.error("解析异常:", e); + return super.toResponse( + ResponseCode.SERVER_INTERNAL_ERROR, + e.toString(), + "ParseExceptionHandler" + ); + } +} diff --git a/sub-services/undergrad/src/main/java/cn/wustlinghang/wusthelper/internal/undergrad/api/json/handler/ValidationExceptionHandler.java b/sub-services/undergrad/src/main/java/cn/wustlinghang/wusthelper/internal/undergrad/api/json/handler/ValidationExceptionHandler.java new file mode 100644 index 0000000..1b32d69 --- /dev/null +++ b/sub-services/undergrad/src/main/java/cn/wustlinghang/wusthelper/internal/undergrad/api/json/handler/ValidationExceptionHandler.java @@ -0,0 +1,23 @@ +package cn.wustlinghang.wusthelper.internal.undergrad.api.json.handler; + +import cn.wustlinghang.wusthelper.rpc.response.ResponseCode; +import jakarta.validation.ConstraintViolationException; +import jakarta.validation.ValidationException; +import jakarta.ws.rs.core.Response; +import jakarta.ws.rs.ext.ExceptionMapper; +import jakarta.ws.rs.ext.Provider; +import lombok.extern.slf4j.Slf4j; + +@Slf4j +@Provider +public class ValidationExceptionHandler extends ExceptionHandlerBase + implements ExceptionMapper { + @Override + public Response toResponse(ValidationException e) { + return super.toResponse( + ResponseCode.PARAM_WRONG, + "参数错误:" + e.toString(), + "ValidationExceptionHandler" + ); + } +} diff --git a/sub-services/undergrad/src/main/java/cn/wustlinghang/wusthelper/internal/undergrad/api/json/interceptor/ResponseWrapperInterceptor.java b/sub-services/undergrad/src/main/java/cn/wustlinghang/wusthelper/internal/undergrad/api/json/interceptor/ResponseWrapperInterceptor.java new file mode 100644 index 0000000..a162242 --- /dev/null +++ b/sub-services/undergrad/src/main/java/cn/wustlinghang/wusthelper/internal/undergrad/api/json/interceptor/ResponseWrapperInterceptor.java @@ -0,0 +1,36 @@ +package cn.wustlinghang.wusthelper.internal.undergrad.api.json.interceptor; + +import cn.wustlinghang.wusthelper.internal.undergrad.api.json.handler.ExceptionHandlerBase; +import cn.wustlinghang.wusthelper.rpc.response.RpcResponse; +import com.fasterxml.jackson.databind.ObjectMapper; +import jakarta.ws.rs.WebApplicationException; +import jakarta.ws.rs.core.HttpHeaders; +import jakarta.ws.rs.core.MediaType; +import jakarta.ws.rs.ext.Provider; +import jakarta.ws.rs.ext.WriterInterceptor; +import jakarta.ws.rs.ext.WriterInterceptorContext; + +import java.io.IOException; + +@Provider +public class ResponseWrapperInterceptor implements WriterInterceptor { + private final ObjectMapper objectMapper; + + public ResponseWrapperInterceptor(ObjectMapper objectMapper) { + this.objectMapper = objectMapper; + } + + @Override + public void aroundWriteTo(WriterInterceptorContext context) throws IOException, WebApplicationException { + boolean hasException = context.getHeaders().get(ExceptionHandlerBase.EXCEPTION_HEADER_KEY) != null; + if (!hasException) { + Object data = context.getEntity(); + RpcResponse wrappedResponse = RpcResponse.success(data); + String json = objectMapper.writeValueAsString(wrappedResponse); + context.getHeaders().putSingle(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON); + context.setEntity(json); + } + + context.proceed(); + } +} diff --git a/sub-services/undergrad/src/main/java/cn/wustlinghang/wusthelper/internal/undergrad/bean/JacksonBean.java b/sub-services/undergrad/src/main/java/cn/wustlinghang/wusthelper/internal/undergrad/bean/JacksonBean.java new file mode 100644 index 0000000..c95e91d --- /dev/null +++ b/sub-services/undergrad/src/main/java/cn/wustlinghang/wusthelper/internal/undergrad/bean/JacksonBean.java @@ -0,0 +1,12 @@ +package cn.wustlinghang.wusthelper.internal.undergrad.bean; + +import com.fasterxml.jackson.databind.ObjectMapper; +import jakarta.enterprise.context.ApplicationScoped; +import jakarta.inject.Singleton; + +public class JacksonBean { + @ApplicationScoped + public ObjectMapper objectMapper() { + return new ObjectMapper(); + } +} diff --git a/sub-services/undergrad/src/main/java/cn/wustlinghang/wusthelper/internal/undergrad/bean/MywustParserBeans.java b/sub-services/undergrad/src/main/java/cn/wustlinghang/wusthelper/internal/undergrad/bean/MywustParserBeans.java new file mode 100644 index 0000000..a9fbc00 --- /dev/null +++ b/sub-services/undergrad/src/main/java/cn/wustlinghang/wusthelper/internal/undergrad/bean/MywustParserBeans.java @@ -0,0 +1,36 @@ +package cn.wustlinghang.wusthelper.internal.undergrad.bean; + +import cn.wustlinghang.mywust.core.parser.undergraduate.*; +import jakarta.enterprise.context.ApplicationScoped; + +public class MywustParserBeans { + @ApplicationScoped + public UndergradCourseTableParser undergradCourseTableParser() { + return new UndergradCourseTableParser(); + } + + @ApplicationScoped + public UndergradScoreParser undergradScoreParser() { + return new UndergradScoreParser(); + } + + @ApplicationScoped + public UndergradStudentInfoPageParser undergradStudentInfoPageParser() { + return new UndergradStudentInfoPageParser(); + } + + @ApplicationScoped + public UndergradTrainingPlanPageParser undergradTrainingPlanPageParser() { + return new UndergradTrainingPlanPageParser(); + } + + @ApplicationScoped + public UndergradCreditStatusParser undergradCreditStatusParser() { + return new UndergradCreditStatusParser(); + } + + @ApplicationScoped + public UndergradExamDelayParser undergradExamDelayParser() { + return new UndergradExamDelayParser(); + } +} diff --git a/sub-services/undergrad/src/main/java/cn/wustlinghang/wusthelper/internal/undergrad/bean/MywustRequestAgentBeans.java b/sub-services/undergrad/src/main/java/cn/wustlinghang/wusthelper/internal/undergrad/bean/MywustRequestAgentBeans.java new file mode 100644 index 0000000..b959e45 --- /dev/null +++ b/sub-services/undergrad/src/main/java/cn/wustlinghang/wusthelper/internal/undergrad/bean/MywustRequestAgentBeans.java @@ -0,0 +1,63 @@ +package cn.wustlinghang.wusthelper.internal.undergrad.bean; + +import cn.wustlinghang.mywust.core.request.service.auth.UndergraduateLogin; +import cn.wustlinghang.mywust.core.request.service.undergraduate.*; +import cn.wustlinghang.mywust.network.RequestClientOption; +import cn.wustlinghang.mywust.network.Requester; +import cn.wustlinghang.mywust.network.okhttp.SimpleOkhttpRequester; +import jakarta.inject.Singleton; + +public class MywustRequestAgentBeans { + + @Singleton + public RequestClientOption requestClientOption() { + RequestClientOption.Proxy proxy = RequestClientOption.Proxy.builder() + .address("127.0.0.1") + .port(8080) + .build(); + RequestClientOption option = new RequestClientOption(); +// option.setProxy(proxy); + + return option; + } + + @Singleton + public Requester requester(RequestClientOption option) { + return new SimpleOkhttpRequester(option, true); + } + + @Singleton + public UndergraduateLogin undergraduateLogin(Requester requester) { + return new UndergraduateLogin(requester); + } + + @Singleton + public UndergradCourseTableApiService undergradCourseTableApiService(Requester requester) { + return new UndergradCourseTableApiService(requester); + } + + @Singleton + public UndergradScoreApiService undergradScoreApiService(Requester requester) { + return new UndergradScoreApiService(requester); + } + + @Singleton + public UndergradStudentInfoApiService undergradStudentInfoApiService(Requester requester) { + return new UndergradStudentInfoApiService(requester); + } + + @Singleton + public UndergradTrainingPlanApiService undergradTrainingPlanApiService(Requester requester) { + return new UndergradTrainingPlanApiService(requester); + } + + @Singleton + public UndergradCreditStatusApiService undergradCreditStatusApiService(Requester requester) { + return new UndergradCreditStatusApiService(requester); + } + + @Singleton + public UndergradExamDelayApiService undergradExamDelayApiService(Requester requester) { + return new UndergradExamDelayApiService(requester); + } +} \ No newline at end of file diff --git a/sub-services/undergrad/src/main/java/cn/wustlinghang/wusthelper/internal/undergrad/exception/InternalException.java b/sub-services/undergrad/src/main/java/cn/wustlinghang/wusthelper/internal/undergrad/exception/InternalException.java new file mode 100644 index 0000000..172bb9c --- /dev/null +++ b/sub-services/undergrad/src/main/java/cn/wustlinghang/wusthelper/internal/undergrad/exception/InternalException.java @@ -0,0 +1,4 @@ +package cn.wustlinghang.wusthelper.internal.undergrad.exception; + +public class InternalException extends Exception { +} diff --git a/sub-services/undergrad/src/main/java/cn/wustlinghang/wusthelper/internal/undergrad/services/LoginService.java b/sub-services/undergrad/src/main/java/cn/wustlinghang/wusthelper/internal/undergrad/services/LoginService.java new file mode 100644 index 0000000..28c3348 --- /dev/null +++ b/sub-services/undergrad/src/main/java/cn/wustlinghang/wusthelper/internal/undergrad/services/LoginService.java @@ -0,0 +1,32 @@ +package cn.wustlinghang.wusthelper.internal.undergrad.services; + +import cn.wustlinghang.mywust.core.request.service.auth.UndergraduateLogin; +import cn.wustlinghang.mywust.exception.ApiException; +import cn.wustlinghang.mywust.network.RequestClientOption; +import jakarta.enterprise.context.ApplicationScoped; + +import java.io.IOException; + +@ApplicationScoped +public class LoginService { + private final RequestClientOption option; + private final UndergraduateLogin undergraduateLogin; + + public LoginService(RequestClientOption option, + UndergraduateLogin undergraduateLogin) { + this.option = option; + this.undergraduateLogin = undergraduateLogin; + } + + public String login(String username, String password, boolean legacy) throws IOException, ApiException { + if (legacy) { + return undergraduateLogin.getLoginCookieLegacy(username, password, option); + } else { + return undergraduateLogin.getLoginCookie(username, password, option); + } + } + + public boolean verify(String cookie) throws IOException { + return !undergraduateLogin.checkCookiesFail(cookie); + } +} diff --git a/sub-services/undergrad/src/main/java/cn/wustlinghang/wusthelper/internal/undergrad/services/ParseService.java b/sub-services/undergrad/src/main/java/cn/wustlinghang/wusthelper/internal/undergrad/services/ParseService.java new file mode 100644 index 0000000..f90f531 --- /dev/null +++ b/sub-services/undergrad/src/main/java/cn/wustlinghang/wusthelper/internal/undergrad/services/ParseService.java @@ -0,0 +1,60 @@ +package cn.wustlinghang.wusthelper.internal.undergrad.services; + +import cn.wustlinghang.mywust.core.parser.undergraduate.*; +import cn.wustlinghang.mywust.data.global.Course; +import cn.wustlinghang.mywust.data.global.Score; +import cn.wustlinghang.mywust.data.global.StudentInfo; +import cn.wustlinghang.mywust.data.undergrad.ExamDelayApplication; +import cn.wustlinghang.mywust.exception.ParseException; +import jakarta.enterprise.context.ApplicationScoped; + +import java.util.List; + +@ApplicationScoped +public class ParseService { + private final UndergradCourseTableParser courseTableParser; + private final UndergradScoreParser scoreParser; + private final UndergradStudentInfoPageParser studentInfoPageParser; + private final UndergradTrainingPlanPageParser trainingPlanPageParser; + private final UndergradCreditStatusParser creditStatusParser; + private final UndergradExamDelayParser examDelayParser; + + public ParseService(UndergradCourseTableParser courseTableParser, + UndergradScoreParser scoreParser, + UndergradStudentInfoPageParser studentInfoPageParser, + UndergradTrainingPlanPageParser trainingPlanPageParser, + UndergradCreditStatusParser creditStatusParser, + UndergradExamDelayParser examDelayParser) { + + this.courseTableParser = courseTableParser; + this.scoreParser = scoreParser; + this.studentInfoPageParser = studentInfoPageParser; + this.trainingPlanPageParser = trainingPlanPageParser; + this.creditStatusParser = creditStatusParser; + this.examDelayParser = examDelayParser; + } + + public List parseCourseTable(String data) throws ParseException { + return courseTableParser.parse(data); + } + + public List parseScore(String data) throws ParseException { + return scoreParser.parse(data); + } + + public StudentInfo parseStudentInfo(String data) throws ParseException { + return studentInfoPageParser.parse(data); + } + + public String parseTrainingPlan(String data) throws ParseException { + return trainingPlanPageParser.parse(data); + } + + public String parseCreditStatus(String data) throws ParseException { + return creditStatusParser.parse(data); + } + + public List parseExamDelayApplications(String data) throws ParseException { + return examDelayParser.parse(data); + } +} diff --git a/sub-services/undergrad/src/main/java/cn/wustlinghang/wusthelper/internal/undergrad/services/RequestAgentService.java b/sub-services/undergrad/src/main/java/cn/wustlinghang/wusthelper/internal/undergrad/services/RequestAgentService.java new file mode 100644 index 0000000..58a62bf --- /dev/null +++ b/sub-services/undergrad/src/main/java/cn/wustlinghang/wusthelper/internal/undergrad/services/RequestAgentService.java @@ -0,0 +1,62 @@ +package cn.wustlinghang.wusthelper.internal.undergrad.services; + +import cn.wustlinghang.mywust.core.request.service.undergraduate.*; +import cn.wustlinghang.mywust.exception.ApiException; +import jakarta.enterprise.context.ApplicationScoped; + +import java.io.IOException; + +@ApplicationScoped +public class RequestAgentService { + private final UndergradCourseTableApiService courseTableApiService; + private final UndergradScoreApiService scoreApiService; + private final UndergradStudentInfoApiService studentInfoApiService; + private final UndergradTrainingPlanApiService trainingPlanApiService; + private final UndergradCreditStatusApiService creditStatusApiService; + private final UndergradExamDelayApiService examDelayApiService; + + public RequestAgentService(UndergradCourseTableApiService courseTableApiService, + UndergradScoreApiService scoreApiService, + UndergradStudentInfoApiService studentInfoApiService, + UndergradTrainingPlanApiService trainingPlanApiService, + UndergradCreditStatusApiService creditStatusApiService, + UndergradExamDelayApiService examDelayApiService) { + + this.courseTableApiService = courseTableApiService; + this.scoreApiService = scoreApiService; + this.studentInfoApiService = studentInfoApiService; + this.trainingPlanApiService = trainingPlanApiService; + this.creditStatusApiService = creditStatusApiService; + this.examDelayApiService = examDelayApiService; + } + + public String getStudentInfoPage(String cookie) throws IOException, ApiException { + return studentInfoApiService.getPage(cookie); + } + + public String getCourseTable(String cookie, String term) throws IOException, ApiException { + return courseTableApiService.getPage(term, cookie); + } + + public String getScore(String cookie) throws IOException, ApiException { + return scoreApiService.getPage(cookie); + } + + public String getTrainingPlan(String cookie) throws IOException, ApiException { + return trainingPlanApiService.getPage(cookie); + } + + public String getCreditStatus(String cookie) throws IOException, ApiException { + return creditStatusApiService.getPage(cookie, null, false); + } + + public UndergradExamDelayApiService.ExamActivity[] getExamActivities(String cookie, String term) + throws IOException, ApiException { + return examDelayApiService.getActivities(term, cookie); + } + + public String getExamDelayApplications(String cookie, String term, String activityId) + throws IOException, ApiException { + return examDelayApiService.getPage(term, activityId, cookie); + } +} diff --git a/sub-services/undergrad/src/main/resources/META-INF/resources/index.html b/sub-services/undergrad/src/main/resources/META-INF/resources/index.html new file mode 100644 index 0000000..2f1551a --- /dev/null +++ b/sub-services/undergrad/src/main/resources/META-INF/resources/index.html @@ -0,0 +1,152 @@ + + + + + getting-started - 1.0.0-SNAPSHOT + + + + + + +
+
+

Congratulations, you have created a new Quarkus application.

+ +

Why do you see this?

+ +

This page is served by Quarkus. The source is in + src/main/resources/META-INF/resources/index.html.

+ +

What can I do from here?

+ +

If not already done, run the application in dev mode using: mvn quarkus:dev. +

+
    +
  • Add REST resources, Servlets, functions and other services in src/main/java.
  • +
  • Your static assets are located in src/main/resources/META-INF/resources.
  • +
  • Configure your application in src/main/resources/application.properties. +
  • +
+ +

How do I get rid of this page?

+

Just delete the src/main/resources/META-INF/resources/index.html file.

+
+
+
+

Application

+
    +
  • GroupId: org.acme
  • +
  • ArtifactId: getting-started
  • +
  • Version: 1.0.0-SNAPSHOT
  • +
  • Quarkus Version: 0.11.0
  • +
+
+ +
+
+ + + + diff --git a/sub-services/undergrad/src/main/resources/application.properties b/sub-services/undergrad/src/main/resources/application.properties new file mode 100644 index 0000000..2c29c49 --- /dev/null +++ b/sub-services/undergrad/src/main/resources/application.properties @@ -0,0 +1,5 @@ +# Quarkus Configuration file +# key = value +quarkus.http.port=22800 +#quarkus.log.level=DEBUG +quarkus.log.file.encoding=UTF-8