diff options
Diffstat (limited to 'models-tosca/src/main')
9 files changed, 55 insertions, 166 deletions
diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaConceptIdentifier.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaConceptIdentifier.java index ade1a28d4..4cc8892c2 100644 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaConceptIdentifier.java +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaConceptIdentifier.java @@ -21,6 +21,7 @@ package org.onap.policy.models.tosca.authorative.concepts; +import java.io.Serializable; import lombok.Data; import lombok.NoArgsConstructor; import lombok.NonNull; @@ -35,7 +36,8 @@ import org.onap.policy.models.base.PfKey; */ @Data @NoArgsConstructor -public class ToscaConceptIdentifier implements Comparable<ToscaConceptIdentifier> { +public class ToscaConceptIdentifier implements Serializable, Comparable<ToscaConceptIdentifier> { + private static final long serialVersionUID = 8010649773816325786L; @NonNull private String name; diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaEntity.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaEntity.java index 5c1167c7d..98efd1991 100644 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaEntity.java +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaEntity.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP Policy Model * ================================================================================ - * Copyright (C) 2019-2020 Nordix Foundation. + * 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. @@ -140,4 +140,22 @@ public class ToscaEntity implements PfNameVersion { return entityMap; } + + /** + * Method that should be specialised to return the type of the entity if the entity has a type. + * + * @return the type of the entity or null if it has no type + */ + public String getType() { + return null; + } + + /** + * Method that should be specialised to return the type version of the entity if the entity has a type. + * + * @return the type of the entity or null if it has no type + */ + public String getTypeVersion() { + return null; + } } diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyComparator.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaEntityComparator.java index 8bbe70db2..9b8c98675 100644 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyComparator.java +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaEntityComparator.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2020 Nordix Foundation. + * Copyright (C) 2020-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. @@ -23,12 +23,12 @@ package org.onap.policy.models.tosca.authorative.concepts; import java.util.Comparator; /** - * Compare two ToscaPolicy objects. + * Compare two ToscaEntity objects. */ -public class ToscaPolicyComparator implements Comparator<ToscaPolicy> { +public class ToscaEntityComparator<T extends ToscaEntity> implements Comparator<T> { @Override - public int compare(final ToscaPolicy left, final ToscaPolicy right) { + public int compare(final ToscaEntity left, final ToscaEntity right) { return left.compareNameVersion(left, right); } } diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyTypeFilter.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaEntityFilter.java index 4e9810b98..ef0b6b183 100644 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyTypeFilter.java +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaEntityFilter.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2019-2020 Nordix Foundation. + * 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. @@ -28,13 +28,13 @@ import lombok.NonNull; import org.onap.policy.models.base.PfObjectFilter; /** - * Filter class for searches for {@link ToscaPolicyType} instances. If any fields are null, they are ignored. + * Filter class for searches for {@link ToscaEntity} instances. If any fields are null, they are ignored. * * @author Liam Fallon (liam.fallon@est.tech) */ @Builder @Data -public class ToscaPolicyTypeFilter implements PfObjectFilter<ToscaPolicyType> { +public class ToscaEntityFilter<T extends ToscaEntity> implements PfObjectFilter<T> { public static final String LATEST_VERSION = "LATEST"; // Regular expression @@ -44,10 +44,10 @@ public class ToscaPolicyTypeFilter implements PfObjectFilter<ToscaPolicyType> { private String version; @Override - public List<ToscaPolicyType> filter(@NonNull final List<ToscaPolicyType> originalList) { + public List<T> filter(@NonNull final List<T> originalList) { // @formatter:off - List<ToscaPolicyType> returnList = originalList.stream() + List<T> returnList = originalList.stream() .filter(p -> filterString(p.getName(), name)) .filter(p -> LATEST_VERSION.equals(version) || filterString(p.getVersion(), version)) @@ -55,7 +55,7 @@ public class ToscaPolicyTypeFilter implements PfObjectFilter<ToscaPolicyType> { // @formatter:off if (LATEST_VERSION.equals(version)) { - return this.latestVersionFilter(returnList, new ToscaPolicyTypeComparator()); + return this.latestVersionFilter(returnList, new ToscaEntityComparator<T>()); } else { return returnList; } diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyTypeComparator.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyTypeComparator.java deleted file mode 100644 index 9f45a7854..000000000 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyTypeComparator.java +++ /dev/null @@ -1,34 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2020 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. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.models.tosca.authorative.concepts; - -import java.util.Comparator; - -/** - * Compare two ToscaPolicyType objects. - */ -public class ToscaPolicyTypeComparator implements Comparator<ToscaPolicyType> { - - @Override - public int compare(final ToscaPolicyType left, final ToscaPolicyType right) { - return left.compareNameVersion(left, right); - } -} diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaServiceTemplateComparator.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaServiceTemplateComparator.java deleted file mode 100644 index 015c10bdd..000000000 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaServiceTemplateComparator.java +++ /dev/null @@ -1,34 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2020 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. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.models.tosca.authorative.concepts; - -import java.util.Comparator; - -/** - * Compare two ToscaServiceTemplate objects. - */ -public class ToscaServiceTemplateComparator implements Comparator<ToscaServiceTemplate> { - - @Override - public int compare(final ToscaServiceTemplate left, final ToscaServiceTemplate right) { - return left.compareNameVersion(left, right); - } -} diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaServiceTemplateFilter.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaServiceTemplateFilter.java deleted file mode 100644 index 75b13969d..000000000 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaServiceTemplateFilter.java +++ /dev/null @@ -1,63 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2020 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. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.models.tosca.authorative.concepts; - -import java.util.List; -import java.util.stream.Collectors; -import lombok.Builder; -import lombok.Data; -import lombok.NonNull; -import org.onap.policy.models.base.PfObjectFilter; - -/** - * Filter class for searches for {@link ToscaServiceTemplate} instances. If any fields are null, they are ignored. - * - * @author Liam Fallon (liam.fallon@est.tech) - */ -@Builder -@Data -public class ToscaServiceTemplateFilter implements PfObjectFilter<ToscaServiceTemplate> { - public static final String LATEST_VERSION = "LATEST"; - - // Regular expression - private String name; - - // Regular Expression, set to LATEST_VERRSION to get the latest version - private String version; - - @Override - public List<ToscaServiceTemplate> filter(@NonNull final List<ToscaServiceTemplate> originalList) { - - // @formatter:off - List<ToscaServiceTemplate> returnList = originalList.stream() - .filter(p -> filterString(p.getName(), name)) - .filter(p -> LATEST_VERSION.equals(version) - || filterString(p.getVersion(), version)) - .collect(Collectors.toList()); - // @formatter:off - - if (LATEST_VERSION.equals(version)) { - return this.latestVersionFilter(returnList, new ToscaServiceTemplateComparator()); - } else { - return returnList; - } - } -} diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyFilter.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaTypedEntityFilter.java index 86c2e6f3e..b6ff86b3c 100644 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyFilter.java +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaTypedEntityFilter.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2019-2020 Nordix Foundation. + * Copyright (C) 2019-2021 Nordix Foundation. * Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -35,7 +35,7 @@ import org.onap.policy.models.base.PfObjectFilter; */ @Builder @Data -public class ToscaPolicyFilter implements PfObjectFilter<ToscaPolicy> { +public class ToscaTypedEntityFilter<T extends ToscaEntity> implements PfObjectFilter<T> { public static final String LATEST_VERSION = "LATEST"; // Exact expression @@ -54,20 +54,20 @@ public class ToscaPolicyFilter implements PfObjectFilter<ToscaPolicy> { private String typeVersion; @Override - public List<ToscaPolicy> filter(@NonNull final List<ToscaPolicy> originalList) { + public List<T> filter(@NonNull final List<T> originalList) { // @formatter:off - List<ToscaPolicy> returnList = originalList.stream() - .filter(filterStringPred(name, ToscaPolicy::getName)) - .filter(filterStringPred((LATEST_VERSION.equals(version) ? null : version), ToscaPolicy::getVersion)) - .filter(filterPrefixPred(versionPrefix, ToscaPolicy::getVersion)) - .filter(filterStringPred(type, ToscaPolicy::getType)) - .filter(filterStringPred(typeVersion, ToscaPolicy::getTypeVersion)) + List<T> returnList = originalList.stream() + .filter(filterStringPred(name, T::getName)) + .filter(filterStringPred((LATEST_VERSION.equals(version) ? null : version), T::getVersion)) + .filter(filterPrefixPred(versionPrefix, T::getVersion)) + .filter(filterStringPred(type, T::getType)) + .filter(filterStringPred(typeVersion, T::getTypeVersion)) .collect(Collectors.toList()); // @formatter:off if (LATEST_VERSION.equals(version)) { - return this.latestVersionFilter(returnList, new ToscaPolicyComparator()); + return this.latestVersionFilter(returnList, new ToscaEntityComparator<T>()); } else { return returnList; } diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/provider/AuthorativeToscaProvider.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/provider/AuthorativeToscaProvider.java index d20f5d080..c43aadf0f 100644 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/provider/AuthorativeToscaProvider.java +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/provider/AuthorativeToscaProvider.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2019-2020 Nordix Foundation. + * Copyright (C) 2019-2021 Nordix Foundation. * Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -34,12 +34,11 @@ import org.onap.policy.models.base.PfModelException; import org.onap.policy.models.base.PfModelRuntimeException; import org.onap.policy.models.dao.PfDao; import org.onap.policy.models.tosca.authorative.concepts.ToscaEntity; +import org.onap.policy.models.tosca.authorative.concepts.ToscaEntityFilter; import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy; -import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyFilter; import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyType; -import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyTypeFilter; import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate; -import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplateFilter; +import org.onap.policy.models.tosca.authorative.concepts.ToscaTypedEntityFilter; import org.onap.policy.models.tosca.simple.concepts.JpaToscaServiceTemplate; import org.onap.policy.models.tosca.simple.provider.SimpleToscaProvider; import org.onap.policy.models.tosca.utils.ToscaServiceTemplateUtils; @@ -97,7 +96,7 @@ public class AuthorativeToscaProvider { * @throws PfModelException on errors getting service templates */ public List<ToscaServiceTemplate> getFilteredServiceTemplateList(PfDao pfDao, - @NonNull ToscaServiceTemplateFilter filter) throws PfModelException { + @NonNull ToscaEntityFilter<ToscaServiceTemplate> filter) throws PfModelException { LOGGER.debug("->getFilteredServiceTemplateList: filter={}", filter); @@ -240,7 +239,7 @@ public class AuthorativeToscaProvider { * @throws PfModelException on errors getting policy types */ public ToscaServiceTemplate getFilteredPolicyTypes(@NonNull final PfDao dao, - @NonNull final ToscaPolicyTypeFilter filter) throws PfModelException { + @NonNull final ToscaEntityFilter<ToscaPolicyType> filter) throws PfModelException { synchronized (providerLockObject) { LOGGER.debug("->getFilteredPolicyTypes: filter={}", filter); @@ -282,7 +281,7 @@ public class AuthorativeToscaProvider { * @throws PfModelException on errors getting policy types */ public List<ToscaPolicyType> getFilteredPolicyTypeList(@NonNull final PfDao dao, - @NonNull final ToscaPolicyTypeFilter filter) throws PfModelException { + @NonNull final ToscaEntityFilter<ToscaPolicyType> filter) throws PfModelException { LOGGER.debug("->getFilteredPolicyTypeList: filter={}", filter); @@ -423,12 +422,13 @@ public class AuthorativeToscaProvider { * @return the policies found * @throws PfModelException on errors getting policies */ - public ToscaServiceTemplate getFilteredPolicies(@NonNull final PfDao dao, @NonNull final ToscaPolicyFilter filter) - throws PfModelException { + public ToscaServiceTemplate getFilteredPolicies(@NonNull final PfDao dao, + @NonNull final ToscaTypedEntityFilter<ToscaPolicy> filter) throws PfModelException { synchronized (providerLockObject) { LOGGER.debug("->getFilteredPolicies: filter={}", filter); - String version = ToscaPolicyFilter.LATEST_VERSION.equals(filter.getVersion()) ? null : filter.getVersion(); + String version = + ToscaTypedEntityFilter.LATEST_VERSION.equals(filter.getVersion()) ? null : filter.getVersion(); SimpleToscaProvider simpleToscaProvider = new SimpleToscaProvider(); final JpaToscaServiceTemplate dbServiceTemplate = @@ -468,11 +468,11 @@ public class AuthorativeToscaProvider { * @return the policies found * @throws PfModelException on errors getting policies */ - public List<ToscaPolicy> getFilteredPolicyList(@NonNull final PfDao dao, @NonNull final ToscaPolicyFilter filter) - throws PfModelException { + public List<ToscaPolicy> getFilteredPolicyList(@NonNull final PfDao dao, + @NonNull final ToscaTypedEntityFilter<ToscaPolicy> filter) throws PfModelException { LOGGER.debug("->getFilteredPolicyList: filter={}", filter); - String version = ToscaPolicyFilter.LATEST_VERSION.equals(filter.getVersion()) ? null : filter.getVersion(); + String version = ToscaTypedEntityFilter.LATEST_VERSION.equals(filter.getVersion()) ? null : filter.getVersion(); List<ToscaPolicy> policyList = filter.filter(getPolicyList(dao, filter.getName(), version)); |