This is an automated email from the ASF dual-hosted git repository.
gongchao pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/hertzbeat.git
The following commit(s) were added to refs/heads/master by this push:
new bf8d5b79b [bugfix] Fix the bug where canceling an edit on a record
still updates the page values. (#2911)
bf8d5b79b is described below
commit bf8d5b79bb783771c1cfa7c426c8abfe509d55d1
Author: yunfan24 <[email protected]>
AuthorDate: Sun Dec 29 11:38:57 2024 +0800
[bugfix] Fix the bug where canceling an edit on a record still updates the
page values. (#2911)
Co-authored-by: aias00 <[email protected]>
Co-authored-by: tomsun28 <[email protected]>
---
.../manager/controller/NoticeConfigController.java | 35 ++++++
.../controller/NoticeConfigControllerTest.java | 58 ++++++++++
.../alert/alert-notice/alert-notice.component.ts | 121 +++++++++++++--------
web-app/src/app/service/notice-receiver.service.ts | 4 +
web-app/src/app/service/notice-rule.service.ts | 4 +
web-app/src/app/service/notice-template.service.ts | 5 +
6 files changed, 182 insertions(+), 45 deletions(-)
diff --git
a/hertzbeat-manager/src/main/java/org/apache/hertzbeat/manager/controller/NoticeConfigController.java
b/hertzbeat-manager/src/main/java/org/apache/hertzbeat/manager/controller/NoticeConfigController.java
index 241bddaa0..3bde1ed61 100644
---
a/hertzbeat-manager/src/main/java/org/apache/hertzbeat/manager/controller/NoticeConfigController.java
+++
b/hertzbeat-manager/src/main/java/org/apache/hertzbeat/manager/controller/NoticeConfigController.java
@@ -87,6 +87,18 @@ public class NoticeConfigController {
return
ResponseEntity.ok(Message.success(noticeConfigService.getNoticeReceivers(name)));
}
+ @GetMapping(path = "/receiver/{id}")
+ @Operation(summary = "Get the recipient information based on the recipient
ID",
+ description = "Get the recipient information based on the
recipient ID")
+ public ResponseEntity<Message<NoticeReceiver>> getReceiverById(
+ @Parameter(description = "en: Recipient ID", example =
"6565463543") @PathVariable("id") final Long receiverId) {
+ NoticeReceiver noticeReceiver =
noticeConfigService.getReceiverById(receiverId);
+ if (noticeReceiver == null) {
+ return ResponseEntity.ok(Message.fail(FAIL_CODE, "The relevant
information of the recipient could not be found, please check whether the
parameters are correct or refresh the page"));
+ }
+ return ResponseEntity.ok(Message.success(noticeReceiver));
+ }
+
@PostMapping(path = "/rule")
@Operation(summary = "Add a notification policy", description = "Add a
notification policy")
public ResponseEntity<Message<Void>> addNewNoticeRule(@Valid @RequestBody
NoticeRule noticeRule) {
@@ -122,6 +134,17 @@ public class NoticeConfigController {
return
ResponseEntity.ok(Message.success(noticeConfigService.getNoticeRules(name)));
}
+ @GetMapping(path = "/rule/{id}")
+ @Operation(summary = "Get the notification policy information based on the
policy ID",
+ description = "Get the notification policy information based on
the policy ID")
+ public ResponseEntity<Message<NoticeRule>> getRuleById(
+ @Parameter(description = "en: Notification Policy ID", example =
"6565463543") @PathVariable("id") final Long ruleId) {
+ NoticeRule noticeRule = noticeConfigService.getNoticeRulesById(ruleId);
+ if (noticeRule == null) {
+ return ResponseEntity.ok(Message.fail(FAIL_CODE, "The specified
notification rule could not be queried, please check whether the parameters are
correct or refresh the page"));
+ }
+ return ResponseEntity.ok(Message.success(noticeRule));
+ }
@PostMapping(path = "/template")
@Operation(summary = "Add a notification template", description = "Add a
notification template")
@@ -159,6 +182,18 @@ public class NoticeConfigController {
return ResponseEntity.ok(Message.success(templatePage));
}
+ @GetMapping(path = "/template/{id}")
+ @Operation(summary = "Get the notification template information based on
the template ID",
+ description = "Get the notification template information based on
the template ID")
+ public ResponseEntity<Message<NoticeTemplate>> getTemplateById(
+ @Parameter(description = "en: Notification template ID", example =
"6565463543") @PathVariable("id") final Long templateId) {
+ Optional<NoticeTemplate> noticeTemplate =
noticeConfigService.getNoticeTemplatesById(templateId);
+ if (noticeTemplate.isEmpty()) {
+ return ResponseEntity.ok(Message.fail(FAIL_CODE, "The specified
notification template could not be queried, please check whether the parameters
are correct or refresh the page"));
+ }
+ return ResponseEntity.ok(Message.success(noticeTemplate.get()));
+ }
+
@PostMapping(path = "/receiver/send-test-msg")
@Operation(summary = "Send test msg to receiver", description = "Send test
msg to receiver")
public ResponseEntity<Message<Void>> sendTestMsg(@Valid @RequestBody
NoticeReceiver noticeReceiver) {
diff --git
a/hertzbeat-manager/src/test/java/org/apache/hertzbeat/manager/controller/NoticeConfigControllerTest.java
b/hertzbeat-manager/src/test/java/org/apache/hertzbeat/manager/controller/NoticeConfigControllerTest.java
index e011b4478..434eaa18f 100644
---
a/hertzbeat-manager/src/test/java/org/apache/hertzbeat/manager/controller/NoticeConfigControllerTest.java
+++
b/hertzbeat-manager/src/test/java/org/apache/hertzbeat/manager/controller/NoticeConfigControllerTest.java
@@ -185,6 +185,26 @@ class NoticeConfigControllerTest {
.andReturn();
}
+ @Test
+ void getReceiverById() throws Exception {
+ NoticeReceiver noticeReceiver = getNoticeReceiver();
+ when(noticeConfigService.getReceiverById(7565463543L))
+ .thenReturn(noticeReceiver);
+ when(noticeConfigService.getReceiverById(6565463543L))
+ .thenReturn(null);
+
+
this.mockMvc.perform(MockMvcRequestBuilders.get("/api/notice/receiver/{id}",
6565463543L))
+ .andExpect(status().isOk())
+ .andExpect(jsonPath("$.code").value((int)
CommonConstants.FAIL_CODE))
+ .andExpect(jsonPath("$.msg").value("The relevant information
of the recipient could not be found, please check whether the parameters are
correct or refresh the page"))
+ .andReturn();
+
+
this.mockMvc.perform(MockMvcRequestBuilders.get("/api/notice/receiver/{id}",
7565463543L))
+ .andExpect(status().isOk())
+ .andExpect(jsonPath("$.code").value((int)
CommonConstants.SUCCESS_CODE))
+ .andReturn();
+ }
+
@Test
void addNewNoticeRule() throws Exception {
NoticeRule noticeRule = getNoticeRule();
@@ -245,6 +265,26 @@ class NoticeConfigControllerTest {
.andReturn();
}
+ @Test
+ void getRuleById() throws Exception {
+ NoticeRule noticeRule = getNoticeRule();
+ when(noticeConfigService.getNoticeRulesById(7565463543L))
+ .thenReturn(noticeRule);
+ when(noticeConfigService.getNoticeRulesById(6565463543L))
+ .thenReturn(null);
+
+
this.mockMvc.perform(MockMvcRequestBuilders.get("/api/notice/rule/{id}",
6565463543L))
+ .andExpect(status().isOk())
+ .andExpect(jsonPath("$.code").value((int)
CommonConstants.FAIL_CODE))
+ .andExpect(jsonPath("$.msg").value("The specified notification
rule could not be queried, please check whether the parameters are correct or
refresh the page"))
+ .andReturn();
+
+
this.mockMvc.perform(MockMvcRequestBuilders.get("/api/notice/rule/{id}",
7565463543L))
+ .andExpect(status().isOk())
+ .andExpect(jsonPath("$.code").value((int)
CommonConstants.SUCCESS_CODE))
+ .andReturn();
+ }
+
@Test
void sendTestMsg() throws Exception {
@@ -349,6 +389,24 @@ class NoticeConfigControllerTest {
.andExpect(jsonPath("$.data[1].name").value("Template2"));
}
+ @Test
+ void testGetTemplatesById() throws Exception {
+ // Mock the service response
+ NoticeTemplate template = new NoticeTemplate();
+ template.setName("Template1");
+
when(noticeConfigService.getNoticeTemplatesById(1010101010L)).thenReturn(Optional.of(template));
+
when(noticeConfigService.getNoticeTemplatesById(25857585858L)).thenReturn(Optional.empty());
+ // Perform the GET request and verify the response
+ this.mockMvc.perform(get("/api/notice/template/{id}", 1010101010L))
+ .andExpect(status().isOk())
+ .andExpect(jsonPath("$.code").value((int)
CommonConstants.SUCCESS_CODE))
+ .andExpect(jsonPath("$.data.name").value("Template1"));
+ this.mockMvc.perform(get("/api/notice/template/{id}", 25857585858L))
+ .andExpect(status().isOk())
+ .andExpect(jsonPath("$.code").value((int)
CommonConstants.FAIL_CODE))
+ .andExpect(jsonPath("$.msg").value("The specified notification
template could not be queried, please check whether the parameters are correct
or refresh the page"));
+ }
+
@Test
void sendTestMsg_Failure() throws Exception {
NoticeReceiver noticeReceiver = getNoticeReceiver();
diff --git
a/web-app/src/app/routes/alert/alert-notice/alert-notice.component.ts
b/web-app/src/app/routes/alert/alert-notice/alert-notice.component.ts
index 4e6d54e85..8319792d8 100644
--- a/web-app/src/app/routes/alert/alert-notice/alert-notice.component.ts
+++ b/web-app/src/app/routes/alert/alert-notice/alert-notice.component.ts
@@ -317,9 +317,20 @@ export class AlertNoticeComponent implements OnInit {
}
onEditOneNoticeReceiver(receiver: NoticeReceiver) {
- this.receiver = receiver;
- this.isManageReceiverModalVisible = true;
- this.isManageReceiverModalAdd = false;
+ this.noticeReceiverSvc.getReceiver(receiver.id).subscribe(
+ message => {
+ if (message.code === 0) {
+ this.receiver = message.data;
+ this.isManageReceiverModalVisible = true;
+ this.isManageReceiverModalAdd = false;
+ } else {
+ this.notifySvc.error(this.i18nSvc.fanyi('common.notify.edit-fail'),
message.msg);
+ }
+ },
+ error => {
+ this.notifySvc.error(this.i18nSvc.fanyi('common.notify.edit-fail'),
error.msg);
+ }
+ );
}
onSendAlertTestMsg() {
@@ -429,9 +440,20 @@ export class AlertNoticeComponent implements OnInit {
}
onEditOneNoticeTemplate(template: NoticeTemplate) {
- this.template = template;
- this.isManageTemplateModalVisible = true;
- this.isManageTemplateModalAdd = false;
+ this.noticeTemplateSvc.getNoticeTemplateById(template.id).subscribe(
+ message => {
+ if (message.code === 0) {
+ this.template = message.data;
+ this.isManageTemplateModalVisible = true;
+ this.isManageTemplateModalAdd = false;
+ } else {
+ this.notifySvc.error(this.i18nSvc.fanyi('common.notify.edit-fail'),
message.msg);
+ }
+ },
+ error => {
+ this.notifySvc.error(this.i18nSvc.fanyi('common.notify.edit-fail'),
error.msg);
+ }
+ );
}
onShowOneNoticeTemplate(template: NoticeTemplate) {
@@ -452,46 +474,55 @@ export class AlertNoticeComponent implements OnInit {
}
onEditOneNoticeRule(rule: NoticeRule) {
- this.rule = rule;
- this.isLimit = !(this.rule.days == null || this.rule.days.length == 7);
- this.isManageRuleModalVisible = true;
- this.isManageRuleModalAdd = false;
- this.receiversOption = [];
-
- this.rule.receiverId.forEach(id => {
- this.receiversOption.push({
- value: id,
- label: this.rule.receiverName[this.rule.receiverId.indexOf(id)]
- });
- });
-
- this.templatesOption = [];
- if (this.rule.templateId && this.rule.templateName) {
- this.templatesOption.push({
- value: rule.templateId,
- label: rule.templateName
- });
- } else {
- this.rule.templateId = -1;
- this.templatesOption.push({
- value: -1,
- label: this.i18nSvc.fanyi('alert.notice.template.preset.true')
- });
- }
- this.filterTags = [];
- if (rule.tags != undefined) {
- rule.tags.forEach(item => {
- let tag = `${item.name}`;
- if (item.value != undefined) {
- tag = `${tag}:${item.value}`;
+ this.noticeRuleSvc.getNoticeRuleById(rule.id).subscribe(
+ message => {
+ if (message.code === 0) {
+ this.rule = message.data;
+ this.isLimit = !(this.rule.days == null || this.rule.days.length ==
7);
+ this.isManageRuleModalVisible = true;
+ this.isManageRuleModalAdd = false;
+ this.receiversOption = [];
+ this.rule.receiverId.forEach(id => {
+ this.receiversOption.push({
+ value: id,
+ label: this.rule.receiverName[this.rule.receiverId.indexOf(id)]
+ });
+ });
+ this.templatesOption = [];
+ if (this.rule.templateId && this.rule.templateName) {
+ this.templatesOption.push({
+ value: rule.templateId,
+ label: rule.templateName
+ });
+ } else {
+ this.rule.templateId = -1;
+ this.templatesOption.push({
+ value: -1,
+ label: this.i18nSvc.fanyi('alert.notice.template.preset.true')
+ });
+ }
+ this.filterTags = [];
+ if (rule.tags != undefined) {
+ rule.tags.forEach(item => {
+ let tag = `${item.name}`;
+ if (item.value != undefined) {
+ tag = `${tag}:${item.value}`;
+ }
+ this.filterTags.push(tag);
+ this.tagsOption.push({
+ value: tag,
+ label: tag
+ });
+ });
+ }
+ } else {
+ this.notifySvc.error(this.i18nSvc.fanyi('common.notify.edit-fail'),
message.msg);
}
- this.filterTags.push(tag);
- this.tagsOption.push({
- value: tag,
- label: tag
- });
- });
- }
+ },
+ error => {
+ this.notifySvc.error(this.i18nSvc.fanyi('common.notify.edit-fail'),
error.msg);
+ }
+ );
}
onNoticeRuleDaysChange(value: any[]) {
diff --git a/web-app/src/app/service/notice-receiver.service.ts
b/web-app/src/app/service/notice-receiver.service.ts
index e358a13e0..d81afca32 100644
--- a/web-app/src/app/service/notice-receiver.service.ts
+++ b/web-app/src/app/service/notice-receiver.service.ts
@@ -50,6 +50,10 @@ export class NoticeReceiverService {
return this.http.get<Message<NoticeReceiver[]>>(notice_receivers_uri);
}
+ public getReceiver(receiverId: number): Observable<Message<NoticeReceiver>> {
+ return
this.http.get<Message<NoticeReceiver>>(`${notice_receiver_uri}/${receiverId}`);
+ }
+
public sendAlertMsgToReceiver(body: NoticeReceiver):
Observable<Message<any>> {
return this.http.post<Message<any>>(notice_receiver_send_test_msg_uri,
body);
}
diff --git a/web-app/src/app/service/notice-rule.service.ts
b/web-app/src/app/service/notice-rule.service.ts
index 1b0145b0f..4edb78cac 100644
--- a/web-app/src/app/service/notice-rule.service.ts
+++ b/web-app/src/app/service/notice-rule.service.ts
@@ -48,4 +48,8 @@ export class NoticeRuleService {
public getNoticeRules(): Observable<Message<NoticeRule[]>> {
return this.http.get<Message<NoticeRule[]>>(notice_rules_uri);
}
+
+ public getNoticeRuleById(ruleId: number): Observable<Message<NoticeRule>> {
+ return this.http.get<Message<NoticeRule>>(`${notice_rule_uri}/${ruleId}`);
+ }
}
diff --git a/web-app/src/app/service/notice-template.service.ts
b/web-app/src/app/service/notice-template.service.ts
index 979e4def1..c6e89cb9c 100644
--- a/web-app/src/app/service/notice-template.service.ts
+++ b/web-app/src/app/service/notice-template.service.ts
@@ -48,7 +48,12 @@ export class NoticeTemplateService {
public getNoticeTemplates(): Observable<Message<NoticeTemplate[]>> {
return this.http.get<Message<NoticeTemplate[]>>(notice_templates_uri);
}
+
public getDefaultNoticeTemplates(): Observable<Message<NoticeTemplate[]>> {
return
this.http.get<Message<NoticeTemplate[]>>(default_notice_templates_uri);
}
+
+ public getNoticeTemplateById(templateId: number):
Observable<Message<NoticeTemplate>> {
+ return
this.http.get<Message<NoticeTemplate>>(`${notice_template_uri}/${templateId}`);
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]