[Policy-52, Policy-92, Policy-93] Policy Enhancements and bugfixes
[policy/engine.git] / ECOMP-PAP-REST / src / main / java / org / openecomp / policy / pap / xacml / rest / controller / MicroServiceDictionaryController.java
index 876f380..b933a4f 100644 (file)
@@ -62,7 +62,11 @@ public class MicroServiceDictionaryController {
        private static final Logger LOGGER  = FlexLogger.getLogger(MicroServiceDictionaryController.class);
 
        private static CommonClassDao commonClassDao;
-       
+
+       public static void setCommonClassDao(CommonClassDao commonClassDao) {
+               MicroServiceDictionaryController.commonClassDao = commonClassDao;
+       }
+
        @Autowired
        public MicroServiceDictionaryController(CommonClassDao commonClassDao){
                MicroServiceDictionaryController.commonClassDao = commonClassDao;
@@ -82,18 +86,18 @@ public class MicroServiceDictionaryController {
     private static String ERROR = "error";
     private static String DICTIONARYDBQUERY = "dictionaryDBQuery";
     private HashMap<String,MSAttributeObject > classMap;
-    private List<String> modelList = new ArrayList<String>();
+    private List<String> modelList = new ArrayList<>();
     
        
 
-       MSModelUtils utils = new MSModelUtils(XACMLPapServlet.msEcompName, XACMLPapServlet.msPolicyName);
+       MSModelUtils utils = new MSModelUtils(XACMLPapServlet.getMsEcompName(), XACMLPapServlet.getMsPolicyName());
        private MicroServiceModels newModel;
        
        
        @RequestMapping(value={"/get_DCAEUUIDDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
        public void getDCAEUUIDDictionaryByNameEntityData(HttpServletRequest request, HttpServletResponse response){
                try{
-                       Map<String, Object> model = new HashMap<String, Object>();
+                       Map<String, Object> model = new HashMap<>();
                        ObjectMapper mapper = new ObjectMapper();
                        model.put("dcaeUUIDDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(DCAEuuid.class, "name")));
                        JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
@@ -108,7 +112,7 @@ public class MicroServiceDictionaryController {
        @RequestMapping(value={"/get_DCAEUUIDData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
        public void getDCAEUUIDDictionaryEntityData(HttpServletRequest request, HttpServletResponse response){
                try{
-                       Map<String, Object> model = new HashMap<String, Object>();
+                       Map<String, Object> model = new HashMap<>();
                        ObjectMapper mapper = new ObjectMapper();
                        model.put("dcaeUUIDDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(DCAEuuid.class)));
                        JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
@@ -239,7 +243,7 @@ public class MicroServiceDictionaryController {
        @RequestMapping(value={"/get_MicroServiceConfigNameDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
        public void getMicroServiceConfigNameByNameDictionaryEntityData(HttpServletRequest request, HttpServletResponse response){
                try{
-                       Map<String, Object> model = new HashMap<String, Object>();
+                       Map<String, Object> model = new HashMap<>();
                        ObjectMapper mapper = new ObjectMapper();
                        model.put("microServiceCongigNameDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(MicroServiceConfigName.class, "name")));
                        JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
@@ -256,7 +260,7 @@ public class MicroServiceDictionaryController {
        @RequestMapping(value={"/get_MicroServiceConfigNameData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
        public void getMicroServiceConfigNameDictionaryEntityData(HttpServletRequest request, HttpServletResponse response){
                try{
-                       Map<String, Object> model = new HashMap<String, Object>();
+                       Map<String, Object> model = new HashMap<>();
                        ObjectMapper mapper = new ObjectMapper();
                        model.put("microServiceCongigNameDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(MicroServiceConfigName.class)));
                        JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
@@ -387,7 +391,7 @@ public class MicroServiceDictionaryController {
        @RequestMapping(value={"/get_MicroServiceLocationDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
        public void getMicroServiceLocationByNameDictionaryEntityData(HttpServletRequest request, HttpServletResponse response){
                try{
-                       Map<String, Object> model = new HashMap<String, Object>();
+                       Map<String, Object> model = new HashMap<>();
                        ObjectMapper mapper = new ObjectMapper();
                        model.put("microServiceLocationDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(MicroServiceLocation.class, "name")));
                        JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
@@ -402,7 +406,7 @@ public class MicroServiceDictionaryController {
        @RequestMapping(value={"/get_MicroServiceLocationData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
        public void getMicroServiceLocationDictionaryEntityData(HttpServletRequest request, HttpServletResponse response){
                try{
-                       Map<String, Object> model = new HashMap<String, Object>();
+                       Map<String, Object> model = new HashMap<>();
                        ObjectMapper mapper = new ObjectMapper();
                        model.put("microServiceLocationDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(MicroServiceLocation.class)));
                        JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
@@ -533,7 +537,7 @@ public class MicroServiceDictionaryController {
     @RequestMapping(value={"/get_MicroServiceAttributeDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
     public void getMicroServiceAttributeByNameDictionaryEntityData(HttpServletRequest request, HttpServletResponse response){
         try{
-            Map<String, Object> model = new HashMap<String, Object>();
+            Map<String, Object> model = new HashMap<>();
             ObjectMapper mapper = new ObjectMapper();
             model.put("microServiceAttributeDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(MicroServiceAttribute.class, "name")));
             JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
@@ -548,7 +552,7 @@ public class MicroServiceDictionaryController {
     @RequestMapping(value={"/get_MicroServiceAttributeData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
     public void getMicroServiceAttributeDictionaryEntityData(HttpServletRequest request, HttpServletResponse response){
         try{
-            Map<String, Object> model = new HashMap<String, Object>();
+            Map<String, Object> model = new HashMap<>();
             ObjectMapper mapper = new ObjectMapper();
             model.put("microServiceAttributeDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(MicroServiceAttribute.class)));
             JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
@@ -679,7 +683,7 @@ public class MicroServiceDictionaryController {
        @RequestMapping(value={"/get_MicroServiceModelsDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
        public void getMicroServiceModelsDictionaryByNameEntityData(HttpServletRequest request, HttpServletResponse response){
                try{
-                       Map<String, Object> model = new HashMap<String, Object>();
+                       Map<String, Object> model = new HashMap<>();
                        ObjectMapper mapper = new ObjectMapper();
                        model.put("microServiceModelsDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(MicroServiceModels.class, "modelName")));
                        JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
@@ -694,7 +698,7 @@ public class MicroServiceDictionaryController {
     @RequestMapping(value={"/get_MicroServiceModelsDataByVersion"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
     public void getMicroServiceModelsDictionaryByVersionEntityData(HttpServletRequest request, HttpServletResponse response){
         try{
-            Map<String, Object> model = new HashMap<String, Object>();
+            Map<String, Object> model = new HashMap<>();
             ObjectMapper mapper = new ObjectMapper();
             JsonNode root = mapper.readTree(request.getReader());
             String modelName = null;
@@ -718,7 +722,7 @@ public class MicroServiceDictionaryController {
        @RequestMapping(value={"/get_MicroServiceModelsData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
        public void getMicroServiceModelsDictionaryEntityData(HttpServletRequest request, HttpServletResponse response){
                try{
-                       Map<String, Object> model = new HashMap<String, Object>();
+                       Map<String, Object> model = new HashMap<>();
                        ObjectMapper mapper = new ObjectMapper();
                        model.put("microServiceModelsDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(MicroServiceModels.class)));
                        JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
@@ -737,9 +741,9 @@ public class MicroServiceDictionaryController {
     @RequestMapping(value={"/get_MicroServiceModelsDataServiceVersion"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
     public void getMicroServiceModelsDictionaryEntityDataServiceVersion(HttpServletRequest request, HttpServletResponse response){
         try{
-            Map<String, Object> model = new HashMap<String, Object>();
+            Map<String, Object> model = new HashMap<>();
             ObjectMapper mapper = new ObjectMapper();
-            List<String> data = new ArrayList<String>();
+            List<String> data = new ArrayList<>();
             List<Object> datas = commonClassDao.getData(MicroServiceModels.class);
             for(int i = 0; i < datas.size(); i++){
                MicroServiceModels msmodel = (MicroServiceModels) datas.get(i);
@@ -765,7 +769,7 @@ public class MicroServiceDictionaryController {
     @RequestMapping(value={"/get_MicroServiceModelsDataByClass"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
     public void getMicroServiceModelsDictionaryClassEntityData(HttpServletRequest request, HttpServletResponse response){
         try{
-            Map<String, Object> model = new HashMap<String, Object>();
+            Map<String, Object> model = new HashMap<>();
             ObjectMapper mapper = new ObjectMapper();
             model.put("microServiceModelsDictionaryClassDatas", mapper.writeValueAsString(modelList));
             JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
@@ -816,7 +820,7 @@ public class MicroServiceDictionaryController {
                                        }
 
                                        MSAttributeObject mainClass  = null;
-                                       classMap = new HashMap<String, MSAttributeObject>();
+                                       classMap = new HashMap<>();
                                        JsonNode data = root.get("classMap");
                                        ObjectMapper mapper1 = new ObjectMapper();
                                        String data1 = data.toString().substring(1, data.toString().length()-1);
@@ -880,7 +884,7 @@ public class MicroServiceDictionaryController {
                                                        }
                                                }
                                                if(root.has("classMap")){
-                                                       classMap = new HashMap<String, MSAttributeObject>();
+                                                       classMap = new HashMap<>();
                                                        JsonNode data = root.get("classMap");
                                                        ObjectMapper mapper1 = new ObjectMapper();
                                                        String data1 = data.toString().substring(1, data.toString().length()-1);
@@ -1010,22 +1014,22 @@ public class MicroServiceDictionaryController {
                        this.newModel.setDependency("");
                }
 
-               if (mainClass.getDependency()==null){
+               if (mainClass != null && mainClass.getDependency()==null){
                        mainClass.setDependency("");
                }
-
-               this.newModel.setDependency(mainClass.getDependency());
-               this.newModel.setSub_attributes(subAttribute.toString());
-               this.newModel.setAttributes(mainClass.getAttribute().toString().replace("{", "").replace("}", ""));
-               this.newModel.setRef_attributes(mainClass.getRefAttribute().toString().replace("{", "").replace("}", ""));
-        this.newModel.setEnumValues(mainClass.getEnumType().toString().replace("{", "").replace("}", ""));
-        this.newModel.setAnnotation(mainClass.getMatchingSet().toString().replace("{", "").replace("}", ""));
-
+               if(mainClass != null){
+                       this.newModel.setDependency(mainClass.getDependency());
+                       this.newModel.setSub_attributes(subAttribute);
+                       this.newModel.setAttributes(mainClass.getAttribute().toString().replace("{", "").replace("}", ""));
+                       this.newModel.setRef_attributes(mainClass.getRefAttribute().toString().replace("{", "").replace("}", ""));
+                       this.newModel.setEnumValues(mainClass.getEnumType().toString().replace("{", "").replace("}", ""));
+                       this.newModel.setAnnotation(mainClass.getMatchingSet().toString().replace("{", "").replace("}", ""));
+               }
        } 
        
        private ArrayList<String> getFullDependencyList(ArrayList<String> dependency) {
-               ArrayList<String> returnList = new ArrayList<String>();
-               ArrayList<String> workingList = new ArrayList<String>();
+               ArrayList<String> returnList = new ArrayList<>();
+               ArrayList<String> workingList = new ArrayList<>();
                returnList.addAll(dependency);
                for (String element : dependency ){
                        if (classMap.containsKey(element)){