aboutsummaryrefslogtreecommitdiffstats
path: root/model/model-api/src
diff options
context:
space:
mode:
Diffstat (limited to 'model/model-api/src')
-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
-rw-r--r--model/model-api/src/test/java/org/onap/policy/apex/model/modelapi/ApexModelApiTest.java36
-rw-r--r--model/model-api/src/test/java/org/onap/policy/apex/model/modelapi/ModelHandlerFacadeTest.java13
-rw-r--r--model/model-api/src/test/resources/META-INF/persistence.xml67
6 files changed, 9 insertions, 271 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
diff --git a/model/model-api/src/test/java/org/onap/policy/apex/model/modelapi/ApexModelApiTest.java b/model/model-api/src/test/java/org/onap/policy/apex/model/modelapi/ApexModelApiTest.java
index a4b42276a..132864bc9 100644
--- a/model/model-api/src/test/java/org/onap/policy/apex/model/modelapi/ApexModelApiTest.java
+++ b/model/model-api/src/test/java/org/onap/policy/apex/model/modelapi/ApexModelApiTest.java
@@ -1,7 +1,7 @@
/*
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
- * Modifications Copyright (C) 2020 Nordix Foundation.
+ * Modifications Copyright (C) 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.
@@ -34,7 +34,6 @@ import java.util.UUID;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
-import org.onap.policy.apex.model.basicmodel.dao.DaoParameters;
import org.onap.policy.apex.model.modelapi.impl.ApexModelImpl;
import org.onap.policy.common.utils.resources.TextFileUtils;
@@ -109,39 +108,6 @@ public class ApexModelApiTest {
}
@Test
- public void testApexModelDatabase() throws IOException {
- final ApexModel apexModel = new ApexModelFactory().createApexModel(null, false);
-
- ApexApiResult result = apexModel.loadFromFile("src/test/resources/models/PolicyModel.json");
- assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
-
- final DaoParameters DaoParameters = new DaoParameters();
- DaoParameters.setPluginClass("org.onap.policy.apex.model.basicmodel.dao.impl.DefaultApexDao");
- DaoParameters.setPersistenceUnit("DAOTest");
-
- result = apexModel.saveToDatabase(DaoParameters);
- assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
-
- result = apexModel.deleteModel();
- assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
-
- result = apexModel.loadFromDatabase("PolicyModel", "0.0.1", DaoParameters);
- assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
-
- result = apexModel.deleteModel();
- assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
-
- result = apexModel.loadFromDatabase("PolicyModel", null, DaoParameters);
- assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
-
- result = apexModel.deleteModel();
- assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
-
- result = apexModel.loadFromDatabase("VPNPolicyModel", "0.0.1", DaoParameters);
- assertEquals(ApexApiResult.Result.FAILED, result.getResult());
- }
-
- @Test
public void testApexModelUrl() throws IOException {
final ApexModel apexModel = new ApexModelFactory().createApexModel(null, false);
diff --git a/model/model-api/src/test/java/org/onap/policy/apex/model/modelapi/ModelHandlerFacadeTest.java b/model/model-api/src/test/java/org/onap/policy/apex/model/modelapi/ModelHandlerFacadeTest.java
index 4a1c3276c..e43e5896b 100644
--- a/model/model-api/src/test/java/org/onap/policy/apex/model/modelapi/ModelHandlerFacadeTest.java
+++ b/model/model-api/src/test/java/org/onap/policy/apex/model/modelapi/ModelHandlerFacadeTest.java
@@ -1,7 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
- * Modifications Copyright (C) 2020 Nordix Foundation.
+ * Modifications Copyright (C) 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.
@@ -29,7 +29,6 @@ import java.io.File;
import java.io.IOException;
import java.util.Properties;
import org.junit.Test;
-import org.onap.policy.apex.model.basicmodel.dao.DaoParameters;
import org.onap.policy.apex.model.modelapi.impl.ModelHandlerFacade;
import org.onap.policy.common.utils.resources.TextFileUtils;
@@ -69,19 +68,9 @@ public class ModelHandlerFacadeTest {
result = mhf.loadFromString(modelString);
assertEquals(ApexApiResult.Result.CONCEPT_EXISTS, result.getResult());
- final DaoParameters DaoParameters = new DaoParameters();
- result = mhf.loadFromDatabase("SomeModel", null, DaoParameters);
- assertEquals(ApexApiResult.Result.CONCEPT_EXISTS, result.getResult());
-
result = apexModel.deleteModel();
assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
- result = mhf.loadFromDatabase("SomeModel", null, DaoParameters);
- assertEquals(ApexApiResult.Result.FAILED, result.getResult());
-
- result = mhf.saveToDatabase(DaoParameters);
- assertEquals(ApexApiResult.Result.FAILED, result.getResult());
-
result = mhf.readFromUrl("blah://somewhere/over/the/rainbow");
assertEquals(ApexApiResult.Result.FAILED, result.getResult());
diff --git a/model/model-api/src/test/resources/META-INF/persistence.xml b/model/model-api/src/test/resources/META-INF/persistence.xml
deleted file mode 100644
index 2603d5496..000000000
--- a/model/model-api/src/test/resources/META-INF/persistence.xml
+++ /dev/null
@@ -1,67 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
- ============LICENSE_START=======================================================
- Copyright (C) 2016-2018 Ericsson. 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.
- 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=========================================================
--->
-
-<persistence xmlns="http://java.sun.com/xml/ns/persistence" version="2.0">
- <persistence-unit name="DAOTest" transaction-type="RESOURCE_LOCAL">
- <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
-
- <class>org.onap.policy.apex.model.basicmodel.dao.converters.CDataConditioner</class>
- <class>org.onap.policy.apex.model.basicmodel.dao.converters.Uuid2String</class>
- <class>org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey</class>
- <class>org.onap.policy.apex.model.basicmodel.concepts.AxConcept</class>
- <class>org.onap.policy.apex.model.basicmodel.concepts.AxKeyInfo</class>
- <class>org.onap.policy.apex.model.basicmodel.concepts.AxKeyInformation</class>
- <class>org.onap.policy.apex.model.basicmodel.concepts.AxModel</class>
- <class>org.onap.policy.apex.model.basicmodel.concepts.TestEntity</class>
- <class>org.onap.policy.apex.model.contextmodel.concepts.AxContextSchema</class>
- <class>org.onap.policy.apex.model.contextmodel.concepts.AxContextSchemas</class>
- <class>org.onap.policy.apex.model.contextmodel.concepts.AxContextAlbum</class>
- <class>org.onap.policy.apex.model.contextmodel.concepts.AxContextAlbums</class>
- <class>org.onap.policy.apex.model.contextmodel.concepts.AxContextModel</class>
- <class>org.onap.policy.apex.model.eventmodel.concepts.AxField</class>
- <class>org.onap.policy.apex.model.eventmodel.concepts.AxInputField</class>
- <class>org.onap.policy.apex.model.eventmodel.concepts.AxOutputField</class>
- <class>org.onap.policy.apex.model.eventmodel.concepts.AxEvent</class>
- <class>org.onap.policy.apex.model.eventmodel.concepts.AxEvents</class>
- <class>org.onap.policy.apex.model.eventmodel.concepts.AxEventModel</class>
- <class>org.onap.policy.apex.model.policymodel.concepts.AxLogic</class>
- <class>org.onap.policy.apex.model.policymodel.concepts.AxTaskParameter</class>
- <class>org.onap.policy.apex.model.policymodel.concepts.AxTaskLogic</class>
- <class>org.onap.policy.apex.model.policymodel.concepts.AxTask</class>
- <class>org.onap.policy.apex.model.policymodel.concepts.AxTasks</class>
- <class>org.onap.policy.apex.model.policymodel.concepts.AxTaskSelectionLogic</class>
- <class>org.onap.policy.apex.model.policymodel.concepts.AxStateFinalizerLogic</class>
- <class>org.onap.policy.apex.model.policymodel.concepts.AxStateOutput</class>
- <class>org.onap.policy.apex.model.policymodel.concepts.AxStateTaskReference</class>
- <class>org.onap.policy.apex.model.policymodel.concepts.AxState</class>
- <class>org.onap.policy.apex.model.policymodel.concepts.AxPolicy</class>
- <class>org.onap.policy.apex.model.policymodel.concepts.AxPolicies</class>
- <class>org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel</class>
-
- <properties>
- <property name="javax.persistence.jdbc.url" value="jdbc:h2:mem:testdb" />
- <property name="javax.persistence.jdbc.driver" value="org.h2.Driver" />
- <property name="eclipselink.ddl-generation" value="create-or-extend-tables" />
- <property name="eclipselink.ddl-generation.output-mode" value="database" />
- <property name="eclipselink.logging.level" value="INFO" />
- </properties>
- </persistence-unit>
-</persistence>