Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#noissue] Cleanup Response #11233

Merged
merged 1 commit into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.navercorp.pinpoint.common.server.response.MapResponse;
import com.navercorp.pinpoint.common.server.response.Result;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.apache.commons.lang3.StringUtils;
Expand Down Expand Up @@ -79,7 +81,7 @@
}

private String jsonError(String errorMessage) throws JsonProcessingException {
SimpleResponse response = new SimpleResponse(false, errorMessage);
MapResponse response = new MapResponse(Result.FAIL, errorMessage);

Check warning on line 84 in collector/src/main/java/com/navercorp/pinpoint/collector/manage/controller/AuthInterceptor.java

View check run for this annotation

Codecov / codecov/patch

collector/src/main/java/com/navercorp/pinpoint/collector/manage/controller/AuthInterceptor.java#L84

Added line #L84 was not covered by tests
return mapper.writeValueAsString(response);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
package com.navercorp.pinpoint.collector.manage.controller;

import com.navercorp.pinpoint.collector.manage.HandlerManager;
import com.navercorp.pinpoint.common.server.response.MapResponse;
import com.navercorp.pinpoint.common.server.response.Response;
import com.navercorp.pinpoint.common.server.response.Result;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
Expand All @@ -39,10 +42,10 @@
}

@GetMapping(value = "/enableAccess")
public ResponseEntity<SimpleResponse> enableAccess() {
public ResponseEntity<Response> enableAccess() {
try {
handlerManager.enableAccess();
return ResponseEntity.ok(SimpleResponse.success());
return ResponseEntity.ok(MapResponse.ok());

Check warning on line 48 in collector/src/main/java/com/navercorp/pinpoint/collector/manage/controller/HandlerManagerController.java

View check run for this annotation

Codecov / codecov/patch

collector/src/main/java/com/navercorp/pinpoint/collector/manage/controller/HandlerManagerController.java#L48

Added line #L48 was not covered by tests
} catch (Exception e) {
return unauthorizedResponse(e.getMessage());
}
Expand All @@ -51,27 +54,27 @@


@GetMapping(value = "/disableAccess")
public ResponseEntity<SimpleResponse> disableAccess() {
public ResponseEntity<Response> disableAccess() {
try {
handlerManager.disableAccess();
return ResponseEntity.ok(SimpleResponse.success());
return ResponseEntity.ok(MapResponse.ok());

Check warning on line 60 in collector/src/main/java/com/navercorp/pinpoint/collector/manage/controller/HandlerManagerController.java

View check run for this annotation

Codecov / codecov/patch

collector/src/main/java/com/navercorp/pinpoint/collector/manage/controller/HandlerManagerController.java#L60

Added line #L60 was not covered by tests
} catch (Exception e) {
return unauthorizedResponse(e.getMessage());
}
}

@GetMapping(value = "/isEnable")
public ResponseEntity<SimpleResponse> isEnable() {
public ResponseEntity<Response> isEnable() {
boolean isEnable = handlerManager.isEnable();

SimpleResponse simpleResponse = SimpleResponse.success();
simpleResponse.addAttribute("isEnable", isEnable);
MapResponse response = new MapResponse(Result.SUCCESS);
response.addAttribute("isEnable", isEnable);

Check warning on line 71 in collector/src/main/java/com/navercorp/pinpoint/collector/manage/controller/HandlerManagerController.java

View check run for this annotation

Codecov / codecov/patch

collector/src/main/java/com/navercorp/pinpoint/collector/manage/controller/HandlerManagerController.java#L70-L71

Added lines #L70 - L71 were not covered by tests

return ResponseEntity.ok(simpleResponse);
return ResponseEntity.ok(response);

Check warning on line 73 in collector/src/main/java/com/navercorp/pinpoint/collector/manage/controller/HandlerManagerController.java

View check run for this annotation

Codecov / codecov/patch

collector/src/main/java/com/navercorp/pinpoint/collector/manage/controller/HandlerManagerController.java#L73

Added line #L73 was not covered by tests
}

private ResponseEntity<SimpleResponse> unauthorizedResponse(String errorMessage) {
SimpleResponse body = new SimpleResponse(false, errorMessage);
private ResponseEntity<Response> unauthorizedResponse(String errorMessage) {
MapResponse body = new MapResponse(Result.FAIL, errorMessage);

Check warning on line 77 in collector/src/main/java/com/navercorp/pinpoint/collector/manage/controller/HandlerManagerController.java

View check run for this annotation

Codecov / codecov/patch

collector/src/main/java/com/navercorp/pinpoint/collector/manage/controller/HandlerManagerController.java#L77

Added line #L77 was not covered by tests
return ResponseEntity.status(HttpStatus.FORBIDDEN).body(body);
}
}
Original file line number Diff line number Diff line change
@@ -1,42 +1,26 @@
package com.navercorp.pinpoint.collector.manage.controller;
package com.navercorp.pinpoint.common.server.response;

import com.fasterxml.jackson.annotation.JsonAnyGetter;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.navercorp.pinpoint.common.server.response.Response;

import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

@JsonInclude(JsonInclude.Include.NON_NULL)
public class SimpleResponse implements Response {
private final boolean result;
private final String message;
public class MapResponse extends SimpleResponse {
private Map<String, Object> attributeMap;

public static SimpleResponse success() {
return new SimpleResponse(true);
public static Response ok() {
return new MapResponse(Result.SUCCESS);

Check warning on line 15 in commons-server/src/main/java/com/navercorp/pinpoint/common/server/response/MapResponse.java

View check run for this annotation

Codecov / codecov/patch

commons-server/src/main/java/com/navercorp/pinpoint/common/server/response/MapResponse.java#L15

Added line #L15 was not covered by tests
}

public SimpleResponse(boolean result, String message) {
this.result = result;
this.message = message;
public MapResponse(Result result, String message) {
super(result, message);

Check warning on line 19 in commons-server/src/main/java/com/navercorp/pinpoint/common/server/response/MapResponse.java

View check run for this annotation

Codecov / codecov/patch

commons-server/src/main/java/com/navercorp/pinpoint/common/server/response/MapResponse.java#L19

Added line #L19 was not covered by tests
}

public SimpleResponse(boolean result) {
this.result = result;
this.message = null;
}

public String getResult() {
if (result) {
return "success";
}
return "fail";
}

public String getMessage() {
return message;
public MapResponse(Result result) {
super(result);

Check warning on line 23 in commons-server/src/main/java/com/navercorp/pinpoint/common/server/response/MapResponse.java

View check run for this annotation

Codecov / codecov/patch

commons-server/src/main/java/com/navercorp/pinpoint/common/server/response/MapResponse.java#L23

Added line #L23 was not covered by tests
}

public void addAttribute(String attributeName, Object attributeValue) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
package com.navercorp.pinpoint.common.server.response;

public interface Response {
}
Result getResult();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.navercorp.pinpoint.common.server.response;

public enum Result {
SUCCESS, FAIL;

Check warning on line 4 in commons-server/src/main/java/com/navercorp/pinpoint/common/server/response/Result.java

View check run for this annotation

Codecov / codecov/patch

commons-server/src/main/java/com/navercorp/pinpoint/common/server/response/Result.java#L3-L4

Added lines #L3 - L4 were not covered by tests

public static Result of(boolean success) {
if (success) {
return SUCCESS;

Check warning on line 8 in commons-server/src/main/java/com/navercorp/pinpoint/common/server/response/Result.java

View check run for this annotation

Codecov / codecov/patch

commons-server/src/main/java/com/navercorp/pinpoint/common/server/response/Result.java#L8

Added line #L8 was not covered by tests
}
return FAIL;

Check warning on line 10 in commons-server/src/main/java/com/navercorp/pinpoint/common/server/response/Result.java

View check run for this annotation

Codecov / codecov/patch

commons-server/src/main/java/com/navercorp/pinpoint/common/server/response/Result.java#L10

Added line #L10 was not covered by tests
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,29 @@

import java.util.Objects;

public class SuccessResponse implements Response {
private final String result;
public class SimpleResponse implements Response {
private final Result result;
private final String message;

public static Response ok() {
return new SuccessResponse("SUCCESS");
return new SimpleResponse(Result.SUCCESS);

Check warning on line 12 in commons-server/src/main/java/com/navercorp/pinpoint/common/server/response/SimpleResponse.java

View check run for this annotation

Codecov / codecov/patch

commons-server/src/main/java/com/navercorp/pinpoint/common/server/response/SimpleResponse.java#L12

Added line #L12 was not covered by tests
}

public static Response ok(String message) {
return new SuccessResponse("SUCCESS", message);
return new SimpleResponse(Result.SUCCESS, message);

Check warning on line 16 in commons-server/src/main/java/com/navercorp/pinpoint/common/server/response/SimpleResponse.java

View check run for this annotation

Codecov / codecov/patch

commons-server/src/main/java/com/navercorp/pinpoint/common/server/response/SimpleResponse.java#L16

Added line #L16 was not covered by tests
}

public SuccessResponse(String result) {
public SimpleResponse(Result result) {
this(result, null);
}

public SuccessResponse(String result, String message) {
public SimpleResponse(Result result, String message) {

Check warning on line 23 in commons-server/src/main/java/com/navercorp/pinpoint/common/server/response/SimpleResponse.java

View check run for this annotation

Codecov / codecov/patch

commons-server/src/main/java/com/navercorp/pinpoint/common/server/response/SimpleResponse.java#L23

Added line #L23 was not covered by tests
this.result = Objects.requireNonNull(result, "result");
this.message = message;

}

public String getResult() {
@Override
public Result getResult() {
return result;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
package com.navercorp.pinpoint.web.authorization.controller;

import com.navercorp.pinpoint.common.server.response.Response;
import com.navercorp.pinpoint.common.server.response.SuccessResponse;
import com.navercorp.pinpoint.common.server.response.Result;
import com.navercorp.pinpoint.common.server.response.SimpleResponse;
import com.navercorp.pinpoint.common.util.StringUtils;
import com.navercorp.pinpoint.web.alarm.CheckerCategory;
import com.navercorp.pinpoint.web.alarm.vo.Rule;
Expand Down Expand Up @@ -62,7 +63,7 @@
throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "there is not applicationId/checkerName/userGroupId/threashold to insert alarm rule");
}
final String ruleId = alarmService.insertRule(rule);
return new AlarmResponse("SUCCESS", ruleId);
return new AlarmResponse(Result.SUCCESS, ruleId);

Check warning on line 66 in web/src/main/java/com/navercorp/pinpoint/web/authorization/controller/AlarmController.java

View check run for this annotation

Codecov / codecov/patch

web/src/main/java/com/navercorp/pinpoint/web/authorization/controller/AlarmController.java#L66

Added line #L66 was not covered by tests
}

@DeleteMapping
Expand All @@ -71,7 +72,7 @@
throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "there is not ruleId to delete alarm rule");
}
alarmService.deleteRule(rule);
return SuccessResponse.ok();
return SimpleResponse.ok();

Check warning on line 75 in web/src/main/java/com/navercorp/pinpoint/web/authorization/controller/AlarmController.java

View check run for this annotation

Codecov / codecov/patch

web/src/main/java/com/navercorp/pinpoint/web/authorization/controller/AlarmController.java#L75

Added line #L75 was not covered by tests
}

@GetMapping(params = USER_GROUP_ID)
Expand All @@ -93,7 +94,7 @@
);
}
alarmService.updateRule(rule);
return SuccessResponse.ok();
return SimpleResponse.ok();

Check warning on line 97 in web/src/main/java/com/navercorp/pinpoint/web/authorization/controller/AlarmController.java

View check run for this annotation

Codecov / codecov/patch

web/src/main/java/com/navercorp/pinpoint/web/authorization/controller/AlarmController.java#L97

Added line #L97 was not covered by tests
}

@GetMapping(value = "/checker")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
package com.navercorp.pinpoint.web.authorization.controller;

import com.navercorp.pinpoint.common.server.response.Response;
import com.navercorp.pinpoint.common.server.response.SuccessResponse;
import com.navercorp.pinpoint.common.server.response.SimpleResponse;
import com.navercorp.pinpoint.common.util.StringUtils;
import com.navercorp.pinpoint.web.service.UserService;
import com.navercorp.pinpoint.web.util.ValueValidator;
Expand Down Expand Up @@ -65,7 +65,7 @@
);
}
userService.insertUser(user);
return SuccessResponse.ok();
return SimpleResponse.ok();

Check warning on line 68 in web/src/main/java/com/navercorp/pinpoint/web/authorization/controller/UserController.java

View check run for this annotation

Codecov / codecov/patch

web/src/main/java/com/navercorp/pinpoint/web/authorization/controller/UserController.java#L68

Added line #L68 was not covered by tests
}

@DeleteMapping
Expand All @@ -77,7 +77,7 @@
);
}
userService.deleteUser(user.getUserId());
return SuccessResponse.ok();
return SimpleResponse.ok();

Check warning on line 80 in web/src/main/java/com/navercorp/pinpoint/web/authorization/controller/UserController.java

View check run for this annotation

Codecov / codecov/patch

web/src/main/java/com/navercorp/pinpoint/web/authorization/controller/UserController.java#L80

Added line #L80 was not covered by tests
}

@GetMapping(params = "userId")
Expand Down Expand Up @@ -129,7 +129,7 @@
);
}
userService.updateUser(user);
return SuccessResponse.ok();
return SimpleResponse.ok();

Check warning on line 132 in web/src/main/java/com/navercorp/pinpoint/web/authorization/controller/UserController.java

View check run for this annotation

Codecov / codecov/patch

web/src/main/java/com/navercorp/pinpoint/web/authorization/controller/UserController.java#L132

Added line #L132 was not covered by tests
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
package com.navercorp.pinpoint.web.authorization.controller;

import com.navercorp.pinpoint.common.server.response.Response;
import com.navercorp.pinpoint.common.server.response.SuccessResponse;
import com.navercorp.pinpoint.common.server.response.Result;
import com.navercorp.pinpoint.common.server.response.SimpleResponse;
import com.navercorp.pinpoint.common.util.StringUtils;
import com.navercorp.pinpoint.web.response.CreateUserGroupResponse;
import com.navercorp.pinpoint.web.service.UserGroupService;
Expand Down Expand Up @@ -71,7 +72,7 @@

try {
final String userGroupNumber = userGroupService.createUserGroup(userGroup);
return new CreateUserGroupResponse("SUCCESS", userGroupNumber);
return new CreateUserGroupResponse(Result.SUCCESS, userGroupNumber);

Check warning on line 75 in web/src/main/java/com/navercorp/pinpoint/web/authorization/controller/UserGroupController.java

View check run for this annotation

Codecov / codecov/patch

web/src/main/java/com/navercorp/pinpoint/web/authorization/controller/UserGroupController.java#L75

Added line #L75 was not covered by tests
} catch (PinpointUserGroupException e) {
logger.error(e.getMessage(), e);
throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, e.getMessage());
Expand All @@ -89,7 +90,7 @@

try {
userGroupService.deleteUserGroup(userGroup);
return SuccessResponse.ok();
return SimpleResponse.ok();

Check warning on line 93 in web/src/main/java/com/navercorp/pinpoint/web/authorization/controller/UserGroupController.java

View check run for this annotation

Codecov / codecov/patch

web/src/main/java/com/navercorp/pinpoint/web/authorization/controller/UserGroupController.java#L93

Added line #L93 was not covered by tests
} catch (PinpointUserGroupException e) {
logger.error(e.getMessage(), e);
throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, e.getMessage());
Expand Down Expand Up @@ -122,7 +123,7 @@
);
}
userGroupService.insertMember(userGroupMember);
return SuccessResponse.ok();
return SimpleResponse.ok();

Check warning on line 126 in web/src/main/java/com/navercorp/pinpoint/web/authorization/controller/UserGroupController.java

View check run for this annotation

Codecov / codecov/patch

web/src/main/java/com/navercorp/pinpoint/web/authorization/controller/UserGroupController.java#L126

Added line #L126 was not covered by tests
}

@DeleteMapping(value = "/member")
Expand All @@ -135,7 +136,7 @@
);
}
userGroupService.deleteMember(userGroupMember);
return SuccessResponse.ok();
return SimpleResponse.ok();

Check warning on line 139 in web/src/main/java/com/navercorp/pinpoint/web/authorization/controller/UserGroupController.java

View check run for this annotation

Codecov / codecov/patch

web/src/main/java/com/navercorp/pinpoint/web/authorization/controller/UserGroupController.java#L139

Added line #L139 was not covered by tests
}

@GetMapping(value = "/member")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
package com.navercorp.pinpoint.web.authorization.controller;

import com.navercorp.pinpoint.common.server.response.Response;
import com.navercorp.pinpoint.common.server.response.SuccessResponse;
import com.navercorp.pinpoint.common.server.response.Result;
import com.navercorp.pinpoint.common.server.response.SimpleResponse;
import com.navercorp.pinpoint.web.alarm.vo.Rule;
import com.navercorp.pinpoint.web.response.AlarmResponse;
import com.navercorp.pinpoint.web.webhook.WebhookModule;
Expand Down Expand Up @@ -57,7 +58,7 @@
}

final String ruleId = webhookAlarmServiceFacade.insertRuleWithWebhooks(rule, ruleWithWebhooks.getWebhookIds());
return new AlarmResponse("SUCCESS", ruleId);
return new AlarmResponse(Result.SUCCESS, ruleId);

Check warning on line 61 in web/src/main/java/com/navercorp/pinpoint/web/authorization/controller/WebhookAlarmController.java

View check run for this annotation

Codecov / codecov/patch

web/src/main/java/com/navercorp/pinpoint/web/authorization/controller/WebhookAlarmController.java#L61

Added line #L61 was not covered by tests
}

@PutMapping(value = "/includeWebhooks")
Expand All @@ -67,7 +68,7 @@
throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "there is not ruleId/userGroupId/applicationid/checkerName to update alarm rule");
}
webhookAlarmServiceFacade.updateRuleWithWebhooks(rule, ruleWithWebhooks.getWebhookIds());
return SuccessResponse.ok();
return SimpleResponse.ok();

Check warning on line 71 in web/src/main/java/com/navercorp/pinpoint/web/authorization/controller/WebhookAlarmController.java

View check run for this annotation

Codecov / codecov/patch

web/src/main/java/com/navercorp/pinpoint/web/authorization/controller/WebhookAlarmController.java#L71

Added line #L71 was not covered by tests
}

static public class RuleWithWebhooks {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
package com.navercorp.pinpoint.web.controller;

import com.navercorp.pinpoint.common.server.response.Response;
import com.navercorp.pinpoint.common.server.response.SuccessResponse;
import com.navercorp.pinpoint.common.server.response.SimpleResponse;
import com.navercorp.pinpoint.common.server.util.time.Range;
import com.navercorp.pinpoint.web.service.AgentStatisticsService;
import com.navercorp.pinpoint.web.util.DateTimeUtils;
Expand Down Expand Up @@ -65,7 +65,7 @@
boolean success = agentStatisticsService.insertAgentCount(agentCountStatistics);

if (success) {
return SuccessResponse.ok();
return SimpleResponse.ok();

Check warning on line 68 in web/src/main/java/com/navercorp/pinpoint/web/controller/AgentStatisticsController.java

View check run for this annotation

Codecov / codecov/patch

web/src/main/java/com/navercorp/pinpoint/web/controller/AgentStatisticsController.java#L68

Added line #L68 was not covered by tests
} else {
throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, "insert DAO error.");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package com.navercorp.pinpoint.web.response;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.navercorp.pinpoint.common.server.response.SuccessResponse;
import com.navercorp.pinpoint.common.server.response.Result;
import com.navercorp.pinpoint.common.server.response.SimpleResponse;

public class AlarmResponse extends SuccessResponse {
public class AlarmResponse extends SimpleResponse {
private final String ruleId;

public AlarmResponse(String result, String ruleId) {
public AlarmResponse(Result result, String ruleId) {
super(result);
this.ruleId = ruleId;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package com.navercorp.pinpoint.web.response;

import com.navercorp.pinpoint.common.server.response.SuccessResponse;
import com.navercorp.pinpoint.common.server.response.Result;
import com.navercorp.pinpoint.common.server.response.SimpleResponse;

import java.util.Objects;

public class CreateUserGroupResponse extends SuccessResponse {
public class CreateUserGroupResponse extends SimpleResponse {
private final String number;

public CreateUserGroupResponse(String result, String number) {
public CreateUserGroupResponse(Result result, String number) {
super(result);
this.number = Objects.requireNonNull(number, "number");
}
Expand Down
Loading