summaryrefslogtreecommitdiffstats
path: root/model/basic-model/src
diff options
context:
space:
mode:
Diffstat (limited to 'model/basic-model/src')
-rw-r--r--model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/concepts/AxArtifactKey.java21
-rw-r--r--model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/concepts/AxConcept.java12
-rw-r--r--model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/concepts/AxKeyInfo.java41
-rw-r--r--model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/concepts/AxKeyInformation.java58
-rw-r--r--model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/concepts/AxModel.java37
-rw-r--r--model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/concepts/AxReferenceKey.java143
-rw-r--r--model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/concepts/package-info.java9
-rw-r--r--model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/dao/ApexDao.java206
-rw-r--r--model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/dao/ApexDaoFactory.java70
-rw-r--r--model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/dao/DaoParameters.java123
-rw-r--r--model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/dao/converters/CDataConditioner.java83
-rw-r--r--model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/dao/converters/Uuid2String.java73
-rw-r--r--model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/dao/converters/package-info.java28
-rw-r--r--model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/dao/impl/DefaultApexDao.java497
-rw-r--r--model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/dao/impl/package-info.java27
-rw-r--r--model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/dao/package-info.java29
-rw-r--r--model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelCustomGsonMapAdapter.java118
-rw-r--r--model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelCustomGsonRefereceKeyAdapter.java50
-rw-r--r--model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelFileWriter.java58
-rw-r--r--model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelReader.java157
-rw-r--r--model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelSaver.java21
-rw-r--r--model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelStringWriter.java71
-rw-r--r--model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelWriter.java216
-rw-r--r--model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/handling/ApexSchemaGenerator.java161
-rw-r--r--model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/handling/KeyInfoMarshalFilter.java104
-rw-r--r--model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/handling/package-info.java17
-rw-r--r--model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/package-info.java4
-rw-r--r--model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/test/TestApexModel.java81
-rw-r--r--model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/xml/AxReferenceKeyAdapter.java58
-rw-r--r--model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/xml/package-info.java34
-rw-r--r--model/basic-model/src/main/resources/xml/example.xsd100
-rw-r--r--model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/concepts/AxKeyInfoTest.java7
-rw-r--r--model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/concepts/DummyEntity.java15
-rw-r--r--model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/dao/DaoMiscTest.java77
-rw-r--r--model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/dao/EntityTest.java262
-rw-r--r--model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelFileWriterTest.java34
-rw-r--r--model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelReaderTest.java77
-rw-r--r--model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelSaverTest.java8
-rw-r--r--model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelStringWriterTest.java29
-rw-r--r--model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelWriterTest.java108
-rw-r--r--model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ApexSchemaGeneratorTest.java95
-rw-r--r--model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/SupportApexBasicModelTest.java89
-rw-r--r--model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/SupportBasicModelTest.java8
-rw-r--r--model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/SupportConceptGetterTest.java24
-rw-r--r--model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/xml/AxReferenceKeyAdapterTest.java42
-rw-r--r--model/basic-model/src/test/resources/META-INF/persistence.xml43
46 files changed, 442 insertions, 3183 deletions
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 1edbc9be9..1efe83db8 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
@@ -1,7 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
- * Modifications Copyright (C) 2019-2021 Nordix Foundation.
+ * Modifications Copyright (C) 2019-2022 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -23,13 +23,6 @@ package org.onap.policy.apex.model.basicmodel.concepts;
import java.util.ArrayList;
import java.util.List;
-import javax.persistence.Column;
-import javax.persistence.Embeddable;
-import javax.xml.bind.annotation.XmlAccessType;
-import javax.xml.bind.annotation.XmlAccessorType;
-import javax.xml.bind.annotation.XmlElement;
-import javax.xml.bind.annotation.XmlRootElement;
-import javax.xml.bind.annotation.XmlType;
import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult.ValidationResult;
import org.onap.policy.common.utils.validation.Assertions;
@@ -41,25 +34,13 @@ import org.onap.policy.common.utils.validation.Assertions;
* <p>Key validation checks that the name and version fields match the NAME_REGEXP and 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" })
-
public class AxArtifactKey extends AxKey {
private static final long serialVersionUID = 8932717618579392561L;
private static final String NAME_TOKEN = "name";
private static final String VERSION_TOKEN = "version";
- @Column(name = NAME_TOKEN)
- @XmlElement(required = true)
private String name;
-
- @Column(name = VERSION_TOKEN)
- @XmlElement(required = true)
private String version;
/**
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 0e2c6bef2..37fe30b33 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
@@ -1,7 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
- * Modifications Copyright (C) 2019 Nordix Foundation.
+ * Modifications Copyright (C) 2019,2022 Nordix Foundation.
* Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -24,7 +24,6 @@ package org.onap.policy.apex.model.basicmodel.concepts;
import java.io.Serializable;
import java.util.List;
-import javax.xml.bind.annotation.XmlType;
import org.onap.policy.common.utils.validation.Assertions;
/**
@@ -33,9 +32,6 @@ import org.onap.policy.common.utils.validation.Assertions;
*
* @author Liam Fallon (liam.fallon@ericsson.com)
*/
-
-@XmlType(name = "AxConcept", namespace = "http://www.onap.org/policy/apex-pdp")
-
public abstract class AxConcept implements Serializable, Comparable<AxConcept> {
private static final long serialVersionUID = -7434939557282697490L;
@@ -86,6 +82,12 @@ public abstract class AxConcept implements Serializable, Comparable<AxConcept> {
public abstract void clean();
/**
+ * Builds references used by a concept.
+ */
+ public void buildReferences() {
+ }
+
+ /**
* {@inheritDoc}.
*/
@Override
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 7e92faddf..bd3b18ec9 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
@@ -1,7 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
- * Modifications Copyright (C) 2019-2021 Nordix Foundation.
+ * Modifications Copyright (C) 2019-2022 Nordix Foundation.
* Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -22,24 +22,12 @@
package org.onap.policy.apex.model.basicmodel.concepts;
+import com.google.gson.annotations.SerializedName;
import java.util.List;
import java.util.Random;
import java.util.UUID;
-import javax.persistence.Column;
-import javax.persistence.Convert;
-import javax.persistence.EmbeddedId;
-import javax.persistence.Entity;
-import javax.persistence.Table;
-import javax.xml.bind.annotation.XmlAccessType;
-import javax.xml.bind.annotation.XmlAccessorType;
-import javax.xml.bind.annotation.XmlElement;
-import javax.xml.bind.annotation.XmlRootElement;
-import javax.xml.bind.annotation.XmlType;
-import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
import org.apache.commons.lang3.StringUtils;
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.common.utils.validation.Assertions;
/**
@@ -49,19 +37,9 @@ import org.onap.policy.common.utils.validation.Assertions;
* <p>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
-@Table(name = "AxKeyInfo")
-
-@XmlAccessorType(XmlAccessType.FIELD)
-@XmlRootElement(name = "apexKeyInfo", namespace = "http://www.onap.org/policy/apex-pdp")
-@XmlType(name = "AxKeyInfo", namespace = "http://www.onap.org/policy/apex-pdp",
- propOrder = { "key", "uuid", "description" })
-
public class AxKeyInfo extends AxConcept {
private static final long serialVersionUID = -4023935924068914308L;
- private static final int MAX_DESCRIPTION_LENGTH_8192 = 8192;
private static final int UUID_BYTE_LENGTH_16 = 16;
/*
@@ -69,20 +47,11 @@ public class AxKeyInfo extends AxConcept {
*/
private static final Random sharedRandom = new Random(); // NOSONAR
- @EmbeddedId
- @XmlElement(name = "key", required = true)
private AxArtifactKey key;
- @Column(name = "uuid")
- @Convert(converter = Uuid2String.class)
- @XmlJavaTypeAdapter(value = Uuid2String.class)
- @XmlElement(name = "UUID", required = true)
+ @SerializedName("UUID")
private UUID uuid;
- @Column(name = "description", length = MAX_DESCRIPTION_LENGTH_8192)
- @Convert(converter = CDataConditioner.class)
- @XmlJavaTypeAdapter(value = CDataConditioner.class)
- @XmlElement(required = true)
private String description;
/**
@@ -299,9 +268,7 @@ 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);
- return thisdesc.equals(otherdesc);
+ return description.equals(description);
}
/**
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 6da5ab3a8..439b2960f 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
@@ -1,7 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
- * Modifications Copyright (C) 2019-2021 Nordix Foundation.
+ * Modifications Copyright (C) 2019-2022 Nordix Foundation.
* Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -30,18 +30,6 @@ import java.util.Set;
import java.util.TreeMap;
import java.util.TreeSet;
import java.util.UUID;
-import javax.persistence.CascadeType;
-import javax.persistence.EmbeddedId;
-import javax.persistence.Entity;
-import javax.persistence.JoinColumn;
-import javax.persistence.JoinTable;
-import javax.persistence.ManyToMany;
-import javax.persistence.Table;
-import javax.xml.bind.Unmarshaller;
-import javax.xml.bind.annotation.XmlAccessType;
-import javax.xml.bind.annotation.XmlAccessorType;
-import javax.xml.bind.annotation.XmlElement;
-import javax.xml.bind.annotation.XmlType;
import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult.ValidationResult;
import org.onap.policy.common.utils.validation.Assertions;
@@ -55,29 +43,11 @@ import org.onap.policy.common.utils.validation.Assertions;
* 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
-@Table(name = "AxKeyInformation")
-
-@XmlAccessorType(XmlAccessType.FIELD)
-@XmlType(name = "AxKeyInformation", namespace = "http://www.onap.org/policy/apex-pdp",
- propOrder = { "key", "keyInfoMap" })
-
public class AxKeyInformation extends AxConcept implements AxConceptGetter<AxKeyInfo> {
private static final long serialVersionUID = -2746380769017043888L;
- @EmbeddedId
- @XmlElement(name = "key", required = true)
private AxArtifactKey key;
-
- // @formatter:off
- @ManyToMany(cascade = CascadeType.ALL)
- @JoinTable(
- joinColumns = { @JoinColumn(name = "keyInfoMapName", referencedColumnName = "name"),
- @JoinColumn(name = "keyInfoMapVersion", referencedColumnName = "version"), },
- inverseJoinColumns = { @JoinColumn(name = "keyInfoName", referencedColumnName = "name"),
- @JoinColumn(name = "keyInfoVersion", referencedColumnName = "version") })
private Map<AxArtifactKey, AxKeyInfo> keyInfoMap;
- // @formatter:on
/**
* The Default Constructor creates this concept with a null key.
@@ -121,22 +91,6 @@ public class AxKeyInformation extends AxConcept implements AxConceptGetter<AxKey
}
/**
- * When a model is unmarshalled from disk or from the database, the key information map is returned as a raw Hash
- * Map. This method is called by JAXB after unmarshaling and is used to convert the hash map to a
- * {@link NavigableMap} so that it will work with the {@link AxConceptGetter} interface.
- *
- * @param unmarshaler the unmarshaler that is unmarshaling the model
- * @param parent the parent object of this object in the unmarshaler
- */
- public void afterUnmarshal(final Unmarshaller unmarshaler, final Object parent) {
- // The map must be navigable to allow name and version searching,
- // unmarshaling returns a hash map
- final NavigableMap<AxArtifactKey, AxKeyInfo> navigablekeyInfoMap = new TreeMap<>();
- navigablekeyInfoMap.putAll(keyInfoMap);
- keyInfoMap = navigablekeyInfoMap;
- }
-
- /**
* This method generates default key information for all keys found in the concept passed in as a parameter that do
* not already have key information.
*
@@ -179,6 +133,14 @@ public class AxKeyInformation extends AxConcept implements AxConceptGetter<AxKey
}
/**
+ * {@inheritDoc}.
+ */
+ @Override
+ public void buildReferences() {
+ keyInfoMap.values().stream().forEach(keyInfo -> keyInfo.buildReferences());
+ }
+
+ /**
* Sets the key of this concept.
*
* @param key the key of this concept
@@ -237,7 +199,7 @@ public class AxKeyInformation extends AxConcept implements AxConceptGetter<AxKey
}
/**
- * Validate an key information entry.
+ * Validate a key information entry.
*
* @param keyInfoEntry the key information entry
* @param uuidSet the set of UUIDs encountered in validation so far, the UUID of this entry is added to the set
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 b29743c0b..ce52b147f 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
@@ -1,7 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
- * Modifications Copyright (C) 2019-2021 Nordix Foundation.
+ * Modifications Copyright (C) 2019-2022 Nordix Foundation.
* Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -25,22 +25,7 @@ package org.onap.policy.apex.model.basicmodel.concepts;
import java.util.List;
import java.util.Set;
import java.util.TreeSet;
-import javax.persistence.CascadeType;
-import javax.persistence.EmbeddedId;
-import javax.persistence.Entity;
-import javax.persistence.Inheritance;
-import javax.persistence.InheritanceType;
-import javax.persistence.JoinColumn;
-import javax.persistence.OneToOne;
-import javax.persistence.Table;
-import javax.xml.bind.annotation.XmlAccessType;
-import javax.xml.bind.annotation.XmlAccessorType;
-import javax.xml.bind.annotation.XmlElement;
-import javax.xml.bind.annotation.XmlRootElement;
-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.handling.KeyInfoMarshalFilter;
import org.onap.policy.apex.model.basicmodel.service.ModelService;
import org.onap.policy.common.utils.validation.Assertions;
@@ -55,33 +40,13 @@ import org.onap.policy.common.utils.validation.Assertions;
* {@link AxArtifactKey} and {@link AxReferenceKey} usage references a key that exists. Finally, a check is made to
* ensure that an {@link AxArtifactKey} instance exists for every {@link AxKeyInfo} instance.
*/
-
-@Entity
-@Table(name = "AxModel")
-@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
-
-@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" })
-
public class AxModel extends AxConcept {
private static final String IS_A_NULL_KEY = " is a null key";
private static final long serialVersionUID = -771659065637205430L;
- @EmbeddedId
- @XmlElement(name = "key", required = true)
private AxArtifactKey key;
-
- // @formatter:off
- @OneToOne(cascade = CascadeType.ALL)
- @JoinColumn(name = "keyInformationName", referencedColumnName = "name")
- @JoinColumn(name = "keyInformationVersion", referencedColumnName = "version")
- @XmlElement(name = "keyInformation", required = true)
- @XmlJavaTypeAdapter(KeyInfoMarshalFilter.class)
private AxKeyInformation keyInformation;
- // @formatter:on
/**
* The Default Constructor creates this concept with a NULL artifact key.
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 03a75a7fb..b37bc47e4 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
@@ -1,7 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
- * Modifications Copyright (C) 2019-2021 Nordix Foundation.
+ * Modifications Copyright (C) 2019-2022 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -23,13 +23,6 @@ package org.onap.policy.apex.model.basicmodel.concepts;
import java.util.ArrayList;
import java.util.List;
-import javax.persistence.Column;
-import javax.persistence.Embeddable;
-import javax.xml.bind.annotation.XmlAccessType;
-import javax.xml.bind.annotation.XmlAccessorType;
-import javax.xml.bind.annotation.XmlElement;
-import javax.xml.bind.annotation.XmlRootElement;
-import javax.xml.bind.annotation.XmlType;
import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult.ValidationResult;
import org.onap.policy.common.utils.validation.Assertions;
@@ -50,12 +43,6 @@ import org.onap.policy.common.utils.validation.Assertions;
* VERSION_REGEXP regular expressions respectively and that the local name fields match the
* LOCAL_NAME_REGEXP regular expression.
*/
-@Embeddable
-@XmlAccessorType(XmlAccessType.FIELD)
-@XmlRootElement(name = "apexReferenceKey", namespace = "http://www.onap.org/policy/apex-pdp")
-@XmlType(name = "AxReferenceKey", namespace = "http://www.onap.org/policy/apex-pdp", propOrder = { "parentKeyName",
- "parentKeyVersion", "parentLocalName", "localName" })
-
public class AxReferenceKey extends AxKey {
private static final String PARENT_KEY_NAME = "parentKeyName";
private static final String PARENT_KEY_VERSION = "parentKeyVersion";
@@ -64,32 +51,25 @@ public class AxReferenceKey extends AxKey {
private static final long serialVersionUID = 8932717618579392561L;
- /** Regular expression to specify the structure of local names in reference keys. */
+ /**
+ * Regular expression to specify the structure of local names in reference keys.
+ */
public static final String LOCAL_NAME_REGEXP = "[A-Za-z0-9\\-_\\.]+|^$";
- /** Regular expression to specify the structure of IDs in reference keys. */
+ /**
+ * 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\\-_]+";
+ "[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;
private static final int PARENT_LOCAL_NAME_FIELD = 2;
private static final int LOCAL_NAME_FIELD = 3;
- @Column(name = PARENT_KEY_NAME)
- @XmlElement(required = true)
private String parentKeyName;
-
- @Column(name = PARENT_KEY_VERSION)
- @XmlElement(required = true)
private String parentKeyVersion;
-
- @Column(name = PARENT_LOCAL_NAME)
- @XmlElement(required = true)
private String parentLocalName;
-
- @Column(name = LOCAL_NAME)
- @XmlElement(required = true)
private String localName;
/**
@@ -102,19 +82,17 @@ public class AxReferenceKey extends AxKey {
/**
* The Copy Constructor creates a key by copying another key.
*
- * @param referenceKey
- * the reference key to copy from
+ * @param referenceKey the reference key to copy from
*/
public AxReferenceKey(final AxReferenceKey referenceKey) {
this(referenceKey.getParentKeyName(), referenceKey.getParentKeyVersion(), referenceKey.getParentLocalName(),
- referenceKey.getLocalName());
+ referenceKey.getLocalName());
}
/**
* Constructor to create a null reference key for the specified parent artifact key.
*
- * @param axArtifactKey
- * the parent artifact key of this reference key
+ * @param axArtifactKey the parent artifact key of this reference key
*/
public AxReferenceKey(final AxArtifactKey axArtifactKey) {
this(axArtifactKey.getName(), axArtifactKey.getVersion(), NULL_KEY_NAME, NULL_KEY_NAME);
@@ -123,10 +101,8 @@ public class AxReferenceKey extends AxKey {
/**
* Constructor to create a reference key for the given parent artifact key with the given local name.
*
- * @param axArtifactKey
- * the parent artifact key of this reference key
- * @param localName
- * the local name of this reference key
+ * @param axArtifactKey the parent artifact key of this reference key
+ * @param localName the local name of this reference key
*/
public AxReferenceKey(final AxArtifactKey axArtifactKey, final String localName) {
this(axArtifactKey, NULL_KEY_NAME, localName);
@@ -135,10 +111,8 @@ public class AxReferenceKey extends AxKey {
/**
* Constructor to create a reference key for the given parent reference key with the given local name.
*
- * @param parentReferenceKey
- * the parent reference key of this reference key
- * @param localName
- * the local name of this reference key
+ * @param parentReferenceKey the parent reference key of this reference key
+ * @param localName the local name of this reference key
*/
public AxReferenceKey(final AxReferenceKey parentReferenceKey, final String localName) {
this(parentReferenceKey.getParentArtifactKey(), parentReferenceKey.getLocalName(), localName);
@@ -148,12 +122,9 @@ public class AxReferenceKey extends AxKey {
* Constructor to create a reference key for the given parent reference key (specified by the parent reference key's
* artifact key and local name) with the given local name.
*
- * @param axArtifactKey
- * the artifact key of the parent reference key of this reference key
- * @param parentLocalName
- * the local name of the parent reference key of this reference key
- * @param localName
- * the local name of this reference key
+ * @param axArtifactKey the artifact key of the parent reference key of this reference key
+ * @param parentLocalName the local name of the parent reference key of this reference key
+ * @param localName the local name of this reference key
*/
public AxReferenceKey(final AxArtifactKey axArtifactKey, final String parentLocalName, final String localName) {
this(axArtifactKey.getName(), axArtifactKey.getVersion(), parentLocalName, localName);
@@ -163,12 +134,9 @@ public class AxReferenceKey extends AxKey {
* Constructor to create a reference key for the given parent artifact key (specified by the parent artifact key's
* name and version) with the given local name.
*
- * @param parentKeyName
- * the name of the parent artifact key of this reference key
- * @param parentKeyVersion
- * the version of the parent artifact key of this reference key
- * @param localName
- * the local name of this reference key
+ * @param parentKeyName the name of the parent artifact key of this reference key
+ * @param parentKeyVersion the version of the parent artifact key of this reference key
+ * @param localName the local name of this reference key
*/
public AxReferenceKey(final String parentKeyName, final String parentKeyVersion, final String localName) {
this(parentKeyName, parentKeyVersion, NULL_KEY_NAME, localName);
@@ -178,31 +146,26 @@ public class AxReferenceKey extends AxKey {
* Constructor to create a reference key for the given parent key (specified by the parent key's name, version nad
* local name) with the given local name.
*
- * @param parentKeyName
- * the parent key name of this reference key
- * @param parentKeyVersion
- * the parent key version of this reference key
- * @param parentLocalName
- * the parent local name of this reference key
- * @param localName
- * the local name of this reference key
+ * @param parentKeyName the parent key name of this reference key
+ * @param parentKeyVersion the parent key version of this reference key
+ * @param parentLocalName the parent local name of this reference key
+ * @param localName the local name of this reference key
*/
public AxReferenceKey(final String parentKeyName, final String parentKeyVersion, final String parentLocalName,
- final String localName) {
+ final String localName) {
super();
this.parentKeyName = Assertions.validateStringParameter(PARENT_KEY_NAME, parentKeyName, NAME_REGEXP);
this.parentKeyVersion = Assertions.validateStringParameter(PARENT_KEY_VERSION, parentKeyVersion,
- VERSION_REGEXP);
+ VERSION_REGEXP);
this.parentLocalName = Assertions.validateStringParameter(PARENT_LOCAL_NAME, parentLocalName,
- LOCAL_NAME_REGEXP);
+ LOCAL_NAME_REGEXP);
this.localName = Assertions.validateStringParameter(LOCAL_NAME, localName, LOCAL_NAME_REGEXP);
}
/**
* Constructor to create a key from the specified key ID.
*
- * @param id
- * the key ID in a format that respects the KEY_ID_REGEXP
+ * @param id the key ID in a format that respects the KEY_ID_REGEXP
*/
public AxReferenceKey(final String id) {
final var conditionedId = Assertions.validateStringParameter("id", id, REFERENCE_KEY_ID_REGEXP);
@@ -215,13 +178,13 @@ public class AxReferenceKey extends AxKey {
// Initiate the new key
parentKeyName = Assertions.validateStringParameter(PARENT_KEY_NAME, nameVersionNameArray[PARENT_NAME_FIELD],
- NAME_REGEXP);
+ NAME_REGEXP);
parentKeyVersion = Assertions.validateStringParameter(PARENT_KEY_VERSION,
- nameVersionNameArray[PARENT_VERSION_FIELD], VERSION_REGEXP);
+ nameVersionNameArray[PARENT_VERSION_FIELD], VERSION_REGEXP);
parentLocalName = Assertions.validateStringParameter(PARENT_LOCAL_NAME,
- nameVersionNameArray[PARENT_LOCAL_NAME_FIELD], LOCAL_NAME_REGEXP);
+ nameVersionNameArray[PARENT_LOCAL_NAME_FIELD], LOCAL_NAME_REGEXP);
localName = Assertions.validateStringParameter(LOCAL_NAME, nameVersionNameArray[LOCAL_NAME_FIELD],
- LOCAL_NAME_REGEXP);
+ LOCAL_NAME_REGEXP);
}
/**
@@ -231,7 +194,7 @@ public class AxReferenceKey extends AxKey {
*/
public static AxReferenceKey getNullKey() {
return new AxReferenceKey(AxKey.NULL_KEY_NAME, AxKey.NULL_KEY_VERSION, AxKey.NULL_KEY_NAME,
- AxKey.NULL_KEY_NAME);
+ AxKey.NULL_KEY_NAME);
}
/**
@@ -281,8 +244,7 @@ public class AxReferenceKey extends AxKey {
/**
* Sets the parent artifact key of this reference key.
*
- * @param parentKey
- * the parent artifact key of this reference key
+ * @param parentKey the parent artifact key of this reference key
*/
public void setParentArtifactKey(final AxArtifactKey parentKey) {
Assertions.argumentNotNull(parentKey, "parentKey may not be null");
@@ -295,8 +257,7 @@ public class AxReferenceKey extends AxKey {
/**
* Sets the parent reference key of this reference key.
*
- * @param parentKey
- * the parent reference key of this reference key
+ * @param parentKey the parent reference key of this reference key
*/
public void setParentReferenceKey(final AxReferenceKey parentKey) {
Assertions.argumentNotNull(parentKey, "parentKey may not be null");
@@ -318,8 +279,7 @@ public class AxReferenceKey extends AxKey {
/**
* Sets the parent key name of this reference key.
*
- * @param parentKeyName
- * the parent key name of this reference key
+ * @param parentKeyName the parent key name of this reference key
*/
public void setParentKeyName(final String parentKeyName) {
this.parentKeyName = Assertions.validateStringParameter(PARENT_KEY_NAME, parentKeyName, NAME_REGEXP);
@@ -337,12 +297,11 @@ public class AxReferenceKey extends AxKey {
/**
* Sets the parent key version of this reference key.
*
- * @param parentKeyVersion
- * the parent key version of this reference key
+ * @param parentKeyVersion the parent key version of this reference key
*/
public void setParentKeyVersion(final String parentKeyVersion) {
this.parentKeyVersion = Assertions.validateStringParameter(PARENT_KEY_VERSION, parentKeyVersion,
- VERSION_REGEXP);
+ VERSION_REGEXP);
}
/**
@@ -357,12 +316,11 @@ public class AxReferenceKey extends AxKey {
/**
* Sets the parent local name of this reference key.
*
- * @param parentLocalName
- * the parent local name of this reference key
+ * @param parentLocalName the parent local name of this reference key
*/
public void setParentLocalName(final String parentLocalName) {
this.parentLocalName = Assertions.validateStringParameter(PARENT_LOCAL_NAME, parentLocalName,
- LOCAL_NAME_REGEXP);
+ LOCAL_NAME_REGEXP);
}
/**
@@ -377,8 +335,7 @@ public class AxReferenceKey extends AxKey {
/**
* Sets the local name of this reference key.
*
- * @param localName
- * the local name of this reference key
+ * @param localName the local name of this reference key
*/
public void setLocalName(final String localName) {
this.localName = Assertions.validateStringParameter(LOCAL_NAME, localName, LOCAL_NAME_REGEXP);
@@ -416,31 +373,31 @@ public class AxReferenceKey extends AxKey {
@Override
public AxValidationResult validate(final AxValidationResult result) {
final var parentNameValidationErrorMessage = Assertions.getStringParameterValidationMessage(PARENT_KEY_NAME,
- parentKeyName, NAME_REGEXP);
+ parentKeyName, NAME_REGEXP);
if (parentNameValidationErrorMessage != null) {
result.addValidationMessage(new AxValidationMessage(this, this.getClass(), ValidationResult.INVALID,
- "parentKeyName invalid-" + parentNameValidationErrorMessage));
+ "parentKeyName invalid-" + parentNameValidationErrorMessage));
}
final var parentKeyVersionValidationErrorMessage = Assertions
- .getStringParameterValidationMessage(PARENT_KEY_VERSION, parentKeyVersion, VERSION_REGEXP);
+ .getStringParameterValidationMessage(PARENT_KEY_VERSION, parentKeyVersion, VERSION_REGEXP);
if (parentKeyVersionValidationErrorMessage != null) {
result.addValidationMessage(new AxValidationMessage(this, this.getClass(), ValidationResult.INVALID,
- "parentKeyVersion invalid-" + parentKeyVersionValidationErrorMessage));
+ "parentKeyVersion invalid-" + parentKeyVersionValidationErrorMessage));
}
final var parentLocalNameValidationErrorMessage = Assertions
- .getStringParameterValidationMessage(PARENT_LOCAL_NAME, parentLocalName, LOCAL_NAME_REGEXP);
+ .getStringParameterValidationMessage(PARENT_LOCAL_NAME, parentLocalName, LOCAL_NAME_REGEXP);
if (parentLocalNameValidationErrorMessage != null) {
result.addValidationMessage(new AxValidationMessage(this, this.getClass(), ValidationResult.INVALID,
- "parentLocalName invalid-" + parentLocalNameValidationErrorMessage));
+ "parentLocalName invalid-" + parentLocalNameValidationErrorMessage));
}
final var localNameValidationErrorMessage = Assertions.getStringParameterValidationMessage(LOCAL_NAME,
- localName, LOCAL_NAME_REGEXP);
+ localName, LOCAL_NAME_REGEXP);
if (localNameValidationErrorMessage != null) {
result.addValidationMessage(new AxValidationMessage(this, this.getClass(), ValidationResult.INVALID,
- "localName invalid-" + localNameValidationErrorMessage));
+ "localName invalid-" + localNameValidationErrorMessage));
}
return result;
diff --git a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/concepts/package-info.java b/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/concepts/package-info.java
index 294a66496..347e46a0f 100644
--- a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/concepts/package-info.java
+++ b/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/concepts/package-info.java
@@ -1,6 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
+ * Modifications Copyright (C) 2022 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -23,12 +24,4 @@
*
* @author Liam Fallon (liam.fallon@ericsson.com)
*/
-
-@XmlSchema(namespace = "http://www.onap.org/policy/apex-pdp", elementFormDefault = XmlNsForm.QUALIFIED,
- xmlns = { @XmlNs(namespaceURI = "http://www.onap.org/policy/apex-pdp", prefix = "") })
-
package org.onap.policy.apex.model.basicmodel.concepts;
-
-import javax.xml.bind.annotation.XmlNs;
-import javax.xml.bind.annotation.XmlNsForm;
-import javax.xml.bind.annotation.XmlSchema;
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
deleted file mode 100644
index b84646038..000000000
--- a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/dao/ApexDao.java
+++ /dev/null
@@ -1,206 +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.Collection;
-import java.util.List;
-import org.onap.policy.apex.model.basicmodel.concepts.ApexException;
-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;
-
-/**
- * The Interface ApexDao describes the DAO interface for reading and writing Apex {@link AxConcept} concepts to and from
- * databases using JDBC.
- *
- * @author Sergey Sachkov
- * @author liam.fallon@ericsson.com
- */
-public interface ApexDao {
-
- /**
- * Initialize the Apex DAO with the given parameters.
- *
- * @param daoParameters parameters to use to access the database
- * @throws ApexException on initialization errors
- */
- void init(DaoParameters daoParameters) throws ApexException;
-
- /**
- * Close the Apex DAO.
- */
- void close();
-
- /**
- * Creates an Apex concept on the database.
- *
- * @param <T> the type of the object to create, a subclass of {@link AxConcept}
- * @param obj the object to create
- */
- <T extends AxConcept> void create(T obj);
-
- /**
- * Delete an Apex concept on the database.
- *
- * @param <T> the type of the object to delete, a subclass of {@link AxConcept}
- * @param obj the object to delete
- */
- <T extends AxConcept> void delete(T obj);
-
- /**
- * Delete an Apex concept on the database.
- *
- * @param <T> the type 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
- */
- <T extends AxConcept> void delete(Class<T> someClass, AxArtifactKey key);
-
- /**
- * Delete an Apex concept on the database.
- *
- * @param <T> the type 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
- */
- <T extends AxConcept> void delete(Class<T> someClass, AxReferenceKey key);
-
- /**
- * Create a collection of objects in the database.
- *
- * @param <T> the type of the object to create, a subclass of {@link AxConcept}
- * @param objs the objects to create
- */
- <T extends AxConcept> void createCollection(Collection<T> objs);
-
- /**
- * Delete a collection of objects in the database.
- *
- * @param <T> the type of the objects to delete, a subclass of {@link AxConcept}
- * @param objs the objects to delete
- */
- <T extends AxConcept> void deleteCollection(Collection<T> objs);
-
- /**
- * Delete a collection of objects in the database referred to by artifact key.
- *
- * @param <T> the type 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
- */
- <T extends AxConcept> int deleteByArtifactKey(Class<T> someClass, Collection<AxArtifactKey> keys);
-
- /**
- * Delete a collection of objects in the database referred to by reference key.
- *
- * @param <T> the type 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
- */
- <T extends AxConcept> int deleteByReferenceKey(Class<T> someClass, Collection<AxReferenceKey> keys);
-
- /**
- * Delete all objects of a given class in the database.
- *
- * @param <T> the type of the objects to delete, a subclass of {@link AxConcept}
- * @param someClass the class of the objects to delete, a subclass of {@link AxConcept}
- */
- <T extends AxConcept> void deleteAll(Class<T> someClass);
-
- /**
- * Get an object from the database, referred to by artifact key.
- *
- * @param <T> the type 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 extends AxConcept> T get(Class<T> someClass, AxArtifactKey key);
-
- /**
- * Get an object from the database, referred to by reference key.
- *
- * @param <T> the type 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 extends AxConcept> T get(Class<T> someClass, AxReferenceKey key);
-
- /**
- * Get all the objects in the database of a given type.
- *
- * @param <T> the type 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
- */
- <T extends AxConcept> List<T> getAll(Class<T> someClass);
-
- /**
- * Get all the objects in the database of the given type with the given parent artifact key.
- *
- * @param <T> the type 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
- */
- <T extends AxConcept> List<T> getAll(Class<T> someClass, AxArtifactKey parentKey);
-
- /**
- * Get a concept from the database with the given artifact key.
- *
- * @param <T> the type 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 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 extends AxConcept> T getArtifact(Class<T> someClass, AxArtifactKey artifactId);
-
- /**
- * Get a concept from the database with the given reference key.
- *
- * @param <T> the type 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 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 extends AxConcept> T getArtifact(Class<T> someClass, AxReferenceKey artifactId);
-
- /**
- * Get the number of instances of a concept that exist in the database.
- *
- * @param <T> the type 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
- */
- <T extends AxConcept> long size(Class<T> someClass);
-
- /**
- * Update a concept in the database.
- *
- * @param <T> the type of the object to get, a subclass of {@link AxConcept}
- * @param obj the object to update
- * @return the updated object
- */
- <T extends AxConcept> T update(T obj);
-}
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
deleted file mode 100644
index fad3b08b9..000000000
--- a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/dao/ApexDaoFactory.java
+++ /dev/null
@@ -1,70 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * Copyright (C) 2016-2018 Ericsson. All rights reserved.
- * Modifications Copyright (C) 2019-2020 Nordix Foundation.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * SPDX-License-Identifier: Apache-2.0
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.apex.model.basicmodel.dao;
-
-import org.onap.policy.apex.model.basicmodel.concepts.ApexException;
-import org.onap.policy.common.utils.validation.Assertions;
-import org.slf4j.ext.XLogger;
-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.
- *
- * @author Liam Fallon (liam.fallon@ericsson.com)
- */
-public class ApexDaoFactory {
- // Get a reference to the logger
- private static final XLogger LOGGER = XLoggerFactory.getXLogger(ApexDaoFactory.class);
-
- /**
- * Return an Apex DAO for the required APEX DAO plugin class.
- *
- * @param daoParameters parameters to use to read the database configuration information
- * @return the Apex DAO
- * @throws ApexException on invalid JPA plugins
- */
- public ApexDao createApexDao(final DaoParameters daoParameters) throws ApexException {
- Assertions.argumentOfClassNotNull(daoParameters, ApexException.class,
- "Parameter \"daoParameters\" may not be null");
-
- // Get the class for the DAO using reflection
- Object apexDaoObject = null;
- try {
- apexDaoObject = Class.forName(daoParameters.getPluginClass()).getDeclaredConstructor().newInstance();
- } catch (final Exception e) {
- LOGGER.error("Apex DAO class not found for DAO plugin \"" + daoParameters.getPluginClass() + "\"", e);
- throw new ApexException(
- "Apex DAO class not found for DAO plugin \"" + daoParameters.getPluginClass() + "\"", e);
- }
-
- // Check the class is an Apex DAO
- if (!(apexDaoObject instanceof ApexDao)) {
- LOGGER.error("Specified Apex DAO plugin class \"" + daoParameters.getPluginClass()
- + "\" does not implement the ApexDao interface");
- throw new ApexException("Specified Apex DAO plugin class \"" + daoParameters.getPluginClass()
- + "\" does not implement the ApexDao interface");
- }
-
- return (ApexDao) apexDaoObject;
- }
-}
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 c575bd7c0..000000000
--- a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/dao/DaoParameters.java
+++ /dev/null
@@ -1,123 +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);
- }
-
- /**
- * {@inheritDoc}.
- */
- @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 460714683..000000000
--- a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/dao/converters/CDataConditioner.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 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<String, String> implements AttributeConverter<String, String> {
-
- private static final String NL = "\n";
-
- /**
- * {@inheritDoc}.
- */
- @Override
- public String convertToDatabaseColumn(final String raw) {
- return clean(raw);
- }
-
- /**
- * {@inheritDoc}.
- */
- @Override
- public String convertToEntityAttribute(final String db) {
- return clean(db);
- }
-
- /**
- * {@inheritDoc}.
- */
- @Override
- public String unmarshal(final String value) throws Exception {
- return this.convertToEntityAttribute(value);
- }
-
- /**
- * {@inheritDoc}.
- */
- @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 f5fffdb00..000000000
--- a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/dao/converters/Uuid2String.java
+++ /dev/null
@@ -1,73 +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<String, UUID> implements AttributeConverter<UUID, String> {
-
- /**
- * {@inheritDoc}.
- */
- @Override
- public String convertToDatabaseColumn(final UUID uuid) {
- String returnString;
- if (uuid == null) {
- returnString = "";
- } else {
- returnString = uuid.toString();
- }
- return returnString;
- }
-
- /**
- * {@inheritDoc}.
- */
- @Override
- public UUID convertToEntityAttribute(final String uuidString) {
- return UUID.fromString(uuidString);
- }
-
- /**
- * {@inheritDoc}.
- */
- @Override
- public UUID unmarshal(final String value) throws Exception {
- return this.convertToEntityAttribute(value);
- }
-
- /**
- * {@inheritDoc}.
- */
- @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/converters/package-info.java b/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/dao/converters/package-info.java
deleted file mode 100644
index f1e9a3ba7..000000000
--- a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/dao/converters/package-info.java
+++ /dev/null
@@ -1,28 +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=========================================================
- */
-
-/**
- * Contains converters used by APEX EclipseLink marshaling and unmarshaling of
- * {@link org.onap.policy.apex.model.basicmodel.concepts.AxConcept} instances to and from files and databases.
- *
- * @author Liam Fallon (liam.fallon@ericsson.com)
- */
-
-package org.onap.policy.apex.model.basicmodel.dao.converters;
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
deleted file mode 100644
index 738d15ed3..000000000
--- a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/dao/impl/DefaultApexDao.java
+++ /dev/null
@@ -1,497 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * Copyright (C) 2016-2018 Ericsson. All rights reserved.
- * Modifications Copyright (C) 2019-2020 Nordix Foundation.
- * Modifications Copyright (C) 2021 AT&T Intellectual Property. 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.impl;
-
-import java.util.Collection;
-import java.util.Collections;
-import java.util.List;
-import javax.persistence.EntityManager;
-import javax.persistence.EntityManagerFactory;
-import javax.persistence.Persistence;
-import org.onap.policy.apex.model.basicmodel.concepts.ApexException;
-import org.onap.policy.apex.model.basicmodel.concepts.ApexRuntimeException;
-import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
-import org.onap.policy.apex.model.basicmodel.concepts.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.slf4j.ext.XLogger;
-import org.slf4j.ext.XLoggerFactory;
-
-/**
- * The Class DefaultApexDao is an JPA implementation of the {@link ApexDao} class for Apex concepts ({@link AxConcept}).
- * It uses the default JPA implementation in the javax {@link Persistence} class.
- *
- *
- * @author Sergey Sachkov (sergey.sachkov@ericsson.com)
- */
-public class DefaultApexDao implements ApexDao {
- private static final XLogger LOGGER = XLoggerFactory.getXLogger(DefaultApexDao.class);
-
- private static final String COL_LOCALNAME = "local_name";
- private static final String COL_PARENT_VERSION = "parent_version";
- private static final String COL_PARENT_NAME = "parent_name";
- private static final String COL_VERSION = "key_version";
- private static final String COL_NAME = "key_name";
-
- private static final String SELECT_C_FROM = "SELECT c FROM ";
- private static final String AND_C_KEY_LOCAL_NAME = " AND c.key.localName=:" + COL_LOCALNAME;
- private static final String AND_C_KEY_PARENT_KEY_VERSION = " AND c.key.parentKeyVersion=:" + COL_PARENT_VERSION;
- private static final String C_WHERE_C_KEY_PARENT_KEY_NAME = " c WHERE c.key.parentKeyName=:" + COL_PARENT_NAME;
- private static final String AND_C_KEY_VERSION = " AND c.key.version=:" + COL_VERSION;
- private static final String C_WHERE_C_KEY_NAME = " c WHERE c.key.name=:" + COL_NAME;
- private static final String DELETE_FROM = "DELETE FROM ";
-
- // Entity manager for JPA
- private EntityManagerFactory emf = null;
-
- /**
- * {@inheritDoc}.
- */
- @Override
- 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");
- }
-
- LOGGER.debug("Creating Apex persistence unit \"" + daoParameters.getPersistenceUnit() + "\" . . .");
- try {
- emf = Persistence.createEntityManagerFactory(daoParameters.getPersistenceUnit(),
- 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);
- }
- LOGGER.debug("Created Apex persistence unit \"" + daoParameters.getPersistenceUnit() + "\"");
- }
-
- /**
- * Gets the entity manager for this DAO.
- *
- * @return the entity manager
- */
- protected final synchronized EntityManager getEntityManager() {
- if (emf == null) {
- LOGGER.warn("Apex DAO has not been initialized");
- throw new ApexRuntimeException("Apex DAO has not been initialized");
- }
-
- return emf.createEntityManager();
- }
-
- /**
- * {@inheritDoc}.
- */
- @Override
- public final void close() {
- if (emf != null) {
- emf.close();
- }
- }
-
- /**
- * {@inheritDoc}.
- */
- @Override
- public <T extends AxConcept> void create(final T obj) {
- if (obj == null) {
- return;
- }
- final EntityManager mg = getEntityManager();
- try {
- mg.getTransaction().begin();
- mg.merge(obj);
- mg.getTransaction().commit();
- } finally {
- mg.close();
- }
- }
-
- /**
- * {@inheritDoc}.
- */
- @Override
- public <T extends AxConcept> void delete(final T obj) {
- if (obj == null) {
- return;
- }
- final EntityManager mg = getEntityManager();
- try {
- mg.getTransaction().begin();
- mg.remove(mg.contains(obj) ? obj : mg.merge(obj));
- mg.getTransaction().commit();
- } finally {
- mg.close();
- }
- }
-
- /**
- * {@inheritDoc}.
- */
- @Override
- public <T extends AxConcept> void delete(final Class<T> someClass, final AxArtifactKey key) {
- if (key == null) {
- return;
- }
- final EntityManager mg = getEntityManager();
- try {
- mg.getTransaction().begin();
- mg.createQuery(DELETE_FROM + someClass.getSimpleName() + C_WHERE_C_KEY_NAME + AND_C_KEY_VERSION, someClass)
- .setParameter(COL_NAME, key.getName())
- .setParameter(COL_VERSION, key.getVersion())
- .executeUpdate();
- mg.getTransaction().commit();
- } finally {
- mg.close();
- }
- }
-
- /**
- * {@inheritDoc}.
- */
- @Override
- public <T extends AxConcept> void delete(final Class<T> someClass, final AxReferenceKey key) {
- if (key == null) {
- return;
- }
- final EntityManager mg = getEntityManager();
- try {
- mg.getTransaction().begin();
- mg.createQuery(DELETE_FROM + someClass.getSimpleName() + C_WHERE_C_KEY_PARENT_KEY_NAME
- + AND_C_KEY_PARENT_KEY_VERSION
- + AND_C_KEY_LOCAL_NAME, someClass)
- .setParameter(COL_PARENT_NAME, key.getParentKeyName())
- .setParameter(COL_PARENT_VERSION, key.getParentKeyVersion())
- .setParameter(COL_LOCALNAME, key.getLocalName())
- .executeUpdate();
- mg.getTransaction().commit();
- } finally {
- mg.close();
- }
- }
-
- /**
- * {@inheritDoc}.
- */
- @Override
- public <T extends AxConcept> void createCollection(final Collection<T> objs) {
- if (objs == null || objs.isEmpty()) {
- return;
- }
- final EntityManager mg = getEntityManager();
- try {
- mg.getTransaction().begin();
- for (final T t : objs) {
- mg.merge(t);
- }
- mg.getTransaction().commit();
- } finally {
- mg.close();
- }
- }
-
- /**
- * {@inheritDoc}.
- */
- @Override
- public <T extends AxConcept> void deleteCollection(final Collection<T> objs) {
- if (objs == null || objs.isEmpty()) {
- return;
- }
- final EntityManager mg = getEntityManager();
- try {
- mg.getTransaction().begin();
- for (final T t : objs) {
- mg.remove(mg.contains(t) ? t : mg.merge(t));
- }
- mg.getTransaction().commit();
- } finally {
- mg.close();
- }
- }
-
- /**
- * {@inheritDoc}.
- */
- @Override
- public <T extends AxConcept> int deleteByArtifactKey(final Class<T> someClass,
- final Collection<AxArtifactKey> keys) {
- if (keys == null || keys.isEmpty()) {
- return 0;
- }
- int deletedCount = 0;
- final EntityManager mg = getEntityManager();
- try {
- mg.getTransaction().begin();
- for (final AxArtifactKey key : keys) {
- deletedCount += mg.createQuery(DELETE_FROM + someClass.getSimpleName() + C_WHERE_C_KEY_NAME
- + AND_C_KEY_VERSION, someClass)
- .setParameter(COL_NAME, key.getName())
- .setParameter(COL_VERSION, key.getVersion())
- .executeUpdate();
- }
- mg.getTransaction().commit();
- } finally {
- mg.close();
- }
- return deletedCount;
- }
-
- /**
- * {@inheritDoc}.
- */
- @Override
- public <T extends AxConcept> int deleteByReferenceKey(final Class<T> someClass,
- final Collection<AxReferenceKey> keys) {
- if (keys == null || keys.isEmpty()) {
- return 0;
- }
- int deletedCount = 0;
- final EntityManager mg = getEntityManager();
- try {
- mg.getTransaction().begin();
- for (final AxReferenceKey key : keys) {
- deletedCount +=
- mg.createQuery(
- DELETE_FROM + someClass.getSimpleName() + C_WHERE_C_KEY_PARENT_KEY_NAME
- + AND_C_KEY_PARENT_KEY_VERSION + AND_C_KEY_LOCAL_NAME, someClass)
- .setParameter(COL_PARENT_NAME, key.getParentKeyName())
- .setParameter(COL_PARENT_VERSION, key.getParentKeyVersion())
- .setParameter(COL_LOCALNAME, key.getLocalName())
- .executeUpdate();
- }
- mg.getTransaction().commit();
- } finally {
- mg.close();
- }
- return deletedCount;
- }
-
- /**
- * {@inheritDoc}.
- */
- @Override
- public <T extends AxConcept> void deleteAll(final Class<T> someClass) {
- final EntityManager mg = getEntityManager();
- try {
- mg.getTransaction().begin();
- mg.createQuery(DELETE_FROM + someClass.getSimpleName() + " c ", someClass).executeUpdate();
- mg.getTransaction().commit();
- } finally {
- mg.close();
- }
- }
-
- /**
- * {@inheritDoc}.
- */
- @Override
- public <T extends AxConcept> T get(final Class<T> someClass, final AxArtifactKey key) {
- if (someClass == null) {
- return null;
- }
- final EntityManager mg = getEntityManager();
- try {
- 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 = someClass.getDeclaredConstructor().newInstance();
- t.copyTo(clonedT);
- return clonedT;
- } catch (final Exception e) {
- LOGGER.warn("Could not clone object of class \"" + someClass.getName() + "\"", e);
- return null;
- }
- } else {
- return null;
- }
- } finally {
- mg.close();
- }
- }
-
- /**
- * {@inheritDoc}.
- */
- @Override
- public <T extends AxConcept> T get(final Class<T> someClass, final AxReferenceKey key) {
- if (someClass == null) {
- return null;
- }
- final EntityManager mg = getEntityManager();
- try {
- final T t = mg.find(someClass, key);
- if (t != null) {
- try {
- final T clonedT = someClass.getDeclaredConstructor().newInstance();
- t.copyTo(clonedT);
- return clonedT;
- } catch (final Exception e) {
- LOGGER.warn("Could not clone object of class \"" + someClass.getName() + "\"", e);
- return null;
- }
- } else {
- return null;
- }
- } finally {
- mg.close();
- }
- }
-
- /**
- * {@inheritDoc}.
- */
- @Override
- public <T extends AxConcept> List<T> getAll(final Class<T> someClass) {
- if (someClass == null) {
- return Collections.emptyList();
- }
- final EntityManager mg = getEntityManager();
- try {
- return mg.createQuery(SELECT_C_FROM + someClass.getSimpleName() + " c", someClass).getResultList();
- } finally {
- mg.close();
- }
- }
-
- /**
- * {@inheritDoc}.
- */
- @Override
- public <T extends AxConcept> List<T> getAll(final Class<T> someClass, final AxArtifactKey parentKey) {
- if (someClass == null) {
- return Collections.emptyList();
- }
- final EntityManager mg = getEntityManager();
- try {
- return mg
- .createQuery(
- SELECT_C_FROM + someClass.getSimpleName() + C_WHERE_C_KEY_PARENT_KEY_NAME
- + AND_C_KEY_PARENT_KEY_VERSION, someClass)
- .setParameter(COL_PARENT_NAME, parentKey.getName())
- .setParameter(COL_PARENT_VERSION, parentKey.getVersion())
- .getResultList();
- } finally {
- mg.close();
- }
- }
-
- /**
- * {@inheritDoc}.
- */
- @Override
- public <T extends AxConcept> T getArtifact(final Class<T> someClass, final AxArtifactKey key) {
- if (someClass == null || key == null) {
- return null;
- }
- final EntityManager mg = getEntityManager();
- List<T> ret;
- try {
- ret = mg.createQuery(SELECT_C_FROM + someClass.getSimpleName() + C_WHERE_C_KEY_NAME
- + AND_C_KEY_VERSION, someClass)
- .setParameter(COL_NAME, key.getName())
- .setParameter(COL_VERSION, key.getVersion())
- .getResultList();
- } finally {
- mg.close();
- }
- if (ret == null || ret.isEmpty()) {
- return null;
- }
- if (ret.size() > 1) {
- throw new IllegalArgumentException("More than one result was returned for search for " + someClass
- + " with key " + key.getId() + ": " + ret);
- }
- return ret.get(0);
- }
-
- /**
- * {@inheritDoc}.
- */
- @Override
- public <T extends AxConcept> T getArtifact(final Class<T> someClass, final AxReferenceKey key) {
- if (someClass == null || key == null) {
- return null;
- }
- final EntityManager mg = getEntityManager();
- List<T> ret;
- try {
- ret = mg.createQuery(SELECT_C_FROM + someClass.getSimpleName() + C_WHERE_C_KEY_PARENT_KEY_NAME
- + AND_C_KEY_PARENT_KEY_VERSION + AND_C_KEY_LOCAL_NAME, someClass)
- .setParameter(COL_PARENT_NAME, key.getParentKeyName())
- .setParameter(COL_PARENT_VERSION, key.getParentKeyVersion())
- .setParameter(COL_LOCALNAME, key.getLocalName())
- .getResultList();
- } finally {
- mg.close();
- }
- if (ret == null || ret.isEmpty()) {
- return null;
- }
- if (ret.size() > 1) {
- throw new IllegalArgumentException("More than one result was returned for search for " + someClass
- + " with key " + key.getId() + ": " + ret);
- }
- return ret.get(0);
- }
-
- /**
- * {@inheritDoc}.
- */
- @Override
- public <T extends AxConcept> T update(final T obj) {
- final EntityManager mg = getEntityManager();
- T ret;
- try {
- mg.getTransaction().begin();
- ret = mg.merge(obj);
- mg.flush();
- mg.getTransaction().commit();
- } finally {
- mg.close();
- }
- return ret;
- }
-
- /**
- * {@inheritDoc}.
- */
- @Override
- public <T extends AxConcept> long size(final Class<T> someClass) {
- if (someClass == null) {
- return 0;
- }
- final EntityManager mg = getEntityManager();
- long size = 0;
- try {
- size = mg.createQuery("SELECT COUNT(c) FROM " + someClass.getSimpleName() + " c", Long.class)
- .getSingleResult();
- } finally {
- mg.close();
- }
- return size;
- }
-}
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
deleted file mode 100644
index 5d585c247..000000000
--- a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/dao/impl/package-info.java
+++ /dev/null
@@ -1,27 +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=========================================================
- */
-
-/**
- * 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)
- */
-package org.onap.policy.apex.model.basicmodel.dao.impl;
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
deleted file mode 100644
index 505e4023a..000000000
--- a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/dao/package-info.java
+++ /dev/null
@@ -1,29 +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=========================================================
- */
-
-/**
- * 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.
- *
- * @author Liam Fallon (liam.fallon@ericsson.com)
- */
-
-package org.onap.policy.apex.model.basicmodel.dao;
diff --git a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelCustomGsonMapAdapter.java b/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelCustomGsonMapAdapter.java
new file mode 100644
index 000000000..cb67590f7
--- /dev/null
+++ b/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelCustomGsonMapAdapter.java
@@ -0,0 +1,118 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2022 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.apex.model.basicmodel.handling;
+
+import com.google.gson.JsonArray;
+import com.google.gson.JsonDeserializationContext;
+import com.google.gson.JsonDeserializer;
+import com.google.gson.JsonElement;
+import com.google.gson.JsonObject;
+import com.google.gson.JsonParseException;
+import com.google.gson.JsonSerializationContext;
+import com.google.gson.JsonSerializer;
+import java.lang.reflect.ParameterizedType;
+import java.lang.reflect.Type;
+import java.util.AbstractMap;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.TreeMap;
+import java.util.stream.Collectors;
+import java.util.stream.StreamSupport;
+
+@SuppressWarnings("rawtypes")
+public class ApexModelCustomGsonMapAdapter implements JsonSerializer<Map>, JsonDeserializer<Map> {
+ private static final String MAP_ENTRY_KEY = "entry";
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public Map deserialize(JsonElement jsonElement, Type typeOfT, JsonDeserializationContext context)
+ throws JsonParseException {
+
+ if (!(jsonElement instanceof JsonObject)) {
+ throw new JsonParseException("could not parse JSON map, map is not a JsonObject");
+ }
+
+ JsonObject jsonObject = (JsonObject) jsonElement;
+
+ if (jsonObject.size() != 1) {
+ throw new JsonParseException("could not parse JSON map, map must be in a JsonObject with a single member");
+ }
+
+ JsonArray mapEntryArray = (JsonArray) jsonObject.get(MAP_ENTRY_KEY);
+ if (mapEntryArray == null) {
+ throw new JsonParseException("could not parse JSON map, map \"entry\" in JsonObject not found");
+ }
+
+ return new TreeMap(
+ StreamSupport
+ .stream(mapEntryArray.spliterator(), true)
+ .map(element -> deserializeMapEntry(element, typeOfT, context))
+ .collect(Collectors.toMap(entry -> entry.getKey(), entry -> entry.getValue()))
+ );
+ }
+
+ @Override
+ public JsonElement serialize(Map sourceMap, Type typeOfSrc, JsonSerializationContext context) {
+
+ // A map is stored in a JsonArray
+ JsonArray mapEntryArray = new JsonArray();
+
+ for (Object mapEntryObject : sourceMap.entrySet()) {
+ Entry mapEntry = (Entry) mapEntryObject;
+ mapEntryArray.add(serializeMapEntry(mapEntry, typeOfSrc, context));
+ }
+
+ JsonObject returnObject = new JsonObject();
+ returnObject.add(MAP_ENTRY_KEY, mapEntryArray);
+
+ return returnObject;
+ }
+
+ @SuppressWarnings("unchecked")
+ private static Entry deserializeMapEntry(JsonElement element, Type typeOfT, JsonDeserializationContext context) {
+ // Get the types of the map
+ ParameterizedType pt = (ParameterizedType) typeOfT;
+
+ // Type of the key and value of the map
+ Type keyType = pt.getActualTypeArguments()[0];
+ Type valueType = pt.getActualTypeArguments()[1];
+
+ // Deserialize the key and value
+ return new AbstractMap.SimpleEntry(
+ context.deserialize(element.getAsJsonObject().get("key"), keyType),
+ context.deserialize(element.getAsJsonObject().get("value"), valueType));
+ }
+
+ private static JsonElement serializeMapEntry(Entry sourceEntry, Type typeOfSrc, JsonSerializationContext context) {
+ // Get the types of the map
+ ParameterizedType pt = (ParameterizedType) typeOfSrc;
+
+ // Type of the key and value of the map
+ Type keyType = pt.getActualTypeArguments()[0];
+ Type valueType = pt.getActualTypeArguments()[1];
+
+ JsonObject entryObject = new JsonObject();
+ entryObject.add("key", context.serialize(sourceEntry.getKey(), keyType));
+ entryObject.add("value", context.serialize(sourceEntry.getValue(), valueType));
+
+ return entryObject;
+ }
+}
diff --git a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelCustomGsonRefereceKeyAdapter.java b/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelCustomGsonRefereceKeyAdapter.java
new file mode 100644
index 000000000..d731c8689
--- /dev/null
+++ b/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelCustomGsonRefereceKeyAdapter.java
@@ -0,0 +1,50 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2022 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.apex.model.basicmodel.handling;
+
+import com.google.gson.JsonDeserializationContext;
+import com.google.gson.JsonDeserializer;
+import com.google.gson.JsonElement;
+import com.google.gson.JsonObject;
+import com.google.gson.JsonParseException;
+import java.lang.reflect.Type;
+import org.onap.policy.apex.model.basicmodel.concepts.AxReferenceKey;
+
+public class ApexModelCustomGsonRefereceKeyAdapter implements JsonDeserializer<AxReferenceKey> {
+
+ @Override
+ public AxReferenceKey deserialize(JsonElement jsonElement, Type typeOfT, JsonDeserializationContext context)
+ throws JsonParseException {
+
+ if (jsonElement instanceof JsonObject) {
+ return new AxReferenceKey(
+ jsonElement.getAsJsonObject().get("parentKeyName").getAsString(),
+ jsonElement.getAsJsonObject().get("parentKeyVersion").getAsString(),
+ jsonElement.getAsJsonObject().get("parentLocalName").getAsString(),
+ jsonElement.getAsJsonObject().get("localName").getAsString()
+ );
+ } else {
+ AxReferenceKey returnKey = new AxReferenceKey();
+ returnKey.setLocalName(jsonElement.getAsString());
+ return returnKey;
+ }
+ }
+}
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 908ad31aa..54b5651cc 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
@@ -1,7 +1,7 @@
/*
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
- * Modifications Copyright (C) 2021 Nordix Foundation.
+ * Modifications Copyright (C) 2021-2022 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -23,6 +23,8 @@ package org.onap.policy.apex.model.basicmodel.handling;
import java.io.File;
import java.io.FileOutputStream;
+import lombok.Getter;
+import lombok.Setter;
import org.onap.policy.apex.model.basicmodel.concepts.ApexException;
import org.onap.policy.apex.model.basicmodel.concepts.AxModel;
import org.slf4j.ext.XLogger;
@@ -34,42 +36,21 @@ import org.slf4j.ext.XLoggerFactory;
* @author Liam Fallon (liam.fallon@ericsson.com)
* @param <M> the type of Apex model to write to file, must be a sub class of {@link AxModel}
*/
+@Getter
+@Setter
public class ApexModelFileWriter<M extends AxModel> {
private static final XLogger LOGGER = XLoggerFactory.getXLogger(ApexModelFileWriter.class);
// Should models being written to files be valid
- private boolean validateFlag;
+ private boolean validate;
/**
* Constructor, set the validation flag.
*
- * @param validateFlag indicates if validation be performed prior to output
+ * @param validate indicates if validation be performed prior to output
*/
- public ApexModelFileWriter(final boolean validateFlag) {
- this.validateFlag = validateFlag;
- }
-
- /**
- * Write a model to an XML file.
- *
- * @param model The model to write
- * @param rootModelClass The concept class
- * @param modelFileName The name of the file to write to
- * @throws ApexException thrown on errors
- */
- public void apexModelWriteXmlFile(final M model, final Class<M> rootModelClass, final String modelFileName)
- throws ApexException {
- LOGGER.debug("running apexModelWriteXMLFile . . .");
-
- final ApexModelWriter<M> modelWriter = new ApexModelWriter<>(rootModelClass);
- modelWriter.setValidateFlag(validateFlag);
- modelWriter.getCDataFieldSet().add("description");
- modelWriter.getCDataFieldSet().add("logic");
- modelWriter.getCDataFieldSet().add("uiLogic");
-
- writeModelFile(model, modelWriter, modelFileName);
-
- LOGGER.debug("ran apexModelWriteXMLFile");
+ public ApexModelFileWriter(final boolean validate) {
+ this.validate = validate;
}
/**
@@ -85,8 +66,7 @@ public class ApexModelFileWriter<M extends AxModel> {
LOGGER.debug("running apexModelWriteJSONFile . . .");
final ApexModelWriter<M> modelWriter = new ApexModelWriter<>(rootModelClass);
- modelWriter.setJsonOutput(true);
- modelWriter.setValidateFlag(validateFlag);
+ modelWriter.setValidate(validate);
writeModelFile(model, modelWriter, modelFileName);
@@ -94,24 +74,6 @@ public class ApexModelFileWriter<M extends AxModel> {
}
/**
- * Checks if the validation flag is set.
- *
- * @return true, the validation flag is set
- */
- public boolean isValidateFlag() {
- return validateFlag;
- }
-
- /**
- * Sets the validate flag.
- *
- * @param validateFlag the validate flag value
- */
- public void setValidateFlag(final boolean validateFlag) {
- this.validateFlag = validateFlag;
- }
-
- /**
* Write a model to a file using a model writer.
*
* @param model The model to write
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 7e136f6b3..a9bd2fe60 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
@@ -1,7 +1,7 @@
/*
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
- * Modifications Copyright (C) 2019-2021 Nordix Foundation.
+ * Modifications Copyright (C) 2019-2022 Nordix Foundation.
* Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -22,55 +22,47 @@
package org.onap.policy.apex.model.basicmodel.handling;
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
-import java.io.StringReader;
-import java.util.regex.Pattern;
-import javax.xml.XMLConstants;
-import javax.xml.bind.JAXBElement;
-import javax.xml.bind.JAXBException;
-import javax.xml.bind.Unmarshaller;
-import javax.xml.transform.stream.StreamSource;
-import javax.xml.validation.SchemaFactory;
-import org.eclipse.persistence.jaxb.JAXBContextFactory;
-import org.eclipse.persistence.jaxb.MarshallerProperties;
-import org.eclipse.persistence.oxm.MediaType;
+import java.util.Map;
+import lombok.Getter;
+import lombok.Setter;
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.concepts.AxValidationResult;
-import org.onap.policy.common.utils.resources.ResourceUtils;
import org.onap.policy.common.utils.resources.TextFileUtils;
import org.onap.policy.common.utils.validation.Assertions;
import org.slf4j.ext.XLogger;
import org.slf4j.ext.XLoggerFactory;
/**
- * This class reads an Apex concept from an XML file into a Java Apex Concept {@link AxConcept}.
+ * This class reads an Apex concept from a file into a Java Apex Concept {@link AxConcept}.
*
* @author Liam Fallon (liam.fallon@ericsson.com)
* @param <C> the type of Apex concept to read, must be a sub class of {@link AxConcept}
*/
+@Getter
+@Setter
public class ApexModelReader<C extends AxConcept> {
// Get a reference to the logger
private static final XLogger LOGGER = XLoggerFactory.getXLogger(ApexModelReader.class);
- // Regular expressions for checking input types
- // (starts with <?xml...>
- 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
+ // Use GSON to deserialize JSON
+ private static Gson gson = new GsonBuilder()
+ .registerTypeAdapter(AxReferenceKey.class, new ApexModelCustomGsonRefereceKeyAdapter())
+ .registerTypeAdapter(Map.class, new ApexModelCustomGsonMapAdapter())
+ .setPrettyPrinting()
+ .create();
//  The root class of the concept we are reading
private final Class<C> rootConceptClass;
- // The unmarshaller for the Apex concepts
- private Unmarshaller unmarshaller = null;
-
// All read concepts are validated after reading if this flag is set
- private boolean validateFlag = true;
+ private boolean validate = true;
/**
* Constructor, initiates the reader with validation on.
@@ -81,17 +73,6 @@ public class ApexModelReader<C extends AxConcept> {
public ApexModelReader(final Class<C> rootConceptClass) throws ApexModelException {
// Save the root concept class
this.rootConceptClass = rootConceptClass;
-
- try {
- final var jaxbContext = JAXBContextFactory.createContext(new Class[] {rootConceptClass}, null);
-
- // Set up the unmarshaller to carry out validation
- unmarshaller = jaxbContext.createUnmarshaller();
- unmarshaller.setEventHandler(new javax.xml.bind.helpers.DefaultValidationEventHandler());
- } catch (final JAXBException e) {
- LOGGER.error("Unable to set JAXB context", e);
- throw new ApexModelException("Unable to set JAXB context", e);
- }
}
/**
@@ -103,36 +84,11 @@ public class ApexModelReader<C extends AxConcept> {
*/
public ApexModelReader(final Class<C> rootConceptClass, final boolean validate) throws ApexModelException {
this(rootConceptClass);
- this.validateFlag = validate;
- }
-
- /**
- * Set the schema to use for reading XML files.
- *
- * @param schemaFileName the schema file to use
- * @throws ApexModelException if the schema cannot be set
- */
- public void setSchema(final String schemaFileName) throws ApexModelException {
- // Has a schema been set
- if (schemaFileName != null) {
- try {
- // Set the concept schema
- final var schemaUrl = ResourceUtils.getUrlResource(schemaFileName);
- final var apexConceptSchema =
- SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI).newSchema(schemaUrl);
- unmarshaller.setSchema(apexConceptSchema);
- } catch (final Exception e) {
- LOGGER.error("Unable to load schema ", e);
- throw new ApexModelException("Unable to load schema", e);
- }
- } else {
- // Clear the schema
- unmarshaller.setSchema(null);
- }
+ this.validate = validate;
}
/**
- * This method checks the specified Apex concept XML file and reads it into an Apex concept.
+ * This method checks the specified Apex concept file and reads it into an Apex concept.
*
* @param apexConceptStream the apex concept stream
* @return the Apex concept
@@ -179,28 +135,23 @@ public class ApexModelReader<C extends AxConcept> {
LOGGER.entry("reading Apex concept from string . . .");
- final var apexString = apexConceptString.trim();
-
- // Set the type of input for this stream
- setInputType(apexString);
-
- // The Apex Concept
C apexConcept = null;
-
- // Use JAXB to read and verify the Apex concept XML file
try {
- // Load the configuration file
- final var source = new StreamSource(new StringReader(apexString));
- final JAXBElement<C> rootElement = unmarshaller.unmarshal(source, rootConceptClass);
- apexConcept = rootElement.getValue();
- } catch (final JAXBException e) {
- throw new ApexModelException("Unable to unmarshal Apex concept ", e);
+ apexConcept = gson.fromJson(apexConceptString, rootConceptClass);
+ } catch (final Exception je) {
+ throw new ApexModelException("Unable to unmarshal Apex concept ", je);
+ }
+
+ if (apexConcept == null) {
+ throw new ApexModelException("Unable to unmarshal Apex concept, unmarshaled model is null ");
}
LOGGER.debug("reading of Apex concept {} completed");
+ apexConcept.buildReferences();
+
// Check if the concept should be validated
- if (validateFlag) {
+ if (validate) {
// Validate the configuration file
final AxValidationResult validationResult = apexConcept.validate(new AxValidationResult());
if (validationResult.isValid()) {
@@ -215,54 +166,4 @@ public class ApexModelReader<C extends AxConcept> {
return apexConcept;
}
}
-
- /**
- * Gets the value of the validation flag.
- *
- * @return the validation flag value
- */
- public boolean getValidateFlag() {
- return validateFlag;
- }
-
- /**
- * Sets the validation flag.
- *
- * @param validateFlag the validation flag value
- */
- public void setValidateFlag(final boolean validateFlag) {
- this.validateFlag = validateFlag;
- }
-
- /**
- * Set the type of input for the concept reader.
- *
- * @param apexConceptString The stream with
- * @throws ApexModelException on errors setting input type
- */
- private void setInputType(final String apexConceptString) throws ApexModelException {
- // Check the input type
- if (Pattern.compile(JSON_INPUT_TYPE_REGEXP).matcher(apexConceptString).find()) {
- // is json
- try {
- unmarshaller.setProperty(MarshallerProperties.MEDIA_TYPE, MediaType.APPLICATION_JSON);
- unmarshaller.setProperty(MarshallerProperties.JSON_INCLUDE_ROOT, true);
- } catch (final Exception e) {
- LOGGER.warn("JAXB error setting marshaller for JSON Input", e);
- throw new ApexModelException("JAXB error setting unmarshaller for JSON input", e);
- }
- } else if (Pattern.compile(XML_INPUT_TYPE_REGEXP).matcher(apexConceptString).find()) {
- // is xml
- try {
- unmarshaller.setProperty(MarshallerProperties.MEDIA_TYPE, MediaType.APPLICATION_XML);
- } catch (final Exception e) {
- LOGGER.warn("JAXB error setting marshaller for XML Input", e);
- throw new ApexModelException("JAXB error setting unmarshaller for XML input", e);
- }
- } else {
- LOGGER.warn("format of input for Apex concept is neither JSON nor XML");
- throw new ApexModelException("format of input for Apex concept is neither JSON nor XML");
- }
- }
-
}
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 dea32df49..79d69bdd5 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
@@ -1,7 +1,7 @@
/*
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
- * Modifications Copyright (C) 2019-2021 Nordix Foundation.
+ * Modifications Copyright (C) 2019-2022 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -29,7 +29,7 @@ import org.slf4j.ext.XLogger;
import org.slf4j.ext.XLoggerFactory;
/**
- * This class is used to save Apex models to file in XML or JSON format.
+ * This class is used to save Apex models to file in JSON format.
*
* @author Liam Fallon (liam.fallon@ericsson.com)
* @param <M> the type of Apex model to save to file, must be a sub class of {@link AxModel}
@@ -51,7 +51,7 @@ public class ApexModelSaver<M extends AxModel> {
* @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}.
+ * Name for its key with the suffix {@code .json}.
*/
public ApexModelSaver(final Class<M> rootModelClass, final M model, final String writePath) {
Assertions.argumentNotNull(rootModelClass, "argument rootModelClass may not be null");
@@ -64,21 +64,6 @@ public class ApexModelSaver<M extends AxModel> {
}
/**
- * Write an Apex model to a file in XML format. The model will be written to {@code <writePath/modelKeyName.xml>}
- *
- * @throws ApexException on errors writing the Apex model
- */
- public void apexModelWriteXml() throws ApexException {
- LOGGER.debug("running apexModelWriteXML . . .");
-
- // Write the file to disk
- final var xmlFile = new File(writePath + File.separatorChar + model.getKey().getName() + ".xml");
- new ApexModelFileWriter<M>(true).apexModelWriteXmlFile(model, rootModelClass, xmlFile.getPath());
-
- LOGGER.debug("ran apexModelWriteXML");
- }
-
- /**
* Write an Apex model to a file in JSON format. The model will be written to {@code <writePath/modelKeyName.json>}
*
* @throws ApexException on errors writing the Apex model
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 de6a72ffd..a9df23afc 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
@@ -1,7 +1,7 @@
/*
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
- * Modifications Copyright (C) 2019-2021 Nordix Foundation.
+ * Modifications Copyright (C) 2019-2022 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -22,6 +22,8 @@
package org.onap.policy.apex.model.basicmodel.handling;
import java.io.ByteArrayOutputStream;
+import lombok.Getter;
+import lombok.Setter;
import org.onap.policy.apex.model.basicmodel.concepts.ApexException;
import org.onap.policy.apex.model.basicmodel.concepts.AxConcept;
import org.onap.policy.common.utils.validation.Assertions;
@@ -34,19 +36,21 @@ import org.slf4j.ext.XLoggerFactory;
* @author Liam Fallon (liam.fallon@ericsson.com)
* @param <C> the type of Apex concept to write to a string, must be a sub class of {@link AxConcept}
*/
+@Getter
+@Setter
public class ApexModelStringWriter<C extends AxConcept> {
private static final XLogger LOGGER = XLoggerFactory.getXLogger(ApexModelStringWriter.class);
// Should concepts being written to files be valid
- private boolean validateFlag;
+ private boolean validate;
/**
* Constructor, set the validation flag.
*
- * @param validateFlag Should validation be performed prior to output
+ * @param validate Should validation be performed prior to output
*/
- public ApexModelStringWriter(final boolean validateFlag) {
- this.validateFlag = validateFlag;
+ public ApexModelStringWriter(final boolean validate) {
+ this.validate = validate;
}
/**
@@ -54,46 +58,14 @@ public class ApexModelStringWriter<C extends AxConcept> {
*
* @param concept The concept to write
* @param rootConceptClass The concept class
- * @param jsonFlag writes JSON if true, and a generic string if false
* @return The string with the concept
* @throws ApexException thrown on errors
*/
- public String writeString(final C concept, final Class<C> rootConceptClass, final boolean jsonFlag)
+ public String writeString(final C concept, final Class<C> rootConceptClass)
throws ApexException {
Assertions.argumentNotNull(concept, "concept may not be null");
- if (jsonFlag) {
- return writeJsonString(concept, rootConceptClass);
- } else {
- return concept.toString();
- }
- }
-
- /**
- * Write a concept to an XML string.
- *
- * @param concept The concept to write
- * @param rootConceptClass The concept class
- * @return The string with the concept
- * @throws ApexException thrown on errors
- */
- public String writeXmlString(final C concept, final Class<C> rootConceptClass) throws ApexException {
- LOGGER.debug("running writeXMLString . . .");
-
- final ApexModelWriter<C> conceptWriter = new ApexModelWriter<>(rootConceptClass);
- conceptWriter.setValidateFlag(validateFlag);
- conceptWriter.getCDataFieldSet().add("description");
- conceptWriter.getCDataFieldSet().add("logic");
- conceptWriter.getCDataFieldSet().add("uiLogic");
-
- try (var baOutputStream = new ByteArrayOutputStream()) {
- conceptWriter.write(concept, baOutputStream);
- return baOutputStream.toString();
- } catch (final Exception e) {
- LOGGER.warn("error writing XML string", e);
- throw new ApexException("error writing XML string", e);
- }
-
+ return writeJsonString(concept, rootConceptClass);
}
/**
@@ -108,8 +80,7 @@ public class ApexModelStringWriter<C extends AxConcept> {
LOGGER.debug("running writeJSONString . . .");
final ApexModelWriter<C> conceptWriter = new ApexModelWriter<>(rootConceptClass);
- conceptWriter.setJsonOutput(true);
- conceptWriter.setValidateFlag(validateFlag);
+ conceptWriter.setValidate(validate);
try (var baOutputStream = new ByteArrayOutputStream()) {
conceptWriter.write(concept, baOutputStream);
@@ -120,22 +91,4 @@ public class ApexModelStringWriter<C extends AxConcept> {
}
}
-
- /**
- * Checks if is validate flag.
- *
- * @return true, if checks if is validate flag
- */
- public boolean isValidateFlag() {
- return validateFlag;
- }
-
- /**
- * Sets the validate flag.
- *
- * @param validateFlag the validate flag
- */
- public void setValidateFlag(final boolean validateFlag) {
- this.validateFlag = validateFlag;
- }
}
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 9e43f76bd..349622697 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
@@ -1,7 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
- * Modifications Copyright (C) 2019-2021 Nordix Foundation.
+ * Modifications Copyright (C) 2019-2022 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -21,129 +21,67 @@
package org.onap.policy.apex.model.basicmodel.handling;
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.Writer;
-import java.util.Set;
-import java.util.TreeSet;
-import javax.xml.XMLConstants;
-import javax.xml.bind.JAXBException;
-import javax.xml.bind.Marshaller;
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.parsers.ParserConfigurationException;
-import javax.xml.transform.OutputKeys;
-import javax.xml.transform.Transformer;
-import javax.xml.transform.TransformerConfigurationException;
-import javax.xml.transform.TransformerException;
-import javax.xml.transform.TransformerFactory;
-import javax.xml.transform.dom.DOMSource;
-import javax.xml.transform.stream.StreamResult;
-import org.eclipse.persistence.jaxb.JAXBContextFactory;
-import org.eclipse.persistence.jaxb.MarshallerProperties;
-import org.eclipse.persistence.oxm.MediaType;
+import java.util.Map;
+import lombok.Getter;
+import lombok.Setter;
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.concepts.AxValidationResult;
import org.onap.policy.common.utils.validation.Assertions;
import org.slf4j.ext.XLogger;
import org.slf4j.ext.XLoggerFactory;
/**
- * This class writes an Apex concept to an XML file or JSON file from a Java Apex Concept.
+ * This class writes an Apex concept to a file from a Java Apex Concept.
*
* @param <C> the type of Apex concept to write, must be a sub class of {@link AxConcept}
* @author John Keeney (john.keeney@ericsson.com)
*/
+@Getter
+@Setter
public class ApexModelWriter<C extends AxConcept> {
private static final String CONCEPT_MAY_NOT_BE_NULL = "concept may not be null";
private static final String CONCEPT_WRITER_MAY_NOT_BE_NULL = "concept writer may not be null";
private static final String CONCEPT_STREAM_MAY_NOT_BE_NULL = "concept stream may not be null";
+ // Use GSON to serialize JSON
+ private static Gson gson = new GsonBuilder()
+ .registerTypeAdapter(AxReferenceKey.class, new ApexModelCustomGsonRefereceKeyAdapter())
+ .registerTypeAdapter(Map.class, new ApexModelCustomGsonMapAdapter())
+ .setPrettyPrinting()
+ .create();
+
// Get a reference to the logger
private static final XLogger LOGGER = XLoggerFactory.getXLogger(ApexModelWriter.class);
- // Writing as JSON or XML
- private boolean jsonOutput = false;
-
- // The list of fields to output as CDATA
- private final Set<String> cdataFieldSet = new TreeSet<>();
-
- // The Marshaller for the Apex concepts
- private Marshaller marshaller = null;
+ //  The root class of the concept we are reading
+ private final Class<C> rootConceptClass;
// All written concepts are validated before writing if this flag is set
- private boolean validateFlag = true;
+ private boolean validate = true;
/**
- * Constructor, initiates the writer.
+ * Constructor, initiates the writer with validation on.
*
* @param rootConceptClass the root concept class for concept reading
- * @throws ApexModelException the apex concept writer exception
+ * @throws ApexModelException the apex concept reader exception
*/
public ApexModelWriter(final Class<C> rootConceptClass) throws ApexModelException {
- // Set up Eclipselink for XML and JSON output
- System.setProperty("javax.xml.bind.context.factory", "org.eclipse.persistence.jaxb.JAXBContextFactory");
-
- try {
- final var jaxbContext = JAXBContextFactory.createContext(new Class[]{rootConceptClass}, null);
-
- // Set up the unmarshaller to carry out validation
- marshaller = jaxbContext.createMarshaller();
- marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
- marshaller.setEventHandler(new javax.xml.bind.helpers.DefaultValidationEventHandler());
- } catch (final JAXBException e) {
- throw new ApexModelException("JAXB marshaller creation exception", e);
- }
- }
-
- /**
- * The set of fields to be output as CDATA.
- *
- * @return the set of fields
- */
- public Set<String> getCDataFieldSet() {
- return cdataFieldSet;
- }
-
- /**
- * Return true if JSON output enabled, XML output if false.
- *
- * @return true for JSON output
- */
- public boolean isJsonOutput() {
- return jsonOutput;
- }
-
- /**
- * Set the value of JSON output, true for JSON output, false for XML output.
- *
- * @param jsonOutput true for JSON output
- * @throws ApexModelException on errors setting output type
- */
- public void setJsonOutput(final boolean jsonOutput) throws ApexModelException {
- this.jsonOutput = jsonOutput;
-
- // Set up output specific parameters
- if (this.jsonOutput) {
- try {
- marshaller.setProperty(MarshallerProperties.MEDIA_TYPE, MediaType.APPLICATION_JSON);
- marshaller.setProperty(MarshallerProperties.JSON_INCLUDE_ROOT, true);
- } catch (final Exception e) {
- throw new ApexModelException("JAXB error setting marshaller for JSON output", e);
- }
- } else {
- try {
- marshaller.setProperty(MarshallerProperties.MEDIA_TYPE, MediaType.APPLICATION_XML);
- } catch (final Exception e) {
- throw new ApexModelException("JAXB error setting marshaller for XML output", e);
- }
- }
+ // Save the root concept class
+ this.rootConceptClass = rootConceptClass;
}
/**
* This method validates the Apex concept then writes it into a stream.
*
- * @param concept the concept to write
+ * @param concept the concept to write
* @param apexConceptStream the stream to write to
* @throws ApexModelException on validation or writing exceptions
*/
@@ -157,7 +95,7 @@ public class ApexModelWriter<C extends AxConcept> {
/**
* This method validates the Apex concept then writes it into a writer.
*
- * @param concept the concept to write
+ * @param concept the concept to write
* @param apexConceptWriter the writer to write to
* @throws ApexModelException on validation or writing exceptions
*/
@@ -166,84 +104,23 @@ public class ApexModelWriter<C extends AxConcept> {
Assertions.argumentNotNull(apexConceptWriter, CONCEPT_WRITER_MAY_NOT_BE_NULL);
// Check if we should validate the concept
- if (validateFlag) {
+ if (validate) {
// Validate the concept first
final AxValidationResult validationResult = concept.validate(new AxValidationResult());
if (!validationResult.isValid()) {
String message =
- "Apex concept xml (" + concept.getKey().getId() + ") validation failed: " + validationResult
- .toString();
+ "Apex concept (" + concept.getKey().getId() + ") validation failed: " + validationResult.toString();
throw new ApexModelException(message);
}
}
- if (jsonOutput) {
- writeJson(concept, apexConceptWriter);
- } else {
- writeXml(concept, apexConceptWriter);
- }
- }
-
- /**
- * This method writes the Apex concept into a writer in XML format.
- *
- * @param concept the concept to write
- * @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 {
- Assertions.argumentNotNull(concept, CONCEPT_MAY_NOT_BE_NULL);
-
- LOGGER.debug("writing Apex concept XML . . .");
-
- try {
- // Write the concept into a DOM document, then transform to add CDATA fields and pretty
- // print, then write out the result
- final var docBuilderFactory = DocumentBuilderFactory.newInstance();
- docBuilderFactory.setAttribute(XMLConstants.ACCESS_EXTERNAL_DTD, "");
- docBuilderFactory.setAttribute(XMLConstants.ACCESS_EXTERNAL_SCHEMA, "");
-
- docBuilderFactory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
- final var document = docBuilderFactory.newDocumentBuilder().newDocument();
-
- // Marshal the concept into the empty document.
- marshaller.marshal(concept, document);
-
- final var domTransformer = getTransformer();
-
- // Convert the cDataFieldSet into a space delimited string
- domTransformer.setOutputProperty(OutputKeys.CDATA_SECTION_ELEMENTS,
- cdataFieldSet.toString().replaceAll("[\\[\\]\\,]", " "));
- domTransformer.transform(new DOMSource(document), new StreamResult(apexConceptWriter));
- } catch (JAXBException | TransformerException | ParserConfigurationException e) {
- throw new ApexModelException("Unable to marshal Apex concept to XML", e);
- }
- LOGGER.debug("wrote Apex concept XML");
- }
-
- private Transformer getTransformer() throws TransformerConfigurationException {
- // Transform the DOM to the output stream
- final var transformerFactory = TransformerFactory.newInstance();
- transformerFactory.setAttribute(XMLConstants.ACCESS_EXTERNAL_DTD, "");
- transformerFactory.setAttribute(XMLConstants.ACCESS_EXTERNAL_STYLESHEET, "");
-
- final var domTransformer = transformerFactory.newTransformer();
-
- // Pretty print
- try {
- domTransformer.setOutputProperty(OutputKeys.INDENT, "yes");
- // May fail if not using XALAN XSLT engine. But not in any way vital
- domTransformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");
- } catch (final Exception ignore) {
- LOGGER.trace("Unable to set indent property", ignore);
- }
- return domTransformer;
+ writeJson(concept, apexConceptWriter);
}
/**
* This method writes the Apex concept into a writer in JSON format.
*
- * @param concept the concept to write
+ * @param concept the concept to write
* @param apexConceptWriter the writer to write to
* @throws ApexModelException on validation or writing exceptions
*/
@@ -252,29 +129,20 @@ public class ApexModelWriter<C extends AxConcept> {
LOGGER.debug("writing Apex concept JSON . . .");
+ String modelJsonString = null;
try {
- marshaller.marshal(concept, apexConceptWriter);
- } catch (final JAXBException e) {
- throw new ApexModelException("Unable to marshal Apex concept to JSON", e);
+ modelJsonString = gson.toJson(concept, rootConceptClass);
+ } catch (Exception je) {
+ throw new ApexModelException("Unable to marshal Apex concept to JSON", je);
}
- LOGGER.debug("wrote Apex concept JSON");
- }
- /**
- * Gets the validation flag value.
- *
- * @return the validation flag value
- */
- public boolean getValidateFlag() {
- return validateFlag;
- }
+ try {
+ apexConceptWriter.write(modelJsonString);
+ apexConceptWriter.close();
+ } catch (IOException ioe) {
+ throw new ApexModelException("Unable to write Apex concept as JSON", ioe);
+ }
- /**
- * Sets the validation flag.
- *
- * @param validateFlag the validation flag value
- */
- public void setValidateFlag(final boolean validateFlag) {
- this.validateFlag = validateFlag;
+ LOGGER.debug("wrote 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
deleted file mode 100644
index d5f34785b..000000000
--- a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/handling/ApexSchemaGenerator.java
+++ /dev/null
@@ -1,161 +0,0 @@
-/*
- * ============LICENSE_START=======================================================
- * Copyright (C) 2016-2018 Ericsson. All rights reserved.
- * Modifications Copyright (C) 2020-2021 Nordix Foundation.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * SPDX-License-Identifier: Apache-2.0
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.apex.model.basicmodel.handling;
-
-import java.io.File;
-import java.io.IOException;
-import java.io.PrintStream;
-import java.io.StringWriter;
-import javax.xml.bind.JAXBContext;
-import javax.xml.bind.JAXBException;
-import javax.xml.bind.SchemaOutputResolver;
-import javax.xml.transform.Result;
-import javax.xml.transform.stream.StreamResult;
-import org.slf4j.ext.XLogger;
-import org.slf4j.ext.XLoggerFactory;
-
-/**
- * This class generates the XML model schema from the given Apex concept classes.
- *
- * @author Liam Fallon (liam.fallon@ericsson.com)
- */
-public class ApexSchemaGenerator {
- // Get a reference to the logger
- private static final XLogger LOGGER = XLoggerFactory.getXLogger(ApexSchemaGenerator.class);
-
- /**
- * A Main method to allow schema generation from the command line or from maven or scripts.
- *
- * @param args the command line arguments, usage is {@code ApexSchemaGenerator apex-root-class [schema-file-name]}
- */
- public static void main(final String[] args) {
- PrintStream printStream = null;
-
- if (args.length == 1) {
- printStream = System.out;
- } else if (args.length == 2) {
- final var schemaFile = new File(args[1]);
-
- try {
- schemaFile.getParentFile().mkdirs();
- printStream = new PrintStream(schemaFile);
- } catch (final Exception e) {
- LOGGER.error("error on Apex schema output", e);
- return;
- }
- } else {
- LOGGER.error("usage: ApexSchemaGenerator apex-root-class [schema-file-name]");
- return;
- }
-
- // Get the schema
- final String schema = new ApexSchemaGenerator().generate(args[0]);
-
- // Output the schema
- printStream.println(schema);
-
- printStream.close();
- }
-
- /**
- * Generates the XML schema (XSD) for the Apex model described using JAXB annotations.
- *
- * @param rootClassName the name of the root class for schema generation
- * @return The schema
- */
- public String generate(final String rootClassName) {
- JAXBContext jaxbContext;
- try {
- jaxbContext = JAXBContext.newInstance(Class.forName(rootClassName));
- } catch (final ClassNotFoundException e) {
- LOGGER.error("could not create JAXB context, root class " + rootClassName + " not found", e);
- return null;
- } catch (final JAXBException e) {
- LOGGER.error("could not create JAXB context", e);
- return null;
- }
-
- final var sor = new ApexSchemaOutputResolver();
- try {
- jaxbContext.generateSchema(sor);
- } catch (final IOException e) {
- LOGGER.error("error generating the Apex schema (XSD) file", e);
- return null;
- }
-
- var schemaString = sor.getSchema();
- schemaString = fixForUnqualifiedBug(schemaString);
-
- return schemaString;
- }
-
- /**
- * 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
- var newSchemaString = schemaString.replace(
- "<xs:element name=\"entry\" minOccurs=\"0\" maxOccurs=\"unbounded\">",
- "<xs:element name=\"entry\" minOccurs=\"0\" maxOccurs=\"unbounded\" form=\"unqualified\">");
-
- // Fix the "key" element
- newSchemaString = newSchemaString.replace("<xs:element name=\"key\"",
- "<xs:element name=\"key\" form=\"unqualified\"");
-
- // Fix the "value" element
- newSchemaString = newSchemaString.replace("<xs:element name=\"value\"",
- "<xs:element name=\"value\" form=\"unqualified\"");
-
- return newSchemaString;
- }
-
- /**
- * This inner class is used to receive the output of schema generation from the JAXB schema generator.
- */
- private class ApexSchemaOutputResolver extends SchemaOutputResolver {
- private final StringWriter stringWriter = new StringWriter();
-
- /**
- * {@inheritDoc}.
- */
- @Override
- public Result createOutput(final String namespaceUri, final String suggestedFileName) throws IOException {
- final var result = new StreamResult(stringWriter);
- result.setSystemId(suggestedFileName);
- return result;
- }
-
- /**
- * Get the schema from the string writer.
- *
- * @return the schema generated by JAXB
- */
- public String getSchema() {
- return stringWriter.toString();
- }
- }
-}
diff --git a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/handling/KeyInfoMarshalFilter.java b/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/handling/KeyInfoMarshalFilter.java
deleted file mode 100644
index cfc385d01..000000000
--- a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/handling/KeyInfoMarshalFilter.java
+++ /dev/null
@@ -1,104 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * Copyright (C) 2019 Nordix Foundation.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * SPDX-License-Identifier: Apache-2.0
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.apex.model.basicmodel.handling;
-
-import java.util.Collection;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-import java.util.TreeMap;
-import javax.xml.bind.annotation.adapters.XmlAdapter;
-import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
-import org.onap.policy.apex.model.basicmodel.concepts.AxKey;
-import org.onap.policy.apex.model.basicmodel.concepts.AxKeyInfo;
-import org.onap.policy.apex.model.basicmodel.concepts.AxKeyInformation;
-
-/**
- * This class implements a filter to prevent some keyinfo information being marshalled when a model is serialised.
- */
-public class KeyInfoMarshalFilter extends XmlAdapter<AxKeyInformation, AxKeyInformation> {
-
- private List<AxKey> filterList = new LinkedList<>();
-
- /**
- * Adds a key to the list to be filtered.
- *
- * @param key the key to add to the filter list
- */
- public void addFilterKey(AxKey key) {
- filterList.add(key);
- }
-
- /**
- * Remove a key from the list to be filtered.
- *
- * @param key the key to remove from the filter list
- * @return true if the passed key was in the filter list and has been removed.
- */
- public boolean removeFilterKey(AxKey key) {
- return filterList.remove(key);
- }
-
- /**
- * Adds some keys to the list to be filtered.
- *
- * @param keys the keys to add to the filter list
- */
- public void addFilterKeys(Collection<? extends AxKey> keys) {
- filterList.addAll(keys);
- }
-
- /**
- * Decide whether to unmarshall some keyinfos - Always.
- *
- * @param val the keyinfo
- * @return the keyinfo
- * @throws Exception if there is some problem unmarshalling
- * @see javax.xml.bind.annotation.adapters.XmlAdapter#unmarshal(Object)
- */
- @Override
- public AxKeyInformation unmarshal(AxKeyInformation val) throws Exception {
- return val;
- }
-
- /**
- * Select which keyinfo entries will be marshalled - i.e. those not in the filter list.
- *
- * @param val the keyinfo
- * @return the keyinfo
- * @throws Exception if there is some problem with the marshalling
- * @see javax.xml.bind.annotation.adapters.XmlAdapter#marshal(Object)
- */
- @Override
- public AxKeyInformation marshal(AxKeyInformation val) throws Exception {
- if (val == null || val.getKeyInfoMap() == null || val.getKeyInfoMap().isEmpty() || filterList.isEmpty()) {
- return val;
- }
- //create a new keyinfo clone to avoid removing keyinfo entries from the original model
- AxKeyInformation ret = new AxKeyInformation(val);
- Map<AxArtifactKey, AxKeyInfo> retmap = new TreeMap<>(ret.getKeyInfoMap());
- for (AxKey key : filterList) {
- retmap.remove(key);
- }
- ret.setKeyInfoMap(retmap);
- return ret;
- }
-}
diff --git a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/handling/package-info.java b/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/handling/package-info.java
index 081cff540..3d6dab3b2 100644
--- a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/handling/package-info.java
+++ b/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/handling/package-info.java
@@ -1,6 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
+ * Modifications Copyright (C) 2022 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,20 +18,4 @@
* SPDX-License-Identifier: Apache-2.0
* ============LICENSE_END=========================================================
*/
-
-/**
- * Contains a number of utility classes for handling APEX {@link org.onap.policy.apex.model.basicmodel.concepts.AxModel}
- * models and {@link org.onap.policy.apex.model.basicmodel.concepts.AxConcept} concepts. Classes to read and write
- * models to files, strings, and databases are included, as well as classes to generate XML schemas for models.
- *
- * @author Liam Fallon (liam.fallon@ericsson.com)
- */
-
-@XmlSchema(namespace = "http://www.onap.org/policy/apex-pdp", elementFormDefault = XmlNsForm.QUALIFIED,
- xmlns = { @XmlNs(namespaceURI = "http://www.onap.org/policy/apex-pdp", prefix = "") })
-
package org.onap.policy.apex.model.basicmodel.handling;
-
-import javax.xml.bind.annotation.XmlNs;
-import javax.xml.bind.annotation.XmlNsForm;
-import javax.xml.bind.annotation.XmlSchema;
diff --git a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/package-info.java b/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/package-info.java
index e540646d9..8ad405e25 100644
--- a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/package-info.java
+++ b/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/package-info.java
@@ -1,7 +1,7 @@
/*
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
- * Modifications Copyright (C) 2019 Nordix Foundation.
+ * Modifications Copyright (C) 2019,2022 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -24,7 +24,7 @@
* the model for APEX concepts anywhere in the system.
*
* <p>It also provides handling support to models, allowing them to be read and written to file and databases in JSON
- * and XML format.
+ * format.
*
* @author Liam Fallon (liam.fallon@ericsson.com)
*/
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 36ce4e438..9dde47d05 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
@@ -1,7 +1,7 @@
/*
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
- * Modifications Copyright (C) 2021 Nordix Foundation.
+ * Modifications Copyright (C) 2021-2022 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -27,8 +27,6 @@ import java.io.File;
import org.onap.policy.apex.model.basicmodel.concepts.ApexException;
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.ApexDaoFactory;
-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;
@@ -46,7 +44,7 @@ import org.slf4j.ext.XLoggerFactory;
public class TestApexModel<M extends AxModel> {
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_UNEQUAL_STR = "test model does not equal model read from XML file ";
+ private static final String TEST_MODEL_UNEQUAL_STR = "test model does not equal model read from 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);
@@ -79,55 +77,6 @@ public class TestApexModel<M extends AxModel> {
}
/**
- * Test write and read in XML format.
- *
- * @throws ApexException on write/read errors
- */
- public final void testApexModelWriteReadXml() throws ApexException {
- LOGGER.debug("running testApexModelWriteReadXML . . .");
-
- final var 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);
- }
- new ApexModelFileWriter<M>(true).apexModelWriteXmlFile(model, rootModelClass, xmlFile.getPath());
-
- // Read the file from disk
- final ApexModelReader<M> modelReader = new ApexModelReader<>(rootModelClass);
-
- try {
- final var apexModelUrl = ResourceUtils.getLocalFile(xmlFile.getAbsolutePath());
- final var fileModel = modelReader.read(apexModelUrl.openStream());
- checkModelEquality(model, fileModel, TEST_MODEL_UNEQUAL_STR + xmlFile.getAbsolutePath());
- } catch (final Exception e) {
- LOGGER.warn(ERROR_PROCESSING_FILE + xmlFile.getAbsolutePath(), e);
- throw new ApexException(ERROR_PROCESSING_FILE + xmlFile.getAbsolutePath(), e);
- }
-
- final ApexModelWriter<M> modelWriter = new ApexModelWriter<>(rootModelClass);
- modelWriter.getCDataFieldSet().add("description");
- modelWriter.getCDataFieldSet().add("logic");
- modelWriter.getCDataFieldSet().add("uiLogic");
-
- final var baOutputStream = new ByteArrayOutputStream();
- modelWriter.write(model, baOutputStream);
- final var baInputStream = new ByteArrayInputStream(baOutputStream.toByteArray());
- final var byteArrayModel = modelReader.read(baInputStream);
-
- checkModelEquality(model, byteArrayModel, "test model does not equal XML marshalled and unmarshalled model");
-
- LOGGER.debug("ran testApexModelWriteReadXML");
- }
-
- /**
* Test write and read in JSON format.
*
* @throws ApexException on write/read errors
@@ -140,7 +89,7 @@ public class TestApexModel<M extends AxModel> {
// Write the file to disk
File jsonFile;
try {
- jsonFile = File.createTempFile("ApexModel", ".xml");
+ jsonFile = File.createTempFile("ApexModel", ".json");
jsonFile.deleteOnExit();
} catch (final Exception e) {
LOGGER.warn(TEMP_FILE_CREATE_ERR_STR, e);
@@ -161,7 +110,6 @@ public class TestApexModel<M extends AxModel> {
}
final ApexModelWriter<M> modelWriter = new ApexModelWriter<>(rootModelClass);
- modelWriter.setJsonOutput(true);
final var baOutputStream = new ByteArrayOutputStream();
modelWriter.write(model, baOutputStream);
@@ -174,29 +122,6 @@ public class TestApexModel<M extends AxModel> {
}
/**
- * Test write and read of an Apex model to database using JPA.
- *
- * @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 {
- LOGGER.debug("running testApexModelWriteReadJPA . . .");
-
- final var model = modelCreator.getModel();
-
- final var apexDao = new ApexDaoFactory().createApexDao(daoParameters);
- apexDao.init(daoParameters);
-
- apexDao.create(model);
- final var dbJpaModel = apexDao.get(rootModelClass, model.getKey());
- apexDao.close();
-
- checkModelEquality(model, dbJpaModel, "test model does not equal model written and read using generic JPA");
-
- LOGGER.debug("ran testApexModelWriteReadJPA");
- }
-
- /**
* Test that an Apex model is valid.
*
* @return the result of the validation
diff --git a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/xml/AxReferenceKeyAdapter.java b/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/xml/AxReferenceKeyAdapter.java
deleted file mode 100644
index 8515f5724..000000000
--- a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/xml/AxReferenceKeyAdapter.java
+++ /dev/null
@@ -1,58 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * Copyright (C) 2016-2018 Ericsson. All rights reserved.
- * Modifications Copyright (C) 2021 Nordix Foundation.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * SPDX-License-Identifier: Apache-2.0
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.apex.model.basicmodel.xml;
-
-import java.io.Serializable;
-import javax.xml.bind.annotation.XmlAccessType;
-import javax.xml.bind.annotation.XmlAccessorType;
-import javax.xml.bind.annotation.XmlType;
-import javax.xml.bind.annotation.adapters.XmlAdapter;
-import org.onap.policy.apex.model.basicmodel.concepts.AxReferenceKey;
-
-/**
- * This class manages marshaling and unmarshaling of Apex {@link AxReferenceKey} concepts using JAXB. The local name in
- * reference keys must have specific handling.
- */
-@XmlAccessorType(XmlAccessType.PROPERTY)
-@XmlType(namespace = "http://www.onap.org/policy/apex-pdp")
-public class AxReferenceKeyAdapter extends XmlAdapter<String, AxReferenceKey> implements Serializable {
-
- private static final long serialVersionUID = -3480405083900107029L;
-
- /**
- * {@inheritDoc}.
- */
- @Override
- public final String marshal(final AxReferenceKey key) throws Exception {
- return key.getLocalName();
- }
-
- /**
- * {@inheritDoc}.
- */
- @Override
- public final AxReferenceKey unmarshal(final String key) throws Exception {
- final var axReferenceKey = new AxReferenceKey();
- axReferenceKey.setLocalName(key);
- return axReferenceKey;
- }
-}
diff --git a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/xml/package-info.java b/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/xml/package-info.java
deleted file mode 100644
index 290209d89..000000000
--- a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/xml/package-info.java
+++ /dev/null
@@ -1,34 +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=========================================================
- */
-
-/**
- * Contains utility classes for managing marshaling and unmarshaling of APEX models using JAXB.
- *
- * @author Liam Fallon (liam.fallon@ericsson.com)
- */
-
-@XmlSchema(namespace = "http://www.onap.org/policy/apex-pdp", elementFormDefault = XmlNsForm.QUALIFIED,
- xmlns = { @XmlNs(namespaceURI = "http://www.onap.org/policy/apex-pdp", prefix = "") })
-
-package org.onap.policy.apex.model.basicmodel.xml;
-
-import javax.xml.bind.annotation.XmlNs;
-import javax.xml.bind.annotation.XmlNsForm;
-import javax.xml.bind.annotation.XmlSchema;
diff --git a/model/basic-model/src/main/resources/xml/example.xsd b/model/basic-model/src/main/resources/xml/example.xsd
deleted file mode 100644
index 75ecdc323..000000000
--- a/model/basic-model/src/main/resources/xml/example.xsd
+++ /dev/null
@@ -1,100 +0,0 @@
-<?xml version="1.0" standalone="yes"?>
-<!--
- ============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=========================================================
--->
-<xs:schema elementFormDefault="qualified" version="1.0" targetNamespace="http://www.onap.org/policy/apex-pdp" xmlns="http://www.onap.org/policy/apex-pdp" xmlns:tns="http://www.onap.org/policy/apex-pdp" xmlns:xs="http://www.w3.org/2001/XMLSchema">
-
- <xs:element name="apexArtifactKey" type="AxArtifactKey"/>
-
- <xs:element name="apexKeyInfo" type="AxKeyInfo"/>
-
- <xs:element name="apexModel" type="AxModel"/>
-
- <xs:complexType name="AxModel">
- <xs:complexContent>
- <xs:extension base="AxConcept">
- <xs:sequence>
- <xs:element name="key" form="unqualified" type="AxArtifactKey"/>
- <xs:element name="keyInformation" type="AxKeyInformation"/>
- </xs:sequence>
- </xs:extension>
- </xs:complexContent>
- </xs:complexType>
-
- <xs:complexType name="AxConcept" abstract="true">
- <xs:sequence/>
- </xs:complexType>
-
- <xs:complexType name="AxArtifactKey">
- <xs:complexContent>
- <xs:extension base="axKey">
- <xs:sequence>
- <xs:element name="name" type="xs:string"/>
- <xs:element name="version" type="xs:string"/>
- </xs:sequence>
- </xs:extension>
- </xs:complexContent>
- </xs:complexType>
-
- <xs:complexType name="axKey" abstract="true">
- <xs:complexContent>
- <xs:extension base="AxConcept">
- <xs:sequence/>
- </xs:extension>
- </xs:complexContent>
- </xs:complexType>
-
- <xs:complexType name="AxKeyInformation">
- <xs:complexContent>
- <xs:extension base="AxConcept">
- <xs:sequence>
- <xs:element name="key" form="unqualified" type="AxArtifactKey"/>
- <xs:element name="keyInfoMap">
- <xs:complexType>
- <xs:sequence>
- <xs:element name="entry" minOccurs="0" maxOccurs="unbounded" form="unqualified">
- <xs:complexType>
- <xs:sequence>
- <xs:element name="key" form="unqualified" minOccurs="0" type="AxArtifactKey"/>
- <xs:element name="value" form="unqualified" minOccurs="0" type="AxKeyInfo"/>
- </xs:sequence>
- </xs:complexType>
- </xs:element>
- </xs:sequence>
- </xs:complexType>
- </xs:element>
- </xs:sequence>
- </xs:extension>
- </xs:complexContent>
- </xs:complexType>
-
- <xs:complexType name="AxKeyInfo">
- <xs:complexContent>
- <xs:extension base="AxConcept">
- <xs:sequence>
- <xs:element name="key" form="unqualified" type="AxArtifactKey"/>
- <xs:element name="UUID" type="xs:string"/>
- <xs:element name="description" type="xs:string"/>
- </xs:sequence>
- </xs:extension>
- </xs:complexContent>
- </xs:complexType>
-</xs:schema>
-
-
diff --git a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/concepts/AxKeyInfoTest.java b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/concepts/AxKeyInfoTest.java
index d066d674c..0c7edee28 100644
--- a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/concepts/AxKeyInfoTest.java
+++ b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/concepts/AxKeyInfoTest.java
@@ -1,7 +1,7 @@
/*
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
- * Modifications Copyright (C) 2019-2021 Nordix Foundation.
+ * Modifications Copyright (C) 2019-2022 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -65,10 +65,11 @@ public class AxKeyInfoTest {
assertEquals(testKeyInfo, testKeyInfo); // NOSONAR
assertEquals(testKeyInfo, clonedReferenceKey);
assertNotNull(testKeyInfo);
- assertNotEquals(testKeyInfo, (Object) new AxArtifactKey());
+ Object differentKeyType = new AxArtifactKey();
+ assertNotEquals(testKeyInfo, differentKeyType);
assertNotEquals(testKeyInfo, new AxKeyInfo(new AxArtifactKey()));
assertNotEquals(testKeyInfo, new AxKeyInfo(key, UUID.randomUUID(), "Some Description"));
- assertNotEquals(testKeyInfo, new AxKeyInfo(key, uuid, "Some Description"));
+ assertEquals(testKeyInfo, new AxKeyInfo(key, uuid, "Some Other Description"));
assertEquals(testKeyInfo, new AxKeyInfo(key, uuid, "Key Description"));
assertEquals(0, testKeyInfo.compareTo(testKeyInfo));
diff --git a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/concepts/DummyEntity.java b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/concepts/DummyEntity.java
index 2407dab38..2b16e89ed 100644
--- a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/concepts/DummyEntity.java
+++ b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/concepts/DummyEntity.java
@@ -1,7 +1,7 @@
/*
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
- * Modifications Copyright (C) 2020 Nordix Foundation.
+ * Modifications Copyright (C) 2020,2022 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -23,24 +23,11 @@ package org.onap.policy.apex.model.basicmodel.concepts;
import java.util.Arrays;
import java.util.List;
-import javax.persistence.EmbeddedId;
-import javax.persistence.Entity;
-import javax.persistence.Table;
-import javax.xml.bind.annotation.XmlElement;
-import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
-import org.onap.policy.apex.model.basicmodel.xml.AxReferenceKeyAdapter;
-
-@Entity
-@Table(name = "TestEntity")
public class DummyEntity extends AxConcept {
private static final long serialVersionUID = -2962570563281067894L;
- @EmbeddedId()
- @XmlElement(name = "key", required = true)
- @XmlJavaTypeAdapter(AxReferenceKeyAdapter.class)
protected AxReferenceKey key;
-
private double doubleValue;
public DummyEntity() {
diff --git a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/dao/DaoMiscTest.java b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/dao/DaoMiscTest.java
deleted file mode 100644
index 6f9bef83d..000000000
--- a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/dao/DaoMiscTest.java
+++ /dev/null
@@ -1,77 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * Copyright (C) 2016-2018 Ericsson. All rights reserved.
- * Modifications Copyright (C) 2020 Nordix Foundation
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * SPDX-License-Identifier: Apache-2.0
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.apex.model.basicmodel.dao;
-
-import static org.assertj.core.api.Assertions.assertThatThrownBy;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNull;
-
-import java.util.Properties;
-import org.junit.Test;
-import org.onap.policy.apex.model.basicmodel.dao.converters.CDataConditioner;
-import org.onap.policy.apex.model.basicmodel.dao.converters.Uuid2String;
-
-public class DaoMiscTest {
-
- @Test
- public void testUuid2StringMopUp() {
- final Uuid2String uuid2String = new Uuid2String();
- assertEquals("", uuid2String.convertToDatabaseColumn(null));
- }
-
- @Test
- public void testCDataConditionerMopUp() {
- assertNull(CDataConditioner.clean(null));
- }
-
- @Test
- public void testDaoFactory() {
- final DaoParameters daoParameters = new DaoParameters();
-
- daoParameters.setPluginClass("somewhere.over.the.rainbow");
- assertThatThrownBy(() -> new ApexDaoFactory().createApexDao(daoParameters))
- .hasMessage("Apex DAO class not found for DAO plugin \"somewhere.over.the.rainbow\"");
- daoParameters.setPluginClass("java.lang.String");
- assertThatThrownBy(() -> new ApexDaoFactory().createApexDao(daoParameters))
- .hasMessage("Specified Apex DAO plugin class \"java.lang.String\" "
- + "does not implement the ApexDao interface");
- }
-
- @Test
- public void testDaoParameters() {
- final DaoParameters pars = new DaoParameters();
- pars.setJdbcProperties(new Properties());
- assertEquals(0, pars.getJdbcProperties().size());
-
- pars.setJdbcProperty("name", "Dorothy");
- assertEquals("Dorothy", pars.getJdbcProperty("name"));
-
- pars.setPersistenceUnit("Kansas");
- assertEquals("Kansas", pars.getPersistenceUnit());
-
- pars.setPluginClass("somewhere.over.the.rainbow");
- assertEquals("somewhere.over.the.rainbow", pars.getPluginClass());
-
- assertEquals("DAOParameters [pluginClass=somewhere.over.the.rainbow, "
- + "persistenceUnit=Kansas, jdbcProperties={name=Dorothy}]", pars.toString());
- }
-}
diff --git a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/dao/EntityTest.java b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/dao/EntityTest.java
deleted file mode 100644
index e584085c3..000000000
--- a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/dao/EntityTest.java
+++ /dev/null
@@ -1,262 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * Copyright (C) 2016-2018 Ericsson. All rights reserved.
- * Modifications Copyright (C) 2020 Nordix Foundation.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * SPDX-License-Identifier: Apache-2.0
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.apex.model.basicmodel.dao;
-
-import static org.assertj.core.api.Assertions.assertThatThrownBy;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Set;
-import java.util.TreeSet;
-import java.util.UUID;
-import org.junit.Test;
-import org.onap.policy.apex.model.basicmodel.concepts.ApexException;
-import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
-import org.onap.policy.apex.model.basicmodel.concepts.AxKeyInfo;
-import org.onap.policy.apex.model.basicmodel.concepts.AxReferenceKey;
-import org.onap.policy.apex.model.basicmodel.concepts.DummyEntity;
-
-/**
- * JUnit test class.
- */
-public class EntityTest {
- private ApexDao apexDao;
-
- @Test
- public void testEntityTestSanity() throws ApexException {
- final DaoParameters daoParameters = new DaoParameters();
-
- apexDao = new ApexDaoFactory().createApexDao(daoParameters);
-
- assertThatThrownBy(() -> apexDao.init(null))
- .hasMessage("Apex persistence unit parameter not set");
- assertThatThrownBy(() -> apexDao.init(daoParameters))
- .hasMessage("Apex persistence unit parameter not set");
- daoParameters.setPluginClass("somewhere.over.the.rainbow");
- daoParameters.setPersistenceUnit("Dorothy");
- assertThatThrownBy(() -> apexDao.init(daoParameters))
- .hasMessage("Creation of Apex persistence unit \"Dorothy\" failed");
- assertThatThrownBy(() -> apexDao.create(new AxArtifactKey()))
- .hasMessage("Apex DAO has not been initialized");
- apexDao.close();
- }
-
- @Test
- public void testEntityTestAllOpsJpa() throws ApexException {
- final DaoParameters daoParameters = new DaoParameters();
- daoParameters.setPluginClass("org.onap.policy.apex.model.basicmodel.dao.impl.DefaultApexDao");
- daoParameters.setPersistenceUnit("DaoTest");
-
- apexDao = new ApexDaoFactory().createApexDao(daoParameters);
- apexDao.init(daoParameters);
-
- testAllOps();
- apexDao.close();
- }
-
- @Test
- public void testEntityTestBadVals() throws ApexException {
- final DaoParameters daoParameters = new DaoParameters();
- assertNotNull(daoParameters);
- daoParameters.setPluginClass("org.onap.policy.apex.model.basicmodel.dao.impl.DefaultApexDao");
- assertEquals("org.onap.policy.apex.model.basicmodel.dao.impl.DefaultApexDao", daoParameters.getPluginClass());
- daoParameters.setPersistenceUnit("DaoTest");
- assertEquals("DaoTest", daoParameters.getPersistenceUnit());
-
- apexDao = new ApexDaoFactory().createApexDao(daoParameters);
- apexDao.init(daoParameters);
-
- final AxArtifactKey nullKey = null;
- final AxReferenceKey nullRefKey = null;
- final List<AxArtifactKey> nullKeyList = null;
- final List<AxArtifactKey> emptyKeyList = new ArrayList<>();
- final List<AxReferenceKey> nullRKeyList = null;
- final List<AxReferenceKey> emptyRKeyList = new ArrayList<>();
-
- apexDao.create(nullKey);
- apexDao.createCollection(nullKeyList);
- apexDao.createCollection(emptyKeyList);
-
- apexDao.delete(nullKey);
- apexDao.deleteCollection(nullKeyList);
- apexDao.deleteCollection(emptyKeyList);
- apexDao.delete(AxArtifactKey.class, nullKey);
- apexDao.delete(AxReferenceKey.class, nullRefKey);
- apexDao.deleteByArtifactKey(AxArtifactKey.class, nullKeyList);
- apexDao.deleteByArtifactKey(AxArtifactKey.class, emptyKeyList);
- apexDao.deleteByReferenceKey(AxReferenceKey.class, nullRKeyList);
- apexDao.deleteByReferenceKey(AxReferenceKey.class, emptyRKeyList);
-
- apexDao.get(null, nullKey);
- apexDao.get(null, nullRefKey);
- apexDao.getAll(null);
- apexDao.getAll(null, nullKey);
- apexDao.getArtifact(null, nullKey);
- apexDao.getArtifact(AxArtifactKey.class, nullKey);
- apexDao.getArtifact(null, nullRefKey);
- apexDao.getArtifact(AxReferenceKey.class, nullRefKey);
- apexDao.size(null);
-
- apexDao.close();
- }
-
- private void testAllOps() {
- final AxArtifactKey aKey0 = new AxArtifactKey("A-KEY0", "0.0.1");
- final AxArtifactKey aKey1 = new AxArtifactKey("A-KEY1", "0.0.1");
- final AxArtifactKey aKey2 = new AxArtifactKey("A-KEY2", "0.0.1");
- final AxKeyInfo keyInfo0 = new AxKeyInfo(aKey0, UUID.fromString("00000000-0000-0000-0000-000000000000"),
- "key description 0");
- final AxKeyInfo keyInfo1 = new AxKeyInfo(aKey1, UUID.fromString("00000000-0000-0000-0000-000000000001"),
- "key description 1");
- final AxKeyInfo keyInfo2 = new AxKeyInfo(aKey2, UUID.fromString("00000000-0000-0000-0000-000000000002"),
- "key description 2");
-
- apexDao.create(keyInfo0);
-
- final AxKeyInfo keyInfoBack0 = apexDao.get(AxKeyInfo.class, aKey0);
- assertEquals(keyInfo0, keyInfoBack0);
-
- final AxKeyInfo keyInfoBackNull = apexDao.get(AxKeyInfo.class, AxArtifactKey.getNullKey());
- assertNull(keyInfoBackNull);
-
- final AxKeyInfo keyInfoBack1 = apexDao.getArtifact(AxKeyInfo.class, aKey0);
- assertEquals(keyInfoBack0, keyInfoBack1);
-
- final AxKeyInfo keyInfoBack2 = apexDao.getArtifact(AxKeyInfo.class, new AxArtifactKey("A-KEY3", "0.0.1"));
- assertNull(keyInfoBack2);
-
- final Set<AxKeyInfo> keyInfoSetIn = new TreeSet<AxKeyInfo>();
- keyInfoSetIn.add(keyInfo1);
- keyInfoSetIn.add(keyInfo2);
-
- apexDao.createCollection(keyInfoSetIn);
-
- Set<AxKeyInfo> keyInfoSetOut = new TreeSet<AxKeyInfo>(apexDao.getAll(AxKeyInfo.class));
-
- keyInfoSetIn.add(keyInfo0);
- assertEquals(keyInfoSetIn, keyInfoSetOut);
-
- apexDao.delete(keyInfo1);
- keyInfoSetIn.remove(keyInfo1);
- keyInfoSetOut = new TreeSet<AxKeyInfo>(apexDao.getAll(AxKeyInfo.class));
- assertEquals(keyInfoSetIn, keyInfoSetOut);
-
- apexDao.deleteCollection(keyInfoSetIn);
- keyInfoSetOut = new TreeSet<AxKeyInfo>(apexDao.getAll(AxKeyInfo.class));
- assertEquals(0, keyInfoSetOut.size());
-
- keyInfoSetIn.add(keyInfo0);
- keyInfoSetIn.add(keyInfo1);
- keyInfoSetIn.add(keyInfo0);
- apexDao.createCollection(keyInfoSetIn);
- keyInfoSetOut = new TreeSet<AxKeyInfo>(apexDao.getAll(AxKeyInfo.class));
- assertEquals(keyInfoSetIn, keyInfoSetOut);
-
- apexDao.delete(AxKeyInfo.class, aKey0);
- keyInfoSetOut = new TreeSet<AxKeyInfo>(apexDao.getAll(AxKeyInfo.class));
- assertEquals(2, keyInfoSetOut.size());
- assertEquals(2, apexDao.size(AxKeyInfo.class));
-
- final Set<AxArtifactKey> keySetIn = new TreeSet<AxArtifactKey>();
- keySetIn.add(aKey1);
- keySetIn.add(aKey2);
-
- final int deletedCount = apexDao.deleteByArtifactKey(AxKeyInfo.class, keySetIn);
- assertEquals(2, deletedCount);
-
- keyInfoSetOut = new TreeSet<AxKeyInfo>(apexDao.getAll(AxKeyInfo.class));
- assertEquals(0, keyInfoSetOut.size());
-
- keyInfoSetIn.add(keyInfo0);
- keyInfoSetIn.add(keyInfo1);
- keyInfoSetIn.add(keyInfo0);
- apexDao.createCollection(keyInfoSetIn);
- keyInfoSetOut = new TreeSet<AxKeyInfo>(apexDao.getAll(AxKeyInfo.class));
- assertEquals(keyInfoSetIn, keyInfoSetOut);
-
- apexDao.deleteAll(AxKeyInfo.class);
- assertEquals(0, apexDao.size(AxKeyInfo.class));
-
- final AxArtifactKey owner0Key = new AxArtifactKey("Owner0", "0.0.1");
- final AxArtifactKey owner1Key = new AxArtifactKey("Owner1", "0.0.1");
- final AxArtifactKey owner2Key = new AxArtifactKey("Owner2", "0.0.1");
- final AxArtifactKey owner3Key = new AxArtifactKey("Owner3", "0.0.1");
- final AxArtifactKey owner4Key = new AxArtifactKey("Owner4", "0.0.1");
- final AxArtifactKey owner5Key = new AxArtifactKey("Owner5", "0.0.1");
-
- apexDao.create(new DummyEntity(new AxReferenceKey(owner0Key, "Entity0"), 100.0));
- apexDao.create(new DummyEntity(new AxReferenceKey(owner0Key, "Entity1"), 101.0));
- apexDao.create(new DummyEntity(new AxReferenceKey(owner0Key, "Entity2"), 102.0));
- apexDao.create(new DummyEntity(new AxReferenceKey(owner0Key, "Entity3"), 103.0));
- apexDao.create(new DummyEntity(new AxReferenceKey(owner0Key, "Entity4"), 104.0));
- apexDao.create(new DummyEntity(new AxReferenceKey(owner1Key, "Entity5"), 105.0));
- apexDao.create(new DummyEntity(new AxReferenceKey(owner1Key, "Entity6"), 106.0));
- apexDao.create(new DummyEntity(new AxReferenceKey(owner1Key, "Entity7"), 107.0));
- apexDao.create(new DummyEntity(new AxReferenceKey(owner2Key, "Entity8"), 108.0));
- apexDao.create(new DummyEntity(new AxReferenceKey(owner2Key, "Entity9"), 109.0));
- apexDao.create(new DummyEntity(new AxReferenceKey(owner3Key, "EntityA"), 110.0));
- apexDao.create(new DummyEntity(new AxReferenceKey(owner4Key, "EntityB"), 111.0));
- apexDao.create(new DummyEntity(new AxReferenceKey(owner5Key, "EntityC"), 112.0));
- apexDao.create(new DummyEntity(new AxReferenceKey(owner5Key, "EntityD"), 113.0));
- apexDao.create(new DummyEntity(new AxReferenceKey(owner5Key, "EntityE"), 114.0));
- apexDao.create(new DummyEntity(new AxReferenceKey(owner5Key, "EntityF"), 115.0));
-
- TreeSet<DummyEntity> testEntitySetOut = new TreeSet<DummyEntity>(apexDao.getAll(DummyEntity.class));
- assertEquals(16, testEntitySetOut.size());
-
- testEntitySetOut = new TreeSet<DummyEntity>(apexDao.getAll(DummyEntity.class, owner0Key));
- assertEquals(5, testEntitySetOut.size());
-
- testEntitySetOut = new TreeSet<DummyEntity>(apexDao.getAll(DummyEntity.class, owner1Key));
- assertEquals(3, testEntitySetOut.size());
-
- testEntitySetOut = new TreeSet<DummyEntity>(apexDao.getAll(DummyEntity.class, owner2Key));
- assertEquals(2, testEntitySetOut.size());
-
- testEntitySetOut = new TreeSet<DummyEntity>(apexDao.getAll(DummyEntity.class, owner3Key));
- assertEquals(1, testEntitySetOut.size());
-
- testEntitySetOut = new TreeSet<DummyEntity>(apexDao.getAll(DummyEntity.class, owner4Key));
- assertEquals(1, testEntitySetOut.size());
-
- testEntitySetOut = new TreeSet<DummyEntity>(apexDao.getAll(DummyEntity.class, owner5Key));
- assertEquals(4, testEntitySetOut.size());
-
- assertNotNull(apexDao.get(DummyEntity.class, new AxReferenceKey(owner0Key, "Entity0")));
- assertNotNull(apexDao.getArtifact(DummyEntity.class, new AxReferenceKey(owner0Key, "Entity0")));
- assertNull(apexDao.get(DummyEntity.class, new AxReferenceKey(owner0Key, "Entity1000")));
- assertNull(apexDao.getArtifact(DummyEntity.class, new AxReferenceKey(owner0Key, "Entity1000")));
- apexDao.delete(DummyEntity.class, new AxReferenceKey(owner0Key, "Entity0"));
-
- final Set<AxReferenceKey> rKeySetIn = new TreeSet<AxReferenceKey>();
- rKeySetIn.add(new AxReferenceKey(owner4Key, "EntityB"));
- rKeySetIn.add(new AxReferenceKey(owner5Key, "EntityD"));
-
- final int deletedRCount = apexDao.deleteByReferenceKey(DummyEntity.class, rKeySetIn);
- assertEquals(2, deletedRCount);
-
- apexDao.update(new DummyEntity(new AxReferenceKey(owner5Key, "EntityF"), 120.0));
- }
-}
diff --git a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelFileWriterTest.java b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelFileWriterTest.java
index 331e57f47..0f8f956ab 100644
--- a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelFileWriterTest.java
+++ b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelFileWriterTest.java
@@ -1,7 +1,7 @@
/*
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
- * Modifications Copyright (C) 2020 Nordix Foundation
+ * Modifications Copyright (C) 2020,2022 Nordix Foundation
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -36,33 +36,27 @@ public class ApexModelFileWriterTest {
public void testModelFileWriter() throws IOException, ApexException {
ApexModelFileWriter<AxModel> modelFileWriter = new ApexModelFileWriter<>(true);
- modelFileWriter.setValidateFlag(true);
- assertTrue(modelFileWriter.isValidateFlag());
+ modelFileWriter.setValidate(true);
+ assertTrue(modelFileWriter.isValidate());
File tempFile = File.createTempFile("ApexFileWriterTest", "test");
File tempDir = tempFile.getParentFile();
File jsonTempFile = new File(tempDir.getAbsolutePath() + "/aaa/ApexFileWriterTest.json");
- File xmlTempFile = new File(tempDir.getAbsolutePath() + "/ccc/ApexFileWriterTest.xml");
AxModel model = new DummyApexBasicModelCreator().getModel();
modelFileWriter.apexModelWriteJsonFile(model, AxModel.class, jsonTempFile.getAbsolutePath());
- modelFileWriter.apexModelWriteXmlFile(model, AxModel.class, xmlTempFile.getAbsolutePath());
jsonTempFile.delete();
- xmlTempFile.delete();
new File(tempDir.getAbsolutePath() + "/aaa").delete();
new File(tempDir.getAbsolutePath() + "/ccc").delete();
jsonTempFile = new File(tempDir.getAbsolutePath() + "/aaa/bbb/ApexFileWriterTest.json");
- xmlTempFile = new File(tempDir.getAbsolutePath() + "/ccc/ddd/ApexFileWriterTest.xml");
modelFileWriter.apexModelWriteJsonFile(model, AxModel.class, jsonTempFile.getAbsolutePath());
- modelFileWriter.apexModelWriteXmlFile(model, AxModel.class, xmlTempFile.getAbsolutePath());
jsonTempFile.delete();
- xmlTempFile.delete();
new File(tempDir.getAbsolutePath() + "/aaa/bbb").delete();
new File(tempDir.getAbsolutePath() + "/aaa").delete();
@@ -70,19 +64,14 @@ public class ApexModelFileWriterTest {
new File(tempDir.getAbsolutePath() + "/ccc").delete();
File dirA = new File(tempDir.getAbsolutePath() + "/aaa");
- //File dirB = new File(tempDir.getAbsolutePath() + "/aaa/bbb");
+ // File dirB = new File(tempDir.getAbsolutePath() + "/aaa/bbb");
dirA.createNewFile();
- //dirB.createNewFile();
+ // dirB.createNewFile();
jsonTempFile = new File(tempDir.getAbsolutePath() + "/aaa/bbb/ApexFileWriterTest.json");
- jsonTempFile = new File(tempDir.getAbsolutePath() + "/aaa/bbb/ApexFileWriterTest.xml");
final File jsonTempFile01 = jsonTempFile;
- assertThatThrownBy(() -> modelFileWriter.apexModelWriteJsonFile(model, AxModel.class,
- jsonTempFile01.getAbsolutePath()))
- .hasMessageContaining("could not create directory");
-
- assertThatThrownBy(() -> modelFileWriter.apexModelWriteXmlFile(model, AxModel.class,
- jsonTempFile01.getAbsolutePath()))
+ assertThatThrownBy(
+ () -> modelFileWriter.apexModelWriteJsonFile(model, AxModel.class, jsonTempFile01.getAbsolutePath()))
.hasMessageContaining("could not create directory");
dirA.delete();
@@ -93,15 +82,10 @@ public class ApexModelFileWriterTest {
fileB.createNewFile();
jsonTempFile = new File(tempDir.getAbsolutePath() + "/aaa/bbb/ApexFileWriterTest.json");
- jsonTempFile = new File(tempDir.getAbsolutePath() + "/aaa/bbb/ApexFileWriterTest.xml");
File jsonTempFile02 = jsonTempFile;
- assertThatThrownBy(() -> modelFileWriter.apexModelWriteJsonFile(model, AxModel.class,
- jsonTempFile02.getAbsolutePath()))
- .hasMessageContaining("error processing file");
-
- assertThatThrownBy(() -> modelFileWriter.apexModelWriteXmlFile(model, AxModel.class,
- jsonTempFile02.getAbsolutePath()))
+ assertThatThrownBy(
+ () -> modelFileWriter.apexModelWriteJsonFile(model, AxModel.class, jsonTempFile02.getAbsolutePath()))
.hasMessageContaining("error processing file");
fileB.delete();
diff --git a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelReaderTest.java b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelReaderTest.java
index d75f20253..1152771ea 100644
--- a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelReaderTest.java
+++ b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelReaderTest.java
@@ -1,7 +1,7 @@
/*
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
- * Modifications Copyright (C) 2020 Nordix Foundation
+ * Modifications Copyright (C) 2020,2022 Nordix Foundation
* Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -34,45 +34,33 @@ import java.io.File;
import java.io.FileInputStream;
import java.io.FileReader;
import java.io.IOException;
-import java.lang.reflect.Field;
-import javax.xml.bind.JAXBException;
-import javax.xml.bind.PropertyException;
-import javax.xml.bind.Unmarshaller;
-import javax.xml.transform.stream.StreamSource;
import org.junit.Test;
import org.junit.runner.RunWith;
-import org.mockito.Mock;
-import org.mockito.Mockito;
-import org.mockito.MockitoAnnotations;
import org.mockito.runners.MockitoJUnitRunner;
import org.onap.policy.apex.model.basicmodel.concepts.ApexException;
import org.onap.policy.apex.model.basicmodel.concepts.AxModel;
@RunWith(MockitoJUnitRunner.class)
public class ApexModelReaderTest {
- @Mock
- private Unmarshaller unmarshallerMock;
-
@Test
public void testModelReader() throws IOException, ApexException {
AxModel model = new DummyApexBasicModelCreator().getModel();
AxModel invalidModel = new DummyApexBasicModelCreator().getInvalidModel();
ApexModelWriter<AxModel> modelWriter = new ApexModelWriter<AxModel>(AxModel.class);
- modelWriter.setValidateFlag(true);
- modelWriter.setJsonOutput(true);
+ modelWriter.setValidate(true);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
modelWriter.write(model, baos);
ByteArrayOutputStream baosInvalid = new ByteArrayOutputStream();
- modelWriter.setValidateFlag(false);
+ modelWriter.setValidate(false);
modelWriter.write(invalidModel, baosInvalid);
ApexModelReader<AxModel> modelReader = new ApexModelReader<AxModel>(AxModel.class, true);
- modelReader.setValidateFlag(true);
- assertTrue(modelReader.getValidateFlag());
+ modelReader.setValidate(true);
+ assertTrue(modelReader.isValidate());
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
AxModel readModel = modelReader.read(bais);
@@ -81,26 +69,24 @@ public class ApexModelReaderTest {
ByteArrayInputStream baisInvalid = new ByteArrayInputStream(baosInvalid.toByteArray());
assertThatThrownBy(() -> modelReader.read(baisInvalid))
.hasMessageStartingWith("Apex concept validation failed");
- modelReader.setValidateFlag(false);
- assertFalse(modelReader.getValidateFlag());
+ modelReader.setValidate(false);
+ assertFalse(modelReader.isValidate());
ByteArrayInputStream bais2 = new ByteArrayInputStream(baos.toByteArray());
AxModel readModel2 = modelReader.read(bais2);
assertEquals(model, readModel2);
- modelWriter.setJsonOutput(false);
-
- ByteArrayOutputStream baosXml = new ByteArrayOutputStream();
- modelWriter.write(model, baosXml);
+ ByteArrayOutputStream baosJson = new ByteArrayOutputStream();
+ modelWriter.write(model, baosJson);
- ByteArrayInputStream baisXml = new ByteArrayInputStream(baosXml.toByteArray());
- AxModel readModelXml = modelReader.read(baisXml);
- assertEquals(model, readModelXml);
+ ByteArrayInputStream baisJson = new ByteArrayInputStream(baosJson.toByteArray());
+ AxModel readModelJson = modelReader.read(baisJson);
+ assertEquals(model, readModelJson);
String dummyString = "SomeDummyText";
ByteArrayInputStream baisDummy = new ByteArrayInputStream(dummyString.getBytes());
assertThatThrownBy(() -> modelReader.read(baisDummy))
- .hasMessage("format of input for Apex concept is neither JSON nor XML");
+ .hasMessageContaining("Unable to unmarshal Apex concept");
ByteArrayInputStream nullBais = null;
assertThatThrownBy(() -> modelReader.read(nullBais))
.hasMessage("concept stream may not be null");
@@ -115,42 +101,5 @@ public class ApexModelReaderTest {
assertThatThrownBy(() -> modelReader.read(br))
.hasMessage("Unable to read Apex concept ");
tempFile.delete();
- modelReader.setSchema(null);
-
- final File tempFileA = File.createTempFile("Apex", "Dummy");
- assertThatThrownBy(() -> modelReader.setSchema(tempFileA.getCanonicalPath()))
- .hasMessage("Unable to load schema");
- tempFile.delete();
- modelReader.setSchema("xml/example.xsd");
- }
-
- @Test
- public void testSetInputTypeError() throws ApexModelException,
- NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
- MockitoAnnotations.initMocks(this);
-
- ApexModelReader<AxModel> modelReader = new ApexModelReader<AxModel>(AxModel.class, true);
-
- Field marshallerField = modelReader.getClass().getDeclaredField("unmarshaller");
- marshallerField.setAccessible(true);
- marshallerField.set(modelReader, unmarshallerMock);
- marshallerField.setAccessible(false);
-
- assertThatThrownBy(() -> {
- Mockito.doThrow(new JAXBException("Exception marshalling to JSON")).when(unmarshallerMock)
- .unmarshal((StreamSource) Mockito.anyObject(), Mockito.anyObject());
-
- modelReader.read("{Hello}");
- }).hasMessage("Unable to unmarshal Apex concept ");
- assertThatThrownBy(() -> {
- Mockito.doThrow(new PropertyException("Exception setting JAXB property")).when(unmarshallerMock)
- .setProperty(Mockito.anyString(), Mockito.anyString());
- modelReader.read("{Hello}");
- }).hasMessage("JAXB error setting unmarshaller for JSON input");
- assertThatThrownBy(() -> {
- Mockito.doThrow(new PropertyException("Exception setting JAXB property")).when(unmarshallerMock)
- .setProperty(Mockito.anyString(), Mockito.anyString());
- modelReader.read("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
- }).hasMessage("JAXB error setting unmarshaller for XML input");
}
}
diff --git a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelSaverTest.java b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelSaverTest.java
index ad897832e..c95106aa8 100644
--- a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelSaverTest.java
+++ b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelSaverTest.java
@@ -1,7 +1,7 @@
/*
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
- * Modifications Copyright (C) 2020 Nordix Foundation
+ * Modifications Copyright (C) 2020,2022 Nordix Foundation
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -41,14 +41,12 @@ public class ApexModelSaverTest {
Path tempPath = Files.createTempDirectory("ApexTest");
assertNotNull(tempPath);
- ApexModelSaver<AxModel> modelSaver = new ApexModelSaver<AxModel>(AxModel.class, model,
- tempPath.toAbsolutePath().toString());
+ ApexModelSaver<AxModel> modelSaver =
+ new ApexModelSaver<AxModel>(AxModel.class, model, tempPath.toAbsolutePath().toString());
assertNotNull(modelSaver);
- modelSaver.apexModelWriteXml();
modelSaver.apexModelWriteJson();
Files.deleteIfExists(new File(tempPath.toAbsolutePath() + "/BasicModel.json").toPath());
- Files.deleteIfExists(new File(tempPath.toAbsolutePath() + "/BasicModel.xml").toPath());
Files.deleteIfExists(tempPath);
}
}
diff --git a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelStringWriterTest.java b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelStringWriterTest.java
index 0b8d789ad..13e72d3e2 100644
--- a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelStringWriterTest.java
+++ b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelStringWriterTest.java
@@ -1,7 +1,7 @@
/*
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
- * Modifications Copyright (C) 2020 Nordix Foundation
+ * Modifications Copyright (C) 2020,2022 Nordix Foundation
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -38,33 +38,26 @@ public class ApexModelStringWriterTest {
AxModel basicModel = new DummyApexBasicModelCreator().getModel();
assertNotNull(basicModel);
- AxKeyInfo intKeyInfo = basicModel.getKeyInformation().get("IntegerKIKey");
+ AxKeyInfo intKeyInfo = basicModel.getKeyInformation().get("IntegerKIKey");
AxKeyInfo floatKeyInfo = basicModel.getKeyInformation().get("FloatKIKey");
// Ensure marshalling is OK
ApexModelStringWriter<AxKeyInfo> stringWriter = new ApexModelStringWriter<AxKeyInfo>(true);
- assertNotNull(stringWriter.writeJsonString(intKeyInfo, AxKeyInfo.class));
+ assertNotNull(stringWriter.writeJsonString(intKeyInfo, AxKeyInfo.class));
assertNotNull(stringWriter.writeJsonString(floatKeyInfo, AxKeyInfo.class));
- assertNotNull(stringWriter.writeString(intKeyInfo, AxKeyInfo.class, true));
- assertNotNull(stringWriter.writeString(floatKeyInfo, AxKeyInfo.class, true));
+ assertNotNull(stringWriter.writeString(intKeyInfo, AxKeyInfo.class));
+ assertNotNull(stringWriter.writeString(floatKeyInfo, AxKeyInfo.class));
- assertNotNull(stringWriter.writeString(intKeyInfo, AxKeyInfo.class, false));
- assertNotNull(stringWriter.writeString(floatKeyInfo, AxKeyInfo.class, false));
+ assertNotNull(stringWriter.writeString(intKeyInfo, AxKeyInfo.class));
+ assertNotNull(stringWriter.writeString(floatKeyInfo, AxKeyInfo.class));
- assertNotNull(stringWriter.writeXmlString(intKeyInfo, AxKeyInfo.class));
- assertNotNull(stringWriter.writeXmlString(floatKeyInfo, AxKeyInfo.class));
-
- assertThatThrownBy(() -> stringWriter.writeString(null, AxKeyInfo.class, true))
- .hasMessage("concept may not be null");
- assertThatThrownBy(() -> stringWriter.writeString(null, AxKeyInfo.class, false))
- .hasMessage("concept may not be null");
+ assertThatThrownBy(() -> stringWriter.writeString(null, AxKeyInfo.class)).hasMessage("concept may not be null");
+ assertThatThrownBy(() -> stringWriter.writeString(null, AxKeyInfo.class)).hasMessage("concept may not be null");
assertThatThrownBy(() -> stringWriter.writeJsonString(null, AxKeyInfo.class))
.hasMessage("error writing JSON string");
- assertThatThrownBy(() -> stringWriter.writeXmlString(null, AxKeyInfo.class))
- .hasMessage("error writing XML string");
- stringWriter.setValidateFlag(true);
- assertTrue(stringWriter.isValidateFlag());
+ stringWriter.setValidate(true);
+ assertTrue(stringWriter.isValidate());
}
}
diff --git a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelWriterTest.java b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelWriterTest.java
index 147eb206a..063855976 100644
--- a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelWriterTest.java
+++ b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelWriterTest.java
@@ -1,7 +1,7 @@
/*
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
- * Modifications Copyright (C) 2020 Nordix Foundation
+ * Modifications Copyright (C) 2020,2022 Nordix Foundation
* Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -23,65 +23,38 @@
package org.onap.policy.apex.model.basicmodel.handling;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
-import java.io.Writer;
-import java.lang.reflect.Field;
-import javax.xml.bind.JAXBException;
-import javax.xml.bind.Marshaller;
-import javax.xml.bind.PropertyException;
import org.junit.Test;
import org.junit.runner.RunWith;
-import org.mockito.Mock;
-import org.mockito.Mockito;
-import org.mockito.MockitoAnnotations;
import org.mockito.runners.MockitoJUnitRunner;
import org.onap.policy.apex.model.basicmodel.concepts.ApexException;
import org.onap.policy.apex.model.basicmodel.concepts.AxModel;
-import org.w3c.dom.Document;
@RunWith(MockitoJUnitRunner.class)
public class ApexModelWriterTest {
- @Mock
- private Marshaller marshallerMock;
-
@Test
public void testModelWriter() throws IOException, ApexException {
ApexModelWriter<AxModel> modelWriter = new ApexModelWriter<AxModel>(AxModel.class);
- modelWriter.setValidateFlag(true);
- assertTrue(modelWriter.getValidateFlag());
- assertEquals(0, modelWriter.getCDataFieldSet().size());
-
- assertFalse(modelWriter.isJsonOutput());
- modelWriter.setJsonOutput(true);
- assertTrue(modelWriter.isJsonOutput());
- modelWriter.setJsonOutput(false);
- assertFalse(modelWriter.isJsonOutput());
+ modelWriter.setValidate(true);
+ assertTrue(modelWriter.isValidate());
ByteArrayOutputStream baos = new ByteArrayOutputStream();
AxModel model = new DummyApexBasicModelCreator().getModel();
modelWriter.write(model, baos);
- modelWriter.setJsonOutput(true);
- modelWriter.write(model, baos);
- modelWriter.setJsonOutput(false);
- modelWriter.setValidateFlag(false);
+ modelWriter.setValidate(false);
modelWriter.write(model, baos);
- modelWriter.setJsonOutput(true);
- modelWriter.write(model, baos);
- modelWriter.setJsonOutput(false);
- modelWriter.setValidateFlag(true);
+ modelWriter.setValidate(true);
model.getKeyInformation().getKeyInfoMap().clear();
assertThatThrownBy(() -> modelWriter.write(model, baos))
- .hasMessageContaining("Apex concept xml (BasicModel:0.0.1) validation failed");
+ .hasMessageContaining("Apex concept (BasicModel:0.0.1) validation failed");
model.getKeyInformation().generateKeyInfo(model);
assertThatThrownBy(() -> modelWriter.write(null, baos))
@@ -91,73 +64,4 @@ public class ApexModelWriterTest {
assertThatThrownBy(() -> modelWriter.write(model, nullBaos))
.hasMessage("concept stream may not be null");
}
-
- @Test
- public void testSetOutputTypeError() throws ApexModelException, NoSuchFieldException, SecurityException,
- IllegalArgumentException, IllegalAccessException, PropertyException {
- MockitoAnnotations.initMocks(this);
-
- ApexModelWriter<AxModel> modelWriter = new ApexModelWriter<AxModel>(AxModel.class);
-
- Field marshallerField = modelWriter.getClass().getDeclaredField("marshaller");
- marshallerField.setAccessible(true);
- marshallerField.set(modelWriter, marshallerMock);
- marshallerField.setAccessible(false);
- Mockito.doThrow(new PropertyException("Exception setting JAXB property")).when(marshallerMock)
- .setProperty(Mockito.anyString(), Mockito.anyString());
- assertThatThrownBy(() -> modelWriter.setJsonOutput(true))
- .hasMessage("JAXB error setting marshaller for JSON output");
- Mockito.doThrow(new PropertyException("Exception setting JAXB property")).when(marshallerMock)
- .setProperty(Mockito.anyString(), Mockito.anyString());
- assertThatThrownBy(() -> modelWriter.setJsonOutput(false))
- .hasMessage("JAXB error setting marshaller for XML output");
- }
-
- @Test
- public void testOutputJsonError() throws ApexModelException, NoSuchFieldException, SecurityException,
- IllegalArgumentException, IllegalAccessException, JAXBException {
- MockitoAnnotations.initMocks(this);
-
- ApexModelWriter<AxModel> modelWriter = new ApexModelWriter<AxModel>(AxModel.class);
-
- Field marshallerField = modelWriter.getClass().getDeclaredField("marshaller");
- marshallerField.setAccessible(true);
- marshallerField.set(modelWriter, marshallerMock);
- marshallerField.setAccessible(false);
-
- modelWriter.setValidateFlag(false);
- modelWriter.setJsonOutput(true);
-
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- AxModel model = new DummyApexBasicModelCreator().getModel();
- Mockito.doThrow(new JAXBException("Exception marshalling to JSON")).when(marshallerMock)
- .marshal((AxModel) Mockito.anyObject(), (Writer) Mockito.anyObject());
- assertThatThrownBy(() -> modelWriter.write(model, baos)).hasMessage("Unable to marshal Apex concept to JSON");
- }
-
- @Test
- public void testOutputXmlError() throws ApexModelException, NoSuchFieldException, SecurityException,
- IllegalArgumentException, IllegalAccessException, JAXBException {
- MockitoAnnotations.initMocks(this);
-
- ApexModelWriter<AxModel> modelWriter = new ApexModelWriter<AxModel>(AxModel.class);
- modelWriter.setJsonOutput(false);
-
- Field marshallerField = modelWriter.getClass().getDeclaredField("marshaller");
- marshallerField.setAccessible(true);
- marshallerField.set(modelWriter, marshallerMock);
- marshallerField.setAccessible(false);
-
- modelWriter.setValidateFlag(false);
- modelWriter.setJsonOutput(false);
-
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- AxModel model = new DummyApexBasicModelCreator().getModel();
-
- Mockito.doThrow(new JAXBException("Exception marshalling to JSON")).when(marshallerMock)
- .marshal((AxModel) Mockito.anyObject(), (Document) Mockito.anyObject());
-
- assertThatThrownBy(() -> modelWriter.write(model, baos))
- .hasMessage("Unable to marshal Apex concept to XML");
- }
}
diff --git a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ApexSchemaGeneratorTest.java b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ApexSchemaGeneratorTest.java
deleted file mode 100644
index 3385830e2..000000000
--- a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ApexSchemaGeneratorTest.java
+++ /dev/null
@@ -1,95 +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.handling;
-
-import static org.junit.Assert.assertTrue;
-
-import java.io.ByteArrayOutputStream;
-import java.io.File;
-import java.io.FileDescriptor;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.PrintStream;
-import org.junit.After;
-import org.junit.Test;
-
-public class ApexSchemaGeneratorTest {
- private final PrintStream stdout = System.out;
-
- @After
- public void tearDown() throws Exception {
- System.setOut(stdout);
- }
-
- @Test
- public void test() throws IOException {
- final ByteArrayOutputStream baos0 = new ByteArrayOutputStream();
- System.setOut(new PrintStream(baos0));
-
- final String[] args0 = {};
- ApexSchemaGenerator.main(args0);
- assertTrue(baos0.toString().contains("usage: ApexSchemaGenerator apex-root-class [schema-file-name]"));
- System.setOut(new PrintStream(new FileOutputStream(FileDescriptor.out)));
-
- final ByteArrayOutputStream baos1 = new ByteArrayOutputStream();
- System.setOut(new PrintStream(baos1));
-
- final String[] args1 = { "hello", "goodbye", "here" };
- ApexSchemaGenerator.main(args1);
- assertTrue(baos1.toString().contains("usage: ApexSchemaGenerator apex-root-class [schema-file-name]"));
- System.setOut(new PrintStream(new FileOutputStream(FileDescriptor.out)));
-
- final ByteArrayOutputStream baos2 = new ByteArrayOutputStream();
- System.setOut(new PrintStream(baos2));
-
- final String[] args2 = { "hello", "goodbye" };
- ApexSchemaGenerator.main(args2);
- assertTrue(baos2.toString().contains("error on Apex schema output"));
- System.setOut(new PrintStream(new FileOutputStream(FileDescriptor.out)));
-
- final ByteArrayOutputStream baos3 = new ByteArrayOutputStream();
- System.setOut(new PrintStream(baos3));
-
- final String[] args3 = { "hello" };
- ApexSchemaGenerator.main(args3);
- assertTrue(baos3.toString().contains("could not create JAXB context, root class hello not found"));
- System.setOut(new PrintStream(new FileOutputStream(FileDescriptor.out)));
-
- final ByteArrayOutputStream baos4 = new ByteArrayOutputStream();
- System.setOut(new PrintStream(baos4));
-
- final String[] args4 = { "org.onap.policy.apex.model.basicmodel.concepts.AxModel" };
- ApexSchemaGenerator.main(args4);
- assertTrue(baos4.toString().contains("targetNamespace=\"http://www.onap.org/policy/apex-pdp\""));
- System.setOut(new PrintStream(new FileOutputStream(FileDescriptor.out)));
-
- final ByteArrayOutputStream baos5 = new ByteArrayOutputStream();
- System.setOut(new PrintStream(baos5));
-
- final File tempFile = File.createTempFile("ApexSchemaGeneratorTest", "xsd");
- tempFile.deleteOnExit();
- final String[] args5 =
- { "org.onap.policy.apex.model.basicmodel.concepts.AxModel", tempFile.getCanonicalPath() };
-
- ApexSchemaGenerator.main(args5);
- assertTrue(tempFile.length() > 100);
- }
-}
diff --git a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/SupportApexBasicModelTest.java b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/SupportApexBasicModelTest.java
index 1c21b6c33..68f755886 100644
--- a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/SupportApexBasicModelTest.java
+++ b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/SupportApexBasicModelTest.java
@@ -1,7 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
- * Modifications Copyright (C) 2020-2021 Nordix Foundation.
+ * Modifications Copyright (C) 2020-2022 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -28,10 +28,45 @@ import org.junit.Before;
import org.junit.Test;
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.DaoParameters;
import org.onap.policy.apex.model.basicmodel.test.TestApexModel;
public class SupportApexBasicModelTest {
+ // As there are no real concepts in a basic model, this is as near to a valid model as we can get
+ private static final String VALID_MODEL_STRING = "\n" + "***warnings issued during validation of model***\n"
+ + "AxArtifactKey:(name=FloatKIKey,version=0.0.1):org.onap.policy.apex.model.basicmodel.concepts"
+ + ".AxModel:WARNING:key not found for key information entry\n"
+ + "AxArtifactKey:(name=IntegerKIKey,version=0.0.1):org.onap.policy.apex.model.basicmodel.concepts"
+ + ".AxModel:WARNING:key not found for key information entry\n" + "********************************";
+
+ private static final String WARNING_MODEL_STRING = "\n" + "***warnings issued during validation of model***\n"
+ + "AxArtifactKey:(name=FloatKIKey,version=0.0.1):org.onap.policy.apex.model.basicmodel.concepts"
+ + ".AxModel:WARNING:key not found for key information entry\n"
+ + "AxArtifactKey:(name=IntegerKIKey,version=0.0.1):org.onap.policy.apex.model.basicmodel.concepts"
+ + ".AxModel:WARNING:key not found for key information entry\n"
+ + "AxArtifactKey:(name=Unref0,version=0.0.1):org.onap.policy.apex.model.basicmodel.concepts"
+ + ".AxModel:WARNING:key not found for key information entry\n"
+ + "AxArtifactKey:(name=Unref1,version=0.0.1):org.onap.policy.apex.model.basicmodel.concepts"
+ + ".AxModel:WARNING:key not found for key information entry\n" + "********************************";
+
+ private static final String INVALID_MODEL_STRING = "\n" + "***validation of model failed***\n"
+ + "AxArtifactKey:(name=BasicModelKey,version=0.0.1):org.onap.policy.apex.model.basicmodel.concepts."
+ + "AxKeyInfo:WARNING:UUID is a zero UUID: 00000000-0000-0000-0000-000000000000\n"
+ + "AxArtifactKey:(name=KeyInfoMapKey,version=0.0.1):org.onap.policy.apex.model.basicmodel.concepts."
+ + "AxKeyInfo:OBSERVATION:description is blank\n"
+ + "AxArtifactKey:(name=KeyInfoMapKey,version=0.0.1):org.onap.policy.apex.model.basicmodel.concepts."
+ + "AxKeyInfo:WARNING:UUID is a zero UUID: 00000000-0000-0000-0000-000000000000\n"
+ + "AxArtifactKey:(name=KeyInfoMapKey,version=0.0.1):org.onap.policy.apex.model.basicmodel.concepts."
+ + "AxKeyInformation:INVALID:duplicate UUID found on keyInfoMap entry AxArtifactKey:"
+ + "(name=KeyInfoMapKey,version=0.0.1):00000000-0000-0000-0000-000000000000\n"
+ + "********************************";
+
+ private static final String INVALID_MODEL_MALSTRUCTURED_STRING = "\n" + "***validation of model failed***\n"
+ + "AxArtifactKey:(name=BasicModelKey,version=0.0.1):org.onap.policy.apex.model.basicmodel.concepts."
+ + "AxKeyInfo:WARNING:UUID is a zero UUID: 00000000-0000-0000-0000-000000000000\n"
+ + "AxArtifactKey:(name=BasicModelKey,version=0.0.1):org.onap.policy.apex.model.basicmodel.concepts."
+ + "AxModel:INVALID:key information not found for key "
+ + "AxArtifactKey:(name=KeyInfoMapKey,version=0.0.1)\n" + "********************************";
+
TestApexModel<AxModel> testApexModel;
/**
@@ -75,57 +110,7 @@ public class SupportApexBasicModelTest {
}
@Test
- public void testModelWriteReadXml() throws Exception {
- testApexModel.testApexModelWriteReadXml();
- }
-
- @Test
public void testModelWriteReadJson() throws Exception {
testApexModel.testApexModelWriteReadJson();
}
-
- @Test
- public void testModelWriteReadJpa() throws Exception {
- final DaoParameters daoParameters = new DaoParameters();
- daoParameters.setPluginClass("org.onap.policy.apex.model.basicmodel.dao.impl.DefaultApexDao");
- daoParameters.setPersistenceUnit("DaoTest");
-
- testApexModel.testApexModelWriteReadJpa(daoParameters);
- }
-
- // As there are no real concepts in a basic model, this is as near to a valid model as we can get
- private static final String VALID_MODEL_STRING = "\n" + "***warnings issued during validation of model***\n"
- + "AxArtifactKey:(name=FloatKIKey,version=0.0.1):org.onap.policy.apex.model.basicmodel.concepts"
- + ".AxModel:WARNING:key not found for key information entry\n"
- + "AxArtifactKey:(name=IntegerKIKey,version=0.0.1):org.onap.policy.apex.model.basicmodel.concepts"
- + ".AxModel:WARNING:key not found for key information entry\n" + "********************************";
-
- private static final String WARNING_MODEL_STRING = "\n" + "***warnings issued during validation of model***\n"
- + "AxArtifactKey:(name=FloatKIKey,version=0.0.1):org.onap.policy.apex.model.basicmodel.concepts"
- + ".AxModel:WARNING:key not found for key information entry\n"
- + "AxArtifactKey:(name=IntegerKIKey,version=0.0.1):org.onap.policy.apex.model.basicmodel.concepts"
- + ".AxModel:WARNING:key not found for key information entry\n"
- + "AxArtifactKey:(name=Unref0,version=0.0.1):org.onap.policy.apex.model.basicmodel.concepts"
- + ".AxModel:WARNING:key not found for key information entry\n"
- + "AxArtifactKey:(name=Unref1,version=0.0.1):org.onap.policy.apex.model.basicmodel.concepts"
- + ".AxModel:WARNING:key not found for key information entry\n" + "********************************";
-
- private static final String INVALID_MODEL_STRING = "\n" + "***validation of model failed***\n"
- + "AxArtifactKey:(name=BasicModelKey,version=0.0.1):org.onap.policy.apex.model.basicmodel.concepts."
- + "AxKeyInfo:WARNING:UUID is a zero UUID: 00000000-0000-0000-0000-000000000000\n"
- + "AxArtifactKey:(name=KeyInfoMapKey,version=0.0.1):org.onap.policy.apex.model.basicmodel.concepts."
- + "AxKeyInfo:OBSERVATION:description is blank\n"
- + "AxArtifactKey:(name=KeyInfoMapKey,version=0.0.1):org.onap.policy.apex.model.basicmodel.concepts."
- + "AxKeyInfo:WARNING:UUID is a zero UUID: 00000000-0000-0000-0000-000000000000\n"
- + "AxArtifactKey:(name=KeyInfoMapKey,version=0.0.1):org.onap.policy.apex.model.basicmodel.concepts."
- + "AxKeyInformation:INVALID:duplicate UUID found on keyInfoMap entry AxArtifactKey:"
- + "(name=KeyInfoMapKey,version=0.0.1):00000000-0000-0000-0000-000000000000\n"
- + "********************************";
-
- private static final String INVALID_MODEL_MALSTRUCTURED_STRING = "\n" + "***validation of model failed***\n"
- + "AxArtifactKey:(name=BasicModelKey,version=0.0.1):org.onap.policy.apex.model.basicmodel.concepts."
- + "AxKeyInfo:WARNING:UUID is a zero UUID: 00000000-0000-0000-0000-000000000000\n"
- + "AxArtifactKey:(name=BasicModelKey,version=0.0.1):org.onap.policy.apex.model.basicmodel.concepts."
- + "AxModel:INVALID:key information not found for key "
- + "AxArtifactKey:(name=KeyInfoMapKey,version=0.0.1)\n" + "********************************";
}
diff --git a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/SupportBasicModelTest.java b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/SupportBasicModelTest.java
index 5fc678ac0..d55a9da29 100644
--- a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/SupportBasicModelTest.java
+++ b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/SupportBasicModelTest.java
@@ -1,7 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
- * Modifications Copyright (C) 2020-2021 Nordix Foundation
+ * Modifications Copyright (C) 2020-2022 Nordix Foundation
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -43,7 +43,6 @@ public class SupportBasicModelTest {
testApexModel.testApexModelVaidateMalstructured();
testApexModel.testApexModelWriteReadJson();
- testApexModel.testApexModelWriteReadXml();
}
@Test
@@ -102,14 +101,11 @@ public class SupportBasicModelTest {
}
@Test
- public void testModelCreator1XmlJson() throws ApexException {
+ public void testModelCreator1Json() throws ApexException {
final TestApexModel<AxModel> testApexModel = new TestApexModel<AxModel>(AxModel.class,
new SupportApexModelCreator1());
assertThatThrownBy(() -> testApexModel.testApexModelWriteReadJson())
.hasMessageStartingWith("error processing file");
-
- assertThatThrownBy(() -> testApexModel.testApexModelWriteReadXml())
- .hasMessageStartingWith("error processing file");
}
}
diff --git a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/SupportConceptGetterTest.java b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/SupportConceptGetterTest.java
index 006c583ec..1783fc00f 100644
--- a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/SupportConceptGetterTest.java
+++ b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/SupportConceptGetterTest.java
@@ -1,7 +1,7 @@
/*
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
- * Modifications Copyright (C) 2020-2021 Nordix Foundation.
+ * Modifications Copyright (C) 2020-2022 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -156,19 +156,19 @@ public class SupportConceptGetterTest {
ApexModelReader<AxModel> modelReader = new ApexModelReader<AxModel>(AxModel.class);
ApexModelFileWriter<AxModel> modelWriter = new ApexModelFileWriter<AxModel>(true);
- modelReader.setValidateFlag(false);
- modelWriter.setValidateFlag(false);
+ modelReader.setValidate(false);
+ modelWriter.setValidate(false);
- File tempXmlFile = File.createTempFile("ApexModel", "xml");
- modelWriter.apexModelWriteJsonFile(basicModel, AxModel.class, tempXmlFile.getCanonicalPath());
+ File tempJsonFile = File.createTempFile("ApexModel", "json");
+ modelWriter.apexModelWriteJsonFile(basicModel, AxModel.class, tempJsonFile.getCanonicalPath());
- FileInputStream xmlFileInputStream = new FileInputStream(tempXmlFile);
- AxModel readXmlModel = modelReader.read(xmlFileInputStream);
- xmlFileInputStream.close();
- assertEquals(basicModel, readXmlModel);
- assertEquals(intKI91, readXmlModel.getKeyInformation().get("IntegerKIKey91"));
- assertNotNull(readXmlModel.getKeyInformation().get("FloatKIKey"));
- tempXmlFile.delete();
+ FileInputStream jsonFileInputStream = new FileInputStream(tempJsonFile);
+ AxModel readJsonModel = modelReader.read(jsonFileInputStream);
+ jsonFileInputStream.close();
+ assertEquals(basicModel, readJsonModel);
+ assertEquals(intKI91, readJsonModel.getKeyInformation().get("IntegerKIKey91"));
+ assertNotNull(readJsonModel.getKeyInformation().get("FloatKIKey"));
+ tempJsonFile.delete();
}
private AxModel setTestBasicModel() {
diff --git a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/xml/AxReferenceKeyAdapterTest.java b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/xml/AxReferenceKeyAdapterTest.java
deleted file mode 100644
index 12a67c803..000000000
--- a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/xml/AxReferenceKeyAdapterTest.java
+++ /dev/null
@@ -1,42 +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.xml;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-
-import org.junit.Test;
-import org.onap.policy.apex.model.basicmodel.concepts.AxReferenceKey;
-
-public class AxReferenceKeyAdapterTest {
-
- @Test
- public void test() throws Exception {
- AxReferenceKeyAdapter arka = new AxReferenceKeyAdapter();
- assertNotNull(arka);
-
- AxReferenceKey rkey = new AxReferenceKey("Name", "0.0.1", "PLN", "LN");
-
- String rkeyString = arka.marshal(rkey);
- assertEquals("LN", rkeyString);
- assertEquals(rkey.getLocalName(), arka.unmarshal(rkeyString).getLocalName());
- }
-}
diff --git a/model/basic-model/src/test/resources/META-INF/persistence.xml b/model/basic-model/src/test/resources/META-INF/persistence.xml
deleted file mode 100644
index 01a8989bb..000000000
--- a/model/basic-model/src/test/resources/META-INF/persistence.xml
+++ /dev/null
@@ -1,43 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
- ============LICENSE_START=======================================================
- Copyright (C) 2016-2018 Ericsson. All rights reserved.
- ================================================================================
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-
- SPDX-License-Identifier: Apache-2.0
- ============LICENSE_END=========================================================
--->
-
-<persistence xmlns="http://java.sun.com/xml/ns/persistence" version="2.0">
- <persistence-unit name="DaoTest" transaction-type="RESOURCE_LOCAL">
- <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
-
- <class>org.onap.policy.apex.model.basicmodel.dao.converters.CDataConditioner</class>
- <class>org.onap.policy.apex.model.basicmodel.dao.converters.Uuid2String</class>
- <class>org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey</class>
- <class>org.onap.policy.apex.model.basicmodel.concepts.AxReferenceKey</class>
- <class>org.onap.policy.apex.model.basicmodel.concepts.AxKeyInfo</class>
- <class>org.onap.policy.apex.model.basicmodel.concepts.AxKeyInformation</class>
- <class>org.onap.policy.apex.model.basicmodel.concepts.AxModel</class>
- <class>org.onap.policy.apex.model.basicmodel.concepts.DummyEntity</class>
-
- <properties>
- <property name="javax.persistence.jdbc.url" value="jdbc:h2:mem:testdb" />
- <property name="javax.persistence.jdbc.driver" value="org.h2.Driver" />
- <property name="eclipselink.ddl-generation" value="drop-and-create-tables" />
- <property name="eclipselink.ddl-generation.output-mode" value="database"/>
- <property name="eclipselink.logging.level" value="INFO" />
- </properties>
- </persistence-unit>
-</persistence>