X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=restconf-client%2Fprovider%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Fccsdk%2Fsli%2Fplugins%2Frestconfapicall%2FRestconfApiUtils.java;h=505089c4422384641cb6143aa8508b81880f077c;hb=614bd0b6897b1ece3ee7deb581089c301bb3f2e8;hp=0f9c9401c789cdb363757ff051f02ea573f312b2;hpb=056df35d0f9b894c1adf8ea9a2d9bdc21497a0e8;p=ccsdk%2Fsli%2Fplugins.git 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..505089c4 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 @@ -3,6 +3,8 @@ * ONAP - CCSDK * ================================================================================ * Copyright (C) 2018 Huawei Technologies Co., Ltd. All rights reserved. + * + * Modifications Copyright © 2018 IBM. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,15 +22,6 @@ package org.onap.ccsdk.sli.plugins.restconfapicall; -import org.onap.ccsdk.sli.core.sli.SvcLogicException; -import org.onap.ccsdk.sli.plugins.restapicall.HttpMethod; -import org.onap.ccsdk.sli.plugins.yangserializers.dfserializer.YangParameters; -import org.opendaylight.yangtools.yang.model.api.SchemaContext; -import org.opendaylight.yangtools.yang.model.parser.api.YangSyntaxErrorException; -import org.opendaylight.yangtools.yang.parser.rfc7950.repo.YangStatementStreamSource; -import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException; -import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementReactor; - import java.io.File; import java.io.IOException; import java.net.URI; @@ -41,7 +34,15 @@ import java.util.LinkedList; import java.util.List; import java.util.Map; -import static org.onap.ccsdk.sli.plugins.restapicall.HttpMethod.PUT; +import org.onap.ccsdk.sli.core.sli.SvcLogicException; +import org.onap.ccsdk.sli.plugins.restapicall.HttpMethod; +import org.onap.ccsdk.sli.plugins.yangserializers.dfserializer.YangParameters; +import org.opendaylight.yangtools.yang.model.api.SchemaContext; +import org.opendaylight.yangtools.yang.model.parser.api.YangSyntaxErrorException; +import org.opendaylight.yangtools.yang.parser.rfc7950.repo.YangStatementStreamSource; +import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException; +import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementReactor; + import static org.onap.ccsdk.sli.plugins.restapicall.RestapiCallNode.getParameters; import static org.onap.ccsdk.sli.plugins.restapicall.RestapiCallNode.parseParam; import static org.opendaylight.yangtools.yang.model.repo.api.StatementParserMode.DEFAULT_MODE; @@ -66,6 +67,8 @@ public final class RestconfApiUtils { static final String COMMA = ","; + static final String COLON = ":"; + static final String HTTP_RES = "httpResponse"; static final String REST_API_URL = "restapiUrl"; @@ -97,11 +100,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."; - private static final String YANG = ".yang"; private static final String YANG_FILE_ERR = "Unable to parse the YANG " + @@ -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,14 +144,29 @@ public final class RestconfApiUtils { } String path = uri.getPath(); - if (path.contains(RESTCONF_PATH)) { - path = path.replaceFirst(RESTCONF_PATH, ""); - } - if (method == PUT) { - if (!path.contains(SLASH)) { - throw new SvcLogicException(PUT_NODE_ERR + url); + path = getParsedPath(path); + return path; + } + + /** + * Returns the path which contains only the schema nodes. + * + * @param path path + * @return path representing schema + */ + private static String getParsedPath(String path) { + String firstHalf; + String secondHalf; + if (path.contains(COLON)) { + String[] p = path.split(COLON); + if (p[0].contains(SLASH)) { + int slash = p[0].lastIndexOf(SLASH); + firstHalf = p[0].substring(slash + 1); + } else { + firstHalf = p[0]; } - path = path.substring(0, path.lastIndexOf(SLASH)); + secondHalf = path.substring(p[0].length() + 1); + return firstHalf + COLON + secondHalf; } return path; } @@ -205,6 +218,13 @@ public final class RestconfApiUtils { } } + /** + * Processes all the obtained files by isolating all the YANG files from + * all the directory of the given path recursively. + * + * @param files files in the given path + * @param yangFiles YANG files list + */ private static void processFiles(File[] files, List yangFiles) { for (File file : files) { if (file.isFile() && file.getName().endsWith(YANG)) { @@ -214,4 +234,20 @@ public final class RestconfApiUtils { } } } + + /** + * Returns the updated XML request message by adding root node to it. + * + * @param req XML request + * @param nodeName root node name + * @param modNs module namespace of the root node + * @return updated XML request message + */ + static String getUpdatedXmlReq(String req, String nodeName, String modNs) { + String rootNode = "\n<" + nodeName + " xmlns=\"" + modNs + + "\">\n"; + req = req.replaceFirst("\n", rootNode); + req = req + ""; + return req.replaceAll(">\\s+<", "><"); + } }