- private JsonObject generateJsonRepresentation(PolicyModel policyModel) {
- JsonObject jsonReturned = new JsonObject();
- if (policyModel == null) {
- return new JsonObject();
- }
- try {
- if (isLegacy()) {
- // Op policy Legacy case
- LegacyOperationalPolicy.preloadConfiguration(jsonReturned, loop);
- jsonReturned =
- OperationalPolicyRepresentationBuilder.generateOperationalPolicySchema(loop.getModelService());
- } else {
- // Generic Case
- jsonReturned = Policy.generateJsonRepresentationFromToscaModel(policyModel.getPolicyModelTosca(),
- policyModel.getPolicyModelType());
- }
- } catch (UnknownComponentException | IOException | NullPointerException e) {
- logger.error("Unable to generate the operational policy Schema ... ", e);
- }
- return jsonReturned;
+ /**
+ * Create an operational policy from a loop element model.
+ *
+ * @param loop The parent loop
+ * @param service The loop service
+ * @param loopElementModel The loop element model
+ * @param toscaConverter The tosca converter that must be used to create the Json representation
+ */
+ public OperationalPolicy(Loop loop, Service service, LoopElementModel loopElementModel,
+ ToscaConverterWithDictionarySupport toscaConverter) {
+ this(Policy.generatePolicyName("OPERATIONAL", service.getName(), service.getVersion(),
+ RandomStringUtils.randomAlphanumeric(3), RandomStringUtils.randomAlphanumeric(3)), new JsonObject(),
+ new JsonObject(), loopElementModel.getPolicyModels().first(), loopElementModel, null, null);
+ this.setLoop(loop);
+ this.updateJsonRepresentation(toscaConverter, service);
+ }
+
+ /**
+ * Create an operational policy from a policy model.
+ *
+ * @param loop The parent loop
+ * @param service The loop service
+ * @param policyModel The policy model
+ * @param toscaConverter The tosca converter that must be used to create the Json representation
+ * @throws IOException In case of issues with the legacy files (generated from resource files
+ */
+ public OperationalPolicy(Loop loop, Service service, PolicyModel policyModel,
+ ToscaConverterWithDictionarySupport toscaConverter) throws IOException {
+ this(Policy.generatePolicyName("OPERATIONAL", service.getName(), service.getVersion(),
+ RandomStringUtils.randomAlphanumeric(3), RandomStringUtils.randomAlphanumeric(3)), new JsonObject(),
+ new JsonObject(), policyModel, null, null, null);
+ this.setLoop(loop);
+ this.updateJsonRepresentation(toscaConverter, service);