X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=ONAP-PAP-REST%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Fpolicy%2Fpap%2Fxacml%2Frest%2Fcontroller%2FDictionaryImportController.java;h=9423017c31b0e604b01298692ecc2cfaa3a877d2;hb=b6d9063e06ab8cdf2d97fc75810792659344e4a8;hp=f3c78ffb9b8817b0d7389bd86b0a2c3a75a1530d;hpb=c8bed1e392b935ec50aaeeb5fb82d25a9568b790;p=policy%2Fengine.git diff --git a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/DictionaryImportController.java b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/DictionaryImportController.java index f3c78ffb9..9423017c3 100644 --- a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/DictionaryImportController.java +++ b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/DictionaryImportController.java @@ -79,16 +79,21 @@ public class DictionaryImportController { private static CommonClassDao commonClassDao; private static final String DESCRIPTION= "description"; + private static final String ERROR= "Error"; + private static final String DEPENDENCY= "dependency"; @Autowired public DictionaryImportController(CommonClassDao commonClassDao){ + setCommonClassDao(commonClassDao); + } + + public static void setCommonClassDao(CommonClassDao commonClassDao) { DictionaryImportController.commonClassDao = commonClassDao; } public DictionaryImportController(){ - super(); - } - + super(); + } @RequestMapping(value={"/dictionary/import_dictionary"}, method={RequestMethod.POST}) public void importDictionaryData(HttpServletRequest request, HttpServletResponse response) throws IOException{ @@ -100,15 +105,15 @@ public class DictionaryImportController { if(dictionaryName == null || dictionaryName.isEmpty()){ LOGGER.error("dictionaryName is null/empty"); response.setStatus(HttpServletResponse.SC_BAD_REQUEST); - response.getWriter().write("Error"); + response.getWriter().write(ERROR); return; } // fix Fortify Path Manipulation issue if(!isValidDictionaryName(dictionaryName)){ LOGGER.error("dictionaryName is invalid"); - response.setStatus(HttpServletResponse.SC_OK); - response.getWriter().write("Dictionary Import failed. Hence the following dictionary doen't support import function : "+ dictionaryName); + response.setStatus(HttpServletResponse.SC_BAD_REQUEST); + response.getWriter().write(ERROR); return; } File file = new File(dictionaryName); @@ -230,7 +235,7 @@ public class DictionaryImportController { if(DESCRIPTION.equalsIgnoreCase(dictSheet.get(0)[j])){ attribute.setDescription(rows[j]); } - if("dependency".equalsIgnoreCase(dictSheet.get(0)[j])){ + if(DEPENDENCY.equalsIgnoreCase(dictSheet.get(0)[j])){ attribute.setDependency(rows[j]); } if("attributes".equalsIgnoreCase(dictSheet.get(0)[j])){ @@ -245,6 +250,50 @@ public class DictionaryImportController { if("Sub Attributes".equalsIgnoreCase(dictSheet.get(0)[j])){ attribute.setSub_attributes(rows[j]); } + if("annotations".equalsIgnoreCase(dictSheet.get(0)[j])) { + attribute.setAnnotation(rows[j]); + } + } + + commonClassDao.save(attribute); + } + } + + if(dictionaryName.startsWith("OptimizationPolicyDictionary")){ + for(int i = 1; i< dictSheet.size(); i++){ + MicroServiceModels attribute = new MicroServiceModels(); + UserInfo userinfo = new UserInfo(); + userinfo.setUserLoginId(userId); + attribute.setUserCreatedBy(userinfo); + String[] rows = dictSheet.get(i); + for (int j=0 ; j