From 87be30582d1db37bee7c6b456c0c5c3ca9584963 Mon Sep 17 00:00:00 2001 From: liamfallon Date: Tue, 4 Sep 2018 17:24:15 +0100 Subject: Fix checkstyle issues in apex model basic CHeckstyle issues in apex model basic and knock on changes in other apex modules. Issue-ID: POLICY-1034 Change-Id: I65823f5e2e344526abc74b0812877113acb056ec Signed-off-by: liamfallon --- .../basicmodel/concepts/ApexConceptException.java | 6 +- .../model/basicmodel/concepts/ApexException.java | 15 ++- .../basicmodel/concepts/ApexRuntimeException.java | 12 +- .../model/basicmodel/concepts/AxArtifactKey.java | 33 +++--- .../apex/model/basicmodel/concepts/AxConcept.java | 12 +- .../model/basicmodel/concepts/AxConceptGetter.java | 6 +- .../basicmodel/concepts/AxConceptGetterImpl.java | 6 +- .../apex/model/basicmodel/concepts/AxKey.java | 6 +- .../apex/model/basicmodel/concepts/AxKeyInfo.java | 30 ++--- .../basicmodel/concepts/AxKeyInformation.java | 22 ++-- .../apex/model/basicmodel/concepts/AxKeyUse.java | 10 +- .../apex/model/basicmodel/concepts/AxModel.java | 56 ++++----- .../model/basicmodel/concepts/AxReferenceKey.java | 25 +++-- .../basicmodel/concepts/AxValidationResult.java | 2 +- .../policy/apex/model/basicmodel/dao/ApexDao.java | 58 +++++----- .../apex/model/basicmodel/dao/ApexDaoFactory.java | 4 +- .../apex/model/basicmodel/dao/DAOParameters.java | 125 --------------------- .../apex/model/basicmodel/dao/DaoParameters.java | 125 +++++++++++++++++++++ .../dao/converters/CDATAConditioner.java | 91 --------------- .../dao/converters/CDataConditioner.java | 91 +++++++++++++++ .../basicmodel/dao/converters/UUID2String.java | 83 -------------- .../basicmodel/dao/converters/Uuid2String.java | 83 ++++++++++++++ .../model/basicmodel/dao/impl/DefaultApexDao.java | 124 ++++++++++---------- .../model/basicmodel/dao/impl/package-info.java | 3 +- .../apex/model/basicmodel/dao/package-info.java | 4 +- .../basicmodel/handling/ApexModelCreator.java | 3 +- .../basicmodel/handling/ApexModelException.java | 6 +- .../basicmodel/handling/ApexModelFileWriter.java | 14 +-- .../model/basicmodel/handling/ApexModelReader.java | 11 +- .../model/basicmodel/handling/ApexModelSaver.java | 16 +-- .../basicmodel/handling/ApexModelStringWriter.java | 20 ++-- .../model/basicmodel/handling/ApexModelWriter.java | 16 +-- .../basicmodel/handling/ApexSchemaGenerator.java | 38 +++---- .../policy/apex/model/basicmodel/package-info.java | 7 +- .../model/basicmodel/service/ModelService.java | 13 ++- .../apex/model/basicmodel/test/TestApexModel.java | 71 ++++++------ .../basicmodel/test/TestApexModelCreator.java | 4 +- 37 files changed, 625 insertions(+), 626 deletions(-) delete mode 100644 model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/dao/DAOParameters.java create mode 100644 model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/dao/DaoParameters.java delete mode 100644 model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/dao/converters/CDATAConditioner.java create mode 100644 model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/dao/converters/CDataConditioner.java delete mode 100644 model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/dao/converters/UUID2String.java create mode 100644 model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/dao/converters/Uuid2String.java (limited to 'model/basic-model/src/main/java/org') diff --git a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/concepts/ApexConceptException.java b/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/concepts/ApexConceptException.java index 1ffb2776c..d62818dc8 100644 --- a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/concepts/ApexConceptException.java +++ b/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/concepts/ApexConceptException.java @@ -41,9 +41,9 @@ public class ApexConceptException extends ApexException { * Instantiates a new apex concept exception. * * @param message the message on the exception - * @param e the exception that caused this Apex exception + * @param exception the exception that caused this Apex exception */ - public ApexConceptException(final String message, final Exception e) { - super(message, e); + public ApexConceptException(final String message, final Exception exception) { + super(message, exception); } } diff --git a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/concepts/ApexException.java b/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/concepts/ApexException.java index 94472d3eb..97920c3b5 100644 --- a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/concepts/ApexException.java +++ b/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/concepts/ApexException.java @@ -55,21 +55,21 @@ public class ApexException extends Exception { * Instantiates a new apex exception. * * @param message the message on the exception - * @param e the exception that caused this Apex exception + * @param exception the exception that caused this Apex exception */ - public ApexException(final String message, final Exception e) { - this(message, e, null); + public ApexException(final String message, final Exception exception) { + this(message, exception, null); } /** * Instantiates a new apex exception. * * @param message the message on the exception - * @param e the exception that caused this Apex exception + * @param exception the exception that caused this Apex exception * @param object the object that the exception was thrown on */ - public ApexException(final String message, final Exception e, final Object object) { - super(message, e); + public ApexException(final String message, final Exception exception, final Object object) { + super(message, exception); this.object = object; } @@ -83,7 +83,7 @@ public class ApexException extends Exception { } /** - * Build a cascaded message from an exception and all its nested exceptions + * Build a cascaded message from an exception and all its nested exceptions. * @param throwable the top level exception * @return cascaded message string */ @@ -100,7 +100,6 @@ public class ApexException extends Exception { } /** - * * Get the object on which the exception was thrown. * * @return The object on which the exception was thrown diff --git a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/concepts/ApexRuntimeException.java b/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/concepts/ApexRuntimeException.java index 5724b487c..b4240ad0f 100644 --- a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/concepts/ApexRuntimeException.java +++ b/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/concepts/ApexRuntimeException.java @@ -55,21 +55,21 @@ public class ApexRuntimeException extends RuntimeException { * Instantiates a new apex runtime exception. * * @param message the message on the exception - * @param e the exception that caused this Apex exception + * @param exception the exception that caused this Apex exception */ - public ApexRuntimeException(final String message, final Exception e) { - this(message, e, null); + public ApexRuntimeException(final String message, final Exception exception) { + this(message, exception, null); } /** * Instantiates a new apex runtime exception. * * @param message the message on the exception - * @param e the exception that caused this Apex exception + * @param exception the exception that caused this Apex exception * @param object the object that the exception was thrown on */ - public ApexRuntimeException(final String message, final Exception e, final Object object) { - super(message, e); + public ApexRuntimeException(final String message, final Exception exception, final Object object) { + super(message, exception); this.object = object; } diff --git a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/concepts/AxArtifactKey.java b/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/concepts/AxArtifactKey.java index e08c3c65f..1f906ea22 100644 --- a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/concepts/AxArtifactKey.java +++ b/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/concepts/AxArtifactKey.java @@ -38,15 +38,16 @@ import org.onap.policy.apex.model.utilities.Assertions; * An artifact key uniquely identifies every first order entity in the system. Every first order concept in the system * must have an {@link AxArtifactKey} to identify it. Concepts that are wholly contained in another concept are * identified using a {@link AxReferenceKey} key. - *

- * Key validation checks that the name and version fields match the {@link NAME_REGEXP} and {@link VERSION_REGEXP} + * + *

Key validation checks that the name and version fields match the {@link NAME_REGEXP} and {@link VERSION_REGEXP} * regular expressions respectively. */ @Embeddable @XmlAccessorType(XmlAccessType.FIELD) @XmlRootElement(name = "apexArtifactKey", namespace = "http://www.onap.org/policy/apex-pdp") -@XmlType(name = "AxArtifactKey", namespace = "http://www.onap.org/policy/apex-pdp", propOrder = { "name", "version" }) +@XmlType(name = "AxArtifactKey", namespace = "http://www.onap.org/policy/apex-pdp", propOrder = + { "name", "version" }) public class AxArtifactKey extends AxKey { private static final long serialVersionUID = 8932717618579392561L; @@ -70,10 +71,9 @@ public class AxArtifactKey extends AxKey { } /** - * Copy constructor + * Copy constructor. * - * @param copyConcept - * the concept to copy from + * @param copyConcept the concept to copy from */ public AxArtifactKey(final AxArtifactKey copyConcept) { super(copyConcept); @@ -82,10 +82,8 @@ public class AxArtifactKey extends AxKey { /** * Constructor to create a key with the specified name and version. * - * @param name - * the key name - * @param version - * the key version + * @param name the key name + * @param version the key version */ public AxArtifactKey(final String name, final String version) { super(); @@ -96,8 +94,7 @@ public class AxArtifactKey extends AxKey { /** * Constructor to create a key using the key and version from the specified key ID. * - * @param id - * the key ID in a format that respects the {@link KEY_ID_REGEXP} + * @param id the key ID in a format that respects the {@link KEY_ID_REGEXP} */ public AxArtifactKey(final String id) { Assertions.argumentNotNull(id, "id may not be null"); @@ -152,7 +149,7 @@ public class AxArtifactKey extends AxKey { * @see org.onap.policy.apex.model.basicmodel.concepts.AxKey#getID() */ @Override - public String getID() { + public String getId() { return name + ':' + version; } @@ -168,8 +165,7 @@ public class AxArtifactKey extends AxKey { /** * Sets the key name. * - * @param name - * the key name + * @param name the key name */ public void setName(final String name) { this.name = Assertions.validateStringParameter(NAME_TOKEN, name, NAME_REGEXP); @@ -187,8 +183,7 @@ public class AxArtifactKey extends AxKey { /** * Sets the key version. * - * @param version - * the key version + * @param version the key version */ public void setVersion(final String version) { this.version = Assertions.validateStringParameter(VERSION_TOKEN, version, VERSION_REGEXP); @@ -265,8 +260,8 @@ public class AxArtifactKey extends AxKey { "name invalid-" + nameValidationErrorMessage)); } - final String versionValidationErrorMessage = Assertions.getStringParameterValidationMessage(VERSION_TOKEN, version, - VERSION_REGEXP); + final String versionValidationErrorMessage = Assertions.getStringParameterValidationMessage(VERSION_TOKEN, + version, VERSION_REGEXP); if (versionValidationErrorMessage != null) { result.addValidationMessage(new AxValidationMessage(this, this.getClass(), ValidationResult.INVALID, "version invalid-" + versionValidationErrorMessage)); diff --git a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/concepts/AxConcept.java b/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/concepts/AxConcept.java index 3d7f5027f..bb6614715 100644 --- a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/concepts/AxConcept.java +++ b/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/concepts/AxConcept.java @@ -40,12 +40,12 @@ public abstract class AxConcept implements Serializable, Comparable { private static final long serialVersionUID = -7434939557282697490L; /** - * Default constructor + * Default constructor. */ public AxConcept() {} /** - * Copy constructor + * Copy constructor. * * @param copyConcept the concept to copy from */ @@ -120,8 +120,8 @@ public abstract class AxConcept implements Serializable, Comparable { * * @return the ID string of this concept */ - public String getID() { - return getKey().getID(); + public String getId() { + return getKey().getId(); } /** @@ -130,10 +130,10 @@ public abstract class AxConcept implements Serializable, Comparable { * @param id the key ID to match against * @return true, if this key matches the ID */ - public final boolean matchesID(final String id) { + public final boolean matchesId(final String id) { Assertions.argumentNotNull(id, "id may not be null"); // Check the ID - return getID().equals(id); + return getId().equals(id); } } diff --git a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/concepts/AxConceptGetter.java b/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/concepts/AxConceptGetter.java index 0735f87c3..0284de48a 100644 --- a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/concepts/AxConceptGetter.java +++ b/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/concepts/AxConceptGetter.java @@ -24,9 +24,9 @@ import java.util.Set; /** * This interface is used to allow get methods to be placed on concepts that have embedded maps. - *

- * It forces those concepts with maps to implement the get methods specified on this interface as convenience methods to avoid concept users having to use a - * second level of referencing to access concepts in the the maps. + * + *

It forces those concepts with maps to implement the get methods specified on this interface as convenience methods + * to avoid concept users having to use a second level of referencing to access concepts in the the maps. * * @author Liam Fallon (liam.fallon@ericsson.com) * @param the type of concept on which the interface is applied. diff --git a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/concepts/AxConceptGetterImpl.java b/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/concepts/AxConceptGetterImpl.java index b4bff80c8..866de8053 100644 --- a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/concepts/AxConceptGetterImpl.java +++ b/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/concepts/AxConceptGetterImpl.java @@ -82,7 +82,8 @@ public class AxConceptGetterImpl implements AxConceptGetter { break; } foundKey = nextkey; - } while (true); + } + while (true); return conceptMap.get(foundKey); } @@ -147,7 +148,8 @@ public class AxConceptGetterImpl implements AxConceptGetter { break; } returnSet.add(conceptMap.get(foundKey)); - } while (true); + } + while (true); return returnSet; } diff --git a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/concepts/AxKey.java b/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/concepts/AxKey.java index 36b49259b..5702a6577 100644 --- a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/concepts/AxKey.java +++ b/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/concepts/AxKey.java @@ -65,14 +65,14 @@ public abstract class AxKey extends AxConcept { } /** - * Default constructor + * Default constructor. */ public AxKey() { super(); } /** - * Copy constructor + * Copy constructor. * * @param copyConcept the concept to copy from */ @@ -86,7 +86,7 @@ public abstract class AxKey extends AxConcept { * @see org.onap.policy.apex.model.basicmodel.concepts.AxConcept#getID() */ @Override - public abstract String getID(); + public abstract String getId(); /** * Return the result of a compatibility check of two keys. diff --git a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/concepts/AxKeyInfo.java b/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/concepts/AxKeyInfo.java index 6c709fa63..2c2952df9 100644 --- a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/concepts/AxKeyInfo.java +++ b/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/concepts/AxKeyInfo.java @@ -37,16 +37,16 @@ import javax.xml.bind.annotation.XmlType; import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult.ValidationResult; -import org.onap.policy.apex.model.basicmodel.dao.converters.CDATAConditioner; -import org.onap.policy.apex.model.basicmodel.dao.converters.UUID2String; +import org.onap.policy.apex.model.basicmodel.dao.converters.CDataConditioner; +import org.onap.policy.apex.model.basicmodel.dao.converters.Uuid2String; import org.onap.policy.apex.model.utilities.Assertions; /** * The key information on an {@link AxArtifactKey} key in an Apex policy model. Each {@link AxArtifactKey} must have an * {@link AxKeyInfo} object. THe information held is the key's UUID and it's description. - *

- * Validation checks that all fields are defined and that the key is valid. It also observes that descriptions are blank - * and warns if the UUID is a zero UUID. + * + *

Validation checks that all fields are defined and that the key is valid. It also observes that descriptions are + * blank and warns if the UUID is a zero UUID. */ @Entity @@ -68,14 +68,14 @@ public class AxKeyInfo extends AxConcept { private AxArtifactKey key; @Column(name = "uuid") - @Convert(converter = UUID2String.class) - @XmlJavaTypeAdapter(value = UUID2String.class) + @Convert(converter = Uuid2String.class) + @XmlJavaTypeAdapter(value = Uuid2String.class) @XmlElement(name = "UUID", required = true) private UUID uuid; @Column(name = "description", length = MAX_DESCRIPTION_LENGTH_8192) - @Convert(converter = CDATAConditioner.class) - @XmlJavaTypeAdapter(value = CDATAConditioner.class) + @Convert(converter = CDataConditioner.class) + @XmlJavaTypeAdapter(value = CDataConditioner.class) @XmlElement(required = true) private String description; @@ -87,7 +87,7 @@ public class AxKeyInfo extends AxConcept { } /** - * Copy constructor + * Copy constructor. * * @param copyConcept the concept to copy from */ @@ -101,7 +101,7 @@ public class AxKeyInfo extends AxConcept { * @param key the key of the concept */ public AxKeyInfo(final AxArtifactKey key) { - this(key, UUID.randomUUID(), "Generated description for concept referred to by key \"" + key.getID() + "\""); + this(key, UUID.randomUUID(), "Generated description for concept referred to by key \"" + key.getId() + "\""); } /** @@ -157,7 +157,7 @@ public class AxKeyInfo extends AxConcept { * * @return the uuid of the concept */ - public UUID getUUID() { + public UUID getUuid() { return uuid; } @@ -313,8 +313,8 @@ public class AxKeyInfo extends AxConcept { if (!uuid.equals(other.uuid)) { return false; } - final String thisdesc = CDATAConditioner.clean(description); - final String otherdesc = CDATAConditioner.clean(other.description); + final String thisdesc = CDataConditioner.clean(description); + final String otherdesc = CDataConditioner.clean(other.description); return thisdesc.equals(otherdesc); } @@ -351,7 +351,7 @@ public class AxKeyInfo extends AxConcept { * @param seed the seed * @return the uuid */ - public static UUID generateReproducibleUUID(final String seed) { + public static UUID generateReproducibleUuid(final String seed) { final Random random; if (seed != null && seed.length() > 0) { random = new Random(seed.hashCode()); diff --git a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/concepts/AxKeyInformation.java b/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/concepts/AxKeyInformation.java index 6590ff456..9afec9999 100644 --- a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/concepts/AxKeyInformation.java +++ b/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/concepts/AxKeyInformation.java @@ -50,9 +50,9 @@ import org.onap.policy.apex.model.utilities.Assertions; * {@link AxModel} must have an {@link AxKeyInformation} field. The {@link AxKeyInformation} class implements the helper * methods of the {@link AxConceptGetter} interface to allow {@link AxKeyInfo} instances to be retrieved by calling * methods directly on this class without referencing the contained map. - *

- * Validation checks that the key is not null, that the key information map is not empty, that each key and value in the - * map is defined, that the key in each map entry matches the key if each entry value, and that no duplicate UUIDs + * + *

Validation checks that the key is not null, that the key information map is not empty, that each key and value in + * the map is defined, that the key in each map entry matches the key if each entry value, and that no duplicate UUIDs * exist. Each key information entry is then validated individually. */ @Entity @@ -87,7 +87,7 @@ public class AxKeyInformation extends AxConcept implements AxConceptGetter navigablekeyInfoMap = new TreeMap<>(); @@ -152,7 +152,7 @@ public class AxKeyInformation extends AxConcept implements AxConceptGetter - * Validation checks that each key is valid. + * + *

Validation checks that each key is valid. */ public class AxKeyUse extends AxKey { @@ -46,7 +46,7 @@ public class AxKeyUse extends AxKey { } /** - * Copy constructor + * Copy constructor. * * @param copyConcept the concept to copy from */ @@ -90,8 +90,8 @@ public class AxKeyUse extends AxKey { * @see org.onap.policy.apex.model.basicmodel.concepts.AxKey#getID() */ @Override - public String getID() { - return usedKey.getID(); + public String getId() { + return usedKey.getId(); } /** diff --git a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/concepts/AxModel.java b/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/concepts/AxModel.java index dac1d693c..66045db48 100644 --- a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/concepts/AxModel.java +++ b/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/concepts/AxModel.java @@ -46,9 +46,9 @@ import org.onap.policy.apex.model.utilities.Assertions; /** * This class is the base class for all models in Apex. All model classes inherit from this model so all models must * have a key and have key information. - *

- * Validation checks that the model key is valid. It goes on to check for null keys and checks each key for uniqueness - * in the model. A check is carried out to ensure that an {@link AxKeyInfo} instance exists for every + * + *

Validation checks that the model key is valid. It goes on to check for null keys and checks each key for + * uniqueness in the model. A check is carried out to ensure that an {@link AxKeyInfo} instance exists for every * {@link AxArtifactKey} key. For each {@link AxReferenceKey} instance, a check is made that its parent and local name * are nut null and that a {@link AxKeyInfo} entry exists for its parent. Then a check is made that each used * {@link AxArtifactKey} and {@link AxReferenceKey} usage references a key that exists. Finally, a check is made to @@ -61,7 +61,8 @@ import org.onap.policy.apex.model.utilities.Assertions; @XmlRootElement(name = "apexModel", namespace = "http://www.onap.org/policy/apex-pdp") @XmlAccessorType(XmlAccessType.FIELD) -@XmlType(name = "AxModel", namespace = "http://www.onap.org/policy/apex-pdp", propOrder = { "key", "keyInformation" }) +@XmlType(name = "AxModel", namespace = "http://www.onap.org/policy/apex-pdp", propOrder = + { "key", "keyInformation" }) public class AxModel extends AxConcept { private static final String IS_A_NULL_KEY = " is a null key"; @@ -88,7 +89,7 @@ public class AxModel extends AxConcept { } /** - * Copy constructor + * Copy constructor. * * @param copyConcept the concept to copy from */ @@ -197,8 +198,8 @@ public class AxModel extends AxConcept { AxValidationResult result = resultIn; if (key.equals(AxArtifactKey.getNullKey())) { - result.addValidationMessage( - new AxValidationMessage(key, this.getClass(), ValidationResult.INVALID, "key is a null key")); + result.addValidationMessage(new AxValidationMessage(key, this.getClass(), ValidationResult.INVALID, + "key is a null key")); } result = key.validate(result); @@ -226,7 +227,7 @@ public class AxModel extends AxConcept { for (final AxReferenceKey referenceKey : referenceKeySet) { if (!artifactKeySet.contains(referenceKey.getParentArtifactKey())) { result.addValidationMessage(new AxValidationMessage(key, this.getClass(), ValidationResult.INVALID, - "parent artifact key not found for reference key " + referenceKey)); + "parent artifact key not found for reference key " + referenceKey)); } } @@ -236,7 +237,7 @@ public class AxModel extends AxConcept { for (final AxArtifactKey keyInfoKey : keyInformation.getKeyInfoMap().keySet()) { if (!artifactKeySet.contains(keyInfoKey)) { result.addValidationMessage(new AxValidationMessage(keyInfoKey, this.getClass(), - ValidationResult.WARNING, "key not found for key information entry")); + ValidationResult.WARNING, "key not found for key information entry")); } } @@ -244,7 +245,7 @@ public class AxModel extends AxConcept { } /** - * Check for consistent usage of an artifact key in the model + * Check for consistent usage of an artifact key in the model. * * @param artifactKey The artifact key to check * @param artifactKeySet The set of artifact keys encountered so far, this key is appended to the set @@ -252,23 +253,23 @@ public class AxModel extends AxConcept { * @return the result of the validation */ private AxValidationResult validateArtifactKeyInModel(final AxArtifactKey artifactKey, - final Set artifactKeySet, final AxValidationResult result) { + final Set artifactKeySet, final AxValidationResult result) { // Null key check if (artifactKey.equals(AxArtifactKey.getNullKey())) { result.addValidationMessage(new AxValidationMessage(key, this.getClass(), ValidationResult.INVALID, - "key " + artifactKey + IS_A_NULL_KEY)); + "key " + artifactKey + IS_A_NULL_KEY)); } // Null key name start check if (artifactKey.getName().toUpperCase().startsWith(AxKey.NULL_KEY_NAME)) { result.addValidationMessage(new AxValidationMessage(key, this.getClass(), ValidationResult.INVALID, - "key " + artifactKey + " name starts with keyword " + AxKey.NULL_KEY_NAME)); + "key " + artifactKey + " name starts with keyword " + AxKey.NULL_KEY_NAME)); } // Unique key check if (artifactKeySet.contains(artifactKey)) { result.addValidationMessage(new AxValidationMessage(key, this.getClass(), ValidationResult.INVALID, - "duplicate key " + artifactKey + " found")); + "duplicate key " + artifactKey + " found")); } else { artifactKeySet.add(artifactKey); } @@ -276,14 +277,14 @@ public class AxModel extends AxConcept { // Key information check if (!keyInformation.getKeyInfoMap().containsKey(artifactKey)) { result.addValidationMessage(new AxValidationMessage(key, this.getClass(), ValidationResult.INVALID, - "key information not found for key " + artifactKey)); + "key information not found for key " + artifactKey)); } return result; } /** - * Check for consistent usage of a reference key in the model + * Check for consistent usage of a reference key in the model. * * @param artifactKey The reference key to check * @param referenceKeySet The set of reference keys encountered so far, this key is appended to the set @@ -291,35 +292,35 @@ public class AxModel extends AxConcept { * @return the result of the validation */ private AxValidationResult validateReferenceKeyInModel(final AxReferenceKey referenceKey, - final Set referenceKeySet, final AxValidationResult result) { + final Set referenceKeySet, final AxValidationResult result) { // Null key check if (referenceKey.equals(AxReferenceKey.getNullKey())) { result.addValidationMessage(new AxValidationMessage(key, this.getClass(), ValidationResult.INVALID, - "key " + referenceKey + IS_A_NULL_KEY)); + "key " + referenceKey + IS_A_NULL_KEY)); } // Null parent key check if (referenceKey.getParentArtifactKey().equals(AxArtifactKey.getNullKey())) { result.addValidationMessage(new AxValidationMessage(key, this.getClass(), ValidationResult.INVALID, - "parent artifact key of key " + referenceKey + IS_A_NULL_KEY)); + "parent artifact key of key " + referenceKey + IS_A_NULL_KEY)); } // Null local name check if (referenceKey.getLocalName().equals(AxKey.NULL_KEY_NAME)) { result.addValidationMessage(new AxValidationMessage(key, this.getClass(), ValidationResult.INVALID, - "key " + referenceKey + " has a null local name")); + "key " + referenceKey + " has a null local name")); } // Null key name start check if (referenceKey.getParentArtifactKey().getName().toUpperCase().startsWith(AxKey.NULL_KEY_NAME)) { result.addValidationMessage(new AxValidationMessage(key, this.getClass(), ValidationResult.INVALID, - "key " + referenceKey + " parent name starts with keyword " + AxKey.NULL_KEY_NAME)); + "key " + referenceKey + " parent name starts with keyword " + AxKey.NULL_KEY_NAME)); } // Unique key check if (referenceKeySet.contains(referenceKey)) { result.addValidationMessage(new AxValidationMessage(key, this.getClass(), ValidationResult.INVALID, - "duplicate key " + referenceKey + " found")); + "duplicate key " + referenceKey + " found")); } else { referenceKeySet.add(referenceKey); } @@ -327,14 +328,14 @@ public class AxModel extends AxConcept { // Key information check if (!keyInformation.getKeyInfoMap().containsKey(referenceKey.getParentArtifactKey())) { result.addValidationMessage(new AxValidationMessage(key, this.getClass(), ValidationResult.INVALID, - "key information not found for parent key of key " + referenceKey)); + "key information not found for parent key of key " + referenceKey)); } return result; } /** - * Check for consistent usage of cross-key references in the model + * Check for consistent usage of cross-key references in the model. * * @param usedKeySet The set of all keys used in the model * @param artifactKeySet The set of artifact keys encountered so far, this key is appended to the set @@ -343,20 +344,20 @@ public class AxModel extends AxConcept { * @return the result of the validation */ private AxValidationResult validateKeyUses(final Set usedKeySet, final Set artifactKeySet, - final Set referenceKeySet, final AxValidationResult result) { + final Set referenceKeySet, final AxValidationResult result) { // Check all key uses for (final AxKeyUse usedKey : usedKeySet) { if (usedKey.getKey() instanceof AxArtifactKey) { // AxArtifact key usage, check the key exists if (!artifactKeySet.contains(usedKey.getKey())) { result.addValidationMessage(new AxValidationMessage(usedKey.getKey(), this.getClass(), - ValidationResult.INVALID, "an artifact key used in the model is not defined")); + ValidationResult.INVALID, "an artifact key used in the model is not defined")); } } else { // AxReference key usage, check the key exists if (!referenceKeySet.contains(usedKey.getKey())) { result.addValidationMessage(new AxValidationMessage(usedKey.getKey(), this.getClass(), - ValidationResult.INVALID, "a reference key used in the model is not defined")); + ValidationResult.INVALID, "a reference key used in the model is not defined")); } } } @@ -364,7 +365,6 @@ public class AxModel extends AxConcept { return result; } - /* * (non-Javadoc) * diff --git a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/concepts/AxReferenceKey.java b/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/concepts/AxReferenceKey.java index 7cb4dd832..55ea95c3a 100644 --- a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/concepts/AxReferenceKey.java +++ b/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/concepts/AxReferenceKey.java @@ -38,16 +38,16 @@ import org.onap.policy.apex.model.utilities.Assertions; * A reference key identifies entities in the system that are contained in other entities. Every contained concept in * the system must have an {@link AxReferenceKey} to identify it. Non-contained first order concepts are identified * using an {@link AxArtifactKey} key. - *

- * An {@link AxReferenceKey} contains an {@link AxArtifactKey} key reference to the first order entity that contains it. - * The local name of the reference key must uniquely identify the referenced concept among those concepts contained in - * the reference key's parent. In other words, if a parent concept has more than one child, the local name in the key of - * all its children must be unique. - *

- * If a reference key's parent is itself a reference key, then the parent's local name must be set in the reference key. - * If the parent is a first order concept, then the parent's local name in the key will be set to NULL. - *

- * Key validation checks that the parent name and parent version fields match the {@link NAME_REGEXP} and + * + *

An {@link AxReferenceKey} contains an {@link AxArtifactKey} key reference to the first order entity that contains + * it. The local name of the reference key must uniquely identify the referenced concept among those concepts contained + * in the reference key's parent. In other words, if a parent concept has more than one child, the local name in the key + * of all its children must be unique. + * + *

If a reference key's parent is itself a reference key, then the parent's local name must be set in the reference + * key. If the parent is a first order concept, then the parent's local name in the key will be set to NULL. + * + *

Key validation checks that the parent name and parent version fields match the {@link NAME_REGEXP} and * {@link VERSION_REGEXP} regular expressions respectively and that the local name fields match the * {@link LOCAL_NAME_REGEXP} regular expression. */ @@ -69,7 +69,8 @@ public class AxReferenceKey extends AxKey { public static final String LOCAL_NAME_REGEXP = "[A-Za-z0-9\\-_\\.]+|^$"; /** Regular expression to specify the structure of IDs in reference keys. */ - public static final String REFERENCE_KEY_ID_REGEXP = "[A-Za-z0-9\\-_]+:[0-9].[0-9].[0-9]:[A-Za-z0-9\\-_]+:[A-Za-z0-9\\-_]+"; + public static final String REFERENCE_KEY_ID_REGEXP = + "[A-Za-z0-9\\-_]+:[0-9].[0-9].[0-9]:[A-Za-z0-9\\-_]+:[A-Za-z0-9\\-_]+"; private static final int PARENT_NAME_FIELD = 0; private static final int PARENT_VERSION_FIELD = 1; @@ -262,7 +263,7 @@ public class AxReferenceKey extends AxKey { * @see org.onap.policy.apex.model.basicmodel.concepts.AxKey#getID() */ @Override - public String getID() { + public String getId() { return parentKeyName + ':' + parentKeyVersion + ':' + parentLocalName + ':' + localName; } diff --git a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/concepts/AxValidationResult.java b/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/concepts/AxValidationResult.java index 664cf9500..dbe4c6a75 100644 --- a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/concepts/AxValidationResult.java +++ b/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/concepts/AxValidationResult.java @@ -73,7 +73,7 @@ public class AxValidationResult { * * @return true, if the concept has no warnings or errors */ - public boolean isOK() { + public boolean isOk() { return validationResult == ValidationResult.VALID || validationResult == ValidationResult.OBSERVATION; } diff --git a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/dao/ApexDao.java b/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/dao/ApexDao.java index 461f3f113..655e9a99f 100644 --- a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/dao/ApexDao.java +++ b/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/dao/ApexDao.java @@ -43,7 +43,7 @@ public interface ApexDao { * @param daoParameters parameters to use to access the database * @throws ApexException on initialization errors */ - void init(DAOParameters daoParameters) throws ApexException; + void init(DaoParameters daoParameters) throws ApexException; /** * Close the Apex DAO. @@ -70,19 +70,19 @@ public interface ApexDao { * Delete an Apex concept on the database. * * @param the type of the object to delete, a subclass of {@link AxConcept} - * @param aClass the class of the object to delete, a subclass of {@link AxConcept} + * @param someClass the class of the object to delete, a subclass of {@link AxConcept} * @param key the key of the object to delete */ - void delete(Class aClass, AxArtifactKey key); + void delete(Class someClass, AxArtifactKey key); /** * Delete an Apex concept on the database. * * @param the type of the object to delete, a subclass of {@link AxConcept} - * @param aClass the class of the object to delete, a subclass of {@link AxConcept} + * @param someClass the class of the object to delete, a subclass of {@link AxConcept} * @param key the key of the object to delete */ - void delete(Class aClass, AxReferenceKey key); + void delete(Class someClass, AxReferenceKey key); /** * Create a collection of objects in the database. @@ -90,7 +90,7 @@ public interface ApexDao { * @param the type of the object to create, a subclass of {@link AxConcept} * @param objs the objects to create */ - void create(Collection objs); + void createCollection(Collection objs); /** * Delete a collection of objects in the database. @@ -98,103 +98,103 @@ public interface ApexDao { * @param the type of the objects to delete, a subclass of {@link AxConcept} * @param objs the objects to delete */ - void delete(Collection objs); + void deleteCollection(Collection objs); /** * Delete a collection of objects in the database referred to by artifact key. * * @param the type of the objects to delete, a subclass of {@link AxConcept} - * @param aClass the class of the objects to delete, a subclass of {@link AxConcept} + * @param someClass the class of the objects to delete, a subclass of {@link AxConcept} * @param keys the keys of the objects to delete * @return the number of objects deleted */ - int deleteByArtifactKey(Class aClass, Collection keys); + int deleteByArtifactKey(Class someClass, Collection keys); /** * Delete a collection of objects in the database referred to by reference key. * * @param the type of the objects to delete, a subclass of {@link AxConcept} - * @param aClass the class of the objects to delete, a subclass of {@link AxConcept} + * @param someClass the class of the objects to delete, a subclass of {@link AxConcept} * @param keys the keys of the objects to delete * @return the number of objects deleted */ - int deleteByReferenceKey(Class aClass, Collection keys); + int deleteByReferenceKey(Class someClass, Collection keys); /** * Delete all objects of a given class in the database. * * @param the type of the objects to delete, a subclass of {@link AxConcept} - * @param aClass the class of the objects to delete, a subclass of {@link AxConcept} + * @param someClass the class of the objects to delete, a subclass of {@link AxConcept} */ - void deleteAll(Class aClass); + void deleteAll(Class someClass); /** * Get an object from the database, referred to by artifact key. * * @param the type of the object to get, a subclass of {@link AxConcept} - * @param aClass the class of the object to get, a subclass of {@link AxConcept} + * @param someClass the class of the object to get, a subclass of {@link AxConcept} * @param key the key of the object to get * @return the object that was retrieved from the database */ - T get(Class aClass, AxArtifactKey key); + T get(Class someClass, AxArtifactKey key); /** * Get an object from the database, referred to by reference key. * * @param the type of the object to get, a subclass of {@link AxConcept} - * @param aClass the class of the object to get, a subclass of {@link AxConcept} + * @param someClass the class of the object to get, a subclass of {@link AxConcept} * @param key the key of the object to get * @return the object that was retrieved from the database or null if the object was not retrieved */ - T get(Class aClass, AxReferenceKey key); + T get(Class someClass, AxReferenceKey key); /** * Get all the objects in the database of a given type. * * @param the type of the objects to get, a subclass of {@link AxConcept} - * @param aClass the class of the objects to get, a subclass of {@link AxConcept} + * @param someClass the class of the objects to get, a subclass of {@link AxConcept} * @return the objects or null if no objects were retrieved */ - List getAll(Class aClass); + List getAll(Class someClass); /** * Get all the objects in the database of the given type with the given parent artifact key. * * @param the type of the objects to get, a subclass of {@link AxConcept} - * @param aClass the class of the objects to get, a subclass of {@link AxConcept} + * @param someClass the class of the objects to get, a subclass of {@link AxConcept} * @param parentKey the parent key of the concepts to get * @return the all */ - List getAll(Class aClass, AxArtifactKey parentKey); + List getAll(Class someClass, AxArtifactKey parentKey); /** * Get a concept from the database with the given artifact key. * * @param the type of the object to get, a subclass of {@link AxConcept} - * @param aClass the class of the object to get, a subclass of {@link AxConcept} - * @param artifactID the artifact key of the concept to get + * @param someClass the class of the object to get, a subclass of {@link AxConcept} + * @param artifactId the artifact key of the concept to get * @return the concept that matches the key or null if the concept is not retrieved */ - T getArtifact(Class aClass, AxArtifactKey artifactID); + T getArtifact(Class someClass, AxArtifactKey artifactId); /** * Get a concept from the database with the given reference key. * * @param the type of the object to get, a subclass of {@link AxConcept} - * @param aClass the class of the object to get, a subclass of {@link AxConcept} - * @param artifactID the artifact key of the concept to get + * @param someClass the class of the object to get, a subclass of {@link AxConcept} + * @param artifactId the artifact key of the concept to get * @return the concept that matches the key or null if the concept is not retrieved */ - T getArtifact(Class aClass, AxReferenceKey artifactID); + T getArtifact(Class someClass, AxReferenceKey artifactId); /** * Get the number of instances of a concept that exist in the database. * * @param the type of the object to get, a subclass of {@link AxConcept} - * @param aClass the class of the object to get, a subclass of {@link AxConcept} + * @param someClass the class of the object to get, a subclass of {@link AxConcept} * @return the number of instances of the concept in the database */ - long size(Class aClass); + long size(Class someClass); /** * Update a concept in the database. diff --git a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/dao/ApexDaoFactory.java b/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/dao/ApexDaoFactory.java index 50724d2d7..82838edf1 100644 --- a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/dao/ApexDaoFactory.java +++ b/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/dao/ApexDaoFactory.java @@ -27,7 +27,7 @@ import org.slf4j.ext.XLoggerFactory; /** * This factory class returns an Apex DAO for the configured persistence mechanism. The factory uses the plugin class - * specified in {@link DAOParameters} to instantiate a DAO instance. + * specified in {@link DaoParameters} to instantiate a DAO instance. * * @author Liam Fallon (liam.fallon@ericsson.com) */ @@ -42,7 +42,7 @@ public class ApexDaoFactory { * @return the Apex DAO * @throws ApexException on invalid JPA plugins */ - public ApexDao createApexDao(final DAOParameters daoParameters) throws ApexException { + public ApexDao createApexDao(final DaoParameters daoParameters) throws ApexException { Assertions.argumentNotNull(daoParameters, ApexException.class, "Parameter \"daoParameters\" may not be null"); // Get the class for the DAO using reflection diff --git a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/dao/DAOParameters.java b/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/dao/DAOParameters.java deleted file mode 100644 index 5a44d18a8..000000000 --- a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/dao/DAOParameters.java +++ /dev/null @@ -1,125 +0,0 @@ -/*- - * ============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========================================================= - */ - -package org.onap.policy.apex.model.basicmodel.dao; - -import java.util.Properties; - -/** - * This class is a POJO that holds properties for Apex DAOs. - * - * @author Liam Fallon (liam.fallon@ericsson.com) - */ -public class DAOParameters { - /** The default Apex DAO plugin class. */ - public static final String DEFAULT_PLUGIN_CLASS = "org.onap.policy.apex.model.basicmodel.dao.impl.DefaultApexDao"; - - private String pluginClass = DEFAULT_PLUGIN_CLASS; - private String persistenceUnit; - - private Properties jdbcProperties = new Properties(); - - /** - * Gets the DAO plugin class, this is the DAO class to use and it must implement the {@link ApexDao} interface. - * - * @return the DAO plugin class - */ - public String getPluginClass() { - return pluginClass; - } - - /** - * Sets the DAO plugin class, a class that implements the {@link ApexDao} interface. - * - * @param daoPluginClass the DAO plugin class - */ - public void setPluginClass(final String daoPluginClass) { - pluginClass = daoPluginClass; - } - - /** - * Gets the persistence unit for the DAO. The persistence unit defines the JDBC properties the DAO will use. The - * persistence unit must defined in the {@code META-INF/persistence.xml} resource file - * - * @return the persistence unit to use for JDBC access - */ - public String getPersistenceUnit() { - return persistenceUnit; - } - - /** - * Sets the persistence unit for the DAO. The persistence unit defines the JDBC properties the DAO will use. The - * persistence unit must defined in the {@code META-INF/persistence.xml} resource file - * - * @param daoPersistenceUnit the persistence unit to use for JDBC access - */ - public void setPersistenceUnit(final String daoPersistenceUnit) { - persistenceUnit = daoPersistenceUnit; - } - - /** - * Gets the JDBC properties. - * - * @return the JDBC properties - */ - public Properties getJdbcProperties() { - return jdbcProperties; - } - - /** - * Sets the JDBC properties. - * - * @param jdbcProperties the JDBC properties - */ - public void setJdbcProperties(final Properties jdbcProperties) { - this.jdbcProperties = jdbcProperties; - } - - /** - * Gets a single JDBC property. - * - * @param key the key of the property - * @return the JDBC property - */ - public String getJdbcProperty(final String key) { - return jdbcProperties.getProperty(key); - } - - /** - * Sets a single JDBC property. - * - * @param key the key of the property - * @param value the value of the JDBC property - */ - public void setJdbcProperty(final String key, final String value) { - jdbcProperties.setProperty(key, value); - } - - /* - * (non-Javadoc) - * - * @see java.lang.Object#toString() - */ - @Override - public String toString() { - return "DAOParameters [pluginClass=" + pluginClass + ", persistenceUnit=" + persistenceUnit - + ", jdbcProperties=" + jdbcProperties + "]"; - } -} diff --git a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/dao/DaoParameters.java b/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/dao/DaoParameters.java new file mode 100644 index 000000000..cdaf64ed0 --- /dev/null +++ b/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/dao/DaoParameters.java @@ -0,0 +1,125 @@ +/*- + * ============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========================================================= + */ + +package org.onap.policy.apex.model.basicmodel.dao; + +import java.util.Properties; + +/** + * This class is a POJO that holds properties for Apex DAOs. + * + * @author Liam Fallon (liam.fallon@ericsson.com) + */ +public class DaoParameters { + /** The default Apex DAO plugin class. */ + public static final String DEFAULT_PLUGIN_CLASS = "org.onap.policy.apex.model.basicmodel.dao.impl.DefaultApexDao"; + + private String pluginClass = DEFAULT_PLUGIN_CLASS; + private String persistenceUnit; + + private Properties jdbcProperties = new Properties(); + + /** + * Gets the DAO plugin class, this is the DAO class to use and it must implement the {@link ApexDao} interface. + * + * @return the DAO plugin class + */ + public String getPluginClass() { + return pluginClass; + } + + /** + * Sets the DAO plugin class, a class that implements the {@link ApexDao} interface. + * + * @param daoPluginClass the DAO plugin class + */ + public void setPluginClass(final String daoPluginClass) { + pluginClass = daoPluginClass; + } + + /** + * Gets the persistence unit for the DAO. The persistence unit defines the JDBC properties the DAO will use. The + * persistence unit must defined in the {@code META-INF/persistence.xml} resource file + * + * @return the persistence unit to use for JDBC access + */ + public String getPersistenceUnit() { + return persistenceUnit; + } + + /** + * Sets the persistence unit for the DAO. The persistence unit defines the JDBC properties the DAO will use. The + * persistence unit must defined in the {@code META-INF/persistence.xml} resource file + * + * @param daoPersistenceUnit the persistence unit to use for JDBC access + */ + public void setPersistenceUnit(final String daoPersistenceUnit) { + persistenceUnit = daoPersistenceUnit; + } + + /** + * Gets the JDBC properties. + * + * @return the JDBC properties + */ + public Properties getJdbcProperties() { + return jdbcProperties; + } + + /** + * Sets the JDBC properties. + * + * @param jdbcProperties the JDBC properties + */ + public void setJdbcProperties(final Properties jdbcProperties) { + this.jdbcProperties = jdbcProperties; + } + + /** + * Gets a single JDBC property. + * + * @param key the key of the property + * @return the JDBC property + */ + public String getJdbcProperty(final String key) { + return jdbcProperties.getProperty(key); + } + + /** + * Sets a single JDBC property. + * + * @param key the key of the property + * @param value the value of the JDBC property + */ + public void setJdbcProperty(final String key, final String value) { + jdbcProperties.setProperty(key, value); + } + + /* + * (non-Javadoc) + * + * @see java.lang.Object#toString() + */ + @Override + public String toString() { + return "DAOParameters [pluginClass=" + pluginClass + ", persistenceUnit=" + persistenceUnit + + ", jdbcProperties=" + jdbcProperties + "]"; + } +} diff --git a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/dao/converters/CDATAConditioner.java b/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/dao/converters/CDATAConditioner.java deleted file mode 100644 index 9e840da2c..000000000 --- a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/dao/converters/CDATAConditioner.java +++ /dev/null @@ -1,91 +0,0 @@ -/*- - * ============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========================================================= - */ - -package org.onap.policy.apex.model.basicmodel.dao.converters; - -import javax.persistence.AttributeConverter; -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 at the ends of - * lines and platform-specific new line endings. - * - * @author John Keeney (John.Keeney@ericsson.com) - */ -@Converter -public class CDATAConditioner extends XmlAdapter implements AttributeConverter { - - private static final String NL = "\n"; - - /* - * (non-Javadoc) - * - * @see javax.persistence.AttributeConverter#convertToDatabaseColumn(java.lang.Object) - */ - @Override - public String convertToDatabaseColumn(final String raw) { - return clean(raw); - } - - /* - * (non-Javadoc) - * - * @see javax.persistence.AttributeConverter#convertToEntityAttribute(java.lang.Object) - */ - @Override - public String convertToEntityAttribute(final String db) { - return clean(db); - } - - /* - * (non-Javadoc) - * - * @see javax.xml.bind.annotation.adapters.XmlAdapter - */ - @Override - public String unmarshal(final String v) throws Exception { - return this.convertToEntityAttribute(v); - } - - /* - * (non-Javadoc) - * - * @see javax.xml.bind.annotation.adapters.XmlAdapter - */ - @Override - public String marshal(final String v) throws Exception { - return this.convertToDatabaseColumn(v); - } - - /** - * Clean. - * - * @param in the in - * @return the string - */ - public static final String clean(final String in) { - if (in == null) { - return null; - } else { - return in.replaceAll("\\s+$", "").replaceAll("\\r?\\n", NL); - } - } -} diff --git a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/dao/converters/CDataConditioner.java b/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/dao/converters/CDataConditioner.java new file mode 100644 index 000000000..93c891b13 --- /dev/null +++ b/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/dao/converters/CDataConditioner.java @@ -0,0 +1,91 @@ +/*- + * ============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========================================================= + */ + +package org.onap.policy.apex.model.basicmodel.dao.converters; + +import javax.persistence.AttributeConverter; +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 at the ends of + * lines and platform-specific new line endings. + * + * @author John Keeney (John.Keeney@ericsson.com) + */ +@Converter +public class CDataConditioner extends XmlAdapter implements AttributeConverter { + + private static final String NL = "\n"; + + /* + * (non-Javadoc) + * + * @see javax.persistence.AttributeConverter#convertToDatabaseColumn(java.lang.Object) + */ + @Override + public String convertToDatabaseColumn(final String raw) { + return clean(raw); + } + + /* + * (non-Javadoc) + * + * @see javax.persistence.AttributeConverter#convertToEntityAttribute(java.lang.Object) + */ + @Override + public String convertToEntityAttribute(final String db) { + return clean(db); + } + + /* + * (non-Javadoc) + * + * @see javax.xml.bind.annotation.adapters.XmlAdapter + */ + @Override + public String unmarshal(final String value) throws Exception { + return this.convertToEntityAttribute(value); + } + + /* + * (non-Javadoc) + * + * @see javax.xml.bind.annotation.adapters.XmlAdapter + */ + @Override + public String marshal(final String value) throws Exception { + return this.convertToDatabaseColumn(value); + } + + /** + * Clean. + * + * @param in the in + * @return the string + */ + public static final String clean(final String in) { + if (in == null) { + return null; + } else { + return in.replaceAll("\\s+$", "").replaceAll("\\r?\\n", NL); + } + } +} diff --git a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/dao/converters/UUID2String.java b/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/dao/converters/UUID2String.java deleted file mode 100644 index f26dfc2de..000000000 --- a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/dao/converters/UUID2String.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - * ============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========================================================= - */ - -package org.onap.policy.apex.model.basicmodel.dao.converters; - -import java.util.UUID; - -import javax.persistence.AttributeConverter; -import javax.persistence.Converter; -import javax.xml.bind.annotation.adapters.XmlAdapter; - -/** - * The Class UUIDConverter converts a UUID to and from database format. - * - * @author Liam Fallon (liam.fallon@ericsson.com) - */ -@Converter -public class UUID2String extends XmlAdapter implements AttributeConverter { - - /* - * (non-Javadoc) - * - * @see javax.persistence.AttributeConverter#convertToDatabaseColumn(java.lang.Object) - */ - @Override - public String convertToDatabaseColumn(final UUID uuid) { - String returnString; - if (uuid == null) { - returnString = ""; - } - else { - returnString = uuid.toString(); - } - return returnString; - } - - /* - * (non-Javadoc) - * - * @see javax.persistence.AttributeConverter#convertToEntityAttribute(java.lang.Object) - */ - @Override - public UUID convertToEntityAttribute(final String uuidString) { - return UUID.fromString(uuidString); - } - - /* - * (non-Javadoc) - * - * @see javax.xml.bind.annotation.adapters.XmlAdapter - */ - @Override - public UUID unmarshal(final String v) throws Exception { - return this.convertToEntityAttribute(v); - } - - /* - * (non-Javadoc) - * - * @see javax.xml.bind.annotation.adapters.XmlAdapter - */ - @Override - public String marshal(final UUID v) throws Exception { - return this.convertToDatabaseColumn(v); - } -} diff --git a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/dao/converters/Uuid2String.java b/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/dao/converters/Uuid2String.java new file mode 100644 index 000000000..3f7bddbd1 --- /dev/null +++ b/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/dao/converters/Uuid2String.java @@ -0,0 +1,83 @@ +/* + * ============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========================================================= + */ + +package org.onap.policy.apex.model.basicmodel.dao.converters; + +import java.util.UUID; + +import javax.persistence.AttributeConverter; +import javax.persistence.Converter; +import javax.xml.bind.annotation.adapters.XmlAdapter; + +/** + * The Class UUIDConverter converts a UUID to and from database format. + * + * @author Liam Fallon (liam.fallon@ericsson.com) + */ +@Converter +public class Uuid2String extends XmlAdapter implements AttributeConverter { + + /* + * (non-Javadoc) + * + * @see javax.persistence.AttributeConverter#convertToDatabaseColumn(java.lang.Object) + */ + @Override + public String convertToDatabaseColumn(final UUID uuid) { + String returnString; + if (uuid == null) { + returnString = ""; + } + else { + returnString = uuid.toString(); + } + return returnString; + } + + /* + * (non-Javadoc) + * + * @see javax.persistence.AttributeConverter#convertToEntityAttribute(java.lang.Object) + */ + @Override + public UUID convertToEntityAttribute(final String uuidString) { + return UUID.fromString(uuidString); + } + + /* + * (non-Javadoc) + * + * @see javax.xml.bind.annotation.adapters.XmlAdapter + */ + @Override + public UUID unmarshal(final String value) throws Exception { + return this.convertToEntityAttribute(value); + } + + /* + * (non-Javadoc) + * + * @see javax.xml.bind.annotation.adapters.XmlAdapter + */ + @Override + public String marshal(final UUID value) throws Exception { + return this.convertToDatabaseColumn(value); + } +} diff --git a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/dao/impl/DefaultApexDao.java b/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/dao/impl/DefaultApexDao.java index 228362bce..7945a0837 100644 --- a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/dao/impl/DefaultApexDao.java +++ b/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/dao/impl/DefaultApexDao.java @@ -34,7 +34,7 @@ import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey; import org.onap.policy.apex.model.basicmodel.concepts.AxConcept; import org.onap.policy.apex.model.basicmodel.concepts.AxReferenceKey; import org.onap.policy.apex.model.basicmodel.dao.ApexDao; -import org.onap.policy.apex.model.basicmodel.dao.DAOParameters; +import org.onap.policy.apex.model.basicmodel.dao.DaoParameters; import org.slf4j.ext.XLogger; import org.slf4j.ext.XLoggerFactory; @@ -66,7 +66,7 @@ public class DefaultApexDao implements ApexDao { * org.onap.policy.apex.model.basicmodel.dao.ApexDao#init(org.onap.policy.apex.model.basicmodel.dao.DAOParameters) */ @Override - public void init(final DAOParameters daoParameters) throws ApexException { + public void init(final DaoParameters daoParameters) throws ApexException { if (daoParameters == null || daoParameters.getPersistenceUnit() == null) { LOGGER.error("Apex persistence unit parameter not set"); throw new ApexException("Apex persistence unit parameter not set"); @@ -75,11 +75,12 @@ public class DefaultApexDao implements ApexDao { LOGGER.debug("Creating Apex persistence unit \"" + daoParameters.getPersistenceUnit() + "\" . . ."); try { emf = Persistence.createEntityManagerFactory(daoParameters.getPersistenceUnit(), - daoParameters.getJdbcProperties()); + daoParameters.getJdbcProperties()); } catch (final Exception e) { LOGGER.warn("Creation of Apex persistence unit \"" + daoParameters.getPersistenceUnit() + "\" failed", e); throw new ApexException( - "Creation of Apex persistence unit \"" + daoParameters.getPersistenceUnit() + "\" failed", e); + "Creation of Apex persistence unit \"" + daoParameters.getPersistenceUnit() + "\" failed", + e); } LOGGER.debug("Created Apex persistence unit \"" + daoParameters.getPersistenceUnit() + "\""); } @@ -159,15 +160,15 @@ public class DefaultApexDao implements ApexDao { * org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey) */ @Override - public void delete(final Class aClass, final AxArtifactKey key) { + public void delete(final Class someClass, final AxArtifactKey key) { if (key == null) { return; } final EntityManager mg = getEntityManager(); try { mg.getTransaction().begin(); - mg.createQuery(DELETE_FROM + aClass.getSimpleName() + C_WHERE_C_KEY_NAME + key.getName() + AND_C_KEY_VERSION - + key.getVersion() + "'", aClass).executeUpdate(); + mg.createQuery(DELETE_FROM + someClass.getSimpleName() + C_WHERE_C_KEY_NAME + key.getName() + + AND_C_KEY_VERSION + key.getVersion() + "'", someClass).executeUpdate(); mg.getTransaction().commit(); } finally { mg.close(); @@ -181,16 +182,16 @@ public class DefaultApexDao implements ApexDao { * org.onap.policy.apex.model.basicmodel.concepts.AxReferenceKey) */ @Override - public void delete(final Class aClass, final AxReferenceKey key) { + public void delete(final Class someClass, final AxReferenceKey key) { if (key == null) { return; } final EntityManager mg = getEntityManager(); try { mg.getTransaction().begin(); - mg.createQuery(DELETE_FROM + aClass.getSimpleName() + C_WHERE_C_KEY_PARENT_KEY_NAME + key.getParentKeyName() - + AND_C_KEY_PARENT_KEY_VERSION + key.getParentKeyVersion() + AND_C_KEY_LOCAL_NAME - + key.getLocalName() + "'", aClass).executeUpdate(); + mg.createQuery(DELETE_FROM + someClass.getSimpleName() + C_WHERE_C_KEY_PARENT_KEY_NAME + + key.getParentKeyName() + AND_C_KEY_PARENT_KEY_VERSION + key.getParentKeyVersion() + + AND_C_KEY_LOCAL_NAME + key.getLocalName() + "'", someClass).executeUpdate(); mg.getTransaction().commit(); } finally { mg.close(); @@ -203,7 +204,7 @@ public class DefaultApexDao implements ApexDao { * @see org.onap.policy.apex.model.basicmodel.dao.ApexDao#create(java.util.Collection) */ @Override - public void create(final Collection objs) { + public void createCollection(final Collection objs) { if (objs == null || objs.isEmpty()) { return; } @@ -225,7 +226,7 @@ public class DefaultApexDao implements ApexDao { * @see org.onap.policy.apex.model.basicmodel.dao.ApexDao#delete(java.util.Collection) */ @Override - public void delete(final Collection objs) { + public void deleteCollection(final Collection objs) { if (objs == null || objs.isEmpty()) { return; } @@ -247,7 +248,8 @@ public class DefaultApexDao implements ApexDao { * @see org.onap.policy.apex.model.basicmodel.dao.ApexDao#deleteByArtifactKey(java.lang.Class, java.util.Collection) */ @Override - public int deleteByArtifactKey(final Class aClass, final Collection keys) { + public int deleteByArtifactKey(final Class someClass, + final Collection keys) { if (keys == null || keys.isEmpty()) { return 0; } @@ -256,8 +258,10 @@ public class DefaultApexDao implements ApexDao { try { mg.getTransaction().begin(); for (final AxArtifactKey key : keys) { - deletedCount += mg.createQuery(DELETE_FROM + aClass.getSimpleName() + C_WHERE_C_KEY_NAME + key.getName() - + AND_C_KEY_VERSION + key.getVersion() + "'", aClass).executeUpdate(); + deletedCount += mg + .createQuery(DELETE_FROM + someClass.getSimpleName() + C_WHERE_C_KEY_NAME + + key.getName() + AND_C_KEY_VERSION + key.getVersion() + "'", someClass) + .executeUpdate(); } mg.getTransaction().commit(); } finally { @@ -273,8 +277,8 @@ public class DefaultApexDao implements ApexDao { * java.util.Collection) */ @Override - public int deleteByReferenceKey(final Class aClass, - final Collection keys) { + public int deleteByReferenceKey(final Class someClass, + final Collection keys) { if (keys == null || keys.isEmpty()) { return 0; } @@ -283,12 +287,9 @@ public class DefaultApexDao implements ApexDao { try { mg.getTransaction().begin(); for (final AxReferenceKey key : keys) { - deletedCount += - mg.createQuery( - DELETE_FROM + aClass.getSimpleName() + C_WHERE_C_KEY_PARENT_KEY_NAME - + key.getParentKeyName() + AND_C_KEY_PARENT_KEY_VERSION - + key.getParentKeyVersion() + AND_C_KEY_LOCAL_NAME + key.getLocalName() + "'", - aClass).executeUpdate(); + deletedCount += mg.createQuery(DELETE_FROM + someClass.getSimpleName() + C_WHERE_C_KEY_PARENT_KEY_NAME + + key.getParentKeyName() + AND_C_KEY_PARENT_KEY_VERSION + key.getParentKeyVersion() + + AND_C_KEY_LOCAL_NAME + key.getLocalName() + "'", someClass).executeUpdate(); } mg.getTransaction().commit(); } finally { @@ -303,11 +304,11 @@ public class DefaultApexDao implements ApexDao { * @see org.onap.policy.apex.model.basicmodel.dao.ApexDao#deleteAll(java.lang.Class) */ @Override - public void deleteAll(final Class aClass) { + public void deleteAll(final Class someClass) { final EntityManager mg = getEntityManager(); try { mg.getTransaction().begin(); - mg.createQuery(DELETE_FROM + aClass.getSimpleName() + " c ", aClass).executeUpdate(); + mg.createQuery(DELETE_FROM + someClass.getSimpleName() + " c ", someClass).executeUpdate(); mg.getTransaction().commit(); } finally { mg.close(); @@ -321,21 +322,21 @@ public class DefaultApexDao implements ApexDao { * org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey) */ @Override - public T get(final Class aClass, final AxArtifactKey key) { - if (aClass == null) { + public T get(final Class someClass, final AxArtifactKey key) { + if (someClass == null) { return null; } final EntityManager mg = getEntityManager(); try { - final T t = mg.find(aClass, key); + final T t = mg.find(someClass, key); if (t != null) { // This clone is created to force the JPA DAO to recurse down through the object try { - final T clonedT = aClass.newInstance(); + final T clonedT = someClass.newInstance(); t.copyTo(clonedT); return clonedT; } catch (final Exception e) { - LOGGER.warn("Could not clone object of class \"" + aClass.getCanonicalName() + "\"", e); + LOGGER.warn("Could not clone object of class \"" + someClass.getCanonicalName() + "\"", e); return null; } } else { @@ -353,20 +354,20 @@ public class DefaultApexDao implements ApexDao { * org.onap.policy.apex.model.basicmodel.concepts.AxReferenceKey) */ @Override - public T get(final Class aClass, final AxReferenceKey key) { - if (aClass == null) { + public T get(final Class someClass, final AxReferenceKey key) { + if (someClass == null) { return null; } final EntityManager mg = getEntityManager(); try { - final T t = mg.find(aClass, key); + final T t = mg.find(someClass, key); if (t != null) { try { - final T clonedT = aClass.newInstance(); + final T clonedT = someClass.newInstance(); t.copyTo(clonedT); return clonedT; } catch (final Exception e) { - LOGGER.warn("Could not clone object of class \"" + aClass.getCanonicalName() + "\"", e); + LOGGER.warn("Could not clone object of class \"" + someClass.getCanonicalName() + "\"", e); return null; } } else { @@ -383,13 +384,13 @@ public class DefaultApexDao implements ApexDao { * @see org.onap.policy.apex.model.basicmodel.dao.ApexDao#getAll(java.lang.Class) */ @Override - public List getAll(final Class aClass) { - if (aClass == null) { + public List getAll(final Class someClass) { + if (someClass == null) { return Collections.emptyList(); } final EntityManager mg = getEntityManager(); try { - return mg.createQuery(SELECT_C_FROM + aClass.getSimpleName() + " c", aClass).getResultList(); + return mg.createQuery(SELECT_C_FROM + someClass.getSimpleName() + " c", someClass).getResultList(); } finally { mg.close(); } @@ -402,16 +403,15 @@ public class DefaultApexDao implements ApexDao { * org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey) */ @Override - public List getAll(final Class aClass, final AxArtifactKey parentKey) { - if (aClass == null) { + public List getAll(final Class someClass, final AxArtifactKey parentKey) { + if (someClass == null) { return Collections.emptyList(); } final EntityManager mg = getEntityManager(); try { - return mg - .createQuery(SELECT_C_FROM + aClass.getSimpleName() + C_WHERE_C_KEY_PARENT_KEY_NAME - + parentKey.getName() + AND_C_KEY_PARENT_KEY_VERSION + parentKey.getVersion() + "'", aClass) - .getResultList(); + return mg.createQuery(SELECT_C_FROM + someClass.getSimpleName() + C_WHERE_C_KEY_PARENT_KEY_NAME + + parentKey.getName() + AND_C_KEY_PARENT_KEY_VERSION + parentKey.getVersion() + "'", + someClass).getResultList(); } finally { mg.close(); } @@ -424,15 +424,15 @@ public class DefaultApexDao implements ApexDao { * org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey) */ @Override - public T getArtifact(final Class aClass, final AxArtifactKey key) { - if (aClass == null || key == null) { + public T getArtifact(final Class someClass, final AxArtifactKey key) { + if (someClass == null || key == null) { return null; } final EntityManager mg = getEntityManager(); List ret; try { - ret = mg.createQuery(SELECT_C_FROM + aClass.getSimpleName() + C_WHERE_C_KEY_NAME + key.getName() - + AND_C_KEY_VERSION + key.getVersion() + "'", aClass).getResultList(); + ret = mg.createQuery(SELECT_C_FROM + someClass.getSimpleName() + C_WHERE_C_KEY_NAME + key.getName() + + AND_C_KEY_VERSION + key.getVersion() + "'", someClass).getResultList(); } finally { mg.close(); } @@ -440,8 +440,8 @@ public class DefaultApexDao implements ApexDao { return null; } if (ret.size() > 1) { - throw new IllegalArgumentException("More than one result was returned for search for " + aClass - + " with key " + key.getID() + ": " + ret); + throw new IllegalArgumentException("More than one result was returned for search for " + someClass + + " with key " + key.getId() + ": " + ret); } return ret.get(0); } @@ -453,16 +453,16 @@ public class DefaultApexDao implements ApexDao { * org.onap.policy.apex.model.basicmodel.concepts.AxReferenceKey) */ @Override - public T getArtifact(final Class aClass, final AxReferenceKey key) { - if (aClass == null || key == null) { + public T getArtifact(final Class someClass, final AxReferenceKey key) { + if (someClass == null || key == null) { return null; } final EntityManager mg = getEntityManager(); List ret; try { - ret = mg.createQuery(SELECT_C_FROM + aClass.getSimpleName() + C_WHERE_C_KEY_PARENT_KEY_NAME - + key.getParentKeyName() + AND_C_KEY_PARENT_KEY_VERSION + key.getParentKeyVersion() - + AND_C_KEY_LOCAL_NAME + key.getLocalName() + "'", aClass).getResultList(); + ret = mg.createQuery(SELECT_C_FROM + someClass.getSimpleName() + C_WHERE_C_KEY_PARENT_KEY_NAME + + key.getParentKeyName() + AND_C_KEY_PARENT_KEY_VERSION + key.getParentKeyVersion() + + AND_C_KEY_LOCAL_NAME + key.getLocalName() + "'", someClass).getResultList(); } finally { mg.close(); } @@ -470,8 +470,8 @@ public class DefaultApexDao implements ApexDao { return null; } if (ret.size() > 1) { - throw new IllegalArgumentException("More than one result was returned for search for " + aClass - + " with key " + key.getID() + ": " + ret); + throw new IllegalArgumentException("More than one result was returned for search for " + someClass + + " with key " + key.getId() + ": " + ret); } return ret.get(0); } @@ -503,15 +503,15 @@ public class DefaultApexDao implements ApexDao { * @see org.onap.policy.apex.model.basicmodel.dao.ApexDao#size(java.lang.Class) */ @Override - public long size(final Class aClass) { - if (aClass == null) { + public long size(final Class someClass) { + if (someClass == null) { return 0; } final EntityManager mg = getEntityManager(); long size = 0; try { - size = mg.createQuery("SELECT COUNT(c) FROM " + aClass.getSimpleName() + " c", Long.class) - .getSingleResult(); + size = mg.createQuery("SELECT COUNT(c) FROM " + someClass.getSimpleName() + " c", Long.class) + .getSingleResult(); } finally { mg.close(); } diff --git a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/dao/impl/package-info.java b/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/dao/impl/package-info.java index 12e854f26..5d585c247 100644 --- a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/dao/impl/package-info.java +++ b/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/dao/impl/package-info.java @@ -19,7 +19,8 @@ */ /** - * Contains a default DAO implementation for APEX {@link org.onap.policy.apex.model.basicmodel.concepts.AxConcept} classes that uses javax persistence. + * Contains a default DAO implementation for APEX {@link org.onap.policy.apex.model.basicmodel.concepts.AxConcept} + * classes that uses javax persistence. * * @author Liam Fallon (liam.fallon@ericsson.com) */ diff --git a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/dao/package-info.java b/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/dao/package-info.java index fe551b87a..505e4023a 100644 --- a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/dao/package-info.java +++ b/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/dao/package-info.java @@ -20,8 +20,8 @@ /** * 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 over - * JDBC. + * {@link org.onap.policy.apex.model.basicmodel.concepts.AxConcept} concepts to be read from and written to databases + * over JDBC. * * @author Liam Fallon (liam.fallon@ericsson.com) */ diff --git a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelCreator.java b/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelCreator.java index 82a808c60..a33e1bf1a 100644 --- a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelCreator.java +++ b/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelCreator.java @@ -23,7 +23,8 @@ package org.onap.policy.apex.model.basicmodel.handling; import org.onap.policy.apex.model.basicmodel.concepts.AxModel; /** - * This interface is implemented by factories that create Apex models. It is mainly used by unit test classes that generate Apex models for test purposes. + * This interface is implemented by factories that create Apex models. It is mainly used by unit test classes that + * generate Apex models for test purposes. * * @author Liam Fallon (liam.fallon@ericsson.com) * @param the type of Apex model to create, must be a sub class of {@link AxModel} diff --git a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelException.java b/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelException.java index 8964a5bc2..17eb2639d 100644 --- a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelException.java +++ b/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelException.java @@ -43,9 +43,9 @@ public class ApexModelException extends ApexException { * Instantiates a new apex model handling exception. * * @param message the message - * @param e the e + * @param exception the exception */ - public ApexModelException(final String message, final Exception e) { - super(message, e); + public ApexModelException(final String message, final Exception exception) { + super(message, exception); } } diff --git a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelFileWriter.java b/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelFileWriter.java index 2312b88db..aead4cb2b 100644 --- a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelFileWriter.java +++ b/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelFileWriter.java @@ -57,8 +57,8 @@ public class ApexModelFileWriter { * @param modelFileName The name of the file to write to * @throws ApexException thrown on errors */ - public void apexModelWriteXMLFile(final M model, final Class rootModelClass, final String modelFileName) - throws ApexException { + public void apexModelWriteXmlFile(final M model, final Class rootModelClass, final String modelFileName) + throws ApexException { LOGGER.debug("running apexModelWriteXMLFile . . ."); final ApexModelWriter modelWriter = new ApexModelWriter<>(rootModelClass); @@ -80,8 +80,8 @@ public class ApexModelFileWriter { * @param modelFileName The name of the file to write to * @throws ApexException thrown on errors */ - public void apexModelWriteJSONFile(final M model, final Class rootModelClass, final String modelFileName) - throws ApexException { + public void apexModelWriteJsonFile(final M model, final Class rootModelClass, final String modelFileName) + throws ApexException { LOGGER.debug("running apexModelWriteJSONFile . . ."); final ApexModelWriter modelWriter = new ApexModelWriter<>(rootModelClass); @@ -119,7 +119,8 @@ public class ApexModelFileWriter { * @param modelFileName the file name of the file to write to * @throws ApexException on exceptions writing the model */ - private void writeModelFile(final M model, final ApexModelWriter modelWriter, final String modelFileName) throws ApexException { + private void writeModelFile(final M model, final ApexModelWriter modelWriter, final String modelFileName) + throws ApexException { final File modelFile = new File(modelFileName); if (!modelFile.getParentFile().exists() && !modelFile.getParentFile().mkdirs()) { LOGGER.warn("could not create directory " + modelFile.getParentFile()); @@ -130,8 +131,7 @@ public class ApexModelFileWriter { final FileOutputStream fileOutputStream = new FileOutputStream(modelFile); modelWriter.write(model, fileOutputStream); fileOutputStream.close(); - } - catch (final Exception e) { + } catch (final Exception e) { LOGGER.warn("error processing file " + modelFile.getAbsolutePath(), e); throw new ApexException("error processing file " + modelFile.getAbsolutePath(), e); } diff --git a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelReader.java b/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelReader.java index 6ca9c03d8..ce2c9fc56 100644 --- a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelReader.java +++ b/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelReader.java @@ -59,8 +59,10 @@ public class ApexModelReader { private static final XLogger LOGGER = XLoggerFactory.getXLogger(ApexModelReader.class); // Regular expressions for checking input types - private static final String XML_INPUT_TYPE_REGEXP = "^\\s*<\\?xml.*>\\s*"; // (starts with - private static final String JSON_INPUT_TYPE_REGEXP = "^\\s*[\\(\\{\\[][\\s+\\S]*[\\)\\}\\]]"; // starts with some kind of bracket [ or ( + // (starts with + private static final String XML_INPUT_TYPE_REGEXP = "^\\s*<\\?xml.*>\\s*"; + // starts with some kind of bracket [ or ( + private static final String JSON_INPUT_TYPE_REGEXP = "^\\s*[\\(\\{\\[][\\s+\\S]*[\\)\\}\\]]"; // or {, then has something, then has // and has a close bracket @@ -119,8 +121,9 @@ public class ApexModelReader { if (schemaFileName != null) { try { // Set the concept schema - final URL schemaURL = ResourceUtils.getUrlResource(schemaFileName); - final Schema apexConceptSchema = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI).newSchema(schemaURL); + final URL schemaUrl = ResourceUtils.getUrlResource(schemaFileName); + final Schema apexConceptSchema = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI) + .newSchema(schemaUrl); unmarshaller.setSchema(apexConceptSchema); } catch (final Exception e) { diff --git a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelSaver.java b/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelSaver.java index 16ea1f3fa..4f3008f04 100644 --- a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelSaver.java +++ b/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelSaver.java @@ -45,13 +45,13 @@ public class ApexModelSaver { private final String writePath; /** - * Constructor, specifies the type of the Apex model (a sub class of {@link AxModel}), the model to write, and the path of a directory to which to write the - * model. + * Constructor, specifies the type of the Apex model (a sub class of {@link AxModel}), the model to write, and the + * path of a directory to which to write the model. * * @param rootModelClass the class of the model, a sub class of {@link AxModel} * @param model the model to write, an instance of a sub class of {@link AxModel} - * @param writePath the directory to which models will be written. The name of the written model will be the Model Name for its key with the suffix - * {@code .xml} or {@code .json}. + * @param writePath the directory to which models will be written. The name of the written model will be the Model + * Name for its key with the suffix {@code .xml} or {@code .json}. */ public ApexModelSaver(final Class rootModelClass, final M model, final String writePath) { Assertions.argumentNotNull(rootModelClass, "argument rootModelClass may not be null"); @@ -68,12 +68,12 @@ public class ApexModelSaver { * * @throws ApexException on errors writing the Apex model */ - public void apexModelWriteXML() throws ApexException { + public void apexModelWriteXml() throws ApexException { LOGGER.debug("running apexModelWriteXML . . ."); // Write the file to disk final File xmlFile = new File(writePath + File.separatorChar + model.getKey().getName() + ".xml"); - new ApexModelFileWriter(true).apexModelWriteXMLFile(model, rootModelClass, xmlFile.getPath()); + new ApexModelFileWriter(true).apexModelWriteXmlFile(model, rootModelClass, xmlFile.getPath()); LOGGER.debug("ran apexModelWriteXML"); } @@ -83,12 +83,12 @@ public class ApexModelSaver { * * @throws ApexException on errors writing the Apex model */ - public void apexModelWriteJSON() throws ApexException { + public void apexModelWriteJson() throws ApexException { LOGGER.debug("running apexModelWriteJSON . . ."); // Write the file to disk final File jsonFile = new File(writePath + File.separatorChar + model.getKey().getName() + ".json"); - new ApexModelFileWriter(true).apexModelWriteJSONFile(model, rootModelClass, jsonFile.getPath()); + new ApexModelFileWriter(true).apexModelWriteJsonFile(model, rootModelClass, jsonFile.getPath()); LOGGER.debug("ran apexModelWriteJSON"); } diff --git a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelStringWriter.java b/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelStringWriter.java index 3d2e50b38..92a956bde 100644 --- a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelStringWriter.java +++ b/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelStringWriter.java @@ -58,13 +58,13 @@ public class ApexModelStringWriter { * @return The string with the concept * @throws ApexException thrown on errors */ - public String writeString(final C concept, final Class rootConceptClass, final boolean jsonFlag) throws ApexException { + public String writeString(final C concept, final Class rootConceptClass, final boolean jsonFlag) + throws ApexException { Assertions.argumentNotNull(concept, "concept may not be null"); - + if (jsonFlag) { - return writeJSONString(concept, rootConceptClass); - } - else { + return writeJsonString(concept, rootConceptClass); + } else { return concept.toString(); } } @@ -77,7 +77,7 @@ public class ApexModelStringWriter { * @return The string with the concept * @throws ApexException thrown on errors */ - public String writeXMLString(final C concept, final Class rootConceptClass) throws ApexException { + public String writeXmlString(final C concept, final Class rootConceptClass) throws ApexException { LOGGER.debug("running writeXMLString . . ."); final ApexModelWriter conceptWriter = new ApexModelWriter<>(rootConceptClass); @@ -90,8 +90,7 @@ public class ApexModelStringWriter { try { conceptWriter.write(concept, baOutputStream); baOutputStream.close(); - } - catch (final Exception e) { + } catch (final Exception e) { LOGGER.warn("error writing XML string", e); throw new ApexException("error writing XML string", e); } @@ -108,7 +107,7 @@ public class ApexModelStringWriter { * @return The string with the concept * @throws ApexException thrown on errors */ - public String writeJSONString(final C concept, final Class rootConceptClass) throws ApexException { + public String writeJsonString(final C concept, final Class rootConceptClass) throws ApexException { LOGGER.debug("running writeJSONString . . ."); final ApexModelWriter conceptWriter = new ApexModelWriter<>(rootConceptClass); @@ -119,8 +118,7 @@ public class ApexModelStringWriter { try { conceptWriter.write(concept, baOutputStream); baOutputStream.close(); - } - catch (final Exception e) { + } catch (final Exception e) { LOGGER.warn("error writing JSON string", e); throw new ApexException("error writing JSON string", e); } diff --git a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelWriter.java b/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelWriter.java index 2bea92cc6..977a8e7c6 100644 --- a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelWriter.java +++ b/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelWriter.java @@ -67,7 +67,7 @@ public class ApexModelWriter { private boolean jsonOutput = false; // The list of fields to output as CDATA - private final Set cDataFieldSet = new TreeSet<>(); + private final Set cdataFieldSet = new TreeSet<>(); // The Marshaller for the Apex concepts private Marshaller marshaller = null; @@ -104,7 +104,7 @@ public class ApexModelWriter { * @return the set of fields */ public Set getCDataFieldSet() { - return cDataFieldSet; + return cdataFieldSet; } /** @@ -176,14 +176,14 @@ public class ApexModelWriter { LOGGER.debug(validationResult.toString()); if (!validationResult.isValid()) { LOGGER.warn(validationResult.toString()); - throw new ApexModelException("Apex concept xml (" + concept.getKey().getID() + ") validation failed"); + throw new ApexModelException("Apex concept xml (" + concept.getKey().getId() + ") validation failed"); } } if (jsonOutput) { - writeJSON(concept, apexConceptWriter); + writeJson(concept, apexConceptWriter); } else { - writeXML(concept, apexConceptWriter); + writeXml(concept, apexConceptWriter); } } @@ -194,7 +194,7 @@ public class ApexModelWriter { * @param apexConceptWriter the writer to write to * @throws ApexModelException on validation or writing exceptions */ - private void writeXML(final C concept, final Writer apexConceptWriter) throws ApexModelException { + private void writeXml(final C concept, final Writer apexConceptWriter) throws ApexModelException { Assertions.argumentNotNull(concept, CONCEPT_MAY_NOT_BE_NULL); LOGGER.debug("writing Apex concept XML . . ."); @@ -212,7 +212,7 @@ public class ApexModelWriter { // Convert the cDataFieldSet into a space delimited string domTransformer.setOutputProperty(OutputKeys.CDATA_SECTION_ELEMENTS, - cDataFieldSet.toString().replaceAll("[\\[\\]\\,]", " ")); + cdataFieldSet.toString().replaceAll("[\\[\\]\\,]", " ")); domTransformer.transform(new DOMSource(document), new StreamResult(apexConceptWriter)); } catch (JAXBException | TransformerException | ParserConfigurationException e) { LOGGER.warn("Unable to marshal Apex concept XML", e); @@ -245,7 +245,7 @@ public class ApexModelWriter { * @param apexConceptWriter the writer to write to * @throws ApexModelException on validation or writing exceptions */ - private void writeJSON(final C concept, final Writer apexConceptWriter) throws ApexModelException { + private void writeJson(final C concept, final Writer apexConceptWriter) throws ApexModelException { Assertions.argumentNotNull(concept, CONCEPT_MAY_NOT_BE_NULL); LOGGER.debug("writing Apex concept JSON . . ."); diff --git a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/handling/ApexSchemaGenerator.java b/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/handling/ApexSchemaGenerator.java index 6e17ab94d..46e30bf10 100644 --- a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/handling/ApexSchemaGenerator.java +++ b/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/handling/ApexSchemaGenerator.java @@ -53,20 +53,17 @@ public class ApexSchemaGenerator { if (args.length == 1) { printStream = System.out; - } - else if (args.length == 2) { + } else if (args.length == 2) { final File schemaFile = new File(args[1]); try { schemaFile.getParentFile().mkdirs(); printStream = new PrintStream(schemaFile); - } - catch (final Exception e) { + } catch (final Exception e) { LOGGER.error("error on Apex schema output", e); return; } - } - else { + } else { LOGGER.error("usage: ApexSchemaGenerator apex-root-class [schema-file-name]"); return; } @@ -90,12 +87,10 @@ public class ApexSchemaGenerator { JAXBContext jaxbContext; try { jaxbContext = JAXBContext.newInstance(Class.forName(rootClassName)); - } - catch (final ClassNotFoundException e) { + } catch (final ClassNotFoundException e) { LOGGER.error("could not create JAXB context, root class " + rootClassName + " not found", e); return null; - } - catch (final JAXBException e) { + } catch (final JAXBException e) { LOGGER.error("could not create JAXB context", e); return null; } @@ -103,8 +98,7 @@ public class ApexSchemaGenerator { final ApexSchemaOutputResolver sor = new ApexSchemaOutputResolver(); try { jaxbContext.generateSchema(sor); - } - catch (final IOException e) { + } catch (final IOException e) { LOGGER.error("error generating the Apex schema (XSD) file", e); return null; } @@ -116,22 +110,26 @@ public class ApexSchemaGenerator { } /** - * There is a bug in schema generation that does not specify the elements from Java Maps as being unqualified. This method "hacks" those - * elements in the schema to fix this, the elements being {@code entry}, {@code key}, and {@code value} + * There is a bug in schema generation that does not specify the elements from Java Maps as being unqualified. This + * method "hacks" those elements in the schema to fix this, the elements being {@code entry}, {@code key}, and + * {@code value} * * @param schemaString The schema in which elements should be fixed * @return the string */ private String fixForUnqualifiedBug(final String schemaString) { // Fix the "entry" element - String newSchemaString = schemaString.replaceAll("", - ""); + String newSchemaString = schemaString.replaceAll( + "", + ""); // Fix the "key" element - newSchemaString = newSchemaString.replaceAll("The reason for having a model service is to avoid having to pass concept and model definitions down long call + * chains in modules such as the Apex engine and editor. The model service makes the model and concept definitions + * available statically. * - * Note that the use of the model service means that only a single Apex model of a particular type may exist in Apex (particularly the engine) at any time. Of - * course the model in a JVM can be changed at any time provided all users of the model are stopped and restrted in an orderly manner. + *

Note that the use of the model service means that only a single Apex model of a particular type may exist in + * Apex (particularly the engine) at any time. Of course the model in a JVM can be changed at any time provided all + * users of the model are stopped and restarted in an orderly manner. * * @author Liam Fallon (liam.fallon@ericsson.com) */ @@ -80,7 +82,8 @@ public abstract class ModelService { final M model = (M) modelMap.get(modelClass); if (model == null) { - throw new ApexRuntimeException("Model for " + modelClass.getCanonicalName() + " not found in model service"); + throw new ApexRuntimeException( + "Model for " + modelClass.getCanonicalName() + " not found in model service"); } return model; diff --git a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/test/TestApexModel.java b/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/test/TestApexModel.java index 356afd723..81b3373e1 100644 --- a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/test/TestApexModel.java +++ b/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/test/TestApexModel.java @@ -30,7 +30,7 @@ import org.onap.policy.apex.model.basicmodel.concepts.AxModel; 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.dao.DaoParameters; import org.onap.policy.apex.model.basicmodel.handling.ApexModelFileWriter; import org.onap.policy.apex.model.basicmodel.handling.ApexModelReader; import org.onap.policy.apex.model.basicmodel.handling.ApexModelWriter; @@ -39,19 +39,19 @@ import org.slf4j.ext.XLogger; import org.slf4j.ext.XLoggerFactory; /** - * This class tests reading and writing of Apex models to file and to a database using JPA. It also tests validation of Apex models. This class is designed for - * use in unit tests in modules that define Apex models. + * This class tests reading and writing of Apex models to file and to a database using JPA. It also tests validation of + * Apex models. This class is designed for use in unit tests in modules that define Apex models. * * @author Liam Fallon (liam.fallon@ericsson.com) * @param the generic type */ public class TestApexModel { private static final String MODEL_IS_INVALID = "model is invalid "; - private static final String ERROR_PROCESSING_FILE = "error processing file "; - private static final String TEST_MODEL_DOES_NOT_EQUAL_MODEL_READ_FROM_XML_FILE = "test model does not equal model read from XML file "; - private static final String ERROR_CREATING_TEMPORARY_FILE_FOR_APEX_MODEL = "error creating temporary file for Apex model"; + private static final String ERROR_PROCESSING_FILE = "error processing file "; + private static final String TEST_MODEL_UNEQUAL_STR = "test model does not equal model read from XML file "; + private static final String TEMP_FILE_CREATE_ERR_STR = "error creating temporary file for Apex model"; - private static final XLogger LOGGER = XLoggerFactory.getXLogger(TestApexModel.class); + private static final XLogger LOGGER = XLoggerFactory.getXLogger(TestApexModel.class); // The root model class that specifies the root to import and export from private final Class rootModelClass; @@ -60,8 +60,8 @@ public class TestApexModel { private TestApexModelCreator modelCreator = null; /** - * Constructor, defines the subclass of {@link AxModel} that is being tested and the {@link TestApexModelCreator} object that is used to generate Apex - * models. + * Constructor, defines the subclass of {@link AxModel} that is being tested and the {@link TestApexModelCreator} + * object that is used to generate Apex models. * * @param rootModelClass the Apex model class, a sub class of {@link AxModel} * @param modelCreator the @link TestApexModelCreator} that will generate Apex models of various types for testing @@ -85,36 +85,34 @@ public class TestApexModel { * * @throws ApexException on write/read errors */ - public final void testApexModelWriteReadXML() throws ApexException { + public final void testApexModelWriteReadXml() throws ApexException { LOGGER.debug("running testApexModelWriteReadXML . . ."); final M model = modelCreator.getModel(); // Write the file to disk File xmlFile; - + try { xmlFile = File.createTempFile("ApexModel", ".xml"); xmlFile.deleteOnExit(); + } catch (final Exception e) { + LOGGER.warn(TEMP_FILE_CREATE_ERR_STR, e); + throw new ApexException(TEMP_FILE_CREATE_ERR_STR, e); } - catch (final Exception e) { - LOGGER.warn(ERROR_CREATING_TEMPORARY_FILE_FOR_APEX_MODEL, e); - throw new ApexException(ERROR_CREATING_TEMPORARY_FILE_FOR_APEX_MODEL, e); - } - new ApexModelFileWriter(true).apexModelWriteXMLFile(model, rootModelClass, xmlFile.getPath()); + new ApexModelFileWriter(true).apexModelWriteXmlFile(model, rootModelClass, xmlFile.getPath()); // Read the file from disk final ApexModelReader modelReader = new ApexModelReader<>(rootModelClass); try { - final URL apexModelURL = ResourceUtils.getLocalFile(xmlFile.getAbsolutePath()); - final M fileModel = modelReader.read(apexModelURL.openStream()); + final URL apexModelUrl = ResourceUtils.getLocalFile(xmlFile.getAbsolutePath()); + final M fileModel = modelReader.read(apexModelUrl.openStream()); if (!model.equals(fileModel)) { - LOGGER.warn(TEST_MODEL_DOES_NOT_EQUAL_MODEL_READ_FROM_XML_FILE + xmlFile.getAbsolutePath()); - throw new ApexException(TEST_MODEL_DOES_NOT_EQUAL_MODEL_READ_FROM_XML_FILE + xmlFile.getAbsolutePath()); + LOGGER.warn(TEST_MODEL_UNEQUAL_STR + xmlFile.getAbsolutePath()); + throw new ApexException(TEST_MODEL_UNEQUAL_STR + xmlFile.getAbsolutePath()); } - } - catch (final Exception e) { + } catch (final Exception e) { LOGGER.warn(ERROR_PROCESSING_FILE + xmlFile.getAbsolutePath(), e); throw new ApexException(ERROR_PROCESSING_FILE + xmlFile.getAbsolutePath(), e); } @@ -141,7 +139,7 @@ public class TestApexModel { * * @throws ApexException on write/read errors */ - public final void testApexModelWriteReadJSON() throws ApexException { + public final void testApexModelWriteReadJson() throws ApexException { LOGGER.debug("running testApexModelWriteReadJSON . . ."); final M model = modelCreator.getModel(); @@ -151,25 +149,24 @@ public class TestApexModel { try { jsonFile = File.createTempFile("ApexModel", ".xml"); jsonFile.deleteOnExit(); + } catch (final Exception e) { + LOGGER.warn(TEMP_FILE_CREATE_ERR_STR, e); + throw new ApexException(TEMP_FILE_CREATE_ERR_STR, e); } - catch (final Exception e) { - LOGGER.warn(ERROR_CREATING_TEMPORARY_FILE_FOR_APEX_MODEL, e); - throw new ApexException(ERROR_CREATING_TEMPORARY_FILE_FOR_APEX_MODEL, e); - } - new ApexModelFileWriter(true).apexModelWriteJSONFile(model, rootModelClass, jsonFile.getPath()); + new ApexModelFileWriter(true).apexModelWriteJsonFile(model, rootModelClass, jsonFile.getPath()); // Read the file from disk final ApexModelReader modelReader = new ApexModelReader<>(rootModelClass); try { - final URL apexModelURL = ResourceUtils.getLocalFile(jsonFile.getAbsolutePath()); - final M fileModel = modelReader.read(apexModelURL.openStream()); + final URL apexModelUrl = ResourceUtils.getLocalFile(jsonFile.getAbsolutePath()); + final M fileModel = modelReader.read(apexModelUrl.openStream()); if (!model.equals(fileModel)) { - LOGGER.warn(TEST_MODEL_DOES_NOT_EQUAL_MODEL_READ_FROM_XML_FILE + jsonFile.getAbsolutePath()); - throw new ApexException(TEST_MODEL_DOES_NOT_EQUAL_MODEL_READ_FROM_XML_FILE + jsonFile.getAbsolutePath()); + LOGGER.warn(TEST_MODEL_UNEQUAL_STR + jsonFile.getAbsolutePath()); + throw new ApexException( + TEST_MODEL_UNEQUAL_STR + jsonFile.getAbsolutePath()); } - } - catch (final Exception e) { + } catch (final Exception e) { LOGGER.warn(ERROR_PROCESSING_FILE + jsonFile.getAbsolutePath(), e); throw new ApexException(ERROR_PROCESSING_FILE + jsonFile.getAbsolutePath(), e); } @@ -195,7 +192,7 @@ public class TestApexModel { * @param daoParameters the DAO parameters to use for JPA/JDBC * @throws ApexException thrown on errors writing or reading the model to database */ - public final void testApexModelWriteReadJPA(final DAOParameters daoParameters) throws ApexException { + public final void testApexModelWriteReadJpa(final DaoParameters daoParameters) throws ApexException { LOGGER.debug("running testApexModelWriteReadJPA . . ."); final M model = modelCreator.getModel(); @@ -204,10 +201,10 @@ public class TestApexModel { apexDao.init(daoParameters); apexDao.create(model); - final M dbJPAModel = apexDao.get(rootModelClass, model.getKey()); + final M dbJpaModel = apexDao.get(rootModelClass, model.getKey()); apexDao.close(); - if (!model.equals(dbJPAModel)) { + if (!model.equals(dbJpaModel)) { LOGGER.warn("test model does not equal model written and read using generic JPA"); throw new ApexException("test model does not equal model written and read using generic JPA"); } diff --git a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/test/TestApexModelCreator.java b/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/test/TestApexModelCreator.java index 980748926..65441a33c 100644 --- a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/test/TestApexModelCreator.java +++ b/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/test/TestApexModelCreator.java @@ -24,8 +24,8 @@ import org.onap.policy.apex.model.basicmodel.concepts.AxModel; import org.onap.policy.apex.model.basicmodel.handling.ApexModelCreator; /** - * The Interface TestApexModelCreator is used to create models for Apex model tests. It is mainly used by unit tests for Apex domain models so that - * developers can write test Java programs to create models. + * The Interface TestApexModelCreator is used to create models for Apex model tests. It is mainly used by unit tests for + * Apex domain models so that developers can write test Java programs to create models. * * @author Liam Fallon (liam.fallon@ericsson.com) * @param the generic type -- cgit 1.2.3-korg