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

refactored code #9

Merged
merged 1 commit into from
Mar 29, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
24 changes: 13 additions & 11 deletions src/main/java/iudx/rs/proxy/apiserver/ApiServerVerticle.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@
import static iudx.rs.proxy.common.ResponseUrn.BACKING_SERVICE_FORMAT_URN;
import static iudx.rs.proxy.common.ResponseUrn.INVALID_PARAM_URN;
import static iudx.rs.proxy.common.ResponseUrn.INVALID_TEMPORAL_PARAM_URN;

import java.util.List;
import java.util.Map;
import java.util.Optional;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import io.netty.handler.codec.http.HttpConstants;
import io.netty.handler.codec.http.QueryStringDecoder;
import io.vertx.core.AbstractVerticle;
Expand All @@ -41,6 +45,7 @@
import io.vertx.ext.web.RoutingContext;
import io.vertx.ext.web.handler.BodyHandler;
import io.vertx.ext.web.handler.CorsHandler;
import io.vertx.serviceproxy.ServiceException;
import iudx.rs.proxy.apiserver.exceptions.DxRuntimeException;
import iudx.rs.proxy.apiserver.handlers.AuthHandler;
import iudx.rs.proxy.apiserver.handlers.FailureHandler;
Expand All @@ -54,11 +59,6 @@
import iudx.rs.proxy.common.ResponseUrn;
import iudx.rs.proxy.database.DatabaseService;
import iudx.rs.proxy.metering.MeteringService;
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 ApiServerVerticle extends AbstractVerticle {

Expand Down Expand Up @@ -282,6 +282,7 @@ private void executeSearchQuery(
handleSuccessResponse(response, ResponseType.Ok.getCode(), handler.result().toString());
} else if (handler.failed()) {
LOGGER.error("Fail: Search Fail");
LOGGER.debug(handler instanceof ServiceException);
processBackendResponse(response, handler.cause().getMessage());
}
});
Expand Down Expand Up @@ -345,9 +346,10 @@ private void processBackendResponse(HttpServerResponse response, String failureM
LOGGER.debug("Info : " + failureMessage);
try {
JsonObject json = new JsonObject(failureMessage);
int type = json.getInteger(JSON_TYPE);
HttpStatusCode status = HttpStatusCode.getByValue(type);
String urnTitle = json.getString(JSON_TITLE);
String type = json.getString(JSON_TYPE);
int status=json.getInteger("status");
HttpStatusCode httpStatus = HttpStatusCode.getByValue(status);
String urnTitle = type;
ResponseUrn urn;
if (urnTitle != null) {
urn = ResponseUrn.fromCode(urnTitle);
Expand All @@ -357,8 +359,8 @@ private void processBackendResponse(HttpServerResponse response, String failureM
// return urn in body
response
.putHeader(CONTENT_TYPE, APPLICATION_JSON)
.setStatusCode(type)
.end(generateResponse(status, urn).toString());
.setStatusCode(status)
.end(generateResponse(httpStatus, urn).toString());
} catch (DecodeException ex) {
LOGGER.error("ERROR : Expecting Json from backend service [ jsonFormattingException ]");
handleResponse(response, HttpStatusCode.BAD_REQUEST, BACKING_SERVICE_FORMAT_URN);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package iudx.rs.proxy.authenticator;

import static iudx.rs.proxy.common.Constants.CACHE_SERVICE_ADDRESS;
import static iudx.rs.proxy.common.Constants.*;

import io.vertx.core.AbstractVerticle;
import io.vertx.core.Future;
Expand All @@ -23,15 +23,15 @@
*
* <h1>Authentication Verticle</h1>
*
* <p>The Authentication Verticle implementation in the the IUDX Resource Server exposes the {@link
* iudx.rs.proxy.authenticator.AuthenticationService} over the Vert.x Event Bus.
* <p>
* The Authentication Verticle implementation in the the IUDX Resource Server exposes the
* {@link iudx.rs.proxy.authenticator.AuthenticationService} over the Vert.x Event Bus.
*
* @version 1.0
* @since 2020-05-31
*/
public class AuthenticationVerticle extends AbstractVerticle {

private static final String AUTH_SERVICE_ADDRESS = "iudx.rs.proxy.auth.service";
private static final Logger LOGGER = LogManager.getLogger(AuthenticationVerticle.class);
private AuthenticationService jwtAuthenticationService;
private ServiceBinder binder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ public class Constants {
public static final String SEARCH_TYPE = "searchType";
public static final String TIME_REL = "timerel";
public static final String TIME = "time";
public static final String END_TIME = "endTime";
public static final String END_TIME = "endtime";
public static final String ATTRS = "attrs";
public static final String BEFORE = "before";
public static final String AFTER = "after";
public static final String ATTR_QUERY = "attr_query";
public static final String ATTR_QUERY = "attr-query";
public static final String ATTRIBUTE = "attribute";
public static final String OPERATOR = "operator";
public static final String VALUE = "value";
Expand All @@ -31,7 +31,7 @@ public class Constants {
// SQL
public static String PSQL_TABLE_EXISTS_QUERY =
"SELECT EXISTS ( SELECT FROM pg_tables WHERE schemaname='public' AND tablename='$1');";
public static String PSQL_SELECT_QUERY = "SELECT $1 FROM $$";
public static String PSQL_TEMPORAL_CONDITION = " WHERE time BETWEEN '$2' and '$3'";
public static String PSQL_SELECT_QUERY = "SELECT $1 FROM $$ WHERE id='$2'";
public static String PSQL_TEMPORAL_CONDITION = "observationdatetime BETWEEN '$2' and '$3'";
public static String PSQL_ATTR_CONDITION = "$4 $op $5";
}
Loading