Skip to content

Commit

Permalink
Merge pull request #99 from ankitmashu/pmdandcheckstyle
Browse files Browse the repository at this point in the history
PMD changes
  • Loading branch information
kailash authored May 3, 2023
2 parents 130f808 + c06ef2b commit 0ceadad
Show file tree
Hide file tree
Showing 54 changed files with 728 additions and 715 deletions.
16 changes: 14 additions & 2 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,20 @@ pipeline {
}
post{
always {
recordIssues enabledForFailure: true, tool: checkStyle(pattern: 'target/checkstyle-result.xml')
recordIssues enabledForFailure: true, tool: pmdParser(pattern: 'target/pmd.xml')
recordIssues(
enabledForFailure: true,
blameDisabled: true,
forensicsDisabled: true,
qualityGates: [[threshold:0, type: 'TOTAL', unstable: false]],
tool: checkStyle(pattern: 'target/checkstyle-result.xml')
)
recordIssues(
enabledForFailure: true,
blameDisabled: true,
forensicsDisabled: true,
qualityGates: [[threshold:0, type: 'TOTAL', unstable: false]],
tool: pmdParser(pattern: 'target/pmd.xml')
)
}
failure{
script{
Expand Down
236 changes: 103 additions & 133 deletions src/main/java/iudx/gis/server/apiserver/ApiServerVerticle.java

Large diffs are not rendered by default.

16 changes: 10 additions & 6 deletions src/main/java/iudx/gis/server/apiserver/handlers/AuthHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,16 @@ public class AuthHandler implements Handler<RoutingContext> {
private static final String AUTH_SERVICE_ADDRESS = "iudx.gis.authentication.service";
private static final Logger LOGGER = LogManager.getLogger(AuthHandler.class);
static AuthenticationService authenticator;
private HttpServerRequest request;
private static String dxApiBasePath;
private static String adminBasePath;
private static Api api;
private HttpServerRequest request;

public static AuthHandler create(Vertx vertx, JsonObject config) {
authenticator = AuthenticationService.createProxy(vertx, AUTH_SERVICE_ADDRESS);
dxApiBasePath = config.getString("dxApiBasePath");
adminBasePath = config.getString("adminBasePath");
api = Api.getInstance(dxApiBasePath,adminBasePath);
api = Api.getInstance(dxApiBasePath, adminBasePath);
return new AuthHandler();
}

Expand All @@ -50,7 +50,9 @@ public void handle(RoutingContext context) {
final String path = getNormalizedPath(request.path());
final String method = context.request().method().toString();

if (token == null) token = "public";
if (token == null) {
token = "public";
}

String paramId = getId4rmRequest();

Expand Down Expand Up @@ -108,12 +110,14 @@ public void processAuthFailure(RoutingContext ctx, String result) {
public String getNormalizedPath(String url) {
LOGGER.debug("URL : {}", url);
String path = null;
if (url.matches(api.getEntitiesEndpoint())) path = api.getEntitiesEndpoint();
else if (url.matches(api.getAdminPath())) path = api.getAdminPath();
if (url.matches(api.getEntitiesEndpoint())) {
path = api.getEntitiesEndpoint();
} else if (url.matches(api.getAdminPath())) {
path = api.getAdminPath();
}
return path;
}


private String getId4rmRequest() {
return request.getParam(ID);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import static iudx.gis.server.apiserver.util.Constants.MSG_BAD_QUERY;

import io.vertx.core.Handler;
import io.vertx.core.buffer.Buffer;
import io.vertx.core.json.JsonObject;
import io.vertx.ext.web.RoutingContext;
import iudx.gis.server.apiserver.exceptions.DxRuntimeException;
Expand All @@ -31,28 +30,30 @@ public void handle(RoutingContext context) {
LOGGER.error(exception.getUrn().getUrn() + " : " + exception.getMessage());
HttpStatusCode code = HttpStatusCode.getByValue(exception.getStatusCode());

JsonObject response = new RestResponse.Builder()
.withType(exception.getUrn().getUrn())
.withTitle(code.getDescription())
.withMessage(exception.getLocalizedMessage())
.build()
.toJson();
JsonObject response =
new RestResponse.Builder()
.withType(exception.getUrn().getUrn())
.withTitle(code.getDescription())
.withMessage(exception.getLocalizedMessage())
.build()
.toJson();

context.response()
context
.response()
.putHeader(CONTENT_TYPE, APPLICATION_JSON)
.setStatusCode(exception.getStatusCode())
.end(response.toString());
}

if (failure instanceof RuntimeException) {

context.response()
context
.response()
.putHeader(CONTENT_TYPE, APPLICATION_JSON)
.setStatusCode(HttpStatus.SC_BAD_REQUEST)
.end( validationFailureResponse().toString());
.end(validationFailureResponse().toString());
}
context.next();
return;
}

private JsonObject validationFailureResponse() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,19 @@
import iudx.gis.server.apiserver.util.RequestType;
import iudx.gis.server.apiserver.validation.ValidatorsHandlersFactory;
import iudx.gis.server.apiserver.validation.types.Validator;
import org.apache.http.HttpStatus;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

public class ValidationHandler implements Handler<RoutingContext> {

private static final Logger LOGGER = LogManager.getLogger(ValidationHandler.class);
private Vertx vertx;
private RequestType type;


public ValidationHandler(Vertx vertx, RequestType type) {
this.vertx = vertx;
this.type = type;
Expand All @@ -42,10 +40,8 @@ public void handle(RoutingContext context) {

for (Validator validator : Optional.ofNullable(validations).orElse(Collections.emptyList())) {
LOGGER.debug("validator :" + validator.getClass().getName());
validator.isValid();
validator.isValid();
}
context.next();
return;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@
import static iudx.gis.server.database.util.Constants.SERVER_URL;
import static iudx.gis.server.database.util.Constants.TOKEN_URL;
import static iudx.gis.server.database.util.Constants.USERNAME;
import java.util.Optional;

import io.vertx.core.json.JsonObject;
import java.util.Optional;

public class PgsqlQueryBuilder {

Expand All @@ -27,10 +28,12 @@ public static String insertAdminDetailsQuery(JsonObject queryParams) {

Optional<JsonObject> accessInfo = Optional.ofNullable(queryParams.getJsonObject(ACCESS_INFO));

String insertQuery = INSERT_ADMIN_DETAILS_QUERY.replace("$1", resourceId)
.replace("$2", serverUrl)
.replace("$3", serverPort.toString())
.replace("$4", isSecure.toString());
String insertQuery =
INSERT_ADMIN_DETAILS_QUERY
.replace("$1", resourceId)
.replace("$2", serverUrl)
.replace("$3", serverPort.toString())
.replace("$4", isSecure.toString());

if (accessInfo.isPresent() && !accessInfo.get().isEmpty()) {
JsonObject accessObject = accessInfo.get();
Expand All @@ -55,27 +58,28 @@ public static String updateAdminDetailsQuery(JsonObject queryParams) {

Optional<JsonObject> accessInfo = Optional.ofNullable(queryParams.getJsonObject(ACCESS_INFO));

String updateQuery=UPDATE_ADMIN_DETAILS_QUERY.replace("$1", serverUrl)
.replace("$2", serverPort.toString())
.replace("$3", isSecure.toString())
.replace("$6", resourceId);
String updateQuery =
UPDATE_ADMIN_DETAILS_QUERY
.replace("$1", serverUrl)
.replace("$2", serverPort.toString())
.replace("$3", isSecure.toString())
.replace("$6", resourceId);

if (accessInfo.isPresent() && !accessInfo.get().isEmpty()) {
JsonObject accessObject = accessInfo.get();
String username = accessObject.getString(USERNAME);
String password = accessObject.getString(PASSWORD);
String tokenUrl = accessObject.getString(TOKEN_URL);
updateQuery =
updateQuery.replace("$4", username).replace("$5", password).replace("$7", tokenUrl);;
updateQuery.replace("$4", username).replace("$5", password).replace("$7", tokenUrl);
} else {
updateQuery = updateQuery.replace("$4", "").replace("$5", "").replace("$7", "");
}

return updateQuery;
}

public static String deleteAdminDetailsQuery(String resourceId) {
return DELETE_ADMIN_DETAILS_QUERY.replace("$1", resourceId);
}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package iudx.gis.server.apiserver.response;

import java.util.stream.Stream;

public enum ResponseType {
Ok(200, "Ok"),
Expand Down
36 changes: 22 additions & 14 deletions src/main/java/iudx/gis/server/apiserver/response/ResponseUrn.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public enum ResponseUrn {
INVALID_ATTR_PARAM("urn:dx:rs:invalidAttributeParam", "Invalid attribute param"),
INVALID_ATTR_VALUE("urn:dx:rs:invalidAttributeValue", "Invalid attribute value"),
INVALID_OPERATION("urn:dx:rs:invalidOperation", "Invalid operation"),
BAD_REQUEST_URN("urn:dx:rs:badRequest","bad request parameter"),
BAD_REQUEST_URN("urn:dx:rs:badRequest", "bad request parameter"),
UNAUTHORIZED_ENDPOINT("urn:dx:rs:unauthorizedEndpoint", "Access to endpoint is not available"),
UNAUTHORIZED_RESOURCE("urn:dx:rs:unauthorizedResource", "Access to resource is not available"),
EXPIRED_TOKEN("urn:dx:rs:expiredAuthorizationToken", "Token has expired"),
Expand All @@ -17,15 +17,23 @@ public enum ResponseUrn {

RESOURCE_ALREADY_EXISTS("urn:dx:rs:resourceAlreadyExists", "Document of given ID already exists"),

INVALID_PAYLOAD_FORMAT("urn:dx:rs:invalidPayloadFormat", "Invalid json format in post request [schema mismatch]"),
INVALID_PAYLOAD_FORMAT(
"urn:dx:rs:invalidPayloadFormat", "Invalid json format in post request [schema mismatch]"),
RESOURCE_NOT_FOUND("urn:dx:rs:resourceNotFound", "Document of given id does not exist"),
METHOD_NOT_FOUND("urn:dx:rs:MethodNotAllowed", "Method not allowed for given endpoint"),
UNSUPPORTED_MEDIA_TYPE("urn:dx:rs:UnsupportedMediaType", "Requested/Presented media type not supported"),
UNSUPPORTED_MEDIA_TYPE(
"urn:dx:rs:UnsupportedMediaType", "Requested/Presented media type not supported"),

RESPONSE_PAYLOAD_EXCEED("urn:dx:rs:responsePayloadLimitExceeded", "Search operations exceeds the default response payload limit"),
REQUEST_PAYLOAD_EXCEED("urn:dx:rs:requestPayloadLimitExceeded", "Operation exceeds the default request payload limit"),
REQUEST_OFFSET_EXCEED("urn:dx:rs:requestOffsetLimitExceeded", "Operation exceeds the default value of offset"),
REQUEST_LIMIT_EXCEED("urn:dx:rs:requestLimitExceeded", "Operation exceeds the default value of limit"),
RESPONSE_PAYLOAD_EXCEED(
"urn:dx:rs:responsePayloadLimitExceeded",
"Search operations exceeds the default response payload limit"),
REQUEST_PAYLOAD_EXCEED(
"urn:dx:rs:requestPayloadLimitExceeded",
"Operation exceeds the default request payload limit"),
REQUEST_OFFSET_EXCEED(
"urn:dx:rs:requestOffsetLimitExceeded", "Operation exceeds the default value of offset"),
REQUEST_LIMIT_EXCEED(
"urn:dx:rs:requestLimitExceeded", "Operation exceeds the default value of limit"),

BACKING_SERVICE_FORMAT("urn:dx:rs:backend", "format error from backing service [cat,auth etc.]"),

Expand All @@ -39,6 +47,13 @@ public enum ResponseUrn {
this.message = message;
}

public static ResponseUrn fromCode(final String urn) {
return Stream.of(values())
.filter(v -> v.urn.equalsIgnoreCase(urn))
.findAny()
.orElse(YET_NOT_IMPLEMENTED); /* If backend services don't respond with URN */
}

public String getUrn() {
return urn;
}
Expand All @@ -47,13 +62,6 @@ public String getMessage() {
return message;
}

public static ResponseUrn fromCode(final String urn) {
return Stream.of(values())
.filter(v -> v.urn.equalsIgnoreCase(urn))
.findAny()
.orElse(YET_NOT_IMPLEMENTED); /* If backend services don't respond with URN */
}

public String toString() {
return "[" + urn + " : " + message + " ]";
}
Expand Down
Loading

0 comments on commit 0ceadad

Please sign in to comment.