summaryrefslogtreecommitdiffstats
path: root/aai-core/src/main
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/main
parenta992c8447913ad4adef713b7cda817e490612cd3 (diff)
parent718ebdc7cab68315bfa9d622d3b6932221920dee (diff)
Merge "Fix sonar issues"
Diffstat (limited to 'aai-core/src/main')
-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
2 files changed, 18 insertions, 22 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);
}
}