Policy TestSuite Enabled
[policy/engine.git] / POLICY-SDK-APP / src / main / java / org / openecomp / policy / controller / PolicyValidationController.java
index 55bff24..d9d0fc9 100644 (file)
@@ -48,6 +48,8 @@ import javax.xml.parsers.SAXParserFactory;
 import org.apache.commons.lang.StringUtils;
 import org.dom4j.util.XMLErrorHandler;
 import org.json.JSONObject;
+import org.openecomp.policy.common.logging.flexlogger.FlexLogger;
+import org.openecomp.policy.common.logging.flexlogger.Logger;
 import org.openecomp.policy.rest.adapter.ClosedLoopFaultBody;
 import org.openecomp.policy.rest.adapter.ClosedLoopPMBody;
 import org.openecomp.policy.rest.adapter.PolicyRestAdapter;
@@ -76,6 +78,8 @@ import com.google.common.base.Strings;
 @RequestMapping("/")
 public class PolicyValidationController extends RestrictedBaseController {
 
+       private static final Logger LOGGER      = FlexLogger.getLogger(PolicyValidationController.class);
+       
        public static final String CONFIG_POLICY = "Config";
        public static final String ACTION_POLICY = "Action";
        public static final String DECISION_POLICY = "Decision";
@@ -448,7 +452,44 @@ public class PolicyValidationController extends RestrictedBaseController {
                                        responseString = responseString + "Ecomp Name: Ecomp Name Should not be empty" + "<br>";
                                        valid = false;
                                }
-
+                               if(policyData.getRuleProvider().equals("GUARD_YAML")){
+                                       if(policyData.getYamlparams()==null){
+                                               responseString = responseString + "<b> Guard Params are Required </b>" + "<br>";
+                                               valid = false;
+                                       }else{
+                                               if(policyData.getYamlparams().getActor()==null){
+                                                       responseString = responseString + "Guard Params <b>Actor</b> is Required " + "<br>";
+                                                       valid = false;
+                                               }
+                                               if(policyData.getYamlparams().getRecipe()==null){
+                                                       responseString = responseString + "Guard Params <b>Recipe</b> is Required " + "<br>";
+                                                       valid = false;
+                                               }
+                                               if(policyData.getYamlparams().getLimit()==null){
+                                                       responseString = responseString + " Guard Params <b>Limit</b> is Required " + "<br>";
+                                                       valid = false;
+                                               }else{
+                                                       try{
+                                                               Integer.parseInt(policyData.getYamlparams().getLimit());
+                                                       }catch(NumberFormatException e){
+                                                               responseString = responseString + " Guard Params <b>Limit</b> Should be Integer " + "<br>";
+                                                               valid = false;
+                                                       }
+                                               }
+                                               if(policyData.getYamlparams().getTimeWindow()==null){
+                                                       responseString = responseString + "Guard Params <b>Time Window</b> is Required" + "<br>";
+                                                       valid = false;
+                                               }
+                                               if(policyData.getYamlparams().getGuardActiveStart()==null){
+                                                       responseString = responseString + "Guard Params <b>Guard Active Start/b>is Required " + "<br>";
+                                                       valid = false;
+                                               }
+                                               if(policyData.getYamlparams().getGuardActiveEnd()==null){
+                                                       responseString = responseString + "Guard Params <b>Guard Active End</b>is Required " + "<br>";
+                                                       valid = false;
+                                               }
+                                       }
+                               }
                        }
 
                        if(policyData.getPolicyType().equals(ACTION_POLICY)){
@@ -607,7 +648,7 @@ public class PolicyValidationController extends RestrictedBaseController {
                        JsonReader jsonReader = Json.createReader(stream);
                        System.out.println("Json Value is: " + jsonReader.read().toString() );
                } catch (Exception e) {
-                       e.printStackTrace();
+                       LOGGER.error("Exception Occured"+e);
                        return false;
                }
                return true;