diff options
Diffstat (limited to 'ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/service')
3 files changed, 1249 insertions, 0 deletions
diff --git a/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/service/DictionaryService.java b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/service/DictionaryService.java new file mode 100644 index 000000000..618710753 --- /dev/null +++ b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/service/DictionaryService.java @@ -0,0 +1,1005 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PAP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ +package org.openecomp.policy.pap.xacml.rest.service; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.openecomp.policy.common.logging.flexlogger.FlexLogger; +import org.openecomp.policy.common.logging.flexlogger.Logger; +import org.openecomp.policy.pap.xacml.rest.controller.ActionPolicyDictionaryController; +import org.openecomp.policy.pap.xacml.rest.controller.BRMSDictionaryController; +import org.openecomp.policy.pap.xacml.rest.controller.ClosedLoopDictionaryController; +import org.openecomp.policy.pap.xacml.rest.controller.DecisionPolicyDictionaryController; +import org.openecomp.policy.pap.xacml.rest.controller.DescriptiveDictionaryController; +import org.openecomp.policy.pap.xacml.rest.controller.DictionaryController; +import org.openecomp.policy.pap.xacml.rest.controller.EnforcerDictionaryController; +import org.openecomp.policy.pap.xacml.rest.controller.FirewallDictionaryController; +import org.openecomp.policy.pap.xacml.rest.controller.MicroServiceDictionaryController; +import org.openecomp.policy.pap.xacml.rest.controller.PolicyScopeDictionaryController; +import org.openecomp.policy.pap.xacml.rest.controller.SafePolicyController; +import org.openecomp.policy.xacml.api.XACMLErrorConstants; +import org.springframework.stereotype.Service; +import org.springframework.web.servlet.ModelAndView; + + +@Service("DictionaryService") +public class DictionaryService { + + private static final Logger LOGGER = FlexLogger.getLogger(DictionaryService.class); + + /* + * Methods that call the controller method directly to Save and Update dictionary data + */ + public String saveEcompDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception{ + + DictionaryController dictionary = new DictionaryController(); + String responseString = null; + try { + ModelAndView result = dictionary.saveEcompDictionary(request, response); + responseString = result.getViewName(); + + } catch (Exception e) { + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); + e.printStackTrace(); + } + + return responseString; + + } + + public String saveAttributeDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception{ + + DictionaryController dictionary = new DictionaryController(); + String responseString = null; + try { + ModelAndView result = dictionary.saveAttributeDictionary(request, response); + responseString = result.getViewName(); + + } catch (Exception e) { + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); + e.printStackTrace(); + } + + return responseString; + } + + public String saveActionPolicyDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception{ + + ActionPolicyDictionaryController action = new ActionPolicyDictionaryController(); + String responseString = null; + try { + ModelAndView result = action.saveActionPolicyDictionary(request, response); + responseString = result.getViewName(); + + } catch (Exception e) { + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); + e.printStackTrace(); + } + + return responseString; + } + + public String saveBRMSParamDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception{ + + BRMSDictionaryController dictionary = new BRMSDictionaryController(); + String responseString = null; + try { + ModelAndView result = dictionary.saveBRMSParamDictionary(request, response); + responseString = result.getViewName(); + + } catch (Exception e) { + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); + e.printStackTrace(); + } + + return responseString; + } + + public String saveVSCLAction(HttpServletRequest request, HttpServletResponse response) throws Exception{ + + ClosedLoopDictionaryController dictionary = new ClosedLoopDictionaryController(); + String responseString = null; + try { + ModelAndView result = dictionary.saveVSCLAction(request, response); + responseString = result.getViewName(); + + } catch (Exception e) { + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); + e.printStackTrace(); + } + + return responseString; + } + + public String saveVnfType(HttpServletRequest request, HttpServletResponse response) throws Exception{ + + ClosedLoopDictionaryController dictionary = new ClosedLoopDictionaryController(); + String responseString = null; + try { + ModelAndView result = dictionary.saveVnfType(request, response); + responseString = result.getViewName(); + + } catch (Exception e) { + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); + e.printStackTrace(); + } + + return responseString; + } + + public String savePEPOptions(HttpServletRequest request, HttpServletResponse response) throws Exception{ + + ClosedLoopDictionaryController dictionary = new ClosedLoopDictionaryController(); + String responseString = null; + try { + ModelAndView result = dictionary.savePEPOptions(request, response); + responseString = result.getViewName(); + + } catch (Exception e) { + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); + e.printStackTrace(); + } + + return responseString; + } + + public String saveVarbind(HttpServletRequest request, HttpServletResponse response) throws Exception{ + + ClosedLoopDictionaryController dictionary = new ClosedLoopDictionaryController(); + String responseString = null; + try { + ModelAndView result = dictionary.saveVarbind(request, response); + responseString = result.getViewName(); + + } catch (Exception e) { + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); + e.printStackTrace(); + } + + return responseString; + } + + public String saveServiceType(HttpServletRequest request, HttpServletResponse response) throws Exception{ + + ClosedLoopDictionaryController dictionary = new ClosedLoopDictionaryController(); + String responseString = null; + try { + ModelAndView result = dictionary.saveServiceType(request, response); + responseString = result.getViewName(); + + } catch (Exception e) { + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); + e.printStackTrace(); + } + + return responseString; + } + + public String saveSiteType(HttpServletRequest request, HttpServletResponse response) throws Exception{ + + ClosedLoopDictionaryController dictionary = new ClosedLoopDictionaryController(); + String responseString = null; + try { + ModelAndView result = dictionary.saveSiteType(request, response); + responseString = result.getViewName(); + + } catch (Exception e) { + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); + e.printStackTrace(); + } + + return responseString; + } + + public String saveSettingsDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception{ + + DecisionPolicyDictionaryController dictionary = new DecisionPolicyDictionaryController(); + String responseString = null; + try { + ModelAndView result = dictionary.saveSettingsDictionary(request, response); + responseString = result.getViewName(); + + } catch (Exception e) { + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); + e.printStackTrace(); + } + + return responseString; + } + + public String saveDescriptiveDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception{ + + DescriptiveDictionaryController dictionary = new DescriptiveDictionaryController(); + String responseString = null; + try { + ModelAndView result = dictionary.saveDescriptiveDictionary(request, response); + responseString = result.getViewName(); + + } catch (Exception e) { + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); + e.printStackTrace(); + } + + return responseString; + } + + public String saveEnforcerDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception{ + + EnforcerDictionaryController dictionary = new EnforcerDictionaryController(); + String responseString = null; + try { + ModelAndView result = dictionary.saveEnforcerDictionary(request, response); + responseString = result.getViewName(); + + } catch (Exception e) { + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); + e.printStackTrace(); + } + + return responseString; + } + + public String saveActionListDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception{ + + FirewallDictionaryController dictionary = new FirewallDictionaryController(); + String responseString = null; + try { + ModelAndView result = dictionary.saveActionListDictionary(request, response); + responseString = result.getViewName(); + + } catch (Exception e) { + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); + e.printStackTrace(); + } + + return responseString; + } + + public String saveProtocolListDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception{ + + FirewallDictionaryController dictionary = new FirewallDictionaryController(); + String responseString = null; + try { + ModelAndView result = dictionary.saveProtocolListDictionary(request, response); + responseString = result.getViewName(); + + } catch (Exception e) { + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); + e.printStackTrace(); + } + + return responseString; + } + + public String saveZoneDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception{ + + FirewallDictionaryController dictionary = new FirewallDictionaryController(); + String responseString = null; + try { + ModelAndView result = dictionary.saveZoneDictionary(request, response); + responseString = result.getViewName(); + + } catch (Exception e) { + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); + e.printStackTrace(); + } + + return responseString; + } + + public String saveSecurityZoneDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception{ + + FirewallDictionaryController dictionary = new FirewallDictionaryController(); + String responseString = null; + try { + ModelAndView result = dictionary.saveSecurityZoneDictionary(request, response); + responseString = result.getViewName(); + + } catch (Exception e) { + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); + e.printStackTrace(); + } + + return responseString; + } + + public String savePrefixListDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception{ + + FirewallDictionaryController dictionary = new FirewallDictionaryController(); + String responseString = null; + try { + ModelAndView result = dictionary.savePrefixListDictionary(request, response); + responseString = result.getViewName(); + + } catch (Exception e) { + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); + e.printStackTrace(); + } + + return responseString; + } + + public String saveAddressGroupDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception{ + + FirewallDictionaryController dictionary = new FirewallDictionaryController(); + String responseString = null; + try { + ModelAndView result = dictionary.saveAddressGroupDictionary(request, response); + responseString = result.getViewName(); + + } catch (Exception e) { + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); + e.printStackTrace(); + } + + return responseString; + } + + public String saveServiceGroupDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception{ + + FirewallDictionaryController dictionary = new FirewallDictionaryController(); + String responseString = null; + try { + ModelAndView result = dictionary.saveServiceGroupDictionary(request, response); + responseString = result.getViewName(); + + } catch (Exception e) { + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); + e.printStackTrace(); + } + + return responseString; + } + + public String saveServiceListDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception{ + + FirewallDictionaryController dictionary = new FirewallDictionaryController(); + String responseString = null; + try { + ModelAndView result = dictionary.saveServiceListDictionary(request, response); + responseString = result.getViewName(); + + } catch (Exception e) { + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); + e.printStackTrace(); + } + + return responseString; + } + + public String saveTermListDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception{ + + FirewallDictionaryController dictionary = new FirewallDictionaryController(); + String responseString = null; + try { + ModelAndView result = dictionary.saveTermListDictionary(request, response); + responseString = result.getViewName(); + + } catch (Exception e) { + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); + e.printStackTrace(); + } + + return responseString; + } + + + + + public String saveMicroServiceLocationDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception{ + + MicroServiceDictionaryController dictionary = new MicroServiceDictionaryController(); + String responseString = null; + try { + ModelAndView result = dictionary.saveMicroServiceLocationDictionary(request, response); + responseString = result.getViewName(); + + } catch (Exception e) { + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); + e.printStackTrace(); + } + + return responseString; + } + + public String saveMicroServiceConfigNameDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception{ + + MicroServiceDictionaryController dictionary = new MicroServiceDictionaryController(); + String responseString = null; + try { + ModelAndView result = dictionary.saveMicroServiceConfigNameDictionary(request, response); + responseString = result.getViewName(); + + } catch (Exception e) { + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); + e.printStackTrace(); + } + + return responseString; + } + + public String saveDCAEUUIDDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception{ + + MicroServiceDictionaryController dictionary = new MicroServiceDictionaryController(); + String responseString = null; + try { + ModelAndView result = dictionary.saveDCAEUUIDDictionary(request, response); + responseString = result.getViewName(); + + } catch (Exception e) { + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); + e.printStackTrace(); + } + + return responseString; + } + + public String saveMicroServiceModelsDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception{ + + MicroServiceDictionaryController dictionary = new MicroServiceDictionaryController(); + String responseString = null; + try { + ModelAndView result = dictionary.saveMicroServiceModelsDictionary(request, response); + responseString = result.getViewName(); + + } catch (Exception e) { + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); + e.printStackTrace(); + } + + return responseString; + } + + public String saveMicroServiceDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception{ + + MicroServiceDictionaryController dictionary = new MicroServiceDictionaryController(); + String responseString = null; + try { + ModelAndView result = dictionary.saveMicroServiceAttributeDictionary(request, response); + responseString = result.getViewName(); + + } catch (Exception e) { + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); + e.printStackTrace(); + } + + return responseString; + } + + public String savePSServiceDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception{ + + PolicyScopeDictionaryController dictionary = new PolicyScopeDictionaryController(); + String responseString = null; + try { + ModelAndView result = dictionary.savePSServiceDictionary(request, response); + responseString = result.getViewName(); + + } catch (Exception e) { + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); + e.printStackTrace(); + } + + return responseString; + } + + public String savePSResourceDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception{ + + PolicyScopeDictionaryController dictionary = new PolicyScopeDictionaryController(); + String responseString = null; + try { + ModelAndView result = dictionary.savePSResourceDictionary(request, response); + responseString = result.getViewName(); + + } catch (Exception e) { + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); + e.printStackTrace(); + } + + return responseString; + } + + public String savePSTypeDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception{ + + PolicyScopeDictionaryController dictionary = new PolicyScopeDictionaryController(); + String responseString = null; + try { + ModelAndView result = dictionary.savePSTypeDictionary(request, response); + responseString = result.getViewName(); + + } catch (Exception e) { + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); + e.printStackTrace(); + } + + return responseString; + } + + public String savePSClosedLoopDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception{ + + PolicyScopeDictionaryController dictionary = new PolicyScopeDictionaryController(); + String responseString = null; + try { + ModelAndView result = dictionary.savePSClosedLoopDictionary(request, response); + responseString = result.getViewName(); + + } catch (Exception e) { + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); + e.printStackTrace(); + } + + return responseString; + } + + public String savePSGroupScopeDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception{ + + PolicyScopeDictionaryController dictionary = new PolicyScopeDictionaryController(); + String responseString = null; + try { + ModelAndView result = dictionary.savePSGroupScopeDictionary(request, response); + responseString = result.getViewName(); + + } catch (Exception e) { + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); + e.printStackTrace(); + } + + return responseString; + } + + public String saveRiskTypeDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception{ + + SafePolicyController dictionary = new SafePolicyController(); + String responseString = null; + try { + ModelAndView result = dictionary.saveRiskTypeDictionary(request, response); + responseString = result.getViewName(); + + } catch (Exception e) { + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); + e.printStackTrace(); + } + + return responseString; + } + + public String saveSafePolicyWarningDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception{ + + SafePolicyController dictionary = new SafePolicyController(); + String responseString = null; + try { + ModelAndView result = dictionary.saveSafePolicyWarningDictionary(request, response); + responseString = result.getViewName(); + + } catch (Exception e) { + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); + e.printStackTrace(); + } + + return responseString; + } + + + /* + * Methods that call the controller get methods directly to get dictionary data + */ + public void getEcompDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception{ + + DictionaryController dictionary = new DictionaryController(); + try { + dictionary.getEcompNameDictionaryEntityData(request, response); + } catch (Exception e) { + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); + e.printStackTrace(); + } + } + + public void getAttributeDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception{ + + DictionaryController dictionary = new DictionaryController(); + try { + dictionary.getAttributeDictionaryEntityData(request, response); + } catch (Exception e) { + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); + e.printStackTrace(); + } + } + + public void getActionPolicyDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception{ + + ActionPolicyDictionaryController action = new ActionPolicyDictionaryController(); + try { + action.getActionPolicyDictionaryEntityData(request, response); + } catch (Exception e) { + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); + e.printStackTrace(); + } + } + + public void getBRMSParamDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception{ + + BRMSDictionaryController dictionary = new BRMSDictionaryController(); + try { + dictionary.getBRMSParamDictionaryEntityData(request, response); + } catch (Exception e) { + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); + e.printStackTrace(); + } + + } + + public void getVSCLAction(HttpServletRequest request, HttpServletResponse response) throws Exception{ + + ClosedLoopDictionaryController dictionary = new ClosedLoopDictionaryController(); + try { + dictionary.getVSCLActionDictionaryEntityData(request, response); + } catch (Exception e) { + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); + e.printStackTrace(); + } + } + + public void getVnfType(HttpServletRequest request, HttpServletResponse response) throws Exception{ + + ClosedLoopDictionaryController dictionary = new ClosedLoopDictionaryController(); + try { + dictionary.getVNFTypeDictionaryEntityData(request, response); + + } catch (Exception e) { + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); + e.printStackTrace(); + } + + } + + public void getPEPOptions(HttpServletRequest request, HttpServletResponse response) throws Exception{ + + ClosedLoopDictionaryController dictionary = new ClosedLoopDictionaryController(); + try { + dictionary.getPEPOptionsDictionaryEntityData(request, response); + } catch (Exception e) { + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); + e.printStackTrace(); + } + } + + public void getVarbind(HttpServletRequest request, HttpServletResponse response) throws Exception{ + + ClosedLoopDictionaryController dictionary = new ClosedLoopDictionaryController(); + try { + dictionary.getVarbindDictionaryEntityData(request, response); + + } catch (Exception e) { + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); + e.printStackTrace(); + } + + } + + public void getServiceType(HttpServletRequest request, HttpServletResponse response) throws Exception{ + + ClosedLoopDictionaryController dictionary = new ClosedLoopDictionaryController(); + try { + dictionary.getClosedLoopServiceDictionaryEntityData(request, response); + } catch (Exception e) { + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); + e.printStackTrace(); + } + } + + public void getSiteType(HttpServletRequest request, HttpServletResponse response) throws Exception{ + + ClosedLoopDictionaryController dictionary = new ClosedLoopDictionaryController(); + try { + dictionary.getClosedLoopSiteDictionaryEntityData(request, response); + } catch (Exception e) { + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); + e.printStackTrace(); + } + } + + public void getSettingsDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception{ + + DecisionPolicyDictionaryController dictionary = new DecisionPolicyDictionaryController(); + try { + dictionary.getSettingsDictionaryEntityData(request, response); + + } catch (Exception e) { + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); + e.printStackTrace(); + } + } + + public void getDescriptiveDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception{ + + DescriptiveDictionaryController dictionary = new DescriptiveDictionaryController(); + try { + dictionary.getDescriptiveDictionaryEntityData(request, response); + + } catch (Exception e) { + e.printStackTrace(); + } + } + + public void getEnforcerDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception{ + + EnforcerDictionaryController dictionary = new EnforcerDictionaryController(); + try { + dictionary.getEnforcerDictionaryEntityData(request, response); + + } catch (Exception e) { + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); + e.printStackTrace(); + } + } + + public void getActionListDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception{ + + FirewallDictionaryController dictionary = new FirewallDictionaryController(); + try { + dictionary.getActionListDictionaryEntityData(request, response); + + } catch (Exception e) { + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); + e.printStackTrace(); + } + } + + public void getProtocolListDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception{ + + FirewallDictionaryController dictionary = new FirewallDictionaryController(); + try { + dictionary.getProtocolListDictionaryEntityData(request, response); + + } catch (Exception e) { + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); + e.printStackTrace(); + } + } + + public void getZoneDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception{ + + FirewallDictionaryController dictionary = new FirewallDictionaryController(); + try { + dictionary.getZoneDictionaryEntityData(request, response); + + } catch (Exception e) { + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); + e.printStackTrace(); + } + } + + public void getSecurityZoneDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception{ + + FirewallDictionaryController dictionary = new FirewallDictionaryController(); + try { + dictionary.getSecurityZoneDictionaryEntityData(request, response); + + } catch (Exception e) { + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); + e.printStackTrace(); + } + } + + public void getPrefixListDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception{ + + FirewallDictionaryController dictionary = new FirewallDictionaryController(); + try { + dictionary.getPrefixListDictionaryEntityData(request, response); + + } catch (Exception e) { + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); + e.printStackTrace(); + } + } + + public void getAddressGroupDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception{ + + FirewallDictionaryController dictionary = new FirewallDictionaryController(); + try { + dictionary.getAddressGroupDictionaryEntityData(request, response); + + } catch (Exception e) { + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); + e.printStackTrace(); + } + } + + public void getServiceGroupDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception{ + + FirewallDictionaryController dictionary = new FirewallDictionaryController(); + try { + dictionary.getServiceGroupDictionaryEntityData(request, response); + + } catch (Exception e) { + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); + e.printStackTrace(); + } + } + + public void getServiceListDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception{ + + FirewallDictionaryController dictionary = new FirewallDictionaryController(); + try { + dictionary.getServiceListDictionaryEntityData(request, response); + + } catch (Exception e) { + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); + e.printStackTrace(); + } + } + + public void getTermListDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception{ + + FirewallDictionaryController dictionary = new FirewallDictionaryController(); + try { + dictionary.getTermListDictionaryEntityData(request, response); + + } catch (Exception e) { + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); + e.printStackTrace(); + } + } + + + public void getMicroServiceLocationDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception{ + + MicroServiceDictionaryController dictionary = new MicroServiceDictionaryController(); + try { + dictionary.getMicroServiceLocationDictionaryEntityData(request, response); + + } catch (Exception e) { + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); + e.printStackTrace(); + } + } + + public void getMicroServiceConfigNameDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception{ + + MicroServiceDictionaryController dictionary = new MicroServiceDictionaryController(); + try { + dictionary.getMicroServiceConfigNameDictionaryEntityData(request, response); + + } catch (Exception e) { + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); + e.printStackTrace(); + } + } + + public void getDCAEUUIDDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception{ + + MicroServiceDictionaryController dictionary = new MicroServiceDictionaryController(); + try { + dictionary.getDCAEUUIDDictionaryEntityData(request, response); + + } catch (Exception e) { + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); + e.printStackTrace(); + } + } + + public void getMicroServiceModelsDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception{ + + MicroServiceDictionaryController dictionary = new MicroServiceDictionaryController(); + try { + dictionary.getMicroServiceModelsDictionaryEntityData(request, response); + + } catch (Exception e) { + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); + e.printStackTrace(); + } + } + + public void getMicroServiceDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception{ + + MicroServiceDictionaryController dictionary = new MicroServiceDictionaryController(); + try { + dictionary.getMicroServiceModelsDictionaryEntityData(request, response); + + } catch (Exception e) { + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); + e.printStackTrace(); + } + } + + public void getPSServiceDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception{ + + PolicyScopeDictionaryController dictionary = new PolicyScopeDictionaryController(); + try { + dictionary.getPSServiceEntityData(request, response); + + } catch (Exception e) { + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); + e.printStackTrace(); + } + } + + public void getPSResourceDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception{ + + PolicyScopeDictionaryController dictionary = new PolicyScopeDictionaryController(); + try { + dictionary.getPSResourceEntityData(request, response); + + } catch (Exception e) { + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); + e.printStackTrace(); + } + } + + public void getPSTypeDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception{ + + PolicyScopeDictionaryController dictionary = new PolicyScopeDictionaryController(); + try { + dictionary.getPSTypeEntityData(request, response); + + } catch (Exception e) { + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); + e.printStackTrace(); + } + } + + public void getPSClosedLoopDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception{ + + PolicyScopeDictionaryController dictionary = new PolicyScopeDictionaryController(); + try { + dictionary.getPSClosedLoopEntityData(request, response); + + } catch (Exception e) { + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); + e.printStackTrace(); + } + } + + public void getPSGroupScopeDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception{ + + PolicyScopeDictionaryController dictionary = new PolicyScopeDictionaryController(); + try { + dictionary.getGroupPolicyScopeEntityData(request, response); + + } catch (Exception e) { + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); + e.printStackTrace(); + } + } + + public void getRiskTypeDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception{ + + SafePolicyController dictionary = new SafePolicyController(); + try { + dictionary.getEcompNameDictionaryEntityData(request, response); + + } catch (Exception e) { + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); + e.printStackTrace(); + } + } + + public void getSafePolicyWarningDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception{ + + SafePolicyController dictionary = new SafePolicyController(); + try { + dictionary.getSafePolicyWarningeEntityData(request, response); + + } catch (Exception e) { + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); + e.printStackTrace(); + } + } +}
\ No newline at end of file diff --git a/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/service/ImportService.java b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/service/ImportService.java new file mode 100644 index 000000000..39a0485e8 --- /dev/null +++ b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/service/ImportService.java @@ -0,0 +1,151 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PAP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ +package org.openecomp.policy.pap.xacml.rest.service; + +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStreamWriter; +import java.io.Writer; +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.openecomp.policy.common.logging.eelf.PolicyLogger; +import org.openecomp.policy.pap.xacml.rest.components.CreateBRMSRuleTemplate; +import org.openecomp.policy.pap.xacml.rest.components.CreateNewMicroSerivceModel; + +public class ImportService { + + public void doImportMicroServicePut(HttpServletRequest request, HttpServletResponse response) { + String importServiceCreation = request.getParameter("importService");; + String fileName = request.getParameter("fileName"); + String version = request.getParameter("version"); + String serviceName = request.getParameter("serviceName"); + String description = request.getParameter("description"); + Map<String, String> successMap = new HashMap<String, String>(); + switch(importServiceCreation){ + case "BRMSPARAM": + StringBuilder builder = new StringBuilder(); + int ch; + try { + while((ch = request.getInputStream().read()) != -1){ + builder.append((char)ch); + } + } catch (IOException e) { + PolicyLogger.error("Error in reading in file from API call"); + response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); + response.addHeader("error", "missing"); + response.addHeader("operation", "import"); + response.addHeader("service", serviceName); + } + CreateBRMSRuleTemplate brmsRuleTemplate = new CreateBRMSRuleTemplate(); + successMap = brmsRuleTemplate.addRule(builder.toString(), serviceName, description, "API"); + break; + case "MICROSERVICE": + CreateNewMicroSerivceModel newMS = null; + String randomID = UUID.randomUUID().toString(); + if ( fileName != null) { + File extracDir = new File("ExtractDir"); + if (!extracDir.exists()){ + extracDir.mkdirs(); + } + if (fileName.contains(".xmi")){ + // get the request content into a String + String xmi = null; + java.util.Scanner scanner; + try { + scanner = new java.util.Scanner(request.getInputStream()); + scanner.useDelimiter("\\A"); + xmi = scanner.hasNext() ? scanner.next() : ""; + scanner.close(); + } catch (IOException e1) { + PolicyLogger.error("Error in reading in file from API call"); + return; + } + PolicyLogger.info("XML request from API for import new Service"); + try (Writer writer = new BufferedWriter(new OutputStreamWriter( + new FileOutputStream("ExtractDir" + File.separator + randomID+".xmi"), "utf-8"))) { + writer.write(xmi); + } catch (IOException e) { + PolicyLogger.error("Error in reading in file from API call"); + return; + } + }else{ + try { + InputStream inputStream = request.getInputStream(); + FileOutputStream outputStream = new FileOutputStream("ExtractDir" + File.separator + randomID+".zip"); + byte[] buffer = new byte[4096]; + int bytesRead = -1 ; + while ((bytesRead = inputStream.read(buffer)) != -1) { + outputStream.write(buffer, 0, bytesRead) ; + } + outputStream.close() ; + inputStream.close() ; + } catch (IOException e) { + PolicyLogger.error("Error in reading in Zip File from API call"); + return; + } + } + newMS = new CreateNewMicroSerivceModel(fileName, serviceName, "API", version, randomID); + successMap = newMS.addValuesToNewModel(); + if (successMap.containsKey("success")) { + successMap.clear(); + successMap = newMS.saveImportService(); + } + } + break; + } + // return a response to the PAP + if (successMap.containsKey("success")) { + response.setStatus(HttpServletResponse.SC_OK); + response.addHeader("successMapKey", "success"); + response.addHeader("operation", "import"); + response.addHeader("service", serviceName); + } else if (successMap.containsKey("DBError")) { + if (successMap.get("DBError").contains("EXISTS")){ + response.setStatus(HttpServletResponse.SC_CONFLICT); + response.addHeader("service", serviceName); + response.addHeader("error", "modelExistsDB"); + }else{ + response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); + response.addHeader("error", "importDB"); + } + response.addHeader("operation", "import"); + response.addHeader("service", serviceName); + }else if (successMap.get("error").contains("MISSING")){ + response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); + response.addHeader("error", "missing"); + response.addHeader("operation", "import"); + response.addHeader("service", serviceName); + }else if (successMap.get("error").contains("VALIDATION")){ + response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); + response.addHeader("error", "validation"); + response.addHeader("operation", "import"); + response.addHeader("service", serviceName); + } + } + +} diff --git a/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/service/MetricService.java b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/service/MetricService.java new file mode 100644 index 000000000..21a630125 --- /dev/null +++ b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/service/MetricService.java @@ -0,0 +1,93 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PAP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ +package org.openecomp.policy.pap.xacml.rest.service; + +import java.util.HashSet; +import java.util.Set; + +import javax.persistence.EntityManager; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.json.JSONObject; +import org.openecomp.policy.common.logging.eelf.MessageCodes; +import org.openecomp.policy.common.logging.eelf.PolicyLogger; +import org.openecomp.policy.pap.xacml.rest.XACMLPapServlet; +import org.openecomp.policy.xacml.api.XACMLErrorConstants; +import org.openecomp.policy.xacml.api.pap.EcompPDPGroup; + +import com.att.research.xacml.api.pap.PDPPolicy; + +public class MetricService { + + public static void doGetPolicyMetrics(HttpServletRequest request, HttpServletResponse response) { + Set<EcompPDPGroup> groups = new HashSet<EcompPDPGroup>(); + try { + //get the count of policies on the PDP + if(XACMLPapServlet.getPAPEngine()!=null){ + groups = XACMLPapServlet.getPAPEngine().getEcompPDPGroups(); + } + int pdpCount = 0; + for (EcompPDPGroup group : groups) { + Set<PDPPolicy> policies = group.getPolicies(); + pdpCount += policies.size(); + } + //get the count of policies on the PAP + EntityManager em = null; + if(XACMLPapServlet.getEmf()!=null){ + em = (EntityManager) XACMLPapServlet.getEmf().createEntityManager(); + } + if (em==null){ + PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE + " Error creating entity manager with persistence unit: " + XACMLPapServlet.getPersistenceUnit()); + response.setStatus(HttpServletResponse.SC_BAD_REQUEST); + response.addHeader("error", "Error creating entity manager with persistence unit"); + return; + } + int papCount = ((Number) em.createNamedQuery("PolicyVersion.findAllCount").getSingleResult()).intValue(); + em.close(); + int totalCount = pdpCount + papCount; + //create json string for API response + JSONObject json = new JSONObject(); + json.put("papCount", papCount); + json.put("pdpCount", pdpCount); + json.put("totalCount", totalCount); + if (pdpCount>0 && papCount>0 && totalCount>0) { + PolicyLogger.info("Metrics have been found on the Policy Engine for the number of policies on the PAP and PDP."); + response.setStatus(HttpServletResponse.SC_OK); + response.addHeader("successMapKey", "success"); + response.addHeader("operation", "getMetrics"); + response.addHeader("metrics", json.toString() ); + return; + }else{ + String message = "The policy count on the PAP and PDP is 0. Please check the database and file system to correct this error."; + response.setStatus(HttpServletResponse.SC_BAD_REQUEST); + response.addHeader("error", message); + return; + } + } catch (Exception e) { + String message = XACMLErrorConstants.ERROR_DATA_ISSUE + " Error Querying the Database: " + e.getMessage(); + PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, e, "XACMLPapServlet", " Error Querying the Database."); + response.setStatus(HttpServletResponse.SC_BAD_REQUEST); + response.addHeader("error", message); + return; + } + } + +} |