Skip to content

Commit d64c6b2

Browse files
committed
feat: implement querying group-id
1 parent 4ff287b commit d64c6b2

3 files changed

Lines changed: 145 additions & 4 deletions

File tree

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* Copyright (c) Huawei Technologies Co., Ltd. 2026-2026. All rights reserved.
3+
*/
4+
5+
package com.datamate.gateway.infrastructure.client.dto;
6+
7+
import lombok.Getter;
8+
9+
import java.time.LocalDateTime;
10+
11+
/**
12+
* 资源组信息
13+
*/
14+
@Getter
15+
public class ResourceGroup {
16+
private String id;
17+
18+
private String parentId;
19+
20+
private String name;
21+
22+
private String description;
23+
24+
private LocalDateTime createTime;
25+
26+
private LocalDateTime updateTime;
27+
28+
private boolean isDeleted;
29+
30+
private boolean isBuiltin;
31+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* Copyright (c) Huawei Technologies Co., Ltd. 2026-2026. All rights reserved.
3+
*/
4+
5+
package com.datamate.gateway.infrastructure.client.dto;
6+
7+
import lombok.Getter;
8+
9+
/**
10+
* oms-extension统一返回包装类
11+
*
12+
* @param code 状态码
13+
* @param msg 消息
14+
* @param data 数据
15+
* @param <T> 数据类
16+
*/
17+
public record Resp<T>(String code, String msg, T data) {
18+
public static final String SUCCESS = "0";
19+
20+
/**
21+
* 成功
22+
* @param data 数据
23+
* @return 响应体
24+
* @param <T> 数据类型
25+
*/
26+
public static <T> Resp<T> ok(T data) {
27+
return new Resp<>(SUCCESS, "success", data);
28+
}
29+
30+
/**
31+
* 成功
32+
*
33+
* @return 响应体
34+
* @param <T> 数据类型
35+
*/
36+
public static <T> Resp<T> ok() {
37+
return Resp.ok(null);
38+
}
39+
40+
/**
41+
* 失败返回
42+
*
43+
* @param code 状态码
44+
* @param message 错误信息
45+
* @return 响应体
46+
* @param <T> 数据类型
47+
*/
48+
public static <T> Resp<T> error(String code, String message) {
49+
return new Resp<>(code, message, null);
50+
}
51+
}
Lines changed: 63 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,77 @@
11
package com.datamate.gateway.infrastructure.client.impl;
22

3+
import com.datamate.gateway.common.config.SslIgnoreHttpClientFactory;
34
import com.datamate.gateway.infrastructure.client.OmsExtensionService;
5+
import com.datamate.gateway.infrastructure.client.dto.ResourceGroup;
6+
import com.datamate.gateway.infrastructure.client.dto.Resp;
7+
import com.fasterxml.jackson.databind.ObjectMapper;
8+
9+
import lombok.extern.slf4j.Slf4j;
10+
11+
import org.apache.hc.client5.http.classic.methods.HttpGet;
12+
import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
13+
import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse;
14+
import org.apache.hc.core5.http.ParseException;
15+
import org.apache.hc.core5.http.io.entity.EntityUtils;
16+
import org.springframework.beans.factory.annotation.Value;
417
import org.springframework.stereotype.Service;
518

19+
import java.io.IOException;
20+
import java.util.List;
21+
622
/**
723
* OmsExtensionServiceImpl is an implementation of OmsExtensionService.
8-
*
9-
* @author songyongtan
10-
* @date 2026-03-17
24+
*
25+
* @author MoeexT
26+
* @since 2026-03-17
1127
*/
28+
@Slf4j
1229
@Service
1330
public class OmsExtensionServiceImpl implements OmsExtensionService {
31+
@Value("${OMS_EXTENSION_URL:https://oms-extension:8021}")
32+
private final String omsExtensionUrl;
33+
34+
private final ObjectMapper objectMapper;
35+
36+
private CloseableHttpClient httpClient;
37+
38+
public OmsExtensionServiceImpl(@Value("${oms.service.url}") String omsExtensionUrl, ObjectMapper objectMapper,
39+
SslIgnoreHttpClientFactory sslIgnoreHttpClientFactory) {
40+
this.omsExtensionUrl = omsExtensionUrl;
41+
this.objectMapper = objectMapper;
42+
try {
43+
this.httpClient = sslIgnoreHttpClientFactory.getHttpClient();
44+
} catch (Exception e) {
45+
log.error("Failed to create SSL ignore HTTP client", e);
46+
}
47+
}
48+
49+
/**
50+
* Get the group ID of the user's user group
51+
*
52+
* @param userName the username
53+
* @return resource-group-id of this user
54+
*/
1455
@Override
1556
public String getUserGroupId(String userName) {
16-
return userName;
57+
try {
58+
String fullPath = this.omsExtensionUrl + "/ui/v1/resource-groups/user/" + userName + "/resource-group";
59+
HttpGet httpGet = new HttpGet(fullPath);
60+
CloseableHttpResponse response = httpClient.execute(httpGet);
61+
String responseBody = EntityUtils.toString(response.getEntity());
62+
log.info("response code: {}, response body: {}", response.getCode(), responseBody);
63+
64+
Resp<List<ResourceGroup>> resp = objectMapper.readValue(responseBody,
65+
objectMapper.getTypeFactory().constructParametricType(Resp.class, List.class, ResourceGroup.class));
66+
67+
if (resp.data() == null || resp.data().isEmpty()) {
68+
return null;
69+
}
70+
71+
return resp.data().getFirst().getId();
72+
} catch (IOException | ParseException e) {
73+
log.error("Failed to get user name from OMS service", e);
74+
return null;
75+
}
1776
}
1877
}

0 commit comments

Comments
 (0)