aboutsummaryrefslogtreecommitdiffstats
path: root/model
diff options
context:
space:
mode:
Diffstat (limited to 'model')
-rw-r--r--model/pom.xml2
-rw-r--r--model/src/main/java/org/onap/policy/apex/model/basicmodel/concepts/AxConcept.java11
-rw-r--r--model/src/main/java/org/onap/policy/apex/model/basicmodel/concepts/AxKeyInfo.java61
-rw-r--r--model/src/main/java/org/onap/policy/apex/model/contextmodel/concepts/AxContextAlbum.java29
-rw-r--r--model/src/main/java/org/onap/policy/apex/model/contextmodel/concepts/AxContextSchema.java48
-rw-r--r--model/src/main/java/org/onap/policy/apex/model/eventmodel/concepts/AxEvent.java154
-rw-r--r--model/src/main/java/org/onap/policy/apex/model/modelapi/impl/PolicyFacade.java301
-rw-r--r--model/src/main/java/org/onap/policy/apex/model/policymodel/concepts/AxLogic.java97
-rw-r--r--model/src/main/java/org/onap/policy/apex/model/policymodel/concepts/AxPolicyModel.java135
-rw-r--r--model/src/main/java/org/onap/policy/apex/model/policymodel/handling/PolicyLogicReader.java41
10 files changed, 376 insertions, 503 deletions
diff --git a/model/pom.xml b/model/pom.xml
index e6312da71..bdbb7f7d6 100644
--- a/model/pom.xml
+++ b/model/pom.xml
@@ -24,7 +24,7 @@
<parent>
<groupId>org.onap.policy.apex-pdp</groupId>
<artifactId>apex-pdp</artifactId>
- <version>4.0.0-SNAPSHOT</version>
+ <version>4.0.1-SNAPSHOT</version>
</parent>
<groupId>org.onap.policy.apex-pdp.model</groupId>
diff --git a/model/src/main/java/org/onap/policy/apex/model/basicmodel/concepts/AxConcept.java b/model/src/main/java/org/onap/policy/apex/model/basicmodel/concepts/AxConcept.java
index 37fe30b33..dc1642bd5 100644
--- a/model/src/main/java/org/onap/policy/apex/model/basicmodel/concepts/AxConcept.java
+++ b/model/src/main/java/org/onap/policy/apex/model/basicmodel/concepts/AxConcept.java
@@ -1,7 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
- * Modifications Copyright (C) 2019,2022 Nordix Foundation.
+ * Modifications Copyright (C) 2019, 2022, 2024 Nordix Foundation.
* Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -22,18 +22,22 @@
package org.onap.policy.apex.model.basicmodel.concepts;
+import java.io.Serial;
import java.io.Serializable;
import java.util.List;
import org.onap.policy.common.utils.validation.Assertions;
/**
* This class is the base class for all Apex concept classes. It enforces implementation of abstract methods and
- * interfaces on all concepts that are sub-classes of this class.
+ * interfaces on all concepts that are subclasses of this class.
*
* @author Liam Fallon (liam.fallon@ericsson.com)
*/
public abstract class AxConcept implements Serializable, Comparable<AxConcept> {
+
+ @Serial
private static final long serialVersionUID = -7434939557282697490L;
+ public static final String WHITESPACE_REGEX = "(\\s+$){1,4}";
/**
* Default constructor.
@@ -71,8 +75,7 @@ public abstract class AxConcept implements Serializable, Comparable<AxConcept> {
* Validate that this concept is structurally correct.
*
* @param result the parameter in which the result of the validation will be returned
- * @return the validation result that was passed in in the @{link result} field with the result of this validation
- * added
+ * @return the validation result that was passed in the result field with the result of this validation added
*/
public abstract AxValidationResult validate(AxValidationResult result);
diff --git a/model/src/main/java/org/onap/policy/apex/model/basicmodel/concepts/AxKeyInfo.java b/model/src/main/java/org/onap/policy/apex/model/basicmodel/concepts/AxKeyInfo.java
index bd3b18ec9..e158846eb 100644
--- a/model/src/main/java/org/onap/policy/apex/model/basicmodel/concepts/AxKeyInfo.java
+++ b/model/src/main/java/org/onap/policy/apex/model/basicmodel/concepts/AxKeyInfo.java
@@ -1,7 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
- * Modifications Copyright (C) 2019-2022 Nordix Foundation.
+ * Modifications Copyright (C) 2019-2022, 2024 Nordix Foundation.
* Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -23,9 +23,11 @@
package org.onap.policy.apex.model.basicmodel.concepts;
import com.google.gson.annotations.SerializedName;
+import java.io.Serial;
import java.util.List;
import java.util.Random;
import java.util.UUID;
+import lombok.Getter;
import org.apache.commons.lang3.StringUtils;
import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult.ValidationResult;
import org.onap.policy.common.utils.validation.Assertions;
@@ -38,6 +40,8 @@ import org.onap.policy.common.utils.validation.Assertions;
* blank and warns if the UUID is a zero UUID.
*/
public class AxKeyInfo extends AxConcept {
+
+ @Serial
private static final long serialVersionUID = -4023935924068914308L;
private static final int UUID_BYTE_LENGTH_16 = 16;
@@ -49,9 +53,11 @@ public class AxKeyInfo extends AxConcept {
private AxArtifactKey key;
+ @Getter
@SerializedName("UUID")
private UUID uuid;
+ @Getter
private String description;
/**
@@ -82,8 +88,8 @@ public class AxKeyInfo extends AxConcept {
/**
* Constructor to create this concept and set all its fields.
*
- * @param key the key of the concept
- * @param uuid the UUID of the concept
+ * @param key the key of the concept
+ * @param uuid the UUID of the concept
* @param description the description of the concept
*/
public AxKeyInfo(final AxArtifactKey key, final UUID uuid, final String description) {
@@ -124,15 +130,6 @@ public class AxKeyInfo extends AxConcept {
}
/**
- * Gets the UUID of the concept.
- *
- * @return the uuid of the concept
- */
- public UUID getUuid() {
- return uuid;
- }
-
- /**
* Sets the UUID of the concept.
*
* @param uuid the uuid of the concept
@@ -143,15 +140,6 @@ public class AxKeyInfo extends AxConcept {
}
/**
- * Gets the description of the concept.
- *
- * @return the description of the concept
- */
- public String getDescription() {
- return description;
- }
-
- /**
* Sets the description of the concept.
*
* @param description the description of the concept
@@ -170,19 +158,19 @@ public class AxKeyInfo extends AxConcept {
if (key.equals(AxArtifactKey.getNullKey())) {
result.addValidationMessage(
- new AxValidationMessage(key, this.getClass(), ValidationResult.INVALID, "key is a null key"));
+ new AxValidationMessage(key, this.getClass(), ValidationResult.INVALID, "key is a null key"));
}
result = key.validate(result);
- if (description.trim().length() == 0) {
+ if (description.trim().isEmpty()) {
result.addValidationMessage(new AxValidationMessage(key, this.getClass(), ValidationResult.OBSERVATION,
- "description is blank"));
+ "description is blank"));
}
if (uuid.equals(new UUID(0, 0))) {
result.addValidationMessage(new AxValidationMessage(key, this.getClass(), ValidationResult.WARNING,
- "UUID is a zero UUID: " + new UUID(0, 0)));
+ "UUID is a zero UUID: " + new UUID(0, 0)));
}
return result;
@@ -202,17 +190,8 @@ public class AxKeyInfo extends AxConcept {
*/
@Override
public String toString() {
- final var builder = new StringBuilder();
- builder.append(this.getClass().getSimpleName());
- builder.append(":(");
- builder.append("artifactId=");
- builder.append(key);
- builder.append(",uuid=");
- builder.append(uuid);
- builder.append(",description=");
- builder.append(description);
- builder.append(")");
- return builder.toString();
+ return this.getClass().getSimpleName()
+ + ":(artifactId=" + key + ",uuid=" + uuid + ",description=" + description + ")";
}
/**
@@ -222,10 +201,9 @@ public class AxKeyInfo extends AxConcept {
public AxConcept copyTo(final AxConcept target) {
Assertions.argumentNotNull(target, "target may not be null");
- final Object copyObject = target;
- Assertions.instanceOf(copyObject, AxKeyInfo.class);
+ Assertions.instanceOf(target, AxKeyInfo.class);
- final AxKeyInfo copy = ((AxKeyInfo) copyObject);
+ final AxKeyInfo copy = ((AxKeyInfo) target);
copy.setKey(new AxArtifactKey(key));
copy.setUuid(UUID.fromString(uuid.toString()));
copy.setDescription(description);
@@ -265,10 +243,7 @@ public class AxKeyInfo extends AxConcept {
if (!key.equals(other.key)) {
return false;
}
- if (!uuid.equals(other.uuid)) {
- return false;
- }
- return description.equals(description);
+ return uuid.equals(other.uuid);
}
/**
diff --git a/model/src/main/java/org/onap/policy/apex/model/contextmodel/concepts/AxContextAlbum.java b/model/src/main/java/org/onap/policy/apex/model/contextmodel/concepts/AxContextAlbum.java
index db64f8847..b7925d43b 100644
--- a/model/src/main/java/org/onap/policy/apex/model/contextmodel/concepts/AxContextAlbum.java
+++ b/model/src/main/java/org/onap/policy/apex/model/contextmodel/concepts/AxContextAlbum.java
@@ -1,7 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
- * Modifications Copyright (C) 2019-2022 Nordix Foundation.
+ * Modifications Copyright (C) 2019-2022, 2024 Nordix Foundation.
* Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -22,6 +22,7 @@
package org.onap.policy.apex.model.contextmodel.concepts;
+import java.io.Serial;
import java.util.List;
import lombok.EqualsAndHashCode;
import lombok.Getter;
@@ -64,6 +65,7 @@ import org.onap.policy.common.utils.validation.Assertions;
public class AxContextAlbum extends AxConcept {
private static final String SCOPE_STRING = "scope";
+ @Serial
private static final long serialVersionUID = 4290442590545820316L;
/**
@@ -71,7 +73,9 @@ public class AxContextAlbum extends AxConcept {
*/
public static final String SCOPE_REGEXP = "[A-Za-z0-9\\-_]+";
- /** The value of scope for a context album for which a scope has not been specified. */
+ /**
+ * The value of scope for a context album for which a scope has not been specified.
+ */
public static final String SCOPE_UNDEFINED = "UNDEFINED";
private AxArtifactKey key;
@@ -117,13 +121,13 @@ public class AxContextAlbum extends AxConcept {
/**
* Constructor that sets all the fields of the context album.
*
- * @param key the key of the context album
- * @param scope the scope field, must match the regular expression SCOPE_REGEXP
+ * @param key the key of the context album
+ * @param scope the scope field, must match the regular expression SCOPE_REGEXP
* @param isWritable specifies whether the context album will be writable or not
* @param itemSchema the artifact key of the context schema to use for this context album
*/
public AxContextAlbum(final AxArtifactKey key, final String scope, final boolean isWritable,
- final AxArtifactKey itemSchema) {
+ final AxArtifactKey itemSchema) {
super();
Assertions.argumentNotNull(key, "key may not be null");
Assertions.argumentNotNull(scope, "scope may not be null");
@@ -185,24 +189,24 @@ public class AxContextAlbum extends AxConcept {
if (key.equals(AxArtifactKey.getNullKey())) {
result.addValidationMessage(new AxValidationMessage(key, this.getClass(), ValidationResult.INVALID,
- "key is a null key"));
+ "key is a null key"));
}
result = key.validate(result);
- if (scope.replaceAll("\\s+$", "").length() == 0 || scope.equals(SCOPE_UNDEFINED)) {
+ if (scope.replaceAll(WHITESPACE_REGEX, "").isEmpty() || scope.equals(SCOPE_UNDEFINED)) {
result.addValidationMessage(new AxValidationMessage(key, this.getClass(), ValidationResult.INVALID,
- "scope is not defined"));
+ "scope is not defined"));
}
var stringCheckResult = Assertions.getStringParameterValidationMessage(SCOPE_STRING, scope, SCOPE_REGEXP);
if (stringCheckResult != null) {
result.addValidationMessage(new AxValidationMessage(key, this.getClass(), ValidationResult.INVALID,
- "scope invalid-" + stringCheckResult));
+ "scope invalid-" + stringCheckResult));
}
if (itemSchema.equals(AxArtifactKey.getNullKey())) {
result.addValidationMessage(new AxValidationMessage(key, this.getClass(), ValidationResult.INVALID,
- "itemSchema reference is a null key, an item schema must be specified"));
+ "itemSchema reference is a null key, an item schema must be specified"));
}
result = itemSchema.validate(result);
@@ -226,10 +230,9 @@ public class AxContextAlbum extends AxConcept {
public AxConcept copyTo(final AxConcept target) {
Assertions.argumentNotNull(target, "targetObject may not be null");
- final Object copyObject = target;
- Assertions.instanceOf(copyObject, AxContextAlbum.class);
+ Assertions.instanceOf(target, AxContextAlbum.class);
- final AxContextAlbum copy = ((AxContextAlbum) copyObject);
+ final AxContextAlbum copy = ((AxContextAlbum) target);
copy.setKey(new AxArtifactKey(key));
copy.setScope(scope);
copy.setWritable(isWritable);
diff --git a/model/src/main/java/org/onap/policy/apex/model/contextmodel/concepts/AxContextSchema.java b/model/src/main/java/org/onap/policy/apex/model/contextmodel/concepts/AxContextSchema.java
index 61434ca67..09a6dd833 100644
--- a/model/src/main/java/org/onap/policy/apex/model/contextmodel/concepts/AxContextSchema.java
+++ b/model/src/main/java/org/onap/policy/apex/model/contextmodel/concepts/AxContextSchema.java
@@ -1,7 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
- * Modifications Copyright (C) 2019-2022 Nordix Foundation.
+ * Modifications Copyright (C) 2019-2022, 2024 Nordix Foundation.
* Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -22,6 +22,7 @@
package org.onap.policy.apex.model.contextmodel.concepts;
+import java.io.Serial;
import java.util.List;
import lombok.AccessLevel;
import lombok.Getter;
@@ -56,17 +57,23 @@ import org.onap.policy.common.utils.validation.Assertions;
@ToString
public class AxContextSchema extends AxConcept {
private static final String SCHEMA_FLAVOUR = "schemaFlavour";
- private static final String WHITESPACE_REGEXP = "\\s+$";
+ @Serial
private static final long serialVersionUID = -6443016863162692288L;
- /** Regular expression that constrains what values a schema flavour can have. */
+ /**
+ * Regular expression that constrains what values a schema flavour can have.
+ */
public static final String SCHEMA_FLAVOUR_REGEXP = "[A-Za-z0-9\\-_]+";
- /** An undefined schema flavour has this value. */
+ /**
+ * An undefined schema flavour has this value.
+ */
public static final String SCHEMA_FLAVOUR_UNDEFINED = "UNDEFINED";
- /** The maximum permissible size of a schema definition. */
+ /**
+ * The maximum permissible size of a schema definition.
+ */
public static final int MAX_SCHEMA_SIZE = 32672; // The maximum size supported by Apache Derby
private AxArtifactKey key;
@@ -106,8 +113,8 @@ public class AxContextSchema extends AxConcept {
/**
* This Constructor creates a context schema with all of its fields defined.
*
- * @param key the key
- * @param schemaFlavour the schema flavour
+ * @param key the key
+ * @param schemaFlavour the schema flavour
* @param schemaDefinition the schema definition
*/
public AxContextSchema(final AxArtifactKey key, final String schemaFlavour, final String schemaDefinition) {
@@ -118,7 +125,7 @@ public class AxContextSchema extends AxConcept {
this.key = key;
this.schemaFlavour = Assertions.validateStringParameter(SCHEMA_FLAVOUR, schemaFlavour, SCHEMA_FLAVOUR_REGEXP);
- this.schemaDefinition = schemaDefinition.replaceAll(WHITESPACE_REGEXP, "");
+ this.schemaDefinition = schemaDefinition.replaceAll(WHITESPACE_REGEX, "");
}
/**
@@ -164,7 +171,7 @@ public class AxContextSchema extends AxConcept {
*/
public void setSchema(final String schema) {
Assertions.argumentNotNull(schema, "schema may not be null");
- this.schemaDefinition = schema.replaceAll(WHITESPACE_REGEXP, "");
+ this.schemaDefinition = schema.replaceAll(WHITESPACE_REGEX, "");
}
/**
@@ -176,27 +183,27 @@ public class AxContextSchema extends AxConcept {
if (key.equals(AxArtifactKey.getNullKey())) {
result.addValidationMessage(new AxValidationMessage(key, this.getClass(), ValidationResult.INVALID,
- "key is a null key"));
+ "key is a null key"));
}
result = key.validate(result);
- if (schemaFlavour.replaceAll(WHITESPACE_REGEXP, "").length() == 0
- || schemaFlavour.equals(SCHEMA_FLAVOUR_UNDEFINED)) {
+ if (schemaFlavour.replaceAll(WHITESPACE_REGEX, "").isEmpty()
+ || schemaFlavour.equals(SCHEMA_FLAVOUR_UNDEFINED)) {
result.addValidationMessage(new AxValidationMessage(key, this.getClass(), ValidationResult.INVALID,
- "schema flavour is not defined"));
+ "schema flavour is not defined"));
}
var flavourValidationResult = Assertions.getStringParameterValidationMessage(SCHEMA_FLAVOUR, schemaFlavour,
- SCHEMA_FLAVOUR_REGEXP);
+ SCHEMA_FLAVOUR_REGEXP);
if (flavourValidationResult != null) {
result.addValidationMessage(new AxValidationMessage(key, this.getClass(), ValidationResult.INVALID,
- "schema flavour invalid-" + flavourValidationResult));
+ "schema flavour invalid-" + flavourValidationResult));
}
- if (schemaDefinition.replaceAll(WHITESPACE_REGEXP, "").length() == 0) {
+ if (schemaDefinition.replaceAll(WHITESPACE_REGEX, "").isEmpty()) {
result.addValidationMessage(new AxValidationMessage(key, this.getClass(), ValidationResult.INVALID,
- "no schemaDefinition specified, schemaDefinition may not be blank"));
+ "no schemaDefinition specified, schemaDefinition may not be blank"));
}
return result;
@@ -209,7 +216,7 @@ public class AxContextSchema extends AxConcept {
public void clean() {
key.clean();
schemaFlavour = Assertions.validateStringParameter(SCHEMA_FLAVOUR, schemaFlavour, SCHEMA_FLAVOUR_REGEXP);
- schemaDefinition = schemaDefinition.replaceAll(WHITESPACE_REGEXP, "");
+ schemaDefinition = schemaDefinition.replaceAll(WHITESPACE_REGEX, "");
}
/**
@@ -219,10 +226,9 @@ public class AxContextSchema extends AxConcept {
public AxConcept copyTo(final AxConcept target) {
Assertions.argumentNotNull(target, "target may not be null");
- final Object copyObject = target;
- Assertions.instanceOf(copyObject, AxContextSchema.class);
+ Assertions.instanceOf(target, AxContextSchema.class);
- final AxContextSchema copy = ((AxContextSchema) copyObject);
+ final AxContextSchema copy = ((AxContextSchema) target);
copy.setKey(new AxArtifactKey(key));
copy.setSchemaFlavour(schemaFlavour);
copy.setSchema(schemaDefinition);
diff --git a/model/src/main/java/org/onap/policy/apex/model/eventmodel/concepts/AxEvent.java b/model/src/main/java/org/onap/policy/apex/model/eventmodel/concepts/AxEvent.java
index a4c0e9db1..652972d13 100644
--- a/model/src/main/java/org/onap/policy/apex/model/eventmodel/concepts/AxEvent.java
+++ b/model/src/main/java/org/onap/policy/apex/model/eventmodel/concepts/AxEvent.java
@@ -1,7 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
- * Modifications Copyright (C) 2019-2020,2022 Nordix Foundation.
+ * Modifications Copyright (C) 2019-2020, 2022, 2024 Nordix Foundation.
* Modifications Copyright (C) 2022 Bell Canada.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -24,6 +24,7 @@ package org.onap.policy.apex.model.eventmodel.concepts;
import com.google.common.base.Strings;
import com.google.gson.annotations.SerializedName;
+import java.io.Serial;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
@@ -32,6 +33,8 @@ import java.util.Set;
import java.util.SortedMap;
import java.util.TreeMap;
import java.util.TreeSet;
+import lombok.Getter;
+import lombok.Setter;
import org.apache.commons.lang3.EnumUtils;
import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
import org.onap.policy.apex.model.basicmodel.concepts.AxConcept;
@@ -65,21 +68,32 @@ import org.onap.policy.common.utils.validation.Assertions;
* checked to ensure it matches the event key.
*/
public class AxEvent extends AxConcept {
- private static final long serialVersionUID = -1460388382582984269L;
- private static final String WHITESPACE_REGEXP = "\\s+$";
+ @Serial
+ private static final long serialVersionUID = -1460388382582984269L;
- /** The key of the event, unique in the Apex system. */
+ /**
+ * The key of the event, unique in the Apex system.
+ */
// CHECKSTYLE:OFF: checkstyle:VisibilityMonitor
protected AxArtifactKey key;
// CHECKSTYLE:ON: checkstyle:VisibilityMonitor
+ @Getter
private String nameSpace;
+
+ @Getter
private String source;
+
+ @Getter
private String target;
+ @Getter
@SerializedName("parameter")
private Map<String, AxField> parameterMap;
+
+ @Setter
+ @Getter
private String toscaPolicyState;
/**
@@ -113,7 +127,7 @@ public class AxEvent extends AxConcept {
* This constructor creates an event with the given artifact key and name space. The event source, and target are
* all defined as empty strings and the parameter map is initialized as an empty map.
*
- * @param key the key of the event
+ * @param key the key of the event
* @param nameSpace the name space of the event
*/
public AxEvent(final AxArtifactKey key, final String nameSpace) {
@@ -124,10 +138,10 @@ public class AxEvent extends AxConcept {
* This constructor creates an event with the given artifact key, name space, source and target. The parameter map
* is initialized as an empty map.
*
- * @param key the key of the event
+ * @param key the key of the event
* @param nameSpace the name space of the event
- * @param source the source of the event
- * @param target the target of the event
+ * @param source the source of the event
+ * @param target the target of the event
*/
public AxEvent(final AxArtifactKey key, final String nameSpace, final String source, final String target) {
this(key, nameSpace, source, target, new TreeMap<>(), "");
@@ -136,15 +150,15 @@ public class AxEvent extends AxConcept {
/**
* This constructor creates an event with all its fields defined.
*
- * @param key the key of the event
- * @param nameSpace the name space of the event
- * @param source the source of the event
- * @param target the target of the event
- * @param parameterMap the map of parameters that the event has
+ * @param key the key of the event
+ * @param nameSpace the name space of the event
+ * @param source the source of the event
+ * @param target the target of the event
+ * @param parameterMap the map of parameters that the event has
* @param toscaPolicyState the TOSCA policy processing status that event is flagged with
*/
public AxEvent(final AxArtifactKey key, final String nameSpace, final String source, final String target,
- final SortedMap<String, AxField> parameterMap, final String toscaPolicyState) {
+ final SortedMap<String, AxField> parameterMap, final String toscaPolicyState) {
super();
Assertions.argumentNotNull(key, "key may not be null");
Assertions.argumentNotNull(nameSpace, "nameSpace may not be null");
@@ -216,15 +230,6 @@ public class AxEvent extends AxConcept {
}
/**
- * Gets the name space of the event.
- *
- * @return the name space of the event
- */
- public String getNameSpace() {
- return nameSpace;
- }
-
- /**
* Sets the name space of the event.
*
* @param nameSpace the name space of the event
@@ -235,15 +240,6 @@ public class AxEvent extends AxConcept {
}
/**
- * Gets the source of the event.
- *
- * @return the source of the event
- */
- public String getSource() {
- return source;
- }
-
- /**
* Sets the source of the event.
*
* @param source the source of the event
@@ -254,15 +250,6 @@ public class AxEvent extends AxConcept {
}
/**
- * Gets the target of the event.
- *
- * @return the target of the event
- */
- public String getTarget() {
- return target;
- }
-
- /**
* Sets the target of the event.
*
* @param target the target of the event
@@ -273,15 +260,6 @@ public class AxEvent extends AxConcept {
}
/**
- * Gets the event parameter map.
- *
- * @return the event parameter map
- */
- public Map<String, AxField> getParameterMap() {
- return parameterMap;
- }
-
- /**
* Gets the fields defined on the event as a set.
*
* @return the fields defined on the event as a set
@@ -301,24 +279,6 @@ public class AxEvent extends AxConcept {
}
/**
- * Gets the TOSCA policy processing status from the event.
- *
- * @return the TOSCA policy processing status
- */
- public String getToscaPolicyState() {
- return toscaPolicyState;
- }
-
- /**
- * Sets the TOSCA policy processing status on the event.
- *
- * @param toscaPolicyState the TOSCA policy processing status
- */
- public void setToscaPolicyState(String toscaPolicyState) {
- this.toscaPolicyState = toscaPolicyState;
- }
-
- /**
* {@inheritDoc}.
*/
@Override
@@ -327,43 +287,43 @@ public class AxEvent extends AxConcept {
if (key.equals(AxArtifactKey.getNullKey())) {
result.addValidationMessage(new AxValidationMessage(key, this.getClass(), ValidationResult.INVALID,
- "key is a null key"));
+ "key is a null key"));
}
result = key.validate(result);
- if (nameSpace.replaceAll(WHITESPACE_REGEXP, "").length() == 0) {
+ if (nameSpace.replaceAll(WHITESPACE_REGEX, "").isEmpty()) {
result.addValidationMessage(new AxValidationMessage(key, this.getClass(), ValidationResult.WARNING,
- "nameSpace on event is blank"));
+ "nameSpace on event is blank"));
}
- if (source.replaceAll(WHITESPACE_REGEXP, "").length() == 0) {
+ if (source.replaceAll(WHITESPACE_REGEX, "").isEmpty()) {
result.addValidationMessage(new AxValidationMessage(key, this.getClass(), ValidationResult.OBSERVATION,
- "source on event is blank"));
+ "source on event is blank"));
}
- if (target.replaceAll(WHITESPACE_REGEXP, "").length() == 0) {
+ if (target.replaceAll(WHITESPACE_REGEX, "").isEmpty()) {
result.addValidationMessage(new AxValidationMessage(key, this.getClass(), ValidationResult.OBSERVATION,
- "target on event is blank"));
+ "target on event is blank"));
}
for (final Entry<String, AxField> eventParameterEntry : parameterMap.entrySet()) {
if (eventParameterEntry.getKey() == null || eventParameterEntry.getKey().equals(AxKey.NULL_KEY_NAME)) {
result.addValidationMessage(new AxValidationMessage(key, this.getClass(), ValidationResult.INVALID,
- "key on parameter " + eventParameterEntry.getKey() + " may not be the null key"));
+ "key on parameter " + eventParameterEntry.getKey() + " may not be the null key"));
} else if (eventParameterEntry.getValue() == null) {
result.addValidationMessage(new AxValidationMessage(key, this.getClass(), ValidationResult.INVALID,
- "value on parameter " + eventParameterEntry.getKey() + " may not be null"));
+ "value on parameter " + eventParameterEntry.getKey() + " may not be null"));
} else {
result = validateEventParameters(eventParameterEntry, result);
}
}
if (!Strings.isNullOrEmpty(toscaPolicyState)
- && !EnumUtils.isValidEnum(AxToscaPolicyProcessingStatus.class, toscaPolicyState)) {
+ && !EnumUtils.isValidEnum(AxToscaPolicyProcessingStatus.class, toscaPolicyState)) {
result.addValidationMessage(new AxValidationMessage(key, this.getClass(), ValidationResult.INVALID,
- "toscaPolicyState on event is not a valid enum. Valid values are: "
- + Arrays.asList(AxToscaPolicyProcessingStatus.values())));
+ "toscaPolicyState on event is not a valid enum. Valid values are: "
+ + Arrays.asList(AxToscaPolicyProcessingStatus.values())));
}
return result;
@@ -373,22 +333,22 @@ public class AxEvent extends AxConcept {
* Validate an event parameter entry.
*
* @param eventParameterEntry the event parameter entry
- * @param result the validation result to append to
+ * @param result the validation result to append to
* @return The validation result
*/
private AxValidationResult validateEventParameters(final Entry<String, AxField> eventParameterEntry,
- final AxValidationResult result) {
+ final AxValidationResult result) {
if (!eventParameterEntry.getKey().equals(eventParameterEntry.getValue().getKey().getLocalName())) {
result.addValidationMessage(new AxValidationMessage(key, this.getClass(), ValidationResult.INVALID,
- "key on parameter " + eventParameterEntry.getKey()
- + " does not equal parameter field local name "
- + eventParameterEntry.getValue().getKey().getLocalName()));
+ "key on parameter " + eventParameterEntry.getKey()
+ + " does not equal parameter field local name "
+ + eventParameterEntry.getValue().getKey().getLocalName()));
}
if (!eventParameterEntry.getValue().getKey().getParentArtifactKey().equals(key)) {
result.addValidationMessage(new AxValidationMessage(key, this.getClass(), ValidationResult.INVALID,
- "parent key on parameter field " + eventParameterEntry.getValue().getKey()
- + " does not equal event key"));
+ "parent key on parameter field " + eventParameterEntry.getValue().getKey()
+ + " does not equal event key"));
}
return eventParameterEntry.getValue().validate(result);
@@ -410,23 +370,9 @@ public class AxEvent extends AxConcept {
*/
@Override
public String toString() {
- final StringBuilder builder = new StringBuilder();
- builder.append(this.getClass().getSimpleName());
- builder.append(":(");
- builder.append("key=");
- builder.append(key);
- builder.append(",nameSpace=");
- builder.append(nameSpace);
- builder.append(",source=");
- builder.append(source);
- builder.append(",target=");
- builder.append(target);
- builder.append(",parameter=");
- builder.append(parameterMap);
- builder.append(",toscaPolicyState=");
- builder.append(toscaPolicyState);
- builder.append(")");
- return builder.toString();
+ return this.getClass().getSimpleName()
+ + ":(" + "key=" + key + ",nameSpace=" + nameSpace + ",source=" + source + ",target=" + target
+ + ",parameter=" + parameterMap + ",toscaPolicyState=" + toscaPolicyState + ")";
}
/**
diff --git a/model/src/main/java/org/onap/policy/apex/model/modelapi/impl/PolicyFacade.java b/model/src/main/java/org/onap/policy/apex/model/modelapi/impl/PolicyFacade.java
index 408f0913f..51778e54e 100644
--- a/model/src/main/java/org/onap/policy/apex/model/modelapi/impl/PolicyFacade.java
+++ b/model/src/main/java/org/onap/policy/apex/model/modelapi/impl/PolicyFacade.java
@@ -1,7 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
- * Modifications Copyright (C) 2019,2022 Nordix Foundation.
+ * Modifications Copyright (C) 2019, 2022, 2024 Nordix Foundation.
* Modifications Copyright (C) 2021 Bell Canada. All rights reserved.
* Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
* ================================================================================
@@ -75,7 +75,7 @@ public class PolicyFacade {
/**
* Constructor that creates a policy facade for the Apex Model API.
*
- * @param apexModel the apex model
+ * @param apexModel the apex model
* @param apexProperties Properties for the model
*/
public PolicyFacade(final ApexModel apexModel, final Properties apexProperties) {
@@ -88,16 +88,16 @@ public class PolicyFacade {
/**
* Create a policy.
*
- * @param name name of the policy
- * @param version version of the policy, set to null to use the default version
- * @param template template used to create the policy, set to null to use the default template
- * @param firstState the first state of the policy
- * @param uuid policy UUID, set to null to generate a UUID
+ * @param name name of the policy
+ * @param version version of the policy, set to null to use the default version
+ * @param template template used to create the policy, set to null to use the default template
+ * @param firstState the first state of the policy
+ * @param uuid policy UUID, set to null to generate a UUID
* @param description policy description, set to null to generate a description
* @return result of the operation
*/
public ApexApiResult createPolicy(final String name, final String version, final String template,
- final String firstState, final String uuid, final String description) {
+ final String firstState, final String uuid, final String description) {
try {
final AxArtifactKey key = new AxArtifactKey();
key.setName(name);
@@ -135,16 +135,16 @@ public class PolicyFacade {
/**
* Update a policy.
*
- * @param name name of the policy
- * @param version version of the policy, set to null to use the latest version
- * @param template template used to create the policy, set to null to not update
- * @param firstState the first state of the policy
- * @param uuid policy UUID, set to null to not update
+ * @param name name of the policy
+ * @param version version of the policy, set to null to use the latest version
+ * @param template template used to create the policy, set to null to not update
+ * @param firstState the first state of the policy
+ * @param uuid policy UUID, set to null to not update
* @param description policy description, set to null to not update
* @return result of the operation
*/
public ApexApiResult updatePolicy(final String name, final String version, final String template,
- final String firstState, final String uuid, final String description) {
+ final String firstState, final String uuid, final String description) {
try {
final AxPolicy policy = apexModel.getPolicyModel().getPolicies().get(name, version);
if (policy == null) {
@@ -168,7 +168,7 @@ public class PolicyFacade {
/**
* List policies.
*
- * @param name name of the policy, set to null to list all
+ * @param name name of the policy, set to null to list all
* @param version starting version of the policy, set to null to list all versions
* @return result of the operation
*/
@@ -193,7 +193,7 @@ public class PolicyFacade {
/**
* Delete a policy.
*
- * @param name name of the policy
+ * @param name name of the policy
* @param version version of the policy, set to null to use the latest version
* @return result of the operation
*/
@@ -232,7 +232,7 @@ public class PolicyFacade {
/**
* Validate policies.
*
- * @param name name of the policy, set to null to list all
+ * @param name name of the policy, set to null to list all
* @param version starting version of the policy, set to null to list all versions
* @return result of the operation
*/
@@ -260,19 +260,20 @@ public class PolicyFacade {
/**
* Create a policy state.
*
- * @param name name of the policy
- * @param version version of the policy, set to null to use the latest version
- * @param stateName of the state
- * @param triggerName name of the trigger event for this state
- * @param triggerVersion version of the trigger event for this state, set to null to use the
- * latest version
- * @param defaultTaskName the default task name
- * @param defaltTaskVersion the default task version, set to null to use the latest version
+ * @param name name of the policy
+ * @param version version of the policy, set to null to use the latest version
+ * @param stateName of the state
+ * @param triggerName name of the trigger event for this state
+ * @param triggerVersion version of the trigger event for this state, set to null to use the
+ * latest version
+ * @param defaultTaskName the default task name
+ * @param defaultTaskVersion the default task version, set to null to use the latest version
* @return result of the operation
*/
public ApexApiResult createPolicyState(final String name, final String version, final String stateName,
- final String triggerName, final String triggerVersion, final String defaultTaskName,
- final String defaltTaskVersion) {
+ final String triggerName, final String triggerVersion,
+ final String defaultTaskName,
+ final String defaultTaskVersion) {
try {
Assertions.argumentNotNull(stateName, STATE_NAME_MAY_NOT_BE_NULL);
@@ -295,10 +296,10 @@ public class PolicyFacade {
CONCEPT + triggerName + ':' + triggerVersion + DOES_NOT_EXIST);
}
- final AxTask defaultTask = apexModel.getPolicyModel().getTasks().get(defaultTaskName, defaltTaskVersion);
+ final AxTask defaultTask = apexModel.getPolicyModel().getTasks().get(defaultTaskName, defaultTaskVersion);
if (defaultTask == null) {
return new ApexApiResult(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST,
- CONCEPT + defaultTaskName + ':' + defaltTaskVersion + DOES_NOT_EXIST);
+ CONCEPT + defaultTaskName + ':' + defaultTaskVersion + DOES_NOT_EXIST);
}
final AxState state = new AxState(refKey);
@@ -315,19 +316,20 @@ public class PolicyFacade {
/**
* Update a policy state.
*
- * @param name name of the policy
- * @param version version of the policy, set to null to use the latest version
- * @param stateName of the state
- * @param triggerName name of the trigger event for this state, set to null to not update
- * @param triggerVersion version of the trigger event for this state, set to use latest version
- * of trigger event
- * @param defaultTaskName the default task name, set to null to not update
- * @param defaltTaskVersion the default task version, set to use latest version of default task
+ * @param name name of the policy
+ * @param version version of the policy, set to null to use the latest version
+ * @param stateName of the state
+ * @param triggerName name of the trigger event for this state, set to null to not update
+ * @param triggerVersion version of the trigger event for this state, set to use latest version
+ * of trigger event
+ * @param defaultTaskName the default task name, set to null to not update
+ * @param defaultTaskVersion the default task version, set to use latest version of default task
* @return result of the operation
*/
public ApexApiResult updatePolicyState(final String name, final String version, final String stateName,
- final String triggerName, final String triggerVersion, final String defaultTaskName,
- final String defaltTaskVersion) {
+ final String triggerName, final String triggerVersion,
+ final String defaultTaskName,
+ final String defaultTaskVersion) {
try {
Assertions.argumentNotNull(stateName, STATE_NAME_MAY_NOT_BE_NULL);
@@ -354,10 +356,10 @@ public class PolicyFacade {
if (defaultTaskName != null) {
final AxTask defaultTask =
- apexModel.getPolicyModel().getTasks().get(defaultTaskName, defaltTaskVersion);
+ apexModel.getPolicyModel().getTasks().get(defaultTaskName, defaultTaskVersion);
if (defaultTask == null) {
return new ApexApiResult(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST,
- CONCEPT + defaultTaskName + ':' + defaltTaskVersion + DOES_NOT_EXIST);
+ CONCEPT + defaultTaskName + ':' + defaultTaskVersion + DOES_NOT_EXIST);
}
state.setDefaultTask(defaultTask.getKey());
}
@@ -371,8 +373,8 @@ public class PolicyFacade {
/**
* List policy states.
*
- * @param name name of the policy
- * @param version version of the policy, set to null to use the latest version
+ * @param name name of the policy
+ * @param version version of the policy, set to null to use the latest version
* @param stateName of the state, set to null to list all states of the policy
* @return result of the operation
*/
@@ -412,8 +414,8 @@ public class PolicyFacade {
/**
* Delete a policy state.
*
- * @param name name of the policy
- * @param version version of the policy, set to null to use the latest version
+ * @param name name of the policy
+ * @param version version of the policy, set to null to use the latest version
* @param stateName of the state, set to null to delete all states
* @return result of the operation
*/
@@ -455,16 +457,17 @@ public class PolicyFacade {
/**
* Create task selection logic for a state.
*
- * @param name name of the policy
- * @param version version of the policy, set to null to use the latest version
- * @param stateName of the state
+ * @param name name of the policy
+ * @param version version of the policy, set to null to use the latest version
+ * @param stateName of the state
* @param logicFlavour the task selection logic flavour for the state, set to null to use the
- * default task logic flavour
- * @param logic the source code for the logic of the state
+ * default task logic flavour
+ * @param logic the source code for the logic of the state
* @return result of the operation
*/
public ApexApiResult createPolicyStateTaskSelectionLogic(final String name, final String version,
- final String stateName, final String logicFlavour, final String logic) {
+ final String stateName, final String logicFlavour,
+ final String logic) {
try {
Assertions.argumentNotNull(stateName, STATE_NAME_MAY_NOT_BE_NULL);
@@ -480,8 +483,7 @@ public class PolicyFacade {
CONCEPT + policy.getKey().getId() + ':' + stateName + DOES_NOT_EXIST);
}
- // There is only one logic item associated with a state so we use a hard coded logic
- // name
+ // There is only one logic item associated with a state, so we use a hard coded logic name
final AxReferenceKey refKey = new AxReferenceKey(state.getKey(), "TaskSelectionLogic");
if (!state.getTaskSelectionLogic().getKey().getLocalName().equals(AxKey.NULL_KEY_NAME)) {
@@ -499,15 +501,16 @@ public class PolicyFacade {
/**
* Update task selection logic for a state.
*
- * @param name name of the policy
- * @param version version of the policy, set to null to use the latest version
- * @param stateName of the state
+ * @param name name of the policy
+ * @param version version of the policy, set to null to use the latest version
+ * @param stateName of the state
* @param logicFlavour the task selection logic flavour for the state, set to null to not update
- * @param logic the source code for the logic of the state, set to null to not update
+ * @param logic the source code for the logic of the state, set to null to not update
* @return result of the operation
*/
public ApexApiResult updatePolicyStateTaskSelectionLogic(final String name, final String version,
- final String stateName, final String logicFlavour, final String logic) {
+ final String stateName, final String logicFlavour,
+ final String logic) {
try {
Assertions.argumentNotNull(stateName, STATE_NAME_MAY_NOT_BE_NULL);
@@ -545,13 +548,13 @@ public class PolicyFacade {
/**
* List task selection logic for a state.
*
- * @param name name of the policy
- * @param version version of the policy, set to null to use the latest version
+ * @param name name of the policy
+ * @param version version of the policy, set to null to use the latest version
* @param stateName of the state
* @return result of the operation
*/
public ApexApiResult listPolicyStateTaskSelectionLogic(final String name, final String version,
- final String stateName) {
+ final String stateName) {
try {
Assertions.argumentNotNull(stateName, STATE_NAME_MAY_NOT_BE_NULL);
@@ -578,13 +581,13 @@ public class PolicyFacade {
/**
* Delete task selection logic for a state.
*
- * @param name name of the policy
- * @param version version of the policy, set to null to use the latest version
+ * @param name name of the policy
+ * @param version version of the policy, set to null to use the latest version
* @param stateName of the state
* @return result of the operation
*/
public ApexApiResult deletePolicyStateTaskSelectionLogic(final String name, final String version,
- final String stateName) {
+ final String stateName) {
try {
Assertions.argumentNotNull(stateName, STATE_NAME_MAY_NOT_BE_NULL);
@@ -618,19 +621,20 @@ public class PolicyFacade {
/**
* Create a policy state output.
*
- * @param name name of the policy
- * @param version version of the policy, set to null to use the latest version
- * @param stateName of the state
- * @param outputName of the state output
- * @param eventName name of the output event for this state output
+ * @param name name of the policy
+ * @param version version of the policy, set to null to use the latest version
+ * @param stateName of the state
+ * @param outputName of the state output
+ * @param eventName name of the output event for this state output
* @param eventVersion version of the output event for this state output, set to null to use the
- * latest version
- * @param nextState for this state to transition to, set to null if this is the last state that
- * the policy transitions to on this branch
+ * latest version
+ * @param nextState for this state to transition to, set to null if this is the last state that
+ * the policy transitions to on this branch
* @return result of the operation
*/
public ApexApiResult createPolicyStateOutput(final String name, final String version, final String stateName,
- final String outputName, final String eventName, final String eventVersion, final String nextState) {
+ final String outputName, final String eventName,
+ final String eventVersion, final String nextState) {
try {
Assertions.argumentNotNull(stateName, STATE_NAME_MAY_NOT_BE_NULL);
Assertions.argumentNotNull(outputName, "outputName may not be null");
@@ -648,7 +652,7 @@ public class PolicyFacade {
}
final AxReferenceKey refKey = new AxReferenceKey(state.getKey(), outputName);
- // There can be multipe state outputs only when the current state is the final state
+ // There can be multiple state outputs only when the current state is the final state
if (nextState != null && !AxReferenceKey.getNullKey().getLocalName().equals(nextState)
&& state.getStateOutputs().containsKey(refKey.getLocalName())) {
return new ApexApiResult(ApexApiResult.Result.CONCEPT_EXISTS,
@@ -683,7 +687,7 @@ public class PolicyFacade {
}
private void populateStateOuputInfo(final String nextState, final AxState state, final AxReferenceKey refKey,
- final AxEvent event, AxReferenceKey nextStateKey) {
+ final AxEvent event, AxReferenceKey nextStateKey) {
// nextState is null. There could be multiple events coming out of the state
if ((nextState == null || AxReferenceKey.getNullKey().getLocalName().equals(nextState))
&& state.getStateOutputs().containsKey(refKey.getLocalName())) {
@@ -707,14 +711,14 @@ public class PolicyFacade {
/**
* List policy state outputs.
*
- * @param name name of the policy
- * @param version version of the policy, set to null to use the latest version
- * @param stateName of the state
+ * @param name name of the policy
+ * @param version version of the policy, set to null to use the latest version
+ * @param stateName of the state
* @param outputName of the state output, set to null to list all outputs of the state
* @return result of the operation
*/
public ApexApiResult listPolicyStateOutput(final String name, final String version, final String stateName,
- final String outputName) {
+ final String outputName) {
try {
Assertions.argumentNotNull(stateName, STATE_NAME_MAY_NOT_BE_NULL);
@@ -740,7 +744,7 @@ public class PolicyFacade {
CONCEPT + state.getKey().getId() + ':' + outputName + DOES_NOT_EXIST);
}
} else {
- if (state.getStateOutputs().size() == 0) {
+ if (state.getStateOutputs().isEmpty()) {
return new ApexApiResult(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST,
"no state output concepts exist for state " + state.getKey().getId());
}
@@ -761,14 +765,14 @@ public class PolicyFacade {
/**
* Delete a policy state output.
*
- * @param name name of the policy
- * @param version version of the policy, set to null to use the latest version
- * @param stateName of the state
+ * @param name name of the policy
+ * @param version version of the policy, set to null to use the latest version
+ * @param stateName of the state
* @param outputName of the state output, set to null to delete all state outputs
* @return result of the operation
*/
public ApexApiResult deletePolicyStateOutput(final String name, final String version, final String stateName,
- final String outputName) {
+ final String outputName) {
try {
Assertions.argumentNotNull(stateName, STATE_NAME_MAY_NOT_BE_NULL);
@@ -796,7 +800,7 @@ public class PolicyFacade {
CONCEPT + state.getKey().getId() + ':' + outputName + DOES_NOT_EXIST);
}
} else {
- if (state.getStateOutputs().size() == 0) {
+ if (state.getStateOutputs().isEmpty()) {
return new ApexApiResult(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST,
"no state output concepts exist for state " + state.getKey().getId());
}
@@ -818,17 +822,18 @@ public class PolicyFacade {
/**
* Create policy finalizer logic for a state.
*
- * @param name name of the policy
- * @param version version of the policy, set to null to use the latest version
- * @param stateName of the state
+ * @param name name of the policy
+ * @param version version of the policy, set to null to use the latest version
+ * @param stateName of the state
* @param finalizerLogicName name of the state finalizer logic
- * @param logicFlavour the policy finalizer logic flavour for the state, set to null to use the
- * default task logic flavour
- * @param logic the source code for the logic of the state
+ * @param logicFlavour the policy finalizer logic flavour for the state, set to null to use the
+ * default task logic flavour
+ * @param logic the source code for the logic of the state
* @return result of the operation
*/
public ApexApiResult createPolicyStateFinalizerLogic(final String name, final String version,
- final String stateName, final String finalizerLogicName, final String logicFlavour, final String logic) {
+ final String stateName, final String finalizerLogicName,
+ final String logicFlavour, final String logic) {
try {
Assertions.argumentNotNull(stateName, STATE_NAME_MAY_NOT_BE_NULL);
Assertions.argumentNotNull(finalizerLogicName, "finalizerlogicName may not be null");
@@ -863,17 +868,18 @@ public class PolicyFacade {
/**
* Update policy finalizer logic for a state.
*
- * @param name name of the policy
- * @param version version of the policy, set to null to use the latest version
- * @param stateName of the state
+ * @param name name of the policy
+ * @param version version of the policy, set to null to use the latest version
+ * @param stateName of the state
* @param finalizerLogicName name of the state finalizer logic
- * @param logicFlavour the policy finalizer logic flavour for the state, set to null to not
- * update
- * @param logic the source code for the logic of the state, set to null to not update
+ * @param logicFlavour the policy finalizer logic flavour for the state, set to null to not
+ * update
+ * @param logic the source code for the logic of the state, set to null to not update
* @return result of the operation
*/
public ApexApiResult updatePolicyStateFinalizerLogic(final String name, final String version,
- final String stateName, final String finalizerLogicName, final String logicFlavour, final String logic) {
+ final String stateName, final String finalizerLogicName,
+ final String logicFlavour, final String logic) {
try {
Assertions.argumentNotNull(stateName, STATE_NAME_MAY_NOT_BE_NULL);
Assertions.argumentNotNull(finalizerLogicName, "finalizerLogicName may not be null");
@@ -914,14 +920,14 @@ public class PolicyFacade {
/**
* List policy finalizer logic for a state.
*
- * @param name name of the policy
- * @param version version of the policy, set to null to use the latest version
- * @param stateName of the state
+ * @param name name of the policy
+ * @param version version of the policy, set to null to use the latest version
+ * @param stateName of the state
* @param finalizerLogicName name of the state finalizer logic
* @return result of the operation
*/
public ApexApiResult listPolicyStateFinalizerLogic(final String name, final String version, final String stateName,
- final String finalizerLogicName) {
+ final String finalizerLogicName) {
try {
Assertions.argumentNotNull(stateName, STATE_NAME_MAY_NOT_BE_NULL);
@@ -950,7 +956,7 @@ public class PolicyFacade {
new ApexModelStringWriter<AxStateFinalizerLogic>(false).writeString(stateFinalizerLogic,
AxStateFinalizerLogic.class));
} else {
- if (state.getStateFinalizerLogicMap().size() == 0) {
+ if (state.getStateFinalizerLogicMap().isEmpty()) {
return new ApexApiResult(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST,
"no state finalizer logic defined on state " + state.getKey().getId());
}
@@ -969,14 +975,14 @@ public class PolicyFacade {
/**
* Delete policy finalizer logic for a state.
*
- * @param name name of the policy
- * @param version version of the policy, set to null to use the latest version
- * @param stateName of the state
+ * @param name name of the policy
+ * @param version version of the policy, set to null to use the latest version
+ * @param stateName of the state
* @param finalizerLogicName name of the state finalizer logic
* @return result of the operation
*/
public ApexApiResult deletePolicyStateFinalizerLogic(final String name, final String version,
- final String stateName, final String finalizerLogicName) {
+ final String stateName, final String finalizerLogicName) {
try {
Assertions.argumentNotNull(stateName, STATE_NAME_MAY_NOT_BE_NULL);
@@ -1007,17 +1013,18 @@ public class PolicyFacade {
state.getStateFinalizerLogicMap().remove(refKey.getLocalName());
return result;
} else {
- if (state.getStateFinalizerLogicMap().size() == 0) {
- return new ApexApiResult(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST,
- "no state finalizer logic defined on state " + state.getKey().getId());
- }
+ ApexApiResult result = new ApexApiResult();
- final ApexApiResult result = new ApexApiResult();
- for (final AxStateFinalizerLogic stateFinalizerLogic : state.getStateFinalizerLogicMap().values()) {
- result.addMessage(new ApexModelStringWriter<AxStateFinalizerLogic>(false)
- .writeString(stateFinalizerLogic, AxStateFinalizerLogic.class));
+ if (state.getStateFinalizerLogicMap().isEmpty()) {
+ result = new ApexApiResult(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST,
+ "no state finalizer logic defined on state " + state.getKey().getId());
+ } else {
+ for (final AxStateFinalizerLogic stateFinalizerLogic : state.getStateFinalizerLogicMap().values()) {
+ result.addMessage(new ApexModelStringWriter<AxStateFinalizerLogic>(false)
+ .writeString(stateFinalizerLogic, AxStateFinalizerLogic.class));
+ }
+ state.getStateFinalizerLogicMap().clear();
}
- state.getStateFinalizerLogicMap().clear();
return result;
}
} catch (final Exception e) {
@@ -1124,15 +1131,15 @@ public class PolicyFacade {
/**
* List policy state task references.
*
- * @param name name of the policy
- * @param version version of the policy, set to null to use the latest version
- * @param stateName of the state
- * @param taskName name of the task, set to null to list all task references
+ * @param name name of the policy
+ * @param version version of the policy, set to null to use the latest version
+ * @param stateName of the state
+ * @param taskName name of the task, set to null to list all task references
* @param taskVersion version of the task, set to null to use the latest version
* @return result of the operation
*/
public ApexApiResult listPolicyStateTaskRef(final String name, final String version, final String stateName,
- final String taskName, final String taskVersion) {
+ final String taskName, final String taskVersion) {
try {
Assertions.argumentNotNull(stateName, STATE_NAME_MAY_NOT_BE_NULL);
@@ -1179,15 +1186,15 @@ public class PolicyFacade {
/**
* Delete a policy state task reference.
*
- * @param name name of the policy
- * @param version version of the policy, set to null to use the latest version
- * @param stateName of the state
- * @param taskName name of the task, set to null to delete all task references
+ * @param name name of the policy
+ * @param version version of the policy, set to null to use the latest version
+ * @param stateName of the state
+ * @param taskName name of the task, set to null to delete all task references
* @param taskVersion version of the task, set to null to use the latest version
* @return result of the operation
*/
public ApexApiResult deletePolicyStateTaskRef(final String name, final String version, final String stateName,
- final String taskName, final String taskVersion) {
+ final String taskName, final String taskVersion) {
try {
Assertions.argumentNotNull(stateName, STATE_NAME_MAY_NOT_BE_NULL);
@@ -1232,16 +1239,16 @@ public class PolicyFacade {
/**
* Create a policy state context album reference.
*
- * @param name name of the policy
- * @param version version of the policy, set to null to use the latest version
- * @param stateName of the state
- * @param contextAlbumName name of the context album for the context album reference
+ * @param name name of the policy
+ * @param version version of the policy, set to null to use the latest version
+ * @param stateName of the state
+ * @param contextAlbumName name of the context album for the context album reference
* @param contextAlbumVersion version of the context album for the context album reference, set
- * to null to use the latest version
+ * to null to use the latest version
* @return result of the operation
*/
public ApexApiResult createPolicyStateContextRef(final String name, final String version, final String stateName,
- final String contextAlbumName, final String contextAlbumVersion) {
+ final String contextAlbumName, final String contextAlbumVersion) {
try {
Assertions.argumentNotNull(stateName, STATE_NAME_MAY_NOT_BE_NULL);
@@ -1279,17 +1286,17 @@ public class PolicyFacade {
/**
* List policy state context album references.
*
- * @param name name of the policy
- * @param version version of the policy, set to null to use the latest version
- * @param stateName of the state
- * @param contextAlbumName name of the context album for the context album reference, set to
- * null to list all task context album references
+ * @param name name of the policy
+ * @param version version of the policy, set to null to use the latest version
+ * @param stateName of the state
+ * @param contextAlbumName name of the context album for the context album reference, set to
+ * null to list all task context album references
* @param contextAlbumVersion version of the context album for the context album reference, set
- * to null to use the latest version
+ * to null to use the latest version
* @return result of the operation
*/
public ApexApiResult listPolicyStateContextRef(final String name, final String version, final String stateName,
- final String contextAlbumName, final String contextAlbumVersion) {
+ final String contextAlbumName, final String contextAlbumVersion) {
try {
Assertions.argumentNotNull(stateName, STATE_NAME_MAY_NOT_BE_NULL);
@@ -1329,17 +1336,17 @@ public class PolicyFacade {
/**
* Delete a policy state context album reference.
*
- * @param name name of the policy
- * @param version version of the policy, set to null to use the default version
- * @param stateName of the state
- * @param contextAlbumName name of the context album for the context album reference, set to
- * null to delete all task context album references
+ * @param name name of the policy
+ * @param version version of the policy, set to null to use the default version
+ * @param stateName of the state
+ * @param contextAlbumName name of the context album for the context album reference, set to
+ * null to delete all task context album references
* @param contextAlbumVersion version of the context album for the context album reference, set
- * to null to use the latest version
+ * to null to use the latest version
* @return result of the operation
*/
public ApexApiResult deletePolicyStateContextRef(final String name, final String version, final String stateName,
- final String contextAlbumName, final String contextAlbumVersion) {
+ final String contextAlbumName, final String contextAlbumVersion) {
try {
Assertions.argumentNotNull(stateName, STATE_NAME_MAY_NOT_BE_NULL);
diff --git a/model/src/main/java/org/onap/policy/apex/model/policymodel/concepts/AxLogic.java b/model/src/main/java/org/onap/policy/apex/model/policymodel/concepts/AxLogic.java
index 0564d5854..50d6771b5 100644
--- a/model/src/main/java/org/onap/policy/apex/model/policymodel/concepts/AxLogic.java
+++ b/model/src/main/java/org/onap/policy/apex/model/policymodel/concepts/AxLogic.java
@@ -1,7 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
- * Modifications Copyright (C) 2019-2020,2022 Nordix Foundation.
+ * Modifications Copyright (C) 2019-2020, 2022, 2024 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -21,7 +21,9 @@
package org.onap.policy.apex.model.policymodel.concepts;
+import java.io.Serial;
import java.util.List;
+import lombok.Getter;
import org.onap.policy.apex.model.basicmodel.concepts.AxConcept;
import org.onap.policy.apex.model.basicmodel.concepts.AxKey;
import org.onap.policy.apex.model.basicmodel.concepts.AxReferenceKey;
@@ -43,26 +45,31 @@ import org.onap.policy.common.utils.validation.Assertions;
* the {@code LOGIC_FLAVOUR_REGEXP} regular expression, and that the specified logic string is not null or blank.
*/
public class AxLogic extends AxConcept {
- private static final long serialVersionUID = -4260562004005697328L;
- private static final String WHITESPACE_REGEXP = "\\s+$";
+ @Serial
+ private static final long serialVersionUID = -4260562004005697328L;
private static final String LOGIC_FLAVOUR_TOKEN = "logicFlavour";
private static final String KEY_NULL_MESSAGE = "key may not be null";
private static final String LOGIC_FLAVOUR_NULL_MESSAGE = "logicFlavour may not be null";
private static final String LOGIC_NULL_MESSAGE = "logic may not be null";
- /** Regular expression that specifies the allowed characters in logic flavour tokens. */
+ /**
+ * Regular expression that specifies the allowed characters in logic flavour tokens.
+ */
public static final String LOGIC_FLAVOUR_REGEXP = "[A-Za-z0-9\\-_]+";
- /** When logic flavour is undefined, it has this value. */
+ /**
+ * When logic flavour is undefined, it has this value.
+ */
public static final String LOGIC_FLAVOUR_UNDEFINED = "UNDEFINED";
- /** The maximum permissible size of a logic definition. */
- public static final int MAX_LOGIC_SIZE = 32672; // The maximum size supported by Apache Derby
-
private AxReferenceKey key;
+
+ @Getter
private String logicFlavour;
+
+ @Getter
private String logic;
/**
@@ -97,22 +104,22 @@ public class AxLogic extends AxConcept {
* This Constructor creates a logic instance with a reference key constructed from the parents key and the logic
* local name and all of its fields defined.
*
- * @param parentKey the reference key of the parent of this logic
- * @param logicName the logic name, held as the local name of the reference key of this logic
+ * @param parentKey the reference key of the parent of this logic
+ * @param logicName the logic name, held as the local name of the reference key of this logic
* @param logicFlavour the flavour of this logic
- * @param logic the actual logic as a string
+ * @param logic the actual logic as a string
*/
public AxLogic(final AxReferenceKey parentKey, final String logicName, final String logicFlavour,
- final String logic) {
+ final String logic) {
this(new AxReferenceKey(parentKey, logicName), logicFlavour, logic);
}
/**
* This Constructor creates a logic instance with the given reference key and all of its fields defined.
*
- * @param key the reference key of this logic
+ * @param key the reference key of this logic
* @param logicFlavour the flavour of this logic
- * @param logic the actual logic as a string
+ * @param logic the actual logic as a string
*/
public AxLogic(final AxReferenceKey key, final String logicFlavour, final String logic) {
super();
@@ -122,16 +129,16 @@ public class AxLogic extends AxConcept {
this.key = key;
this.logicFlavour = Assertions.validateStringParameter(LOGIC_FLAVOUR_TOKEN, logicFlavour, LOGIC_FLAVOUR_REGEXP);
- this.logic = logic.replaceAll(WHITESPACE_REGEXP, "");
+ this.logic = logic.replaceAll(WHITESPACE_REGEX, "");
}
/**
* This Constructor creates a logic instance with the given reference key and logic flavour, the logic is provided
* by the given logic reader instance.
*
- * @param key the reference key of this logic
+ * @param key the reference key of this logic
* @param logicFlavour the flavour of this logic
- * @param logicReader the logic reader to use to read the logic for this logic instance
+ * @param logicReader the logic reader to use to read the logic for this logic instance
*/
public AxLogic(final AxReferenceKey key, final String logicFlavour, final AxLogicReader logicReader) {
super();
@@ -171,15 +178,6 @@ public class AxLogic extends AxConcept {
}
/**
- * Gets the logic flavour.
- *
- * @return the logic flavour
- */
- public String getLogicFlavour() {
- return logicFlavour;
- }
-
- /**
* Sets the logic flavour.
*
* @param logicFlavour the logic flavour
@@ -189,22 +187,13 @@ public class AxLogic extends AxConcept {
}
/**
- * Gets the logic.
- *
- * @return the logic
- */
- public String getLogic() {
- return logic;
- }
-
- /**
* Sets the logic.
*
* @param logic the logic
*/
public void setLogic(final String logic) {
Assertions.argumentNotNull(logic, LOGIC_NULL_MESSAGE);
- this.logic = logic.replaceAll(WHITESPACE_REGEXP, "");
+ this.logic = logic.replaceAll(WHITESPACE_REGEX, "");
}
/**
@@ -216,27 +205,27 @@ public class AxLogic extends AxConcept {
if (key.equals(AxReferenceKey.getNullKey())) {
result.addValidationMessage(new AxValidationMessage(key, this.getClass(), ValidationResult.INVALID,
- "key is a null key"));
+ "key is a null key"));
}
result = key.validate(result);
- if (logicFlavour.replaceAll(WHITESPACE_REGEXP, "").length() == 0
- || logicFlavour.equals(LOGIC_FLAVOUR_UNDEFINED)) {
+ if (logicFlavour.replaceAll(WHITESPACE_REGEX, "").isEmpty()
+ || logicFlavour.equals(LOGIC_FLAVOUR_UNDEFINED)) {
result.addValidationMessage(new AxValidationMessage(key, this.getClass(), ValidationResult.INVALID,
- "logic flavour is not defined"));
+ "logic flavour is not defined"));
}
String flavourValidationString = Assertions.getStringParameterValidationMessage(LOGIC_FLAVOUR_TOKEN,
- logicFlavour, LOGIC_FLAVOUR_REGEXP);
+ logicFlavour, LOGIC_FLAVOUR_REGEXP);
if (flavourValidationString != null) {
result.addValidationMessage(new AxValidationMessage(key, this.getClass(), ValidationResult.INVALID,
- "logic flavour invalid-" + flavourValidationString));
+ "logic flavour invalid-" + flavourValidationString));
}
- if (logic.replaceAll(WHITESPACE_REGEXP, "").length() == 0) {
+ if (logic.replaceAll(WHITESPACE_REGEX, "").isEmpty()) {
result.addValidationMessage(new AxValidationMessage(key, this.getClass(), ValidationResult.INVALID,
- "no logic specified, logic may not be blank"));
+ "no logic specified, logic may not be blank"));
}
return result;
@@ -251,7 +240,7 @@ public class AxLogic extends AxConcept {
key.clean();
}
logicFlavour = Assertions.validateStringParameter(LOGIC_FLAVOUR_TOKEN, logicFlavour, LOGIC_FLAVOUR_REGEXP);
- logic = logic.replaceAll(WHITESPACE_REGEXP, "");
+ logic = logic.replaceAll(WHITESPACE_REGEX, "");
}
/**
@@ -259,17 +248,8 @@ public class AxLogic extends AxConcept {
*/
@Override
public String toString() {
- final StringBuilder builder = new StringBuilder();
- builder.append(this.getClass().getSimpleName());
- builder.append(":(");
- builder.append("key=");
- builder.append(key);
- builder.append(",logicFlavour=");
- builder.append(logicFlavour);
- builder.append(",logic=");
- builder.append(logic);
- builder.append(")");
- return builder.toString();
+ return this.getClass().getSimpleName()
+ + ":(" + "key=" + key + ",logicFlavour=" + logicFlavour + ",logic=" + logic + ")";
}
/**
@@ -279,10 +259,9 @@ public class AxLogic extends AxConcept {
public AxConcept copyTo(final AxConcept targetObject) {
Assertions.argumentNotNull(targetObject, "target may not be null");
- final Object copyObject = targetObject;
- Assertions.instanceOf(copyObject, AxLogic.class);
+ Assertions.instanceOf(targetObject, AxLogic.class);
- final AxLogic copy = ((AxLogic) copyObject);
+ final AxLogic copy = ((AxLogic) targetObject);
copy.setKey(new AxReferenceKey(key));
copy.setLogicFlavour(logicFlavour);
copy.setLogic(logic);
diff --git a/model/src/main/java/org/onap/policy/apex/model/policymodel/concepts/AxPolicyModel.java b/model/src/main/java/org/onap/policy/apex/model/policymodel/concepts/AxPolicyModel.java
index e119536fb..049757599 100644
--- a/model/src/main/java/org/onap/policy/apex/model/policymodel/concepts/AxPolicyModel.java
+++ b/model/src/main/java/org/onap/policy/apex/model/policymodel/concepts/AxPolicyModel.java
@@ -1,7 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
- * Modifications Copyright (C) 2019,2022 Nordix Foundation.
+ * Modifications Copyright (C) 2019, 2022, 2024 Nordix Foundation.
* Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
* Modifications Copyright (C) 2021 Bell Canada. All rights reserved.
* ================================================================================
@@ -23,8 +23,10 @@
package org.onap.policy.apex.model.policymodel.concepts;
+import java.io.Serial;
import java.util.List;
import java.util.Map.Entry;
+import lombok.Getter;
import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
import org.onap.policy.apex.model.basicmodel.concepts.AxConcept;
import org.onap.policy.apex.model.basicmodel.concepts.AxKey;
@@ -88,17 +90,19 @@ import org.onap.policy.common.utils.validation.Assertions;
* <li>All events referred to on direct state outputs must exist
* </ol>
*/
+@Getter
public class AxPolicyModel extends AxModel {
- // @formatter:off
- private static final String SCHEMAS_TOKEN = "_Schemas";
- private static final String KEY_INFO_TOKEN = "_KeyInfo";
- private static final String EVENTS_TOKEN = "_Events";
- private static final String ALBUMS_TOKEN = "_Albums";
- private static final String TASKS_TOKEN = "_Tasks";
+
+ private static final String SCHEMAS_TOKEN = "_Schemas";
+ private static final String KEY_INFO_TOKEN = "_KeyInfo";
+ private static final String EVENTS_TOKEN = "_Events";
+ private static final String ALBUMS_TOKEN = "_Albums";
+ private static final String TASKS_TOKEN = "_Tasks";
private static final String POLICIESS_TOKEN = "_Policies";
private static final String DOES_NOT_EXIST = " does not exist";
+ @Serial
private static final long serialVersionUID = 8800599637708309945L;
private AxPolicies policies;
@@ -136,23 +140,24 @@ public class AxPolicyModel extends AxModel {
new AxKeyInformation(new AxArtifactKey(key.getName() + KEY_INFO_TOKEN, key.getVersion())),
new AxEvents(new AxArtifactKey(key.getName() + EVENTS_TOKEN, key.getVersion())),
new AxContextAlbums(new AxArtifactKey(key.getName() + ALBUMS_TOKEN, key.getVersion())),
- new AxTasks(new AxArtifactKey(key.getName() + TASKS_TOKEN, key.getVersion())),
+ new AxTasks(new AxArtifactKey(key.getName() + TASKS_TOKEN, key.getVersion())),
new AxPolicies(new AxArtifactKey(key.getName() + POLICIESS_TOKEN, key.getVersion())));
}
/**
* This Constructor creates a policy model with all of its fields specified.
*
- * @param key the key of the policy model
- * @param schemas the context schema container for the policy model
+ * @param key the key of the policy model
+ * @param schemas the context schema container for the policy model
* @param keyInformation the key information container for the policy model
- * @param events the event container for the policy model
- * @param albums the context album container for the policy model
- * @param tasks the task container for the policy model
- * @param policies the policy container for the policy model
- */
- public AxPolicyModel(final AxArtifactKey key, final AxContextSchemas schemas, final AxKeyInformation keyInformation,
- final AxEvents events, final AxContextAlbums albums, final AxTasks tasks, final AxPolicies policies) {
+ * @param events the event container for the policy model
+ * @param albums the context album container for the policy model
+ * @param tasks the task container for the policy model
+ * @param policies the policy container for the policy model
+ */
+ public AxPolicyModel(final AxArtifactKey key, final AxContextSchemas schemas,
+ final AxKeyInformation keyInformation, final AxEvents events, final AxContextAlbums albums,
+ final AxTasks tasks, final AxPolicies policies) {
super(key, keyInformation);
Assertions.argumentNotNull(schemas, "schemas may not be null");
Assertions.argumentNotNull(events, "events may not be null");
@@ -203,17 +208,8 @@ public class AxPolicyModel extends AxModel {
* @return the context model
*/
public AxContextModel getContextModel() {
- return new AxContextModel(new AxArtifactKey(albums.getKey().getName() + "_Model", albums.getKey().getVersion()),
- getSchemas(), getAlbums(), getKeyInformation());
- }
-
- /**
- * Gets the policy container from the policy model.
- *
- * @return the policy container with all the policies in the model
- */
- public AxPolicies getPolicies() {
- return policies;
+ return new AxContextModel(new AxArtifactKey(albums.getKey().getName() + "_Model",
+ albums.getKey().getVersion()), getSchemas(), getAlbums(), getKeyInformation());
}
/**
@@ -227,15 +223,6 @@ public class AxPolicyModel extends AxModel {
}
/**
- * Gets the task container from the policy model.
- *
- * @return the task container with all the tasks in the model
- */
- public AxTasks getTasks() {
- return tasks;
- }
-
- /**
* Sets the task container from the policy model.
*
* @param tasks the task container with all the tasks in the model
@@ -246,15 +233,6 @@ public class AxPolicyModel extends AxModel {
}
/**
- * Gets the event container from the policy model.
- *
- * @return the event container with all the events in the model
- */
- public AxEvents getEvents() {
- return events;
- }
-
- /**
* Sets the event container from the policy model.
*
* @param events the event container with all the events in the model
@@ -265,15 +243,6 @@ public class AxPolicyModel extends AxModel {
}
/**
- * Gets the context album container from the policy model.
- *
- * @return the context album container with all the context albums in the model
- */
- public AxContextAlbums getAlbums() {
- return albums;
- }
-
- /**
* Sets the context album container from the policy model.
*
* @param albums the context album container with all the context albums in the model
@@ -284,15 +253,6 @@ public class AxPolicyModel extends AxModel {
}
/**
- * Gets the context schema container from the policy model.
- *
- * @return the context schema container with all the context schemas in the model
- */
- public AxContextSchemas getSchemas() {
- return schemas;
- }
-
- /**
* Sets the context schema container from the policy model.
*
* @param schemas the context schema container with all the context schemas in the model
@@ -376,7 +336,7 @@ public class AxPolicyModel extends AxModel {
/**
* Validate all fundamental concepts keyed in tasks exist.
*
- * @param task The task to validate the keys of
+ * @param task The task to validate the keys of
* @param result the validation result to return
* @return the result
*/
@@ -409,7 +369,7 @@ public class AxPolicyModel extends AxModel {
/**
* Validate that the references used on a state are valid.
*
- * @param state The state to check
+ * @param state The state to check
* @param result the validation result to append to
*/
private void validateStateReferences(AxState state, AxValidationResult result) {
@@ -436,7 +396,7 @@ public class AxPolicyModel extends AxModel {
if (events.getEventMap().get(stateOutput.getOutgoingEvent()) == null) {
result.addValidationMessage(new AxValidationMessage(stateOutput.getKey(), this.getClass(),
ValidationResult.INVALID, "output event " + stateOutput.getOutgoingEvent().getId()
- + " for state output " + stateOutput.getId() + DOES_NOT_EXIST));
+ + " for state output " + stateOutput.getId() + DOES_NOT_EXIST));
}
}
@@ -447,7 +407,7 @@ public class AxPolicyModel extends AxModel {
* Validate that the fields on tasks and events that trigger them and are output by them are
* compatible for all tasks used on a state.
*
- * @param state The state to check
+ * @param state The state to check
* @param result the validation result to append to
*/
private void validateEventTaskFieldCompatibilityOnState(AxState state, AxValidationResult result) {
@@ -474,13 +434,14 @@ public class AxPolicyModel extends AxModel {
* Validate that the fields on a task of a state output and the events that trigger it are
* compatible.
*
- * @param state The state to check
- * @param task The task to check
+ * @param state The state to check
+ * @param task The task to check
* @param stateOutput The state output to check
- * @param result the validation result to append to
+ * @param result the validation result to append to
*/
private void validateEventTaskFieldCompatibilityOnStateOutput(final AxState state, final AxTask task,
- final AxStateOutput stateOutput, AxValidationResult result) {
+ final AxStateOutput stateOutput,
+ AxValidationResult result) {
if (stateOutput == null) {
result.addValidationMessage(new AxValidationMessage(state.getKey(), this.getClass(),
ValidationResult.INVALID, "state output on task reference for task " + task.getId() + " is null"));
@@ -490,7 +451,7 @@ public class AxPolicyModel extends AxModel {
if (usedEvent == null) {
result.addValidationMessage(new AxValidationMessage(stateOutput.getKey(), this.getClass(),
ValidationResult.INVALID, "output event " + stateOutput.getOutgoingEvent().getId()
- + " for state output " + stateOutput.getId() + DOES_NOT_EXIST));
+ + " for state output " + stateOutput.getId() + DOES_NOT_EXIST));
}
}
}
@@ -509,10 +470,10 @@ public class AxPolicyModel extends AxModel {
getPolicies().buildReferences();
getKeyInformation().buildReferences();
- AxArtifactKey nullAlbumskey = new AxArtifactKey(AxKey.NULL_KEY_NAME + ALBUMS_TOKEN, AxKey.NULL_KEY_VERSION);
+ AxArtifactKey nullAlbumsKey = new AxArtifactKey(AxKey.NULL_KEY_NAME + ALBUMS_TOKEN, AxKey.NULL_KEY_VERSION);
if (AxArtifactKey.getNullKey().equals(getAlbums().getKey())
- || nullAlbumskey.equals(getAlbums().getKey())) {
+ || nullAlbumsKey.equals(getAlbums().getKey())) {
getAlbums().setKey(new AxArtifactKey(getKey().getName() + ALBUMS_TOKEN, getKey().getVersion()));
getKeyInformation().generateKeyInfo(getAlbums());
}
@@ -536,22 +497,9 @@ public class AxPolicyModel extends AxModel {
*/
@Override
public String toString() {
- final StringBuilder builder = new StringBuilder();
- builder.append(this.getClass().getSimpleName());
- builder.append(":(");
- builder.append(super.toString());
- builder.append(",policies=");
- builder.append(policies);
- builder.append(",tasks=");
- builder.append(tasks);
- builder.append(",events=");
- builder.append(events);
- builder.append(",albums=");
- builder.append(albums);
- builder.append(",schemas=");
- builder.append(schemas);
- builder.append(")");
- return builder.toString();
+ return this.getClass().getSimpleName()
+ + ":(" + super.toString() + ",policies=" + policies + ",tasks=" + tasks + ",events=" + events + ",albums="
+ + albums + ",schemas=" + schemas + ")";
}
/**
@@ -561,10 +509,9 @@ public class AxPolicyModel extends AxModel {
public AxConcept copyTo(final AxConcept targetObject) {
Assertions.argumentNotNull(targetObject, "target may not be null");
- final Object copyObject = targetObject;
- Assertions.instanceOf(copyObject, AxPolicyModel.class);
+ Assertions.instanceOf(targetObject, AxPolicyModel.class);
- final AxPolicyModel copy = ((AxPolicyModel) copyObject);
+ final AxPolicyModel copy = ((AxPolicyModel) targetObject);
super.copyTo(targetObject);
copy.setPolicies(new AxPolicies(policies));
copy.setTasks(new AxTasks(tasks));
diff --git a/model/src/main/java/org/onap/policy/apex/model/policymodel/handling/PolicyLogicReader.java b/model/src/main/java/org/onap/policy/apex/model/policymodel/handling/PolicyLogicReader.java
index f70068454..4a8780a4f 100644
--- a/model/src/main/java/org/onap/policy/apex/model/policymodel/handling/PolicyLogicReader.java
+++ b/model/src/main/java/org/onap/policy/apex/model/policymodel/handling/PolicyLogicReader.java
@@ -1,7 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
- * Modifications Copyright (C) 2020 Nordix Foundation.
+ * Modifications Copyright (C) 2020, 2024 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -21,6 +21,8 @@
package org.onap.policy.apex.model.policymodel.handling;
+import static org.onap.policy.apex.model.basicmodel.concepts.AxConcept.WHITESPACE_REGEX;
+
import org.onap.policy.apex.model.basicmodel.concepts.AxKey;
import org.onap.policy.apex.model.policymodel.concepts.AxLogic;
import org.onap.policy.apex.model.policymodel.concepts.AxLogicReader;
@@ -96,19 +98,35 @@ public class PolicyLogicReader implements AxLogicReader {
// Return the java class name for the logic
if (axLogic.getKey().getParentLocalName().equals(AxKey.NULL_KEY_NAME)) {
return logicPackage + DOT_JAVA + axLogic.getKey().getParentKeyName()
- + axLogic.getKey().getLocalName();
+ + axLogic.getKey().getLocalName();
} else {
return logicPackage + DOT_JAVA + axLogic.getKey().getParentKeyName()
- + axLogic.getKey().getParentLocalName() + axLogic.getKey().getLocalName();
+ + axLogic.getKey().getParentLocalName() + axLogic.getKey().getLocalName();
}
}
}
// Now, we read in the script
// Get the package name of the current package and convert dots to slashes for the file path
+ String fullLogicFilePath = getFullLogicFilePath(axLogic);
+
+ final String logicString = ResourceUtils.getResourceAsString(fullLogicFilePath);
+
+ // Check if the logic was found
+ if (logicString == null || logicString.isEmpty()) {
+ String errorMessage = "logic not found for logic \"" + fullLogicFilePath + "\"";
+ LOGGER.warn(errorMessage);
+ throw new PolicyRuntimeException(errorMessage);
+ }
+
+ // Return the right trimmed logic string
+ return logicString.replaceAll(WHITESPACE_REGEX, "");
+ }
+
+ private String getFullLogicFilePath(AxLogic axLogic) {
String fullLogicFilePath = logicPackage.replace(".", "/");
- // Now, the logic should be in a sub directory for the logic executor type
+ // Now, the logic should be in a subdirectory for the logic executor type
fullLogicFilePath += "/" + axLogic.getLogicFlavour().toLowerCase();
// Check if we're using the default logic
@@ -120,23 +138,12 @@ public class PolicyLogicReader implements AxLogicReader {
fullLogicFilePath += "/" + axLogic.getKey().getParentKeyName() + axLogic.getKey().getLocalName();
} else {
fullLogicFilePath += "/" + axLogic.getKey().getParentKeyName()
- + axLogic.getKey().getParentLocalName() + axLogic.getKey().getLocalName();
+ + axLogic.getKey().getParentLocalName() + axLogic.getKey().getLocalName();
}
}
// Now get the type of executor to find the extension of the file
fullLogicFilePath += "." + axLogic.getLogicFlavour().toLowerCase();
-
- final String logicString = ResourceUtils.getResourceAsString(fullLogicFilePath);
-
- // Check if the logic was found
- if (logicString == null || logicString.length() == 0) {
- String errorMessage = "logic not found for logic \"" + fullLogicFilePath + "\"";
- LOGGER.warn(errorMessage);
- throw new PolicyRuntimeException(errorMessage);
- }
-
- // Return the right trimmed logic string
- return logicString.replaceAll("\\s+$", "");
+ return fullLogicFilePath;
}
}