summaryrefslogtreecommitdiffstats
path: root/models-pdp/src/main
diff options
context:
space:
mode:
authorJim Hahn <jrh3@att.com>2020-12-17 12:07:14 -0500
committerJim Hahn <jrh3@att.com>2020-12-17 18:52:46 -0500
commit6345dce40405740dc09176c45dae03baeb939b8e (patch)
tree07804a2f9e2dfd1083975c79059346a9cf778b1d /models-pdp/src/main
parent4c4946e339942863e73e20726dd95aaacfcfb5a6 (diff)
Use ValidationResult for models v2.0
Policy models uses PfValidationXxx classes which are totally unrelated to ValidationResult in policy common. This precludes the use of various utility methods and annotations for doing validation. Modified policy models to use ValidationResult instead. This approach uses function calls, though a future approach could make use of annotations instead. Issue-ID: POLICY-2648 Change-Id: I9760f1dc46902ab6bef7f440f3caf5e951660a5d Signed-off-by: Jim Hahn <jrh3@att.com>
Diffstat (limited to 'models-pdp/src/main')
-rw-r--r--models-pdp/src/main/java/org/onap/policy/models/pdp/persistence/concepts/JpaPdp.java44
-rw-r--r--models-pdp/src/main/java/org/onap/policy/models/pdp/persistence/concepts/JpaPdpGroup.java63
-rw-r--r--models-pdp/src/main/java/org/onap/policy/models/pdp/persistence/concepts/JpaPdpStatistics.java16
-rw-r--r--models-pdp/src/main/java/org/onap/policy/models/pdp/persistence/concepts/JpaPdpSubGroup.java81
-rw-r--r--models-pdp/src/main/java/org/onap/policy/models/pdp/persistence/provider/PdpProvider.java42
-rw-r--r--models-pdp/src/main/java/org/onap/policy/models/pdp/persistence/provider/PdpStatisticsProvider.java24
6 files changed, 63 insertions, 207 deletions
diff --git a/models-pdp/src/main/java/org/onap/policy/models/pdp/persistence/concepts/JpaPdp.java b/models-pdp/src/main/java/org/onap/policy/models/pdp/persistence/concepts/JpaPdp.java
index 5820a355b..d231fe7e4 100644
--- a/models-pdp/src/main/java/org/onap/policy/models/pdp/persistence/concepts/JpaPdp.java
+++ b/models-pdp/src/main/java/org/onap/policy/models/pdp/persistence/concepts/JpaPdp.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* ONAP Policy Model
* ================================================================================
- * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved.
* Modifications Copyright (C) 2019 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -35,14 +35,11 @@ import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NonNull;
import org.apache.commons.lang3.ObjectUtils;
-import org.apache.commons.lang3.StringUtils;
+import org.onap.policy.common.parameters.BeanValidationResult;
import org.onap.policy.models.base.PfAuthorative;
import org.onap.policy.models.base.PfConcept;
import org.onap.policy.models.base.PfKey;
import org.onap.policy.models.base.PfReferenceKey;
-import org.onap.policy.models.base.PfValidationMessage;
-import org.onap.policy.models.base.PfValidationResult;
-import org.onap.policy.models.base.PfValidationResult.ValidationResult;
import org.onap.policy.models.pdp.concepts.Pdp;
import org.onap.policy.models.pdp.enums.PdpHealthStatus;
import org.onap.policy.models.pdp.enums.PdpState;
@@ -163,40 +160,19 @@ public class JpaPdp extends PfConcept implements PfAuthorative<Pdp>, Serializabl
}
@Override
- public PfValidationResult validate(@NonNull final PfValidationResult resultIn) {
- PfValidationResult result = resultIn;
+ public BeanValidationResult validate(@NonNull String fieldName) {
+ BeanValidationResult result = new BeanValidationResult(fieldName, this);
- if (key.isNullKey()) {
- result.addValidationMessage(
- new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID, "key is a null key"));
- }
-
- result = key.validate(result);
-
- if (key.getParentConceptKey().isNullKey()) {
- result.addValidationMessage(new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID,
- "parent of key is a null key"));
- }
+ result.addResult(validateKeyNotNull("key", key));
+ result.addResult(validateKeyNotNull("parent of key", key.getParentConceptKey()));
if (PfKey.NULL_KEY_NAME.equals(key.getParentLocalName())) {
- result.addValidationMessage(new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID,
- "local name of parent of key is null"));
+ addResult(result, "local name of parent of key", key.getParentLocalName(), IS_NULL);
}
- if (pdpState == null) {
- result.addValidationMessage(new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID,
- "PDP state may not be null"));
- }
-
- if (healthy == null) {
- result.addValidationMessage(new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID,
- "PDP health status may not be null"));
- }
-
- if (message != null && StringUtils.isBlank(message)) {
- result.addValidationMessage(new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID,
- "message may not be blank"));
- }
+ result.addResult(validateNotNull("pdpState", pdpState));
+ result.addResult(validateNotNull("healthy", healthy));
+ result.addResult(validateNotBlank("message", message, false));
return result;
}
diff --git a/models-pdp/src/main/java/org/onap/policy/models/pdp/persistence/concepts/JpaPdpGroup.java b/models-pdp/src/main/java/org/onap/policy/models/pdp/persistence/concepts/JpaPdpGroup.java
index 67458cf5f..66d36d8d6 100644
--- a/models-pdp/src/main/java/org/onap/policy/models/pdp/persistence/concepts/JpaPdpGroup.java
+++ b/models-pdp/src/main/java/org/onap/policy/models/pdp/persistence/concepts/JpaPdpGroup.java
@@ -44,17 +44,14 @@ import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NonNull;
import org.apache.commons.lang3.ObjectUtils;
-import org.apache.commons.lang3.StringUtils;
-import org.onap.policy.common.utils.validation.ParameterValidationUtils;
+import org.onap.policy.common.parameters.BeanValidationResult;
import org.onap.policy.models.base.PfAuthorative;
import org.onap.policy.models.base.PfConcept;
import org.onap.policy.models.base.PfConceptKey;
import org.onap.policy.models.base.PfKey;
import org.onap.policy.models.base.PfReferenceKey;
import org.onap.policy.models.base.PfUtils;
-import org.onap.policy.models.base.PfValidationMessage;
-import org.onap.policy.models.base.PfValidationResult;
-import org.onap.policy.models.base.PfValidationResult.ValidationResult;
+import org.onap.policy.models.base.Validated;
import org.onap.policy.models.pdp.concepts.PdpGroup;
import org.onap.policy.models.pdp.concepts.PdpSubGroup;
import org.onap.policy.models.pdp.enums.PdpState;
@@ -218,61 +215,21 @@ public class JpaPdpGroup extends PfConcept implements PfAuthorative<PdpGroup> {
}
@Override
- public PfValidationResult validate(@NonNull final PfValidationResult resultIn) {
- PfValidationResult result = resultIn;
+ public BeanValidationResult validate(@NonNull String fieldName) {
+ BeanValidationResult result = new BeanValidationResult(fieldName, this);
- if (key.isNullKey()) {
- result.addValidationMessage(
- new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID, "key is a null key"));
- }
-
- result = key.validate(result);
-
- if (description != null && StringUtils.isBlank(description)) {
- result.addValidationMessage(new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID,
- "description may not be blank"));
- }
-
- if (pdpGroupState == null) {
- result.addValidationMessage(new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID,
- "pdpGroupState may not be null"));
- }
+ result.addResult(validateKeyNotNull("key", key));
+ result.addResult(validateNotBlank("description", description, false));
+ result.addResult(validateNotNull("pdpGroupState", pdpGroupState));
- if (properties != null) {
- validateProperties(result);
- }
+ validateMap(result, "properties", properties, Validated::validateEntryNotBlankNotBlank);
- if (pdpSubGroups == null) {
- result.addValidationMessage(new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID,
- "a PDP group must have a list of PDP subgroups"));
- } else {
- for (JpaPdpSubGroup jpaPdpSubgroup : pdpSubGroups) {
- result = jpaPdpSubgroup.validate(result);
- }
- }
+ result.addResult(validateNotNull("pdpSubGroups", pdpSubGroups));
+ validateList(result, "pdpSubGroups", pdpSubGroups, Validated::validateNotNull);
return result;
}
- /**
- * Validate the properties.
- *
- * @param result where to place any new validation results
- */
- private void validateProperties(PfValidationResult result) {
-
- for (Entry<String, String> propertyEntry : properties.entrySet()) {
- if (!ParameterValidationUtils.validateStringParameter(propertyEntry.getKey())) {
- result.addValidationMessage(new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID,
- "a property key may not be null or blank"));
- }
- if (!ParameterValidationUtils.validateStringParameter(propertyEntry.getValue())) {
- result.addValidationMessage(new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID,
- "a property value may not be null or blank"));
- }
- }
- }
-
@Override
public int compareTo(final PfConcept otherConcept) {
if (otherConcept == null) {
diff --git a/models-pdp/src/main/java/org/onap/policy/models/pdp/persistence/concepts/JpaPdpStatistics.java b/models-pdp/src/main/java/org/onap/policy/models/pdp/persistence/concepts/JpaPdpStatistics.java
index d08a19a6a..49163ee8c 100644
--- a/models-pdp/src/main/java/org/onap/policy/models/pdp/persistence/concepts/JpaPdpStatistics.java
+++ b/models-pdp/src/main/java/org/onap/policy/models/pdp/persistence/concepts/JpaPdpStatistics.java
@@ -3,6 +3,7 @@
* ONAP Policy Model
* ================================================================================
* Copyright (C) 2019 Nordix Foundation.
+ * Modifications Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -37,14 +38,12 @@ import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NonNull;
import org.apache.commons.lang3.builder.CompareToBuilder;
+import org.onap.policy.common.parameters.BeanValidationResult;
import org.onap.policy.models.base.PfAuthorative;
import org.onap.policy.models.base.PfConcept;
import org.onap.policy.models.base.PfKey;
import org.onap.policy.models.base.PfTimestampKey;
import org.onap.policy.models.base.PfUtils;
-import org.onap.policy.models.base.PfValidationMessage;
-import org.onap.policy.models.base.PfValidationResult;
-import org.onap.policy.models.base.PfValidationResult.ValidationResult;
import org.onap.policy.models.pdp.concepts.PdpEngineWorkerStatistics;
import org.onap.policy.models.pdp.concepts.PdpStatistics;
@@ -203,15 +202,10 @@ public class JpaPdpStatistics extends PfConcept implements PfAuthorative<PdpStat
}
@Override
- public PfValidationResult validate(@NonNull PfValidationResult resultIn) {
- PfValidationResult result = resultIn;
+ public BeanValidationResult validate(@NonNull String fieldName) {
+ BeanValidationResult result = new BeanValidationResult(fieldName, this);
- if (key.isNullKey()) {
- result.addValidationMessage(
- new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID, "key is a null key"));
- }
-
- result = key.validate(result);
+ result.addResult(validateKeyNotNull("key", key));
return result;
}
diff --git a/models-pdp/src/main/java/org/onap/policy/models/pdp/persistence/concepts/JpaPdpSubGroup.java b/models-pdp/src/main/java/org/onap/policy/models/pdp/persistence/concepts/JpaPdpSubGroup.java
index 7d018860e..c3d172a85 100644
--- a/models-pdp/src/main/java/org/onap/policy/models/pdp/persistence/concepts/JpaPdpSubGroup.java
+++ b/models-pdp/src/main/java/org/onap/policy/models/pdp/persistence/concepts/JpaPdpSubGroup.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* ONAP Policy Model
* ================================================================================
- * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved.
* Modifications Copyright (C) 2019 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -43,7 +43,7 @@ import javax.persistence.Table;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NonNull;
-import org.onap.policy.common.utils.validation.ParameterValidationUtils;
+import org.onap.policy.common.parameters.BeanValidationResult;
import org.onap.policy.models.base.PfAuthorative;
import org.onap.policy.models.base.PfConcept;
import org.onap.policy.models.base.PfConceptKey;
@@ -52,9 +52,7 @@ import org.onap.policy.models.base.PfKeyUse;
import org.onap.policy.models.base.PfReferenceKey;
import org.onap.policy.models.base.PfSearchableKey;
import org.onap.policy.models.base.PfUtils;
-import org.onap.policy.models.base.PfValidationMessage;
-import org.onap.policy.models.base.PfValidationResult;
-import org.onap.policy.models.base.PfValidationResult.ValidationResult;
+import org.onap.policy.models.base.Validated;
import org.onap.policy.models.pdp.concepts.Pdp;
import org.onap.policy.models.pdp.concepts.PdpSubGroup;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyIdentifier;
@@ -279,80 +277,33 @@ public class JpaPdpSubGroup extends PfConcept implements PfAuthorative<PdpSubGro
}
@Override
- public PfValidationResult validate(@NonNull final PfValidationResult resultIn) {
- PfValidationResult result = resultIn;
+ public BeanValidationResult validate(@NonNull String fieldName) {
+ BeanValidationResult result = new BeanValidationResult(fieldName, this);
- if (key.isNullKey()) {
- result.addValidationMessage(
- new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID, "key is a null key"));
- }
-
- result = key.validate(result);
-
- if (key.getParentConceptKey().isNullKey()) {
- result.addValidationMessage(new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID,
- "parent of key is a null key"));
- }
+ result.addResult(validateKeyNotNull("key", key));
+ result.addResult(validateKeyNotNull("parent of key", key.getParentConceptKey()));
if (currentInstanceCount < 0) {
- result.addValidationMessage(new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID,
- "the current instance count of a PDP sub group may not be negative"));
+ addResult(result, "currentInstanceCount", currentInstanceCount, "is negative");
}
if (desiredInstanceCount < 0) {
- result.addValidationMessage(new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID,
- "the desired instance count of a PDP sub group may not be negative"));
- }
-
- if (properties != null) {
- for (Entry<String, String> propertyEntry : properties.entrySet()) {
- if (!ParameterValidationUtils.validateStringParameter(propertyEntry.getKey())) {
- result.addValidationMessage(new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID,
- "a property key may not be null or blank"));
- }
- if (!ParameterValidationUtils.validateStringParameter(propertyEntry.getValue())) {
- result.addValidationMessage(new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID,
- "a property value may not be null or blank"));
- }
- }
+ addResult(result, "desiredInstanceCount", desiredInstanceCount, "is negative");
}
- return validateSubConcepts(result);
- }
+ validateMap(result, "properties", properties, Validated::validateEntryNotBlankNotBlank);
- /**
- * Validate collections of sub concepts.
- *
- * @param result the result in which to store the validation result
- * @return the validation result including the results of this method
- */
- private PfValidationResult validateSubConcepts(PfValidationResult result) {
if (supportedPolicyTypes == null || supportedPolicyTypes.isEmpty()) {
- result.addValidationMessage(new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID,
- "a PDP subgroup must support at least one policy type"));
+ addResult(result, "supportedPolicyTypes", supportedPolicyTypes, "is empty");
} else {
- for (PfSearchableKey supportedPolicyType : supportedPolicyTypes) {
- result = supportedPolicyType.validate(result);
- }
+ validateList(result, "supportedPolicyTypes", supportedPolicyTypes, Validated::validateNotNull);
}
- if (policies == null) {
- result.addValidationMessage(new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID,
- "a PDP subgroup must have a list of policies"));
- } else {
- for (PfConceptKey policyKey : policies) {
- result = policyKey.validate(result);
- }
- }
+ result.validateNotNull("policies", policies);
+ validateList(result, "policies", policies, Validated::validateNotNull);
- if (pdpInstances == null) {
- result.addValidationMessage(new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID,
- "a PDP subgroup must have a list of PDPs"));
- } else {
- for (JpaPdp jpaPdp : pdpInstances) {
- result = jpaPdp.validate(result);
- }
- }
+ result.validateNotNull("pdpInstances", pdpInstances);
+ validateList(result, "pdpInstances", pdpInstances, Validated::validateNotNull);
return result;
}
diff --git a/models-pdp/src/main/java/org/onap/policy/models/pdp/persistence/provider/PdpProvider.java b/models-pdp/src/main/java/org/onap/policy/models/pdp/persistence/provider/PdpProvider.java
index 7ea7cd376..e496521b7 100644
--- a/models-pdp/src/main/java/org/onap/policy/models/pdp/persistence/provider/PdpProvider.java
+++ b/models-pdp/src/main/java/org/onap/policy/models/pdp/persistence/provider/PdpProvider.java
@@ -1,7 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2019 Nordix Foundation.
- * Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -25,12 +25,12 @@ import java.util.ArrayList;
import java.util.List;
import javax.ws.rs.core.Response;
import lombok.NonNull;
+import org.onap.policy.common.parameters.BeanValidationResult;
import org.onap.policy.models.base.PfConceptKey;
import org.onap.policy.models.base.PfKey;
import org.onap.policy.models.base.PfModelException;
import org.onap.policy.models.base.PfModelRuntimeException;
import org.onap.policy.models.base.PfReferenceKey;
-import org.onap.policy.models.base.PfValidationResult;
import org.onap.policy.models.dao.PfDao;
import org.onap.policy.models.pdp.concepts.Pdp;
import org.onap.policy.models.pdp.concepts.PdpGroup;
@@ -40,8 +40,6 @@ import org.onap.policy.models.pdp.concepts.PdpSubGroup;
import org.onap.policy.models.pdp.persistence.concepts.JpaPdp;
import org.onap.policy.models.pdp.persistence.concepts.JpaPdpGroup;
import org.onap.policy.models.pdp.persistence.concepts.JpaPdpSubGroup;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
/**
* This class provides the provision of information on PAP concepts in the database to callers.
@@ -49,10 +47,6 @@ import org.slf4j.LoggerFactory;
* @author Liam Fallon (liam.fallon@est.tech)
*/
public class PdpProvider {
- private static final Logger LOGGER = LoggerFactory.getLogger(PdpProvider.class);
-
- // Recurring string constants
- private static final String NOT_VALID = "\" is not valid \n";
/**
* Get PDP groups.
@@ -96,11 +90,9 @@ public class PdpProvider {
JpaPdpGroup jpaPdpGroup = new JpaPdpGroup();
jpaPdpGroup.fromAuthorative(pdpGroup);
- PfValidationResult validationResult = jpaPdpGroup.validate(new PfValidationResult());
- if (!validationResult.isOk()) {
- String errorMessage = "pdp group \"" + jpaPdpGroup.getId() + NOT_VALID + validationResult;
- LOGGER.warn(errorMessage);
- throw new PfModelRuntimeException(Response.Status.BAD_REQUEST, errorMessage);
+ BeanValidationResult validationResult = jpaPdpGroup.validate("PDP group");
+ if (!validationResult.isValid()) {
+ throw new PfModelRuntimeException(Response.Status.BAD_REQUEST, validationResult.getResult());
}
dao.create(jpaPdpGroup);
@@ -133,11 +125,9 @@ public class PdpProvider {
JpaPdpGroup jpaPdpGroup = new JpaPdpGroup();
jpaPdpGroup.fromAuthorative(pdpGroup);
- PfValidationResult validationResult = jpaPdpGroup.validate(new PfValidationResult());
- if (!validationResult.isOk()) {
- String errorMessage = "pdp group \"" + jpaPdpGroup.getId() + NOT_VALID + validationResult;
- LOGGER.warn(errorMessage);
- throw new PfModelRuntimeException(Response.Status.BAD_REQUEST, errorMessage);
+ BeanValidationResult validationResult = jpaPdpGroup.validate("PDP group");
+ if (!validationResult.isValid()) {
+ throw new PfModelRuntimeException(Response.Status.BAD_REQUEST, validationResult.getResult());
}
dao.update(jpaPdpGroup);
@@ -171,11 +161,9 @@ public class PdpProvider {
final JpaPdpSubGroup jpaPdpSubgroup = new JpaPdpSubGroup(subGroupKey);
jpaPdpSubgroup.fromAuthorative(pdpSubGroup);
- PfValidationResult validationResult = jpaPdpSubgroup.validate(new PfValidationResult());
- if (!validationResult.isOk()) {
- String errorMessage = "PDP subgroup \"" + jpaPdpSubgroup.getId() + NOT_VALID + validationResult;
- LOGGER.warn(errorMessage);
- throw new PfModelRuntimeException(Response.Status.BAD_REQUEST, errorMessage);
+ BeanValidationResult validationResult = jpaPdpSubgroup.validate("PDP sub group");
+ if (!validationResult.isValid()) {
+ throw new PfModelRuntimeException(Response.Status.BAD_REQUEST, validationResult.getResult());
}
dao.update(jpaPdpSubgroup);
@@ -198,11 +186,9 @@ public class PdpProvider {
final JpaPdp jpaPdp = new JpaPdp(pdpKey);
jpaPdp.fromAuthorative(pdp);
- PfValidationResult validationResult = jpaPdp.validate(new PfValidationResult());
- if (!validationResult.isOk()) {
- String errorMessage = "PDP \"" + jpaPdp.getId() + NOT_VALID + validationResult;
- LOGGER.warn(errorMessage);
- throw new PfModelRuntimeException(Response.Status.BAD_REQUEST, errorMessage);
+ BeanValidationResult validationResult = jpaPdp.validate("PDP");
+ if (!validationResult.isValid()) {
+ throw new PfModelRuntimeException(Response.Status.BAD_REQUEST, validationResult.getResult());
}
dao.update(jpaPdp);
diff --git a/models-pdp/src/main/java/org/onap/policy/models/pdp/persistence/provider/PdpStatisticsProvider.java b/models-pdp/src/main/java/org/onap/policy/models/pdp/persistence/provider/PdpStatisticsProvider.java
index 3b1718090..7901246d7 100644
--- a/models-pdp/src/main/java/org/onap/policy/models/pdp/persistence/provider/PdpStatisticsProvider.java
+++ b/models-pdp/src/main/java/org/onap/policy/models/pdp/persistence/provider/PdpStatisticsProvider.java
@@ -3,6 +3,7 @@
* ONAP Policy Model
* ================================================================================
* Copyright (C) 2019-2020 Nordix Foundation.
+ * Modifications Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -30,16 +31,14 @@ import java.util.Map;
import java.util.stream.Collectors;
import javax.ws.rs.core.Response;
import lombok.NonNull;
+import org.onap.policy.common.parameters.BeanValidationResult;
import org.onap.policy.models.base.PfKey;
import org.onap.policy.models.base.PfModelException;
import org.onap.policy.models.base.PfModelRuntimeException;
import org.onap.policy.models.base.PfTimestampKey;
-import org.onap.policy.models.base.PfValidationResult;
import org.onap.policy.models.dao.PfDao;
import org.onap.policy.models.pdp.concepts.PdpStatistics;
import org.onap.policy.models.pdp.persistence.concepts.JpaPdpStatistics;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
/**
@@ -48,10 +47,7 @@ import org.slf4j.LoggerFactory;
* @author Ning Xi (ning.xi@est.tech)
*/
public class PdpStatisticsProvider {
- private static final Logger LOGGER = LoggerFactory.getLogger(PdpStatisticsProvider.class);
-
// Recurring string constants
- private static final String NOT_VALID = "\" is not valid \n";
private static final String DESC_ORDER = "DESC";
/**
@@ -118,11 +114,9 @@ public class PdpStatisticsProvider {
JpaPdpStatistics jpaPdpStatistics = new JpaPdpStatistics();
jpaPdpStatistics.fromAuthorative(pdpStatistics);
- PfValidationResult validationResult = jpaPdpStatistics.validate(new PfValidationResult());
- if (!validationResult.isOk()) {
- String errorMessage = "pdp statictics \"" + jpaPdpStatistics.getName() + NOT_VALID + validationResult;
- LOGGER.warn(errorMessage);
- throw new PfModelRuntimeException(Response.Status.BAD_REQUEST, errorMessage);
+ BeanValidationResult validationResult = jpaPdpStatistics.validate("pdp statistics");
+ if (!validationResult.isValid()) {
+ throw new PfModelRuntimeException(Response.Status.BAD_REQUEST, validationResult.getResult());
}
dao.create(jpaPdpStatistics);
@@ -156,11 +150,9 @@ public class PdpStatisticsProvider {
JpaPdpStatistics jpaPdpStatistics = new JpaPdpStatistics();
jpaPdpStatistics.fromAuthorative(pdpStatistics);
- PfValidationResult validationResult = jpaPdpStatistics.validate(new PfValidationResult());
- if (!validationResult.isOk()) {
- String errorMessage = "pdp statistics \"" + jpaPdpStatistics.getId() + NOT_VALID + validationResult;
- LOGGER.warn(errorMessage);
- throw new PfModelRuntimeException(Response.Status.BAD_REQUEST, errorMessage);
+ BeanValidationResult validationResult = jpaPdpStatistics.validate("pdp statistics");
+ if (!validationResult.isValid()) {
+ throw new PfModelRuntimeException(Response.Status.BAD_REQUEST, validationResult.getResult());
}
dao.update(jpaPdpStatistics);