- mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
- JsonNode root = mapper.readTree(request.getReader());
- PolicyRestAdapter policyData = (PolicyRestAdapter)mapper.readValue(root.get("policyData").toString(), PolicyRestAdapter.class);
- if(policyData.getPolicyName() != null){
- String policyNameValidate = emptyValidator(policyData.getPolicyName());
- if(!policyNameValidate.contains("success")){
- responseString.append("PolicyName:" + policyNameValidate + "<br>");
- valid = false;
- };
- }else{
- responseString.append( "PolicyName: PolicyName Should not be empty" + "<br>");
- valid = false;
- }
- if(policyData.getPolicyDescription() != null){
- String descriptionValidate = descriptionValidator(policyData.getPolicyDescription());
- if(!descriptionValidate.contains("success")){
- responseString.append("Description:" + descriptionValidate + "<br>");
- valid = false;
- }
- }
-
- if(policyData.getPolicyType().equals(CONFIG_POLICY)){
- if (policyData.getConfigPolicyType().equals("Base") || policyData.getConfigPolicyType().equals(CLOSEDLOOP_POLICY)
- || policyData.getConfigPolicyType().equals(CLOSEDLOOP_PM) || policyData.getConfigPolicyType().equals(ENFORCER_CONFIG_POLICY) || policyData.getConfigPolicyType().equals(MICROSERVICES)) {
- if(policyData.getOnapName() != null){
- String onapNameValidate = emptyValidator(policyData.getOnapName());
- if(!onapNameValidate.contains("success")){
- responseString.append("OnapName:" + onapNameValidate + "<br>");
- valid = false;
- }
- }else{
- responseString.append("Onap Name: Onap Name Should not be empty" + "<br>");
- valid = false;
- }
- }
-
- if(policyData.getRiskType() != null){
- String riskTypeValidate = emptyValidator(policyData.getRiskType());
- if(!riskTypeValidate.contains("success")){
- responseString.append("RiskType:" + riskTypeValidate + "<br>");
- valid = false;
- }
- }else {
- responseString.append("Risk Type: Risk Type Should not be Empty" + "<br>");
- valid = false;
- }
-
- if(policyData.getRiskLevel() != null){
- String validateRiskLevel = emptyValidator(policyData.getRiskLevel());
- if(!validateRiskLevel.contains("success")){
- responseString.append("RiskLevel:" + validateRiskLevel + "<br>");
- valid = false;
- }
- }else {
- responseString.append("Risk Level: Risk Level Should not be Empty" + "<br>");
- valid = false;
- }
-
- if(policyData.getGuard() != null){
- String validateGuard = emptyValidator(policyData.getGuard());
- if(!validateGuard.contains("success")){
- responseString.append("Guard:" + validateGuard + "<br>");
- valid = false;
- }
- }else {
- responseString.append("Guard: Guard Value Should not be Empty" + "<br>");
- valid = false;
- }
-
- if(policyData.getConfigPolicyType().equals("Base")){
- if(policyData.getConfigName() != null){
- String configNameValidate = emptyValidator(policyData.getConfigName());
- if(!configNameValidate.contains("success")){
- responseString.append("ConfigName:" + configNameValidate + "<br>");
- valid = false;
- }
- }else{
- responseString.append("Config Name: Config Name Should not be Empty" + "<br>");
- valid = false;
- }
- if(policyData.getConfigType() != null){
- String configTypeValidate = emptyValidator(policyData.getConfigType());
- if(!configTypeValidate.contains("success")){
- responseString.append("ConfigType:" + configTypeValidate + "<br>");
- valid = false;
- }
- }else{
- responseString.append("Config Type: Config Type Should not be Empty" + "<br>");
- valid = false;
- }
- if(policyData.getConfigBodyData() != null){
- String configBodyData = policyData.getConfigBodyData();
- String policyType = policyData.getConfigType();
- if (policyType != null) {
- if (policyType.equals("JSON")) {
- if (!isJSONValid(configBodyData)) {
- responseString.append("Config Body: JSON Content is not valid" + "<br>");
- valid = false;
- }
- } else if (policyType.equals("XML")) {
- if (!isXMLValid(configBodyData)) {
- responseString.append("Config Body: XML Content data is not valid" + "<br>");
- valid = false;
- }
- } else if (policyType.equals("PROPERTIES")) {
- if (!isPropValid(configBodyData)||configBodyData.equals("")) {
- responseString.append("Config Body: Property data is not valid" + "<br>");
- valid = false;
- }
- } else if (policyType.equals("OTHER")) {
- if (configBodyData.equals("")) {
- responseString.append("Config Body: Config Body Should not be Empty" + "<br>");
- valid = false;
- }
- }
- }
- }else{
- responseString.append("Config Body: Config Body Should not be Empty" + "<br>");
- valid = false;
- }
- }
-
- if(policyData.getConfigPolicyType().equals("Firewall Config")){
- if(policyData.getConfigName() != null){
- String configNameValidate = PolicyUtils.emptyPolicyValidator(policyData.getConfigName());
- if(!configNameValidate.contains("success")){
- responseString.append("<b>ConfigName</b>:<i>" + configNameValidate + "</i><br>");
- valid = false;
- }
- }else{
- responseString.append("<b>Config Name</b>:<i> Config Name is required" + "</i><br>");
- valid = false;
- }
- if(policyData.getSecurityZone() == null){
- responseString.append("<b>Security Zone</b>:<i> Security Zone is required" + "</i><br>");
- valid = false;
- }
- }
- if(policyData.getConfigPolicyType().equals("BRMS_Param")){
- if(policyData.getRuleName() == null){
- responseString.append("<b>BRMS Template</b>:<i>BRMS Template is required</i><br>");
- valid = false;
- }
- }
- if(policyData.getConfigPolicyType().equals("BRMS_Raw")){
- if(policyData.getConfigBodyData() != null){
- String message = PolicyUtils.brmsRawValidate(policyData.getConfigBodyData());
- // If there are any error other than Annotations then this is not Valid
- if(message.contains("[ERR")){
- responseString.append("<b>Raw Rule Validate</b>:<i>Raw Rule has error"+ message +"</i><br>");
- valid = false;
- }
- }else{
- responseString.append("<b>Raw Rule</b>:<i>Raw Rule is required</i><br>");
- valid = false;
- }
- }
- if(policyData.getConfigPolicyType().equals("ClosedLoop_PM")){
- try{
- if(root.get("policyData").get("verticaMetrics").get("serviceTypePolicyName") == null && policyData.getServiceTypePolicyName().isEmpty()){
- responseString.append("<b>ServiceType PolicyName</b>:<i>ServiceType PolicyName is required</i><br>");
- valid = false;
- }
- }catch(Exception e){
- LOGGER.error("ERROR in ClosedLoop_PM PolicyName" , e);
- responseString.append("<b>ServiceType PolicyName</b>:<i>ServiceType PolicyName is required</i><br>");
- valid = false;
- }
-
- if(root.get("policyData").get("jsonBodyData") != null){
- ClosedLoopPMBody pmBody = (ClosedLoopPMBody)mapper.readValue(root.get("policyData").get("jsonBodyData").toString(), ClosedLoopPMBody.class);
- if(pmBody.getEmailAddress() != null){
- String result = emailValidation(pmBody.getEmailAddress(), responseString.toString());
- if(result != "success"){
- responseString.append(result + "<br>");
- valid = false;
- }
- }
- if(pmBody.getGeoLink() != null){
- String result = PolicyUtils.emptyPolicyValidator(pmBody.getGeoLink());
- if(!result.contains("success")){
- responseString.append("<b>GeoLink</b>:<i>" + result + "</i><br>");
- valid = false;
- };
- }
- if(pmBody.getAttributes() != null){
- for(Entry<String, String> entry : pmBody.getAttributes().entrySet()){
- String key = entry.getKey();
- String value = entry.getValue();
- if(!key.contains("Message")){
- String attributeValidate = PolicyUtils.emptyPolicyValidator(value);
- if(!attributeValidate.contains("success")){
- responseString.append("<b>Attributes</b>:<i>" + key + " : value has spaces</i><br>");
- valid = false;
- };
- }
- }
- }
- }else{
- responseString.append("<b>D2/Virtualized Services</b>:<i>Select atleast one D2/Virtualized Services</i><br>");
- valid = false;
- }
- }
- if(policyData.getConfigPolicyType().equals("ClosedLoop_Fault")){
- if(root.get("policyData").get("jsonBodyData") != null){
- ClosedLoopFaultBody faultBody = (ClosedLoopFaultBody)mapper.readValue(root.get("policyData").get("jsonBodyData").toString(), ClosedLoopFaultBody.class);
- if(faultBody.getEmailAddress() != null){
- String result = emailValidation(faultBody.getEmailAddress(), responseString.toString());
- if(result != "success"){
- responseString.append(result+ "<br>");
- valid = false;
- }
- }
- if((faultBody.isGama() || faultBody.isMcr() || faultBody.isTrinity() || faultBody.isvDNS() || faultBody.isvUSP()) != true){
- responseString.append("<b>D2/Virtualized Services</b>:<i>Select atleast one D2/Virtualized Services</i><br>");
- valid = false;
- }
- if(faultBody.getActions() == null){
- responseString.append("<b>vPRO Actions</b>:<i>vPRO Actions is required</i><br>");
- valid = false;
- }
- if(faultBody.getClosedLoopPolicyStatus() == null){
- responseString.append("<b>Policy Status</b>:<i>Policy Status is required</i><br>");
- valid = false;
- }
- if(faultBody.getConditions() == null){
- responseString.append("<b>Conditions</b>:<i>Select Atleast one Condition</i><br>");
- valid = false;
- }
- if(faultBody.getGeoLink() != null){
- String result = PolicyUtils.emptyPolicyValidatorWithSpaceAllowed(faultBody.getGeoLink());
- if(!result.contains("success")){
- responseString.append("<b>GeoLink</b>:<i>" + result + "</i><br>");
- valid = false;
- };
- }
-
- if(faultBody.getTimeInterval() == 0){
- responseString.append("<b>Time Interval</b>:<i>Time Interval is required</i><br>");
- valid = false;
- }
- if(faultBody.getRetrys() == 0){
- responseString.append("<b>Number of Retries</b>:<i>Number of Retries is required</i><br>");
- valid = false;
- }
- if(faultBody.getTimeOutvPRO() == 0){
- responseString.append("<b>APP-C Timeout</b>:<i>APP-C Timeout is required</i><br>");
- valid = false;
- }
- if(faultBody.getTimeOutRuby() == 0){
- responseString.append("<b>TimeOutRuby</b>:<i>TimeOutRuby is required</i><br>");
- valid = false;
- }
- if(faultBody.getVnfType() == null){
- responseString.append("<b>Vnf Type</b>:<i>Vnf Type is required</i><br>");
- valid = false;
- }
- }else{
- responseString.append("<b>D2/Virtualized Services</b>:<i>Select atleast one D2/Virtualized Services</i><br>");
- responseString.append("<b>vPRO Actions</b>:<i>vPRO Actions is required</i><br>");
- responseString.append("<b>Aging Window</b>:<i>Aging Window is required</i><br>");
- responseString.append("<b>Policy Status</b>:<i>Policy Status is required</i><br>");
- responseString.append("<b>Conditions</b>:<i>Select Atleast one Condition</i><br>");
- responseString.append("<b>PEP Name</b>:<i>PEP Name is required</i><br>");
- responseString.append("<b>PEP Action</b>:<i>PEP Action is required</i><br>");
- responseString.append("<b>Time Interval</b>:<i>Time Interval is required</i><br>");
- responseString.append("<b>Number of Retries</b>:<i>Number of Retries is required</i><br>");
- responseString.append("<b>APP-C Timeout</b>:<i>APP-C Timeout is required</i><br>");
- responseString.append("<b>TimeOutRuby</b>:<i>TimeOutRuby is required</i><br>");
- responseString.append("<b>Vnf Type</b>:<i>Vnf Type is required</i><br>");
- valid = false;
- }
- }