- policyParameters.setRequestID(UUID.randomUUID());
- // Set Safe Policy value for Risk Type
- SimpleDateFormat dateformat3 = new SimpleDateFormat("dd/MM/yyyy");
- Date date = dateformat3.parse("15/10/2016");
- policyParameters.setTtlDate(date);
- // Set Safe Policy value for Guard
- policyParameters.setGuard(true);
- // Set Safe Policy value for Risk Level
- policyParameters.setRiskLevel("5");
- // Set Safe Policy value for Risk Type
- policyParameters.setRiskType("PROD");
-
- // API method to create or update Policy.
- PolicyChangeResponse response = null;
- if (!isEdit) {
- response = policyEngine.createPolicy(policyParameters);
- }
- else {
- response = policyEngine.updatePolicy(policyParameters);
- }
-
- if(response.getResponseCode()==200){
- System.out.println(response.getResponseMessage());
- System.out.println("Policy Created Successfully!");
- }else{
- System.out.println("Error! " + response.getResponseMessage());
- }
- } catch (Exception e) {
- System.err.println(e.getMessage());
- }
- }
+ // Builds JSONObject from File
+ private static JsonObject buildJson(File jsonInput, String jsonString) throws FileNotFoundException {
+ JsonObject json = null;;
+ JsonReader jsonReader = null;
+ if (jsonString != null && jsonInput == null) {
+ StringReader in = null;
+ in = new StringReader(jsonString);
+ jsonReader = Json.createReader(in);
+ json = jsonReader.readObject();
+ in.close();
+ } else {
+ InputStream in = null;
+ in = new FileInputStream(jsonInput);
+ jsonReader = Json.createReader(in);
+ json = jsonReader.readObject();
+ try {
+ in.close();
+ } catch (IOException e) {
+ System.err.println("Exception Occured while closing input stream" + e);
+ }
+ }
+ jsonReader.close();
+
+ return json;
+ }
+
+ /**
+ * main.
+ *
+ * @param args String[] args
+ */
+ public static void main(String[] args) {
+ try {
+ PolicyEngine policyEngine = new PolicyEngine("config.properties");
+ PolicyParameters policyParameters = new PolicyParameters();
+ // Set Policy Type
+ policyParameters.setPolicyConfigType(PolicyConfigType.ClosedLoop_Fault);
+ policyParameters.setPolicyName("MikeAPItests.ClosedLoopFaultApiTest45");
+ policyParameters.setPolicyDescription("This is a sample ClosedLoop_Fault policy CREATE example");
+ // policyParameters.setPolicyScope("MikeAPItests");
+
+ // Set up Micro Services Attributes
+ File jsonFile = null;
+ String msJsonString = null;
+ Path file = Paths.get("C:\\policyAPI\\ClosedLoopJSON\\faultTestJson.json");
+ jsonFile = file.toFile();
+
+ policyParameters.setConfigBody(buildJson(jsonFile, msJsonString).toString());
+ policyParameters.setConfigBodyType(PolicyType.JSON);
+
+ policyParameters.setRequestID(UUID.randomUUID());
+ // Set Safe Policy value for Risk Type
+ SimpleDateFormat dateformat3 = new SimpleDateFormat("dd/MM/yyyy");
+ Date date = dateformat3.parse("15/10/2016");
+ policyParameters.setTtlDate(date);
+ // Set Safe Policy value for Guard
+ policyParameters.setGuard(true);
+ // Set Safe Policy value for Risk Level
+ policyParameters.setRiskLevel("5");
+ // Set Safe Policy value for Risk Type
+ policyParameters.setRiskType("PROD");
+
+ // API method to create or update Policy.
+ PolicyChangeResponse response = null;
+ if (!isEdit) {
+ response = policyEngine.createPolicy(policyParameters);
+ } else {
+ response = policyEngine.updatePolicy(policyParameters);
+ }
+
+ if (response.getResponseCode() == 200) {
+ System.out.println(response.getResponseMessage());
+ System.out.println("Policy Created Successfully!");
+ } else {
+ System.out.println("Error! " + response.getResponseMessage());
+ }
+ } catch (Exception e) {
+ System.err.println(e.getMessage());
+ }
+ }