diff options
author | liamfallon <liam.fallon@est.tech> | 2020-05-06 16:19:38 +0100 |
---|---|---|
committer | liamfallon <liam.fallon@est.tech> | 2020-05-06 16:27:30 +0100 |
commit | 3adbaa909ad1af4f80f7347cdfbce8bcab892db0 (patch) | |
tree | 9ae867bf0ed606ab0cb791eb266be5fa120856d4 /models-tosca/src/main/java/org | |
parent | 0813923baa10ddd08e8cb3eccff8ac224f2b8aa4 (diff) |
Make type and type_version mandatory on policies
Up until now, the "type" and "type_version" fields defaulted to "NULL"
and "0.0.0" respectively when they were not specified because the
"type_version" field was not always specified on policies in previous
releases. In cases where the "type_version" field was not specified, it
was assumend that a "0.0.0" version of the policy type existed. In
parallel, if the version field was not specified on the policy type, the
version was stored as 0.0.0.
This behaviour is now changed and the "type" and "type_version" fields
are now always mandatory.
Issue-ID: POLICY-2538
Change-Id: I4279adfa86f531205879dbb87986453604624032
Signed-off-by: liamfallon <liam.fallon@est.tech>
Diffstat (limited to 'models-tosca/src/main/java/org')
-rw-r--r-- | models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicy.java | 22 |
1 files changed, 13 insertions, 9 deletions
diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicy.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicy.java index 1f5c76e59..a7650c532 100644 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicy.java +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicy.java @@ -173,7 +173,7 @@ public class JpaToscaPolicy extends JpaToscaEntityType<ToscaPolicy> implements P propertyMap.put(entry.getKey(), coder.decode(entry.getValue(), Object.class)); } catch (CoderException ce) { String errorMessage = "error decoding property JSON value read from database: key=" + entry.getKey() - + ", value=" + entry.getValue(); + + ", value=" + entry.getValue(); throw new PfModelRuntimeException(Response.Status.INTERNAL_SERVER_ERROR, errorMessage, ce); } } @@ -191,13 +191,17 @@ public class JpaToscaPolicy extends JpaToscaEntityType<ToscaPolicy> implements P if (toscaPolicy.getType() != null) { type.setName(toscaPolicy.getType()); } else { - type.setName(PfKey.NULL_KEY_NAME); + throw new PfModelRuntimeException(Response.Status.BAD_REQUEST, + "PolicyType type not specified, the type of the PolicyType for this policy must be specified in " + + "the type field"); } if (toscaPolicy.getTypeVersion() != null) { type.setVersion(toscaPolicy.getTypeVersion()); } else { - type.setVersion(PfKey.NULL_KEY_VERSION); + throw new PfModelRuntimeException(Response.Status.BAD_REQUEST, + "PolicyType version not specified, the version of the PolicyType for this policy must be specified in " + + "the type_version field"); } if (toscaPolicy.getProperties() != null) { @@ -215,7 +219,7 @@ public class JpaToscaPolicy extends JpaToscaEntityType<ToscaPolicy> implements P properties.put(propertyEntry.getKey(), coder.encode(propertyEntry.getValue())); } catch (CoderException ce) { String errorMessage = "error encoding property JSON value for database: key=" - + propertyEntry.getKey() + ", value=" + propertyEntry.getValue(); + + propertyEntry.getKey() + ", value=" + propertyEntry.getValue(); throw new PfModelRuntimeException(Response.Status.INTERNAL_SERVER_ERROR, errorMessage, ce); } } @@ -263,12 +267,12 @@ public class JpaToscaPolicy extends JpaToscaEntityType<ToscaPolicy> implements P if (PfKey.NULL_KEY_VERSION.equals(getKey().getVersion())) { result.addValidationMessage(new PfValidationMessage(getKey(), this.getClass(), ValidationResult.INVALID, - "key version is a null version")); + "key version is a null version")); } if (type == null || type.isNullKey()) { result.addValidationMessage(new PfValidationMessage(getKey(), this.getClass(), ValidationResult.INVALID, - "type is null or a null key")); + "type is null or a null key")); } else { result = type.validate(result); } @@ -294,10 +298,10 @@ public class JpaToscaPolicy extends JpaToscaEntityType<ToscaPolicy> implements P for (Entry<String, String> propertyEntry : properties.entrySet()) { if (!ParameterValidationUtils.validateStringParameter(propertyEntry.getKey())) { result.addValidationMessage(new PfValidationMessage(getKey(), this.getClass(), ValidationResult.INVALID, - "policy property key may not be null ")); + "policy property key may not be null ")); } else if (propertyEntry.getValue() == null) { result.addValidationMessage(new PfValidationMessage(getKey(), this.getClass(), ValidationResult.INVALID, - "policy property value may not be null ")); + "policy property value may not be null ")); } } } @@ -314,7 +318,7 @@ public class JpaToscaPolicy extends JpaToscaEntityType<ToscaPolicy> implements P for (PfConceptKey target : targets) { if (target == null) { result.addValidationMessage(new PfValidationMessage(getKey(), this.getClass(), ValidationResult.INVALID, - "policy target may not be null ")); + "policy target may not be null ")); } else { result = target.validate(result); } |