Changed identifiers to concept identifiers
[policy/models.git] / models-provider / src / main / java / org / onap / policy / models / provider / impl / DatabasePolicyModelsProviderImpl.java
index f8ff4f3..c80ca31 100644 (file)
@@ -1,7 +1,8 @@
 /*-
  * ============LICENSE_START=======================================================
- *  Copyright (C) 2019-2020 Nordix Foundation.
+ *  Copyright (C) 2019-2021 Nordix Foundation.
  *  Modifications Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved.
+ *  Modifications Copyright (C) 2020 Bell Canada. All rights reserved.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
 
 package org.onap.policy.models.provider.impl;
 
-import java.util.Base64;
 import java.util.Date;
 import java.util.List;
 import java.util.Properties;
-
 import javax.ws.rs.core.Response;
-
 import lombok.NonNull;
-
 import org.eclipse.persistence.config.PersistenceUnitProperties;
 import org.onap.policy.models.base.PfModelException;
 import org.onap.policy.models.base.PfModelRuntimeException;
@@ -46,16 +43,14 @@ import org.onap.policy.models.pdp.persistence.provider.PdpProvider;
 import org.onap.policy.models.pdp.persistence.provider.PdpStatisticsProvider;
 import org.onap.policy.models.provider.PolicyModelsProvider;
 import org.onap.policy.models.provider.PolicyModelsProviderParameters;
+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.ToscaPolicyFilter;
-import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyIdentifier;
 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.ToscaPolicyTypeIdentifier;
 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.provider.AuthorativeToscaProvider;
-import org.onap.policy.models.tosca.legacy.concepts.LegacyOperationalPolicy;
-import org.onap.policy.models.tosca.legacy.provider.LegacyProvider;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -99,15 +94,12 @@ public class DatabasePolicyModelsProviderImpl implements PolicyModelsProvider {
         daoParameters.setPluginClass(DefaultPfDao.class.getName());
         daoParameters.setPersistenceUnit(parameters.getPersistenceUnit());
 
-        // Decode the password using Base64
-        String decodedPassword = new String(Base64.getDecoder().decode(getValue(parameters.getDatabasePassword())));
-
         // @formatter:off
         Properties jdbcProperties = new Properties();
         jdbcProperties.setProperty(PersistenceUnitProperties.JDBC_DRIVER,   parameters.getDatabaseDriver());
         jdbcProperties.setProperty(PersistenceUnitProperties.JDBC_URL,      parameters.getDatabaseUrl());
         jdbcProperties.setProperty(PersistenceUnitProperties.JDBC_USER,     parameters.getDatabaseUser());
-        jdbcProperties.setProperty(PersistenceUnitProperties.JDBC_PASSWORD, decodedPassword);
+        jdbcProperties.setProperty(PersistenceUnitProperties.JDBC_PASSWORD, parameters.getDatabasePassword());
         // @formatter:on
 
         daoParameters.setJdbcProperties(jdbcProperties);
@@ -124,13 +116,6 @@ public class DatabasePolicyModelsProviderImpl implements PolicyModelsProvider {
         }
     }
 
-    private String getValue(final String value) {
-        if (value != null && value.startsWith("${") && value.endsWith("}")) {
-            return System.getenv(value.substring(2, value.length() - 1));
-        }
-        return value;
-    }
-
     @Override
     public void close() throws PfModelException {
         LOGGER.debug("closing the database connection to {} using persistence unit {}", parameters.getDatabaseUrl(),
@@ -145,6 +130,43 @@ public class DatabasePolicyModelsProviderImpl implements PolicyModelsProvider {
                 parameters.getPersistenceUnit());
     }
 
+    @Override
+    public List<ToscaServiceTemplate> getServiceTemplateList(final String name, final String version)
+            throws PfModelException {
+        assertInitialized();
+        return new AuthorativeToscaProvider().getServiceTemplateList(pfDao, name, version);
+    }
+
+
+    @Override
+    public List<ToscaServiceTemplate> getFilteredServiceTemplateList(@NonNull ToscaServiceTemplateFilter filter)
+            throws PfModelException {
+        assertInitialized();
+        return new AuthorativeToscaProvider().getFilteredServiceTemplateList(pfDao, filter);
+    }
+
+    @Override
+    public ToscaServiceTemplate createServiceTemplate(@NonNull final ToscaServiceTemplate serviceTemplate)
+            throws PfModelException {
+        assertInitialized();
+        return new AuthorativeToscaProvider().createServiceTemplate(pfDao, serviceTemplate);
+    }
+
+    @Override
+    public ToscaServiceTemplate updateServiceTemplate(@NonNull final ToscaServiceTemplate serviceTemplate)
+            throws PfModelException {
+        assertInitialized();
+        return new AuthorativeToscaProvider().updateServiceTemplate(pfDao, serviceTemplate);
+    }
+
+    @Override
+    public ToscaServiceTemplate deleteServiceTemplate(@NonNull final String name, @NonNull final String version)
+            throws PfModelException {
+        assertInitialized();
+
+        return new AuthorativeToscaProvider().deleteServiceTemplate(pfDao, name, version);
+    }
+
     @Override
     public ToscaServiceTemplate getPolicyTypes(final String name, final String version) throws PfModelException {
         assertInitialized();
@@ -189,7 +211,7 @@ public class DatabasePolicyModelsProviderImpl implements PolicyModelsProvider {
             throws PfModelException {
         assertInitialized();
 
-        ToscaPolicyTypeIdentifier policyTypeIdentifier = new ToscaPolicyTypeIdentifier(name, version);
+        ToscaConceptIdentifier policyTypeIdentifier = new ToscaConceptIdentifier(name, version);
         assertPolicyTypeNotSupportedInPdpGroup(policyTypeIdentifier);
 
         return new AuthorativeToscaProvider().deletePolicyType(pfDao, name, version);
@@ -238,44 +260,12 @@ public class DatabasePolicyModelsProviderImpl implements PolicyModelsProvider {
             throws PfModelException {
         assertInitialized();
 
-        ToscaPolicyIdentifier policyIdentifier = new ToscaPolicyIdentifier(name, version);
+        ToscaConceptIdentifier policyIdentifier = new ToscaConceptIdentifier(name, version);
         assertPolicyNotDeployedInPdpGroup(policyIdentifier);
 
         return new AuthorativeToscaProvider().deletePolicy(pfDao, name, version);
     }
 
-    @Override
-    public LegacyOperationalPolicy getOperationalPolicy(@NonNull final String policyId, final String policyVersion)
-            throws PfModelException {
-        assertInitialized();
-        return new LegacyProvider().getOperationalPolicy(pfDao, policyId, policyVersion);
-    }
-
-    @Override
-    public LegacyOperationalPolicy createOperationalPolicy(
-            @NonNull final LegacyOperationalPolicy legacyOperationalPolicy) throws PfModelException {
-        assertInitialized();
-        return new LegacyProvider().createOperationalPolicy(pfDao, legacyOperationalPolicy);
-    }
-
-    @Override
-    public LegacyOperationalPolicy updateOperationalPolicy(
-            @NonNull final LegacyOperationalPolicy legacyOperationalPolicy) throws PfModelException {
-        assertInitialized();
-        return new LegacyProvider().updateOperationalPolicy(pfDao, legacyOperationalPolicy);
-    }
-
-    @Override
-    public LegacyOperationalPolicy deleteOperationalPolicy(@NonNull final String policyId,
-            @NonNull final String policyVersion) throws PfModelException {
-        assertInitialized();
-
-        assertPolicyNotDeployedInPdpGroup(
-                new ToscaPolicyIdentifier(policyId, policyVersion + LegacyProvider.LEGACY_MINOR_PATCH_SUFFIX));
-
-        return new LegacyProvider().deleteOperationalPolicy(pfDao, policyId, policyVersion);
-    }
-
     @Override
     public List<PdpGroup> getPdpGroups(final String name) throws PfModelException {
         assertInitialized();
@@ -372,7 +362,7 @@ public class DatabasePolicyModelsProviderImpl implements PolicyModelsProvider {
      * @param policyTypeIdentifier the policy type identifier
      * @throws PfModelException if the policy type is supported in a PDP group
      */
-    private void assertPolicyTypeNotSupportedInPdpGroup(ToscaPolicyTypeIdentifier policyTypeIdentifier)
+    private void assertPolicyTypeNotSupportedInPdpGroup(ToscaConceptIdentifier policyTypeIdentifier)
             throws PfModelException {
         for (PdpGroup pdpGroup : getPdpGroups(null)) {
             for (PdpSubGroup pdpSubGroup : pdpGroup.getPdpSubgroups()) {
@@ -391,7 +381,7 @@ public class DatabasePolicyModelsProviderImpl implements PolicyModelsProvider {
      * @param policyIdentifier the identifier of the policy
      * @throws PfModelException thrown if the policy is deployed in a PDP group
      */
-    private void assertPolicyNotDeployedInPdpGroup(final ToscaPolicyIdentifier policyIdentifier)
+    private void assertPolicyNotDeployedInPdpGroup(final ToscaConceptIdentifier policyIdentifier)
             throws PfModelException {
         for (PdpGroup pdpGroup : getPdpGroups(null)) {
             for (PdpSubGroup pdpSubGroup : pdpGroup.getPdpSubgroups()) {