Skip to content

Commit

Permalink
Refactor: resolve checkstyle issues
Browse files Browse the repository at this point in the history
  • Loading branch information
shreelakshmijoshi committed Nov 13, 2024
1 parent 9b1f4f9 commit 732929f
Show file tree
Hide file tree
Showing 29 changed files with 155 additions and 175 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import iudx.data.marketplace.apiserver.handlers.AuthHandler;
import iudx.data.marketplace.apiserver.handlers.ExceptionHandler;
import iudx.data.marketplace.apiserver.handlers.ValidationHandler;
import iudx.data.marketplace.apiserver.provider.linkedAccount.LinkedAccountService;
import iudx.data.marketplace.apiserver.provider.linkedaccount.LinkedAccountService;
import iudx.data.marketplace.apiserver.util.RequestType;
import iudx.data.marketplace.authenticator.AuthClient;
import iudx.data.marketplace.authenticator.AuthenticationService;
Expand Down Expand Up @@ -95,7 +95,6 @@ public void start() throws Exception {
webClientOptions.setTrustAll(false).setVerifyHost(true).setSsl(true);
webClient = WebClient.create(vertx, webClientOptions);

Api api = Api.getInstance(config().getString("dxApiBasePath"));

/* Initialize service proxy */
policyService = PolicyService.createProxy(vertx, POLICY_SERVICE_ADDRESS);
Expand Down Expand Up @@ -163,6 +162,7 @@ public void start() throws Exception {
serverOptions.setCompressionSupported(true).setCompressionLevel(5);
server = vertx.createHttpServer(serverOptions);
server.requestHandler(router).listen(port);
Api api = Api.getInstance(config().getString("dxApiBasePath"));

router
.route(PROVIDER_PATH + "/*")
Expand Down Expand Up @@ -533,9 +533,6 @@ private void handleSuccessResponse(HttpServerResponse response, int statusCode,
response.putHeader(CONTENT_TYPE, APPLICATION_JSON).setStatusCode(statusCode).end(result);
}

private void handleResponse(HttpServerResponse response, int statusCode, String result) {
response.putHeader(CONTENT_TYPE, APPLICATION_JSON).setStatusCode(statusCode).end(result);
}

/**
* Handles Failed HTTP Response
Expand Down Expand Up @@ -582,6 +579,10 @@ private void handleFailureResponse(RoutingContext routingContext, String failure
}
}

private void handleResponse(HttpServerResponse response, int statusCode, String result) {
response.putHeader(CONTENT_TYPE, APPLICATION_JSON).setStatusCode(statusCode).end(result);
}

private void handleResponse(
HttpServerResponse response, HttpStatusCode statusCode, ResponseUrn urn) {
handleResponse(response, statusCode, urn, statusCode.getDescription());
Expand Down
27 changes: 16 additions & 11 deletions src/main/java/iudx/data/marketplace/apiserver/ConsumerApis.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,7 @@ Router init() {

ValidationHandler resourceValidationHandler = new ValidationHandler(RequestType.RESOURCE);
ValidationHandler providerValidationHandler = new ValidationHandler(RequestType.PROVIDER);
ValidationHandler orderValidationHandler = new ValidationHandler(RequestType.ORDER);
ValidationHandler purchaseValidationHandler = new ValidationHandler(RequestType.PURCHASE);
ExceptionHandler exceptionHandler = new ExceptionHandler();
ValidationHandler productVariantHandler = new ValidationHandler(RequestType.PRODUCT);

consumerService = ConsumerService.createProxy(vertx, CONSUMER_SERVICE_ADDRESS);

Expand All @@ -89,20 +86,26 @@ Router init() {
.handler(this::listProducts)
.failureHandler(exceptionHandler);

ValidationHandler purchaseValidationHandler = new ValidationHandler(RequestType.PURCHASE);

router
.get(api.getConsumerListPurchases())
.handler(purchaseValidationHandler)
.handler(AuthHandler.create(authenticationService, api, postgresService, authClient))
.handler(this::listPurchases)
.failureHandler(exceptionHandler);

ValidationHandler productVariantHandler = new ValidationHandler(RequestType.PRODUCT);

router
.get(api.getConsumerProductVariantPath())
.handler(productVariantHandler)
.handler(AuthHandler.create(authenticationService, api, postgresService, authClient))
.handler(this::listProductVariants)
.failureHandler(exceptionHandler);

ValidationHandler orderValidationHandler = new ValidationHandler(RequestType.ORDER);

router
.post(CONSUMER_PATH + ORDERS_PATH + "/:productVariantId")
.handler(orderValidationHandler)
Expand Down Expand Up @@ -263,14 +266,6 @@ private void listPurchases(RoutingContext routingContext) {
});
}

private void handleFailureResponse(RoutingContext routingContext, Throwable cause) {
routingContext
.response()
.putHeader(CONTENT_TYPE, APPLICATION_JSON)
.setStatusCode(400)
.end(cause.getMessage());
}

private void handleSuccessResponse(
RoutingContext routingContext, int statusCode, JsonObject result) {

Expand All @@ -290,9 +285,19 @@ private void handleSuccessResponse(
.setStatusCode(statusCode)
.end();
break;
default:
break;
}
}

private void handleFailureResponse(RoutingContext routingContext, Throwable cause) {
routingContext
.response()
.putHeader(CONTENT_TYPE, APPLICATION_JSON)
.setStatusCode(400)
.end(cause.getMessage());
}

/**
* Handles Failed HTTP Response
*
Expand Down
15 changes: 7 additions & 8 deletions src/main/java/iudx/data/marketplace/apiserver/ProviderApis.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,6 @@ public class ProviderApis {
Router init() {

ValidationHandler productValidationHandler = new ValidationHandler(RequestType.PRODUCT);
ValidationHandler variantValidationHandler = new ValidationHandler(RequestType.PRODUCT_VARIANT);
ValidationHandler deleteVariantValidationHandler =
new ValidationHandler(RequestType.DELETE_PRODUCT_VARIANT);
ValidationHandler listVariantValidationHandler =
new ValidationHandler(RequestType.LIST_PRODUCT_VARIANT);
ValidationHandler resourceValidationHandler = new ValidationHandler(RequestType.RESOURCE);
ValidationHandler purchaseValidationHandler = new ValidationHandler(RequestType.PURCHASE);
ExceptionHandler exceptionHandler = new ExceptionHandler();

productService = ProductService.createProxy(vertx, PRODUCT_SERVICE_ADDRESS);
Expand All @@ -90,20 +83,23 @@ Router init() {
.handler(AuthHandler.create(authenticationService, api, postgresService, authClient))
.handler(this::handleDeleteProduct)
.failureHandler(exceptionHandler);
ValidationHandler resourceValidationHandler = new ValidationHandler(RequestType.RESOURCE);

router
.get(api.getProviderListProductsPath())
.handler(resourceValidationHandler)
.handler(AuthHandler.create(authenticationService, api, postgresService, authClient))
.handler(this::listProducts)
.failureHandler(exceptionHandler);
ValidationHandler purchaseValidationHandler = new ValidationHandler(RequestType.PURCHASE);

router
.get(api.getProviderListPurchasesPath())
.handler(purchaseValidationHandler)
.handler(AuthHandler.create(authenticationService, api, postgresService, authClient))
.handler(this::listPurchases)
.failureHandler(exceptionHandler);
ValidationHandler variantValidationHandler = new ValidationHandler(RequestType.PRODUCT_VARIANT);

router
.post(api.getProviderProductVariantPath())
Expand All @@ -118,13 +114,16 @@ Router init() {
.handler(AuthHandler.create(authenticationService, api, postgresService, authClient))
.handler(this::handleUpdateProductVariant)
.failureHandler(exceptionHandler);

ValidationHandler listVariantValidationHandler =
new ValidationHandler(RequestType.LIST_PRODUCT_VARIANT);
router
.get(api.getProviderProductVariantPath())
.handler(listVariantValidationHandler)
.handler(AuthHandler.create(authenticationService, api, postgresService, authClient))
.handler(this::handleGetProductVariants)
.failureHandler(exceptionHandler);
ValidationHandler deleteVariantValidationHandler =
new ValidationHandler(RequestType.DELETE_PRODUCT_VARIANT);

router
.delete(api.getProviderProductVariantPath())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package iudx.data.marketplace.apiserver.provider.linkedAccount;
package iudx.data.marketplace.apiserver.provider.linkedaccount;

import static iudx.data.marketplace.apiserver.provider.linkedAccount.util.Constants.*;
import static iudx.data.marketplace.apiserver.provider.linkedaccount.util.Constants.*;
import static iudx.data.marketplace.apiserver.util.Constants.*;

import com.google.common.hash.Hashing;
Expand Down Expand Up @@ -130,7 +130,6 @@ private Future<Boolean> createLinkedAccount(JsonObject merchantDetails) {
*/
public JsonObject getLinkedAccountDetails(
JsonObject request, String referenceId, String emailId) {
String businessType = request.getString("businessType");
String category = request.getJsonObject("profile").getString("category");
String subcategory = request.getJsonObject("profile").getString("subcategory");
JsonObject registered =
Expand All @@ -141,7 +140,6 @@ public JsonObject getLinkedAccountDetails(
String state = registered.getString("state");
String postalCode = registered.getString("postalCode");
String country = registered.getString("country");
String contactName = request.getString("contactName");

JsonObject registeredJson =
new JsonObject()
Expand All @@ -153,11 +151,7 @@ public JsonObject getLinkedAccountDetails(
.put("country", country);

JsonObject addressJson = new JsonObject().put("registered", registeredJson);
JsonObject profileJson =
new JsonObject()
.put("category", category)
.put("subcategory", subcategory)
.put("addresses", addressJson);


JsonObject legalInfoJson = new JsonObject();
/* checks if optional field legal info is null */
Expand All @@ -173,32 +167,27 @@ public JsonObject getLinkedAccountDetails(
}
String phoneNumber = request.getString("phone");
String legalBusinessName = request.getString("legalBusinessName");
String customerFacingBusinessName = request.getString("customerFacingBusinessName");
String businessType = request.getString("businessType");
JsonObject profileJson = new JsonObject().put("category", category)
.put("subcategory", subcategory).put("addresses", addressJson);
JsonObject details = new JsonObject().put("email", emailId).put("phone", phoneNumber)
.put("legal_business_name", legalBusinessName).put("type", ACCOUNT_TYPE).put("reference_id", referenceId)
.put("business_type", businessType).put("profile", profileJson).put("legal_info", legalInfoJson);

setLegalBusinessName(legalBusinessName);
setEmailId(emailId);
setPhoneNumber(phoneNumber);
setBusinessType(businessType);

JsonObject details =
new JsonObject()
.put("email", emailId)
.put("phone", phoneNumber)
.put("legal_business_name", legalBusinessName)
.put("type", ACCOUNT_TYPE)
.put("reference_id", referenceId)
.put("business_type", businessType)
.put("profile", profileJson)
.put("legal_info", legalInfoJson);

setCustomerFacingBusinessName(legalBusinessName);
/* customer facing business name is not a necessary field in the request body
* while inserting in the DB, if customer facing business name is null, it is
* replaced with the legal business name */
String customerFacingBusinessName = request.getString("customerFacingBusinessName");
if (StringUtils.isNotBlank(customerFacingBusinessName)) {
setCustomerFacingBusinessName(customerFacingBusinessName);
details.put("customer_facing_business_name", customerFacingBusinessName);
}
String contactName = request.getString("contactName");
if (StringUtils.isNotBlank(contactName)) {
details.put("contact_name", contactName);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package iudx.data.marketplace.apiserver.provider.linkedAccount;
package iudx.data.marketplace.apiserver.provider.linkedaccount;

import static iudx.data.marketplace.apiserver.provider.linkedAccount.util.Constants.*;
import static iudx.data.marketplace.apiserver.provider.linkedaccount.util.Constants.*;
import static iudx.data.marketplace.apiserver.util.Constants.RESULTS;

import io.vertx.core.Future;
Expand Down Expand Up @@ -53,11 +53,9 @@ public Future<JsonObject> initiateFetchingLinkedAccount(User provider) {

public Future<JsonObject> generateSuccessResponse(JsonObject rzpResponseJson) {
String emailId = rzpResponseJson.getString("email");
String accountId = rzpResponseJson.getString("id");
String type = rzpResponseJson.getString("type");
String status = rzpResponseJson.getString("status");
String referenceId = rzpResponseJson.getString("reference_id");
String businessType = rzpResponseJson.getString("business_type");
String category = rzpResponseJson.getJsonObject("profile").getString("category");
String subcategory = rzpResponseJson.getJsonObject("profile").getString("subcategory");
JsonObject registered =
Expand Down Expand Up @@ -102,12 +100,8 @@ public Future<JsonObject> generateSuccessResponse(JsonObject rzpResponseJson) {
}
}
String phoneNumber = rzpResponseJson.getString("phone");
String legalBusinessName = rzpResponseJson.getString("legal_business_name");
String customerFacingBusinessName = rzpResponseJson.getString("customer_facing_business_name");

JsonObject details =
new JsonObject()
.put("accountId", accountId)
String accountId = rzpResponseJson.getString("id");
JsonObject details = new JsonObject().put("accountId", accountId)
.put("type", type)
.put("status", status)
.put("email", emailId)
Expand All @@ -117,9 +111,16 @@ public Future<JsonObject> generateSuccessResponse(JsonObject rzpResponseJson) {
if (StringUtils.isNotBlank(contactName)) {
details.put("contactName", contactName);
}

String businessType = rzpResponseJson.getString("business_type");
String legalBusinessName = rzpResponseJson.getString("legal_business_name");

details.put("referenceId", referenceId);
details.put("businessType", businessType);
details.put("legalBusinessName", legalBusinessName);

String customerFacingBusinessName = rzpResponseJson.getString("customer_facing_business_name");

if (StringUtils.isNotBlank(customerFacingBusinessName)) {
details.put("customerFacingBusinessName", customerFacingBusinessName);
}
Expand Down Expand Up @@ -148,13 +149,13 @@ Future<JsonObject> getAccountId(String query, User provider) {
if (handler.succeeded()) {
if (!handler.result().getJsonArray(RESULTS).isEmpty()) {
JsonObject result = handler.result().getJsonArray(RESULTS).getJsonObject(0);
String accountId = result.getString("account_id");
String accountProductId = result.getString("rzp_account_product_id");
String updatedAt = result.getString("updatedAt");
String createdAt = result.getString("createdAt");
setRazorpayAccountProductId(accountProductId);
setUpdatedAt(updatedAt);
setCreatedAt(createdAt);
String accountId = result.getString("account_id");
promise.complete(new JsonObject().put("accountId", accountId));
} else {
promise.fail(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package iudx.data.marketplace.apiserver.provider.linkedAccount;
package iudx.data.marketplace.apiserver.provider.linkedaccount;

import io.vertx.codegen.annotations.GenIgnore;
import io.vertx.codegen.annotations.ProxyGen;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package iudx.data.marketplace.apiserver.provider.linkedAccount;
package iudx.data.marketplace.apiserver.provider.linkedaccount;

import io.vertx.core.Future;
import io.vertx.core.Promise;
import io.vertx.core.json.JsonObject;
import iudx.data.marketplace.policies.User;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class LinkedAccountServiceImpl implements LinkedAccountService {
// private static final Logger LOG = LoggerFactory.getLogger(LinkedAccountServiceImpl.class);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package iudx.data.marketplace.apiserver.provider.linkedAccount;
package iudx.data.marketplace.apiserver.provider.linkedaccount;

import static iudx.data.marketplace.common.Constants.*;

Expand All @@ -9,8 +9,6 @@
import iudx.data.marketplace.common.Api;
import iudx.data.marketplace.postgres.PostgresService;
import iudx.data.marketplace.razorpay.RazorPayService;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

public class LinkedAccountVerticle extends AbstractVerticle {
// private static final Logger LOGGER = LogManager.getLogger(LinkedAccountVerticle.class);
Expand Down
Loading

0 comments on commit 732929f

Please sign in to comment.