* 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.
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;
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;
static final String COMMA = ",";
+ static final String COLON = ":";
+
static final String HTTP_RES = "httpResponse";
static final String REST_API_URL = "restapiUrl";
private static final String URL_SYNTAX = "The following URL cannot be " +
"parsed into URI : ";
- 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 " +
String path = uri.getPath();
path = getParsedPath(path);
- if (method == PUT) {
- if (!path.contains(SLASH)) {
- throw new SvcLogicException(PUT_NODE_ERR + url);
- }
- path = path.substring(0, path.lastIndexOf(SLASH));
- }
return path;
}
*/
private static String getParsedPath(String path) {
String firstHalf;
- if (path.contains(":")) {
- String[] p = path.split(":");
+ 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];
}
- return firstHalf + ":" + p[1];
+ secondHalf = path.substring(p[0].length() + 1);
+ return firstHalf + COLON + secondHalf;
}
return path;
}
}
}
+ /**
+ * 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<File> yangFiles) {
for (File file : files) {
if (file.isFile() && file.getName().endsWith(YANG)) {
}
}
}
+
+ /**
+ * 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 + "</" + nodeName + ">";
+ return req.replaceAll(">\\s+<", "><");
+ }
}