aboutsummaryrefslogtreecommitdiffstats
path: root/aai-core/src
diff options
context:
space:
mode:
authorJames Forsyth <jf2512@att.com>2018-08-24 16:21:31 +0000
committerGerrit Code Review <gerrit@onap.org>2018-08-24 16:21:31 +0000
commitdfef19e542581df2f69c263721fd6ead3752549d (patch)
tree40eb244748b8599562e35c491003a3b658b1f0c9 /aai-core/src
parenta992c8447913ad4adef713b7cda817e490612cd3 (diff)
parent718ebdc7cab68315bfa9d622d3b6932221920dee (diff)
Merge "Fix sonar issues"
Diffstat (limited to 'aai-core/src')
-rw-r--r--aai-core/src/main/java/org/onap/aai/util/PojoUtils.java19
-rw-r--r--aai-core/src/main/java/org/onap/aai/util/genxsd/YAMLfromOXM.java21
-rw-r--r--aai-core/src/test/java/org/onap/aai/util/PojoUtilsTest.java3
3 files changed, 20 insertions, 23 deletions
diff --git a/aai-core/src/main/java/org/onap/aai/util/PojoUtils.java b/aai-core/src/main/java/org/onap/aai/util/PojoUtils.java
index 8354d841..f3e67388 100644
--- a/aai-core/src/main/java/org/onap/aai/util/PojoUtils.java
+++ b/aai-core/src/main/java/org/onap/aai/util/PojoUtils.java
@@ -162,16 +162,17 @@ public class PojoUtils {
* @param clazz the clazz
* @return the xml from object
* @throws JAXBException the JAXB exception
+ * @throws IOException
*/
- public <T> String getXmlFromObject(T clazz) throws JAXBException {
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- JAXBContext jc = JAXBContext.newInstance(clazz.getClass().getPackage().getName());
-
- Marshaller marshaller = jc.createMarshaller();
- marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
- marshaller.marshal(clazz, baos);
-
- return baos.toString();
+ public <T> String getXmlFromObject(T clazz) throws JAXBException, IOException {
+ try(ByteArrayOutputStream baos = new ByteArrayOutputStream()){
+ JAXBContext jc = JAXBContext.newInstance(clazz.getClass().getPackage().getName());
+
+ Marshaller marshaller = jc.createMarshaller();
+ marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
+ marshaller.marshal(clazz, baos);
+ return baos.toString();
+ }
}
/**
diff --git a/aai-core/src/main/java/org/onap/aai/util/genxsd/YAMLfromOXM.java b/aai-core/src/main/java/org/onap/aai/util/genxsd/YAMLfromOXM.java
index 930e2fb2..f90d54e6 100644
--- a/aai-core/src/main/java/org/onap/aai/util/genxsd/YAMLfromOXM.java
+++ b/aai-core/src/main/java/org/onap/aai/util/genxsd/YAMLfromOXM.java
@@ -111,7 +111,7 @@ public class YAMLfromOXM extends OxmFileProcessor {
try {
init();
} catch(Exception e) {
- logger.error( "Error initializing " + this.getClass());
+ logger.error( "Error initializing " + this.getClass(),e);
throw e;
}
pathSb.append(getDocumentHeader());
@@ -441,7 +441,7 @@ public class YAMLfromOXM extends OxmFileProcessor {
results.get(key).stream().filter((i) -> (i.getFrom().equals(xmlRootElementName) && (! i.isPrivateEdge() && i.getPreventDelete().equals("OUT")))).forEach((i) ->{ preventDelete.add(i.getTo().toUpperCase());} );
}
} catch(Exception e) {
- logger.debug("xmlRootElementName: "+xmlRootElementName+"\n"+e);
+ logger.debug("xmlRootElementName: "+xmlRootElementName+"\n",e);
}
try {
EdgeRuleQuery q1 = new EdgeRuleQuery.Builder(xmlRootElementName).version(v).toOnly().build();
@@ -454,7 +454,7 @@ public class YAMLfromOXM extends OxmFileProcessor {
results.get(key).stream().filter((i) -> (i.getTo().equals(xmlRootElementName) && (! i.isPrivateEdge() && i.getPreventDelete().equals("IN")))).forEach((i) ->{ preventDelete.add(i.getFrom().toUpperCase());} );
}
} catch(Exception e) {
- logger.debug("xmlRootElementName: "+xmlRootElementName+"\n"+e);
+ logger.debug("xmlRootElementName: "+xmlRootElementName+"\n",e);
}
if(preventDelete.size() > 0) {
prevent = xmlRootElementName.toUpperCase()+" cannot be deleted if related to "+String.join(",",preventDelete);
@@ -505,7 +505,7 @@ public class YAMLfromOXM extends OxmFileProcessor {
javaTypeDefinitions.put(xmlRootElementName, definitionsLocalSb.toString());
}
} catch (Exception e) {
- e.printStackTrace();
+ logger.error("Exception adding in javaTypeDefinitions",e);
}
if ( xmlRootElementName.equals("inventory") ) {
logger.trace("skip xmlRootElementName(2)="+xmlRootElementName);
@@ -535,21 +535,16 @@ public class YAMLfromOXM extends OxmFileProcessor {
try {
outfile.createNewFile();
} catch (IOException e) {
- logger.error( "Exception creating output file " + outfileName);
- e.printStackTrace();
+ logger.error( "Exception creating output file " + outfileName,e);
}
- BufferedWriter bw = null;
try {
Charset charset = Charset.forName("UTF-8");
Path path = Paths.get(outfileName);
- bw = Files.newBufferedWriter(path, charset);
- bw.write(fileContent);
- if ( bw != null ) {
- bw.close();
+ try(BufferedWriter bw = Files.newBufferedWriter(path, charset)){
+ bw.write(fileContent);
}
} catch ( IOException e) {
- logger.error( "Exception writing output file " + outfileName);
- e.printStackTrace();
+ logger.error( "Exception writing output file " + outfileName,e);
}
}
diff --git a/aai-core/src/test/java/org/onap/aai/util/PojoUtilsTest.java b/aai-core/src/test/java/org/onap/aai/util/PojoUtilsTest.java
index 3658704e..35065fd5 100644
--- a/aai-core/src/test/java/org/onap/aai/util/PojoUtilsTest.java
+++ b/aai-core/src/test/java/org/onap/aai/util/PojoUtilsTest.java
@@ -23,6 +23,7 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
+import java.io.IOException;
import java.time.LocalDateTime;
import java.time.Month;
import java.util.ArrayList;
@@ -159,7 +160,7 @@ public class PojoUtilsTest {
}
@Test
- public void testGetXmlFromObject() throws JAXBException {
+ public void testGetXmlFromObject() throws JAXBException, IOException {
NotificationEvent notificationEvent = new NotificationEvent();
notificationEvent.setCambriaPartition("partition");