diff options
author | liamfallon <liam.fallon@est.tech> | 2021-01-04 12:15:18 +0000 |
---|---|---|
committer | liamfallon <liam.fallon@est.tech> | 2021-01-06 14:20:06 +0000 |
commit | f2b0318f53abf9f2345a5cdca74f3dd635aa9b60 (patch) | |
tree | 0a5d64add719e43596f95b9415db04257c037988 /models-pap/src/main | |
parent | 8ad3f95cdcec48b8315a5febfd4ec07bae7aabba (diff) |
Changed identifiers to concept identifiers
The policy models tosca classes ToscaPolicyIdentifier and
ToscaPolicyIdentifierOptVersion can be used to identify any TOSCA
concept, not just TOSCA policies so they are renamed to
ToscaConceptIdentifier and ToscaCinceptIdentifierOptVersion
respectively.
The class ToscaPolicyTypeIdentifier is redundant and is replaced by
ToscaConceptIdentifier.
Issue-ID: POLICY-2900
Change-Id: Id0a37c42ea4e74f07b47e1694c4f8291c35879c9
Signed-off-by: liamfallon <liam.fallon@est.tech>
Diffstat (limited to 'models-pap/src/main')
3 files changed, 96 insertions, 17 deletions
diff --git a/models-pap/src/main/java/org/onap/policy/models/pap/concepts/PapPolicyIdentifier.java b/models-pap/src/main/java/org/onap/policy/models/pap/concepts/PapPolicyIdentifier.java new file mode 100644 index 000000000..7bd78a222 --- /dev/null +++ b/models-pap/src/main/java/org/onap/policy/models/pap/concepts/PapPolicyIdentifier.java @@ -0,0 +1,62 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP Policy Models + * ================================================================================ + * Copyright (C) 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.models.pap.concepts; + +import com.google.gson.annotations.SerializedName; +import io.swagger.annotations.ApiModelProperty; +import lombok.NonNull; +import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; +import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifierOptVersion; + +/** + * Policy identifier with an optional version; only the "name" is required. + * + * <p>Note that there are deliberately no setters or getters on this class, it is use purely for GSON serialization and + * deserializaiton + */ +public class PapPolicyIdentifier { + @NonNull + @ApiModelProperty(name = "policy-id") + @SerializedName("policy-id") + private String name; + + @ApiModelProperty(name = "policy-version") + @SerializedName("policy-version") + private String version; + + public PapPolicyIdentifier(final String name, final String version) { + this.name = name; + this.version = version; + } + + public PapPolicyIdentifier(@NonNull final ToscaConceptIdentifier identifier) { + this(identifier.getName(), identifier.getVersion()); + } + + public PapPolicyIdentifier(@NonNull final ToscaConceptIdentifierOptVersion identifier) { + this(identifier.getName(), identifier.getVersion()); + } + + public ToscaConceptIdentifierOptVersion getGenericIdentifier() { + return name == null ? new ToscaConceptIdentifierOptVersion() + : new ToscaConceptIdentifierOptVersion(name, version); + } +} diff --git a/models-pap/src/main/java/org/onap/policy/models/pap/concepts/PdpDeployPolicies.java b/models-pap/src/main/java/org/onap/policy/models/pap/concepts/PdpDeployPolicies.java index 7bc8892f2..6ab41ddf8 100644 --- a/models-pap/src/main/java/org/onap/policy/models/pap/concepts/PdpDeployPolicies.java +++ b/models-pap/src/main/java/org/onap/policy/models/pap/concepts/PdpDeployPolicies.java @@ -1,8 +1,9 @@ -/* +/*- * ============LICENSE_START======================================================= * ONAP Policy Models * ================================================================================ * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 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. @@ -21,19 +22,35 @@ package org.onap.policy.models.pap.concepts; import java.util.List; -import lombok.Getter; -import lombok.Setter; +import java.util.stream.Collectors; import lombok.ToString; -import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyIdentifierOptVersion; +import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifierOptVersion; /** - * Request deploy or update a set of policies using the <i>simple</i> PDP Group deployment - * REST API. Only the "name" and "version" fields of a Policy are used, and only the - * "name" field is actually required. + * Request deploy or update a set of policies using the <i>simple</i> PDP Group deployment REST API. Only the "name" and + * "version" fields of a Policy are used, and only the "name" field is actually required. */ -@Getter -@Setter @ToString public class PdpDeployPolicies { - private List<ToscaPolicyIdentifierOptVersion> policies; + private List<PapPolicyIdentifier> policies; + + /** + * Get the identifiers of the policies on the list. + * + * @return The list of identifiers + */ + public List<ToscaConceptIdentifierOptVersion> getPolicies() { + return policies == null ? null + : policies.stream().map(PapPolicyIdentifier::getGenericIdentifier).collect(Collectors.toList()); + } + + /** + * Set the identifiers of the policies on the list. + * + * @param policies The list of identifiers + */ + public void setPolicies(final List<ToscaConceptIdentifierOptVersion> policies) { + this.policies = + policies == null ? null : policies.stream().map(PapPolicyIdentifier::new).collect(Collectors.toList()); + } } diff --git a/models-pap/src/main/java/org/onap/policy/models/pap/concepts/PolicyStatus.java b/models-pap/src/main/java/org/onap/policy/models/pap/concepts/PolicyStatus.java index 427f168ea..b05af9204 100644 --- a/models-pap/src/main/java/org/onap/policy/models/pap/concepts/PolicyStatus.java +++ b/models-pap/src/main/java/org/onap/policy/models/pap/concepts/PolicyStatus.java @@ -1,6 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 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. @@ -21,8 +22,7 @@ package org.onap.policy.models.pap.concepts; import com.google.gson.annotations.SerializedName; import lombok.Data; import lombok.NoArgsConstructor; -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; @Data @NoArgsConstructor @@ -66,18 +66,18 @@ public class PolicyStatus { * @param policy policy identifier, from which the name and version are to be * extracted */ - public PolicyStatus(ToscaPolicyTypeIdentifier policyType, ToscaPolicyIdentifier policy) { + public PolicyStatus(ToscaConceptIdentifier policyType, ToscaConceptIdentifier policy) { this.policyTypeId = policyType.getName(); this.policyTypeVersion = policyType.getVersion(); this.policyId = policy.getName(); this.policyVersion = policy.getVersion(); } - public ToscaPolicyTypeIdentifier getPolicyType() { - return new ToscaPolicyTypeIdentifier(policyTypeId, policyTypeVersion); + public ToscaConceptIdentifier getPolicyType() { + return new ToscaConceptIdentifier(policyTypeId, policyTypeVersion); } - public ToscaPolicyIdentifier getPolicy() { - return new ToscaPolicyIdentifier(policyId, policyVersion); + public ToscaConceptIdentifier getPolicy() { + return new ToscaConceptIdentifier(policyId, policyVersion); } } |