summaryrefslogtreecommitdiffstats
path: root/restconf-client/provider/src/main
diff options
context:
space:
mode:
authorjanani b <janani.b@huawei.com>2018-09-19 21:10:17 +0530
committerjanani b <janani.b@huawei.com>2018-09-19 21:10:17 +0530
commit2092b7c383f1a3280da05b71517fae6521b73327 (patch)
tree91e595d7be541ad9e06af961d11429f7aeaf80eb /restconf-client/provider/src/main
parent259eece936114ccacf9acc8f412eeed033fd10c4 (diff)
Issue fix for RestconfApiCallNode
Sonar and Issue fix Issue-ID: CCSDK-325 Change-Id: I469fcc5c4da2ec26c3a39b48d52736d45c1718d4 Signed-off-by: janani b <janani.b@huawei.com>
Diffstat (limited to 'restconf-client/provider/src/main')
-rw-r--r--restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/restconfapicall/RestconfApiCallNode.java18
-rw-r--r--restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/restconfapicall/RestconfApiUtils.java29
-rw-r--r--restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/dfserializer/MdsalSerializerHelper.java3
3 files changed, 34 insertions, 16 deletions
diff --git a/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/restconfapicall/RestconfApiCallNode.java b/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/restconfapicall/RestconfApiCallNode.java
index f9a1ecbf..91ce3338 100644
--- a/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/restconfapicall/RestconfApiCallNode.java
+++ b/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/restconfapicall/RestconfApiCallNode.java
@@ -54,6 +54,7 @@ import java.util.Map;
import static java.lang.String.format;
import static org.apache.commons.lang3.StringUtils.join;
+import static org.onap.ccsdk.sli.plugins.restapicall.HttpMethod.PATCH;
import static org.onap.ccsdk.sli.plugins.restapicall.HttpMethod.POST;
import static org.onap.ccsdk.sli.plugins.restapicall.HttpMethod.PUT;
import static org.onap.ccsdk.sli.plugins.restapicall.RestapiCallNode.parseParam;
@@ -153,7 +154,8 @@ public class RestconfApiCallNode implements SvcLogicJavaPlugin {
InstanceIdentifierContext<?> insIdCtx = getInsIdCtx(p, uri);
String req = null;
- if (p.httpMethod == POST || p.httpMethod == PUT) {
+ if (p.httpMethod == POST || p.httpMethod == PUT
+ || p.httpMethod == PATCH) {
req = serializeRequest(props, p, uri, insIdCtx);
}
if (req == null && p.requestBody != null) {
@@ -181,8 +183,8 @@ public class RestconfApiCallNode implements SvcLogicJavaPlugin {
log.error(REQ_ERR + e.getMessage(), e);
String prefix = parseParam(paramMap, RES_PRE, false, null);
- if (retryPolicy == null || shouldRetry == false) {
- setFailureResponseStatus(ctx, prefix, e.getMessage(), r);
+ if (retryPolicy == null || !shouldRetry) {
+ setFailureResponseStatus(ctx, prefix, e.getMessage());
} else {
if (retryCount == null) {
retryCount = 0;
@@ -198,12 +200,11 @@ public class RestconfApiCallNode implements SvcLogicJavaPlugin {
sendRequest(paramMap, ctx, retryCount);
} else {
log.debug(MAX_RETRY_ERR);
- setFailureResponseStatus(ctx, prefix,
- e.getMessage(), r);
+ setFailureResponseStatus(ctx, prefix, e.getMessage());
}
} catch (Exception ex) {
log.error(NO_MORE_RETRY, ex);
- setFailureResponseStatus(ctx, prefix, RETRY_FAIL, r);
+ setFailureResponseStatus(ctx, prefix, RETRY_FAIL);
}
}
}
@@ -338,11 +339,10 @@ public class RestconfApiCallNode implements SvcLogicJavaPlugin {
* @param ctx service logic context
* @param prefix prefix to be added
* @param errMsg error message
- * @param res http response
*/
private void setFailureResponseStatus(SvcLogicContext ctx, String prefix,
- String errMsg, HttpResponse res) {
- res = new HttpResponse();
+ String errMsg) {
+ HttpResponse res = new HttpResponse();
res.code = 500;
res.message = errMsg;
ctx.setAttribute(prefix + RES_CODE, String.valueOf(res.code));
diff --git a/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/restconfapicall/RestconfApiUtils.java b/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/restconfapicall/RestconfApiUtils.java
index 0f9c9401..b51272f7 100644
--- a/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/restconfapicall/RestconfApiUtils.java
+++ b/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/restconfapicall/RestconfApiUtils.java
@@ -97,8 +97,6 @@ public final class RestconfApiUtils {
private static final String URL_SYNTAX = "The following URL cannot be " +
"parsed into URI : ";
- private static final String RESTCONF_PATH = "/restconf/operations/";
-
private static final String PUT_NODE_ERR = "The following URL does not " +
"contain minimum two nodes for PUT operation.";
@@ -136,7 +134,7 @@ public final class RestconfApiUtils {
* @return YANG path pointing to parent
* @throws SvcLogicException when parsing the URL fails
*/
- static String parseUrl(String url, HttpMethod method)
+ public static String parseUrl(String url, HttpMethod method)
throws SvcLogicException {
URI uri;
try {
@@ -146,9 +144,7 @@ public final class RestconfApiUtils {
}
String path = uri.getPath();
- if (path.contains(RESTCONF_PATH)) {
- path = path.replaceFirst(RESTCONF_PATH, "");
- }
+ path = getParsedPath(path);
if (method == PUT) {
if (!path.contains(SLASH)) {
throw new SvcLogicException(PUT_NODE_ERR + url);
@@ -159,6 +155,27 @@ public final class RestconfApiUtils {
}
/**
+ * Returns the path which contains only the schema nodes.
+ *
+ * @param path path
+ * @return path representing schema
+ */
+ private static String getParsedPath(String path) {
+ String firstHalf;
+ if (path.contains(":")) {
+ String[] p = path.split(":");
+ if (p[0].contains(SLASH)) {
+ int slash = p[0].lastIndexOf(SLASH);
+ firstHalf = p[0].substring(slash + 1);
+ } else {
+ firstHalf = p[0];
+ }
+ return firstHalf + ":" + p[1];
+ }
+ return path;
+ }
+
+ /**
* Returns the schema context of the YANG files present in a directory.
*
* @param di directory path
diff --git a/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/dfserializer/MdsalSerializerHelper.java b/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/dfserializer/MdsalSerializerHelper.java
index 6f9f9070..1fd0d2de 100644
--- a/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/dfserializer/MdsalSerializerHelper.java
+++ b/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/dfserializer/MdsalSerializerHelper.java
@@ -274,11 +274,12 @@ public class MdsalSerializerHelper extends SerializerHelper<SchemaNode, SchemaCo
if (curSchemaNode instanceof DataSchemaNode) {
Deque<DataSchemaNode> dataSchema = findSchemaNodeByNameAndNamespace(
(DataSchemaNode) curSchemaNode, name, namespace.moduleNs());
+
if (dataSchema != null && !dataSchema.isEmpty()) {
childNode = dataSchema.pop();
}
- if (!dataSchema.isEmpty()) {
+ if (dataSchema != null && !dataSchema.isEmpty()) {
childNode = findSchemaForChild(((ChoiceSchemaNode) childNode),
qname);
}