diff options
Diffstat (limited to 'models-provider/src/main')
3 files changed, 61 insertions, 53 deletions
diff --git a/models-provider/src/main/java/org/onap/policy/models/provider/PolicyModelsProvider.java b/models-provider/src/main/java/org/onap/policy/models/provider/PolicyModelsProvider.java index e390a04f0..a8d8483e3 100644 --- a/models-provider/src/main/java/org/onap/policy/models/provider/PolicyModelsProvider.java +++ b/models-provider/src/main/java/org/onap/policy/models/provider/PolicyModelsProvider.java @@ -24,13 +24,12 @@ import java.util.Map; import lombok.NonNull; -import org.onap.policy.models.base.PfConceptKey; import org.onap.policy.models.base.PfModelException; import org.onap.policy.models.pdp.concepts.PdpGroups; +import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate; import org.onap.policy.models.tosca.legacy.concepts.LegacyGuardPolicyInput; import org.onap.policy.models.tosca.legacy.concepts.LegacyGuardPolicyOutput; import org.onap.policy.models.tosca.legacy.concepts.LegacyOperationalPolicy; -import org.onap.policy.models.tosca.simple.concepts.JpaToscaServiceTemplate; /** * This interface describes the operations that are provided to users and components for reading objects from and @@ -49,12 +48,13 @@ public interface PolicyModelsProvider extends AutoCloseable { /** * Get policy types. * - * @param policyTypeKey the policy type key for the policy types to be retrieved. A null key name returns all policy - * types. A null key version returns all versions of the policy type name specified in the key. + * @param name the name of the policy type to get. + * @param version the version of the policy type to get. * @return the policy types found * @throws PfModelException on errors getting policy types */ - public JpaToscaServiceTemplate getPolicyTypes(@NonNull final PfConceptKey policyTypeKey) throws PfModelException; + public ToscaServiceTemplate getPolicyTypes(@NonNull final String name, @NonNull final String version) + throws PfModelException; /** * Create policy types. @@ -63,7 +63,7 @@ public interface PolicyModelsProvider extends AutoCloseable { * @return the TOSCA service template containing the created policy types * @throws PfModelException on errors creating policy types */ - public JpaToscaServiceTemplate createPolicyTypes(@NonNull final JpaToscaServiceTemplate serviceTemplate) + public ToscaServiceTemplate createPolicyTypes(@NonNull final ToscaServiceTemplate serviceTemplate) throws PfModelException; /** @@ -73,28 +73,30 @@ public interface PolicyModelsProvider extends AutoCloseable { * @return the TOSCA service template containing the modified policy types * @throws PfModelException on errors updating policy types */ - public JpaToscaServiceTemplate updatePolicyTypes(@NonNull final JpaToscaServiceTemplate serviceTemplate) + public ToscaServiceTemplate updatePolicyTypes(@NonNull final ToscaServiceTemplate serviceTemplate) throws PfModelException; /** * Delete policy types. * - * @param policyTypeKey the policy type key for the policy types to be deleted, if the version of the key is null, - * all versions of the policy type are deleted. + * @param name the name of the policy type to delete. + * @param version the version of the policy type to delete. * @return the TOSCA service template containing the policy types that were deleted * @throws PfModelException on errors deleting policy types */ - public JpaToscaServiceTemplate deletePolicyTypes(@NonNull final PfConceptKey policyTypeKey) throws PfModelException; + public ToscaServiceTemplate deletePolicyTypes(@NonNull final String name, @NonNull final String version) + throws PfModelException; /** * Get policies. * - * @param policyKey the policy key for the policies to be retrieved. The parent name and version must be specified. - * A null local name returns all policies for a parent policy type. + * @param name the name of the policy to get. + * @param version the version of the policy to get. * @return the policies found * @throws PfModelException on errors getting policies */ - public JpaToscaServiceTemplate getPolicies(@NonNull final PfConceptKey policyKey) throws PfModelException; + public ToscaServiceTemplate getPolicies(@NonNull final String name, @NonNull final String version) + throws PfModelException; /** * Create policies. @@ -103,7 +105,7 @@ public interface PolicyModelsProvider extends AutoCloseable { * @return the TOSCA service template containing the policy types that were created * @throws PfModelException on errors creating policies */ - public JpaToscaServiceTemplate createPolicies(@NonNull final JpaToscaServiceTemplate serviceTemplate) + public ToscaServiceTemplate createPolicies(@NonNull final ToscaServiceTemplate serviceTemplate) throws PfModelException; @@ -114,17 +116,19 @@ public interface PolicyModelsProvider extends AutoCloseable { * @return the TOSCA service template containing the policies that were updated * @throws PfModelException on errors updating policies */ - public JpaToscaServiceTemplate updatePolicies(@NonNull final JpaToscaServiceTemplate serviceTemplate) + public ToscaServiceTemplate updatePolicies(@NonNull final ToscaServiceTemplate serviceTemplate) throws PfModelException; /** * Delete policies. * - * @param policyKey the policy key + * @param name the name of the policy to delete. + * @param version the version of the policy to delete. * @return the TOSCA service template containing the policy types that were deleted * @throws PfModelException on errors deleting policies */ - public JpaToscaServiceTemplate deletePolicies(@NonNull final PfConceptKey policyKey) throws PfModelException; + public ToscaServiceTemplate deletePolicies(@NonNull final String name, @NonNull final String version) + throws PfModelException; /** * Get legacy operational policy. diff --git a/models-provider/src/main/java/org/onap/policy/models/provider/impl/DatabasePolicyModelsProviderImpl.java b/models-provider/src/main/java/org/onap/policy/models/provider/impl/DatabasePolicyModelsProviderImpl.java index 85c4d139c..9a32feb65 100644 --- a/models-provider/src/main/java/org/onap/policy/models/provider/impl/DatabasePolicyModelsProviderImpl.java +++ b/models-provider/src/main/java/org/onap/policy/models/provider/impl/DatabasePolicyModelsProviderImpl.java @@ -29,7 +29,6 @@ import javax.ws.rs.core.Response; import lombok.NonNull; -import org.onap.policy.models.base.PfConceptKey; import org.onap.policy.models.base.PfModelException; import org.onap.policy.models.base.PfModelRuntimeException; import org.onap.policy.models.dao.DaoParameters; @@ -40,12 +39,12 @@ import org.onap.policy.models.pdp.concepts.PdpGroups; import org.onap.policy.models.pdp.persistence.provider.PdpProvider; import org.onap.policy.models.provider.PolicyModelsProvider; import org.onap.policy.models.provider.PolicyModelsProviderParameters; +import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate; +import org.onap.policy.models.tosca.authorative.provider.AuthorativeToscaProvider; import org.onap.policy.models.tosca.legacy.concepts.LegacyGuardPolicyInput; import org.onap.policy.models.tosca.legacy.concepts.LegacyGuardPolicyOutput; import org.onap.policy.models.tosca.legacy.concepts.LegacyOperationalPolicy; import org.onap.policy.models.tosca.legacy.provider.LegacyProvider; -import org.onap.policy.models.tosca.simple.concepts.JpaToscaServiceTemplate; -import org.onap.policy.models.tosca.simple.provider.SimpleToscaProvider; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -138,56 +137,59 @@ public class DatabasePolicyModelsProviderImpl implements PolicyModelsProvider { } @Override - public JpaToscaServiceTemplate getPolicyTypes(@NonNull final PfConceptKey policyTypeKey) throws PfModelException { + public ToscaServiceTemplate getPolicyTypes(@NonNull final String name, @NonNull final String version) + throws PfModelException { assertInitilized(); - return new SimpleToscaProvider().getPolicyTypes(pfDao, policyTypeKey); + return new AuthorativeToscaProvider().getPolicyTypes(pfDao, name, version); } @Override - public JpaToscaServiceTemplate createPolicyTypes(@NonNull final JpaToscaServiceTemplate serviceTemplate) + public ToscaServiceTemplate createPolicyTypes(@NonNull final ToscaServiceTemplate serviceTemplate) throws PfModelException { assertInitilized(); - return new SimpleToscaProvider().createPolicyTypes(pfDao, serviceTemplate); + return new AuthorativeToscaProvider().createPolicyTypes(pfDao, serviceTemplate); } @Override - public JpaToscaServiceTemplate updatePolicyTypes(@NonNull final JpaToscaServiceTemplate serviceTemplate) + public ToscaServiceTemplate updatePolicyTypes(@NonNull final ToscaServiceTemplate serviceTemplate) throws PfModelException { assertInitilized(); - return new SimpleToscaProvider().updatePolicyTypes(pfDao, serviceTemplate); + return new AuthorativeToscaProvider().updatePolicyTypes(pfDao, serviceTemplate); } @Override - public JpaToscaServiceTemplate deletePolicyTypes(@NonNull final PfConceptKey policyTypeKey) + public ToscaServiceTemplate deletePolicyTypes(@NonNull final String name, @NonNull final String version) throws PfModelException { assertInitilized(); - return new SimpleToscaProvider().deletePolicyTypes(pfDao, policyTypeKey); + return new AuthorativeToscaProvider().deletePolicyTypes(pfDao, name, version); } @Override - public JpaToscaServiceTemplate getPolicies(@NonNull final PfConceptKey policyKey) throws PfModelException { + public ToscaServiceTemplate getPolicies(@NonNull final String name, @NonNull final String version) + throws PfModelException { assertInitilized(); - return new SimpleToscaProvider().getPolicies(pfDao, policyKey); + return new AuthorativeToscaProvider().getPolicies(pfDao, name, version); } @Override - public JpaToscaServiceTemplate createPolicies(@NonNull final JpaToscaServiceTemplate serviceTemplate) + public ToscaServiceTemplate createPolicies(@NonNull final ToscaServiceTemplate serviceTemplate) throws PfModelException { assertInitilized(); - return new SimpleToscaProvider().createPolicies(pfDao, serviceTemplate); + return new AuthorativeToscaProvider().createPolicies(pfDao, serviceTemplate); } @Override - public JpaToscaServiceTemplate updatePolicies(@NonNull final JpaToscaServiceTemplate serviceTemplate) + public ToscaServiceTemplate updatePolicies(@NonNull final ToscaServiceTemplate serviceTemplate) throws PfModelException { assertInitilized(); - return new SimpleToscaProvider().updatePolicies(pfDao, serviceTemplate); + return new AuthorativeToscaProvider().updatePolicies(pfDao, serviceTemplate); } @Override - public JpaToscaServiceTemplate deletePolicies(@NonNull final PfConceptKey policyKey) throws PfModelException { + public ToscaServiceTemplate deletePolicies(@NonNull final String name, @NonNull final String version) + throws PfModelException { assertInitilized(); - return new SimpleToscaProvider().deletePolicies(pfDao, policyKey); + return new AuthorativeToscaProvider().deletePolicies(pfDao, name, version); } @Override diff --git a/models-provider/src/main/java/org/onap/policy/models/provider/impl/DummyPolicyModelsProviderImpl.java b/models-provider/src/main/java/org/onap/policy/models/provider/impl/DummyPolicyModelsProviderImpl.java index e37b1d632..8881ed08e 100644 --- a/models-provider/src/main/java/org/onap/policy/models/provider/impl/DummyPolicyModelsProviderImpl.java +++ b/models-provider/src/main/java/org/onap/policy/models/provider/impl/DummyPolicyModelsProviderImpl.java @@ -21,25 +21,23 @@ package org.onap.policy.models.provider.impl; -import com.google.gson.Gson; - import java.util.HashMap; import java.util.Map; import javax.ws.rs.core.Response; import lombok.NonNull; + +import org.onap.policy.common.utils.coder.StandardCoder; import org.onap.policy.common.utils.resources.ResourceUtils; -import org.onap.policy.models.base.PfConceptKey; import org.onap.policy.models.base.PfModelException; import org.onap.policy.models.base.PfModelRuntimeException; import org.onap.policy.models.pdp.concepts.PdpGroups; import org.onap.policy.models.provider.PolicyModelsProvider; import org.onap.policy.models.provider.PolicyModelsProviderParameters; +import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate; import org.onap.policy.models.tosca.legacy.concepts.LegacyGuardPolicyInput; import org.onap.policy.models.tosca.legacy.concepts.LegacyGuardPolicyOutput; import org.onap.policy.models.tosca.legacy.concepts.LegacyOperationalPolicy; -import org.onap.policy.models.tosca.simple.concepts.JpaToscaServiceTemplate; -import org.onap.policy.models.tosca.simple.serialization.ToscaServiceTemplateMessageBodyHandler; /** * This class provides a dummy implementation of the Policy Models Provider for the ONAP Policy Framework. @@ -66,47 +64,50 @@ public class DummyPolicyModelsProviderImpl implements PolicyModelsProvider { } @Override - public JpaToscaServiceTemplate getPolicyTypes(@NonNull final PfConceptKey policyTypeKey) throws PfModelException { + public ToscaServiceTemplate getPolicyTypes(@NonNull final String name, @NonNull final String version) + throws PfModelException { return getDummyResponse("dummyimpl/DummyToscaPolicyTypeGetResponse.json"); } @Override - public JpaToscaServiceTemplate createPolicyTypes(@NonNull final JpaToscaServiceTemplate serviceTemplate) + public ToscaServiceTemplate createPolicyTypes(@NonNull final ToscaServiceTemplate serviceTemplate) throws PfModelException { return serviceTemplate; } @Override - public JpaToscaServiceTemplate updatePolicyTypes(@NonNull final JpaToscaServiceTemplate serviceTemplate) + public ToscaServiceTemplate updatePolicyTypes(@NonNull final ToscaServiceTemplate serviceTemplate) throws PfModelException { return serviceTemplate; } @Override - public JpaToscaServiceTemplate deletePolicyTypes(@NonNull final PfConceptKey policyTypeKey) + public ToscaServiceTemplate deletePolicyTypes(@NonNull final String name, @NonNull final String version) throws PfModelException { return getDummyResponse("dummyimpl/DummyToscaPolicyTypeDeleteResponse.json"); } @Override - public JpaToscaServiceTemplate getPolicies(@NonNull final PfConceptKey policyKey) throws PfModelException { + public ToscaServiceTemplate getPolicies(@NonNull final String name, @NonNull final String version) + throws PfModelException { return getDummyResponse("dummyimpl/DummyToscaPolicyGetResponse.json"); } @Override - public JpaToscaServiceTemplate createPolicies(@NonNull final JpaToscaServiceTemplate serviceTemplate) + public ToscaServiceTemplate createPolicies(@NonNull final ToscaServiceTemplate serviceTemplate) throws PfModelException { return serviceTemplate; } @Override - public JpaToscaServiceTemplate updatePolicies(@NonNull final JpaToscaServiceTemplate serviceTemplate) + public ToscaServiceTemplate updatePolicies(@NonNull final ToscaServiceTemplate serviceTemplate) throws PfModelException { return serviceTemplate; } @Override - public JpaToscaServiceTemplate deletePolicies(@NonNull final PfConceptKey policyKey) throws PfModelException { + public ToscaServiceTemplate deletePolicies(@NonNull final String name, @NonNull final String version) + throws PfModelException { return getDummyResponse("dummyimpl/DummyToscaPolicyDeleteResponse.json"); } @@ -182,12 +183,13 @@ public class DummyPolicyModelsProviderImpl implements PolicyModelsProvider { * @param fileName the file name containing the dummy response * @return the ToscaServiceTemplate with the dummy response */ - protected JpaToscaServiceTemplate getDummyResponse(@NonNull final String fileName) { - Gson gson = new ToscaServiceTemplateMessageBodyHandler().getGson(); - JpaToscaServiceTemplate serviceTemplate; + protected ToscaServiceTemplate getDummyResponse(@NonNull final String fileName) { + StandardCoder standardCoder = new StandardCoder(); + ToscaServiceTemplate serviceTemplate; try { - serviceTemplate = gson.fromJson(ResourceUtils.getResourceAsString(fileName), JpaToscaServiceTemplate.class); + serviceTemplate = + standardCoder.decode(ResourceUtils.getResourceAsString(fileName), ToscaServiceTemplate.class); if (serviceTemplate == null) { throw new PfModelException(Response.Status.INTERNAL_SERVER_ERROR, "error reading specified file"); } |