Fixed the Sonar technical debt.
[policy/engine.git] / POLICY-SDK-APP / src / main / java / org / onap / policy / controller / CreateDcaeMicroServiceController.java
index 815b88f..431482d 100644 (file)
@@ -31,6 +31,7 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
 import java.io.PrintWriter;
+import java.io.StringReader;
 import java.nio.file.Files;
 import java.nio.file.Path;
 import java.nio.file.Paths;
@@ -47,9 +48,17 @@ import java.util.Map;
 import java.util.Map.Entry;
 import java.util.Set;
 import java.util.TreeMap;
+import java.util.UUID;
 import java.util.zip.ZipEntry;
 import java.util.zip.ZipFile;
 
+import javax.json.Json;
+import javax.json.JsonArray;
+import javax.json.JsonArrayBuilder;
+import javax.json.JsonObject;
+import javax.json.JsonObjectBuilder;
+import javax.json.JsonReader;
+import javax.json.JsonValue;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
@@ -73,8 +82,8 @@ 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.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;
@@ -131,6 +140,7 @@ public class CreateDcaeMicroServiceController extends RestrictedBaseController {
        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.";
@@ -148,7 +158,9 @@ public class CreateDcaeMicroServiceController extends RestrictedBaseController {
                CreateDcaeMicroServiceController.commonClassDao = commonClassDao;
        }
 
-       public CreateDcaeMicroServiceController(){}
+       public CreateDcaeMicroServiceController(){
+               // Empty Constructor
+       }
 
        protected PolicyRestAdapter policyAdapter = null;
        private int priorityCount; 
@@ -159,8 +171,18 @@ public class CreateDcaeMicroServiceController extends RestrictedBaseController {
                
                String jsonContent = null;
                try{
-                       jsonContent = decodeContent(root.get("policyJSON")).toString();
-                       constructJson(policyData, jsonContent);
+                       LOGGER.info("policyJSON :" + (root.get("policyJSON")).toString());
+                       
+                       String tempJson = root.get("policyJSON").toString();
+                       
+                       //---replace empty value with the value below before calling decodeContent method.
+                       String dummyValue = "*empty-value*" + UUID.randomUUID().toString();
+                       LOGGER.info("dummyValue:" + dummyValue);
+                       tempJson = StringUtils.replaceEach(tempJson, new String[]{"\"\""}, new String[]{"\""+dummyValue+"\""});
+                       ObjectMapper mapper = new ObjectMapper();
+                       JsonNode tempJsonNode = mapper.readTree(tempJson);
+                       jsonContent = decodeContent(tempJsonNode).toString();
+                       constructJson(policyData, jsonContent, dummyValue);
                }catch(Exception e){
                        LOGGER.error("Error while decoding microservice content", e);
                }
@@ -169,11 +191,10 @@ public class CreateDcaeMicroServiceController extends RestrictedBaseController {
        }
        
        private GroupPolicyScopeList getPolicyObject(String policyScope) {
-               GroupPolicyScopeList groupList= (GroupPolicyScopeList) commonClassDao.getEntityItem(GroupPolicyScopeList.class, "name", policyScope);
-               return groupList;
+               return (GroupPolicyScopeList) commonClassDao.getEntityItem(GroupPolicyScopeList.class, "name", policyScope);
        }
        
-       private PolicyRestAdapter constructJson(PolicyRestAdapter policyAdapter, String jsonContent) {
+       private PolicyRestAdapter constructJson(PolicyRestAdapter policyAdapter, String jsonContent, String dummyValue) {
                ObjectWriter om = new ObjectMapper().writer();
                String json="";
                DCAEMicroServiceObject microServiceObject = new DCAEMicroServiceObject();
@@ -228,9 +249,13 @@ public class CreateDcaeMicroServiceController extends RestrictedBaseController {
                } catch (JsonProcessingException e) {
                        LOGGER.error("Error writing out the object", e);
                }
-               LOGGER.info(json);
+               LOGGER.info("input json: " + json);
+               LOGGER.info("input jsonContent: " + jsonContent);
                String cleanJson = cleanUPJson(json);
-               cleanJson = removeNullAttributes(cleanJson);
+        //--- reset empty value back after called cleanUPJson method and before calling removeNullAttributes
+               String tempJson = StringUtils.replaceEach(cleanJson, new String[]{"\""+dummyValue+"\""},  new String[]{"\"\""});
+               LOGGER.info("tempJson: " + tempJson);
+               cleanJson = removeNullAttributes(tempJson);
                policyAdapter.setJsonBody(cleanJson);
                return policyAdapter;
        }
@@ -243,10 +268,30 @@ public class CreateDcaeMicroServiceController extends RestrictedBaseController {
                        JsonNode returnNode = mapper.readTree(cleanJson);
                        Iterator<Map.Entry<String, JsonNode>> fieldsIterator = rootNode.fields();
                        boolean remove = false;
+                       JsonObject removed = null;
+                       boolean contentChanged = false;
                        while (fieldsIterator.hasNext()) {
                                Map.Entry<String, JsonNode> field = fieldsIterator.next();
                                final String key = field.getKey();
                                final JsonNode value = field.getValue();
+                               if("content".equalsIgnoreCase(key)){
+                                       String contentStr = value.toString();
+                                       try(JsonReader reader = Json.createReader(new StringReader(contentStr))){
+                               JsonObject jsonContent = reader.readObject();                 
+                                                       removed = removeNull(jsonContent);
+                                                       if(!jsonContent.toString().equals(removed.toString())){
+                                                       contentChanged = true;  
+                                               }
+                    }
+
+                                       if  (value==null || value.isNull()){
+                                               ((ObjectNode) returnNode).remove(key);
+                                               remove = true;
+                                       }
+                               }
+                               if (remove){
+                                       cleanJson = returnNode.toString();
+                               }
                                if  (value==null || value.isNull()){
                                        ((ObjectNode) returnNode).remove(key);
                                        remove = true;
@@ -255,12 +300,91 @@ public class CreateDcaeMicroServiceController extends RestrictedBaseController {
                        if (remove){
                                cleanJson = returnNode.toString();
                        }
+                       
+                       if(contentChanged){
+                               //set modified content to cleanJson
+                               JSONObject  jObject  =  new JSONObject(cleanJson);      
+                               jObject.put("content",removed.toString());
+                               cleanJson = cleanUPJson(jObject.toString());
+                       }
+                       
                } catch (IOException e) {
                        LOGGER.error("Error writing out the JsonNode",e);
                }
                return cleanJson;
        }
        
+       public static JsonArray removeNull(JsonArray array) {
+           JsonArrayBuilder builder = Json.createArrayBuilder();
+           int i = 0;
+           for (Iterator<JsonValue> it = array.iterator(); it.hasNext(); ++i) {
+               JsonValue value = it.next();
+               switch (value.getValueType()) {
+               case ARRAY:
+                   JsonArray a = removeNull(array.getJsonArray(i));
+                   if (!a.isEmpty())
+                       builder.add(a);
+                   break;
+               case OBJECT:
+                   JsonObject object = removeNull(array.getJsonObject(i));
+                   if (!object.isEmpty())
+                       builder.add(object);
+                   break;
+               case STRING:
+                   String s = array.getString(i);
+                   if (s != null && !s.isEmpty())
+                       builder.add(s);
+                   break;
+               case NUMBER:
+                   builder.add(array.getJsonNumber(i));
+                   break;
+               case TRUE:
+               case FALSE:
+                   builder.add(array.getBoolean(i));
+                   break;
+               case NULL:
+                   break;
+               }
+           }
+           return builder.build();
+       }
+
+       public static JsonObject removeNull(JsonObject obj) {
+           JsonObjectBuilder builder = Json.createObjectBuilder();
+           for (Iterator<Entry<String, JsonValue>> it = obj.entrySet().iterator(); it.hasNext();) {
+               Entry<String, JsonValue> e = it.next();
+               String key = e.getKey();
+               JsonValue value = e.getValue();
+               switch (value.getValueType()) {
+               case ARRAY:
+                   JsonArray array = removeNull(obj.getJsonArray(key));
+                   if (!array.isEmpty())
+                       builder.add(key, array);
+                   break;
+               case OBJECT:
+                   JsonObject object = removeNull(obj.getJsonObject(key));
+                   if (!object.isEmpty())
+                       builder.add(key, object);
+                   break;
+               case STRING:
+                   String s = obj.getString(key);
+                   if (s != null && !s.isEmpty())
+                       builder.add(key, s);
+                   break;
+               case NUMBER:
+                   builder.add(key, obj.getJsonNumber(key));
+                   break;
+               case TRUE:
+               case FALSE:
+                   builder.add(key, obj.getBoolean(key));
+                   break;
+               case NULL:
+                   break;
+               }
+           }
+           return builder.build();
+       }
+       
        // Second index of dot should be returned. 
        public int stringBetweenDots(String str){
                String stringToSearch=str;
@@ -288,18 +412,17 @@ public class CreateDcaeMicroServiceController extends RestrictedBaseController {
        }
        
  
+       @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();
-               @SuppressWarnings("unchecked")
-               Map<Object, Object> yamlMap = (Map<Object, Object>) yaml.load(is); 
                StringBuilder sb = new StringBuilder(); 
                Map<String, String> settings = new HashMap<>(); 
                if (yamlMap == null) { 
@@ -310,7 +433,7 @@ public class CreateDcaeMicroServiceController extends RestrictedBaseController {
                return settings; 
        } 
 
-       public Map<String, String> load(byte[] source) throws IOException 
+       public Map<String, String> load(byte[] source) { 
                Yaml yaml = new Yaml(); 
                @SuppressWarnings("unchecked")
                Map<Object, Object> yamlMap = (Map<Object, Object>) yaml.load(Arrays.toString(source)); 
@@ -403,7 +526,7 @@ public class CreateDcaeMicroServiceController extends RestrictedBaseController {
                                String findType=DATATYPE+uniqueDataKeySplit[0]+PROPERTIES+uniqueDataKeySplit[1]+TYPE;
                                String typeValue=map.get(findType);
                                LOGGER.info(typeValue);
-                               if(typeValue.equalsIgnoreCase(STRING)||
+                               if(typeValue != null && typeValue.equalsIgnoreCase(STRING)||
                                                typeValue.equalsIgnoreCase(INTEGER)
                                  )
                                {
@@ -421,7 +544,7 @@ public class CreateDcaeMicroServiceController extends RestrictedBaseController {
                                        attributeIndividualStringBuilder.append(requiredValue+MANYFALSE);
                                        dataMapForJson.put(uniqueDataKey, attributeIndividualStringBuilder.toString());         
                                }
-                               else if(typeValue.equalsIgnoreCase(LIST)){
+                               else if(typeValue != null && typeValue.equalsIgnoreCase(LIST)){
                                        String findList= DATATYPE+uniqueDataKeySplit[0]+PROPERTIES+uniqueDataKeySplit[1]+".entry_schema.type";
                                        String listValue=map.get(findList);
                                        if(listValue!=null){
@@ -563,8 +686,8 @@ public class CreateDcaeMicroServiceController extends RestrictedBaseController {
                for(Map.Entry<String,HashMap<String,String>> entry: mapKey.entrySet()){
                        String keySetString= entry.getKey();
                        HashMap<String,String> keyValues=mapKey.get(keySetString);
-                       if(keyValues.get("type").equalsIgnoreCase(STRING)||
-                                       keyValues.get("type").equalsIgnoreCase(INTEGER)
+                       if(keyValues.get("type") != null && keyValues.get("type").equalsIgnoreCase(STRING)||
+                                       keyValues.get("type") != null && keyValues.get("type").equalsIgnoreCase(INTEGER)
                                        ){
                                StringBuilder attributeIndividualStringBuilder= new StringBuilder();
                                attributeIndividualStringBuilder.append(keySetString+"=");
@@ -574,39 +697,50 @@ public class CreateDcaeMicroServiceController extends RestrictedBaseController {
                                attributeStringBuilder.append(attributeIndividualStringBuilder+",");    
 
                        }
-                       else if(keyValues.get("type").equalsIgnoreCase(LIST)){
+                       else if(keyValues.get("type") != null && keyValues.get("type").equalsIgnoreCase(LIST)){
                                //List Datatype
                                Set<String> keys= keyValues.keySet();
                                Iterator<String> itr=keys.iterator();
                                while(itr.hasNext()){
                                        String key= itr.next();
-                                       if((!("type").equals(key) ||("required").equals(key)))
+                                       if(!("type").equals(key) ||("required").equals(key))
                                        {
                                                String value= keyValues.get(key);
                                                //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) &&
+                                       (constraints == null || constraints.isEmpty()) ) {
+                                               referenceStringBuilder.append(keySetString+"=MANY-true"+",");
+                               }
                        }else{
                                //User defined Datatype. 
                                String value=keyValues.get("type");
-                               String trimValue=value.substring(value.lastIndexOf('.')+1);
-                               StringBuilder referenceIndividualStringBuilder= new StringBuilder();
-                               referenceIndividualStringBuilder.append(keySetString+"="+trimValue+":MANY-false");
-                               referenceStringBuilder.append(referenceIndividualStringBuilder+",");
+                               if(value != null && !value.isEmpty()){
+                                       String trimValue=value.substring(value.lastIndexOf('.')+1);
+                                       StringBuilder referenceIndividualStringBuilder= new StringBuilder();
+                                       referenceIndividualStringBuilder.append(keySetString+"="+trimValue+":MANY-false");
+                                       referenceStringBuilder.append(referenceIndividualStringBuilder+",");
+                               }else{
+                                       LOGGER.info("keyValues.get(type) is null/empty");
+                               }
 
                        }
-                       if(constraints!=null &&constraints.isEmpty()==false){
+                       if(constraints!=null && ! constraints.isEmpty()){
                                //List handling. 
                                listBuffer.append(keySetString.toUpperCase()+"=[");
                                for(String str:constraints){
@@ -696,19 +830,21 @@ public class CreateDcaeMicroServiceController extends RestrictedBaseController {
                JsonNodeFactory nodeFactory = JsonNodeFactory.instance;
                ObjectNode node = nodeFactory.objectNode();
                String prevKey = null;
-               String presKey = null;
-               for(String key: element.keySet()){
+               String presKey;
+               for(Entry<String, String> entry: element.entrySet()){
+                       String key = entry.getKey();
+                       String value = entry.getValue();
                        if(key.contains(".")){
-                               presKey = key.substring(0,key.indexOf("."));
+                               presKey = key.substring(0,key.indexOf('.'));
                        }else if(key.contains("@")){
-                               presKey = key.substring(0,key.indexOf("@"));
+                               presKey = key.substring(0,key.indexOf('@'));
                        }else{
                                presKey = key;
                        }
                        // first check if we are different from old.
                        LOGGER.info(key+"\n");
                        if(jsonArray!=null && jsonArray.length()>0 && key.contains("@") && !key.contains(".") && oldValue!=null){
-                               if(!oldValue.equals(key.substring(0,key.indexOf("@")))){
+                               if(!oldValue.equals(key.substring(0,key.indexOf('@')))){
                                        jsonResult.put(oldValue, jsonArray);
                                        jsonArray = new JSONArray();
                                }
@@ -722,86 +858,62 @@ public class CreateDcaeMicroServiceController extends RestrictedBaseController {
                        // 
                        if(key.contains(".")){
                                if(nodeKey==null){
-                                       nodeKey = key.substring(0,key.indexOf("."));
+                                       nodeKey = key.substring(0,key.indexOf('.'));
                                }
-                               if(nodeKey.equals(key.substring(0,key.indexOf(".")))){
-                                       node.put(key.substring(key.indexOf(".")+1), element.get(key));
+                               if(nodeKey.equals(key.substring(0,key.indexOf('.')))){
+                                       node.put(key.substring(key.indexOf('.')+1), value);
                                }else{
                                        if(node.size()!=0){
                                                if(nodeKey.contains("@")){
                                                        if(arryKey==null){
-                                                               arryKey = nodeKey.substring(0,nodeKey.indexOf("@"));
+                                                               arryKey = nodeKey.substring(0,nodeKey.indexOf('@'));
                                                        }
                                                        if(nodeKey.endsWith("@0")){
                                                                isArray = true;
                                                                jsonArray = new JSONArray();
                                                        }
-                                                       if(jsonArray != null && arryKey.equals(nodeKey.substring(0,nodeKey.indexOf("@")))){
+                                                       if(jsonArray != null && arryKey.equals(nodeKey.substring(0,nodeKey.indexOf('@')))){
                                                                jsonArray.put(decodeContent(node));
                                                        } 
-                                                       if((key.contains("@") && !arryKey.equals(key.substring(0,nodeKey.indexOf("@")))) || !key.contains("@")){
+                                                       if((key.contains("@") && !arryKey.equals(key.substring(0,nodeKey.indexOf('@')))) || !key.contains("@")){
                                                                jsonResult.put(arryKey, jsonArray);
                                                                jsonArray = new JSONArray();
                                                        }
-                                                       arryKey = nodeKey.substring(0,nodeKey.indexOf("@"));
+                                                       arryKey = nodeKey.substring(0,nodeKey.indexOf('@'));
                                                }else{
                                                        isArray = false;
                                                        jsonResult.put(nodeKey, decodeContent(node));
                                                }
                                                node = nodeFactory.objectNode();
                                        }
-                                       nodeKey = key.substring(0,key.indexOf("."));
+                                       nodeKey = key.substring(0,key.indexOf('.'));
                                        if(nodeKey.contains("@")){
-                                               arryKey = nodeKey.substring(0,nodeKey.indexOf("@"));
+                                               arryKey = nodeKey.substring(0,nodeKey.indexOf('@'));
                                        }
-                                       node.put(key.substring(key.indexOf(".")+1), element.get(key));
+                                       node.put(key.substring(key.indexOf('.')+1), value);
                                }
-                       }else if(node.size()!=0){
-                               if(nodeKey.contains("@")){
-                                       if(arryKey==null){
-                                               arryKey = nodeKey.substring(0,nodeKey.indexOf("@"));
-                                       }
-                                       if(nodeKey.endsWith("@0")){
-                                               isArray = true;
-                                               jsonArray = new JSONArray();
-                                       }
-                                       if(jsonArray != null && arryKey.equals(nodeKey.substring(0,nodeKey.indexOf("@")))){
-                                               jsonArray.put(decodeContent(node));
-                                       }
-                                       jsonResult.put(arryKey, jsonArray);
-                                       jsonArray = new JSONArray();
-                                       arryKey = nodeKey.substring(0,nodeKey.indexOf("@"));
-                               }else{
-                                       isArray = false;
-                                       jsonResult.put(nodeKey, decodeContent(node));
-                               }
-                               node = nodeFactory.objectNode();
-                               if(key.contains("@")){
-                                       isArray = true;
-                                       if(key.endsWith("@0")|| jsonArray==null){
+                       }else {
+                               if(node.size()!=0){
+                                       if(nodeKey.contains("@")){
+                                               if(arryKey==null){
+                                                       arryKey = nodeKey.substring(0,nodeKey.indexOf('@'));
+                                               }
+                                               if(nodeKey.endsWith("@0")){
+                                                       isArray = true;
+                                                       jsonArray = new JSONArray();
+                                               }
+                                               if(jsonArray != null && arryKey.equals(nodeKey.substring(0,nodeKey.indexOf('@')))){
+                                                       jsonArray.put(decodeContent(node));
+                                               }
+                                               jsonResult.put(arryKey, jsonArray);
                                                jsonArray = new JSONArray();
-                                       }
-                               }else if(!key.contains("@")){
-                                       isArray = false;
-                               }
-                               if(isArray){
-                                       if(oldValue==null){
-                                               oldValue = key.substring(0,key.indexOf("@"));
-                                       }
-                                       if(oldValue!=prevKey){
-                                               oldValue = key.substring(0,key.indexOf("@"));
-                                       }
-                                       if(oldValue.equals(key.substring(0,key.indexOf("@")))){
-                                               jsonArray.put(element.get(key));
+                                               arryKey = nodeKey.substring(0,nodeKey.indexOf('@'));
                                        }else{
-                                               jsonResult.put(oldValue, jsonArray);
-                                               jsonArray = new JSONArray();
+                                               isArray = false;
+                                               jsonResult.put(nodeKey, decodeContent(node));
                                        }
-                                       oldValue = key.substring(0,key.indexOf("@"));
-                               }else{
-                                       jsonResult.put(key, element.get(key));
+                                       node = nodeFactory.objectNode();
                                }
-                       }else{
                                if(key.contains("@")){
                                        isArray = true;
                                        if(key.endsWith("@0")|| jsonArray==null){
@@ -812,20 +924,20 @@ public class CreateDcaeMicroServiceController extends RestrictedBaseController {
                                }
                                if(isArray){
                                        if(oldValue==null){
-                                               oldValue = key.substring(0,key.indexOf("@"));
+                                               oldValue = key.substring(0,key.indexOf('@'));
                                        }
                                        if(oldValue!=prevKey){
-                                               oldValue = key.substring(0,key.indexOf("@"));
+                                               oldValue = key.substring(0,key.indexOf('@'));
                                        }
-                                       if(oldValue.equals(key.substring(0,key.indexOf("@")))){
-                                               jsonArray.put(element.get(key));
+                                       if(oldValue.equals(key.substring(0,key.indexOf('@')))){
+                                               jsonArray.put(value);
                                        }else{
                                                jsonResult.put(oldValue, jsonArray);
                                                jsonArray = new JSONArray();
                                        }
-                                       oldValue = key.substring(0,key.indexOf("@"));
+                                       oldValue = key.substring(0,key.indexOf('@'));
                                }else{
-                                       jsonResult.put(key, element.get(key));
+                                       jsonResult.put(key, value);
                                }
                        }
                }
@@ -835,11 +947,11 @@ public class CreateDcaeMicroServiceController extends RestrictedBaseController {
                                        jsonArray = new JSONArray();
                                }
                                if(arryKey==null){
-                                       arryKey = nodeKey.substring(0,nodeKey.indexOf("@"));
+                                       arryKey = nodeKey.substring(0,nodeKey.indexOf('@'));
                                }
                                jsonArray.put(decodeContent(node));
                                jsonResult.put(arryKey, jsonArray);
-                               isArray = false;;
+                               isArray = false;
                        }else{
                                jsonResult.put(nodeKey, decodeContent(node));
                        }
@@ -857,14 +969,62 @@ public class CreateDcaeMicroServiceController extends RestrictedBaseController {
                JsonNode root = mapper.readTree(request.getReader());
 
                String value = root.get("policyData").toString().replaceAll("^\"|\"$", "");
-               String  servicename = value.toString().split("-v")[0];
+               String  servicename = value.split("-v")[0];
                String version = null;
-               if (value.toString().contains("-v")){
-                       version = value.toString().split("-v")[1];
+               if (value.contains("-v")){
+                       version = value.split("-v")[1];
                }
                MicroServiceModels returnModel = getAttributeObject(servicename, version);
                
-               String jsonModel = createMicroSeriveJson(returnModel);
+               
+               //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());      
+                       getAllKeys(json); 
+                       allkeys = allManyTrueKeys;
+                       allManyTrueKeys = new  HashSet <>();
+                       LOGGER.info("allkeys : " + allkeys);
+               }
+               
+               String allManyTrueKeys = "";
+               if(allkeys != null){
+                       allManyTrueKeys = allkeys.toString();
+               }
+               
+               String jsonModel = createMicroSeriveJson(returnModel, allkeys);
+               
+               JSONObject jsonObject = new JSONObject(jsonModel);
+               
+               JSONObject finalJsonObject = null;
+               if(allkeys != null){
+                       Iterator<String> iter = allkeys.iterator();
+                       while(iter.hasNext()){
+                               //Convert to array values for MANY-true keys
+                               finalJsonObject = convertToArrayElement(jsonObject, iter.next());
+                       }
+               }
+
+               if(finalJsonObject != null){
+                   LOGGER.info(finalJsonObject.toString());
+                   jsonModel  = finalJsonObject.toString();
+               }
+               
+               //get all properties with "MANY-true" defined in Ref_attributes
+               Set<String> manyTrueProperties = getManyTrueProperties(returnModel.getRef_attributes());
+               if(manyTrueProperties != null){
+                       JSONObject jsonObj = new JSONObject(jsonModel);
+                       for (String s : manyTrueProperties) {
+                               LOGGER.info(s);
+                               //convert to array element for MANY-true properties
+                               finalJsonObject = convertToArrayElement(jsonObj, s.trim());
+                       }
+                       
+                       if(finalJsonObject != null){
+                           LOGGER.info(finalJsonObject.toString());
+                           jsonModel = finalJsonObject.toString();
+                       }
+               }
                
                response.setCharacterEncoding("UTF-8");
                response.setContentType("application / json");
@@ -872,14 +1032,19 @@ public class CreateDcaeMicroServiceController extends RestrictedBaseController {
                List<Object>  list = new ArrayList<>();
                PrintWriter out = response.getWriter();
                String responseString = mapper.writeValueAsString(returnModel);
-               JSONObject j = new JSONObject("{dcaeModelData: " + responseString + ",jsonValue: " + jsonModel + "}");
+               JSONObject j;
+               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;
        }
        
        @SuppressWarnings({ "unchecked", "rawtypes" })
-       private String createMicroSeriveJson(MicroServiceModels returnModel) {
+       private String createMicroSeriveJson(MicroServiceModels returnModel, Set<String> allkeys) {
                Map<String, String> attributeMap = new HashMap<>();
                Map<String, String> refAttributeMap = new HashMap<>();
                String attribute = returnModel.getAttributes();
@@ -912,12 +1077,12 @@ public class CreateDcaeMicroServiceController extends RestrictedBaseController {
                Map gsonObject = (Map) gson.fromJson(subAttributes, Object.class);
                
                JSONObject object = new JSONObject();
-               JSONArray array = new JSONArray();
+               JSONArray array;
                
                for (Entry<String, String> keySet : attributeMap.entrySet()){
                        array = new JSONArray();
                        String value = keySet.getValue();
-                       if (keySet.getValue().split("MANY-")[1].equalsIgnoreCase("true")){
+                       if ("true".equalsIgnoreCase(keySet.getValue().split("MANY-")[1])){
                                array.put(value);
                                object.put(keySet.getKey().trim(), array);
                        }else {
@@ -929,14 +1094,14 @@ public class CreateDcaeMicroServiceController extends RestrictedBaseController {
                        array = new JSONArray();
                        String value = keySet.getValue().split(":")[0];
                        if (gsonObject.containsKey(value)){
-                               if (keySet.getValue().split("MANY-")[1].equalsIgnoreCase("true")){
+                               if ("true".equalsIgnoreCase(keySet.getValue().split("MANY-")[1])){
                                        array.put(recursiveReference(value, gsonObject, enumAttribute));
                                        object.put(keySet.getKey().trim(), array);
                                }else {
                                        object.put(keySet.getKey().trim(), recursiveReference(value, gsonObject, enumAttribute));
                                }
                        }else {
-                               if (keySet.getValue().split("MANY-")[1].equalsIgnoreCase("true")){
+                               if ("true".equalsIgnoreCase(keySet.getValue().split("MANY-")[1])){
                                        array.put(value.trim());
                                        object.put(keySet.getKey().trim(), array);
                                }else {
@@ -944,6 +1109,8 @@ public class CreateDcaeMicroServiceController extends RestrictedBaseController {
                                }
                        }
                }
+               
+               
 
                return object.toString();
        }
@@ -951,23 +1118,23 @@ public class CreateDcaeMicroServiceController extends RestrictedBaseController {
        @SuppressWarnings("unchecked")
        private JSONObject recursiveReference(String name, Map<String,String> subAttributeMap, String enumAttribute) {
                JSONObject object = new JSONObject();
-               Map<String, String> map = new HashMap<>();
+               Map<String, String> map;
                Object returnClass = subAttributeMap.get(name);
                map = (Map<String, String>) returnClass; 
-               JSONArray array = new JSONArray();
+               JSONArray array;
                
                for( Entry<String, String> m:map.entrySet()){  
                        String[] splitValue = m.getValue().split(":");
                        array = new JSONArray();
                        if (subAttributeMap.containsKey(splitValue[0])){
-                               if (m.getValue().split("MANY-")[1].equalsIgnoreCase("true")){
+                               if ("true".equalsIgnoreCase(m.getValue().split("MANY-")[1])){
                                        array.put(recursiveReference(splitValue[0], subAttributeMap, enumAttribute));
                                        object.put(m.getKey().trim(), array);
                                }else {
                                        object.put(m.getKey().trim(), recursiveReference(splitValue[0], subAttributeMap, enumAttribute));
                                }
                        } else{
-                               if (m.getValue().split("MANY-")[1].equalsIgnoreCase("true")){
+                               if ("true".equalsIgnoreCase(m.getValue().split("MANY-")[1])){
                                        array.put(splitValue[0].trim());
                                        object.put(m.getKey().trim(), array);
                                }else {
@@ -978,6 +1145,88 @@ public class CreateDcaeMicroServiceController extends RestrictedBaseController {
                
                return object;
        }
+       
+       
+       public static JSONObject convertToArrayElement(JSONObject json, String keyValue) {
+           return convertToArrayElement(json, new HashSet<>(), keyValue);
+       }
+       
+       private static JSONObject convertToArrayElement(JSONObject json, Set<String> keys, String keyValue) {
+           for (String key : json.keySet()) {
+               Object obj = json.get(key);
+               if(key.equals(keyValue.trim())){
+                       if(!(obj instanceof JSONArray)){
+                               JSONArray newJsonArray = new JSONArray();
+                               newJsonArray.put(obj);
+                               json.put(key, newJsonArray);
+                       }
+                       LOGGER.info("key : " + key);
+                       LOGGER.info("obj : " + obj);
+                       LOGGER.info("json.get(key) : " + json.get(key));
+                       LOGGER.info("keyValue : " + keyValue);
+                   keys.addAll(json.keySet());
+                   
+                   return json;
+               }
+
+               if (obj instanceof JSONObject) convertToArrayElement(json.getJSONObject(key), keyValue);            
+           }
+
+           return json;
+       }
+       
+       // call this method to get all MANY-true properties 
+       public static Set<String> getManyTrueProperties(String referAttributes){
+               LOGGER.info("referAttributes : " + referAttributes);
+               Set<String> manyTrueProperties = new HashSet<>();
+               
+               if(referAttributes != null){
+                       String[] referAarray = referAttributes.split(",");
+                       String []element;
+                       for(int i=0; i<referAarray.length; i++){
+                               element = referAarray[i].split("=");      
+                               if(element.length > 1 && element[1].contains("MANY-true")){
+                                       manyTrueProperties.add(element[0]);
+                               }
+                       }               
+               }
+               
+               return manyTrueProperties;
+       }
+       
+       //call this method to start the recursive
+       private Set<String> getAllKeys(JSONObject json) {
+           return getAllKeys(json, new HashSet<>());
+       }
+
+       private Set<String> getAllKeys(JSONArray arr) {
+           return getAllKeys(arr, new HashSet<>());
+       }
+
+       private Set<String> getAllKeys(JSONArray arr, Set<String> keys) {
+           for (int i = 0; i < arr.length(); i++) {
+               Object obj = arr.get(i);
+               if (obj instanceof JSONObject) keys.addAll(getAllKeys(arr.getJSONObject(i)));
+               if (obj instanceof JSONArray) keys.addAll(getAllKeys(arr.getJSONArray(i)));
+           }
+
+           return keys;
+       }
+    // this method returns a set of keys with "MANY-true" defined in their value.
+       private Set<String> getAllKeys(JSONObject json, Set<String> keys) {
+           for (String key : json.keySet()) {
+               Object obj = json.get(key);
+               if(obj instanceof String && ((String) obj).contains("MANY-true")){
+                       LOGGER.info("key : " + key);
+                       LOGGER.info("obj : " + obj);
+                       allManyTrueKeys.add(key);
+               }
+               if (obj instanceof JSONObject) keys.addAll(getAllKeys(json.getJSONObject(key)));
+               if (obj instanceof JSONArray) keys.addAll(getAllKeys(json.getJSONArray(key)));
+           }
+
+           return keys;
+       }
 
        
        @RequestMapping(value={"/policyController/getModelServiceVersioneData.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
@@ -987,7 +1236,7 @@ public class CreateDcaeMicroServiceController extends RestrictedBaseController {
                JsonNode root = mapper.readTree(request.getReader());
 
                String value = root.get("policyData").toString().replaceAll("^\"|\"$", "");
-               String  servicename = value.toString().split("-v")[0];
+               String  servicename = value.split("-v")[0];
                Set<String> returnList = getVersionList(servicename);
                
                response.setCharacterEncoding("UTF-8");
@@ -1003,7 +1252,7 @@ public class CreateDcaeMicroServiceController extends RestrictedBaseController {
        }
 
        private Set<String> getVersionList(String name) {       
-               MicroServiceModels workingModel = new MicroServiceModels();
+               MicroServiceModels workingModel;
                Set<String> list = new HashSet<>();
                List<Object> microServiceModelsData = commonClassDao.getDataById(MicroServiceModels.class, "modelName", name);
                for (int i = 0; i < microServiceModelsData.size(); i++) {
@@ -1103,29 +1352,30 @@ public class CreateDcaeMicroServiceController extends RestrictedBaseController {
                                                                                AttributeDesignatorType designator = match.getAttributeDesignator();
                                                                                String attributeId = designator.getAttributeId();
                                                                                // First match in the target is OnapName, so set that value.
-                                                                               if (attributeId.equals("ONAPName")) {
+                                                                               if ("ONAPName".equals(attributeId)) {
                                                                                        policyAdapter.setOnapName(value);
                                                                                }
-                                                                               if (attributeId.equals("ConfigName")){
+                                                                               if ("ConfigName".equals(attributeId)){
                                                                                        policyAdapter.setConfigName(value);
                                                                                }
-                                                                               if (attributeId.equals("uuid")){
+                                                                               if ("uuid".equals(attributeId)){
                                                                                        policyAdapter.setUuid(value);
                                                                                }
-                                                                               if (attributeId.equals("location")){
+                                                                               if ("location".equals(attributeId)){
                                                                                        policyAdapter.setLocation(value);
                                                                                }
-                                                                               if (attributeId.equals("RiskType")){
+                                                                               if ("RiskType".equals(attributeId)){
                                                                                        policyAdapter.setRiskType(value);
                                                                                }
-                                                                               if (attributeId.equals("RiskLevel")){
+                                                                               if ("RiskLevel".equals(attributeId)){
                                                                                        policyAdapter.setRiskLevel(value);
                                                                                }
-                                                                               if (attributeId.equals("guard")){
+                                                                               if ("guard".equals(attributeId)){
                                                                                        policyAdapter.setGuard(value);
                                                                                }
-                                                                               if (attributeId.equals("TTLDate") && !value.contains("NA")){
-                                                                                       String newDate = convertDate(value, true);
+                                                                               if ("TTLDate".equals(attributeId) && !value.contains("NA")){
+                                                                                       PolicyController controller = new PolicyController();
+                                                                                       String newDate = controller.convertDate(value);
                                                                                        policyAdapter.setTtlDate(newDate);
                                                                                }
                                                                        }
@@ -1138,15 +1388,6 @@ public class CreateDcaeMicroServiceController extends RestrictedBaseController {
                        }
                }
        }
-
-       private String convertDate(String dateTTL, boolean portalType) {
-               String formateDate = null;
-               String[] date  = dateTTL.split("T");
-               String[] parts = date[0].split("-");
-                       
-               formateDate = parts[2] + "-" + parts[1] + "-" + parts[0];
-               return formateDate;
-       }
        
        public static Map<String, String> convert(String str, String split) {
                Map<String, String> map = new HashMap<>();
@@ -1163,7 +1404,7 @@ public class CreateDcaeMicroServiceController extends RestrictedBaseController {
                String policyScopeName = null;
                ObjectMapper mapper = new ObjectMapper();
                try {
-                       DCAEMicroServiceObject msBody = (DCAEMicroServiceObject) mapper.readValue(entity.getConfigurationData().getConfigBody(), DCAEMicroServiceObject.class);
+                       DCAEMicroServiceObject msBody = mapper.readValue(entity.getConfigurationData().getConfigBody(), DCAEMicroServiceObject.class);
                        policyScopeName = getPolicyScope(msBody.getPolicyScope());
                        policyAdapter.setPolicyScope(policyScopeName);
 
@@ -1196,8 +1437,8 @@ public class CreateDcaeMicroServiceController extends RestrictedBaseController {
                        if(value instanceof LinkedHashMap<?, ?>){
                                LinkedHashMap<String, Object> secondObjec = new LinkedHashMap<>(); 
                                readRecursivlyJSONContent((LinkedHashMap<String, ?>) value, secondObjec);
-                               for(String objKey: secondObjec.keySet()){
-                                       data.put(key+"." +objKey, secondObjec.get(objKey));
+                               for( Entry<String, Object> entry : secondObjec.entrySet()){
+                                       data.put(key+"." + entry.getKey(), entry.getValue());
                                }
                        }else if(value instanceof ArrayList){
                                ArrayList<?> jsonArrayVal = (ArrayList<?>)value;
@@ -1206,8 +1447,8 @@ public class CreateDcaeMicroServiceController extends RestrictedBaseController {
                                        if(arrayvalue instanceof LinkedHashMap<?, ?>){
                                                LinkedHashMap<String, Object> newData = new LinkedHashMap<>();   
                                                readRecursivlyJSONContent((LinkedHashMap<String, ?>) arrayvalue, newData);
-                                               for(String objKey: newData.keySet()){
-                                                       data.put(key+"@"+i+"." +objKey, newData.get(objKey));
+                                               for(Entry<String, Object> entry: newData.entrySet()){
+                                                       data.put(key+"@"+i+"." +entry.getKey(), entry.getValue());
                                                }
                                        }else if(arrayvalue instanceof ArrayList){
                                                ArrayList<?> jsonArrayVal1 = (ArrayList<?>)value;
@@ -1237,7 +1478,7 @@ public class CreateDcaeMicroServiceController extends RestrictedBaseController {
        //Convert the map values and set into JSON body
        public Map<String, String> convertMap(Map<String, String> attributesMap, Map<String, String> attributesRefMap) {
                Map<String, String> attribute = new HashMap<>();
-               String temp = null;
+               StringBuilder temp;
                String key;
                String value;
                for (Entry<String, String> entry : attributesMap.entrySet()) {
@@ -1247,12 +1488,12 @@ public class CreateDcaeMicroServiceController extends RestrictedBaseController {
                }
                for (Entry<String, String> entryRef : attributesRefMap.entrySet()) {
                        key = entryRef.getKey();
-                       value = entryRef.getValue().toString();
+                       value = entryRef.getValue();
                        attribute.put(key, value);
                }
                for (Entry<String, String> entryList : attributesListRefMap.entrySet()) {
                        key = entryList.getKey();
-                       value = entryList.getValue().toString();
+                       value = entryList.getValue();
                        attribute.put(key, value);
                }
                for (Entry<String, LinkedList<String>> arrayList : arrayTextList.entrySet()){
@@ -1260,9 +1501,10 @@ public class CreateDcaeMicroServiceController extends RestrictedBaseController {
                        temp = null;
                        for (Object textList : arrayList.getValue()){
                                if (temp == null){
-                                       temp = "[" + textList;
+                                       temp = new StringBuilder();
+                                       temp.append("[" + textList);
                                }else{
-                                       temp = temp + "," + textList;
+                                       temp.append("," + textList);
                                }
                        }
                        attribute.put(key, temp+ "]");                  
@@ -1273,9 +1515,18 @@ public class CreateDcaeMicroServiceController extends RestrictedBaseController {
        
        @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;
+               String errorMsg = "";
                for (FileItem item : items) {
                        if(item.getName().endsWith(".zip") || item.getName().endsWith(".xmi")||item.getName().endsWith(".yml")){
                                this.newModel = new MicroServiceModels();
@@ -1285,40 +1536,55 @@ public class CreateDcaeMicroServiceController extends RestrictedBaseController {
                                        IOUtils.copy(item.getInputStream(), outputStream);
                                        outputStream.close();
                                        this.newFile = file.toString();
-                                       this.newModel.setModelName(this.newFile.toString().split("-v")[0]);
+                                       this.newModel.setModelName(this.newFile.split("-v")[0]);
                                
-                                       if (this.newFile.toString().contains("-v")){
+                                       if (this.newFile.contains("-v")){
                                                if (item.getName().endsWith(".zip")){
-                                                       this.newModel.setVersion(this.newFile.toString().split("-v")[1].replace(".zip", ""));
+                                                       this.newModel.setVersion(this.newFile.split("-v")[1].replace(".zip", ""));
                                                        zip = true;
                                                }else if(item.getName().endsWith(".yml")){
-                                                       this.newModel.setVersion(this.newFile.toString().split("-v")[1].replace(".yml", ""));
+                                                       this.newModel.setVersion(this.newFile.split("-v")[1].replace(".yml", ""));
                                                        yml = true;
                                                }
                                                else {
-                                                       this.newModel.setVersion(this.newFile.toString().split("-v")[1].replace(".xmi", ""));
+                                                       this.newModel.setVersion(this.newFile.split("-v")[1].replace(".xmi", ""));
                                                }
-                                       }
-                               
+                                       }                               
                                }catch(Exception e){
-                                       LOGGER.error("Upload error : " + e);
+                                       LOGGER.error("Upload error : ", e);
+                                       errorMsg = "Upload error:" + e.getMessage();
                                }
                        }
                        
                }
-               List<File> fileList = new ArrayList<>();;
+               
+               if(!errorMsg.isEmpty()){
+                       
+                       PrintWriter out = response.getWriter();
+                       
+                       response.setCharacterEncoding("UTF-8");
+                       response.setContentType("application / json");
+                       request.setCharacterEncoding("UTF-8");
+                       
+                       JSONObject j = new JSONObject();
+                       j.put("errorMsg", errorMsg);
+                       out.write(j.toString());
+                       return;
+               }
+               
+               List<File> fileList = new ArrayList<>();
                this.directory = "model";
                if (zip){
                        extractFolder(this.newFile);
                        fileList = listModelFiles(this.directory);
-               }else if (yml==true){
+               }else if (yml){
                        parseTosca(this.newFile);
                }else {
                        File file = new File(this.newFile);
                        fileList.add(file);
                }
-               String modelType= "";
-               if(yml==false){
+               String modelType;
+               if(! yml){
                        modelType="xmi";
                        //Process Main Model file first
                        classMap = new HashMap<>();
@@ -1346,7 +1612,6 @@ public class CreateDcaeMicroServiceController extends RestrictedBaseController {
                        msAttributes.setSubClass(this.retmap);
                        
                        HashMap<String, String> returnReferenceList =new HashMap<>();
-                       //String[] referenceArray=this.referenceAttributes.split("=");
                        returnReferenceList.put(className, this.referenceAttributes);
                        msAttributes.setRefAttribute(returnReferenceList);
                        
@@ -1389,9 +1654,7 @@ public class CreateDcaeMicroServiceController extends RestrictedBaseController {
            int BUFFER = 2048;
            File file = new File(zipFile);
 
-           ZipFile zip = null;
-               try {
-                       zip = new ZipFile(file);
+               try (ZipFile zip = new ZipFile(file)) {
                    String newPath =  "model" + File.separator + zipFile.substring(0, zipFile.length() - 4);
                    this.directory = "model" + File.separator + zipFile.substring(0, zipFile.length() - 4);
                    checkZipDirectory(this.directory);
@@ -1411,15 +1674,20 @@ public class CreateDcaeMicroServiceController extends RestrictedBaseController {
                        if (!entry.isDirectory()){
                            BufferedInputStream is = new BufferedInputStream(zip.getInputStream(entry));
                            int currentByte;
-                           byte data[] = new byte[BUFFER];
-                           FileOutputStream fos = new FileOutputStream(destFile);
-                           BufferedOutputStream dest = new BufferedOutputStream(fos, BUFFER);
-                           while ((currentByte = is.read(data, 0, BUFFER)) != -1) {
-                               dest.write(data, 0, currentByte);
+                           byte[] data = new byte[BUFFER];
+                           try (FileOutputStream fos = new FileOutputStream(destFile);
+                                       BufferedOutputStream dest = new BufferedOutputStream(fos, BUFFER)) {
+                                   while ((currentByte = is.read(data, 0, BUFFER)) != -1) {
+                                       dest.write(data, 0, currentByte);
+                                   }
+                                   dest.flush();
+                           } catch (IOException e) {
+                               LOGGER.error("Failed to write zip contents to {}" + destFile + e);
+                               //
+                               // PLD should I throw e?
+                               //
+                               throw e;
                            }
-                           dest.flush();
-                           dest.close();
-                           is.close();
                        }
        
                        if (currentEntry.endsWith(".zip")){
@@ -1428,20 +1696,13 @@ public class CreateDcaeMicroServiceController extends RestrictedBaseController {
                    }
            } catch (IOException e) {
                LOGGER.error("Failed to unzip model file " + zipFile, e);
-               }finally{
-                       try {
-                               if(zip != null)
-                               zip.close();
-                       } catch (IOException e) {
-                               LOGGER.error("Exception Occured While closing zipfile " + e);
-                       }
                }
        }
        
        private void retreiveDependency(String workingFile, Boolean modelClass) {
                
                MSModelUtils utils = new MSModelUtils(PolicyController.getMsOnapName(), PolicyController.getMsPolicyName());
-           HashMap<String, MSAttributeObject> tempMap = new HashMap<>();
+           Map<String, MSAttributeObject> tempMap;
            
            tempMap = utils.processEpackage(workingFile, MODEL_TYPE.XMI);