* ONAP Policy Model
* ================================================================================
* Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved.
- * Modifications Copyright (C) 2019 Nordix Foundation.
+ * Modifications Copyright (C) 2019-2021 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
import lombok.EqualsAndHashCode;
import lombok.NonNull;
import org.onap.policy.common.parameters.BeanValidationResult;
+import org.onap.policy.common.parameters.annotations.Entries;
+import org.onap.policy.common.parameters.annotations.Items;
+import org.onap.policy.common.parameters.annotations.Min;
+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.PfReferenceKey;
import org.onap.policy.models.base.PfSearchableKey;
import org.onap.policy.models.base.PfUtils;
-import org.onap.policy.models.base.Validated;
+import org.onap.policy.models.base.validation.annotations.VerifyKey;
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;
-import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyTypeIdentifier;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
/**
* Class to represent a PDP subgroup in the database.
private static final long serialVersionUID = -357224425637789775L;
@EmbeddedId
+ @VerifyKey
+ @NotNull
private PfReferenceKey key;
@ElementCollection
+ @NotNull
+ @Items(notNull = {@NotNull}, valid = {@Valid})
private List<PfSearchableKey> supportedPolicyTypes;
@ElementCollection
+ @NotNull
+ @Items(notNull = {@NotNull}, valid = {@Valid})
private List<PfConceptKey> policies;
@Column
+ @Min(0)
private int currentInstanceCount;
@Column
+ @Min(0)
private int desiredInstanceCount;
@ElementCollection
+ @Entries(key = @Items(notNull = {@NotNull}, notBlank = {@NotBlank}),
+ value = @Items(notNull = {@NotNull}, notBlank = {@NotBlank}))
private Map<String, String> properties;
// @formatter:off
}
)
// formatter:on
+ @NotNull
+ @Items(notNull = {@NotNull}, valid = {@Valid})
private List<JpaPdp> pdpInstances;
/**
pdpSubgroup.setSupportedPolicyTypes(new ArrayList<>());
for (PfSearchableKey supportedPolicyTypeKey : supportedPolicyTypes) {
- ToscaPolicyTypeIdentifier supportedPolicyTypeIdent = new ToscaPolicyTypeIdentifier(
+ ToscaConceptIdentifier supportedPolicyTypeIdent = new ToscaConceptIdentifier(
supportedPolicyTypeKey.getName(), supportedPolicyTypeKey.getVersion());
pdpSubgroup.getSupportedPolicyTypes().add(supportedPolicyTypeIdent);
}
pdpSubgroup.setPolicies(new ArrayList<>());
for (PfConceptKey policyKey : policies) {
- ToscaPolicyIdentifier toscaPolicyIdentifier = new ToscaPolicyIdentifier();
+ ToscaConceptIdentifier toscaPolicyIdentifier = new ToscaConceptIdentifier();
toscaPolicyIdentifier.setName(policyKey.getName());
toscaPolicyIdentifier.setVersion(policyKey.getVersion());
pdpSubgroup.getPolicies().add(toscaPolicyIdentifier);
this.supportedPolicyTypes = new ArrayList<>();
if (pdpSubgroup.getSupportedPolicyTypes() != null) {
- for (ToscaPolicyTypeIdentifier supportedPolicyType : pdpSubgroup.getSupportedPolicyTypes()) {
+ for (ToscaConceptIdentifier supportedPolicyType : pdpSubgroup.getSupportedPolicyTypes()) {
this.supportedPolicyTypes
.add(new PfSearchableKey(supportedPolicyType.getName(), supportedPolicyType.getVersion()));
}
this.policies = new ArrayList<>();
if (pdpSubgroup.getPolicies() != null) {
- for (ToscaPolicyIdentifier toscaPolicyIdentifier : pdpSubgroup.getPolicies()) {
+ for (ToscaConceptIdentifier toscaPolicyIdentifier : pdpSubgroup.getPolicies()) {
this.policies
.add(new PfConceptKey(toscaPolicyIdentifier.getName(), toscaPolicyIdentifier.getVersion()));
}
@Override
public BeanValidationResult validate(@NonNull String fieldName) {
- BeanValidationResult result = new BeanValidationResult(fieldName, this);
+ BeanValidationResult result = super.validate(fieldName);
- result.addResult(validateKeyNotNull("key", key));
result.addResult(validateKeyNotNull("parent of key", key.getParentConceptKey()));
- if (currentInstanceCount < 0) {
- addResult(result, "currentInstanceCount", currentInstanceCount, "is negative");
- }
-
- if (desiredInstanceCount < 0) {
- addResult(result, "desiredInstanceCount", desiredInstanceCount, "is negative");
- }
-
- validateMap(result, "properties", properties, Validated::validateEntryNotBlankNotBlank);
-
- if (supportedPolicyTypes == null || supportedPolicyTypes.isEmpty()) {
+ if (supportedPolicyTypes != null && supportedPolicyTypes.isEmpty()) {
addResult(result, "supportedPolicyTypes", supportedPolicyTypes, "is empty");
- } else {
- validateList(result, "supportedPolicyTypes", supportedPolicyTypes, Validated::validateNotNull);
}
- result.validateNotNull("policies", policies);
- validateList(result, "policies", policies, Validated::validateNotNull);
-
- result.validateNotNull("pdpInstances", pdpInstances);
- validateList(result, "pdpInstances", pdpInstances, Validated::validateNotNull);
-
return result;
}