aboutsummaryrefslogtreecommitdiffstats
path: root/model/model-api/src/main
diff options
context:
space:
mode:
authorliamfallon <liam.fallon@est.tech>2022-02-03 12:01:57 +0000
committerliamfallon <liam.fallon@est.tech>2022-02-03 12:02:01 +0000
commitde18be8467912348ea73c7f5557397bab9ba86b3 (patch)
tree0dc1ea0d7e6612aace7bc42225a86fa32192ef25 /model/model-api/src/main
parent47847dc47c42325ed416d59b1f6b9087733db92f (diff)
Remove direct DB Load/Save from apex-pdp
This review is part of a series of reviews to move the apex-pdp state machine model to use the base model types in policy models. Persistence of policies for apex-pdp is now implemented in PAP and API. The historic direct load and save functionality for APEX policy state machine models to and from databases is no longer used and no longer supported. This revmoves the DAO code from apex-pdp and the associated handling and test code. The next review will remove the JPA annotations. Subsequent reviews will mvoe the mdoel across to use the policy models base model types. Issue-ID: POLICY-1820 Change-Id: Iabf034b40a413d32fe62091fe3446f52ec30d3af Signed-off-by: liamfallon <liam.fallon@est.tech>
Diffstat (limited to 'model/model-api/src/main')
-rw-r--r--model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/ApexModel.java27
-rw-r--r--model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/impl/ApexModelImpl.java22
-rw-r--r--model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/impl/ModelHandlerFacade.java115
3 files changed, 7 insertions, 157 deletions
diff --git a/model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/ApexModel.java b/model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/ApexModel.java
index 6c37e453c..d721e33fd 100644
--- a/model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/ApexModel.java
+++ b/model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/ApexModel.java
@@ -1,26 +1,26 @@
/*
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
+ * Modifications Copyright (C) 2022 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.apex.model.modelapi;
-import org.onap.policy.apex.model.basicmodel.dao.DaoParameters;
import org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel;
/**
@@ -62,25 +62,6 @@ public interface ApexModel extends ApexEditorApi {
ApexApiResult saveToFile(String fileName, boolean xmlFlag);
/**
- * Load an Apex model from a database.
- *
- * @param modelName the name of the model to load
- * @param modelVersion the version of the model to load, loads the policy model from the database with this name, if
- * more than one exist, an exception is thrown
- * @param daoParameters the parameters to use to access the database over JDBC
- * @return the result of the operation
- */
- ApexApiResult loadFromDatabase(String modelName, String modelVersion, DaoParameters daoParameters);
-
- /**
- * Save an Apex model to a database.
- *
- * @param daoParameters the parameters to use to access the database over JDBC
- * @return the result of the operation
- */
- ApexApiResult saveToDatabase(DaoParameters daoParameters);
-
- /**
* Read an APEX model from a location identified by a URL.
*
* @param urlString the url string
diff --git a/model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/impl/ApexModelImpl.java b/model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/impl/ApexModelImpl.java
index cca9d3454..944d95f2b 100644
--- a/model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/impl/ApexModelImpl.java
+++ b/model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/impl/ApexModelImpl.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
* Modifications Copyright (C) 2019 Samsung Electronics Co., Ltd.
- * Modifications Copyright (C) 2019 Nordix Foundation.
+ * Modifications Copyright (C) 2019,2022 Nordix Foundation.
* Modifications Copyright (C) 2022 Bell Canada. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -28,7 +28,6 @@ import lombok.AccessLevel;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
-import org.onap.policy.apex.model.basicmodel.dao.DaoParameters;
import org.onap.policy.apex.model.modelapi.ApexApiResult;
import org.onap.policy.apex.model.modelapi.ApexApiResult.Result;
import org.onap.policy.apex.model.modelapi.ApexModel;
@@ -792,23 +791,6 @@ public final class ApexModelImpl implements ApexModel {
* {@inheritDoc}.
*/
@Override
- public ApexApiResult loadFromDatabase(final String modelName, final String modelVersion,
- final DaoParameters daoParameters) {
- return modelHandlerFacade.loadFromDatabase(modelName, modelVersion, daoParameters);
- }
-
- /**
- * {@inheritDoc}.
- */
- @Override
- public ApexApiResult saveToDatabase(final DaoParameters daoParameters) {
- return modelHandlerFacade.saveToDatabase(daoParameters);
- }
-
- /**
- * {@inheritDoc}.
- */
- @Override
public ApexApiResult readFromUrl(final String urlString) {
return modelHandlerFacade.readFromUrl(urlString);
}
@@ -894,4 +876,4 @@ public final class ApexModelImpl implements ApexModel {
return policyModel;
}
-} \ No newline at end of file
+}
diff --git a/model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/impl/ModelHandlerFacade.java b/model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/impl/ModelHandlerFacade.java
index b350af527..9d03ba1e0 100644
--- a/model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/impl/ModelHandlerFacade.java
+++ b/model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/impl/ModelHandlerFacade.java
@@ -1,7 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
- * Modifications Copyright (C) 2019-2020 Nordix Foundation.
+ * Modifications Copyright (C) 2019-2020,2022 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,16 +30,11 @@ import java.net.URL;
import java.net.URLConnection;
import java.nio.file.Files;
import java.util.LinkedHashSet;
-import java.util.List;
import java.util.Properties;
import java.util.Set;
import org.onap.policy.apex.model.basicmodel.concepts.ApexException;
-import org.onap.policy.apex.model.basicmodel.concepts.ApexRuntimeException;
import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult;
-import org.onap.policy.apex.model.basicmodel.dao.ApexDao;
-import org.onap.policy.apex.model.basicmodel.dao.ApexDaoFactory;
-import org.onap.policy.apex.model.basicmodel.dao.DaoParameters;
import org.onap.policy.apex.model.basicmodel.handling.ApexModelException;
import org.onap.policy.apex.model.basicmodel.handling.ApexModelFileWriter;
import org.onap.policy.apex.model.basicmodel.handling.ApexModelReader;
@@ -66,7 +61,6 @@ import org.slf4j.ext.XLoggerFactory;
* @author Liam Fallon (liam.fallon@ericsson.com)
*/
public class ModelHandlerFacade {
- private static final String FOUND_IN_DATABASE = " found in database";
private static final String FILE_NAME_MAY_NOT_BE_NULL = "fileName may not be null";
private static final String MODEL = "model ";
private static final String ALREADY_LOADED = " already loaded";
@@ -161,113 +155,6 @@ public class ModelHandlerFacade {
}
/**
- * Load an Apex model from a database.
- *
- * @param modelName the name of the model to load
- * @param modelVersion the version of the model to load, loads the policy model from the database with this name, if
- * more than one exist, an exception is thrown
- * @param daoParameters the parameters to use to access the database over JDBC
- * @return the result of the operation
- */
- public ApexApiResult loadFromDatabase(final String modelName, final String modelVersion,
- final DaoParameters daoParameters) {
- Assertions.argumentNotNull(modelName, "modelName may not be null");
- Assertions.argumentNotNull(daoParameters, "DaoParameters may not be null");
-
- if (!apexModel.getPolicyModel().getKey().equals(AxArtifactKey.getNullKey())) {
- return new ApexApiResult(ApexApiResult.Result.CONCEPT_EXISTS,
- MODEL + apexModel.getPolicyModel().getKey().getId() + ALREADY_LOADED);
- }
-
- ApexDao apexDao = null;
- try {
- apexDao = new ApexDaoFactory().createApexDao(daoParameters);
- apexDao.init(daoParameters);
-
- // Single specific model requested
- if (modelVersion != null) {
- AxPolicyModel daoPolicyModel =
- apexDao.get(AxPolicyModel.class, new AxArtifactKey(modelName, modelVersion));
-
- if (daoPolicyModel != null) {
- apexModel.setPolicyModel(daoPolicyModel);
- return new ApexApiResult();
- } else {
- apexModel.setPolicyModel(new AxPolicyModel());
- return new ApexApiResult(ApexApiResult.Result.FAILED, "no policy model with name " + modelName
- + " and version " + modelVersion + FOUND_IN_DATABASE);
- }
- } else {
- // Fishing expedition
- return searchInDatabase(modelName, apexDao, apexModel);
- }
- } catch (ApexException | ApexRuntimeException e) {
- return new ApexApiResult(ApexApiResult.Result.FAILED, e);
- } finally {
- if (apexDao != null) {
- apexDao.close();
- }
- }
- }
-
- /**
- * Search for an Apex model in the database.
- *
- * @param modelName the name of the model to load
- * @param apexDao the DAO to use to find the model
- * @param apexModel the APEX model we are loading the found model into
- * @return the result of the operation
- */
- private ApexApiResult searchInDatabase(String modelName, ApexDao apexDao, ApexModel apexModel) {
- AxPolicyModel foundPolicyModel = null;
-
- List<AxPolicyModel> policyModelList = apexDao.getAll(AxPolicyModel.class);
- for (AxPolicyModel dbPolicyModel : policyModelList) {
- if (dbPolicyModel.getKey().getName().equals(modelName)) {
- if (foundPolicyModel == null) {
- foundPolicyModel = dbPolicyModel;
- } else {
- return new ApexApiResult(ApexApiResult.Result.FAILED,
- "more than one policy model with name " + modelName + FOUND_IN_DATABASE);
- }
- }
- }
-
- if (foundPolicyModel != null) {
- apexModel.setPolicyModel(foundPolicyModel);
- return new ApexApiResult();
- } else {
- apexModel.setPolicyModel(new AxPolicyModel());
- return new ApexApiResult(ApexApiResult.Result.FAILED,
- "no policy model with name " + modelName + FOUND_IN_DATABASE);
- }
- }
-
- /**
- * Save an Apex model to a database.
- *
- * @param daoParameters the parameters to use to access the database over JDBC
- * @return the result of the operation
- */
- public ApexApiResult saveToDatabase(final DaoParameters daoParameters) {
- ApexDao apexDao = null;
-
- try {
- apexDao = new ApexDaoFactory().createApexDao(daoParameters);
- apexDao.init(daoParameters);
-
- apexDao.create(apexModel.getPolicyModel());
- return new ApexApiResult();
- } catch (ApexException e) {
- return new ApexApiResult(ApexApiResult.Result.FAILED, e);
- } finally {
- if (apexDao != null) {
- apexDao.close();
- }
- }
- }
-
- /**
* Read an APEX model from a location identified by a URL.
*
* @param urlString the url string