From: Michael Mokry Date: Fri, 7 Jul 2017 21:00:59 +0000 (-0500) Subject: [POLICY-67] Add new Rainy Day Decision Policy X-Git-Tag: v1.1.0~122 X-Git-Url: https://gerrit.onap.org/r/gitweb?p=policy%2Fengine.git;a=commitdiff_plain;h=eb654437ee2815028602daa943d0a939a5bee3cd [POLICY-67] Add new Rainy Day Decision Policy Change-Id: I8fb730e4363c885ccbe3a05ae971c5de5608d70c Signed-off-by: Michael Mokry --- diff --git a/ECOMP-PAP-REST/src/main/java/hibernate.cfg.xml b/ECOMP-PAP-REST/src/main/java/hibernate.cfg.xml index a898c57aa..e2ba058e8 100644 --- a/ECOMP-PAP-REST/src/main/java/hibernate.cfg.xml +++ b/ECOMP-PAP-REST/src/main/java/hibernate.cfg.xml @@ -39,7 +39,8 @@ - + + diff --git a/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/components/DecisionPolicy.java b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/components/DecisionPolicy.java index 02ea630a6..180b989e7 100644 --- a/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/components/DecisionPolicy.java +++ b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/components/DecisionPolicy.java @@ -88,7 +88,8 @@ public class DecisionPolicy extends Policy { public static final String FUNCTION_NOT = "urn:oasis:names:tc:xacml:1.0:function:not"; private static final String AAFProvider = "AAF"; public static final String GUARD_YAML = "GUARD_YAML"; - public static final String GUARD_BL_YAML = "GUARD_BL_YAML"; + public static final String GUARD_BL_YAML = "GUARD_BL_YAML"; + public static final String RAINY_DAY = "Rainy_Day"; private static final String XACML_GUARD_TEMPLATE = "Decision_GuardPolicyTemplate.xml"; private static final String XACML_BLGUARD_TEMPLATE = "Decision_GuardBLPolicyTemplate.xml"; @@ -235,9 +236,21 @@ public class DecisionPolicy extends Policy { VariableDefinitionType dynamicVariable = createDynamicVariable(key, value, dataType); decisionPolicy.getCombinerParametersOrRuleCombinerParametersOrVariableDefinition().add(dynamicVariable); } + + + Map dynamicFieldTreatmentAttributes = policyAdapter.getRainydayMap(); + + if(policyAdapter.getRuleProvider().equals(RAINY_DAY)){ + for(String keyField : dynamicFieldTreatmentAttributes.keySet()) { + String errorcode = keyField; + String treatment = dynamicFieldTreatmentAttributes.get(errorcode); + createRainydayRule(decisionPolicy, errorcode, treatment, true); + } + } else { + createRule(decisionPolicy, true); + createRule(decisionPolicy, false); + } - createRule(decisionPolicy, true); - createRule(decisionPolicy, false); } setPreparedToSave(true); @@ -483,6 +496,87 @@ public class DecisionPolicy extends Policy { } + private void createRainydayRule(PolicyType decisionPolicy, String errorcode, String treatment, boolean permitRule) { + RuleType rule = new RuleType(); + + rule.setRuleId(UUID.randomUUID().toString()); + + if (permitRule) { + rule.setEffect(EffectType.PERMIT); + } else { + rule.setEffect(EffectType.DENY); + } + rule.setTarget(new TargetType()); + + // Create Target in Rule + AllOfType allOfInRule = new AllOfType(); + + // Creating match for ACCESS in rule target + MatchType accessMatch = new MatchType(); + AttributeValueType accessAttributeValue = new AttributeValueType(); + accessAttributeValue.setDataType(STRING_DATATYPE); + accessAttributeValue.getContent().add("DECIDE"); + accessMatch.setAttributeValue(accessAttributeValue); + AttributeDesignatorType accessAttributeDesignator = new AttributeDesignatorType(); + URI accessURI = null; + try { + accessURI = new URI(ACTION_ID); + } catch (URISyntaxException e) { + PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, e, "DecisionPolicy", "Exception creating ACCESS URI"); + } + accessAttributeDesignator.setCategory(CATEGORY_ACTION); + accessAttributeDesignator.setDataType(STRING_DATATYPE); + accessAttributeDesignator.setAttributeId(new IdentifierImpl(accessURI).stringValue()); + accessMatch.setAttributeDesignator(accessAttributeDesignator); + accessMatch.setMatchId(FUNCTION_STRING_EQUAL_IGNORE); + + allOfInRule.getMatch().add(accessMatch); + + // Creating match for ErrorCode in rule target + MatchType errorcodeMatch = new MatchType(); + AttributeValueType errorcodeAttributeValue = new AttributeValueType(); + errorcodeAttributeValue.setDataType(STRING_DATATYPE); + errorcodeAttributeValue.getContent().add(errorcode); + errorcodeMatch.setAttributeValue(errorcodeAttributeValue); + AttributeDesignatorType errorcodeAttributeDesignator = new AttributeDesignatorType(); + errorcodeAttributeDesignator.setCategory(CATEGORY_ACTION); + errorcodeAttributeDesignator.setDataType(STRING_DATATYPE); + errorcodeAttributeDesignator.setAttributeId("ErrorCode"); + errorcodeMatch.setAttributeDesignator(errorcodeAttributeDesignator); + errorcodeMatch.setMatchId(FUNCTION_STRING_EQUAL_IGNORE); + + allOfInRule.getMatch().add(errorcodeMatch); + + AnyOfType anyOfInRule = new AnyOfType(); + anyOfInRule.getAllOf().add(allOfInRule); + + TargetType targetInRule = new TargetType(); + targetInRule.getAnyOf().add(anyOfInRule); + + rule.setTarget(targetInRule); + + AdviceExpressionsType adviceExpressions = new AdviceExpressionsType(); + AdviceExpressionType adviceExpression = new AdviceExpressionType(); + adviceExpression.setAdviceId(RAINY_DAY); + adviceExpression.setAppliesTo(EffectType.PERMIT); + + AttributeAssignmentExpressionType assignment = new AttributeAssignmentExpressionType(); + assignment.setAttributeId("treatment"); + assignment.setCategory(CATEGORY_RESOURCE); + + AttributeValueType treatmentAttributeValue = new AttributeValueType(); + treatmentAttributeValue.setDataType(STRING_DATATYPE); + treatmentAttributeValue.getContent().add(treatment); + assignment.setExpression(new ObjectFactory().createAttributeValue(treatmentAttributeValue)); + + adviceExpression.getAttributeAssignmentExpression().add(assignment); + adviceExpressions.getAdviceExpression().add(adviceExpression); + rule.setAdviceExpressions(adviceExpressions); + decisionPolicy.getCombinerParametersOrRuleCombinerParametersOrVariableDefinition().add(rule); + policyAdapter.setPolicyData(decisionPolicy); + + } + // if compound setting the inner apply here protected ApplyType getInnerDecisionApply(String value1Label) { ApplyType decisionApply = new ApplyType(); diff --git a/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/controller/DecisionPolicyDictionaryController.java b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/controller/DecisionPolicyDictionaryController.java index db3ebda44..fc525bbe3 100644 --- a/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/controller/DecisionPolicyDictionaryController.java +++ b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/controller/DecisionPolicyDictionaryController.java @@ -21,7 +21,9 @@ package org.openecomp.policy.pap.xacml.rest.controller; import java.io.PrintWriter; +import java.util.ArrayList; import java.util.HashMap; +import java.util.LinkedHashMap; import java.util.List; import java.util.Map; @@ -35,6 +37,7 @@ import org.openecomp.policy.pap.xacml.rest.util.JsonMessage; import org.openecomp.policy.rest.dao.CommonClassDao; import org.openecomp.policy.rest.jpa.Datatype; import org.openecomp.policy.rest.jpa.DecisionSettings; +import org.openecomp.policy.rest.jpa.RainyDayTreatments; import org.openecomp.policy.rest.jpa.UserInfo; import org.openecomp.policy.xacml.api.XACMLErrorConstants; import org.springframework.beans.factory.annotation.Autowired; @@ -238,4 +241,184 @@ public class DecisionPolicyDictionaryController { return null; } + + + @RequestMapping(value={"/get_RainyDayDictionaryDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) + public void getRainyDayDictionaryByNameEntityData(HttpServletRequest request, HttpServletResponse response){ + try{ + Map model = new HashMap<>(); + ObjectMapper mapper = new ObjectMapper(); + model.put("rainyDayDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(RainyDayTreatments.class, "bbID"))); + JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); + JSONObject j = new JSONObject(msg); + response.getWriter().write(j.toString()); + } + catch (Exception e){ + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); + } + } + + + @RequestMapping(value={"/get_RainyDayDictionaryData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) + public void getRainyDayDictionaryEntityData(HttpServletRequest request, HttpServletResponse response){ + try{ + Map model = new HashMap<>(); + ObjectMapper mapper = new ObjectMapper(); + model.put("rainyDayDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(RainyDayTreatments.class))); + JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); + JSONObject j = new JSONObject(msg); + response.addHeader("successMapKey", "success"); + response.addHeader("operation", "getDictionary"); + response.getWriter().write(j.toString()); + } + catch (Exception e){ + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); + response.setStatus(HttpServletResponse.SC_BAD_REQUEST); + response.addHeader("error", "dictionaryDBQuery"); + } + } + + @RequestMapping(value={"/decision_dictionary/save_RainyDay"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + public ModelAndView saveRainyDayDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception{ + try { + boolean duplicateflag = false; + boolean isFakeUpdate = false; + boolean fromAPI = false; + if (request.getParameter("apiflag")!=null && request.getParameter("apiflag").equalsIgnoreCase("api")) { + fromAPI = true; + } + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + JsonNode root = mapper.readTree(request.getReader()); + RainyDayTreatments decisionRainyDay; + TreatmentValues treatmentsData = null; + if (fromAPI) { + decisionRainyDay = (RainyDayTreatments)mapper.readValue(root.get("dictionaryFields").toString(), RainyDayTreatments.class); + treatmentsData = (TreatmentValues)mapper.readValue(root.get("dictionaryFields").toString(), TreatmentValues.class); + //check if update operation or create, get id for data to be updated and update attributeData + if (request.getParameter("operation").equals("update")) { + List duplicateData = commonClassDao.checkDuplicateEntry(decisionRainyDay.getBbid()+":"+decisionRainyDay.getWorkstep(), "bbid:workstep", RainyDayTreatments.class); + int id = 0; + RainyDayTreatments data = (RainyDayTreatments) duplicateData.get(0); + id = data.getId(); + if(id==0){ + isFakeUpdate=true; + } else { + decisionRainyDay.setId(id); + } + } + } else { + decisionRainyDay = (RainyDayTreatments)mapper.readValue(root.get("rainyDayDictionaryData").toString(), RainyDayTreatments.class); + treatmentsData = (TreatmentValues)mapper.readValue(root.get("rainyDayDictionaryData").toString(), TreatmentValues.class); + } + + String userValue = ""; + int counter = 0; + if(treatmentsData.getUserDataTypeValues().size() > 0){ + for(Object treatment : treatmentsData.getUserDataTypeValues()){ + if(treatment instanceof LinkedHashMap){ + String key = ((LinkedHashMap) treatment).get("treatment").toString(); + if(counter>0){ + userValue = userValue + ","; + } + userValue = userValue + key ; + counter ++; + } + } + } + decisionRainyDay.setTreatments(userValue); + + if(decisionRainyDay.getId() == 0){ + List duplicateData = commonClassDao.checkDuplicateEntry(decisionRainyDay.getBbid()+":"+decisionRainyDay.getWorkstep(), "bbid:workstep", RainyDayTreatments.class); + if(!duplicateData.isEmpty()){ + duplicateflag = true; + }else{ + commonClassDao.save(decisionRainyDay); + } + }else{ + if(!isFakeUpdate) { + commonClassDao.update(decisionRainyDay); + } + } + String responseString = ""; + if(duplicateflag){ + responseString = "Duplicate"; + }else{ + responseString = mapper.writeValueAsString(commonClassDao.getData(RainyDayTreatments.class)); + } + + if (fromAPI) { + if (responseString!=null && !responseString.equals("Duplicate")) { + if(isFakeUpdate){ + responseString = "Exists"; + } else { + responseString = "Success"; + } + } + ModelAndView result = new ModelAndView(); + result.setViewName(responseString); + return result; + } else { + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + JSONObject j = new JSONObject("{rainyDayDictionaryDatas: " + responseString + "}"); + out.write(j.toString()); + return null; + } + + }catch (Exception e){ + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); + response.setCharacterEncoding("UTF-8"); + request.setCharacterEncoding("UTF-8"); + PrintWriter out = response.getWriter(); + out.write(e.getMessage()); + } + return null; + } + + @RequestMapping(value={"/decision_dictionary/remove_rainyDay"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + public ModelAndView removeRainyDayDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception { + try{ + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + JsonNode root = mapper.readTree(request.getReader()); + RainyDayTreatments decisionRainyDay = (RainyDayTreatments)mapper.readValue(root.get("data").toString(), RainyDayTreatments.class); + commonClassDao.delete(decisionRainyDay); + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + + String responseString = mapper.writeValueAsString(commonClassDao.getData(RainyDayTreatments.class)); + JSONObject j = new JSONObject("{rainyDayDictionaryDatas: " + responseString + "}"); + out.write(j.toString()); + + return null; + } + catch (Exception e){ + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); + response.setCharacterEncoding("UTF-8"); + request.setCharacterEncoding("UTF-8"); + PrintWriter out = response.getWriter(); + out.write(e.getMessage()); + } + return null; + } + +} + +class TreatmentValues { + private ArrayList userDataTypeValues; + + public ArrayList getUserDataTypeValues() { + return userDataTypeValues; + } + + public void setUserDataTypeValues(ArrayList userDataTypeValues) { + this.userDataTypeValues = userDataTypeValues; + } } diff --git a/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/handler/DeleteHandler.java b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/handler/DeleteHandler.java index dd8cc656a..693196517 100644 --- a/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/handler/DeleteHandler.java +++ b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/handler/DeleteHandler.java @@ -158,7 +158,7 @@ public class DeleteHandler { getPolicyVersion.setParameter("pname", removeVersionExtension.replace(".", File.separator)); List pvResult = getPolicyVersion.getResultList(); PolicyVersion pVersion = (PolicyVersion) pvResult.get(0); - int highestVersion = 0; + int newVersion = 0; em.getTransaction().begin(); Class.forName(papDbDriver); con = DriverManager.getConnection(papDbUrl,papDbUser,papDbPassword); @@ -180,7 +180,7 @@ public class DeleteHandler { return; }else if(status.equals("PolicyInPDP")){ PolicyLogger.error(MessageCodes.GENERAL_WARNING + "Policy can't be deleted, it is active in PDP Groups."); - response.addHeader("error", "unknown"); + response.addHeader("error", "PolicyInPDP"); response.setStatus(HttpServletResponse.SC_CONFLICT); return; }else{ @@ -217,13 +217,13 @@ public class DeleteHandler { policyEntity = (PolicyEntity) object; String policyEntityName = policyEntity.getPolicyName().replace(".xml", ""); int policyEntityVersion = Integer.parseInt(policyEntityName.substring(policyEntityName.lastIndexOf(".")+1)); - if(policyEntityVersion > highestVersion){ - highestVersion = policyEntityVersion; + if(policyEntityVersion > newVersion){ + newVersion = policyEntityVersion-1; } } } - pVersion.setActiveVersion(highestVersion); - pVersion.setHigherVersion(highestVersion); + pVersion.setActiveVersion(newVersion); + pVersion.setHigherVersion(newVersion); try{ policyVersionDeleted = true; em.persist(pVersion); diff --git a/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/policycontroller/PolicyCreation.java b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/policycontroller/PolicyCreation.java index 3437dab03..0d84519d3 100644 --- a/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/policycontroller/PolicyCreation.java +++ b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/policycontroller/PolicyCreation.java @@ -82,6 +82,14 @@ public class PolicyCreation extends AbstractPolicyCreation{ private static CommonClassDao commonClassDao; + public static CommonClassDao getCommonClassDao() { + return commonClassDao; + } + + public static void setCommonClassDao(CommonClassDao commonClassDao) { + PolicyCreation.commonClassDao = commonClassDao; + } + @Autowired public PolicyCreation(CommonClassDao commonClassDao){ PolicyCreation.commonClassDao = commonClassDao; @@ -334,12 +342,15 @@ public class PolicyCreation extends AbstractPolicyCreation{ } else if (policyType.equalsIgnoreCase("Decision")) { if(policyData.getApiflag() == null){ Map settingsMap = new HashMap<>(); + Map treatmentMap = new HashMap<>(); List dynamicRuleAlgorithmLabels = new LinkedList<>(); List dynamicRuleAlgorithmCombo = new LinkedList<>(); List dynamicRuleAlgorithmField1 = new LinkedList<>(); List dynamicRuleAlgorithmField2 = new LinkedList<>(); List dynamicVariableList = new LinkedList<>(); List dataTypeList = new LinkedList<>(); + List errorCodeList = new LinkedList<>(); + List treatmentList = new LinkedList<>(); if(policyData.getSettings().size() > 0){ for(Object settingsData : policyData.getSettings()){ @@ -365,7 +376,8 @@ public class PolicyCreation extends AbstractPolicyCreation{ } } if(policyData.getRuleProvider()!=null && (policyData.getRuleProvider().equals(DecisionPolicy.GUARD_YAML)|| policyData.getRuleProvider().equals(DecisionPolicy.GUARD_BL_YAML)) - && policyData.getYamlparams()!=null){ attributeMap.put("actor", policyData.getYamlparams().getActor()); + && policyData.getYamlparams()!=null){ + attributeMap.put("actor", policyData.getYamlparams().getActor()); attributeMap.put("recipe", policyData.getYamlparams().getRecipe()); attributeMap.put("limit", policyData.getYamlparams().getLimit()); attributeMap.put("timeWindow", policyData.getYamlparams().getTimeWindow()); @@ -376,6 +388,23 @@ public class PolicyCreation extends AbstractPolicyCreation{ attributeMap.put("blackList", blackList); } } + if(policyData.getRuleProvider()!=null && policyData.getRuleProvider().equals(DecisionPolicy.RAINY_DAY)){ + attributeMap.put("ServiceType", policyData.getRainyday().getServiceType()); + attributeMap.put("VNFType", policyData.getRainyday().getVnfType()); + attributeMap.put("BB_ID", policyData.getRainyday().getBbid()); + attributeMap.put("WorkStep", policyData.getRainyday().getWorkstep()); + + if(policyData.getRainyday().getTreatmentTableChoices()!=null && policyData.getRainyday().getTreatmentTableChoices().size() > 0){ + for (Object table : policyData.getRainyday().getTreatmentTableChoices()){ + if(table instanceof LinkedHashMap){ + String errorcode = ((LinkedHashMap) table).get("errorcode").toString(); + String treatment = ((LinkedHashMap) table).get("treatment").toString(); + treatmentMap.put(errorcode, treatment); + } + } + } + } + policyData.setDynamicRuleAlgorithmLabels(dynamicRuleAlgorithmLabels); policyData.setDynamicRuleAlgorithmCombo(dynamicRuleAlgorithmCombo); policyData.setDynamicRuleAlgorithmField1(dynamicRuleAlgorithmField1); @@ -384,6 +413,9 @@ public class PolicyCreation extends AbstractPolicyCreation{ policyData.setDynamicSettingsMap(settingsMap); policyData.setDynamicFieldConfigAttributes(attributeMap); policyData.setDataTypeList(dataTypeList); + policyData.setRainydayMap(treatmentMap); + policyData.setErrorCodeList(errorCodeList); + policyData.setTreatmentList(treatmentList); } newPolicy = new DecisionPolicy(policyData); } @@ -480,7 +512,7 @@ public class PolicyCreation extends AbstractPolicyCreation{ } } catch (Exception e){ - LOGGER.error("Exception Occured"+e); + LOGGER.error("Exception Occured : "+e); } return new ResponseEntity(body, status); } diff --git a/ECOMP-REST/src/main/java/org/openecomp/policy/rest/adapter/PolicyRestAdapter.java b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/adapter/PolicyRestAdapter.java index 8c54f2a2d..27da724e2 100644 --- a/ECOMP-REST/src/main/java/org/openecomp/policy/rest/adapter/PolicyRestAdapter.java +++ b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/adapter/PolicyRestAdapter.java @@ -127,6 +127,12 @@ public class PolicyRestAdapter { private String actionDictMethod = null; private YAMLParams yamlparams; + //Rainy Day Decision + private RainyDayParams rainyday; + private Map rainydayMap; + private List errorCodeList; + private List treatmentList; + //MicroSerice private String serviceType = null; private String uuid = null; @@ -150,7 +156,7 @@ public class PolicyRestAdapter { private String riskLevel; private String guard = null; private String ttlDate; - private Map matching; + private Map matching; private ArrayList triggerSignatures; private ArrayList symptomSignatures; @@ -839,4 +845,52 @@ public class PolicyRestAdapter { public void setYamlparams(YAMLParams yamlparams) { this.yamlparams = yamlparams; } + /** + * @return the rainyday + */ + public RainyDayParams getRainyday() { + return rainyday; + } + /** + * @param rainyday the rainyday to set + */ + public void setRainyday(RainyDayParams rainyday) { + this.rainyday = rainyday; + } + /** + * @return the errorCodeList + */ + public List getErrorCodeList() { + return errorCodeList; + } + /** + * @param errorCodeList the errorCodeList to set + */ + public void setErrorCodeList(List errorCodeList) { + this.errorCodeList = errorCodeList; + } + /** + * @return the treatmentList + */ + public List getTreatmentList() { + return treatmentList; + } + /** + * @param treatmentList the treatmentList to set + */ + public void setTreatmentList(List treatmentList) { + this.treatmentList = treatmentList; + } + /** + * @return the rainydayMap + */ + public Map getRainydayMap() { + return rainydayMap; + } + /** + * @param rainydayMap the rainydayMap to set + */ + public void setRainydayMap(Map rainydayMap) { + this.rainydayMap = rainydayMap; + } } diff --git a/ECOMP-REST/src/main/java/org/openecomp/policy/rest/adapter/RainyDayParams.java b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/adapter/RainyDayParams.java new file mode 100644 index 000000000..8fdcc0ffb --- /dev/null +++ b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/adapter/RainyDayParams.java @@ -0,0 +1,100 @@ +package org.openecomp.policy.rest.adapter; + +import java.util.ArrayList; +import java.util.List; + +public class RainyDayParams { + private String serviceType; + private String vnfType; + private String bbid; + private String workstep; + private ArrayList treatmentTableChoices; + private List errorcode; + private List treatment; + + /** + * @return the serviceType + */ + public String getServiceType() { + return serviceType; + } + /** + * @param serviceType the serviceType to set + */ + public void setServiceType(String serviceType) { + this.serviceType = serviceType; + } + /** + * @return the vnfType + */ + public String getVnfType() { + return vnfType; + } + /** + * @param vnfType the vnfType to set + */ + public void setVnfType(String vnfType) { + this.vnfType = vnfType; + } + /** + * @return the workstep + */ + public String getWorkstep() { + return workstep; + } + /** + * @param workstep the workstep to set + */ + public void setWorkstep(String workstep) { + this.workstep = workstep; + } + /** + * @return the bbid + */ + public String getBbid() { + return bbid; + } + /** + * @param bbid the bbid to set + */ + public void setBbid(String bbid) { + this.bbid = bbid; + } + /** + * @return the treatmentTableChoices + */ + public ArrayList getTreatmentTableChoices() { + return treatmentTableChoices; + } + /** + * @param treatmentTableChoices the treatmentTableChoices to set + */ + public void setTreatmentTableChoices(ArrayList treatmentTableChoices) { + this.treatmentTableChoices = treatmentTableChoices; + } + /** + * @return the errorcode + */ + public List getErrorcode() { + return errorcode; + } + /** + * @param errorcode the errorcode to set + */ + public void setErrorcode(List errorcode) { + this.errorcode = errorcode; + } + /** + * @return the treatment + */ + public List getTreatment() { + return treatment; + } + /** + * @param treatment the treatment to set + */ + public void setTreatment(List treatment) { + this.treatment = treatment; + } + +} diff --git a/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/RainyDayTreatments.java b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/RainyDayTreatments.java new file mode 100644 index 000000000..7219c7d36 --- /dev/null +++ b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/RainyDayTreatments.java @@ -0,0 +1,118 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-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.rest.jpa; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; + +import javax.persistence.NamedQuery; +import javax.persistence.OrderBy; +import javax.persistence.Table; + +import java.io.Serializable; + +/** + * The persistent class for the RainyDayTreatment database table. + * + */ +@Entity +@Table(name="RainyDayTreatments") +@NamedQuery(name="RainyDayTreatments.findAll", query="SELECT e FROM RainyDayTreatments e") +public class RainyDayTreatments implements Serializable { + /** + * + */ + private static final long serialVersionUID = -2491410352490381323L; + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + @Column(name="id") + private int id; + + @Column(name="bbid", nullable=false, length=255) + @OrderBy("asc") + private String bbid; + + @Column(name="workstep", nullable=true, length=255) + private String workstep; + + @Column(name="treatments", nullable=true, length=1028) + private String treatments; + + public RainyDayTreatments() { + + } + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + /** + * @return the bbid + */ + public String getBbid() { + return bbid; + } + + /** + * @param bbid the bbid to set + */ + public void setBbid(String bbid) { + this.bbid = bbid; + } + + /** + * @return the workstep + */ + public String getWorkstep() { + return workstep; + } + + /** + * @param workstep the workstep to set + */ + public void setWorkstep(String workstep) { + this.workstep = workstep; + } + + /** + * @return the treatments + */ + public String getTreatments() { + return treatments; + } + + /** + * @param treatments the treatments to set + */ + public void setTreatments(String treatments) { + this.treatments = treatments; + } + + +} \ No newline at end of file diff --git a/POLICY-SDK-APP/src/main/java/org/openecomp/policy/controller/DecisionPolicyController.java b/POLICY-SDK-APP/src/main/java/org/openecomp/policy/controller/DecisionPolicyController.java index 28278062d..ef43135c2 100644 --- a/POLICY-SDK-APP/src/main/java/org/openecomp/policy/controller/DecisionPolicyController.java +++ b/POLICY-SDK-APP/src/main/java/org/openecomp/policy/controller/DecisionPolicyController.java @@ -32,12 +32,15 @@ import javax.xml.bind.JAXBElement; import org.openecomp.policy.common.logging.flexlogger.FlexLogger; import org.openecomp.policy.common.logging.flexlogger.Logger; import org.openecomp.policy.rest.adapter.PolicyRestAdapter; +import org.openecomp.policy.rest.adapter.RainyDayParams; import org.openecomp.policy.rest.adapter.YAMLParams; import org.openecomp.policy.rest.jpa.PolicyEntity; import org.openecomp.portalsdk.core.controller.RestrictedBaseController; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.AdviceExpressionType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.AdviceExpressionsType; import oasis.names.tc.xacml._3_0.core.schema.wd_17.AllOfType; import oasis.names.tc.xacml._3_0.core.schema.wd_17.AnyOfType; import oasis.names.tc.xacml._3_0.core.schema.wd_17.ApplyType; @@ -63,6 +66,7 @@ public class DecisionPolicyController extends RestrictedBaseController { private ArrayList attributeList; private ArrayList decisionList; private ArrayList ruleAlgorithmList; + private ArrayList treatmentList = null; protected LinkedList ruleAlgoirthmTracker; public static final String FUNCTION_NOT = "urn:oasis:names:tc:xacml:1.0:function:not"; @@ -71,7 +75,10 @@ public class DecisionPolicyController extends RestrictedBaseController { attributeList = new ArrayList<>(); decisionList = new ArrayList<>(); ruleAlgorithmList = new ArrayList<>(); + treatmentList = new ArrayList<>(); + if (policyAdapter.getPolicyData() instanceof PolicyType) { + RainyDayParams rainydayParams = new RainyDayParams(); Object policyData = policyAdapter.getPolicyData(); PolicyType policy = (PolicyType) policyData; policyAdapter.setOldPolicyFileName(policyAdapter.getPolicyName()); @@ -133,6 +140,24 @@ public class DecisionPolicyController extends RestrictedBaseController { } } } + // Setting rainy day attributes to the parameters object if they exist + if(!attributeList.isEmpty()) { + for(int i=0; i map = (Map)attributeList.get(i); + if(map.get("key").equals("WorkStep")){ + rainydayParams.setWorkstep(map.get("value")); + }else if(map.get("key").equals("BB_ID")){ + rainydayParams.setBbid(map.get("value")); + }else if(map.get("key").equals("ServiceType")){ + rainydayParams.setServiceType(map.get("value")); + }else if(map.get("key").equals("VNFType")){ + rainydayParams.setVnfType(map.get("value")); + } + } + } + + policyAdapter.setRuleProvider("Rainy_Day"); + } List ruleList = policy.getCombinerParametersOrRuleCombinerParametersOrVariableDefinition(); @@ -203,15 +228,40 @@ public class DecisionPolicyController extends RestrictedBaseController { prePopulateDecisionCompoundRuleAlgorithm(index, decisionApply); policyAdapter.setRuleAlgorithmschoices(ruleAlgorithmList); } + } else if (((RuleType) object).getEffect().equals(EffectType.PERMIT)) { + + TargetType ruleTarget = ((RuleType) object).getTarget(); + AdviceExpressionsType adviceExpression = ((RuleType) object).getAdviceExpressions(); + + String errorcode = ruleTarget.getAnyOf().get(0).getAllOf().get(0).getMatch(). + get(1).getAttributeValue().getContent().get(0).toString(); + JAXBElement tempTreatmentObj = (JAXBElement) adviceExpression.getAdviceExpression(). + get(0).getAttributeAssignmentExpression().get(0).getExpression(); + String treatment = tempTreatmentObj.getValue().getContent().get(0).toString(); + + prePopulateRainyDayTreatments(errorcode, treatment); + } } } } + + rainydayParams.setTreatmentTableChoices(treatmentList); + policyAdapter.setRainyday(rainydayParams); policyAdapter.setSettings(decisionList); } } + private void prePopulateRainyDayTreatments(String errorcode, String treatment) { + Map ruleMap = new HashMap<>(); + + ruleMap.put("errorcode", errorcode); + ruleMap.put("treatment", treatment); + treatmentList.add(ruleMap); + + } + private void prePopulateDecisionRuleAlgorithms(int index, ApplyType decisionApply, List> jaxbDecisionTypes) { Map ruleMap = new HashMap<>(); ruleMap.put("id", "A" + (index +1)); @@ -293,6 +343,7 @@ public class DecisionPolicyController extends RestrictedBaseController { ruleAlgorithmList.add(rule); index++; } + return index; } } diff --git a/POLICY-SDK-APP/src/main/java/org/openecomp/policy/controller/PolicyValidationController.java b/POLICY-SDK-APP/src/main/java/org/openecomp/policy/controller/PolicyValidationController.java index ed47fd949..cc6903b91 100644 --- a/POLICY-SDK-APP/src/main/java/org/openecomp/policy/controller/PolicyValidationController.java +++ b/POLICY-SDK-APP/src/main/java/org/openecomp/policy/controller/PolicyValidationController.java @@ -438,6 +438,35 @@ public class PolicyValidationController extends RestrictedBaseController { responseString.append("Ecomp Name: Ecomp Name Should not be empty" + "
"); valid = false; } + + if("Rainy_Day".equals(policyData.getRuleProvider())){ + if(policyData.getRainyday()==null){ + responseString.append(" Rainy Day Parameters are Required
"); + valid = false; + }else{ + if(policyData.getRainyday().getServiceType()==null){ + responseString.append("Rainy Day Service Type is Required
"); + valid = false; + } + if(policyData.getRainyday().getVnfType()==null){ + responseString.append("Rainy Day VNF Type is Required
"); + valid = false; + } + if(policyData.getRainyday().getBbid()==null){ + responseString.append("Rainy Day Building Block ID is Required
"); + valid = false; + } + if(policyData.getRainyday().getWorkstep()==null){ + responseString.append("Rainy Day Work Step is Required
"); + valid = false; + } + if(policyData.getRainyday().getServiceType()==null){ + responseString.append("Rainy Day Error Code is Required
"); + valid = false; + } + } + } + if("GUARD_YAML".equals(policyData.getRuleProvider()) || "GUARD_BL_YAML".equals(policyData.getRuleProvider())){ if(policyData.getYamlparams()==null){ responseString.append(" Guard Params are Required " + "
"); diff --git a/POLICY-SDK-APP/src/main/webapp/app/policyApp/Windows/Dictionary/DecisionRainyDayDictionary.html b/POLICY-SDK-APP/src/main/webapp/app/policyApp/Windows/Dictionary/DecisionRainyDayDictionary.html new file mode 100644 index 000000000..62f5a4800 --- /dev/null +++ b/POLICY-SDK-APP/src/main/webapp/app/policyApp/Windows/Dictionary/DecisionRainyDayDictionary.html @@ -0,0 +1,73 @@ + + diff --git a/POLICY-SDK-APP/src/main/webapp/app/policyApp/controller/DictionaryController.js b/POLICY-SDK-APP/src/main/webapp/app/policyApp/controller/DictionaryController.js index 243591f22..cf0d0961c 100644 --- a/POLICY-SDK-APP/src/main/webapp/app/policyApp/controller/DictionaryController.js +++ b/POLICY-SDK-APP/src/main/webapp/app/policyApp/controller/DictionaryController.js @@ -24,7 +24,7 @@ var subDictionarys = [["Action Dictionary"], ["BRMS Controller" , "BRMS Dependency", "BRMS Param Template"], ["Attribute Dictionary","EcompName Dictionary"], ["PEP Options","Site Dictionary","Service Dictionary","Varbind Dictionary", "VNF Type","VSCL Action"], - ["Settings Dictionary"], + ["Settings Dictionary","Rainy Day Allowed Treatments"], ["Descriptive Scope"], ["Action List", "Address Group", "Parent Dictionary List", "Port List", "Prefix List", "Protocol List", "Security Zone", "Service Group", "Service List", "Tag List", "Tag Picker List", "Term List", "Zone"], ["DCAE UUID","MicroService ConfigName","MicroService Location", "MicroService Models", "MicroService Dictionary"], diff --git a/POLICY-SDK-APP/src/main/webapp/app/policyApp/controller/dictionaryController/DecisionRainyDayDictController.js b/POLICY-SDK-APP/src/main/webapp/app/policyApp/controller/dictionaryController/DecisionRainyDayDictController.js new file mode 100644 index 000000000..fc34fa7ca --- /dev/null +++ b/POLICY-SDK-APP/src/main/webapp/app/policyApp/controller/dictionaryController/DecisionRainyDayDictController.js @@ -0,0 +1,100 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * 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========================================================= + */ +app.controller('editRainyDayDictController' , function ($scope, $modalInstance, message, UserInfoServiceDS2, Notification){ + + if(message.rainyDayDictionaryData==null) + $scope.label='Add Allowed Treatments', + $scope.treatments = []; + else{ + $scope.treatments = []; + $scope.label='Edit Treatment' + $scope.disableCd=true; + var headers = message.rainyDayDictionaryData.treatments; + var splitEqual = ','; + if(headers != null && headers != ""){ + if (headers.indexOf(splitEqual) >= 0) { + var splitValue = headers.split(splitEqual); + for(i = 0; i < splitValue.length; i++){ + var key = splitValue[i]; + $scope.treatments.push({'treatment': key}); + } + }else{ + var key = headers; + $scope.treatments.push({'treatment': key}); + } + } + } + + + /*getting user info from session*/ + var userid = null; + UserInfoServiceDS2.getFunctionalMenuStaticDetailSession() + .then(function (response) { + userid = response.userid; + }); + + $scope.editRainyDayTreatment = message.rainyDayDictionaryData; + $scope.saveDecisionTreatments = function(rainyDayDictionaryData) { + var finalData = extend(rainyDayDictionaryData, $scope.treatmentDatas[0]); + var uuu = "saveDictionary/decision_dictionary/save_RainyDay"; + var postData={rainyDayDictionaryData: rainyDayDictionaryData, userid: userid}; + $.ajax({ + type : 'POST', + url : uuu, + dataType: 'json', + contentType: 'application/json', + data: JSON.stringify(postData), + success : function(data){ + $scope.$apply(function(){ + $scope.rainyDayDictionaryDatas=data.rainyDayDictionaryDatas;}); + if($scope.rainyDayDictionaryDatas == "Duplicate"){ + Notification.error("Allowed Treatments Dictionary exists with Same Building Block and Workstep.") + }else{ + console.log($scope.rainyDayDictionaryDatas); + $modalInstance.close({rainyDayDictionaryDatas:$scope.rainyDayDictionaryDatas}); + } + }, + error : function(data){ + alert("Error while saving."); + } + }); + }; + + function extend(obj, src) { + for (var key in src) { + if (src.hasOwnProperty(key)) obj[key] = src[key]; + } + return obj; + } + + $scope.treatmentDatas = [{"userDataTypeValues" : $scope.treatments}]; + $scope.addNewTreatment = function() { + $scope.treatments.push({}); + }; + $scope.removeTreatment = function() { + var lastItem = $scope.treatments.length-1; + $scope.treatments.splice(lastItem); + }; + + + $scope.close = function() { + $modalInstance.close(); + }; +}); \ No newline at end of file diff --git a/POLICY-SDK-APP/src/main/webapp/app/policyApp/controller/dictionaryGridController/DecisionRainyDayDictGridController.js b/POLICY-SDK-APP/src/main/webapp/app/policyApp/controller/dictionaryGridController/DecisionRainyDayDictGridController.js new file mode 100644 index 000000000..e4fa18645 --- /dev/null +++ b/POLICY-SDK-APP/src/main/webapp/app/policyApp/controller/dictionaryGridController/DecisionRainyDayDictGridController.js @@ -0,0 +1,153 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * 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========================================================= + */ +app.controller('decisionRainyDayDictGridController', function ($scope, PolicyAppService, modalService, $modal){ + $( "#dialog" ).hide(); + + PolicyAppService.getData('getDictionary/get_RainyDayDictionaryData').then(function (data) { + var j = data; + $scope.data = JSON.parse(j.data); + console.log($scope.data); + $scope.rainyDayDictionaryDatas = JSON.parse($scope.data.rainyDayDictionaryDatas); + console.log($scope.rainyDayDictionaryDatas); + }, function (error) { + console.log("failed"); + }); + + PolicyAppService.getData('get_LockDownData').then(function(data){ + var j = data; + $scope.data = JSON.parse(j.data); + $scope.lockdowndata = JSON.parse($scope.data.lockdowndata); + if($scope.lockdowndata[0].lockdown == true){ + $scope.decisionRainyDayDictionaryGrid.columnDefs[0].visible = false; + $scope.gridApi.grid.refresh(); + }else{ + $scope.decisionRainyDayDictionaryGrid.columnDefs[0].visible = true; + $scope.gridApi.grid.refresh(); + } + },function(error){ + console.log("failed"); + }); + $scope.decisionRainyDayDictionaryGrid = { + data : 'rainyDayDictionaryDatas', + enableFiltering: true, + exporterCsvFilename: 'AllowedTreatments.csv', + enableGridMenu: true, + enableSelectAll: true, + columnDefs: [{ + field: 'id', enableFiltering: false, headerCellTemplate: '' + + '', + cellTemplate: + ' ' + + ' ', width: '8%' + }, + {field: 'bbid', displayName : 'Building Block ID', sort: { direction: 'asc', priority: 0 }}, + {field: 'workstep', displayName : 'Work Step' }, + {field: 'treatments', displayName : 'Allowed Treatments'} + ], + exporterMenuPdf: false, + exporterPdfDefaultStyle: {fontSize: 9}, + exporterPdfTableStyle: {margin: [30, 30, 30, 30]}, + exporterPdfTableHeaderStyle: {fontSize: 10, bold: true, italics: true, color: 'red'}, + exporterPdfHeader: { text: "My Header", style: 'headerStyle' }, + exporterPdfFooter: function ( currentPage, pageCount ) { + return { text: currentPage.toString() + ' of ' + pageCount.toString(), style: 'footerStyle' }; + }, + exporterPdfCustomFormatter: function ( docDefinition ) { + docDefinition.styles.headerStyle = { fontSize: 22, bold: true }; + docDefinition.styles.footerStyle = { fontSize: 10, bold: true }; + return docDefinition; + }, + exporterPdfOrientation: 'portrait', + exporterPdfPageSize: 'LETTER', + exporterPdfMaxGridWidth: 500, + exporterCsvLinkElement: angular.element(document.querySelectorAll(".custom-csv-link-location")), + onRegisterApi: function(gridApi){ + $scope.gridApi = gridApi; + } + }; + + $scope.editRainyDayTreatment = null; + $scope.createNewRainyDayDictWindow = function(){ + $scope.editRainyDayTreatment = null; + var modalInstance = $modal.open({ + backdrop: 'static', keyboard: false, + templateUrl : 'add_RainyDayDict_popup.html', + controller: 'editRainyDayDictController', + resolve: { + message: function () { + var message = { + rainyDayDictionaryDatas: $scope.editRainyDayTreatment + }; + return message; + } + } + }); + modalInstance.result.then(function(response){ + console.log('response', response); + $scope.rainyDayDictionaryDatas=response.rainyDayDictionaryDatas; + }); + }; + + $scope.editRainyDayDictWindow = function(rainyDayDictionaryData) { + $scope.editRainyDayTreatment = rainyDayDictionaryData; + var modalInstance = $modal.open({ + backdrop: 'static', keyboard: false, + templateUrl : 'add_RainyDayDict_popup.html', + controller: 'editRainyDayDictController', + resolve: { + message: function () { + var message = { + rainyDayDictionaryData: $scope.editRainyDayTreatment + }; + return message; + } + } + }); + modalInstance.result.then(function(response){ + console.log('response', response); + $scope.rainyDayDictionaryDatas = response.rainyDayDictionaryDatas; + }); + }; + + $scope.deleteRainyDayDict = function(data) { + modalService.popupConfirmWin("Confirm","You are about to delete the Rainy Day Allowed Treatment Dictionary "+data.allowedTreatments+". Do you want to continue?", + function(){ + var uuu = "deleteDictionary/decision_dictionary/remove_rainyDay"; + var postData={data: data}; + $.ajax({ + type : 'POST', + url : uuu, + dataType: 'json', + contentType: 'application/json', + data: JSON.stringify(postData), + success : function(data){ + $scope.$apply(function(){$scope.rainyDayDictionaryDatas=data.rainyDayDictionaryDatas;}); + }, + error : function(data){ + console.log(data); + modalService.showFailure("Fail","Error while deleting: "+ data.responseText); + } + }); + + }) + }; + + +}); \ No newline at end of file diff --git a/POLICY-SDK-APP/src/main/webapp/app/policyApp/main/policyEditor.html b/POLICY-SDK-APP/src/main/webapp/app/policyApp/main/policyEditor.html index fe822d4c3..50a1e53f5 100644 --- a/POLICY-SDK-APP/src/main/webapp/app/policyApp/main/policyEditor.html +++ b/POLICY-SDK-APP/src/main/webapp/app/policyApp/main/policyEditor.html @@ -134,6 +134,7 @@ + @@ -176,6 +177,7 @@ + @@ -240,6 +242,7 @@
+
diff --git a/POLICY-SDK-APP/src/main/webapp/app/policyApp/policy-models/Dictionary/DecisionRainyDayDictionary.html b/POLICY-SDK-APP/src/main/webapp/app/policyApp/policy-models/Dictionary/DecisionRainyDayDictionary.html new file mode 100644 index 000000000..a81111518 --- /dev/null +++ b/POLICY-SDK-APP/src/main/webapp/app/policyApp/policy-models/Dictionary/DecisionRainyDayDictionary.html @@ -0,0 +1,22 @@ + +
+
+
\ No newline at end of file diff --git a/POLICY-SDK-APP/src/main/webapp/app/policyApp/policy-models/Editor/PolicyTemplateController/DecisionPolicyController.js b/POLICY-SDK-APP/src/main/webapp/app/policyApp/policy-models/Editor/PolicyTemplateController/DecisionPolicyController.js index e7858d7b5..4b5a990ef 100644 --- a/POLICY-SDK-APP/src/main/webapp/app/policyApp/policy-models/Editor/PolicyTemplateController/DecisionPolicyController.js +++ b/POLICY-SDK-APP/src/main/webapp/app/policyApp/policy-models/Editor/PolicyTemplateController/DecisionPolicyController.js @@ -80,8 +80,6 @@ angular.module('abs').controller('decisionPolicyController', ['$scope', 'PolicyA console.log("failed"); }); - - function extend(obj, src) { for (var key in src) { if (src.hasOwnProperty(key)) obj[key] = src[key]; @@ -171,6 +169,13 @@ angular.module('abs').controller('decisionPolicyController', ['$scope', 'PolicyA if(!$scope.temp.policy.yamlparams.blackList){ $scope.temp.policy.yamlparams.blackList = []; } + if(!$scope.temp.policy.rainyday){ + $scope.temp.policy.rainyday = {}; + } + if(!$scope.temp.policy.rainyday.treatmentTableChoices){ + $scope.temp.policy.rainyday.treatmentTableChoices = []; + } + }else if($scope.temp.policy.ruleProvider=="Custom"){ if($scope.temp.policy.attributes.length == 0){ $scope.temp.policy.attributes = []; @@ -182,8 +187,12 @@ angular.module('abs').controller('decisionPolicyController', ['$scope', 'PolicyA $scope.temp.policy.ruleAlgorithmschoices = []; } }else if($scope.temp.policy.ruleProvider=="GUARD_BL_YAML"){ - if($scope.temp.policy.yamlparams.blackList.length==0){ - $scope.temp.policy.yamlparams.blackList = []; + if($scope.temp.policy.yamlparams.blackList.length==0){ + $scope.temp.policy.yamlparams.blackList = []; + } + }else if($scope.temp.policy.ruleProvider=="Rainy_Day"){ + if($scope.temp.policy.rainyday.treatmentTableChoices == null || $scope.temp.policy.rainyday.treatmentTableChoices.length == 0){ + $scope.temp.policy.rainyday.treatmentTableChoices = []; } } $scope.attributeDatas = [{"attributes" : $scope.temp.policy.attributes}]; @@ -196,7 +205,6 @@ angular.module('abs').controller('decisionPolicyController', ['$scope', 'PolicyA $scope.temp.policy.attributes.splice(lastItem); }; - $scope.settingsDatas = [{"settings" : $scope.temp.policy.settings}]; $scope.addNewSettingsChoice = function() { var newItemNo = $scope.temp.policy.settings.length+1; @@ -215,6 +223,15 @@ angular.module('abs').controller('decisionPolicyController', ['$scope', 'PolicyA $scope.temp.policy.yamlparams.blackList.splice(lastItem); }; + $scope.treatmentDatas = [{"treatmentValues" : $scope.temp.policy.rainyday.treatmentTableChoices}]; + $scope.addNewTreatment = function() { + $scope.temp.policy.rainyday.treatmentTableChoices.push({}); + }; + $scope.removeTreatment = function() { + var lastItem = $scope.temp.policy.rainyday.treatmentTableChoices.length-1; + $scope.temp.policy.rainyday.treatmentTableChoices.splice(lastItem); + }; + $scope.ItemNo = 0; $scope.ruleAlgorithmDatas = [{"ruleAlgorithms" : $scope.temp.policy.ruleAlgorithmschoices }]; diff --git a/POLICY-SDK-APP/src/main/webapp/app/policyApp/policy-models/Editor/PolicyTemplates/DecisionPolicyTemplate.html b/POLICY-SDK-APP/src/main/webapp/app/policyApp/policy-models/Editor/PolicyTemplates/DecisionPolicyTemplate.html index 637ecff03..49fc70df4 100644 --- a/POLICY-SDK-APP/src/main/webapp/app/policyApp/policy-models/Editor/PolicyTemplates/DecisionPolicyTemplate.html +++ b/POLICY-SDK-APP/src/main/webapp/app/policyApp/policy-models/Editor/PolicyTemplates/DecisionPolicyTemplate.html @@ -31,13 +31,102 @@ ng-click="providerListener(temp.policy.ruleProvider);"> +