summaryrefslogtreecommitdiffstats
path: root/gui-editors/gui-editor-apex/src/main/java
diff options
context:
space:
mode:
authordanielhanrahan <daniel.hanrahan@est.tech>2022-03-10 14:39:42 +0000
committerdanielhanrahan <daniel.hanrahan@est.tech>2022-03-14 11:53:36 +0000
commit93b5533e44728faa87c291fbf44120ea013fab51 (patch)
treefa26abbb89f0c596c84371f3c144957b9591167c /gui-editors/gui-editor-apex/src/main/java
parent1e95c73cef25b524bc1f5791d4578332670202f7 (diff)
Upgrade apex-pdp version in Apex Editor
Upgrade apex-pdp version to 2.7.1-SNAPSHOT Fix NullPointerException in ModelHandler::setUuidAndDescription Allow parsing models from policy_type_impl or apexPolicyModel Remove deprecated Task input and output field functionality Fix JS REST calls and tests after JAXB to Gson changes Fix bugs in Task Edit form relating to task logic edit area Issue-ID: POLICY-3990 Signed-off-by: danielhanrahan <daniel.hanrahan@est.tech> Change-Id: I4f506889df46619a0178ab99c99c73ec2fd5a1e3
Diffstat (limited to 'gui-editors/gui-editor-apex/src/main/java')
-rw-r--r--gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/EventHandler.java4
-rw-r--r--gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/ModelHandler.java4
-rw-r--r--gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/RestSession.java53
-rw-r--r--gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/TaskHandler.java107
-rw-r--r--gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/bean/BeanTask.java6
5 files changed, 40 insertions, 134 deletions
diff --git a/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/EventHandler.java b/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/EventHandler.java
index a5113e9..cc95b4b 100644
--- a/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/EventHandler.java
+++ b/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/EventHandler.java
@@ -114,7 +114,7 @@ public class EventHandler implements RestCommandHandler {
ApexApiResult result = session.getApexModelEdited().createEvent(jsonbean.getName(), jsonbean.getVersion(),
jsonbean.getNameSpace(), jsonbean.getSource(), jsonbean.getTarget(), jsonbean.getUuid(),
- jsonbean.getDescription());
+ jsonbean.getDescription(), null);
if (result.isOk()) {
result = createEventParameters(session, jsonbean);
@@ -193,7 +193,7 @@ public class EventHandler implements RestCommandHandler {
if (result.isOk()) {
result = session.getApexModelEdited().createEvent(jsonbean.getName(), jsonbean.getVersion(),
jsonbean.getNameSpace(), jsonbean.getSource(), jsonbean.getTarget(), jsonbean.getUuid(),
- jsonbean.getDescription());
+ jsonbean.getDescription(), null);
if (result.isOk() && jsonbean.getParameters() != null) {
result = createEventParameters(session, jsonbean);
diff --git a/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/ModelHandler.java b/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/ModelHandler.java
index 07051f2..c34b63e 100644
--- a/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/ModelHandler.java
+++ b/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/ModelHandler.java
@@ -246,7 +246,7 @@ public class ModelHandler implements RestCommandHandler {
ApexApiResult result = session.getApexModel().getModelKey();
- LOGGER.exit("Model/GetKey" + (result != null && result.isOk() ? OK : NOT_OK));
+ LOGGER.exit("Model/GetKey" + (result.isOk() ? OK : NOT_OK));
return result;
}
@@ -451,7 +451,7 @@ public class ModelHandler implements RestCommandHandler {
String version) {
// Look up the key information for the name and version
var keyInfoJsonObject = lookupKeyInfo(session, name, version);
- if (keyInfoJsonObject == null || keyInfoJsonObject.get(APEX_KEY_INFO) != null) {
+ if (keyInfoJsonObject == null || keyInfoJsonObject.get(APEX_KEY_INFO) == null) {
return false;
}
diff --git a/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/RestSession.java b/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/RestSession.java
index 48daf9f..f92490b 100644
--- a/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/RestSession.java
+++ b/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/RestSession.java
@@ -49,9 +49,10 @@ public class RestSession {
// Recurring string constants
private static final String ENGINE_SERVICE_PARAMETERS = "engineServiceParameters";
private static final String POLICY_TYPE_IMPL = "policy_type_impl";
+ private static final String APEX_POLICY_MODEL = "apexPolicyModel";
// The ID of the session
- private int sessionId;
+ private final int sessionId;
// The TOSCA Service Template of the session
private ToscaServiceTemplate toscaServiceTemplate;
@@ -79,14 +80,14 @@ public class RestSession {
e);
}
- this.apexModel = new ApexModelFactory().createApexModel(null, true);
+ this.apexModel = new ApexModelFactory().createApexModel(null);
}
/**
* Load the policy model from a TOSCA Service Template.
*
* @param toscaServiceTemplateString The TOSCA service template string
- * @return the result of the lading operation
+ * @return the result of the loading operation
*/
public ApexApiResult loadFromString(final String toscaServiceTemplateString) {
try {
@@ -105,21 +106,42 @@ public class RestSession {
return new ApexApiResult(Result.FAILED, "no policies found on incoming TOSCA service template");
}
- @SuppressWarnings("unchecked")
- var apexEngineServiceParameterMap = (Map<String, Object>) toscaServiceTemplate
- .getToscaTopologyTemplate().getPoliciesAsMap().values().iterator().next().getProperties()
- .get(ENGINE_SERVICE_PARAMETERS);
-
String apexModelString;
try {
- apexModelString = new StandardCoder().encode(apexEngineServiceParameterMap.get(POLICY_TYPE_IMPL));
- } catch (CoderException e) {
+ apexModelString = extractPolicyModel(toscaServiceTemplate);
+ } catch (Exception e) {
return new ApexApiResult(Result.FAILED, "APEX model not found TOSCA Service template", e);
}
return apexModelEdited.loadFromString(apexModelString);
}
+ private String extractPolicyModel(ToscaServiceTemplate toscaServiceTemplate)
+ throws IllegalArgumentException, CoderException {
+ // Check for "engineServiceParameters"
+ @SuppressWarnings("unchecked")
+ var engineServiceParameterMap = (Map<String, Object>) toscaServiceTemplate
+ .getToscaTopologyTemplate().getPoliciesAsMap().values().iterator().next().getProperties()
+ .get(ENGINE_SERVICE_PARAMETERS);
+ if (null == engineServiceParameterMap) {
+ throw new IllegalArgumentException(ENGINE_SERVICE_PARAMETERS + " not found in toscaServiceTemplate");
+ }
+
+ // Check for "policy_type_impl"
+ @SuppressWarnings("unchecked")
+ var policyTypeImplMap = (Map<String, Object>) engineServiceParameterMap.get(POLICY_TYPE_IMPL);
+ if (null == policyTypeImplMap) {
+ throw new IllegalArgumentException(POLICY_TYPE_IMPL + " not found in toscaServiceTemplate");
+ }
+
+ // Check for "apexPolicyModel", this is sometimes used to encapsulate policy models
+ @SuppressWarnings("unchecked")
+ var policyModelMap = (Map<String, Object>) policyTypeImplMap.get(APEX_POLICY_MODEL);
+
+ // Encode "apexPolicyModel" if present, otherwise encode "policy_type_impl"
+ return new StandardCoder().encode(policyModelMap != null ? policyModelMap : policyTypeImplMap);
+ }
+
/**
* Commence making changes to the Apex model.
*
@@ -130,7 +152,7 @@ public class RestSession {
return new ApexApiResult(Result.FAILED, "model is already being edited");
}
- apexModelEdited = apexModel.clone();
+ apexModelEdited = apexModel.getCopy();
return new ApexApiResult();
}
@@ -234,13 +256,4 @@ public class RestSession {
public ApexModel getApexModelEdited() {
return apexModelEdited;
}
-
- /**
- * Get the edited or unedited Apex model of the session.
- *
- * @return the apexModel
- */
- public ApexModel getApexModelToDownload() {
- return apexModelEdited == null ? apexModel : apexModelEdited;
- }
}
diff --git a/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/TaskHandler.java b/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/TaskHandler.java
index 581fdd7..554eca9 100644
--- a/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/TaskHandler.java
+++ b/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/TaskHandler.java
@@ -27,7 +27,6 @@ import org.onap.policy.apex.model.basicmodel.concepts.AxKeyInfo;
import org.onap.policy.apex.model.modelapi.ApexApiResult;
import org.onap.policy.apex.model.modelapi.ApexApiResult.Result;
import org.onap.policy.apex.model.policymodel.concepts.AxTask;
-import org.onap.policy.gui.editors.apex.rest.handling.bean.BeanField;
import org.onap.policy.gui.editors.apex.rest.handling.bean.BeanKeyRef;
import org.onap.policy.gui.editors.apex.rest.handling.bean.BeanLogic;
import org.onap.policy.gui.editors.apex.rest.handling.bean.BeanTask;
@@ -140,15 +139,7 @@ public class TaskHandler implements RestCommandHandler {
* can be retrieved using {@link ApexApiResult#getMessages()}
*/
private ApexApiResult createTaskContent(final RestSession session, final BeanTask jsonbean) {
- ApexApiResult result = createInputFields(session, jsonbean);
-
- if (result.isOk()) {
- result = createOutputFields(session, jsonbean);
- }
-
- if (result.isOk()) {
- result = createTaskLogic(session, jsonbean);
- }
+ ApexApiResult result = createTaskLogic(session, jsonbean);
if (result.isOk()) {
result = createTaskParameters(session, jsonbean);
@@ -161,102 +152,6 @@ public class TaskHandler implements RestCommandHandler {
}
/**
- * Create the input fields for the task.
- *
- * @param session the Apex model editing session
- * @param jsonbean the ban containing the fields
- * @return the result of the operation
- */
- private ApexApiResult createInputFields(final RestSession session, final BeanTask jsonbean) {
- var result = new ApexApiResult();
-
- if (jsonbean.getInputFields() == null || jsonbean.getInputFields().isEmpty()) {
- return result;
- }
-
- for (final Entry<String, BeanField> fieldEntry : jsonbean.getInputFields().entrySet()) {
- if (fieldEntry.getValue() == null) {
- result.setResult(Result.FAILED);
- result.addMessage("Null task input field information for field \"" + fieldEntry.getKey() + IN_TASK
- + jsonbean.getName() + ":" + jsonbean.getVersion()
- + ". The task was created, but there was an error adding the input fields."
- + TASK_PARTIALLY_DEFINED);
- continue;
- }
-
- if (fieldEntry.getKey() == null || !fieldEntry.getKey().equals(fieldEntry.getValue().getLocalName())) {
- result.setResult(Result.FAILED);
- result.addMessage("Invalid task input field information for field \"" + fieldEntry.getKey() + IN_TASK
- + jsonbean.getName() + ":" + jsonbean.getVersion() + ". The localName of the field (\""
- + fieldEntry.getValue().getLocalName() + "\") is not the same as the field name. "
- + "The task was created, but there was an error adding the input fields." + TASK_PARTIALLY_DEFINED);
- } else {
- ApexApiResult fieldCreationResult = session.getApexModelEdited().createTaskInputField(
- jsonbean.getName(), jsonbean.getVersion(), fieldEntry.getKey(), fieldEntry.getValue().getName(),
- fieldEntry.getValue().getVersion(), fieldEntry.getValue().isOptional());
-
- if (fieldCreationResult.isNok()) {
- result.setResult(fieldCreationResult.getResult());
- result.addMessage("Failed to add task input field information for field \"" + fieldEntry.getKey()
- + IN_TASK + jsonbean.getName() + ":" + jsonbean.getVersion()
- + ". The task was created, but there was an error adding the input fields."
- + TASK_PARTIALLY_DEFINED);
- }
- }
- }
-
- return result;
- }
-
- /**
- * Create the output fields for the task.
- *
- * @param session the Apex model editing session
- * @param jsonbean the ban containing the fields
- * @return the result of the operation
- */
- private ApexApiResult createOutputFields(final RestSession session, final BeanTask jsonbean) {
- var result = new ApexApiResult();
-
- if (jsonbean.getOutputFields() == null || jsonbean.getOutputFields().isEmpty()) {
- return result;
- }
-
- for (final Entry<String, BeanField> fieldEntry : jsonbean.getOutputFields().entrySet()) {
- if (fieldEntry.getValue() == null) {
- result.setResult(Result.FAILED);
- result.addMessage("Null task output field information for field \"" + fieldEntry.getKey() + IN_TASK
- + jsonbean.getName() + ":" + jsonbean.getVersion()
- + ". The task was created, but there was an error adding the output fields."
- + TASK_PARTIALLY_DEFINED);
- continue;
- }
-
- if (fieldEntry.getKey() == null || !fieldEntry.getKey().equals(fieldEntry.getValue().getLocalName())) {
- result.setResult(Result.FAILED);
- result.addMessage("Invalid task output field information for field \"" + fieldEntry.getKey() + IN_TASK
- + jsonbean.getName() + ":" + jsonbean.getVersion() + ". The localName of the field (\""
- + fieldEntry.getValue().getLocalName() + "\") is not the same as the field name. "
- + "The task was created, but there was an error adding the output fields."
- + TASK_PARTIALLY_DEFINED);
- } else {
- ApexApiResult fieldCreationResult = session.getApexModelEdited().createTaskOutputField(
- jsonbean.getName(), jsonbean.getVersion(), fieldEntry.getKey(), fieldEntry.getValue().getName(),
- fieldEntry.getValue().getVersion(), fieldEntry.getValue().isOptional());
- if (fieldCreationResult.isNok()) {
- result.setResult(fieldCreationResult.getResult());
- result.addMessage("Failed to add task output field information for field \"" + fieldEntry.getKey()
- + IN_TASK + jsonbean.getName() + ":" + jsonbean.getVersion()
- + ". The task was created, but there was an error adding the output fields."
- + TASK_PARTIALLY_DEFINED);
- }
- }
- }
-
- return result;
- }
-
- /**
* Create the task logic for the task.
*
* @param session the Apex model editing session
diff --git a/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/bean/BeanTask.java b/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/bean/BeanTask.java
index eebfc92..3c4d392 100644
--- a/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/bean/BeanTask.java
+++ b/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/bean/BeanTask.java
@@ -38,8 +38,6 @@ public class BeanTask extends BeanBase {
private String uuid = null;
private String description = null;
private BeanLogic taskLogic = null;
- private Map<String, BeanField> inputFields = null;
- private Map<String, BeanField> outputFields = null;
private Map<String, BeanTaskParameter> parameters = null;
private BeanKeyRef[] contexts = null;
@@ -49,7 +47,7 @@ public class BeanTask extends BeanBase {
@Override
public String toString() {
return "BeanTask [name=" + name + ", version=" + version + ", uuid=" + uuid + ", description=" + description
- + ", taskLogic=" + taskLogic + ", inputFields=" + inputFields + ", outputFields=" + outputFields
- + ", parameters=" + parameters + ", contexts=" + Arrays.toString(contexts) + "]";
+ + ", taskLogic=" + taskLogic + ", parameters=" + parameters + ", contexts=" + Arrays.toString(contexts)
+ + "]";
}
}