Skip to content

Commit

Permalink
adjust the gateway code to align the reconstruct in Java sdk.
Browse files Browse the repository at this point in the history
  • Loading branch information
ren2003u committed Oct 30, 2023
1 parent a3ca7aa commit 66f0282
Show file tree
Hide file tree
Showing 5 changed files with 179 additions and 7 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
<dependency>
<groupId>io.github.ren2003u</groupId>
<artifactId>platform-sdk-java</artifactId>
<version>1.0.4</version>
<version>1.0.5</version>
</dependency>
<!-- <dependency>-->
<!-- <groupId>io.github.ren2003u</groupId>-->
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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<RegisterUserResponse> response = client.registerUser(properties.boxUuid(), userRegistryInfo.userId(), userRegistryInfo.subdomain(), userRegistryInfo.userType(), userRegistryInfo.clientUUID(), requestId, boxRegKey);
ApiResponse<RegisterUserResponse> response = client.registerUser(jsonRequest, requestId, boxRegKey);
if (response.getError() != null) {
LOG.error("Error registering user: {}", response.getError().getMessage());
return null;
Expand All @@ -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<RegisterClientResponse> response = client.registerClient(properties.boxUuid(), userId, clientRegistryInfo.clientUUID(), clientRegistryInfo.clientType(), requestId, boxRegKey);
ApiResponse<RegisterClientResponse> response = client.registerClient(properties.boxUuid(), userId, jsonRequest, requestId, boxRegKey);
if (response.getError() != null) {
LOG.error("Error registering client: {}", response.getError().getMessage());
return null;
Expand All @@ -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<ObtainBoxRegKeyResponse> 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<ObtainBoxRegKeyResponse> response = client.obtainBoxRegKey(properties.boxUuid(), List.of("10001"), requestId,sign);
ApiResponse<ObtainBoxRegKeyResponse> response = client.obtainBoxRegKey(jsonRequest, requestId);
if (response.getError() != null) {
LOG.error("Error obtaining BoxRegKey: {}", response.getError().getMessage());
return null;
Expand Down
Original file line number Diff line number Diff line change
@@ -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<String> 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<String> getServiceIds() {
return this.serviceIds;
}

public void setServiceIds(List<String> 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;
}
}

Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -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;
}

}

0 comments on commit 66f0282

Please sign in to comment.