From 80fdb11bd8d46617dd7b279c0d8011c508c6ba5a Mon Sep 17 00:00:00 2001 From: burdziak Date: Mon, 18 Feb 2019 13:34:58 +0100 Subject: Sonar issues in ReportParamDateValueParser Change-Id: I7ce7d7441e539f7ccf86bbfaa8344548eab1044d Issue-ID: PORTAL-523 Signed-off-by: burdziak --- .../model/runtime/ReportParamDateValueParser.java | 111 ++++++++++----------- 1 file changed, 51 insertions(+), 60 deletions(-) (limited to 'ecomp-sdk/epsdk-analytics') diff --git a/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/model/runtime/ReportParamDateValueParser.java b/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/model/runtime/ReportParamDateValueParser.java index 158e1ffe..73380025 100644 --- a/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/model/runtime/ReportParamDateValueParser.java +++ b/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/model/runtime/ReportParamDateValueParser.java @@ -66,48 +66,42 @@ public class ReportParamDateValueParser { public static boolean isDateHrParam(String param) { SimpleDateFormat[] dateFormats = new SimpleDateFormat[2]; - (dateFormats[0] = new SimpleDateFormat(AppConstants.JAVA_DATE_FORMAT_MMDDYYYY_HR)) - .setLenient(true); - (dateFormats[1] = new SimpleDateFormat(AppConstants.JAVA_DATE_FORMAT_DDMONYYYY_HR)) - .setLenient(true); + dateFormats[0] = new SimpleDateFormat(AppConstants.JAVA_DATE_FORMAT_MMDDYYYY_HR); + dateFormats[0].setLenient(true); + dateFormats[1] = new SimpleDateFormat(AppConstants.JAVA_DATE_FORMAT_DDMONYYYY_HR); + dateFormats[1].setLenient(true); for (int i = 0; i < dateFormats.length; i++) { try { if (dateFormats[i].parse(param) != null) { return true; } - } catch (ParseException pe) { + } catch (ParseException | NumberFormatException pe) { // do nothing, continue to check param against other dates } - catch (NumberFormatException pe) { - // do nothing, continue to check param against other dates - } } return false; } public static boolean isDateParam(String param) { SimpleDateFormat[] dateFormats = new SimpleDateFormat[5]; - (dateFormats[0] = new SimpleDateFormat(AppConstants.JAVA_DATE_FORMAT_MONTHYYYY)) - .setLenient(true); - (dateFormats[1] = new SimpleDateFormat(AppConstants.JAVA_DATE_FORMAT_MONTHDDYYYY)) - .setLenient(true); - (dateFormats[2] = new SimpleDateFormat(AppConstants.JAVA_DATE_FORMAT_MMDDYYYY)) - .setLenient(true); - (dateFormats[3] = new SimpleDateFormat(AppConstants.JAVA_DATE_FORMAT_MMYYYY)) - .setLenient(true); - (dateFormats[4] = new SimpleDateFormat(AppConstants.JAVA_DATE_FORMAT_DDMONYYYY)) - .setLenient(true); + dateFormats[0] = new SimpleDateFormat(AppConstants.JAVA_DATE_FORMAT_MONTHYYYY); + dateFormats[0].setLenient(true); + dateFormats[1] = new SimpleDateFormat(AppConstants.JAVA_DATE_FORMAT_MONTHDDYYYY); + dateFormats[1].setLenient(true); + dateFormats[2] = new SimpleDateFormat(AppConstants.JAVA_DATE_FORMAT_MMDDYYYY); + dateFormats[2].setLenient(true); + dateFormats[3] = new SimpleDateFormat(AppConstants.JAVA_DATE_FORMAT_MMYYYY); + dateFormats[3].setLenient(true); + dateFormats[4] = new SimpleDateFormat(AppConstants.JAVA_DATE_FORMAT_DDMONYYYY); + dateFormats[4].setLenient(true); for (int i = 0; i < dateFormats.length; i++) { try { if (dateFormats[i].parse(param) != null) { return true; } - } catch (ParseException pe) { + } catch (ParseException | NumberFormatException pe) { // do nothing, continue to check param against other dates } - catch (NumberFormatException pe) { - // do nothing, continue to check param against other dates - } } return false; } @@ -128,10 +122,10 @@ public class ReportParamDateValueParser { : "HH"; SimpleDateFormat[] dateFormats = new SimpleDateFormat[2]; - (dateFormats[0] = new SimpleDateFormat(AppConstants.JAVA_DATE_FORMAT_MMDDYYYY_HR)) - .setLenient(true); - (dateFormats[1] = new SimpleDateFormat(AppConstants.JAVA_DATE_FORMAT_DDMONYYYY_HR)) - .setLenient(true); + dateFormats[0] = new SimpleDateFormat(AppConstants.JAVA_DATE_FORMAT_MMDDYYYY_HR); + dateFormats[0].setLenient(true); + dateFormats[1] = new SimpleDateFormat(AppConstants.JAVA_DATE_FORMAT_DDMONYYYY_HR); + dateFormats[1].setLenient(true); for (int i = 0; i < dateFormats.length; i++) { try { @@ -143,13 +137,10 @@ public class ReportParamDateValueParser { return formattedDate; } - } catch (ParseException pe) { + } catch (ParseException | NumberFormatException pe) { // do nothing, continue to check param against other dates and // format accordingly } - catch (NumberFormatException pe) { - // do nothing, continue to check param against other dates - } } return param; } @@ -163,47 +154,47 @@ public class ReportParamDateValueParser { : AppConstants.JAVA_DATE_FORMAT_MMDDYYYY; SimpleDateFormat[] dateFormats = new SimpleDateFormat[5]; - (dateFormats[0] = new SimpleDateFormat(AppConstants.JAVA_DATE_FORMAT_MONTHYYYY)) - .setLenient(true); - (dateFormats[1] = new SimpleDateFormat(AppConstants.JAVA_DATE_FORMAT_MONTHDDYYYY)) - .setLenient(true); - (dateFormats[2] = new SimpleDateFormat(AppConstants.JAVA_DATE_FORMAT_MMDDYYYY)) - .setLenient(true); - (dateFormats[3] = new SimpleDateFormat(AppConstants.JAVA_DATE_FORMAT_MMYYYY)) - .setLenient(true); - (dateFormats[4] = new SimpleDateFormat(AppConstants.JAVA_DATE_FORMAT_DDMONYYYY)) - .setLenient(true); + dateFormats[0] = new SimpleDateFormat(AppConstants.JAVA_DATE_FORMAT_MONTHYYYY); + dateFormats[0].setLenient(true); + dateFormats[1] = new SimpleDateFormat(AppConstants.JAVA_DATE_FORMAT_MONTHDDYYYY); + dateFormats[1].setLenient(true); + dateFormats[2] = new SimpleDateFormat(AppConstants.JAVA_DATE_FORMAT_MMDDYYYY); + dateFormats[2].setLenient(true); + dateFormats[3] = new SimpleDateFormat(AppConstants.JAVA_DATE_FORMAT_MMYYYY); + dateFormats[3].setLenient(true); + dateFormats[4] = new SimpleDateFormat(AppConstants.JAVA_DATE_FORMAT_DDMONYYYY); + dateFormats[4].setLenient(true); for (int i = 0; i < dateFormats.length; i++) { try { - if (dateFormats[i].parse(param) != null) { - SimpleDateFormat newDateFormat = new SimpleDateFormat(dateFormatPattern); - parsedDate = dateFormats[i].parse(param); - formattedDate = newDateFormat.format(parsedDate); + if (dateFormats[i].parse(param) == null) { + continue; + } - if (Globals.getMonthFormatUseLastDay() - && (dateFormats[i].toPattern().equals( - AppConstants.JAVA_DATE_FORMAT_MMYYYY) || dateFormats[i] - .toPattern().equals( - AppConstants.JAVA_DATE_FORMAT_MONTHYYYY))) { + SimpleDateFormat newDateFormat = new SimpleDateFormat(dateFormatPattern); + parsedDate = dateFormats[i].parse(param); + formattedDate = newDateFormat.format(parsedDate); - GregorianCalendar gc = new GregorianCalendar(); - gc.setTime(parsedDate); - int day = gc.getActualMaximum(GregorianCalendar.DAY_OF_MONTH); - formattedDate = Utils.replaceInString(formattedDate, "/01/", "/" - + String.valueOf(day) + "/"); + if (Globals.getMonthFormatUseLastDay() + && (dateFormats[i].toPattern().equals( + AppConstants.JAVA_DATE_FORMAT_MMYYYY) || dateFormats[i] + .toPattern().equals( + AppConstants.JAVA_DATE_FORMAT_MONTHYYYY))) { - } + GregorianCalendar gc = new GregorianCalendar(); + gc.setTime(parsedDate); + int day = gc.getActualMaximum(GregorianCalendar.DAY_OF_MONTH); + formattedDate = Utils.replaceInString(formattedDate, "/01/", "/" + + day + "/"); - return formattedDate; } - } catch (ParseException pe) { + + return formattedDate; + + } catch (ParseException | NumberFormatException pe) { // do nothing, continue to check param against other dates and // format accordingly } - catch (NumberFormatException pe) { - // do nothing, continue to check param against other dates - } } return param; } -- cgit 1.2.3-korg