From 66f02828f117804bd674070116d4ac9e7be6536d Mon Sep 17 00:00:00 2001 From: jiahao ren Date: Mon, 30 Oct 2023 20:15:07 +0800 Subject: [PATCH] adjust the gateway code to align the reconstruct in Java sdk. --- pom.xml | 2 +- .../support/platform/PlatformClient.java | 39 ++++++++++-- .../model/ObtainBoxRegKeyRequest.java | 51 +++++++++++++++ .../platform/model/RegisterClientRequest.java | 32 ++++++++++ .../platform/model/RegisterUserRequest.java | 62 +++++++++++++++++++ 5 files changed, 179 insertions(+), 7 deletions(-) create mode 100644 src/main/java/space/ao/services/support/platform/model/ObtainBoxRegKeyRequest.java create mode 100644 src/main/java/space/ao/services/support/platform/model/RegisterClientRequest.java create mode 100644 src/main/java/space/ao/services/support/platform/model/RegisterUserRequest.java diff --git a/pom.xml b/pom.xml index 0870a3d..2d74814 100644 --- a/pom.xml +++ b/pom.xml @@ -47,7 +47,7 @@ io.github.ren2003u platform-sdk-java - 1.0.4 + 1.0.5 diff --git a/src/main/java/space/ao/services/support/platform/PlatformClient.java b/src/main/java/space/ao/services/support/platform/PlatformClient.java index 3661a48..835d5bd 100644 --- a/src/main/java/space/ao/services/support/platform/PlatformClient.java +++ b/src/main/java/space/ao/services/support/platform/PlatformClient.java @@ -1,6 +1,7 @@ package space.ao.services.support.platform; //import io.github.ren2003u.authentication.model.ObtainBoxRegKeyResponse; +import com.fasterxml.jackson.databind.ObjectMapper; import io.github.ren2003u.client.Client; import io.github.ren2003u.domain.errorHandle.ApiResponse; //import io.github.ren2003u.register.model.RegisterClientResponse; @@ -17,9 +18,7 @@ import space.ao.services.support.platform.info.registry.UserRegistryInfo; import space.ao.services.support.platform.info.registry.UserRegistryResult; import space.ao.services.support.platform.info.token.TokenVerifySignInfo; -import space.ao.services.support.platform.model.ObtainBoxRegKeyResponse; -import space.ao.services.support.platform.model.RegisterClientResponse; -import space.ao.services.support.platform.model.RegisterUserResponse; +import space.ao.services.support.platform.model.*; import space.ao.services.support.security.SecurityUtils; import java.nio.charset.StandardCharsets; @@ -71,8 +70,19 @@ public UserRegistryResult registerUser(String requestId, UserRegistryInfo userRe return null; } + // Prepare RegisterUserRequest object + RegisterUserRequest request = new RegisterUserRequest(); + request.setBoxUUID(properties.boxUuid()); + request.setUserId(userRegistryInfo.userId()); + request.setSubdomain(userRegistryInfo.subdomain()); + request.setUserType(userRegistryInfo.userType()); + request.setClientUUID(userRegistryInfo.clientUUID()); + + // Convert RegisterUserRequest object to JSON + String jsonRequest = new ObjectMapper().writeValueAsString(request); + // Register User - ApiResponse response = client.registerUser(properties.boxUuid(), userRegistryInfo.userId(), userRegistryInfo.subdomain(), userRegistryInfo.userType(), userRegistryInfo.clientUUID(), requestId, boxRegKey); + ApiResponse response = client.registerUser(jsonRequest, requestId, boxRegKey); if (response.getError() != null) { LOG.error("Error registering user: {}", response.getError().getMessage()); return null; @@ -93,8 +103,16 @@ public ClientRegistryResult registerClient(String requestId, ClientRegistryInfo return null; } + // Prepare RegisterClientRequest object + RegisterClientRequest request = new RegisterClientRequest(); + request.setClientUUID(clientRegistryInfo.clientUUID()); + request.setClientType(clientRegistryInfo.clientType()); + + // Convert RegisterClientRequest object to JSON + String jsonRequest = new ObjectMapper().writeValueAsString(request); + // Register Client - ApiResponse response = client.registerClient(properties.boxUuid(), userId, clientRegistryInfo.clientUUID(), clientRegistryInfo.clientType(), requestId, boxRegKey); + ApiResponse response = client.registerClient(properties.boxUuid(), userId, jsonRequest, requestId, boxRegKey); if (response.getError() != null) { LOG.error("Error registering client: {}", response.getError().getMessage()); return null; @@ -117,7 +135,16 @@ private String obtainBoxRegKey(String requestId) { Base64.getEncoder().encodeToString( utils.objectToJson(TokenVerifySignInfo.of(properties.boxUuid(), List.of("10001"))) .getBytes(StandardCharsets.UTF_8))); - ApiResponse response = client.obtainBoxRegKey(properties.boxUuid(), List.of("10001"), requestId,sign); + + ObtainBoxRegKeyRequest request = new ObtainBoxRegKeyRequest(); + request.setBoxUUID(properties.boxUuid()); + request.setServiceIds(List.of("10001")); + request.setSign(sign); + + String jsonRequest = new ObjectMapper().writeValueAsString(request); + + //ApiResponse response = client.obtainBoxRegKey(properties.boxUuid(), List.of("10001"), requestId,sign); + ApiResponse response = client.obtainBoxRegKey(jsonRequest, requestId); if (response.getError() != null) { LOG.error("Error obtaining BoxRegKey: {}", response.getError().getMessage()); return null; diff --git a/src/main/java/space/ao/services/support/platform/model/ObtainBoxRegKeyRequest.java b/src/main/java/space/ao/services/support/platform/model/ObtainBoxRegKeyRequest.java new file mode 100644 index 0000000..268c5f6 --- /dev/null +++ b/src/main/java/space/ao/services/support/platform/model/ObtainBoxRegKeyRequest.java @@ -0,0 +1,51 @@ +package space.ao.services.support.platform.model; + +import io.quarkus.runtime.annotations.RegisterForReflection; + +import java.util.List; +@RegisterForReflection +public class ObtainBoxRegKeyRequest { + + // Field for Box UUID + private String boxUUID; + + // Field for Service IDs + private List serviceIds; + + // Field for Sign + private String sign; + + + public String getBoxUUID() { + return this.boxUUID; + } + + public void setBoxUUID(String boxUUID) { + if (boxUUID == null || boxUUID.trim().isEmpty()) { + throw new IllegalArgumentException("Box UUID cannot be null or empty."); + } + this.boxUUID = boxUUID; + + } + + public List getServiceIds() { + return this.serviceIds; + } + + public void setServiceIds(List serviceIds) { + if (serviceIds == null || serviceIds.isEmpty()) { + throw new IllegalArgumentException("Service IDs cannot be null or empty."); + } + this.serviceIds = serviceIds; + + } + + public String getSign() { + return this.sign; + } + + public void setSign(String sign) { + this.sign = sign; + } +} + diff --git a/src/main/java/space/ao/services/support/platform/model/RegisterClientRequest.java b/src/main/java/space/ao/services/support/platform/model/RegisterClientRequest.java new file mode 100644 index 0000000..b3fe874 --- /dev/null +++ b/src/main/java/space/ao/services/support/platform/model/RegisterClientRequest.java @@ -0,0 +1,32 @@ +package space.ao.services.support.platform.model; + +import io.quarkus.runtime.annotations.RegisterForReflection; + +@RegisterForReflection +public class RegisterClientRequest { + + private String clientUUID; + private String clientType; + + public String getClientUUID() { + return this.clientUUID; + } + + public void setClientUUID(String clientUUID) { + if (clientUUID == null || clientUUID.trim().isEmpty()) { + throw new IllegalArgumentException("Client UUID cannot be null or empty."); + } + this.clientUUID = clientUUID; + } + + public String getClientType() { + return this.clientType; + } + + public void setClientType(String clientType) { + if (clientType == null || clientType.trim().isEmpty()) { + throw new IllegalArgumentException("Client Type cannot be null or empty."); + } + this.clientType = clientType; + } +} diff --git a/src/main/java/space/ao/services/support/platform/model/RegisterUserRequest.java b/src/main/java/space/ao/services/support/platform/model/RegisterUserRequest.java new file mode 100644 index 0000000..60fd354 --- /dev/null +++ b/src/main/java/space/ao/services/support/platform/model/RegisterUserRequest.java @@ -0,0 +1,62 @@ +package space.ao.services.support.platform.model; + +import io.quarkus.runtime.annotations.RegisterForReflection; + +@RegisterForReflection +public class RegisterUserRequest { + private String boxUUID; + private String userId; + private String subdomain; + private String userType; + private String clientUUID; + + + public String getBoxUUID() { + return this.boxUUID; + } + + public void setBoxUUID(String boxUUID) { + if (boxUUID == null || boxUUID.trim().isEmpty()) { + throw new IllegalArgumentException("Box UUID cannot be null or empty."); + } + this.boxUUID = boxUUID; + + } + + public String getUserId() { + return this.userId; + } + + public void setUserId(String userId) { + if (userId == null || userId.trim().isEmpty()) { + throw new IllegalArgumentException("User ID cannot be null or empty."); + } + this.userId = userId; + + } + + public String getSubdomain() { + return this.subdomain; + } + + public void setSubdomain(String subdomain) { + this.subdomain = subdomain; + } + + public String getUserType() { + return this.userType; + } + + public void setUserType(String userType) { + this.userType = userType; + } + + public String getClientUUID() { + return this.clientUUID; + } + + public void setClientUUID(String clientUUID) { + this.clientUUID = clientUUID; + } + +}