aboutsummaryrefslogtreecommitdiffstats
path: root/models-dao
diff options
context:
space:
mode:
Diffstat (limited to 'models-dao')
-rw-r--r--models-dao/src/main/java/org/onap/policy/models/dao/DaoParameters.java2
-rw-r--r--models-dao/src/main/java/org/onap/policy/models/dao/PfDaoFactory.java8
-rw-r--r--models-dao/src/main/java/org/onap/policy/models/dao/converters/CDataConditioner.java2
-rw-r--r--models-dao/src/main/java/org/onap/policy/models/dao/converters/Uuid2String.java4
-rw-r--r--models-dao/src/main/java/org/onap/policy/models/dao/converters/package-info.java2
-rw-r--r--models-dao/src/main/java/org/onap/policy/models/dao/impl/DefaultPfDao.java12
-rw-r--r--models-dao/src/main/java/org/onap/policy/models/dao/impl/package-info.java2
-rw-r--r--models-dao/src/main/java/org/onap/policy/models/dao/package-info.java6
-rw-r--r--models-dao/src/test/java/org/onap/policy/models/dao/converters/CDataConditionerTest.java41
-rw-r--r--models-dao/src/test/java/org/onap/policy/models/dao/converters/Uuid2StringConditionerTest.java44
10 files changed, 112 insertions, 11 deletions
diff --git a/models-dao/src/main/java/org/onap/policy/models/dao/DaoParameters.java b/models-dao/src/main/java/org/onap/policy/models/dao/DaoParameters.java
index 18ae74ae1..a6b6f2f2e 100644
--- a/models-dao/src/main/java/org/onap/policy/models/dao/DaoParameters.java
+++ b/models-dao/src/main/java/org/onap/policy/models/dao/DaoParameters.java
@@ -24,6 +24,8 @@ import java.util.Properties;
/**
* This class is a POJO that holds properties for PF DAOs.
+ *
+ * @author Liam Fallon (liam.fallon@est.tech)
*/
public class DaoParameters {
/** The default PF DAO plugin class. */
diff --git a/models-dao/src/main/java/org/onap/policy/models/dao/PfDaoFactory.java b/models-dao/src/main/java/org/onap/policy/models/dao/PfDaoFactory.java
index 3b7e31eb8..6b7c7b3ad 100644
--- a/models-dao/src/main/java/org/onap/policy/models/dao/PfDaoFactory.java
+++ b/models-dao/src/main/java/org/onap/policy/models/dao/PfDaoFactory.java
@@ -20,6 +20,8 @@
package org.onap.policy.models.dao;
+import javax.ws.rs.core.Response;
+
import org.onap.policy.common.utils.validation.Assertions;
import org.onap.policy.models.base.PfModelException;
import org.slf4j.Logger;
@@ -28,6 +30,8 @@ import org.slf4j.LoggerFactory;
/**
* This factory class returns a Policy Framework DAO for the configured persistence mechanism. The
* factory uses the plugin class specified in {@link DaoParameters} to instantiate a DAO instance.
+ *
+ * @author Liam Fallon (liam.fallon@est.tech)
*/
public class PfDaoFactory {
// Get a reference to the logger
@@ -52,7 +56,7 @@ public class PfDaoFactory {
String errorMessage =
"Policy Framework DAO class not found for DAO plugin \"" + daoParameters.getPluginClass() + "\"";
LOGGER.error(errorMessage, e);
- throw new PfModelException(errorMessage, e);
+ throw new PfModelException(Response.Status.INTERNAL_SERVER_ERROR, errorMessage, e);
}
// Check the class is a Policy Framework DAO
@@ -60,7 +64,7 @@ public class PfDaoFactory {
String errorMessage = "Specified DAO plugin class \"" + daoParameters.getPluginClass()
+ "\" does not implement the PfDao interface";
LOGGER.error(errorMessage);
- throw new PfModelException(errorMessage);
+ throw new PfModelException(Response.Status.INTERNAL_SERVER_ERROR, errorMessage);
}
return (PfDao) pfDaoObject;
diff --git a/models-dao/src/main/java/org/onap/policy/models/dao/converters/CDataConditioner.java b/models-dao/src/main/java/org/onap/policy/models/dao/converters/CDataConditioner.java
index 327f65ece..e4cfd74d3 100644
--- a/models-dao/src/main/java/org/onap/policy/models/dao/converters/CDataConditioner.java
+++ b/models-dao/src/main/java/org/onap/policy/models/dao/converters/CDataConditioner.java
@@ -25,7 +25,7 @@ import javax.persistence.Converter;
import javax.xml.bind.annotation.adapters.XmlAdapter;
/**
- * The Class CDATAConditioner converts a CDATA String to and from database format by removing spaces
+ * The Class CDataConditioner converts a CDATA String to and from database format by removing spaces
* at the ends of lines and platform-specific new line endings.
*/
@Converter
diff --git a/models-dao/src/main/java/org/onap/policy/models/dao/converters/Uuid2String.java b/models-dao/src/main/java/org/onap/policy/models/dao/converters/Uuid2String.java
index a2b1c085a..369b5a19d 100644
--- a/models-dao/src/main/java/org/onap/policy/models/dao/converters/Uuid2String.java
+++ b/models-dao/src/main/java/org/onap/policy/models/dao/converters/Uuid2String.java
@@ -27,7 +27,9 @@ import javax.persistence.Converter;
import javax.xml.bind.annotation.adapters.XmlAdapter;
/**
- * The Class UUIDConverter converts a UUID to and from database format.
+ * The Class UuidConverter converts a UUID to and from database format.
+ *
+ * @author Liam Fallon (liam.fallon@est.tech)
*/
@Converter
public class Uuid2String extends XmlAdapter<String, UUID> implements AttributeConverter<UUID, String> {
diff --git a/models-dao/src/main/java/org/onap/policy/models/dao/converters/package-info.java b/models-dao/src/main/java/org/onap/policy/models/dao/converters/package-info.java
index 416eff20c..184f59b0e 100644
--- a/models-dao/src/main/java/org/onap/policy/models/dao/converters/package-info.java
+++ b/models-dao/src/main/java/org/onap/policy/models/dao/converters/package-info.java
@@ -21,6 +21,8 @@
/**
* Contains converters used by PF EclipseLink marshaling and unmarshaling of
* {@link org.onap.policy.models.base.PfConcept} instances to and from files and databases.
+ *
+ * @author Liam Fallon (liam.fallon@est.tech)
*/
package org.onap.policy.models.dao.converters;
diff --git a/models-dao/src/main/java/org/onap/policy/models/dao/impl/DefaultPfDao.java b/models-dao/src/main/java/org/onap/policy/models/dao/impl/DefaultPfDao.java
index 429632db0..947b866a1 100644
--- a/models-dao/src/main/java/org/onap/policy/models/dao/impl/DefaultPfDao.java
+++ b/models-dao/src/main/java/org/onap/policy/models/dao/impl/DefaultPfDao.java
@@ -27,6 +27,7 @@ import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
+import javax.ws.rs.core.Response;
import org.onap.policy.models.base.PfConcept;
import org.onap.policy.models.base.PfConceptKey;
@@ -61,7 +62,8 @@ public class DefaultPfDao implements PfDao {
public void init(final DaoParameters daoParameters) throws PfModelException {
if (daoParameters == null || daoParameters.getPersistenceUnit() == null) {
LOGGER.error("Policy Framework persistence unit parameter not set");
- throw new PfModelException("Policy Framework persistence unit parameter not set");
+ throw new PfModelException(Response.Status.INTERNAL_SERVER_ERROR,
+ "Policy Framework persistence unit parameter not set");
}
LOGGER.debug("Creating Policy Framework persistence unit \"{}\" . . .", daoParameters.getPersistenceUnit());
@@ -72,7 +74,7 @@ public class DefaultPfDao implements PfDao {
String errorMessage = "Creation of Policy Framework persistence unit \""
+ daoParameters.getPersistenceUnit() + "\" failed";
LOGGER.warn(errorMessage, ex);
- throw new PfModelException(errorMessage, ex);
+ throw new PfModelException(Response.Status.INTERNAL_SERVER_ERROR, errorMessage, ex);
}
LOGGER.debug("Created Policy Framework persistence unit \"{}\"", daoParameters.getPersistenceUnit());
}
@@ -85,7 +87,8 @@ public class DefaultPfDao implements PfDao {
protected final synchronized EntityManager getEntityManager() {
if (emf == null) {
LOGGER.warn("Policy Framework DAO has not been initialized");
- throw new PfModelRuntimeException("Policy Framework DAO has not been initialized");
+ throw new PfModelRuntimeException(Response.Status.INTERNAL_SERVER_ERROR,
+ "Policy Framework DAO has not been initialized");
}
return emf.createEntityManager();
@@ -196,8 +199,7 @@ public class DefaultPfDao implements PfDao {
}
@Override
- public <T extends PfConcept> int deleteByConceptKey(final Class<T> someClass,
- final Collection<PfConceptKey> keys) {
+ public <T extends PfConcept> int deleteByConceptKey(final Class<T> someClass, final Collection<PfConceptKey> keys) {
if (keys == null || keys.isEmpty()) {
return 0;
}
diff --git a/models-dao/src/main/java/org/onap/policy/models/dao/impl/package-info.java b/models-dao/src/main/java/org/onap/policy/models/dao/impl/package-info.java
index 0d27628a0..f62116639 100644
--- a/models-dao/src/main/java/org/onap/policy/models/dao/impl/package-info.java
+++ b/models-dao/src/main/java/org/onap/policy/models/dao/impl/package-info.java
@@ -21,5 +21,7 @@
/**
* Contains a default DAO implementation for the PF {@link org.onap.policy.models.base.PfConcept}
* classes that uses javax persistence.
+ *
+ * @author Liam Fallon (liam.fallon@est.tech)
*/
package org.onap.policy.models.dao.impl;
diff --git a/models-dao/src/main/java/org/onap/policy/models/dao/package-info.java b/models-dao/src/main/java/org/onap/policy/models/dao/package-info.java
index e8cfbe4e7..c4cb6a265 100644
--- a/models-dao/src/main/java/org/onap/policy/models/dao/package-info.java
+++ b/models-dao/src/main/java/org/onap/policy/models/dao/package-info.java
@@ -19,9 +19,11 @@
*/
/**
- * Defines and implements the Data Access Object (DAO) that allows Apex
- * {@link org.onap.policy.apex.model.basicmodel.concepts.AxConcept} concepts to be read from and written to databases
+ * Defines and implements the Data Access Object (DAO) that allows Policy Framework
+ * {@link org.onap.policy.models.base.pfConcept} concepts to be read from and written to databases
* over JDBC.
+ *
+ * @author Liam Fallon (liam.fallon@est.tech)
*/
package org.onap.policy.models.dao;
diff --git a/models-dao/src/test/java/org/onap/policy/models/dao/converters/CDataConditionerTest.java b/models-dao/src/test/java/org/onap/policy/models/dao/converters/CDataConditionerTest.java
new file mode 100644
index 000000000..60a42c299
--- /dev/null
+++ b/models-dao/src/test/java/org/onap/policy/models/dao/converters/CDataConditionerTest.java
@@ -0,0 +1,41 @@
+/*-
+ * ============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.dao.converters;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+
+/**
+ * Test the CDataConditioner Class.
+ *
+ * @author Liam Fallon (liam.fallon@est.tech)
+ */
+public class CDataConditionerTest {
+
+ @Test
+ public void testCDataConditioner() throws Exception {
+ assertEquals("Raw", new CDataConditioner().convertToDatabaseColumn("Raw"));
+ assertEquals("entityAttribute", new CDataConditioner().convertToEntityAttribute("entityAttribute"));
+ assertEquals("marshal", new CDataConditioner().marshal("marshal"));
+ assertEquals("unmarshal", new CDataConditioner().unmarshal("unmarshal"));
+ }
+}
diff --git a/models-dao/src/test/java/org/onap/policy/models/dao/converters/Uuid2StringConditionerTest.java b/models-dao/src/test/java/org/onap/policy/models/dao/converters/Uuid2StringConditionerTest.java
new file mode 100644
index 000000000..771f0fb65
--- /dev/null
+++ b/models-dao/src/test/java/org/onap/policy/models/dao/converters/Uuid2StringConditionerTest.java
@@ -0,0 +1,44 @@
+/*-
+ * ============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.dao.converters;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.UUID;
+
+import org.junit.Test;
+
+/**
+ * Test the UUID conditioner class.
+ *
+ * @author Liam Fallon (liam.fallon@est.tech)
+ */
+public class Uuid2StringConditionerTest {
+
+ @Test
+ public void testUuidConditioner() throws Exception {
+ UUID randomUuid = UUID.randomUUID();
+ assertEquals(randomUuid.toString(), new Uuid2String().convertToDatabaseColumn(randomUuid));
+ assertEquals(randomUuid, new Uuid2String().convertToEntityAttribute(randomUuid.toString()));
+ assertEquals(randomUuid.toString(), new Uuid2String().marshal(randomUuid));
+ assertEquals(randomUuid, new Uuid2String().unmarshal(randomUuid.toString()));
+ }
+}