diff options
Diffstat (limited to 'models-provider/src/main/java')
5 files changed, 388 insertions, 86 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 fa666c0ab..9bc49837e 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,6 +24,7 @@ import lombok.NonNull; import org.onap.policy.models.base.PfConceptKey; import org.onap.policy.models.base.PfModelException; +import org.onap.policy.models.pap.concepts.PdpGroups; import org.onap.policy.models.tosca.legacy.concepts.LegacyGuardPolicy; import org.onap.policy.models.tosca.legacy.concepts.LegacyOperationalPolicy; import org.onap.policy.models.tosca.simple.concepts.ToscaServiceTemplate; @@ -34,7 +35,13 @@ import org.onap.policy.models.tosca.simple.concepts.ToscaServiceTemplate; * * @author Liam Fallon (liam.fallon@est.tech) */ -public interface PolicyModelsProvider { +public interface PolicyModelsProvider extends AutoCloseable { + /** + * Open the policy model provider initializing whatever internal handling it needs. + * + * @throws PfModelException on errors opening the models provider + */ + public void init() throws PfModelException; /** * Get policy types. @@ -200,34 +207,36 @@ public interface PolicyModelsProvider { /** * Get PDP groups. * - * @param somePdpGroupFilter a filter for the get + * @param pdpGroupFilter a filter for the get * @return the PDP groups found * @throws PfModelException on errors getting PDP groups */ - public Object getPdpGroups(@NonNull final Object somePdpGroupFilter) throws PfModelException; + public PdpGroups getPdpGroups(@NonNull final String pdpGroupFilter) throws PfModelException; /** * Creates PDP groups. * - * @param somePdpGroupSpecification a specification for the PDP group + * @param pdpGroups a specification of the PDP groups to create + * @return the PDP groups created * @throws PfModelException on errors creating PDP groups */ - public Object createPdpGroups(@NonNull final Object somePdpGroupSpecification) throws PfModelException; - + public PdpGroups createPdpGroups(@NonNull final PdpGroups pdpGroups) throws PfModelException; /** * Updates PDP groups. * - * @param somePdpGroupSpecification a specification for the PDP group + * @param pdpGroups a specification of the PDP groups to update + * @return the PDP groups updated * @throws PfModelException on errors updating PDP groups */ - public Object updatePdpGroups(@NonNull final Object somePdpGroupSpecification) throws PfModelException; + public PdpGroups updatePdpGroups(@NonNull final PdpGroups pdpGroups) throws PfModelException; /** * Delete PDP groups. * - * @param somePdpGroupFilter a filter for the get + * @param pdpGroupFilter a filter for the get + * @return the PDP groups deleted * @throws PfModelException on errors deleting PDP groups */ - public Object deletePdpGroups(@NonNull final Object somePdpGroupFilter) throws PfModelException; + public PdpGroups deletePdpGroups(@NonNull final String pdpGroupFilter) throws PfModelException; } diff --git a/models-provider/src/main/java/org/onap/policy/models/provider/PolicyModelsProviderFactory.java b/models-provider/src/main/java/org/onap/policy/models/provider/PolicyModelsProviderFactory.java index b4b5f1ddc..718668b97 100644 --- a/models-provider/src/main/java/org/onap/policy/models/provider/PolicyModelsProviderFactory.java +++ b/models-provider/src/main/java/org/onap/policy/models/provider/PolicyModelsProviderFactory.java @@ -20,7 +20,14 @@ package org.onap.policy.models.provider; -import org.onap.policy.models.provider.impl.DummyPolicyModelsProviderImpl; +import javax.ws.rs.core.Response; + +import lombok.NonNull; + +import org.onap.policy.models.base.PfModelException; +import org.onap.policy.models.dao.impl.DefaultPfDao; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * A factory for creating PolicyModelsProvider objects using the default Policy Framework implementation. @@ -28,11 +35,44 @@ import org.onap.policy.models.provider.impl.DummyPolicyModelsProviderImpl; * @author Liam Fallon (liam.fallon@est.tech) */ public class PolicyModelsProviderFactory { + private static final Logger LOGGER = LoggerFactory.getLogger(DefaultPfDao.class); /** * Creates a new PolicyModelsProvider object from its implementation. + * + * @param parameters The parameters for the implementation of the PolicyModelProvider + * @throws PfModelException on errors creating an implementation of the PolicyModelProvider */ - public PolicyModelsProvider createPolicyModelsProvider() { - return new DummyPolicyModelsProviderImpl(); + public PolicyModelsProvider createPolicyModelsProvider(@NonNull final PolicyModelsProviderParameters parameters) + throws PfModelException { + // Get the class for the PolicyModelsProvider + Class<?> implementationClass = null; + try { + // Check if the implementation class is on the classpath + implementationClass = Class.forName(parameters.getImplementation()); + } catch (final Exception exc) { + String errorMessage = "could not find implementation of the \"PolicyModelsProvider\" interface \"" + + parameters.getImplementation() + "\""; + LOGGER.warn(errorMessage, exc); + throw new PfModelException(Response.Status.NOT_FOUND, errorMessage, exc); + } + + // It is, now check if it is a PolicyModelsProvider + if (!PolicyModelsProvider.class.isAssignableFrom(implementationClass)) { + String errorMessage = "the class \"" + implementationClass.getCanonicalName() + + "\" is not an implementation of the \"PolicyModelsProvider\" interface"; + LOGGER.warn(errorMessage); + throw new PfModelException(Response.Status.BAD_REQUEST, errorMessage); + } + + try { + return (PolicyModelsProvider) implementationClass.getConstructor(PolicyModelsProviderParameters.class) + .newInstance(parameters); + } catch (Exception exc) { + String errorMessage = + "could not create an instance of PolicyModelsProvider \"" + parameters.getImplementation() + "\""; + LOGGER.warn(errorMessage, exc); + throw new PfModelException(Response.Status.INTERNAL_SERVER_ERROR, errorMessage, exc); + } } } diff --git a/models-provider/src/main/java/org/onap/policy/models/provider/PolicyModelsProviderParameters.java b/models-provider/src/main/java/org/onap/policy/models/provider/PolicyModelsProviderParameters.java new file mode 100644 index 000000000..5abafed22 --- /dev/null +++ b/models-provider/src/main/java/org/onap/policy/models/provider/PolicyModelsProviderParameters.java @@ -0,0 +1,88 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2019 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.provider; + +import lombok.Data; + +import org.onap.policy.common.parameters.GroupValidationResult; +import org.onap.policy.common.parameters.ParameterGroup; +import org.onap.policy.common.parameters.ValidationStatus; +import org.onap.policy.common.utils.validation.ParameterValidationUtils; +import org.onap.policy.models.provider.impl.DatabasePolicyModelsProviderImpl; + +// @formatter:off +/** + * Class to hold all the plugin handler parameters. + * + * <p>The following parameters are defined: + * <ol> + * <li>name: A name for the parameters. + * <li>implementation: The implementation of the PolicyModelsProvider to use for writing and reading concepts, + * defaults to {@link DatabasePolicyModelsProviderImpl} and may not be null + * <li>databaseUrl: The JDBC URL for the database, mandatory. + * <li>databaseUser: The user id to use for connecting to the database, optional, defaults to null. + * <li>databasePassword: The password to use for connecting to the database encoded in Base64, optional, + * defaults to null. + * <li>persistenceUnit: The persistence unit refined in META-INF/persistence.xml to use for connecting + * to the database, mandatory. + * </ol> + * + * @author Liam Fallon (liam.fallon@est.tech) + */ +//@formatter:on + +@Data +public class PolicyModelsProviderParameters implements ParameterGroup { + private static final String DEFAULT_IMPLEMENTATION = DatabasePolicyModelsProviderImpl.class.getCanonicalName(); + + private String name; + private String implementation = DEFAULT_IMPLEMENTATION; + private String databaseUrl; + private String databaseUser; + private String databasePassword; + private String persistenceUnit; + + /** + * Validate the model provider parameters. + * + */ + @Override + public GroupValidationResult validate() { + final GroupValidationResult validationResult = new GroupValidationResult(this); + + if (!ParameterValidationUtils.validateStringParameter(implementation)) { + validationResult.setResult("implementation", ValidationStatus.INVALID, + "a PolicyModelsProvider implementation must be specified"); + } + + if (!ParameterValidationUtils.validateStringParameter(databaseUrl)) { + validationResult.setResult("databaseUrl", ValidationStatus.INVALID, + "a URL must be specified for the JDBC connection to the database"); + } + + if (!ParameterValidationUtils.validateStringParameter(persistenceUnit)) { + validationResult.setResult("persistenceUnit", ValidationStatus.INVALID, + "a persistence unit must be specified for connecting to the database"); + } + + return validationResult; + } +} 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 8136a75af..970aa8fef 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 @@ -20,125 +20,266 @@ package org.onap.policy.models.provider.impl; +import java.sql.Connection; +import java.sql.DriverManager; +import java.util.Base64; + +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; +import org.onap.policy.models.dao.PfDao; +import org.onap.policy.models.dao.PfDaoFactory; +import org.onap.policy.models.dao.impl.DefaultPfDao; +import org.onap.policy.models.pap.concepts.PdpGroups; +import org.onap.policy.models.pap.provider.PapProvider; import org.onap.policy.models.provider.PolicyModelsProvider; +import org.onap.policy.models.provider.PolicyModelsProviderParameters; import org.onap.policy.models.tosca.legacy.concepts.LegacyGuardPolicy; import org.onap.policy.models.tosca.legacy.concepts.LegacyOperationalPolicy; +import org.onap.policy.models.tosca.legacy.provider.LegacyToscaProvider; import org.onap.policy.models.tosca.simple.concepts.ToscaServiceTemplate; +import org.onap.policy.models.tosca.simple.provider.SimpleToscaProvider; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** - * This class provides an implementation of the Policy Models Provider for the ONAP Policy Framework - * that works towards a relational database. + * This class provides an implementation of the Policy Models Provider for the ONAP Policy Framework that works towards + * a relational database. * * @author Liam Fallon (liam.fallon@est.tech) */ public class DatabasePolicyModelsProviderImpl implements PolicyModelsProvider { + private static final Logger LOGGER = LoggerFactory.getLogger(DefaultPfDao.class); + + private final PolicyModelsProviderParameters parameters; + + // Database connection and the DAO for reading and writing Policy Framework concepts + private Connection connection; + private PfDao pfDao; + + /** + * Constructor that takes the parameters. + * + * @param parameters the parameters for the provider + */ + public DatabasePolicyModelsProviderImpl(@NonNull final PolicyModelsProviderParameters parameters) { + this.parameters = parameters; + } + + @Override + public void init() throws PfModelException { + LOGGER.debug("opening the database connection to {} using persistence unit {}", parameters.getDatabaseUrl(), + parameters.getPersistenceUnit()); + + // Decode the password using Base64 + String decodedPassword = new String(Base64.getDecoder().decode(parameters.getDatabasePassword())); + + // Connect to the database, call does not implement AutoCloseable for try-with-resources + try { + connection = DriverManager.getConnection(parameters.getDatabaseUrl(), parameters.getDatabaseUser(), + decodedPassword); + } catch (Exception exc) { + String errorMessage = "could not connect to database with URL \"" + parameters.getDatabaseUrl() + "\""; + LOGGER.warn(errorMessage, exc); + throw new PfModelException(Response.Status.NOT_ACCEPTABLE, errorMessage, exc); + } + + // Parameters for the DAO + final DaoParameters daoParameters = new DaoParameters(); + daoParameters.setPluginClass(DefaultPfDao.class.getCanonicalName()); + daoParameters.setPersistenceUnit(parameters.getPersistenceUnit()); + + try { + pfDao = new PfDaoFactory().createPfDao(daoParameters); + pfDao.init(daoParameters); + } catch (Exception exc) { + String errorMessage = "could not create Data Access Object (DAO) using url \"" + parameters.getDatabaseUrl() + + "\" and persistence unit \"" + parameters.getPersistenceUnit() + "\""; + LOGGER.warn(errorMessage, exc); + + this.close(); + throw new PfModelException(Response.Status.NOT_ACCEPTABLE, errorMessage, exc); + } + } + + @Override + public void close() throws PfModelException { + LOGGER.debug("closing the database connection to {} using persistence unit {}", parameters.getDatabaseUrl(), + parameters.getPersistenceUnit()); + + if (pfDao != null) { + pfDao.close(); + pfDao = null; + } + + if (connection != null) { + try { + connection.close(); + } catch (Exception exc) { + + String errorMessage = + "could not close connection to database with URL \"" + parameters.getDatabaseUrl() + "\""; + LOGGER.warn(errorMessage, exc); + throw new PfModelException(Response.Status.INTERNAL_SERVER_ERROR, errorMessage, exc); + } finally { + connection = null; + } + } + + LOGGER.debug("closed the database connection to {} using persistence unit {}", parameters.getDatabaseUrl(), + parameters.getPersistenceUnit()); + } @Override - public ToscaServiceTemplate getPolicyTypes(@NonNull PfConceptKey policyTypeKey) throws PfModelException { - return null; + public ToscaServiceTemplate getPolicyTypes(@NonNull final PfConceptKey policyTypeKey) throws PfModelException { + assertInitilized(); + return new SimpleToscaProvider().getPolicyTypes(pfDao, policyTypeKey); } @Override - public ToscaServiceTemplate createPolicyTypes(@NonNull ToscaServiceTemplate serviceTemplate) + public ToscaServiceTemplate createPolicyTypes(@NonNull final ToscaServiceTemplate serviceTemplate) throws PfModelException { - return null; + assertInitilized(); + return new SimpleToscaProvider().createPolicyTypes(pfDao, serviceTemplate); } @Override - public ToscaServiceTemplate updatePolicyTypes(@NonNull ToscaServiceTemplate serviceTemplate) + public ToscaServiceTemplate updatePolicyTypes(@NonNull final ToscaServiceTemplate serviceTemplate) throws PfModelException { - return null; + assertInitilized(); + return new SimpleToscaProvider().updatePolicyTypes(pfDao, serviceTemplate); } @Override - public ToscaServiceTemplate deletePolicyTypes(@NonNull PfConceptKey policyTypeKey) throws PfModelException { - return null; + public ToscaServiceTemplate deletePolicyTypes(@NonNull final PfConceptKey policyTypeKey) throws PfModelException { + assertInitilized(); + return new SimpleToscaProvider().deletePolicyTypes(pfDao, policyTypeKey); } @Override - public ToscaServiceTemplate getPolicies(@NonNull PfConceptKey policyKey) throws PfModelException { - return null; + public ToscaServiceTemplate getPolicies(@NonNull final PfConceptKey policyKey) throws PfModelException { + assertInitilized(); + return new SimpleToscaProvider().getPolicies(pfDao, policyKey); } @Override - public ToscaServiceTemplate createPolicies(@NonNull ToscaServiceTemplate serviceTemplate) throws PfModelException { - return null; + public ToscaServiceTemplate createPolicies(@NonNull final ToscaServiceTemplate serviceTemplate) + throws PfModelException { + assertInitilized(); + return new SimpleToscaProvider().createPolicies(pfDao, serviceTemplate); } @Override - public ToscaServiceTemplate updatePolicies(@NonNull ToscaServiceTemplate serviceTemplate) throws PfModelException { - return null; + public ToscaServiceTemplate updatePolicies(@NonNull final ToscaServiceTemplate serviceTemplate) + throws PfModelException { + assertInitilized(); + return new SimpleToscaProvider().updatePolicies(pfDao, serviceTemplate); } @Override - public ToscaServiceTemplate deletePolicies(@NonNull PfConceptKey policyKey) throws PfModelException { - return null; + public ToscaServiceTemplate deletePolicies(@NonNull final PfConceptKey policyKey) throws PfModelException { + assertInitilized(); + return new SimpleToscaProvider().deletePolicies(pfDao, policyKey); } @Override - public LegacyOperationalPolicy getOperationalPolicy(@NonNull String policyId) throws PfModelException { - return null; + public LegacyOperationalPolicy getOperationalPolicy(@NonNull final String policyId) throws PfModelException { + assertInitilized(); + return new LegacyToscaProvider().getOperationalPolicy(pfDao, policyId); } @Override - public LegacyOperationalPolicy createOperationalPolicy(@NonNull LegacyOperationalPolicy legacyOperationalPolicy) - throws PfModelException { - return null; + public LegacyOperationalPolicy createOperationalPolicy( + @NonNull final LegacyOperationalPolicy legacyOperationalPolicy) throws PfModelException { + assertInitilized(); + return new LegacyToscaProvider().createOperationalPolicy(pfDao, legacyOperationalPolicy); } @Override - public LegacyOperationalPolicy updateOperationalPolicy(@NonNull LegacyOperationalPolicy legacyOperationalPolicy) - throws PfModelException { - return null; + public LegacyOperationalPolicy updateOperationalPolicy( + @NonNull final LegacyOperationalPolicy legacyOperationalPolicy) throws PfModelException { + assertInitilized(); + return new LegacyToscaProvider().updateOperationalPolicy(pfDao, legacyOperationalPolicy); } @Override - public LegacyOperationalPolicy deleteOperationalPolicy(@NonNull String policyId) throws PfModelException { - return null; + public LegacyOperationalPolicy deleteOperationalPolicy(@NonNull final String policyId) throws PfModelException { + assertInitilized(); + return new LegacyToscaProvider().deleteOperationalPolicy(pfDao, policyId); } @Override - public LegacyGuardPolicy getGuardPolicy(@NonNull String policyId) throws PfModelException { - return null; + public LegacyGuardPolicy getGuardPolicy(@NonNull final String policyId) throws PfModelException { + assertInitilized(); + return new LegacyToscaProvider().getGuardPolicy(pfDao, policyId); } @Override - public LegacyGuardPolicy createGuardPolicy(@NonNull LegacyGuardPolicy legacyGuardPolicy) throws PfModelException { - return null; + public LegacyGuardPolicy createGuardPolicy(@NonNull final LegacyGuardPolicy legacyGuardPolicy) + throws PfModelException { + assertInitilized(); + return new LegacyToscaProvider().createGuardPolicy(pfDao, legacyGuardPolicy); } @Override - public LegacyGuardPolicy updateGuardPolicy(@NonNull LegacyGuardPolicy legacyGuardPolicy) throws PfModelException { - return null; + public LegacyGuardPolicy updateGuardPolicy(@NonNull final LegacyGuardPolicy legacyGuardPolicy) + throws PfModelException { + assertInitilized(); + return new LegacyToscaProvider().updateGuardPolicy(pfDao, legacyGuardPolicy); } @Override - public LegacyGuardPolicy deleteGuardPolicy(@NonNull String policyId) throws PfModelException { - return null; + public LegacyGuardPolicy deleteGuardPolicy(@NonNull final String policyId) throws PfModelException { + assertInitilized(); + return new LegacyToscaProvider().deleteGuardPolicy(pfDao, policyId); } @Override - public Object getPdpGroups(@NonNull Object somePdpGroupFilter) throws PfModelException { - return null; + public PdpGroups getPdpGroups(@NonNull String pdpGroupFilter) throws PfModelException { + assertInitilized(); + return new PapProvider().getPdpGroups(pfDao, pdpGroupFilter); } @Override - public Object createPdpGroups(@NonNull Object somePdpGroupSpecification) throws PfModelException { - return null; + public PdpGroups createPdpGroups(@NonNull PdpGroups pdpGroups) throws PfModelException { + assertInitilized(); + return new PapProvider().createPdpGroups(pfDao, pdpGroups); } @Override - public Object updatePdpGroups(@NonNull Object somePdpGroupSpecification) throws PfModelException { - return null; + public PdpGroups updatePdpGroups(@NonNull PdpGroups pdpGroups) throws PfModelException { + assertInitilized(); + return new PapProvider().updatePdpGroups(pfDao, pdpGroups); } @Override - public Object deletePdpGroups(@NonNull Object somePdpGroupFilter) throws PfModelException { - return null; + public PdpGroups deletePdpGroups(@NonNull String pdpGroupFilter) throws PfModelException { + assertInitilized(); + return new PapProvider().deletePdpGroups(pfDao, pdpGroupFilter); } + /** + * Check if the model provider is initialized. + */ + private void assertInitilized() { + if (pfDao == null) { + String errorMessage = "policy models provider is not initilaized"; + LOGGER.warn(errorMessage); + throw new PfModelRuntimeException(Response.Status.BAD_REQUEST, errorMessage); + } + } + + /** + * Hook for unit test mocking of database connection. + * + * @param client the mocked client + */ + protected void setConnection(final Connection connection) { + this.connection = connection; + } } 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 3d57c543a..d8750192c 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 @@ -30,121 +30,145 @@ import org.onap.policy.common.utils.resources.TextFileUtils; 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.pap.concepts.PdpGroups; import org.onap.policy.models.provider.PolicyModelsProvider; +import org.onap.policy.models.provider.PolicyModelsProviderParameters; import org.onap.policy.models.tosca.legacy.concepts.LegacyGuardPolicy; import org.onap.policy.models.tosca.legacy.concepts.LegacyOperationalPolicy; import org.onap.policy.models.tosca.simple.concepts.ToscaServiceTemplate; 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. + * This class provides a dummy implementation of the Policy Models Provider for the ONAP Policy Framework. * * @author Liam Fallon (liam.fallon@est.tech) */ public class DummyPolicyModelsProviderImpl implements PolicyModelsProvider { + /** + * Constructor that takes the parameters. + * + * @param parameters the parameters for the provider + */ + public DummyPolicyModelsProviderImpl(@NonNull final PolicyModelsProviderParameters parameters) { + } + + @Override + public void init() throws PfModelException { + // Not required on the dummy provider + } + + @Override + public void close() { + // Not required on the dummy provider + } + @Override - public ToscaServiceTemplate getPolicyTypes(@NonNull PfConceptKey policyTypeKey) throws PfModelException { + public ToscaServiceTemplate getPolicyTypes(@NonNull final PfConceptKey policyTypeKey) throws PfModelException { return getDummyResponse("src/main/resources/dummyimpl/DummyToscaPolicyTypeGetResponse.json"); } @Override - public ToscaServiceTemplate createPolicyTypes(@NonNull ToscaServiceTemplate serviceTemplate) + public ToscaServiceTemplate createPolicyTypes(@NonNull final ToscaServiceTemplate serviceTemplate) throws PfModelException { return serviceTemplate; } @Override - public ToscaServiceTemplate updatePolicyTypes(@NonNull ToscaServiceTemplate serviceTemplate) + public ToscaServiceTemplate updatePolicyTypes(@NonNull final ToscaServiceTemplate serviceTemplate) throws PfModelException { return serviceTemplate; } @Override - public ToscaServiceTemplate deletePolicyTypes(@NonNull PfConceptKey policyTypeKey) throws PfModelException { + public ToscaServiceTemplate deletePolicyTypes(@NonNull final PfConceptKey policyTypeKey) throws PfModelException { return getDummyResponse("src/main/resources/dummyimpl/DummyToscaPolicyTypeDeleteResponse.json"); } @Override - public ToscaServiceTemplate getPolicies(@NonNull PfConceptKey policyKey) throws PfModelException { + public ToscaServiceTemplate getPolicies(@NonNull final PfConceptKey policyKey) throws PfModelException { return getDummyResponse("src/main/resources/dummyimpl/DummyToscaPolicyGetResponse.json"); } @Override - public ToscaServiceTemplate createPolicies(@NonNull ToscaServiceTemplate serviceTemplate) throws PfModelException { + public ToscaServiceTemplate createPolicies(@NonNull final ToscaServiceTemplate serviceTemplate) + throws PfModelException { return serviceTemplate; } @Override - public ToscaServiceTemplate updatePolicies(@NonNull ToscaServiceTemplate serviceTemplate) throws PfModelException { + public ToscaServiceTemplate updatePolicies(@NonNull final ToscaServiceTemplate serviceTemplate) + throws PfModelException { return serviceTemplate; } @Override - public ToscaServiceTemplate deletePolicies(@NonNull PfConceptKey policyKey) throws PfModelException { + public ToscaServiceTemplate deletePolicies(@NonNull final PfConceptKey policyKey) throws PfModelException { return getDummyResponse("src/main/resources/dummyimpl/DummyToscaPolicyDeleteResponse.json"); } @Override - public LegacyOperationalPolicy getOperationalPolicy(@NonNull String policyId) throws PfModelException { + + public LegacyOperationalPolicy getOperationalPolicy(@NonNull final String policyId) throws PfModelException { return new LegacyOperationalPolicy(); } @Override - public LegacyOperationalPolicy createOperationalPolicy(@NonNull LegacyOperationalPolicy legacyOperationalPolicy) - throws PfModelException { + public LegacyOperationalPolicy createOperationalPolicy( + @NonNull final LegacyOperationalPolicy legacyOperationalPolicy) throws PfModelException { return legacyOperationalPolicy; } @Override - public LegacyOperationalPolicy updateOperationalPolicy(@NonNull LegacyOperationalPolicy legacyOperationalPolicy) - throws PfModelException { + public LegacyOperationalPolicy updateOperationalPolicy( + @NonNull final LegacyOperationalPolicy legacyOperationalPolicy) throws PfModelException { return legacyOperationalPolicy; } @Override - public LegacyOperationalPolicy deleteOperationalPolicy(@NonNull String policyId) throws PfModelException { + public LegacyOperationalPolicy deleteOperationalPolicy(@NonNull final String policyId) throws PfModelException { return new LegacyOperationalPolicy(); } @Override - public LegacyGuardPolicy getGuardPolicy(@NonNull String policyId) throws PfModelException { + public LegacyGuardPolicy getGuardPolicy(@NonNull final String policyId) throws PfModelException { return new LegacyGuardPolicy(); } @Override - public LegacyGuardPolicy createGuardPolicy(@NonNull LegacyGuardPolicy legacyGuardPolicy) throws PfModelException { + public LegacyGuardPolicy createGuardPolicy(@NonNull final LegacyGuardPolicy legacyGuardPolicy) + throws PfModelException { return legacyGuardPolicy; } @Override - public LegacyGuardPolicy updateGuardPolicy(@NonNull LegacyGuardPolicy legacyGuardPolicy) throws PfModelException { + public LegacyGuardPolicy updateGuardPolicy(@NonNull final LegacyGuardPolicy legacyGuardPolicy) + throws PfModelException { return legacyGuardPolicy; } @Override - public LegacyGuardPolicy deleteGuardPolicy(@NonNull String policyId) throws PfModelException { + public LegacyGuardPolicy deleteGuardPolicy(@NonNull final String policyId) throws PfModelException { return new LegacyGuardPolicy(); } @Override - public Object getPdpGroups(@NonNull Object somePdpGroupFilter) throws PfModelException { - return null; + public PdpGroups getPdpGroups(@NonNull String pdpGroupFilter) throws PfModelException { + return new PdpGroups(); } @Override - public Object createPdpGroups(@NonNull Object somePdpGroupSpecification) throws PfModelException { - return null; + public PdpGroups createPdpGroups(@NonNull PdpGroups pdpGroups) throws PfModelException { + return new PdpGroups(); } @Override - public Object updatePdpGroups(@NonNull Object somePdpGroupSpecification) throws PfModelException { - return null; + public PdpGroups updatePdpGroups(@NonNull PdpGroups pdpGroups) throws PfModelException { + return new PdpGroups(); } @Override - public Object deletePdpGroups(@NonNull Object somePdpGroupFilter) throws PfModelException { - return null; + public PdpGroups deletePdpGroups(@NonNull String pdpGroupFilter) throws PfModelException { + return new PdpGroups(); } /** @@ -153,7 +177,7 @@ public class DummyPolicyModelsProviderImpl implements PolicyModelsProvider { * @param fileName the file name containing the dummy response * @return the ToscaServiceTemplate with the dummy response */ - private ToscaServiceTemplate getDummyResponse(@NonNull final String fileName) { + protected ToscaServiceTemplate getDummyResponse(@NonNull final String fileName) { Gson gson = new ToscaServiceTemplateMessageBodyHandler().getGson(); ToscaServiceTemplate serviceTemplate; |