aboutsummaryrefslogtreecommitdiffstats
path: root/model/basic-model/src/main
diff options
context:
space:
mode:
authorlapentafd <francesco.lapenta@est.tech>2021-06-02 12:02:46 +0100
committerlapentafd <francesco.lapenta@est.tech>2021-06-08 10:07:11 +0100
commit1418e7fcc3bba8980e1877c6576983583877ec1e (patch)
tree8537c66c29beea9c6f7a28b256ba846d880760d4 /model/basic-model/src/main
parent328fa34f8ac18d30fec00c7c5f59a05850f631a5 (diff)
Fix Sonar Issues in apex-pdp-model
Changes made into model/basic-model Renamed test classes to match the others Issue-ID: POLICY-3093 Change-Id: I7a0d6046ead42a9165aaf96b89511dd8d064d109 Signed-off-by: lapentafd <francesco.lapenta@est.tech>
Diffstat (limited to 'model/basic-model/src/main')
-rw-r--r--model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/concepts/ApexException.java5
-rw-r--r--model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/concepts/AxArtifactKey.java14
-rw-r--r--model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/concepts/AxConceptGetterImpl.java6
-rw-r--r--model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/concepts/AxKeyInfo.java12
-rw-r--r--model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/concepts/AxKeyInformation.java10
-rw-r--r--model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelFileWriter.java13
-rw-r--r--model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelReader.java15
-rw-r--r--model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelSaver.java6
-rw-r--r--model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelStringWriter.java16
-rw-r--r--model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelWriter.java16
-rw-r--r--model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/handling/ApexSchemaGenerator.java12
-rw-r--r--model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/test/TestApexModel.java53
12 files changed, 83 insertions, 95 deletions
diff --git a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/concepts/ApexException.java b/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/concepts/ApexException.java
index 97920c3b5..2eca2f783 100644
--- a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/concepts/ApexException.java
+++ b/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/concepts/ApexException.java
@@ -1,6 +1,7 @@
/*-
* ============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.
@@ -88,10 +89,10 @@ public class ApexException extends Exception {
* @return cascaded message string
*/
public static String buildCascadedMessage(Throwable throwable) {
- final StringBuilder builder = new StringBuilder();
+ final var builder = new StringBuilder();
builder.append(throwable.getMessage());
- for (Throwable t = throwable; t != null; t = t.getCause()) {
+ for (var t = throwable; t != null; t = t.getCause()) {
builder.append("\ncaused by: ");
builder.append(t.getMessage());
}
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 86c89c35e..6e0a3cf4d 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 Nordix Foundation.
+ * Modifications Copyright (C) 2019-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.
@@ -235,7 +235,7 @@ public class AxArtifactKey extends AxKey {
}
final AxArtifactKey otherArtifactKey = (AxArtifactKey) otherKey;
- final Compatibility compatibility = this.getCompatibility(otherArtifactKey);
+ final var compatibility = this.getCompatibility(otherArtifactKey);
return !(compatibility == Compatibility.DIFFERENT || compatibility == Compatibility.MAJOR);
}
@@ -245,14 +245,14 @@ public class AxArtifactKey extends AxKey {
*/
@Override
public AxValidationResult validate(final AxValidationResult result) {
- final String nameValidationErrorMessage = Assertions.getStringParameterValidationMessage(NAME_TOKEN, name,
+ final var nameValidationErrorMessage = Assertions.getStringParameterValidationMessage(NAME_TOKEN, name,
NAME_REGEXP);
if (nameValidationErrorMessage != null) {
result.addValidationMessage(new AxValidationMessage(this, this.getClass(), ValidationResult.INVALID,
"name invalid-" + nameValidationErrorMessage));
}
- final String versionValidationErrorMessage = Assertions.getStringParameterValidationMessage(VERSION_TOKEN,
+ final var versionValidationErrorMessage = Assertions.getStringParameterValidationMessage(VERSION_TOKEN,
version, VERSION_REGEXP);
if (versionValidationErrorMessage != null) {
result.addValidationMessage(new AxValidationMessage(this, this.getClass(), ValidationResult.INVALID,
@@ -276,7 +276,7 @@ public class AxArtifactKey extends AxKey {
*/
@Override
public String toString() {
- final StringBuilder builder = new StringBuilder();
+ final var builder = new StringBuilder();
builder.append(this.getClass().getSimpleName());
builder.append(":(");
builder.append("name=");
@@ -309,8 +309,8 @@ public class AxArtifactKey extends AxKey {
*/
@Override
public int hashCode() {
- final int prime = 31;
- int result = 1;
+ final var prime = 31;
+ var result = 1;
result = prime * result + name.hashCode();
result = prime * result + version.hashCode();
return result;
diff --git a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/concepts/AxConceptGetterImpl.java b/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/concepts/AxConceptGetterImpl.java
index 175cded08..9c907da9c 100644
--- a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/concepts/AxConceptGetterImpl.java
+++ b/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/concepts/AxConceptGetterImpl.java
@@ -1,7 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
- * Modifications Copyright (C) 2019 Nordix Foundation.
+ * Modifications Copyright (C) 2019-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.
@@ -62,7 +62,7 @@ public class AxConceptGetterImpl<C> implements AxConceptGetter<C> {
Assertions.argumentNotNull(conceptKeyName, "conceptKeyName may not be null");
// The very fist key that could have this name
- final AxArtifactKey lowestArtifactKey = new AxArtifactKey(conceptKeyName, "0.0.1");
+ final var lowestArtifactKey = new AxArtifactKey(conceptKeyName, "0.0.1");
// Check if we found a key for our name
AxArtifactKey foundKey = conceptMap.ceilingKey(lowestArtifactKey);
@@ -117,7 +117,7 @@ public class AxConceptGetterImpl<C> implements AxConceptGetter<C> {
}
// The very fist key that could have this name
- final AxArtifactKey lowestArtifactKey = new AxArtifactKey(conceptKeyName, "0.0.1");
+ final var lowestArtifactKey = new AxArtifactKey(conceptKeyName, "0.0.1");
if (conceptKeyVersion != null) {
lowestArtifactKey.setVersion(conceptKeyVersion);
}
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 4b84a403a..7e92faddf 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 Nordix Foundation.
+ * Modifications Copyright (C) 2019-2021 Nordix Foundation.
* Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -233,7 +233,7 @@ public class AxKeyInfo extends AxConcept {
*/
@Override
public String toString() {
- final StringBuilder builder = new StringBuilder();
+ final var builder = new StringBuilder();
builder.append(this.getClass().getSimpleName());
builder.append(":(");
builder.append("artifactId=");
@@ -269,8 +269,8 @@ public class AxKeyInfo extends AxConcept {
*/
@Override
public int hashCode() {
- final int prime = 31;
- int result = 1;
+ final var prime = 31;
+ var result = 1;
result = prime * result + key.hashCode();
result = prime * result + uuid.hashCode();
result = prime * result + description.hashCode();
@@ -336,14 +336,14 @@ public class AxKeyInfo extends AxConcept {
* @return the uuid
*/
public static UUID generateReproducibleUuid(final String seed) {
- Random random = sharedRandom;
+ var random = sharedRandom;
if (!StringUtils.isEmpty(seed)) {
/*
* This is not used for encryption/security, thus disabling sonar.
*/
random = new Random(seed.hashCode()); // NOSONAR
}
- final byte[] array = new byte[UUID_BYTE_LENGTH_16];
+ final var array = new byte[UUID_BYTE_LENGTH_16];
random.nextBytes(array);
return UUID.nameUUIDFromBytes(array);
}
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 2619d2eea..fe597bb08 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-2020 Nordix Foundation.
+ * Modifications Copyright (C) 2019-2021 Nordix Foundation.
* Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -151,7 +151,7 @@ public class AxKeyInformation extends AxConcept implements AxConceptGetter<AxKey
final AxArtifactKey artifactKey = (AxArtifactKey) axKey;
keyInfoMap.computeIfAbsent(artifactKey, unusedKey -> {
- final AxKeyInfo keyInfo = new AxKeyInfo(artifactKey);
+ final var keyInfo = new AxKeyInfo(artifactKey);
// generate a reproducible UUID
keyInfo.setUuid(AxKeyInfo.generateReproducibleUuid(keyInfo.getId() + keyInfo.getDescription()));
return keyInfo;
@@ -290,7 +290,7 @@ public class AxKeyInformation extends AxConcept implements AxConceptGetter<AxKey
*/
@Override
public String toString() {
- final StringBuilder builder = new StringBuilder();
+ final var builder = new StringBuilder();
builder.append(this.getClass().getSimpleName());
builder.append(":(");
builder.append("key=");
@@ -327,8 +327,8 @@ public class AxKeyInformation extends AxConcept implements AxConceptGetter<AxKey
*/
@Override
public int hashCode() {
- final int prime = 31;
- int result = 1;
+ final var prime = 31;
+ var result = 1;
result = prime * result + key.hashCode();
result = prime * result + keyInfoMap.hashCode();
return result;
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 04dd2a3f4..908ad31aa 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,19 +1,20 @@
/*
* ============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=========================================================
*/
@@ -120,16 +121,14 @@ public class ApexModelFileWriter<M extends AxModel> {
*/
private void writeModelFile(final M model, final ApexModelWriter<M> modelWriter, final String modelFileName)
throws ApexException {
- final File modelFile = new File(modelFileName);
+ final var modelFile = new File(modelFileName);
if (!modelFile.getParentFile().exists() && !modelFile.getParentFile().mkdirs()) {
LOGGER.warn("could not create directory " + modelFile.getParentFile());
throw new ApexException("could not create directory " + modelFile.getParentFile());
}
- try {
- final FileOutputStream fileOutputStream = new FileOutputStream(modelFile);
+ try (final var fileOutputStream = new FileOutputStream(modelFile)) {
modelWriter.write(model, fileOutputStream);
- fileOutputStream.close();
} catch (final Exception e) {
LOGGER.warn("error processing file " + modelFile.getAbsolutePath(), e);
throw new ApexException("error processing file " + modelFile.getAbsolutePath(), e);
diff --git a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelReader.java b/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelReader.java
index db7360e75..7e136f6b3 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-2020 Nordix Foundation.
+ * Modifications Copyright (C) 2019-2021 Nordix Foundation.
* Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -27,15 +27,12 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.StringReader;
-import java.net.URL;
import java.util.regex.Pattern;
import javax.xml.XMLConstants;
-import javax.xml.bind.JAXBContext;
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.Schema;
import javax.xml.validation.SchemaFactory;
import org.eclipse.persistence.jaxb.JAXBContextFactory;
import org.eclipse.persistence.jaxb.MarshallerProperties;
@@ -86,7 +83,7 @@ public class ApexModelReader<C extends AxConcept> {
this.rootConceptClass = rootConceptClass;
try {
- final JAXBContext jaxbContext = JAXBContextFactory.createContext(new Class[] {rootConceptClass}, null);
+ final var jaxbContext = JAXBContextFactory.createContext(new Class[] {rootConceptClass}, null);
// Set up the unmarshaller to carry out validation
unmarshaller = jaxbContext.createUnmarshaller();
@@ -120,8 +117,8 @@ public class ApexModelReader<C extends AxConcept> {
if (schemaFileName != null) {
try {
// Set the concept schema
- final URL schemaUrl = ResourceUtils.getUrlResource(schemaFileName);
- final Schema apexConceptSchema =
+ 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) {
@@ -182,7 +179,7 @@ public class ApexModelReader<C extends AxConcept> {
LOGGER.entry("reading Apex concept from string . . .");
- final String apexString = apexConceptString.trim();
+ final var apexString = apexConceptString.trim();
// Set the type of input for this stream
setInputType(apexString);
@@ -193,7 +190,7 @@ public class ApexModelReader<C extends AxConcept> {
// Use JAXB to read and verify the Apex concept XML file
try {
// Load the configuration file
- final StreamSource source = new StreamSource(new StringReader(apexString));
+ final var source = new StreamSource(new StringReader(apexString));
final JAXBElement<C> rootElement = unmarshaller.unmarshal(source, rootConceptClass);
apexConcept = rootElement.getValue();
} catch (final JAXBException e) {
diff --git a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelSaver.java b/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelSaver.java
index 8217badbc..dea32df49 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 Nordix Foundation.
+ * Modifications Copyright (C) 2019-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.
@@ -72,7 +72,7 @@ public class ApexModelSaver<M extends AxModel> {
LOGGER.debug("running apexModelWriteXML . . .");
// Write the file to disk
- final File xmlFile = new File(writePath + File.separatorChar + model.getKey().getName() + ".xml");
+ 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");
@@ -87,7 +87,7 @@ public class ApexModelSaver<M extends AxModel> {
LOGGER.debug("running apexModelWriteJSON . . .");
// Write the file to disk
- final File jsonFile = new File(writePath + File.separatorChar + model.getKey().getName() + ".json");
+ final var jsonFile = new File(writePath + File.separatorChar + model.getKey().getName() + ".json");
new ApexModelFileWriter<M>(true).apexModelWriteJsonFile(model, rootModelClass, jsonFile.getPath());
LOGGER.debug("ran apexModelWriteJSON");
diff --git a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelStringWriter.java b/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelStringWriter.java
index f1725d8e3..de6a72ffd 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 Nordix Foundation.
+ * Modifications Copyright (C) 2019-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.
@@ -86,17 +86,14 @@ public class ApexModelStringWriter<C extends AxConcept> {
conceptWriter.getCDataFieldSet().add("logic");
conceptWriter.getCDataFieldSet().add("uiLogic");
- final ByteArrayOutputStream baOutputStream = new ByteArrayOutputStream();
- try {
+ try (var baOutputStream = new ByteArrayOutputStream()) {
conceptWriter.write(concept, baOutputStream);
- baOutputStream.close();
+ return baOutputStream.toString();
} catch (final Exception e) {
LOGGER.warn("error writing XML string", e);
throw new ApexException("error writing XML string", e);
}
- LOGGER.debug("ran writeXMLString");
- return baOutputStream.toString();
}
/**
@@ -114,17 +111,14 @@ public class ApexModelStringWriter<C extends AxConcept> {
conceptWriter.setJsonOutput(true);
conceptWriter.setValidateFlag(validateFlag);
- final ByteArrayOutputStream baOutputStream = new ByteArrayOutputStream();
- try {
+ try (var baOutputStream = new ByteArrayOutputStream()) {
conceptWriter.write(concept, baOutputStream);
- baOutputStream.close();
+ return baOutputStream.toString();
} catch (final Exception e) {
LOGGER.warn("error writing JSON string", e);
throw new ApexException("error writing JSON string", e);
}
- LOGGER.debug("ran writeJSONString");
- return baOutputStream.toString();
}
/**
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 0763492fc..9e43f76bd 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-2020 Nordix Foundation.
+ * Modifications Copyright (C) 2019-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.
@@ -27,7 +27,6 @@ import java.io.Writer;
import java.util.Set;
import java.util.TreeSet;
import javax.xml.XMLConstants;
-import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
import javax.xml.parsers.DocumentBuilderFactory;
@@ -47,7 +46,6 @@ 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;
-import org.w3c.dom.Document;
/**
* This class writes an Apex concept to an XML file or JSON file from a Java Apex Concept.
@@ -87,7 +85,7 @@ public class ApexModelWriter<C extends AxConcept> {
System.setProperty("javax.xml.bind.context.factory", "org.eclipse.persistence.jaxb.JAXBContextFactory");
try {
- final JAXBContext jaxbContext = JAXBContextFactory.createContext(new Class[]{rootConceptClass}, null);
+ final var jaxbContext = JAXBContextFactory.createContext(new Class[]{rootConceptClass}, null);
// Set up the unmarshaller to carry out validation
marshaller = jaxbContext.createMarshaller();
@@ -201,17 +199,17 @@ public class ApexModelWriter<C extends AxConcept> {
try {
// Write the concept into a DOM document, then transform to add CDATA fields and pretty
// print, then write out the result
- final DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
+ 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 Document document = docBuilderFactory.newDocumentBuilder().newDocument();
+ final var document = docBuilderFactory.newDocumentBuilder().newDocument();
// Marshal the concept into the empty document.
marshaller.marshal(concept, document);
- final Transformer domTransformer = getTransformer();
+ final var domTransformer = getTransformer();
// Convert the cDataFieldSet into a space delimited string
domTransformer.setOutputProperty(OutputKeys.CDATA_SECTION_ELEMENTS,
@@ -225,11 +223,11 @@ public class ApexModelWriter<C extends AxConcept> {
private Transformer getTransformer() throws TransformerConfigurationException {
// Transform the DOM to the output stream
- final TransformerFactory transformerFactory = TransformerFactory.newInstance();
+ final var transformerFactory = TransformerFactory.newInstance();
transformerFactory.setAttribute(XMLConstants.ACCESS_EXTERNAL_DTD, "");
transformerFactory.setAttribute(XMLConstants.ACCESS_EXTERNAL_STYLESHEET, "");
- final Transformer domTransformer = transformerFactory.newTransformer();
+ final var domTransformer = transformerFactory.newTransformer();
// Pretty print
try {
diff --git a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/handling/ApexSchemaGenerator.java b/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/handling/ApexSchemaGenerator.java
index 8617f2c81..d5f34785b 100644
--- a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/handling/ApexSchemaGenerator.java
+++ b/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/handling/ApexSchemaGenerator.java
@@ -1,7 +1,7 @@
/*
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
- * Modifications Copyright (C) 2020 Nordix Foundation.
+ * 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.
@@ -53,7 +53,7 @@ public class ApexSchemaGenerator {
if (args.length == 1) {
printStream = System.out;
} else if (args.length == 2) {
- final File schemaFile = new File(args[1]);
+ final var schemaFile = new File(args[1]);
try {
schemaFile.getParentFile().mkdirs();
@@ -94,7 +94,7 @@ public class ApexSchemaGenerator {
return null;
}
- final ApexSchemaOutputResolver sor = new ApexSchemaOutputResolver();
+ final var sor = new ApexSchemaOutputResolver();
try {
jaxbContext.generateSchema(sor);
} catch (final IOException e) {
@@ -102,7 +102,7 @@ public class ApexSchemaGenerator {
return null;
}
- String schemaString = sor.getSchema();
+ var schemaString = sor.getSchema();
schemaString = fixForUnqualifiedBug(schemaString);
return schemaString;
@@ -118,7 +118,7 @@ public class ApexSchemaGenerator {
*/
private String fixForUnqualifiedBug(final String schemaString) {
// Fix the "entry" element
- String newSchemaString = schemaString.replace(
+ var newSchemaString = schemaString.replace(
"<xs:element name=\"entry\" minOccurs=\"0\" maxOccurs=\"unbounded\">",
"<xs:element name=\"entry\" minOccurs=\"0\" maxOccurs=\"unbounded\" form=\"unqualified\">");
@@ -144,7 +144,7 @@ public class ApexSchemaGenerator {
*/
@Override
public Result createOutput(final String namespaceUri, final String suggestedFileName) throws IOException {
- final StreamResult result = new StreamResult(stringWriter);
+ final var result = new StreamResult(stringWriter);
result.setSystemId(suggestedFileName);
return result;
}
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 bf63e6db7..36ce4e438 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,19 +1,20 @@
/*
* ============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=========================================================
*/
@@ -23,11 +24,9 @@ package org.onap.policy.apex.model.basicmodel.test;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
-import java.net.URL;
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.ApexDao;
import org.onap.policy.apex.model.basicmodel.dao.ApexDaoFactory;
import org.onap.policy.apex.model.basicmodel.dao.DaoParameters;
import org.onap.policy.apex.model.basicmodel.handling.ApexModelFileWriter;
@@ -87,7 +86,7 @@ public class TestApexModel<M extends AxModel> {
public final void testApexModelWriteReadXml() throws ApexException {
LOGGER.debug("running testApexModelWriteReadXML . . .");
- final M model = modelCreator.getModel();
+ final var model = modelCreator.getModel();
// Write the file to disk
File xmlFile;
@@ -105,8 +104,8 @@ public class TestApexModel<M extends AxModel> {
final ApexModelReader<M> modelReader = new ApexModelReader<>(rootModelClass);
try {
- final URL apexModelUrl = ResourceUtils.getLocalFile(xmlFile.getAbsolutePath());
- final M fileModel = modelReader.read(apexModelUrl.openStream());
+ 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);
@@ -118,10 +117,10 @@ public class TestApexModel<M extends AxModel> {
modelWriter.getCDataFieldSet().add("logic");
modelWriter.getCDataFieldSet().add("uiLogic");
- final ByteArrayOutputStream baOutputStream = new ByteArrayOutputStream();
+ final var baOutputStream = new ByteArrayOutputStream();
modelWriter.write(model, baOutputStream);
- final ByteArrayInputStream baInputStream = new ByteArrayInputStream(baOutputStream.toByteArray());
- final M byteArrayModel = modelReader.read(baInputStream);
+ 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");
@@ -136,7 +135,7 @@ public class TestApexModel<M extends AxModel> {
public final void testApexModelWriteReadJson() throws ApexException {
LOGGER.debug("running testApexModelWriteReadJSON . . .");
- final M model = modelCreator.getModel();
+ final var model = modelCreator.getModel();
// Write the file to disk
File jsonFile;
@@ -153,8 +152,8 @@ public class TestApexModel<M extends AxModel> {
final ApexModelReader<M> modelReader = new ApexModelReader<>(rootModelClass);
try {
- final URL apexModelUrl = ResourceUtils.getLocalFile(jsonFile.getAbsolutePath());
- final M fileModel = modelReader.read(apexModelUrl.openStream());
+ final var apexModelUrl = ResourceUtils.getLocalFile(jsonFile.getAbsolutePath());
+ final var fileModel = modelReader.read(apexModelUrl.openStream());
checkModelEquality(model, fileModel, TEST_MODEL_UNEQUAL_STR + jsonFile.getAbsolutePath());
} catch (final Exception e) {
LOGGER.warn(ERROR_PROCESSING_FILE + jsonFile.getAbsolutePath(), e);
@@ -164,11 +163,11 @@ public class TestApexModel<M extends AxModel> {
final ApexModelWriter<M> modelWriter = new ApexModelWriter<>(rootModelClass);
modelWriter.setJsonOutput(true);
- final ByteArrayOutputStream baOutputStream = new ByteArrayOutputStream();
+ final var baOutputStream = new ByteArrayOutputStream();
modelWriter.write(model, baOutputStream);
- final ByteArrayInputStream baInputStream = new ByteArrayInputStream(baOutputStream.toByteArray());
- final M byteArrayModel = modelReader.read(baInputStream);
-
+ final var baInputStream = new ByteArrayInputStream(baOutputStream.toByteArray());
+ final var byteArrayModel = modelReader.read(baInputStream);
+
checkModelEquality(model, byteArrayModel, "test model does not equal JSON marshalled and unmarshalled model");
LOGGER.debug("ran testApexModelWriteReadJSON");
@@ -183,13 +182,13 @@ public class TestApexModel<M extends AxModel> {
public final void testApexModelWriteReadJpa(final DaoParameters daoParameters) throws ApexException {
LOGGER.debug("running testApexModelWriteReadJPA . . .");
- final M model = modelCreator.getModel();
+ final var model = modelCreator.getModel();
- final ApexDao apexDao = new ApexDaoFactory().createApexDao(daoParameters);
+ final var apexDao = new ApexDaoFactory().createApexDao(daoParameters);
apexDao.init(daoParameters);
apexDao.create(model);
- final M dbJpaModel = apexDao.get(rootModelClass, model.getKey());
+ 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");
@@ -206,7 +205,7 @@ public class TestApexModel<M extends AxModel> {
public final AxValidationResult testApexModelValid() throws ApexException {
LOGGER.debug("running testApexModelVaid . . .");
- final M model = modelCreator.getModel();
+ final var model = modelCreator.getModel();
final AxValidationResult result = model.validate(new AxValidationResult());
if (!result.isValid()) {
@@ -228,7 +227,7 @@ public class TestApexModel<M extends AxModel> {
public final AxValidationResult testApexModelVaidateMalstructured() throws ApexException {
LOGGER.debug("running testApexModelVaidateMalstructured . . .");
- final M model = modelCreator.getMalstructuredModel();
+ final var model = modelCreator.getMalstructuredModel();
final AxValidationResult result = model.validate(new AxValidationResult());
if (result.isValid()) {
@@ -250,7 +249,7 @@ public class TestApexModel<M extends AxModel> {
public final AxValidationResult testApexModelVaidateObservation() throws ApexException {
LOGGER.debug("running testApexModelVaidateObservation . . .");
- final M model = modelCreator.getObservationModel();
+ final var model = modelCreator.getObservationModel();
final AxValidationResult result = model.validate(new AxValidationResult());
if (!result.isValid()) {
@@ -277,7 +276,7 @@ public class TestApexModel<M extends AxModel> {
public final AxValidationResult testApexModelVaidateWarning() throws ApexException {
LOGGER.debug("running testApexModelVaidateWarning . . .");
- final M model = modelCreator.getWarningModel();
+ final var model = modelCreator.getWarningModel();
final AxValidationResult result = model.validate(new AxValidationResult());
if (!result.isValid()) {
@@ -304,7 +303,7 @@ public class TestApexModel<M extends AxModel> {
public final AxValidationResult testApexModelVaidateInvalidModel() throws ApexException {
LOGGER.debug("running testApexModelVaidateInvalidModel . . .");
- final M model = modelCreator.getInvalidModel();
+ final var model = modelCreator.getInvalidModel();
final AxValidationResult result = model.validate(new AxValidationResult());
if (result.isValid()) {
@@ -319,7 +318,7 @@ public class TestApexModel<M extends AxModel> {
/**
* Check if two models are equal.
- *
+ *
* @param leftModel the left model
* @param rightModel the right model
* @param errorMessage the error message to output on inequality