aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRahul_cool <rahul.tamrkar@huawei.com>2020-04-01 15:49:25 +0530
committerDan Timoney <dtimoney@att.com>2020-04-01 12:23:58 +0000
commitfaaf89d113eb5b820f5d5806de0e0a466ba79964 (patch)
tree302bee35d6506f8bbdced2b5e936fd9ae6dfce7d
parent3397b655d7f6909a7dfee8b6e8ed880392569b28 (diff)
Added code for decoding base64 encoded value
Issue-ID: SDNC-899 Signed-off-by: Rahul_cool <rahul.tamrkar@huawei.com> Change-Id: I231f891118dabf59518bcf4dbe456df97cd3e5b2 (cherry picked from commit 4cbff49506b31844ccda7ca38b3ba7283974475a)
-rw-r--r--sliPluginUtils/provider/src/main/java/org/onap/ccsdk/sli/core/slipluginutils/SliStringUtils.java32
-rw-r--r--sliPluginUtils/provider/src/test/java/org/onap/ccsdk/sli/core/slipluginutils/SliStringUtilsTest.java9
2 files changed, 41 insertions, 0 deletions
diff --git a/sliPluginUtils/provider/src/main/java/org/onap/ccsdk/sli/core/slipluginutils/SliStringUtils.java b/sliPluginUtils/provider/src/main/java/org/onap/ccsdk/sli/core/slipluginutils/SliStringUtils.java
index fdc057b2..9e3367d4 100644
--- a/sliPluginUtils/provider/src/main/java/org/onap/ccsdk/sli/core/slipluginutils/SliStringUtils.java
+++ b/sliPluginUtils/provider/src/main/java/org/onap/ccsdk/sli/core/slipluginutils/SliStringUtils.java
@@ -27,6 +27,7 @@ import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.util.Map;
+import java.util.Base64;
import org.apache.commons.text.StringEscapeUtils;
import org.apache.commons.lang3.StringUtils;
import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
@@ -311,6 +312,37 @@ public class SliStringUtils implements SvcLogicJavaPlugin {
.replace(parameters.get(INPUT_PARAM_TARGET), parameters.get("replacement"))));
}
+/**
+ * exposes base64decoding algo
+ * writes the length of source to outputPath
+ * @param parameters HashMap<String,String> of parameters passed by the DG to this function
+ * <table border="1">
+ * <thead><th>parameter</th><th>Mandatory/Optional</th><th>description</th></thead>
+ * <tbody>
+ * <tr><td>encodedValue</td><td>Mandatory</td><td>source string</td></tr>
+ * <tr><td>decodedValue</td><td>Mandatory</td><td>Destination path</td></tr>
+ * </tbody>
+ * </table>
+ * @param ctx Reference to context memory
+ * @throws SvcLogicException
+ * @since 11.0.2
+ */
+ public static void base64DecodingAlgo(Map<String, String> parameters, SvcLogicContext ctx) throws SvcLogicException{
+ try {
+ SliPluginUtils.checkParameters(parameters, new String[]{"encodedValue","decodedValue"}, LOG);
+
+ Base64.Decoder decoder = Base64.getDecoder();
+ byte[] decodedByteArray = decoder.decode(parameters.get("encodedValue"));
+ //Verify the decoded string
+ String decodeVal = new String(decodedByteArray);
+ ctx.setAttribute(parameters.get("decodedValue"), decodeVal);
+ }catch (Exception exc){
+ LOG.error("Exception occure "+exc.getMessage());
+ throw new SvcLogicException(exc.getMessage());
+ }
+ }
+
+
/**
* exposes replaceAll to directed graph
* writes the length of source to outputPath
diff --git a/sliPluginUtils/provider/src/test/java/org/onap/ccsdk/sli/core/slipluginutils/SliStringUtilsTest.java b/sliPluginUtils/provider/src/test/java/org/onap/ccsdk/sli/core/slipluginutils/SliStringUtilsTest.java
index 3a6c31a3..da7046f4 100644
--- a/sliPluginUtils/provider/src/test/java/org/onap/ccsdk/sli/core/slipluginutils/SliStringUtilsTest.java
+++ b/sliPluginUtils/provider/src/test/java/org/onap/ccsdk/sli/core/slipluginutils/SliStringUtilsTest.java
@@ -386,4 +386,13 @@ public class SliStringUtilsTest {
assertEquals(SliStringUtils.FALSE_CONSTANT, result);
}
+ @Test
+ public void testBase64DecodingAlgo() throws Exception{
+ String input = "MDUxMDAw";
+ String decodeVal = "decodedPath";
+ param.put("encodedValue",input);
+ param.put("decodedValue", decodeVal);
+ SliStringUtils.base64DecodingAlgo(param,ctx);
+ assertEquals("051000",ctx.getAttribute(decodeVal));
+ }
}