Skip to content

Commit

Permalink
[Feature-416][Notification] notification add test send button (#421)
Browse files Browse the repository at this point in the history
  • Loading branch information
xxzuo authored Jul 26, 2024
1 parent a50f720 commit a44e08b
Show file tree
Hide file tree
Showing 9 changed files with 80 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public SlaNotificationResultRecord sendCardMsg(Set<ReceiverConfig> receiverSet,
private String generateMsgJson(String title, String content,ReceiverConfig receiverConfig) {

final String atMobiles = receiverConfig.getAtMobiles();
final String atUserIds = receiverConfig.getAtUserIds();
final String atDingtalkIds = receiverConfig.getAtDingtalkIds();
final Boolean isAtAll = receiverConfig.getIsAtAll();

if (org.apache.commons.lang3.StringUtils.isBlank(msgType)) {
Expand All @@ -133,8 +133,8 @@ private String generateMsgJson(String title, String content,ReceiverConfig recei
builder.append(" ");
});
}
if (org.apache.commons.lang3.StringUtils.isNotBlank(atUserIds)) {
Arrays.stream(atUserIds.split(",")).forEach(value -> {
if (org.apache.commons.lang3.StringUtils.isNotBlank(atDingtalkIds)) {
Arrays.stream(atDingtalkIds.split(",")).forEach(value -> {
builder.append("@");
builder.append(value);
builder.append(" ");
Expand Down Expand Up @@ -163,10 +163,10 @@ private String generateMsgJson(String title, String content,ReceiverConfig recei
org.apache.commons.lang3.StringUtils.isNotBlank(atMobiles) ? atMobiles.split(",")
: new String[0];
String[] atUserArray =
org.apache.commons.lang3.StringUtils.isNotBlank(atUserIds) ? atUserIds.split(",")
org.apache.commons.lang3.StringUtils.isNotBlank(atDingtalkIds) ? atDingtalkIds.split(",")
: new String[0];
at.put("atMobiles", atMobileArray);
at.put("atUserIds", atUserArray);
at.put("atDingtalkIds", atUserArray);
at.put("isAtAll", isAtAll);

items.put("at", at);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,10 @@ public String getConfigJson() {
List<PluginParams> paramsList = new ArrayList<>();

InputParam atMobiles = InputParam.newBuilder("atMobiles", "atMobiles")
.addValidate(Validate.newBuilder().setRequired(true).build())
.addValidate(Validate.newBuilder().setRequired(false).build())
.build();
InputParam atUserIds = InputParam.newBuilder("atUserIds", "atUserIds")
.addValidate(Validate.newBuilder().setRequired(true).build())
InputParam atDingtalkIds = InputParam.newBuilder("atDingtalkIds", "atDingtalkIds")
.addValidate(Validate.newBuilder().setRequired(false).build())
.build();
RadioParam isAtAll = RadioParam.newBuilder("isAtAll", "isAtAll")
.addParamsOptions(new ParamsOptions(STRING_YES, STRING_TRUE, false))
Expand All @@ -120,7 +120,7 @@ public String getConfigJson() {
.build();

paramsList.add(atMobiles);
paramsList.add(atUserIds);
paramsList.add(atDingtalkIds);
paramsList.add(isAtAll);

ObjectMapper mapper = new ObjectMapper();
Expand All @@ -135,4 +135,4 @@ public String getConfigJson() {

return result;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class ReceiverConfig {

private String atMobiles;

private String atUserIds;
private String atDingtalkIds;

private Boolean isAtAll;

Expand All @@ -47,6 +47,6 @@ public boolean equals(Object o) {

@Override
public int hashCode() {
return Objects.hash(atMobiles, atUserIds);
return Objects.hash(atMobiles, atDingtalkIds);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,16 @@ public Object test(@PathVariable("slaId") Long slaId) {
return client.notify(message, configuration);
}

@ApiOperation(value = "test sla sender")
@PostMapping(value = "/sender/test")
public Object testSend(@Valid @RequestBody SlaNotificationCreate slaNotificationSendTest) {
SlaNotificationMessage message = new SlaNotificationMessage();
message.setMessage("[\"test sla sender\"]");
message.setSubject("Test sender");
Map<SlaSenderMessage, Set<SlaConfigMessage>> configuration = slaNotificationService.getSlasNotificationConfigurationBySlasIdAndSenderId(slaNotificationSendTest.getSlaId(), slaNotificationSendTest.getSenderId(), slaNotificationSendTest.getConfig());
return client.notify(message, configuration);
}

@ApiOperation(value = "page list sla")
@GetMapping(value = "/page")
public Object listSlas(@RequestParam("workspaceId") Long workspaceId,
Expand Down Expand Up @@ -219,4 +229,4 @@ public Object pageListNotification(@RequestParam("workspaceId") Long workspaceId
@RequestParam("pageSize") Integer pageSize) {
return slaNotificationService.pageListNotification(workspaceId, slaId, searchVal, pageNumber, pageSize);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ public interface SlaNotificationService extends IService<SlaNotification>{

Map<SlaSenderMessage, Set<SlaConfigMessage>> getSlasNotificationConfigurationBySlasId(Long slaId);

Map<SlaSenderMessage, Set<SlaConfigMessage>> getSlasNotificationConfigurationBySlasIdAndSenderId(Long slaId, Long senderId, String config);

Map<SlaSenderMessage, Set<SlaConfigMessage>> getSlasNotificationConfigurationByJobId(Long job);

String getConfigJson(String type);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,21 @@ public Map<SlaSenderMessage, Set<SlaConfigMessage>> getSlasNotificationConfigura
return result;
}

@Override
public Map<SlaSenderMessage, Set<SlaConfigMessage>> getSlasNotificationConfigurationBySlasIdAndSenderId(Long slaId, Long senderId, String config) {
// Assemble sender information
SlaSender slaSender = slaSenderService.getById(senderId);
SlaSenderMessage slaSenderMessage = BeanConvertUtils.convertBean(slaSender, SlaSenderMessage::new);
HashMap<SlaSenderMessage, Set<SlaConfigMessage>> result = new HashMap<>();
SlaConfigMessage configMessage = new SlaConfigMessage();
configMessage.setType(slaSender.getType());
configMessage.setConfig(config);
HashSet<SlaConfigMessage> set = new HashSet<>();
set.add(configMessage);
result.put(slaSenderMessage, set);
return result;
}

@Override
public Map<SlaSenderMessage, Set<SlaConfigMessage>> getSlasNotificationConfigurationByJobId(Long jobId) {
LambdaQueryWrapper<SlaJob> wrapper = new LambdaQueryWrapper<>();
Expand Down
1 change: 1 addition & 0 deletions datavines-ui/src/locale/en_US.ts
Original file line number Diff line number Diff line change
Expand Up @@ -321,4 +321,5 @@ export default {

next_ten_cron_run_times: 'Next ten cron run times',
view_future_execute_plan: 'view future execute plan',
test_send: 'test send',
};
1 change: 1 addition & 0 deletions datavines-ui/src/locale/zh_CN.ts
Original file line number Diff line number Diff line change
Expand Up @@ -319,4 +319,5 @@ export default {

next_ten_cron_run_times: '未来十次执行时间',
view_future_execute_plan: '查看未来执行计划',
test_send: '测试发送',
};
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useState, useRef } from 'react';
import {
Input, ModalProps, Form, FormInstance, Radio, message,
Input, ModalProps, Form, FormInstance, Radio, message, Button,
} from 'antd';
import { useIntl } from 'react-intl';
import querystring from 'querystring';
Expand Down Expand Up @@ -53,6 +53,9 @@ const Inner = ({ form }: InnerProps) => {
};
const list = (await $http.get('/sla/sender/list', params)) || [];
setSenderList(list);
form?.setFieldsValue({
senderId: undefined,
});
if (res) {
const $res = JSON.parse(res) as NoticeDynamicItem[];
setDynamicMeta($res.map((item) => {
Expand Down Expand Up @@ -144,6 +147,27 @@ export const useNotificationFormModal = (options: ModalProps) => {
editRef.current = editInfo;
const [qs] = useState(querystring.parse(window.location.href.split('?')[1] || ''));
const { workspaceId } = useSelector((r) => r.workSpaceReducer);
const testSender = usePersistFn(async () => {
form.validateFields().then(async (values) => {
try {
setLoading(true);
const { senderId, ...rest } = values;
const params = {
senderId,
slaId: qs.slaId,
config: JSON.stringify(rest),
};
await $http.post('/sla/sender/test', params);
message.success(intl.formatMessage({ id: 'common_success' }));
} catch (error) {
console.log(error);
} finally {
setLoading(false);
}
}).catch((err) => {
console.log(err);
});
});
const onOk = usePersistFn(async () => {
form.validateFields().then(async (values) => {
try {
Expand Down Expand Up @@ -179,6 +203,18 @@ export const useNotificationFormModal = (options: ModalProps) => {
onOk,
width: 600,
...(options || {}),
footer: (
<div style={{ textAlign: 'center' }}>
<Button style={{ width: 120 }} onClick={testSender}>{intl.formatMessage({ id: 'test_send' })}</Button>
<Button
style={{ width: 120 }}
type="primary"
onClick={onOk}
>
{intl.formatMessage({ id: 'confirm_text' })}
</Button>
</div>
),
});
return {
Render: useImmutable(() => (<Render><Inner form={form} /></Render>)),
Expand Down

0 comments on commit a44e08b

Please sign in to comment.