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 13 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
2 changes: 1 addition & 1 deletion src/main/java/io/aiven/klaw/config/ManageDatabase.java
Original file line number Diff line number Diff line change
Expand Up @@ -748,6 +748,6 @@ public String deleteTenant(int tenantId) {
kwSchemaRegClustersPertenant.remove(tenantId);
kwKafkaConnectClustersPertenant.remove(tenantId);
kwAllClustersPertenant.remove(tenantId);
return "success";
return ApiResultStatus.SUCCESS.value;
}
}
99 changes: 37 additions & 62 deletions src/main/java/io/aiven/klaw/controller/AclController.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package io.aiven.klaw.controller;

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

import io.aiven.klaw.error.KlawException;
import io.aiven.klaw.model.*;
import io.aiven.klaw.service.AclControllerService;
import java.util.List;
import java.util.Map;
import javax.validation.Valid;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
Expand All @@ -19,19 +22,18 @@

@RestController
@RequestMapping("/")
@Slf4j
public class AclController {

@Autowired AclControllerService aclControllerService;

@PostMapping(value = "/createAcl")
public ResponseEntity<String> createAcl(@Valid @RequestBody AclRequestsModel addAclRequest) {
return new ResponseEntity<>(aclControllerService.createAcl(addAclRequest), HttpStatus.OK);
}

@PostMapping(value = "/updateSyncAcls")
public ResponseEntity<Map<String, String>> updateSyncAcls(
@RequestBody List<SyncAclUpdates> syncAclUpdates) {
return new ResponseEntity<>(aclControllerService.updateSyncAcls(syncAclUpdates), HttpStatus.OK);
public ResponseEntity<ApiResponse> createAcl(@Valid @RequestBody AclRequestsModel addAclRequest) {
try {
return new ResponseEntity<>(aclControllerService.createAcl(addAclRequest), HttpStatus.OK);
} catch (KlawException e) {
return handleException(e);
}
muralibasani marked this conversation as resolved.
Show resolved Hide resolved
}

@RequestMapping(
Expand Down Expand Up @@ -66,29 +68,44 @@ public ResponseEntity<List<AclRequestsModel>> getCreatedAclRequests(
value = "/deleteAclRequests",
method = RequestMethod.POST,
produces = {MediaType.APPLICATION_JSON_VALUE})
public ResponseEntity<String> deleteAclRequests(@RequestParam("req_no") String req_no) {
return new ResponseEntity<>(aclControllerService.deleteAclRequests(req_no), HttpStatus.OK);
public ResponseEntity<ApiResponse> deleteAclRequests(@RequestParam("req_no") String req_no) {
try {
return new ResponseEntity<>(aclControllerService.deleteAclRequests(req_no), HttpStatus.OK);
} catch (KlawException e) {
return handleException(e);
}
}

@PostMapping(value = "/execAclRequest")
public ResponseEntity<String> approveAclRequests(@RequestParam("req_no") String req_no)
throws KlawException {
return new ResponseEntity<>(aclControllerService.approveAclRequests(req_no), HttpStatus.OK);
public ResponseEntity<ApiResponse> approveAclRequests(@RequestParam("req_no") String req_no) {
try {
return new ResponseEntity<>(aclControllerService.approveAclRequests(req_no), HttpStatus.OK);
} catch (KlawException e) {
return handleException(e);
}
}

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

@PostMapping(value = "/execAclRequestDecline")
public ResponseEntity<String> declineAclRequests(
public ResponseEntity<ApiResponse> declineAclRequests(
@RequestParam("req_no") String req_no,
@RequestParam("reasonForDecline") String reasonForDecline) {
return new ResponseEntity<>(
aclControllerService.declineAclRequests(req_no, reasonForDecline), HttpStatus.OK);
try {
return new ResponseEntity<>(
aclControllerService.declineAclRequests(req_no, reasonForDecline), HttpStatus.OK);
} catch (KlawException e) {
return handleException(e);
}
}

@RequestMapping(
Expand All @@ -111,47 +128,6 @@ public ResponseEntity<TopicOverview> getSchemaOfTopic(
aclControllerService.getSchemaOfTopic(topicNameSearch, schemaVersionSearch), HttpStatus.OK);
}

@RequestMapping(
value = "/getSyncBackAcls",
method = RequestMethod.GET,
produces = {MediaType.APPLICATION_JSON_VALUE})
public ResponseEntity<List<AclInfo>> getSyncBackAcls(
@RequestParam("env") String envId,
@RequestParam("pageNo") String pageNo,
@RequestParam(value = "currentPage", defaultValue = "") String currentPage,
@RequestParam(value = "topicnamesearch", required = false) String topicNameSearch,
@RequestParam(value = "teamName", required = false) String teamName) {
return new ResponseEntity<>(
aclControllerService.getSyncBackAcls(envId, pageNo, currentPage, topicNameSearch, teamName),
HttpStatus.OK);
}

@PostMapping(value = "/updateSyncBackAcls")
public ResponseEntity<Map<String, List<String>>> updateSyncBackAcls(
@RequestBody SyncBackAcls syncBackAcls) {
Map<String, List<String>> updateSyncAclsResult =
aclControllerService.updateSyncBackAcls(syncBackAcls);
return new ResponseEntity<>(updateSyncAclsResult, HttpStatus.OK);
}

// get acls from kafka cluster
@RequestMapping(
value = "/getSyncAcls",
method = RequestMethod.GET,
produces = {MediaType.APPLICATION_JSON_VALUE})
public ResponseEntity<List<AclInfo>> getSyncAcls(
@RequestParam("env") String envId,
@RequestParam("pageNo") String pageNo,
@RequestParam(value = "currentPage", defaultValue = "") String currentPage,
@RequestParam(value = "topicnamesearch", required = false) String topicNameSearch,
@RequestParam(value = "showAllAcls", defaultValue = "false", required = false)
String showAllAcls)
throws KlawException {
return new ResponseEntity<>(
aclControllerService.getSyncAcls(envId, pageNo, currentPage, topicNameSearch, showAllAcls),
HttpStatus.OK);
}

// getConsumerOffsets from kafka cluster
@RequestMapping(
value = "/getConsumerOffsets",
Expand All @@ -160,8 +136,7 @@ public ResponseEntity<List<AclInfo>> getSyncAcls(
public ResponseEntity<List<Map<String, String>>> getConsumerOffsets(
@RequestParam("env") String envId,
@RequestParam("topicName") String topicName,
@RequestParam(value = "consumerGroupId") String consumerGroupId)
throws KlawException {
@RequestParam(value = "consumerGroupId") String consumerGroupId) {
return new ResponseEntity<>(
aclControllerService.getConsumerOffsets(envId, consumerGroupId, topicName), HttpStatus.OK);
}
Expand Down
86 changes: 86 additions & 0 deletions src/main/java/io/aiven/klaw/controller/AclSyncController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
package io.aiven.klaw.controller;

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

import io.aiven.klaw.error.KlawException;
import io.aiven.klaw.model.AclInfo;
import io.aiven.klaw.model.ApiResponse;
import io.aiven.klaw.model.SyncAclUpdates;
import io.aiven.klaw.model.SyncBackAcls;
import io.aiven.klaw.service.AclSyncControllerService;
import java.util.List;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/")
@Slf4j
public class AclSyncController {

@Autowired AclSyncControllerService aclSyncControllerService;

@PostMapping(value = "/updateSyncAcls")
public ResponseEntity<ApiResponse> updateSyncAcls(
@RequestBody List<SyncAclUpdates> syncAclUpdates) {
try {
return new ResponseEntity<>(
aclSyncControllerService.updateSyncAcls(syncAclUpdates), HttpStatus.OK);
} catch (KlawException e) {
return handleException(e);
}
}

@RequestMapping(
value = "/getSyncBackAcls",
method = RequestMethod.GET,
produces = {MediaType.APPLICATION_JSON_VALUE})
public ResponseEntity<List<AclInfo>> getSyncBackAcls(
@RequestParam("env") String envId,
@RequestParam("pageNo") String pageNo,
@RequestParam(value = "currentPage", defaultValue = "") String currentPage,
@RequestParam(value = "topicnamesearch", required = false) String topicNameSearch,
@RequestParam(value = "teamName", required = false) String teamName) {
return new ResponseEntity<>(
aclSyncControllerService.getSyncBackAcls(
envId, pageNo, currentPage, topicNameSearch, teamName),
HttpStatus.OK);
}

@PostMapping(value = "/updateSyncBackAcls")
public ResponseEntity<ApiResponse> updateSyncBackAcls(@RequestBody SyncBackAcls syncBackAcls) {
try {
return new ResponseEntity<>(
aclSyncControllerService.updateSyncBackAcls(syncBackAcls), HttpStatus.OK);
} catch (KlawException e) {
return handleException(e);
}
}

// get acls from kafka cluster
@RequestMapping(
value = "/getSyncAcls",
method = RequestMethod.GET,
produces = {MediaType.APPLICATION_JSON_VALUE})
public ResponseEntity<List<AclInfo>> getSyncAcls(
@RequestParam("env") String envId,
@RequestParam("pageNo") String pageNo,
@RequestParam(value = "currentPage", defaultValue = "") String currentPage,
@RequestParam(value = "topicnamesearch", required = false) String topicNameSearch,
@RequestParam(value = "showAllAcls", defaultValue = "false", required = false)
String showAllAcls)
throws KlawException {
return new ResponseEntity<>(
aclSyncControllerService.getSyncAcls(
envId, pageNo, currentPage, topicNameSearch, showAllAcls),
HttpStatus.OK);
}
}
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.EnvModel;
import io.aiven.klaw.model.KwClustersModel;
import io.aiven.klaw.model.KwTenantModel;
Expand Down Expand Up @@ -75,13 +79,17 @@ public ResponseEntity<List<EnvModel>> getEnvsBaseClusterFilteredForTeam() {
}

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

@PostMapping(value = "/addNewCluster")
public ResponseEntity<Map<String, String>> addNewCluster(
public ResponseEntity<ApiResponse> addNewCluster(
@Valid @RequestBody KwClustersModel kwClustersModel) {
return new ResponseEntity<>(
envsClustersTenantsControllerService.addNewCluster(kwClustersModel), HttpStatus.OK);
Expand Down Expand Up @@ -136,13 +144,6 @@ public ResponseEntity<List<Map<String, String>>> getSyncEnv() {
return new ResponseEntity<>(envsClustersTenantsControllerService.getSyncEnvs(), HttpStatus.OK);
}

// @RequestMapping(value = "/getEnvsStatus", method = RequestMethod.GET, produces =
// {MediaType.APPLICATION_JSON_VALUE})
// public ResponseEntity<Map<String, List<EnvModel>>> getEnvsStatus() {
// return new ResponseEntity<>(envsClustersTenantsControllerService.getEnvsStatus(),
// HttpStatus.OK);
// }

@RequestMapping(
value = "/getEnvParams",
method = RequestMethod.GET,
Expand Down Expand Up @@ -181,16 +182,24 @@ public ResponseEntity<List<EnvModel>> getSchemaRegEnvsStatus() {
}

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

@PostMapping(value = "/deleteEnvironmentRequest")
public ResponseEntity<Map<String, String>> deleteEnvironment(
public ResponseEntity<ApiResponse> deleteEnvironment(
@RequestParam("envId") String envId, @RequestParam("envType") String envType) {
return new ResponseEntity<>(
envsClustersTenantsControllerService.deleteEnvironment(envId, envType), HttpStatus.OK);
try {
return new ResponseEntity<>(
envsClustersTenantsControllerService.deleteEnvironment(envId, envType), HttpStatus.OK);
} catch (KlawException e) {
return handleException(e);
}
}

@RequestMapping(
Expand All @@ -212,28 +221,40 @@ public ResponseEntity<List<String>> getExtensionPeriods() {
}

@PostMapping(value = "/addTenantId")
public ResponseEntity<Map<String, String>> addTenantId(
@Valid @RequestBody KwTenantModel kwTenantModel) {
return new ResponseEntity<>(
envsClustersTenantsControllerService.addTenantId(kwTenantModel, true), HttpStatus.OK);
public ResponseEntity<ApiResponse> addTenantId(@Valid @RequestBody KwTenantModel kwTenantModel) {
try {
return new ResponseEntity<>(
envsClustersTenantsControllerService.addTenantId(kwTenantModel, true), HttpStatus.OK);
} catch (KlawException e) {
return handleException(e);
}
}

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

// Pattern a-zA-z and/or spaces.
@PostMapping(value = "/udpateTenant")
public ResponseEntity<Map<String, String>> udpateTenant(
public ResponseEntity<ApiResponse> udpateTenant(
@RequestParam("orgName") @Pattern(message = "Invalid Organization.", regexp = "^[a-zA-z ]*$")
String orgName) {
return new ResponseEntity<>(
envsClustersTenantsControllerService.updateTenant(orgName), HttpStatus.OK);
try {
return new ResponseEntity<>(
envsClustersTenantsControllerService.updateTenant(orgName), HttpStatus.OK);
} catch (KlawException e) {
return handleException(e);
}
}

@PostMapping(value = "/udpateTenantExtension")
public ResponseEntity<Map<String, String>> udpateTenantExtension(
public ResponseEntity<ApiResponse> udpateTenantExtension(
@RequestParam("selectedTenantExtensionPeriod") String selectedTenantExtensionPeriod) {
return new ResponseEntity<>(
envsClustersTenantsControllerService.udpateTenantExtension(selectedTenantExtensionPeriod),
Expand Down
Loading