summaryrefslogtreecommitdiffstats
path: root/ecomp-sdk
diff options
context:
space:
mode:
Diffstat (limited to 'ecomp-sdk')
-rw-r--r--ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/gmap/line/LineCollection.java6
-rw-r--r--ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/model/ReportHandler.java269
-rw-r--r--ecomp-sdk/epsdk-app-common/src/main/java/org/onap/portalapp/controller/core/ManifestController.java1
-rw-r--r--ecomp-sdk/epsdk-app-common/src/main/java/org/onap/portalapp/controller/core/ProfileController.java4
-rw-r--r--ecomp-sdk/epsdk-app-common/src/main/java/org/onap/portalapp/controller/sample/AngularSinglePageController.java2
-rw-r--r--ecomp-sdk/epsdk-app-common/src/main/java/org/onap/portalapp/controller/sample/BroadcastController.java4
-rw-r--r--ecomp-sdk/epsdk-app-common/src/main/java/org/onap/portalapp/controller/sample/BroadcastListController.java2
-rw-r--r--ecomp-sdk/epsdk-app-common/src/main/java/org/onap/portalapp/controller/sample/ElementModelController.java12
-rw-r--r--ecomp-sdk/epsdk-app-common/src/main/java/org/onap/portalapp/controller/sample/PostDroolsController.java4
-rw-r--r--ecomp-sdk/epsdk-app-common/src/main/java/org/onap/portalapp/service/OnBoardingApiServiceImpl.java8
-rw-r--r--ecomp-sdk/epsdk-core/README.md3
-rw-r--r--ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/conf/HibernateConfiguration.java25
-rw-r--r--ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/restful/client/PortalRestClientBase.java29
-rw-r--r--ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/service/LoginServiceImpl.java2
14 files changed, 132 insertions, 239 deletions
diff --git a/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/gmap/line/LineCollection.java b/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/gmap/line/LineCollection.java
index d68c9855..eee04045 100644
--- a/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/gmap/line/LineCollection.java
+++ b/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/gmap/line/LineCollection.java
@@ -47,8 +47,8 @@ public class LineCollection {
private ArrayList<LineInfo> lineCollection;
public LineCollection() {
- lineCollection = new ArrayList<LineInfo>(20000);
- selectedLine = new HashSet<String>();
+ lineCollection = new ArrayList<>(20000);
+ selectedLine = new HashSet<>();
}
public void addSelectedLine(String lineID) {
@@ -157,7 +157,7 @@ public class LineCollection {
}
public String[] getWildCardLine(String lineID) {
- ArrayList<String> list = new ArrayList<String>();
+ ArrayList<String> list = new ArrayList<>();
for (LineInfo lineInfo : lineCollection) {
if (lineInfo.getLineID().toLowerCase().indexOf(lineID.toLowerCase()) != -1) {
diff --git a/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/model/ReportHandler.java b/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/model/ReportHandler.java
index 415edb0c..00e9dfea 100644
--- a/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/model/ReportHandler.java
+++ b/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/model/ReportHandler.java
@@ -505,13 +505,15 @@ public class ReportHandler extends org.onap.portalsdk.analytics.RaptorObject {
name = "";
}
*/ }
- int cw = 0;
- cw = name.trim().length() + 12;
+ //int cw = 0;
+ //cw = name.trim().length() + 12;
// if(i!=cellWidth.size()-1)
- if(sheet.getColumnWidth((short)0)< (short) name.trim().length())
- sheet.setColumnWidth((short)0, (short) name.trim().length());
- if(sheet.getColumnWidth((short)1)< (short) value.trim().length())
- sheet.setColumnWidth((short)1, (short) value.trim().length());
+ if(name!=null && (sheet.getColumnWidth((short)0)< (short) name.trim().length())){
+ sheet.setColumnWidth((short)0, (short) name.trim().length());
+ }
+ if(sheet.getColumnWidth((short)1)< (short) value.trim().length()){
+ sheet.setColumnWidth((short)1, (short) value.trim().length());
+ }
name = "";
value = "";
@@ -969,22 +971,16 @@ public class ReportHandler extends org.onap.portalsdk.analytics.RaptorObject {
SimpleDateFormat MMMMMDDYYYYHHMMSS = new SimpleDateFormat("MMMMM-dd-yyyy HH:mm:ss");
-
-
- ResultSet rs = null;
- Connection conn = null;
- Statement st = null;
ResultSetMetaData rsmd = null;
CreationHelper createHelper = wb.getCreationHelper();
if(nvl(sql_whole).length() >0 && rr.getReportType().equals(AppConstants.RT_LINEAR)) {
- try {
- conn = ConnectionUtils.getConnection(rr.getDbInfo());
- st = conn.createStatement();
+ try(Connection conn = ConnectionUtils.getConnection(rr.getDbInfo());
+ Statement st = conn.createStatement();
+ ResultSet rs = st.executeQuery(sql_whole)) {
System.out.println("************* Map Whole SQL *************");
System.out.println(sql_whole);
System.out.println("*****************************************");
- rs = st.executeQuery(sql_whole);
rsmd = rs.getMetaData();
int numberOfColumns = rsmd.getColumnCount();
HashMap colHash = new HashMap();
@@ -1655,18 +1651,7 @@ public class ReportHandler extends org.onap.portalsdk.analytics.RaptorObject {
} catch (Exception ex) {
if(!(ex.getCause() instanceof java.net.SocketException) )
throw new RaptorException (ex);
- } finally {
- try {
- if(conn!=null)
- conn.close();
- if(st!=null)
- st.close();
- if(rs!=null)
- rs.close();
- } catch (SQLException ex) {
- throw new RaptorException(ex);
- }
- }
+ }
/*if(Globals.getShowDisclaimer() && !Globals.disclaimerPositionedTopInCSVExcel()) {
rowNum += 1;
@@ -2793,8 +2778,8 @@ public class ReportHandler extends org.onap.portalsdk.analytics.RaptorObject {
logger.debug(EELFLoggerDelegate.debugLogger, ("Xls File name " +
AppUtils.getTempFolderPath()
+ xlsFName));
- FileOutputStream xlsOut = new FileOutputStream(FilenameUtils.normalize(AppUtils.getTempFolderPath()
- + xlsFName));
+ try(FileOutputStream xlsOut = new FileOutputStream(FilenameUtils.normalize(AppUtils.getTempFolderPath()
+ + xlsFName))){
// BufferedWriter xlsOut = new BufferedWriter(new
// FileWriter(AppUtils
// .getTempFolderPath()
@@ -2832,7 +2817,7 @@ public class ReportHandler extends org.onap.portalsdk.analytics.RaptorObject {
// + user_id + ".xls");
wb.write(xlsOut);
xlsOut.flush();
- xlsOut.close();
+ }
return xlsFName;
} catch (Exception e) {
e.printStackTrace();
@@ -3269,8 +3254,6 @@ public class ReportHandler extends org.onap.portalsdk.analytics.RaptorObject {
Map<String, XSSFCellStyle> styles = new HashMap<String, XSSFCellStyle>();
HttpSession session = request.getSession();
- ServletOutputStream sos = null;
- BufferedInputStream buf = null;
XSSFWorkbook wb = null;
String formattedReportName = new HtmlStripper().stripSpecialCharacters(rr.getReportName());
String formattedDate = new SimpleDateFormat("MMddyyyyHHmm").format(new Date());
@@ -3324,7 +3307,6 @@ public class ReportHandler extends org.onap.portalsdk.analytics.RaptorObject {
String sheetRef = null;
- FileOutputStream os = null; //template file
File templateFile = null;
if(isDashboard) {
@@ -3344,7 +3326,7 @@ public class ReportHandler extends org.onap.portalsdk.analytics.RaptorObject {
count++;
Map.Entry entry = (Entry) iter.next();
ReportRuntime rrDashRep = (ReportRuntime) entry.getValue();
- os = new FileOutputStream(AppUtils.getTempFolderPath()+ filename+"T."+ nvls(extension, "xlsx"));
+ try(FileOutputStream os = new FileOutputStream(AppUtils.getTempFolderPath()+ filename+"T."+ nvls(extension, "xlsx"))){
if(count==1) {
if(nvl(rr.getTemplateFile()).length()>0) {
@@ -3374,21 +3356,18 @@ public class ReportHandler extends org.onap.portalsdk.analytics.RaptorObject {
os.flush();
if(nvl(rr.getTemplateFile()).length()>0) {
readTemplate.close();
- }
- os.close();
-
- FileInputStream inF = new FileInputStream(AppUtils.getTempFolderPath()+ filename+"T."+ nvls(extension, "xlsx"));
- FileOutputStream outStream = new FileOutputStream(AppUtils.getTempFolderPath()+ filename+"."+ nvls(extension, "xlsx"));
- copyStream(inF, outStream);
- outStream.flush();
- outStream.close();
- inF.close();
+ }
+
+ try(FileInputStream inF = new FileInputStream(AppUtils.getTempFolderPath()+ filename+"T."+ nvls(extension, "xlsx"));
+ FileOutputStream outStream = new FileOutputStream(AppUtils.getTempFolderPath()+ filename+"."+ nvls(extension, "xlsx"))){
+ copyStream(inF, outStream);
+ outStream.flush();
+ }
}
-
+ }
FileInputStream xlsIn = null;
POIFSFileSystem fileSystem = null;
- buf = null;
FileOutputStream xlsOut = null;
formattedDate = new SimpleDateFormat("MMddyyyyHHmm").format(new Date());
String xlsFName = "dashboard"+formattedDate+user_id+".xls";
@@ -3417,39 +3396,37 @@ public class ReportHandler extends org.onap.portalsdk.analytics.RaptorObject {
//Step 2. Generate XML file.
File tmp = File.createTempFile("sheet", ".xml");
- FileOutputStream fileOutTemp = new FileOutputStream(tmp);
- Writer fw = new OutputStreamWriter(fileOutTemp, XML_ENCODING);
- String sql_whole = rrDashRep.getWholeSQL();
+ try(FileOutputStream fileOutTemp = new FileOutputStream(tmp);
+ Writer fw = new OutputStreamWriter(fileOutTemp, XML_ENCODING)){
- SpreadsheetWriter sw = new SpreadsheetWriter(fw);
- sw.beginSheet();
-
-
- generate(wb, sw, styles, rdDashRep, sql_whole, rrDashRep, request, sheet);
-
-
- sw.endSheet();
-
- fw.flush();
- fw.close();
- fileOutTemp.flush();
- fileOutTemp.close();
-
+ String sql_whole = rrDashRep.getWholeSQL();
+
+ SpreadsheetWriter sw = new SpreadsheetWriter(fw);
+ sw.beginSheet();
+
+
+ generate(wb, sw, styles, rdDashRep, sql_whole, rrDashRep, request, sheet);
+
+
+ sw.endSheet();
+
+ fw.flush();
+ fileOutTemp.flush();
+ }
//Step 3. Substitute the template entry with the generated data
- FileOutputStream outF = new FileOutputStream(AppUtils.getTempFolderPath()+ filename+"."+ nvls(extension, "xlsx"));
- templateFile = new File(AppUtils.getTempFolderPath()+ filename+"T."+ nvls(extension, "xlsx"));
- substitute(templateFile, tmp, sheetRef.substring(1), outF);
- outF.flush();
- outF.close();
+ try(FileOutputStream outF = new FileOutputStream(AppUtils.getTempFolderPath()+ filename+"."+ nvls(extension, "xlsx"))){
+ templateFile = new File(AppUtils.getTempFolderPath()+ filename+"T."+ nvls(extension, "xlsx"));
+ substitute(templateFile, tmp, sheetRef.substring(1), outF);
+ outF.flush();
+ }
- FileInputStream inF = new FileInputStream(AppUtils.getTempFolderPath()+ filename+"."+ nvls(extension, "xlsx"));
- FileOutputStream outStream = new FileOutputStream(AppUtils.getTempFolderPath()+ filename+"T."+ nvls(extension, "xlsx"));
+ try(FileInputStream inF = new FileInputStream(AppUtils.getTempFolderPath()+ filename+"."+ nvls(extension, "xlsx"));
+ FileOutputStream outStream = new FileOutputStream(AppUtils.getTempFolderPath()+ filename+"T."+ nvls(extension, "xlsx"))){
copyStream(inF, outStream);
outStream.flush();
- outStream.close();
- inF.close();
+ }
}
}
} else {
@@ -3459,12 +3436,12 @@ public class ReportHandler extends org.onap.portalsdk.analytics.RaptorObject {
extension = templateFilename.substring(templateFilename.lastIndexOf(".")+1);
filename = formattedReportName+formattedDate+user_id;
//filename = templateFilename.substring(0, templateFilename.lastIndexOf("."))+"_"+formattedDate+user_id;
- } else
+ } else {
filename = formattedReportName+formattedDate+user_id;
-
+ }
if(nvl(rr.getTemplateFile()).length()<=0) {
- os = new FileOutputStream(AppUtils.getTempFolderPath()+"template"+formattedDate+user_id+".xlsx");
+ try(FileOutputStream os = new FileOutputStream(AppUtils.getTempFolderPath()+"template"+formattedDate+user_id+".xlsx")){
wb=new XSSFWorkbook();
//Load customized styles
if (rr != null)
@@ -3490,11 +3467,11 @@ public class ReportHandler extends org.onap.portalsdk.analytics.RaptorObject {
wb.write(os);
os.flush();
//wb = null;
- os.close();
+ }
} else {
- os = new FileOutputStream(AppUtils.getTempFolderPath()+ filename+"T."+ nvls(extension, "xlsx"));
- FileInputStream readTemplate = new FileInputStream(org.onap.portalsdk.analytics.system.AppUtils.getExcelTemplatePath()+rr.getTemplateFile());
+ try(FileOutputStream os = new FileOutputStream(AppUtils.getTempFolderPath()+ filename+"T."+ nvls(extension, "xlsx"));
+ FileInputStream readTemplate = new FileInputStream(org.onap.portalsdk.analytics.system.AppUtils.getExcelTemplatePath()+rr.getTemplateFile());){
wb=new XSSFWorkbook(readTemplate);
if (rr != null)
styles = loadXSSFStyles(rr, wb, styles);
@@ -3507,15 +3484,14 @@ public class ReportHandler extends org.onap.portalsdk.analytics.RaptorObject {
sheetRef = sheet.getPackagePart().getPartName().getName();
wb.write(os);
os.flush();
- readTemplate.close();
//wb = null;
- os.close();
+ }
}
//Step 2. Generate XML file.
File tmp = File.createTempFile("sheet", ".xml");
- FileOutputStream fileOutTemp = new FileOutputStream(tmp);
- Writer fw = new OutputStreamWriter(fileOutTemp, XML_ENCODING);
+ try(FileOutputStream fileOutTemp = new FileOutputStream(tmp);
+ Writer fw = new OutputStreamWriter(fileOutTemp, XML_ENCODING)){
//String sql_whole = (String) request.getAttribute(AppConstants.RI_REPORT_SQL_WHOLE);
String sql_whole = "";
@@ -3541,30 +3517,29 @@ public class ReportHandler extends org.onap.portalsdk.analytics.RaptorObject {
sw.endSheet();
fw.flush();
- fw.close();
fileOutTemp.flush();
- fileOutTemp.close();
-
-
+ }
//Step 3. Substitute the template entry with the generated data
- FileOutputStream outF = new FileOutputStream(AppUtils.getTempFolderPath()+ filename+"."+ nvls(extension, "xlsx"));
+ try(FileOutputStream outF = new FileOutputStream(AppUtils.getTempFolderPath()+ filename+"."+ nvls(extension, "xlsx"))){
if(nvl(rr.getTemplateFile()).length()>0) {
templateFile = new File(AppUtils.getTempFolderPath()+ filename+"T."+ nvls(extension, "xlsx"));
- } else
+ } else {
templateFile = new File(AppUtils.getTempFolderPath()+"template"+formattedDate+user_id+".xlsx");
-
+ }
substitute(templateFile, tmp, sheetRef.substring(1), outF);
outF.flush();
- outF.close();
+ }
}
//get servlet output stream
response.reset();
- sos = response.getOutputStream();
+ try(BufferedInputStream buf = new BufferedInputStream(new FileInputStream(AppUtils.getTempFolderPath()+filename + "."+ nvls(extension, "xlsx")));
+ ServletOutputStream sos = response.getOutputStream()){
+
String mime_type = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
if(extension.equals("xlsm"))
mime_type = "application/vnd.ms-excel.sheet.macroEnabled.12";
@@ -3572,16 +3547,16 @@ public class ReportHandler extends org.onap.portalsdk.analytics.RaptorObject {
response.setHeader("Content-disposition", "attachment;filename="+filename+"."+ nvls(extension, "xlsx"));
- buf = new BufferedInputStream(new FileInputStream(AppUtils.getTempFolderPath()+filename + "."+ nvls(extension, "xlsx")));
+
int readBytes = 0;
//read from the file; write to the ServletOutputStream
while ((readBytes = buf.read()) != -1)
sos.write(readBytes);
- buf.close();
+
sos.flush();
- sos.close();
+ }
logger.debug(EELFLoggerDelegate.debugLogger, ("ENDING..DOWNLOADING XLSX..."));
logger.debug(EELFLoggerDelegate.debugLogger, ("##### Heap utilization statistics [MB] #####"));
logger.debug(EELFLoggerDelegate.debugLogger, ("Used Memory:"
@@ -3601,9 +3576,10 @@ public class ReportHandler extends org.onap.portalsdk.analytics.RaptorObject {
* @param out the stream to write the result to
*/
private static void substitute(File zipfile, File tmpfile, String entry, OutputStream out) throws IOException {
- ZipFile zip = new ZipFile(zipfile);
+ try(ZipFile zip = new ZipFile(zipfile);
+ ZipOutputStream zos = new ZipOutputStream(out)){
- ZipOutputStream zos = new ZipOutputStream(out);
+
@SuppressWarnings("unchecked")
Enumeration<ZipEntry> en = (Enumeration<ZipEntry>) zip.entries();
@@ -3611,18 +3587,17 @@ public class ReportHandler extends org.onap.portalsdk.analytics.RaptorObject {
ZipEntry ze = en.nextElement();
if(!ze.getName().equals(entry)){
zos.putNextEntry(new ZipEntry(ze.getName()));
- InputStream is = zip.getInputStream(ze);
+ try(InputStream is = zip.getInputStream(ze)){
copyStream(is, zos);
- is.close();
+ }
}
}
zos.putNextEntry(new ZipEntry(entry));
- InputStream is = new FileInputStream(tmpfile);
- copyStream(is, zos);
- zos.flush();
- zos.close();
- is.close();
- zip.close();
+ try(InputStream is = new FileInputStream(tmpfile)){
+ copyStream(is, zos);
+ }
+ zos.flush();
+ }
}
private static void copyStream(InputStream in, OutputStream out) throws IOException {
@@ -3641,8 +3616,6 @@ public class ReportHandler extends org.onap.portalsdk.analytics.RaptorObject {
//String reportTitle = rr.getReportName();
//String reportDescr = rr.getReportDescr();
PrintWriter csvOut = new PrintWriter(out);
- ServletOutputStream sos = null;
- BufferedInputStream buf = null;
String fileName = "";
String formattedReportName = new HtmlStripper().stripSpecialCharacters(rr.getReportName());
String formattedDate = new SimpleDateFormat("MMddyyyyHHmm").format(new Date());
@@ -3667,13 +3640,10 @@ public class ReportHandler extends org.onap.portalsdk.analytics.RaptorObject {
}
}
HtmlStripper strip = new HtmlStripper();
- ResultSet rs = null;
//OracleConnection conn = null;
//OracleStatement st = null;
//Connection conO = null;
//Statement stO = null;
- Connection conn = null;
- Statement st = null;
ResultSetMetaData rsmd = null;
ColumnHeaderRow chr = null;
int mb = 1024*1024;
@@ -3751,16 +3721,16 @@ public class ReportHandler extends org.onap.portalsdk.analytics.RaptorObject {
if(nvl(sql_whole).length()>0) {
- try {
- conn = ConnectionUtils.getConnection(rr.getDbInfo());
- st = conn.createStatement();
+ try(Connection conn = ConnectionUtils.getConnection(rr.getDbInfo());
+ Statement st = conn.createStatement();
+ ResultSet rs = st.executeQuery(sql_whole)) {
+
//conn.setDefaultRowPrefetch(1000);
//st.setFetchDirection(ResultSet.TYPE_FORWARD_ONLY);
//st.setFetchSize(1000);
System.out.println("************* Map Whole SQL *************");
System.out.println(sql_whole);
System.out.println("*****************************************");
- rs = st.executeQuery(sql_whole);
//st.setFetchSize(1000);
rsmd = rs.getMetaData();
int numberOfColumns = rsmd.getColumnCount();
@@ -3852,17 +3822,6 @@ public class ReportHandler extends org.onap.portalsdk.analytics.RaptorObject {
throw new RaptorException(ex);
} catch (Exception ex) {
throw new RaptorException (ex);
- } finally {
- try {
- if(conn!=null)
- conn.close();
- if(st!=null)
- st.close();
- if(rs!=null)
- rs.close();
- } catch (SQLException ex) {
- throw new RaptorException(ex);
- }
}
if(!raw) {
@@ -3990,8 +3949,9 @@ public class ReportHandler extends org.onap.portalsdk.analytics.RaptorObject {
csvOut.println();
} // if
*/
- if(true && !raw) {
- try {
+ if(!raw) {
+ try(ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(AppUtils.getTempFolderPath()+""+zipFName));
+ FileInputStream fis = new FileInputStream(fileName)) {
//final int BUFFER = 2048;
@@ -4002,9 +3962,7 @@ public class ReportHandler extends org.onap.portalsdk.analytics.RaptorObject {
//CRC32 crc = new CRC32();
//PrintStream fos = new PrintStream(new WriterOutputStream(out));
//BufferedOutputStream dest = new BufferedOutputStream(fos, BUFFER);
- //ZipOutputStream s = new ZipOutputStream(dest);
- ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(AppUtils.getTempFolderPath()+""+zipFName));
- FileInputStream fis = new FileInputStream(fileName);
+ //ZipOutputStream s = new ZipOutputStream(dest);
//s.setLevel(6);
@@ -4032,7 +3990,7 @@ public class ReportHandler extends org.onap.portalsdk.analytics.RaptorObject {
response.reset();
java.io.File file = null;
- if(true && !raw) {
+ if(!raw) {
response.setContentType("application/octet-stream");
response.setHeader("Content-disposition","attachment;filename="+fName+".zip");
file = new java.io.File(AppUtils.getTempFolderPath()+""+fName+".zip");
@@ -4043,12 +4001,11 @@ public class ReportHandler extends org.onap.portalsdk.analytics.RaptorObject {
}
- FileInputStream fileIn = null;
int c;
- try {
- sos = response.getOutputStream();
- fileIn = new FileInputStream(file);
- buf = new BufferedInputStream(fileIn);
+ try(ServletOutputStream sos = response.getOutputStream();
+ FileInputStream fileIn = new FileInputStream(file);
+ BufferedInputStream buf = new BufferedInputStream(fileIn);) {
+
byte [] bOut = new byte [4096];
//read from the file; write to the ServletOutputStream
//while ((readBytes = buf.read()) != -1)
@@ -4062,18 +4019,6 @@ public class ReportHandler extends org.onap.portalsdk.analytics.RaptorObject {
ex.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
- } finally {
- try {
- if (sos != null)
- sos.close();
- if (buf != null)
- buf.close();
- if (fileIn!=null) {
- fileIn.close();
- }
- } catch (Exception e1) {
- e1.printStackTrace();
- }
}
File f = new File (AppUtils.getTempFolderPath()
@@ -4136,10 +4081,10 @@ public class ReportHandler extends org.onap.portalsdk.analytics.RaptorObject {
try {
String xmlFName = AppUtils.generateUniqueFileName(request, reportName, AppConstants.FT_XML);
- PrintWriter xmlOut = new PrintWriter(new BufferedWriter(new FileWriter(new File(
- AppUtils.getTempFolderPath() + xmlFName))));
- xmlOut.println(reportXML);
- xmlOut.close();
+ try(PrintWriter xmlOut = new PrintWriter(new BufferedWriter(new FileWriter(new File(
+ AppUtils.getTempFolderPath() + xmlFName))))){
+ xmlOut.println(reportXML);
+ }
//return AppUtils.getTempFolderURL()
// + java.net.URLEncoder.encode(java.net.URLDecoder.decode(xmlFName));
@@ -4810,20 +4755,17 @@ public class ReportHandler extends org.onap.portalsdk.analytics.RaptorObject {
dateFormat = createHelper.createDataFormat().getFormat("MMMMM-dd-yyyy HH:mm:ss");
dateFormatMap.put("MMMMMDDYYYYHHMMSS", new Short(dateFormat));
- ResultSet rs = null;
- Connection conn = null;
- Statement st = null;
ResultSetMetaData rsmd = null;
if(nvl(sql_whole).length() >0 && (rr.getReportType().equals(AppConstants.RT_LINEAR) || rr.getReportType().equals(AppConstants.RT_HIVE) )) {
- try {
- conn = ConnectionUtils.getConnection(rr.getDbInfo());
- st = conn.createStatement();
+ try(Connection conn = ConnectionUtils.getConnection(rr.getDbInfo());
+ Statement st = conn.createStatement();
+ ResultSet rs = st.executeQuery(sql_whole)) {
+
logger.debug(EELFLoggerDelegate.debugLogger, ("************* Map Whole SQL *************"));
logger.debug(EELFLoggerDelegate.debugLogger, (sql_whole));
logger.debug(EELFLoggerDelegate.debugLogger, ("*****************************************"));
- rs = st.executeQuery(sql_whole);
rsmd = rs.getMetaData();
int numberOfColumns = rsmd.getColumnCount();
HashMap colHash = new HashMap();
@@ -5492,18 +5434,7 @@ public class ReportHandler extends org.onap.portalsdk.analytics.RaptorObject {
} catch (Exception ex) {
if(!(ex.getCause() instanceof java.net.SocketException) )
throw new RaptorException (ex);
- } finally {
- try {
- if(conn!=null)
- conn.close();
- if(st!=null)
- st.close();
- if(rs!=null)
- rs.close();
- } catch (SQLException ex) {
- throw new RaptorException(ex);
- }
- }
+ }
String footer = (String) session.getAttribute("FOOTER_"+index);
if(nvl(footer).length()>0) {
diff --git a/ecomp-sdk/epsdk-app-common/src/main/java/org/onap/portalapp/controller/core/ManifestController.java b/ecomp-sdk/epsdk-app-common/src/main/java/org/onap/portalapp/controller/core/ManifestController.java
index 65964fe5..0fd3cfbb 100644
--- a/ecomp-sdk/epsdk-app-common/src/main/java/org/onap/portalapp/controller/core/ManifestController.java
+++ b/ecomp-sdk/epsdk-app-common/src/main/java/org/onap/portalapp/controller/core/ManifestController.java
@@ -45,7 +45,6 @@ import java.util.jar.Attributes;
import java.util.jar.Manifest;
import javax.servlet.ServletContext;
-import javax.servlet.http.HttpServletRequest;
import org.onap.portalsdk.core.controller.RestrictedBaseController;
import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
diff --git a/ecomp-sdk/epsdk-app-common/src/main/java/org/onap/portalapp/controller/core/ProfileController.java b/ecomp-sdk/epsdk-app-common/src/main/java/org/onap/portalapp/controller/core/ProfileController.java
index 74c18850..c7edfb81 100644
--- a/ecomp-sdk/epsdk-app-common/src/main/java/org/onap/portalapp/controller/core/ProfileController.java
+++ b/ecomp-sdk/epsdk-app-common/src/main/java/org/onap/portalapp/controller/core/ProfileController.java
@@ -88,7 +88,7 @@ public class ProfileController extends RestrictedBaseController {
@RequestMapping(value = { "/profile" }, method = RequestMethod.GET)
public ModelAndView profile(HttpServletRequest request) throws IOException {
- Map<String, Object> model = new HashMap<String, Object>();
+ Map<String, Object> model = new HashMap<>();
ObjectMapper mapper = new ObjectMapper();
User user = UserUtils.getUserSession(request);
@@ -138,7 +138,7 @@ public class ProfileController extends RestrictedBaseController {
@RequestMapping(value = { "/get_self_profile" }, method = RequestMethod.GET)
public void getSelfProfile(HttpServletRequest request, HttpServletResponse response) {
- Map<String, Object> model = new HashMap<String, Object>();
+ Map<String, Object> model = new HashMap<>();
ObjectMapper mapper = new ObjectMapper();
User user = UserUtils.getUserSession(request);
diff --git a/ecomp-sdk/epsdk-app-common/src/main/java/org/onap/portalapp/controller/sample/AngularSinglePageController.java b/ecomp-sdk/epsdk-app-common/src/main/java/org/onap/portalapp/controller/sample/AngularSinglePageController.java
index b5d78768..96b602c3 100644
--- a/ecomp-sdk/epsdk-app-common/src/main/java/org/onap/portalapp/controller/sample/AngularSinglePageController.java
+++ b/ecomp-sdk/epsdk-app-common/src/main/java/org/onap/portalapp/controller/sample/AngularSinglePageController.java
@@ -59,7 +59,7 @@ public class AngularSinglePageController extends RestrictedBaseController {
@RequestMapping(value = { "/singlePageSample" }, method = RequestMethod.GET)
public ModelAndView view(HttpServletRequest request) {
- Map<String, Object> model = new HashMap<String, Object>();
+ Map<String, Object> model = new HashMap<>();
return new ModelAndView("single_page_sample", "model", model);
}
diff --git a/ecomp-sdk/epsdk-app-common/src/main/java/org/onap/portalapp/controller/sample/BroadcastController.java b/ecomp-sdk/epsdk-app-common/src/main/java/org/onap/portalapp/controller/sample/BroadcastController.java
index ec300780..ba90f46f 100644
--- a/ecomp-sdk/epsdk-app-common/src/main/java/org/onap/portalapp/controller/sample/BroadcastController.java
+++ b/ecomp-sdk/epsdk-app-common/src/main/java/org/onap/portalapp/controller/sample/BroadcastController.java
@@ -73,7 +73,7 @@ public class BroadcastController extends RestrictedBaseController {
@RequestMapping(value = { "/broadcast" }, method = RequestMethod.GET)
public ModelAndView broadcast(HttpServletRequest request) {
- Map<String, Object> model = new HashMap<String, Object>();
+ Map<String, Object> model = new HashMap<>();
ObjectMapper mapper = new ObjectMapper();
try {
@@ -87,7 +87,7 @@ public class BroadcastController extends RestrictedBaseController {
@RequestMapping(value = { "/get_broadcast" }, method = RequestMethod.GET)
public void getBroadcast(HttpServletRequest request, HttpServletResponse response) {
- Map<String, Object> model = new HashMap<String, Object>();
+ Map<String, Object> model = new HashMap<>();
ObjectMapper mapper = new ObjectMapper();
try {
diff --git a/ecomp-sdk/epsdk-app-common/src/main/java/org/onap/portalapp/controller/sample/BroadcastListController.java b/ecomp-sdk/epsdk-app-common/src/main/java/org/onap/portalapp/controller/sample/BroadcastListController.java
index 15e6c57c..8b740d0b 100644
--- a/ecomp-sdk/epsdk-app-common/src/main/java/org/onap/portalapp/controller/sample/BroadcastListController.java
+++ b/ecomp-sdk/epsdk-app-common/src/main/java/org/onap/portalapp/controller/sample/BroadcastListController.java
@@ -70,7 +70,7 @@ public class BroadcastListController extends RestrictedBaseController {
@RequestMapping(value = { "/broadcast_list" }, method = RequestMethod.GET)
public ModelAndView broadcastList(HttpServletRequest request) {
- Map<String, Object> model = new HashMap<String, Object>();
+ Map<String, Object> model = new HashMap<>();
model.put("model", broadcastService.getBcModel(request));
return new ModelAndView(getViewName(), model);
diff --git a/ecomp-sdk/epsdk-app-common/src/main/java/org/onap/portalapp/controller/sample/ElementModelController.java b/ecomp-sdk/epsdk-app-common/src/main/java/org/onap/portalapp/controller/sample/ElementModelController.java
index 361a4187..9588a7e4 100644
--- a/ecomp-sdk/epsdk-app-common/src/main/java/org/onap/portalapp/controller/sample/ElementModelController.java
+++ b/ecomp-sdk/epsdk-app-common/src/main/java/org/onap/portalapp/controller/sample/ElementModelController.java
@@ -89,18 +89,6 @@ public class ElementModelController extends RestrictedBaseController {
return yamlString;
}
- /*
- public ModelAndView callflowAdditional(HttpServletRequest request, HttpServletResponse response) throws Exception {
- Map<String, Object> model = new HashMap<String, Object>();
- String callFlowName = request.getParameter("callFlowName");
- String callFlowStep = request.getParameter("callFlowStep");
-
- ElementLinkService main = new ElementLinkService();
- String yamlString = main.main2(new String[] { callFlowName, callFlowStep });
- model.put("output_string", yamlString);
- return new ModelAndView("data_out", "model", model);
- }
- */
}
diff --git a/ecomp-sdk/epsdk-app-common/src/main/java/org/onap/portalapp/controller/sample/PostDroolsController.java b/ecomp-sdk/epsdk-app-common/src/main/java/org/onap/portalapp/controller/sample/PostDroolsController.java
index fb0338ea..43d548f9 100644
--- a/ecomp-sdk/epsdk-app-common/src/main/java/org/onap/portalapp/controller/sample/PostDroolsController.java
+++ b/ecomp-sdk/epsdk-app-common/src/main/java/org/onap/portalapp/controller/sample/PostDroolsController.java
@@ -75,7 +75,7 @@ public class PostDroolsController extends RestrictedBaseController {
@RequestMapping(value = { "/getDrools" }, method = RequestMethod.GET)
public void getDrools(HttpServletRequest request, HttpServletResponse response) {
- // Map<String, Object> model = new HashMap<String, Object>();
+
ObjectMapper mapper = new ObjectMapper();
try {
@@ -97,7 +97,6 @@ public class PostDroolsController extends RestrictedBaseController {
PostDroolsBean postDroolsBean = new PostDroolsBean();
String selectedFile = request.getParameter("selectedFile");
postDroolsBean.setDroolsFile(selectedFile);// sample populated
- // postDroolsBean.setSelectedRules("[\"NJ\",\"NY\",\"KY\"]");
postDroolsBean.setClassName(postDroolsService.retrieveClass(selectedFile));
JsonMessage msg = new JsonMessage(mapper.writeValueAsString(postDroolsBean));
@@ -126,7 +125,6 @@ public class PostDroolsController extends RestrictedBaseController {
request.setCharacterEncoding("UTF-8");
PrintWriter out = response.getWriter();
- // String responseString = mapper.writeValueAsString(resultsString);
JSONObject j = new JSONObject("{resultsString: " + resultsString + "}");
out.write(j.toString());
diff --git a/ecomp-sdk/epsdk-app-common/src/main/java/org/onap/portalapp/service/OnBoardingApiServiceImpl.java b/ecomp-sdk/epsdk-app-common/src/main/java/org/onap/portalapp/service/OnBoardingApiServiceImpl.java
index 871a3750..966eb8f2 100644
--- a/ecomp-sdk/epsdk-app-common/src/main/java/org/onap/portalapp/service/OnBoardingApiServiceImpl.java
+++ b/ecomp-sdk/epsdk-app-common/src/main/java/org/onap/portalapp/service/OnBoardingApiServiceImpl.java
@@ -279,7 +279,7 @@ public class OnBoardingApiServiceImpl implements IPortalRestAPIService, IPortalR
}
else {
List<User> users = userProfileService.findAllActive();
- List<EcompUser> ecompUsers = new ArrayList<EcompUser>();
+ List<EcompUser> ecompUsers = new ArrayList<>();
for (User user : users)
ecompUsers.add(UserUtils.convertToEcompUser(user));
return ecompUsers;
@@ -299,7 +299,7 @@ public class OnBoardingApiServiceImpl implements IPortalRestAPIService, IPortalR
public List<EcompRole> getAvailableRoles(String requestedLoginId) throws PortalAPIException {
try {
List<Role> roles = roleService.getActiveRoles(requestedLoginId);
- List<EcompRole> ecompRoles = new ArrayList<EcompRole>();
+ List<EcompRole> ecompRoles = new ArrayList<>();
for (Role role : roles)
ecompRoles.add(UserUtils.convertToEcompRole(role));
return ecompRoles;
@@ -323,7 +323,7 @@ public class OnBoardingApiServiceImpl implements IPortalRestAPIService, IPortalR
* TypeFactory.defaultInstance().constructCollectionType(List.class,
* EcompRole.class));
*/
- SortedSet<Role> roles = new TreeSet<Role>();
+ SortedSet<Role> roles = new TreeSet<>();
for (EcompRole role : rolesJson) {
roles.add(roleService.getRole(loginId,role.getId()));
}
@@ -357,7 +357,7 @@ public class OnBoardingApiServiceImpl implements IPortalRestAPIService, IPortalR
public List<EcompRole> getUserRoles(String loginId) throws PortalAPIException {
if (logger.isDebugEnabled())
logger.debug(EELFLoggerDelegate.debugLogger, "## REST API ## loginId: {}", loginId);
- List<EcompRole> ecompRoles = new ArrayList<EcompRole>();
+ List<EcompRole> ecompRoles = new ArrayList<>();
try {
if (isCentralized.equals(isAccessCentralized)) {
diff --git a/ecomp-sdk/epsdk-core/README.md b/ecomp-sdk/epsdk-core/README.md
index 55cf69fd..9dad2789 100644
--- a/ecomp-sdk/epsdk-core/README.md
+++ b/ecomp-sdk/epsdk-core/README.md
@@ -13,6 +13,9 @@ ECOMP SDK web application.
### ONAP Distributions
+Version 2.5.0
+- PORTAL-338 Fix sonar reported issues (try-with-resources)
+
Version 2.1.0
- PORTAL-19 Rename Java package base to org.onap
- PORTAL-145 Harden code to address penetration attacks
diff --git a/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/conf/HibernateConfiguration.java b/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/conf/HibernateConfiguration.java
index 28bd39d9..2e8875c0 100644
--- a/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/conf/HibernateConfiguration.java
+++ b/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/conf/HibernateConfiguration.java
@@ -97,15 +97,9 @@ public class HibernateConfiguration {
@SuppressWarnings("rawtypes")
@Bean
public Map dataSourceMap() throws Exception {
- Connection conn = null;
- Statement stmt = null;
- ResultSet rs = null;
- Map<String, ComboPooledDataSource> dataSourceMap = new HashMap<String, ComboPooledDataSource>();
- try {
- conn = dataSource.getConnection();
- stmt = conn.createStatement();
- String sql = "SELECT schema_id,datasource_type,connection_url,user_name,password,driver_class,min_pool_size,max_pool_size,idle_connection_test_period FROM schema_info";
- rs = stmt.executeQuery(sql);
+ Map<String, ComboPooledDataSource> dataSourceMap = new HashMap<>();
+ String sql = "SELECT schema_id,datasource_type,connection_url,user_name,password,driver_class,min_pool_size,max_pool_size,idle_connection_test_period FROM schema_info";
+ try (Connection conn = dataSource.getConnection();Statement stmt = conn.createStatement();ResultSet rs = stmt.executeQuery(sql)){
while (rs.next()) {
ComboPooledDataSource pool = new ComboPooledDataSource();
pool.setDriverClass(rs.getString("driver_class"));
@@ -121,18 +115,7 @@ public class HibernateConfiguration {
logger.error(EELFLoggerDelegate.errorLogger, "dataSourceMap failed", e);
dataSourceMap = null;
throw e;
- } finally {
- try {
- if (rs != null)
- rs.close();
- if (stmt != null)
- stmt.close();
- if (conn != null)
- conn.close();
- } catch (SQLException se2) {
- logger.warn(EELFLoggerDelegate.errorLogger, "dataSourceMap failed to close", se2);
- }
- }
+ }
return dataSourceMap;
}
diff --git a/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/restful/client/PortalRestClientBase.java b/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/restful/client/PortalRestClientBase.java
index 3bc6677b..5b22b75f 100644
--- a/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/restful/client/PortalRestClientBase.java
+++ b/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/restful/client/PortalRestClientBase.java
@@ -99,16 +99,13 @@ public class PortalRestClientBase {
throw new IllegalArgumentException(
"getRestWithCredentials: Missing one or more required properties and/or database entries");
String decryptedPassword = CipherUtil.decryptPKC(app.getAppPassword());
- CloseableHttpClient httpClient = HttpClients.createDefault();
HttpGet httpGet = new HttpGet(uri);
httpGet.setHeader("uebkey", uebKey);
httpGet.setHeader("username", app.getUsername());
httpGet.setHeader("password", decryptedPassword);
String responseJson = null;
- CloseableHttpResponse response = null;
logger.info(EELFLoggerDelegate.debugLogger, "getRestWithCredentials: URL {}", uri);
- try {
- response = httpClient.execute(httpGet);
+ try (CloseableHttpClient httpClient = HttpClients.createDefault();CloseableHttpResponse response = httpClient.execute(httpGet)){
logger.debug(EELFLoggerDelegate.debugLogger, "getRestWithCredentials: status " + response.getStatusLine());
HttpEntity entity = response.getEntity();
if (entity == null) {
@@ -120,12 +117,10 @@ public class PortalRestClientBase {
logger.debug(EELFLoggerDelegate.debugLogger, "getRestWithCredentials: JSON {}", responseJson);
EntityUtils.consume(entity);
}
- } finally {
- if (response != null)
- response.close();
+
+ return new HttpStatusAndResponse(response.getStatusLine().getStatusCode(), responseJson);
}
- httpClient.close();
- return new HttpStatusAndResponse(response.getStatusLine().getStatusCode(), responseJson);
+
}
/**
@@ -151,7 +146,6 @@ public class PortalRestClientBase {
throw new IllegalArgumentException(
"postRestWithCredentials: missing one or more required properties and/or database entries");
String decryptedPassword = CipherUtil.decryptPKC(app.getAppPassword());
- CloseableHttpClient httpClient = HttpClients.createDefault();
HttpPost httpPost = new HttpPost(uri);
httpPost.setHeader("uebkey", uebKey);
httpPost.setHeader("username", app.getUsername());
@@ -159,10 +153,8 @@ public class PortalRestClientBase {
StringEntity postEntity = new StringEntity(json, ContentType.create("application/json", Consts.UTF_8));
httpPost.setEntity(postEntity);
String responseJson = null;
- CloseableHttpResponse response = null;
- try {
+ try (CloseableHttpClient httpClient = HttpClients.createDefault();CloseableHttpResponse response = httpClient.execute(httpPost)){
logger.debug(EELFLoggerDelegate.debugLogger, "postRestWithCredentials: POST to {}", uri);
- response = httpClient.execute(httpPost);
logger.debug(EELFLoggerDelegate.debugLogger, "postRestWithCredentials: status {} ",
response.getStatusLine());
HttpEntity entity = response.getEntity();
@@ -175,12 +167,11 @@ public class PortalRestClientBase {
logger.debug(EELFLoggerDelegate.debugLogger, "postRestWithCredentials: JSON {}", responseJson);
EntityUtils.consume(entity);
}
- } finally {
- if (response != null)
- response.close();
- }
- httpClient.close();
- return new HttpStatusAndResponse(response.getStatusLine().getStatusCode(), responseJson);
+
+ return new HttpStatusAndResponse(response.getStatusLine().getStatusCode(), responseJson);
+ }
+
+
}
}
diff --git a/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/service/LoginServiceImpl.java b/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/service/LoginServiceImpl.java
index 95e1c501..ca96a360 100644
--- a/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/service/LoginServiceImpl.java
+++ b/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/service/LoginServiceImpl.java
@@ -79,7 +79,7 @@ public class LoginServiceImpl extends FusionService implements LoginService {
boolean matchPassword) {
User user;
- if (bean.getUserid() != null && bean.getUserid() != null) {
+ if (bean.getUserid() != null) {
user = findUser(bean);
} else {
if (matchPassword)