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

Issue30 builderclasses #60

Merged
merged 18 commits into from
Oct 10, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Updating response with ApiResponse for a few apis Users/Envs/Tenants/…
…Teams
  • Loading branch information
muralibasani committed Oct 5, 2022
commit 5b6abd637c96faa1f19ebb7605c5e0203b4c7a98
33 changes: 21 additions & 12 deletions src/main/java/io/aiven/klaw/controller/TopicSyncController.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package io.aiven.klaw.controller;

import static io.aiven.klaw.service.UtilControllerService.handleException;

import io.aiven.klaw.error.KlawException;
import io.aiven.klaw.model.ApiResponse;
import io.aiven.klaw.model.SyncBackTopics;
import io.aiven.klaw.model.SyncTopicUpdates;
import io.aiven.klaw.model.SyncTopicsBulk;
Expand All @@ -25,19 +29,25 @@ public class TopicSyncController {
@Autowired private TopicSyncControllerService topicSyncControllerService;

@PostMapping(value = "/updateSyncTopics")
public ResponseEntity<Map<String, String>> updateSyncTopics(
public ResponseEntity<ApiResponse> updateSyncTopics(
@RequestBody List<SyncTopicUpdates> syncTopicUpdates) {
Map<String, String> updateSyncTopicsResult =
topicSyncControllerService.updateSyncTopics(syncTopicUpdates);
return new ResponseEntity<>(updateSyncTopicsResult, HttpStatus.OK);
try {
return new ResponseEntity<>(
topicSyncControllerService.updateSyncTopics(syncTopicUpdates), HttpStatus.OK);
} catch (KlawException e) {
return handleException(e);
}
}

@PostMapping(value = "/updateSyncTopicsBulk")
public ResponseEntity<Map<String, List<String>>> updateSyncTopicsBulk(
public ResponseEntity<ApiResponse> updateSyncTopicsBulk(
@RequestBody SyncTopicsBulk syncTopicsBulk) {
Map<String, List<String>> updateSyncTopicsBulkResult =
topicSyncControllerService.updateSyncTopicsBulk(syncTopicsBulk);
return new ResponseEntity<>(updateSyncTopicsBulkResult, HttpStatus.OK);
try {
return new ResponseEntity<>(
topicSyncControllerService.updateSyncTopicsBulk(syncTopicsBulk), HttpStatus.OK);
} catch (KlawException e) {
return handleException(e);
}
}

// sync back topics
Expand All @@ -61,11 +71,10 @@ public ResponseEntity<List<TopicInfo>> getTopicsRowView(
}

@PostMapping(value = "/updateSyncBackTopics")
public ResponseEntity<Map<String, List<String>>> updateSyncBackTopics(
public ResponseEntity<ApiResponse> updateSyncBackTopics(
@RequestBody SyncBackTopics syncBackTopics) {
Map<String, List<String>> updateSyncTopicsResult =
topicSyncControllerService.updateSyncBackTopics(syncBackTopics);
return new ResponseEntity<>(updateSyncTopicsResult, HttpStatus.OK);
return new ResponseEntity<>(
topicSyncControllerService.updateSyncBackTopics(syncBackTopics), HttpStatus.OK);
}

@RequestMapping(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.aiven.klaw.controller;

import io.aiven.klaw.dao.ActivityLog;
import io.aiven.klaw.model.ApiResponse;
import io.aiven.klaw.service.UiConfigControllerService;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -37,7 +38,7 @@ public ResponseEntity<List<String>> getRequestTypeStatuses() {
}

@PostMapping(value = "/sendMessageToAdmin")
public ResponseEntity<Map<String, String>> sendMessageToAdmin(
public ResponseEntity<ApiResponse> sendMessageToAdmin(
@RequestParam("contactFormSubject") String contactFormSubject,
@RequestParam("contactFormMessage") String contactFormMessage) {
return new ResponseEntity<>(
Expand Down
125 changes: 79 additions & 46 deletions src/main/java/io/aiven/klaw/controller/UsersTeamsController.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
package io.aiven.klaw.controller;

import static io.aiven.klaw.service.UtilControllerService.handleException;

import io.aiven.klaw.error.KlawException;
import io.aiven.klaw.model.ApiResponse;
import io.aiven.klaw.model.RegisterSaasUserInfoModel;
import io.aiven.klaw.model.RegisterUserInfoModel;
import io.aiven.klaw.model.TeamModel;
import io.aiven.klaw.model.UserInfoModel;
import io.aiven.klaw.service.SaasService;
import io.aiven.klaw.service.UsersTeamsControllerService;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.validation.Valid;
Expand Down Expand Up @@ -50,66 +53,73 @@ public ResponseEntity<List<String>> getAllTeamsSUOnly() {
}

@PostMapping(value = "/deleteTeamRequest")
public ResponseEntity<String> deleteTeam(@RequestParam("teamId") Integer teamId) {

return new ResponseEntity<>(usersTeamsControllerService.deleteTeam(teamId), HttpStatus.OK);
public ResponseEntity<ApiResponse> deleteTeam(@RequestParam("teamId") Integer teamId) {
try {
return new ResponseEntity<>(usersTeamsControllerService.deleteTeam(teamId), HttpStatus.OK);
} catch (KlawException e) {
return handleException(e);
}
}

@PostMapping(value = "/deleteUserRequest")
public ResponseEntity<String> deleteUser(@RequestParam("userId") String userId) {

return new ResponseEntity<>(
usersTeamsControllerService.deleteUser(userId, true), HttpStatus.OK);
public ResponseEntity<ApiResponse> deleteUser(@RequestParam("userId") String userId) {
try {
return new ResponseEntity<>(
usersTeamsControllerService.deleteUser(userId, true), HttpStatus.OK);
} catch (KlawException e) {
return handleException(e);
}
}

@PostMapping(value = "/updateUser")
public ResponseEntity<String> updateUser(@Valid @RequestBody UserInfoModel updateUserObj) {
return new ResponseEntity<>(
usersTeamsControllerService.updateUser(updateUserObj), HttpStatus.OK);
public ResponseEntity<ApiResponse> updateUser(@Valid @RequestBody UserInfoModel updateUserObj) {
try {
return new ResponseEntity<>(
usersTeamsControllerService.updateUser(updateUserObj), HttpStatus.OK);
} catch (KlawException e) {
return handleException(e);
}
}

@PostMapping(value = "/updateProfile")
public ResponseEntity<Map<String, String>> updateProfile(
public ResponseEntity<ApiResponse> updateProfile(
@Valid @RequestBody UserInfoModel updateUserObj) {
return new ResponseEntity<>(
usersTeamsControllerService.updateProfile(updateUserObj), HttpStatus.OK);
try {
return new ResponseEntity<>(
usersTeamsControllerService.updateProfile(updateUserObj), HttpStatus.OK);
} catch (KlawException e) {
return handleException(e);
}
}

@PostMapping(value = "/addNewUser")
public ResponseEntity<Map<String, String>> addNewUser(@Valid @RequestBody UserInfoModel newUser) {

public ResponseEntity<ApiResponse> addNewUser(@Valid @RequestBody UserInfoModel newUser) {
try {
Map<String, String> response = usersTeamsControllerService.addNewUser(newUser, true);
return new ResponseEntity<>(response, HttpStatus.OK);
} catch (Exception e) {
Map<String, String> resMap = new HashMap<>();
resMap.put("result", "Failure. Unable to create the user.");
return new ResponseEntity<>(resMap, HttpStatus.INTERNAL_SERVER_ERROR);
return new ResponseEntity<>(
usersTeamsControllerService.addNewUser(newUser, true), HttpStatus.OK);
} catch (KlawException e) {
return handleException(e);
}
}

@PostMapping(value = "/registerUser")
public ResponseEntity<Map<String, String>> registerUser(
@Valid @RequestBody RegisterUserInfoModel newUser) throws Exception {
public ResponseEntity<ApiResponse> registerUser(@Valid @RequestBody RegisterUserInfoModel newUser)
throws Exception {
try {
return new ResponseEntity<>(
usersTeamsControllerService.registerUser(newUser, true), HttpStatus.OK);
} catch (Exception e) {
Map<String, String> resMap = new HashMap<>();
resMap.put("result", "Failure. " + e.getMessage());
return new ResponseEntity<>(resMap, HttpStatus.INTERNAL_SERVER_ERROR);
} catch (KlawException e) {
return handleException(e);
}
}

@PostMapping(value = "/registerUserSaas")
public ResponseEntity<Map<String, String>> registerUserSaas(
public ResponseEntity<ApiResponse> registerUserSaas(
@Valid @RequestBody RegisterSaasUserInfoModel newUser) throws Exception {
try {
return new ResponseEntity<>(saasService.registerUserSaas(newUser), HttpStatus.OK);
} catch (Exception e) {
Map<String, String> resMap = new HashMap<>();
resMap.put("result", "Failure. Something went wrong. Please try later.");
return new ResponseEntity<>(resMap, HttpStatus.INTERNAL_SERVER_ERROR);
} catch (KlawException e) {
return handleException(e);
}
}

Expand Down Expand Up @@ -142,26 +152,45 @@ public ResponseEntity<RegisterUserInfoModel> getRegistrationInfoFromId(
}

@PostMapping(value = "/execNewUserRequestApprove")
public ResponseEntity<String> approveNewUserRequests(@RequestParam("username") String username) {
return new ResponseEntity<>(
usersTeamsControllerService.approveNewUserRequests(username, true, 0, ""), HttpStatus.OK);
public ResponseEntity<ApiResponse> approveNewUserRequests(
@RequestParam("username") String username) {
try {
return new ResponseEntity<>(
usersTeamsControllerService.approveNewUserRequests(username, true, 0, ""), HttpStatus.OK);
} catch (KlawException e) {
return handleException(e);
}
}

@PostMapping(value = "/execNewUserRequestDecline")
public ResponseEntity<String> declineNewUserRequests(@RequestParam("username") String username) {
return new ResponseEntity<>(
usersTeamsControllerService.declineNewUserRequests(username), HttpStatus.OK);
public ResponseEntity<ApiResponse> declineNewUserRequests(
@RequestParam("username") String username) {
try {
return new ResponseEntity<>(
usersTeamsControllerService.declineNewUserRequests(username), HttpStatus.OK);
} catch (KlawException e) {
return handleException(e);
}
}

@PostMapping(value = "/addNewTeam")
public ResponseEntity<String> addNewTeam(@Valid @RequestBody TeamModel newTeam) {
return new ResponseEntity<>(
usersTeamsControllerService.addNewTeam(newTeam, true), HttpStatus.OK);
public ResponseEntity<ApiResponse> addNewTeam(@Valid @RequestBody TeamModel newTeam) {
try {
return new ResponseEntity<>(
usersTeamsControllerService.addNewTeam(newTeam, true), HttpStatus.OK);
} catch (KlawException e) {
return handleException(e);
}
}

@PostMapping(value = "/updateTeam")
public ResponseEntity<String> updateTeam(@Valid @RequestBody TeamModel updateTeam) {
return new ResponseEntity<>(usersTeamsControllerService.updateTeam(updateTeam), HttpStatus.OK);
public ResponseEntity<ApiResponse> updateTeam(@Valid @RequestBody TeamModel updateTeam) {
try {
return new ResponseEntity<>(
usersTeamsControllerService.updateTeam(updateTeam), HttpStatus.OK);
} catch (KlawException e) {
return handleException(e);
}
}

@RequestMapping(
Expand All @@ -176,8 +205,12 @@ public ResponseEntity<TeamModel> getTeamDetails(
}

@PostMapping(value = "/chPwd")
public ResponseEntity<String> changePwd(@RequestParam("changePwd") String changePwd) {
return new ResponseEntity<>(usersTeamsControllerService.changePwd(changePwd), HttpStatus.OK);
public ResponseEntity<ApiResponse> changePwd(@RequestParam("changePwd") String changePwd) {
try {
return new ResponseEntity<>(usersTeamsControllerService.changePwd(changePwd), HttpStatus.OK);
} catch (KlawException e) {
return handleException(e);
}
}

@RequestMapping(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1084,10 +1084,13 @@ public Map<String, String> deleteTenant() {

List<UserInfo> allUsers = manageDatabase.getHandleDbRequests().selectAllUsersInfo(tenantId);
for (UserInfo userInfo : allUsers) {
usersTeamsControllerService.deleteUser(userInfo.getUsername(), false); // internal delete
try {
usersTeamsControllerService.deleteUser(userInfo.getUsername(), false); // internal delete
} catch (KlawException e) {
throw new RuntimeException(e);
}
}
manageDatabase.getHandleDbRequests().deleteAllUsers(tenantId);

manageDatabase.getHandleDbRequests().deleteAllTeams(tenantId);
manageDatabase.getHandleDbRequests().deleteAllEnvs(tenantId);
manageDatabase.getHandleDbRequests().deleteAllClusters(tenantId);
Expand All @@ -1097,7 +1100,7 @@ public Map<String, String> deleteTenant() {

String result = manageDatabase.getHandleDbRequests().disableTenant(tenantId);

if ("success".equals(result)) {
if (ApiResultStatus.SUCCESS.value.equals(result)) {
commonUtilsService.updateMetadata(tenantId, EntityType.TENANT, MetadataOperationType.DELETE);
resultMap.put("result", "success");
resultMap.put("tenantId", tenantName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,13 @@ public Map<String, String> getConnectorDetails(String connectorName, String envI
}

response.put("result", res.toString());

return response;
}

public ApiResponse updateSyncConnectors(List<SyncConnectorUpdates> updatedSyncTopics)
throws KlawException {
log.info("updateSyncConnectors {}", updatedSyncTopics);
String userDetails = getUserName();
Map<String, String> response = new HashMap<>();

if (commonUtilsService.isNotAuthorizedUser(getPrincipal(), PermissionType.SYNC_CONNECTORS)) {
return ApiResponse.builder().result(ApiResultStatus.NOT_AUTHORIZED.value).build();
Expand Down
Loading