* ============LICENSE_START=======================================================
* ONAP Policy Model
* ================================================================================
- * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2019-2021 AT&T Intellectual Property. All rights reserved.
* Modifications Copyright (C) 2019 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
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.annotations.NotBlank;
+import org.onap.policy.common.parameters.annotations.NotNull;
+import org.onap.policy.common.parameters.annotations.Valid;
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.validation.annotations.VerifyKey;
import org.onap.policy.models.pdp.concepts.PdpGroup;
import org.onap.policy.models.pdp.concepts.PdpSubGroup;
import org.onap.policy.models.pdp.enums.PdpState;
private static final long serialVersionUID = -357224425637789775L;
@EmbeddedId
+ @VerifyKey
+ @NotNull
private PfConceptKey key;
@Column
+ @NotBlank
private String description;
@Column
+ @NotNull
private PdpState pdpGroupState;
@ElementCollection
- private Map<String, String> properties;
+ private Map<@NotNull @NotBlank String, @NotNull @NotBlank String> properties;
// @formatter:off
@OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL, orphanRemoval = true)
@JoinColumn(name = "pdpGroupLocalName", referencedColumnName = "localName")
})
// @formatter:on
- private List<JpaPdpSubGroup> pdpSubGroups;
+ @NotNull
+ private List<@NotNull @Valid JpaPdpSubGroup> pdpSubGroups;
/**
* The Default Constructor creates a {@link JpaPdpGroup} object with a null key.
}
}
- @Override
- public PfValidationResult validate(@NonNull final PfValidationResult resultIn) {
- PfValidationResult result = resultIn;
-
- 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"));
- }
-
- if (properties != null) {
- result = validateProperties(result);
- }
-
- 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);
- }
- }
-
- return result;
- }
-
- /**
- * Validate the properties.
- *
- * @param resultIn the incoming validation results so far
- * @return the revalidation results including the property validation results
- */
- private PfValidationResult validateProperties(PfValidationResult resultIn) {
- PfValidationResult result = resultIn;
-
- 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"));
- }
- }
-
- return result;
- }
-
@Override
public int compareTo(final PfConcept otherConcept) {
if (otherConcept == null) {