* ============LICENSE_START=======================================================
* ONAP Policy Engine
* ================================================================================
- * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2020 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
import com.fasterxml.jackson.databind.node.JsonNodeFactory;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.google.gson.Gson;
-
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
import java.io.StringReader;
+import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
+import java.util.Base64;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.HashSet;
import java.util.regex.Pattern;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
-
import javax.json.Json;
import javax.json.JsonArray;
import javax.json.JsonArrayBuilder;
import oasis.names.tc.xacml._3_0.core.schema.wd_17.MatchType;
import oasis.names.tc.xacml._3_0.core.schema.wd_17.PolicyType;
import oasis.names.tc.xacml._3_0.core.schema.wd_17.TargetType;
-
import org.apache.commons.compress.utils.IOUtils;
import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.FileUploadException;
import org.apache.commons.fileupload.servlet.ServletFileUpload;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.StringUtils;
+import org.apache.commons.lang3.StringEscapeUtils;
import org.json.JSONArray;
import org.json.JSONObject;
import org.onap.policy.common.logging.flexlogger.FlexLogger;
import org.onap.policy.rest.jpa.MicroServiceModels;
import org.onap.policy.rest.jpa.MicroserviceHeaderdeFaults;
import org.onap.policy.rest.jpa.PolicyEntity;
-import org.onap.policy.rest.util.MSAttributeObject;
-import org.onap.policy.rest.util.MSModelUtils;
-import org.onap.policy.rest.util.MSModelUtils.MODEL_TYPE;
+import org.onap.policy.rest.util.MsAttributeObject;
+import org.onap.policy.rest.util.MsModelUtils;
+import org.onap.policy.rest.util.MsModelUtils.ModelType;
import org.onap.policy.utils.PolicyUtils;
import org.onap.portalsdk.core.controller.RestrictedBaseController;
import org.onap.portalsdk.core.web.support.JsonMessage;
private String directory;
private List<String> modelList = new ArrayList<>();
private List<String> dirDependencyList = new ArrayList<>();
- private LinkedHashMap<String, MSAttributeObject> classMap = new LinkedHashMap<>();
+ private LinkedHashMap<String, MsAttributeObject> classMap = new LinkedHashMap<>();
String referenceAttributes;
String attributeString;
Set<String> allManyTrueKeys = null;
String tempJson = root.get(POLICYJSON).toString();
JSONObject policyJson = new JSONObject(root.get(POLICYJSON).toString());
- if (policyJson != null) {
- tempJson = saveOriginalJsonObject(policyJson, jsonStringValues).toString();
- }
+ tempJson = decodeJsonVal(tempJson, policyJson);
// ---replace empty value with the value below before calling decodeContent method.
String dummyValue = "*empty-value*" + UUID.randomUUID().toString();
LOGGER.info("dummyValue:" + dummyValue);
JSONObject content = contentJson.getJSONObject("content");
content = setOriginalJsonObject(content, jsonStringValues);
contentJson.put("content", content);
- policyData.setJsonBody(contentJson.toString());
+ policyData.setJsonBody(StringEscapeUtils.unescapeJava(contentJson.toString()));
}
return policyData;
}
+ private String decodeJsonVal(String tempJson, JSONObject policyJson) {
+ if (policyJson != null) {
+ for (Object key : policyJson.keySet()) {
+ String keyStr = (String) key;
+ Object keyvalue = policyJson.get(keyStr);
+ String decodedString = keyvalue.toString();//.replace("\"", "");
+ if(!decodedString.equals("true") && !decodedString.equals("false")) {
+ String decodedJson = new String(Base64.getDecoder().decode(decodedString), StandardCharsets.UTF_8).replace("\"", "\\\"");
+ policyJson.put(keyStr, decodedJson);
+ }
+ }
+ tempJson = saveOriginalJsonObject(policyJson, jsonStringValues).toString();
+ }
+ return tempJson;
+ }
+
private JSONObject saveOriginalJsonObject(JSONObject jsonObj, Map<String, String> jsonStringValues) {
for (Object key : jsonObj.keySet()) {
String keyStr = (String) key;
if (arrOfKeys[i].contains(".")) {
arrOfKeys[i] = arrOfKeys[i].substring(arrOfKeys[i].indexOf(".") + 1);
if (arrOfKeys[i].equals(key)) {
- return StringUtils.replaceEach(jsonStringValues.get(k), new String[] {"\""},
- new String[] {"\\\""});
+ return jsonStringValues.get(k);
}
}
}
}
if (k.endsWith(key)) {
- return StringUtils.replaceEach(jsonStringValues.get(k), new String[] {"\""}, new String[] {"\\\""});
+ return jsonStringValues.get(k);
}
}
case OBJECT:
JsonObject object = removeNull(obj.getJsonObject(key));
if (!object.isEmpty()) {
- if (!jsonStringValues.isEmpty()) {
- String originalValue = getOriginalValue(key);
- if (originalValue != null) {
- builder.add(key, object.toString());
- break;
- }
- }
builder.add(key, object);
}
break;
case STRING:
String str = obj.getString(key);
if (str != null && !str.isEmpty()) {
- if (!jsonStringValues.isEmpty()) {
- String originalValue = getOriginalValue(key);
- if (originalValue != null) {
- str = getOriginalValue(key);
- }
- }
builder.add(key, str);
}
break;
}
if (obj instanceof JSONArray) {
- convertToArrayElement(json.getJSONArray(key).getJSONObject(0), keyValue);
+ try {
+ if (json.getJSONArray(key).length() > 0) {
+ convertToArrayElement(json.getJSONArray(key).getJSONObject(0), keyValue);
+ }
+ } catch (Exception ex) {
+ LOGGER.info("XMI Model load issue : " + ex);
+ }
}
}
}
List<File> fileList = new ArrayList<>();
- MSModelUtils msModelUtils = new MSModelUtils(commonClassDao);
+ MsModelUtils msModelUtils = new MsModelUtils(commonClassDao);
this.directory = "model";
if (zip) {
extractFolder(this.newFile);
modelType = "yml";
modelList.add(this.newModel.getModelName());
String className = this.newModel.getModelName();
- MSAttributeObject msAttributes = new MSAttributeObject();
+ MsAttributeObject msAttributes = new MsAttributeObject();
msAttributes.setClassName(className);
LinkedHashMap<String, String> returnAttributeList = new LinkedHashMap<>();
private void retrieveDependency(String workingFile) {
- MSModelUtils utils = new MSModelUtils(PolicyController.getMsOnapName(), PolicyController.getMsPolicyName());
- Map<String, MSAttributeObject> tempMap;
+ MsModelUtils utils = new MsModelUtils(PolicyController.getMsOnapName(), PolicyController.getMsPolicyName());
+ Map<String, MsAttributeObject> tempMap;
- tempMap = utils.processEpackage(workingFile, MODEL_TYPE.XMI);
+ tempMap = utils.processEpackage(workingFile, ModelType.XMI);
classMap.putAll(tempMap);
LOGGER.info(tempMap);
private List<String> createList() {
List<String> list = new ArrayList<>();
- for (Entry<String, MSAttributeObject> entrySet : classMap.entrySet()) {
+ for (Entry<String, MsAttributeObject> entrySet : classMap.entrySet()) {
if (entrySet.getValue().isPolicyTempalate()) {
list.add(entrySet.getKey());
}