import org.json.JSONObject;
import org.onap.policy.common.logging.flexlogger.FlexLogger;
import org.onap.policy.common.logging.flexlogger.Logger;
-import org.onap.policy.controller.PolicyController;
import org.onap.policy.rest.XACMLRestProperties;
import org.onap.policy.rest.adapter.PolicyRestAdapter;
import org.onap.policy.rest.dao.CommonClassDao;
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.openecomp.portalsdk.core.controller.RestrictedBaseController;
-import org.openecomp.portalsdk.core.web.support.JsonMessage;
+import org.onap.portalsdk.core.controller.RestrictedBaseController;
+import org.onap.portalsdk.core.web.support.JsonMessage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
Set<String> uniqueDataKeys= new HashSet<>();
StringBuilder dataListBuffer=new StringBuilder();
List<String> dataConstraints= new ArrayList <>();
+ Set<String> allManyTrueKeys= new HashSet <>();
public static final String DATATYPE = "data_types.policy.data.";
public static final String PROPERTIES=".properties.";
}
+ @SuppressWarnings("unchecked")
public Map<String, String> load(String fileName) throws IOException {
File newConfiguration = new File(fileName);
- InputStream is = null;
- try {
- is = new FileInputStream(newConfiguration);
+ Yaml yaml = new Yaml();
+ Map<Object, Object> yamlMap = null;
+ try(InputStream is = new FileInputStream(newConfiguration)){
+ yamlMap = (Map<Object, Object>) yaml.load(is);
} catch (FileNotFoundException e) {
LOGGER.error(e);
}
- Yaml yaml = new Yaml();
-
- Map<Object, Object> yamlMap = null;
- try{
- yamlMap = (Map<Object, Object>) yaml.load(is);
- }catch(Exception e){
- LOGGER.error("load:", e);
- }
StringBuilder sb = new StringBuilder();
Map<String, String> settings = new HashMap<>();
if (yamlMap == null) {
//The "." in the value determines if its a string or a user defined type.
if (!value.contains(".")){
//This is string
- constraints.add(keyValues.get(key));
+ if(StringUtils.isNumeric(key) ){ //only integer key for the value of Constrains
+ constraints.add(keyValues.get(key));
+ }
}else{
- //This is userdefined string
+ //This is user defined string
String trimValue=value.substring(value.lastIndexOf('.')+1);
StringBuilder referenceIndividualStringBuilder= new StringBuilder();
referenceIndividualStringBuilder.append(keySetString+"="+trimValue+":MANY-true");
referenceStringBuilder.append(referenceIndividualStringBuilder+",");
}
- }
+ }
+
}
+ if(keyValues.get("type").equalsIgnoreCase(LIST)){
+ if(constraints == null || constraints.isEmpty()){
+ referenceStringBuilder.append(keySetString+"=MANY-true"+",");
+ }
+ }
}else{
//User defined Datatype.
String value=keyValues.get("type");
MicroServiceModels returnModel = getAttributeObject(servicename, version);
- //get all keys with "MANY-true" defined in their value from subAttribute
+ //Get all keys with "MANY-true" defined in their value from subAttribute
Set<String> allkeys = null;
if(returnModel.getSub_attributes() != null && !returnModel.getSub_attributes().isEmpty()){
- JSONObject json = new JSONObject(returnModel.getSub_attributes());
- allkeys = getAllKeys(json);
+ JSONObject json = new JSONObject(returnModel.getSub_attributes());
+ getAllKeys(json);
+ allkeys = allManyTrueKeys;
+ allManyTrueKeys = new HashSet <>();
LOGGER.info("allkeys : " + allkeys);
}
if(allkeys != null){
Iterator<String> iter = allkeys.iterator();
while(iter.hasNext()){
- //convert to array values for MANY-true keys
+ //Convert to array values for MANY-true keys
finalJsonObject = convertToArrayElement(jsonObject, iter.next());
}
}
if(finalJsonObject != null){
LOGGER.info(finalJsonObject.toString());
- jsonModel = finalJsonObject.toString();
+ jsonModel = finalJsonObject.toString();
}
}
List<Object> list = new ArrayList<>();
PrintWriter out = response.getWriter();
String responseString = mapper.writeValueAsString(returnModel);
- JSONObject j = new JSONObject("{dcaeModelData: " + responseString + ",jsonValue: " + jsonModel + ",allManyTrueKeys: " + allManyTrueKeys+ "}");
+ JSONObject j = null;
+ if("".equals(allManyTrueKeys)){
+ j = new JSONObject("{dcaeModelData: " + responseString + ",jsonValue: " + jsonModel + "}");
+ }else{
+ j = new JSONObject("{dcaeModelData: " + responseString + ",jsonValue: " + jsonModel + ",allManyTrueKeys: " + allManyTrueKeys+ "}");
+ }
list.add(j);
out.write(list.toString());
return null;
return object;
}
- //call this method to check if the key is in the many-true key set
- private boolean isKeyFound(Set<String> allManyTruekeys, String key){
-
- if(allManyTruekeys != null && key != null){
- Iterator<String> iter = allManyTruekeys.iterator();
- while(iter.hasNext()){
- if(key.equals(iter.next())){
- return true;
- }
- }
- }
- return false;
- }
public static JSONObject convertToArrayElement(JSONObject json, String keyValue) {
return convertToArrayElement(json, new HashSet<>(), keyValue);
if(obj instanceof String && ((String) obj).contains("MANY-true")){
LOGGER.info("key : " + key);
LOGGER.info("obj : " + obj);
- keys.addAll(json.keySet());
+ allManyTrueKeys.add(key);
}
if (obj instanceof JSONObject) keys.addAll(getAllKeys(json.getJSONObject(key)));
if (obj instanceof JSONArray) keys.addAll(getAllKeys(json.getJSONArray(key)));
@RequestMapping(value={"/ms_dictionary/set_MSModelData"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
public void SetMSModelData(HttpServletRequest request, HttpServletResponse response) throws IOException, FileUploadException{
+ modelList = new ArrayList<>();
+ dirDependencyList = new ArrayList<>();
+ classMap = new HashMap<>();
+ retmap = new HashMap<>();
+ uniqueKeys= new HashSet<>();
+ uniqueDataKeys= new HashSet<>();
+ dataListBuffer=new StringBuilder();
+ dataConstraints= new ArrayList <>();
List<FileItem> items = new ServletFileUpload(new DiskFileItemFactory()).parseRequest(request);
boolean zip = false;
boolean yml= false;
else {
this.newModel.setVersion(this.newFile.toString().split("-v")[1].replace(".xmi", ""));
}
- }else{
- errorMsg = "Upload error: The file name should contain '-v', such as xxx-v1802.yml";
- }
-
+ }
}catch(Exception e){
LOGGER.error("Upload error : ", e);
errorMsg = "Upload error:" + e.getMessage();
response.setContentType("application / json");
request.setCharacterEncoding("UTF-8");
- ObjectMapper mapper = new ObjectMapper();
JSONObject j = new JSONObject();
j.put("errorMsg", errorMsg);
out.write(j.toString());
return;
}
- List<File> fileList = new ArrayList<>();;
+ List<File> fileList = new ArrayList<>();
this.directory = "model";
if (zip){
extractFolder(this.newFile);