summaryrefslogtreecommitdiffstats
path: root/appc-inbound/appc-design-services/provider/src/main
diff options
context:
space:
mode:
authorJakub Dudycz <jakub.dudycz@nokia.com>2018-02-06 16:22:11 +0100
committerPatrick Brady <pb071s@att.com>2018-02-07 19:30:16 +0000
commit43162d627da7aea95ab3ae92a2264b621f96b2be (patch)
tree2b2c45e397c7fb08d57d02172ad8f6dae76535d8 /appc-inbound/appc-design-services/provider/src/main
parent26444d69bdafd40d4982a895e1dde9df169cbf62 (diff)
DesignServicesImpl sonar fixes
Change-Id: I55159c7b26463965c0d0bee147b4a5f808a6c55a Issue-ID: APPC-571 Signed-off-by: Jakub Dudycz <jakub.dudycz@nokia.com>
Diffstat (limited to 'appc-inbound/appc-design-services/provider/src/main')
-rw-r--r--appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/services/impl/DesignServicesImpl.java144
-rw-r--r--appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/services/impl/RequestValidationException.java8
2 files changed, 88 insertions, 64 deletions
diff --git a/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/services/impl/DesignServicesImpl.java b/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/services/impl/DesignServicesImpl.java
index 0016a52df..eb1594bfa 100644
--- a/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/services/impl/DesignServicesImpl.java
+++ b/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/services/impl/DesignServicesImpl.java
@@ -24,7 +24,14 @@
package org.onap.appc.design.services.impl;
+import com.google.common.util.concurrent.Futures;
import java.util.concurrent.Future;
+import org.onap.appc.design.dbervices.DbResponseProcessor;
+import org.onap.appc.design.dbervices.DesignDBService;
+import org.onap.appc.design.services.util.DesignServiceConstants;
+import org.onap.appc.design.validator.ValidatorService;
+import org.onap.appc.design.xinterface.XInterfaceService;
+import org.onap.appc.design.xinterface.XResponseProcessor;
import org.opendaylight.yang.gen.v1.org.onap.appc.rev170627.DbserviceInput;
import org.opendaylight.yang.gen.v1.org.onap.appc.rev170627.DbserviceOutput;
import org.opendaylight.yang.gen.v1.org.onap.appc.rev170627.DbserviceOutputBuilder;
@@ -39,121 +46,130 @@ import org.opendaylight.yang.gen.v1.org.onap.appc.rev170627.data.DataBuilder;
import org.opendaylight.yang.gen.v1.org.onap.appc.rev170627.status.StatusBuilder;
import org.opendaylight.yangtools.yang.common.RpcResult;
import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
-import org.onap.appc.design.dbervices.DbResponseProcessor;
-import org.onap.appc.design.dbervices.DesignDBService;
-import org.onap.appc.design.services.util.DesignServiceConstants;
-import org.onap.appc.design.validator.ValidatorResponseProcessor;
-import org.onap.appc.design.validator.ValidatorService;
-import org.onap.appc.design.xinterface.XInterfaceService;
-import org.onap.appc.design.xinterface.XResponseProcessor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import com.google.common.util.concurrent.Futures;
-
public class DesignServicesImpl implements DesignServicesService {
private static final Logger log = LoggerFactory.getLogger(DesignServicesImpl.class);
+ private static final String RECEIVED_REQUEST_STR = "Received Request: ";
+ private static final String WITH_PAYLOAD_STR = " with Payload :";
+ private static final String ACTION_STR = " Action : ";
@Override
public Future<RpcResult<DbserviceOutput>> dbservice(DbserviceInput input) {
- log.info("Received Request: " + input.getDesignRequest().getRequestId() + " Action : " +
- input.getDesignRequest().getAction() + " with Payload :" + input.getDesignRequest().getPayload());
-
-
+ log.info(RECEIVED_REQUEST_STR + input.getDesignRequest().getRequestId() + ACTION_STR +
+ input.getDesignRequest().getAction() + WITH_PAYLOAD_STR + input.getDesignRequest().getPayload());
+
DbserviceOutputBuilder outputBuilder = new DbserviceOutputBuilder();
DataBuilder databuilder = new DataBuilder();
- StatusBuilder statusBuilder = new StatusBuilder();
+ StatusBuilder statusBuilder = new StatusBuilder();
- try{
+ try {
DesignDBService dbservices = DesignDBService.initialise();
- DbResponseProcessor responseProcessor = new DbResponseProcessor();
- String response = responseProcessor.parseResponse(dbservices.execute(input.getDesignRequest().getAction(), input.getDesignRequest().getPayload(), input.getDesignRequest().getRequestId()), input.getDesignRequest().getAction());
+ DbResponseProcessor responseProcessor = new DbResponseProcessor();
+ String response = responseProcessor.parseResponse(dbservices
+ .execute(input.getDesignRequest().getAction(), input.getDesignRequest().getPayload(),
+ input.getDesignRequest().getRequestId()), input.getDesignRequest().getAction());
log.info("Response in for Design Service : " + response);
databuilder.setBlock(response);
databuilder.setRequestId(input.getDesignRequest().getRequestId());
statusBuilder.setCode("400");
- statusBuilder.setMessage("success");
- }
- catch(Exception e){
- log.error("Error" + e.getMessage());
- e.printStackTrace();
+ statusBuilder.setMessage("success");
+ } catch (Exception e) {
+ log.error("Error", e);
statusBuilder.setCode("401");
- statusBuilder.setMessage(e.getMessage());
+ statusBuilder.setMessage(e.getMessage());
}
outputBuilder.setData(databuilder.build());
outputBuilder.setStatus(statusBuilder.build());
- RpcResult<DbserviceOutput> result = RpcResultBuilder.<DbserviceOutput>status(true).withResult(outputBuilder.build()).build();
+ RpcResult<DbserviceOutput> result = RpcResultBuilder.<DbserviceOutput>status(true)
+ .withResult(outputBuilder.build()).build();
return Futures.immediateFuture(result);
}
@Override
public Future<RpcResult<XinterfaceserviceOutput>> xinterfaceservice(XinterfaceserviceInput input) {
- log.info("Received Request: " + input.getDesignRequest().getRequestId() + " Action : " +
- input.getDesignRequest().getAction() + " with Payload :" + input.getDesignRequest().getPayload());
+ log.info(RECEIVED_REQUEST_STR + input.getDesignRequest().getRequestId() + ACTION_STR +
+ input.getDesignRequest().getAction() + WITH_PAYLOAD_STR + input.getDesignRequest().getPayload());
XinterfaceserviceOutputBuilder outputBuilder = new XinterfaceserviceOutputBuilder();
DataBuilder databuilder = new DataBuilder();
- StatusBuilder statusBuilder = new StatusBuilder();
+ StatusBuilder statusBuilder = new StatusBuilder();
try {
- XInterfaceService xInterfaceService = new XInterfaceService();
- XResponseProcessor responseProcessor = new XResponseProcessor();
- String response = responseProcessor.parseResponse(xInterfaceService.execute(input.getDesignRequest().getAction(), input.getDesignRequest().getPayload()), input.getDesignRequest().getAction());
+ XInterfaceService xInterfaceService = new XInterfaceService();
+ XResponseProcessor responseProcessor = new XResponseProcessor();
+ String response = responseProcessor.parseResponse(
+ xInterfaceService.execute(input.getDesignRequest().getAction(), input.getDesignRequest().getPayload()),
+ input.getDesignRequest().getAction());
databuilder.setBlock(response);
databuilder.setRequestId(input.getDesignRequest().getRequestId());
statusBuilder.setCode("400");
- statusBuilder.setMessage("success");
+ statusBuilder.setMessage("success");
} catch (Exception e) {
- e.printStackTrace();
+ log.error("An error occurred in xInterfaceService", e);
statusBuilder.setCode("401");
- statusBuilder.setMessage(e.getMessage());
- }
+ statusBuilder.setMessage(e.getMessage());
+ }
outputBuilder.setData(databuilder.build());
outputBuilder.setStatus(statusBuilder.build());
- RpcResult<XinterfaceserviceOutput> result = RpcResultBuilder.<XinterfaceserviceOutput>status(true).withResult(outputBuilder.build()).build();
+ RpcResult<XinterfaceserviceOutput> result = RpcResultBuilder.<XinterfaceserviceOutput>status(true)
+ .withResult(outputBuilder.build()).build();
return Futures.immediateFuture(result);
}
@Override
public Future<RpcResult<ValidatorOutput>> validator(ValidatorInput input) {
- log.info("Received Request: " + input.getDesignRequest().getRequestId() + " Action : " +
- input.getDesignRequest().getAction() + " with Payload :" + input.getDesignRequest().getPayload() + " and Data Type = " + input.getDesignRequest().getDataType());
+ log.info(RECEIVED_REQUEST_STR + input.getDesignRequest().getRequestId() + ACTION_STR +
+ input.getDesignRequest().getAction() + WITH_PAYLOAD_STR + input.getDesignRequest().getPayload()
+ + " and Data Type = " + input.getDesignRequest().getDataType());
ValidatorOutputBuilder outputBuilder = new ValidatorOutputBuilder();
- StatusBuilder statusBuilder = new StatusBuilder();
-
-
+ StatusBuilder statusBuilder = new StatusBuilder();
+
+ build(input, statusBuilder);
+
+ outputBuilder.setStatus(statusBuilder.build());
+
+ RpcResult<ValidatorOutput> result = RpcResultBuilder.<ValidatorOutput>status(true)
+ .withResult(outputBuilder.build()).build();
+ return Futures.immediateFuture(result);
+ }
+
+ private void build(ValidatorInput input, StatusBuilder statusBuilder) {
try {
- if(input.getDesignRequest().getDataType() == null || input.getDesignRequest().getDataType().isEmpty())
- throw new Exception ("Data Type required for validate Serivce");
- if(input.getDesignRequest().getAction()== null || input.getDesignRequest().getAction().isEmpty())
- throw new Exception ("Action required for validate Serivce");
-
-
- if(! input.getDesignRequest().getDataType().equals(DesignServiceConstants.DATA_TYPE_JSON) &&
- ! input.getDesignRequest().getDataType().equals(DesignServiceConstants.DATA_TYPE_YAML) &&
- ! input.getDesignRequest().getDataType().equals(DesignServiceConstants.DATA_TYPE_XML) &&
- ! input.getDesignRequest().getDataType().equals(DesignServiceConstants.DATA_TYPE_VELOCITY))
- throw new Exception ("Request Data format " + input.getDesignRequest().getDataType()
- + " is not supported by validate Service : Supported data types are : XML, YAML, VELOCITY, JSON ");
-
- ValidatorService validatorService = new ValidatorService();
- ValidatorResponseProcessor responseProcessor = new ValidatorResponseProcessor();
- String response = validatorService.execute(input.getDesignRequest().getAction(), input.getDesignRequest().getPayload(), input.getDesignRequest().getDataType());
+ if (input.getDesignRequest().getDataType() == null || input.getDesignRequest().getDataType().isEmpty()) {
+ throw new RequestValidationException("Data Type required for validate Serivce");
+ }
+ if (input.getDesignRequest().getAction() == null || input.getDesignRequest().getAction().isEmpty()) {
+ throw new RequestValidationException("Action required for validate Serivce");
+ }
+
+ if (validateInput(input)) {
+ throw new RequestValidationException("Request Data format " + input.getDesignRequest().getDataType()
+ + " is not supported by validate Service : Supported data types are : XML, YAML, VELOCITY, JSON ");
+ }
+
+ ValidatorService validatorService = new ValidatorService();
+ String response = validatorService
+ .execute(input.getDesignRequest().getAction(), input.getDesignRequest().getPayload(),
+ input.getDesignRequest().getDataType());
statusBuilder.setCode("400");
- statusBuilder.setMessage(response);
+ statusBuilder.setMessage(response);
} catch (Exception e) {
- e.printStackTrace();
+ log.error("An error occurred in validator", e);
statusBuilder.setCode("401");
- statusBuilder.setMessage(e.getMessage());
- }
-
- outputBuilder.setStatus(statusBuilder.build());
+ statusBuilder.setMessage(e.getMessage());
+ }
+ }
- RpcResult<ValidatorOutput> result = RpcResultBuilder.<ValidatorOutput>status(true).withResult(outputBuilder.build()).build();
- return Futures.immediateFuture(result);
+ private boolean validateInput(ValidatorInput input) {
+ return !input.getDesignRequest().getDataType().equals(DesignServiceConstants.DATA_TYPE_JSON) &&
+ !input.getDesignRequest().getDataType().equals(DesignServiceConstants.DATA_TYPE_YAML) &&
+ !input.getDesignRequest().getDataType().equals(DesignServiceConstants.DATA_TYPE_XML) &&
+ !input.getDesignRequest().getDataType().equals(DesignServiceConstants.DATA_TYPE_VELOCITY);
}
}
diff --git a/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/services/impl/RequestValidationException.java b/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/services/impl/RequestValidationException.java
new file mode 100644
index 000000000..052246338
--- /dev/null
+++ b/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/services/impl/RequestValidationException.java
@@ -0,0 +1,8 @@
+package org.onap.appc.design.services.impl;
+
+public class RequestValidationException extends Exception{
+
+ public RequestValidationException(String message) {
+ super(message);
+ }
+}