+ /**
+ * Format Tca Policy Content JSON
+ *
+ * @param refProp
+ * The refProp generally created by Spring, it's an access on the
+ * clds-references.properties file
+ * @param modelProperties
+ * The Model Prop created from BPMN JSON and BPMN properties JSON
+ * @return The Json string containing that should be sent to policy
+ */
+ public static JsonNode createPolicyContent(RefProp refProp, ModelProperties modelProperties, String service, String policyName, Tca tca) {
+ try {
+ if (null == service) {
+ service = modelProperties.getGlobal().getService();
+ }
+ if (null == tca){
+ tca = modelProperties.getType(Tca.class);
+ modelProperties.setCurrentModelElementId(tca.getId());
+ }
+ if (null == policyName) {
+ policyName = refProp.getStringValue("tca.policyid.prefix") + modelProperties.getCurrentPolicyScopeAndPolicyName();
+ }
+ ObjectNode rootNode = (ObjectNode) refProp.getJsonTemplate("tca.template", service);
+ ((ObjectNode) rootNode.get("metricsPerEventName").get(0)).put("eventName", tca.getTcaItem().getEventName());
+ ((ObjectNode) rootNode.get("metricsPerEventName").get(0)).put("policyName", policyName);
+ ((ObjectNode) rootNode.get("metricsPerEventName").get(0)).put("controlLoopSchemaType", tca.getTcaItem().getControlLoopSchemaType());
+ ObjectNode thresholdsParent = ((ObjectNode) rootNode.get("metricsPerEventName").get(0));
+
+ addThresholds(refProp, service, thresholdsParent, tca.getTcaItem(), modelProperties);
+
+ logger.info("tcaPolicyContent=" + rootNode.toString());
+ return (JsonNode) rootNode;
+ } catch (Exception e) {
+ throw new TcaRequestFormatterException("Exception caught when attempting to create the policy content JSON", e);
+ }
+ }
+