From fc81493c03b641734233769245f2175325c12e1e Mon Sep 17 00:00:00 2001 From: Sadaf-A Date: Fri, 4 Aug 2023 21:56:06 +0530 Subject: [PATCH 1/2] adding RequestOperationType as an arguement for uploadSchema method --- .../controller/SchemaRegistryController.java | 3 ++- .../service/SchemaRegistryControllerService.java | 9 ++++++--- .../controller/SchemaRegistryControllerTest.java | 2 +- .../SchemaRegistryControllerServiceTest.java | 16 +++++++++++----- 4 files changed, 20 insertions(+), 10 deletions(-) diff --git a/core/src/main/java/io/aiven/klaw/controller/SchemaRegistryController.java b/core/src/main/java/io/aiven/klaw/controller/SchemaRegistryController.java index 6aff368a55..70d39fef1b 100644 --- a/core/src/main/java/io/aiven/klaw/controller/SchemaRegistryController.java +++ b/core/src/main/java/io/aiven/klaw/controller/SchemaRegistryController.java @@ -165,7 +165,8 @@ public ResponseEntity execSchemaRequestsDecline( public ResponseEntity uploadSchema( @Valid @RequestBody SchemaRequestModel addSchemaRequest) throws KlawException { return new ResponseEntity<>( - schemaRegistryControllerService.uploadSchema(addSchemaRequest), HttpStatus.OK); + schemaRegistryControllerService.uploadSchema(addSchemaRequest, RequestOperationType.CREATE), + HttpStatus.OK); } @PostMapping( diff --git a/core/src/main/java/io/aiven/klaw/service/SchemaRegistryControllerService.java b/core/src/main/java/io/aiven/klaw/service/SchemaRegistryControllerService.java index 9f0484b75d..061dc03862 100644 --- a/core/src/main/java/io/aiven/klaw/service/SchemaRegistryControllerService.java +++ b/core/src/main/java/io/aiven/klaw/service/SchemaRegistryControllerService.java @@ -440,7 +440,8 @@ public ApiResponse promoteSchema(SchemaPromotion schemaPromotion) throws Excepti schemaObjects.get(Integer.valueOf(schemaPromotion.getSchemaVersion())); // Pretty Print the Json String so that it can be seen clearly in the UI. schemaRequest.setSchemafull(prettyPrintUglyJsonString((String) schemaObject.get("schema"))); - return uploadSchema(schemaRequest); + // sending request operation type along with function call + return uploadSchema(schemaRequest, RequestOperationType.PROMOTE); } private boolean userAndTopicOwnerAreOnTheSameTeam( @@ -491,7 +492,9 @@ private SchemaRequestModel buildSchemaRequestFromPromotionRequest( return schemaRequest; } - public ApiResponse uploadSchema(SchemaRequestModel schemaRequest) throws KlawException { + public ApiResponse uploadSchema( + SchemaRequestModel schemaRequest, RequestOperationType requestOperationType) + throws KlawException { log.info("uploadSchema {}", schemaRequest); String userName = getUserName(); @@ -560,7 +563,7 @@ public ApiResponse uploadSchema(SchemaRequestModel schemaRequest) throws KlawExc schemaRequest.setRequestor(userName); SchemaRequest schemaRequestDao = new SchemaRequest(); copyProperties(schemaRequest, schemaRequestDao); - schemaRequestDao.setRequestOperationType(RequestOperationType.CREATE.value); + schemaRequestDao.setRequestOperationType(requestOperationType.value); HandleDbRequests dbHandle = manageDatabase.getHandleDbRequests(); schemaRequestDao.setTenantId(tenantId); try { diff --git a/core/src/test/java/io/aiven/klaw/controller/SchemaRegistryControllerTest.java b/core/src/test/java/io/aiven/klaw/controller/SchemaRegistryControllerTest.java index 8658986df8..6e54b9f840 100644 --- a/core/src/test/java/io/aiven/klaw/controller/SchemaRegistryControllerTest.java +++ b/core/src/test/java/io/aiven/klaw/controller/SchemaRegistryControllerTest.java @@ -118,7 +118,7 @@ public void uploadSchema() throws Exception { SchemaRequestModel schemaRequest = utilMethods.getSchemaRequests().get(0); String jsonReq = OBJECT_MAPPER.writer().writeValueAsString(schemaRequest); ApiResponse apiResponse = ApiResponse.builder().message(ApiResultStatus.SUCCESS.value).build(); - when(schemaRegistryControllerService.uploadSchema(any())).thenReturn(apiResponse); + when(schemaRegistryControllerService.uploadSchema(any(), any())).thenReturn(apiResponse); mvc.perform( MockMvcRequestBuilders.post("/uploadSchema") diff --git a/core/src/test/java/io/aiven/klaw/service/SchemaRegistryControllerServiceTest.java b/core/src/test/java/io/aiven/klaw/service/SchemaRegistryControllerServiceTest.java index 3b8cb8dd3b..b51430c2a7 100644 --- a/core/src/test/java/io/aiven/klaw/service/SchemaRegistryControllerServiceTest.java +++ b/core/src/test/java/io/aiven/klaw/service/SchemaRegistryControllerServiceTest.java @@ -27,6 +27,7 @@ import io.aiven.klaw.model.enums.ApiResultStatus; import io.aiven.klaw.model.enums.KafkaClustersType; import io.aiven.klaw.model.enums.PermissionType; +import io.aiven.klaw.model.enums.RequestOperationType; import io.aiven.klaw.model.enums.RequestStatus; import io.aiven.klaw.model.requests.SchemaPromotion; import io.aiven.klaw.model.requests.SchemaRequestModel; @@ -312,7 +313,8 @@ public void uploadSchemaSuccess() throws KlawException { .thenReturn(List.of(topic)); when(commonUtilsService.getFilteredTopicsForTenant(any())).thenReturn(List.of(topic)); - ApiResponse resultResp = schemaRegistryControllerService.uploadSchema(schemaRequest); + ApiResponse resultResp = + schemaRegistryControllerService.uploadSchema(schemaRequest, RequestOperationType.CREATE); assertThat(resultResp.isSuccess()).isTrue(); } @@ -336,7 +338,7 @@ public void uploadSchemaFailure() throws KlawException { .thenReturn(buildValidationResponse(true)); try { - schemaRegistryControllerService.uploadSchema(schemaRequest); + schemaRegistryControllerService.uploadSchema(schemaRequest, RequestOperationType.CREATE); } catch (KlawException e) { assertThat(e.getMessage()).contains("Error from schema upload"); } @@ -505,7 +507,8 @@ public void uploadSchemaIncompatibleSchemaError() throws KlawException { when(commonUtilsService.getTenantId(anyString())).thenReturn(101); when(commonUtilsService.isNotAuthorizedUser(any(), any())).thenReturn(false); - ApiResponse resultResp = schemaRegistryControllerService.uploadSchema(schemaRequest); + ApiResponse resultResp = + schemaRegistryControllerService.uploadSchema(schemaRequest, RequestOperationType.CREATE); assertThat(resultResp.getMessage()).isEqualTo(VALIDATION_FAILURE_MSG); verify(clusterApiService, times(1)) .validateSchema(anyString(), anyString(), anyString(), anyInt()); @@ -610,7 +613,8 @@ public void uploadSchema_NoValidationOnSave() throws KlawException { .thenReturn(List.of(topic)); when(commonUtilsService.getFilteredTopicsForTenant(any())).thenReturn(List.of(topic)); - ApiResponse resultResp = schemaRegistryControllerService.uploadSchema(schemaRequest); + ApiResponse resultResp = + schemaRegistryControllerService.uploadSchema(schemaRequest, RequestOperationType.CREATE); assertThat(resultResp.getMessage()).isEqualTo(ApiResultStatus.SUCCESS.value); verify(clusterApiService, times(0)) @@ -637,7 +641,9 @@ public void uploadSchema_ValidationPropertyNotSet() throws KlawException { NullPointerException ex = assertThrows( NullPointerException.class, - () -> schemaRegistryControllerService.uploadSchema(schemaRequest)); + () -> + schemaRegistryControllerService.uploadSchema( + schemaRequest, RequestOperationType.CREATE)); assertThat(ex.getMessage()) .contains("Cannot invoke \"java.lang.Boolean.booleanValue()\"") .contains("validateCompatiblityOnSave\" is null"); From 83187dcb70b5e18a3a1fbf24aeca0416f264fa30 Mon Sep 17 00:00:00 2001 From: Sadaf-A Date: Tue, 8 Aug 2023 03:47:08 +0530 Subject: [PATCH 2/2] fix: updating schema html files --- .../main/resources/templates/execSchemas.html | 18 ++++++------------ .../resources/templates/mySchemaRequests.html | 18 +++++------------- 2 files changed, 11 insertions(+), 25 deletions(-) diff --git a/core/src/main/resources/templates/execSchemas.html b/core/src/main/resources/templates/execSchemas.html index 39e3db87d3..607c49ee2f 100644 --- a/core/src/main/resources/templates/execSchemas.html +++ b/core/src/main/resources/templates/execSchemas.html @@ -555,18 +555,12 @@
Status
{{ schemaRequest.requestStatus }} -
-
Request Type
- {{ schemaRequest.requestOperationType }} Schema -
-
-
Request Type
- {{ schemaRequest.requestOperationType }} Schema -
-
-
Request Type
- {{ schemaRequest.requestOperationType }} Schema -
+ +
+
Request Type
+ {{ schemaRequest.requestOperationType }} Schema +
+
Date Requested
{{ schemaRequest.requesttimestring }} diff --git a/core/src/main/resources/templates/mySchemaRequests.html b/core/src/main/resources/templates/mySchemaRequests.html index d47e745a83..9bcff2e268 100644 --- a/core/src/main/resources/templates/mySchemaRequests.html +++ b/core/src/main/resources/templates/mySchemaRequests.html @@ -532,19 +532,11 @@
Status
Status
{{ schemaRequest.requestStatus }}
- -
-
Request Type
- {{ schemaRequest.requestOperationType }} Schema -
-
-
Request Type
- {{ schemaRequest.requestOperationType }} Schema -
-
-
Request Type
- {{ schemaRequest.requestOperationType }} Schema -
+ +
+
Request Type
+ {{ schemaRequest.requestOperationType }} Schema +
Date Requested
{{ schemaRequest.requesttimestring }}