diff options
author | liamfallon <liam.fallon@est.tech> | 2021-01-04 15:58:25 +0000 |
---|---|---|
committer | liamfallon <liam.fallon@est.tech> | 2021-01-04 16:22:19 +0000 |
commit | ca2f61793ab1d971414c25c68f9007c7c9abfaac (patch) | |
tree | f3551785175224a2007dc9eff4b1fea078f22538 /policy-utils/src | |
parent | 223519c0c263ea2f9b2b9a94efe52d40ab2cf6f7 (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: I677cc1f8730001b300ab2041f2d57c2485cbc4ed
Signed-off-by: liamfallon <liam.fallon@est.tech>
Diffstat (limited to 'policy-utils/src')
-rw-r--r-- | policy-utils/src/main/java/org/onap/policy/drools/policies/DomainMaker.java | 19 | ||||
-rw-r--r-- | policy-utils/src/test/java/org/onap/policy/drools/policies/DomainMakerTest.java | 27 |
2 files changed, 24 insertions, 22 deletions
diff --git a/policy-utils/src/main/java/org/onap/policy/drools/policies/DomainMaker.java b/policy-utils/src/main/java/org/onap/policy/drools/policies/DomainMaker.java index 58d5052a..ae85d576 100644 --- a/policy-utils/src/main/java/org/onap/policy/drools/policies/DomainMaker.java +++ b/policy-utils/src/main/java/org/onap/policy/drools/policies/DomainMaker.java @@ -1,6 +1,7 @@ /* * ============LICENSE_START======================================================= * Copyright (C) 2020 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. @@ -30,9 +31,9 @@ import org.onap.policy.common.utils.coder.CoderException; import org.onap.policy.common.utils.coder.StandardCoder; import org.onap.policy.common.utils.coder.StandardValCoder; import org.onap.policy.common.utils.resources.ResourceUtils; +import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy; import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyType; -import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyTypeIdentifier; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -56,7 +57,7 @@ public class DomainMaker { /** * policy-type -> schema validator map. */ - private final Map<ToscaPolicyTypeIdentifier, StandardValCoder> validators = new ConcurrentHashMap<>(); + private final Map<ToscaConceptIdentifier, StandardValCoder> validators = new ConcurrentHashMap<>(); /** * non-validation serialization coder. @@ -66,7 +67,7 @@ public class DomainMaker { /** * Does this json conform to a registered policy type schema?. */ - public boolean isConformant(@NonNull ToscaPolicyTypeIdentifier policyType, @NonNull String json) { + public boolean isConformant(@NonNull ToscaConceptIdentifier policyType, @NonNull String json) { if (!isRegistered(policyType)) { return false; } @@ -89,7 +90,7 @@ public class DomainMaker { /** * Does this domain policy conforms to its schema definition?. */ - public <T> boolean isDomainConformant(@NonNull ToscaPolicyTypeIdentifier policyType, @NonNull T domainPolicy) { + public <T> boolean isDomainConformant(@NonNull ToscaConceptIdentifier policyType, @NonNull T domainPolicy) { if (!isRegistered(policyType)) { return false; } @@ -134,7 +135,7 @@ public class DomainMaker { * Checks a domain policy conformance to its specification providing a list of errors * in a ValidationFailedException. */ - public <T> boolean conformance(@NonNull ToscaPolicyTypeIdentifier policyType, T domainPolicy) { + public <T> boolean conformance(@NonNull ToscaConceptIdentifier policyType, T domainPolicy) { if (!isRegistered(policyType)) { return false; @@ -156,7 +157,7 @@ public class DomainMaker { /** * Registers a known schema resource for validation. */ - public boolean registerValidator(@NonNull ToscaPolicyTypeIdentifier policyType) { + public boolean registerValidator(@NonNull ToscaConceptIdentifier policyType) { // // A known schema is one that embedded in a .jar in the classpath as a resource // matching the following syntax: <policy-type-name>-<policy-type-version>.schema.json. @@ -175,7 +176,7 @@ public class DomainMaker { /** * Registers/Overrides a new/known schema for a policy type. */ - public boolean registerValidator(@NonNull ToscaPolicyTypeIdentifier policyType, @NonNull String schema) { + public boolean registerValidator(@NonNull ToscaConceptIdentifier policyType, @NonNull String schema) { try { validators.put(policyType, new StandardValCoder(schema, policyType.toString())); } catch (RuntimeException r) { @@ -195,7 +196,7 @@ public class DomainMaker { /** * Converts a JSON policy into a Domain Policy. */ - public <T> T convertTo(@NonNull ToscaPolicyTypeIdentifier policyType, @NonNull String json, @NonNull Class<T> clazz) + public <T> T convertTo(@NonNull ToscaConceptIdentifier policyType, @NonNull String json, @NonNull Class<T> clazz) throws CoderException { if (isRegistered(policyType)) { return validators.get(policyType).decode(json, clazz); @@ -215,7 +216,7 @@ public class DomainMaker { throw new UnsupportedOperationException("schema generation from policy type is not supported"); } - public boolean isRegistered(@NonNull ToscaPolicyTypeIdentifier policyType) { + public boolean isRegistered(@NonNull ToscaConceptIdentifier policyType) { return validators.containsKey(policyType) || registerValidator(policyType); } diff --git a/policy-utils/src/test/java/org/onap/policy/drools/policies/DomainMakerTest.java b/policy-utils/src/test/java/org/onap/policy/drools/policies/DomainMakerTest.java index 5bc767cd..2c883304 100644 --- a/policy-utils/src/test/java/org/onap/policy/drools/policies/DomainMakerTest.java +++ b/policy-utils/src/test/java/org/onap/policy/drools/policies/DomainMakerTest.java @@ -1,6 +1,7 @@ /* * ============LICENSE_START======================================================= * Copyright (C) 2020 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. @@ -38,9 +39,9 @@ import org.onap.policy.drools.models.domains.a.DomainAPolicy; import org.onap.policy.drools.models.domains.a.Metadata; import org.onap.policy.drools.models.domains.a.Nested; import org.onap.policy.drools.models.domains.a.Properties; +import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy; import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyType; -import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyTypeIdentifier; public class DomainMakerTest { @@ -53,8 +54,8 @@ public class DomainMakerTest { @Test public void testIsConformantString() throws IOException { - ToscaPolicyTypeIdentifier policyTypeId = - new ToscaPolicyTypeIdentifier("policy.type.A", "1.0.0"); + ToscaConceptIdentifier policyTypeId = + new ToscaConceptIdentifier("policy.type.A", "1.0.0"); String rawJsonPolicyType = getJsonFromFile("src/test/resources/policyA.json"); @@ -75,8 +76,8 @@ public class DomainMakerTest { @Test public void testIsDomainConformant() { - ToscaPolicyTypeIdentifier policyTypeId = - new ToscaPolicyTypeIdentifier("policy.type.A", "1.0.0"); + ToscaConceptIdentifier policyTypeId = + new ToscaConceptIdentifier("policy.type.A", "1.0.0"); DomainAPolicy domainAPolicy = createDomainPolicy(); @@ -108,7 +109,7 @@ public class DomainMakerTest { assertDomainPolicy(domainAPolicy); domainAPolicy.getProperties().getNested().setNested1(""); - ToscaPolicyTypeIdentifier ident1 = policy1.getTypeIdentifier(); + ToscaConceptIdentifier ident1 = policy1.getTypeIdentifier(); assertThatThrownBy(() -> domainMaker.conformance(ident1, domainAPolicy)) .isInstanceOf(ValidationFailedException.class) .hasMessageContaining("Pattern ^(.+)$ is not contained in text"); @@ -116,8 +117,8 @@ public class DomainMakerTest { @Test public void testRegisterValidator() throws IOException, CoderException { - ToscaPolicyTypeIdentifier policyTypeId = - new ToscaPolicyTypeIdentifier("policy.type.external", "9.9.9"); + ToscaConceptIdentifier policyTypeId = + new ToscaConceptIdentifier("policy.type.external", "9.9.9"); assertTrue(domainMaker.registerValidator(policyTypeId, getJsonFromFile("src/test/resources/policy.type.external-9.9.9.schema.json"))); @@ -151,12 +152,12 @@ public class DomainMakerTest { @Test public void testIsRegistered() { - ToscaPolicyTypeIdentifier policyTypeId1 = - new ToscaPolicyTypeIdentifier("policy.type.A", "1.0.0"); + ToscaConceptIdentifier policyTypeId1 = + new ToscaConceptIdentifier("policy.type.A", "1.0.0"); assertTrue(domainMaker.isRegistered(policyTypeId1)); - ToscaPolicyTypeIdentifier policyTypeId2 = - new ToscaPolicyTypeIdentifier("policy.type.external", "7.7.9"); + ToscaConceptIdentifier policyTypeId2 = + new ToscaConceptIdentifier("policy.type.external", "7.7.9"); assertFalse(domainMaker.isRegistered(policyTypeId2)); } @@ -191,4 +192,4 @@ public class DomainMakerTest { assertEquals(true, domainAPolicy.getProperties().getNested().isNested2()); assertEquals(50, domainAPolicy.getProperties().getNested().getNested3()); } -}
\ No newline at end of file +} |