summaryrefslogtreecommitdiffstats
path: root/ecomp-sdk/epsdk-analytics/src/main/java/org
diff options
context:
space:
mode:
Diffstat (limited to 'ecomp-sdk/epsdk-analytics/src/main/java/org')
-rw-r--r--ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/RaptorObject.java6
-rw-r--r--ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/controller/Controller.java35
-rw-r--r--ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/controller/ErrorHandler.java20
-rw-r--r--ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/model/runtime/ReportParamDateValueParser.java111
4 files changed, 82 insertions, 90 deletions
diff --git a/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/RaptorObject.java b/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/RaptorObject.java
index 8b968cc8..fd5fdba1 100644
--- a/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/RaptorObject.java
+++ b/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/RaptorObject.java
@@ -44,7 +44,7 @@ public class RaptorObject extends java.lang.Object {
}
protected String nvl(String s, String sDefault) {
- return nvl(s).equals("") ? sDefault : s;
+ return nvl(s).isEmpty() ? sDefault : s;
}
protected static String nvls(String s) {
@@ -52,11 +52,11 @@ public class RaptorObject extends java.lang.Object {
}
protected static String nvls(String s, String sDefault) {
- return nvls(s).equals("") ? sDefault : s;
+ return nvls(s).isEmpty() ? sDefault : s;
}
protected boolean getFlagInBoolean(String s) {
- return nvl(s).toUpperCase().startsWith("Y") || nvl(s).toLowerCase().equals("true");
+ return nvl(s).toUpperCase().startsWith("Y") || "true".equalsIgnoreCase(nvl(s));
}
} // RaptorObject
diff --git a/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/controller/Controller.java b/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/controller/Controller.java
index 24f66092..b26beb7a 100644
--- a/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/controller/Controller.java
+++ b/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/controller/Controller.java
@@ -37,10 +37,12 @@
*/
package org.onap.portalsdk.analytics.controller;
+import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import javax.servlet.ServletContext;
+import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@@ -51,7 +53,12 @@ import org.onap.portalsdk.analytics.util.AppConstants;
import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
public class Controller extends org.onap.portalsdk.analytics.RaptorObject {
-
+
+ private static final String CONTROLLER_INVALID_ACTION =
+ "[Controller.processRequest]Invalid raptor action [";
+ private static final String CONTROLLER_INSTANTIATE_EXCEPTION =
+ "[Controller.processRequest] Unable to instantiate and invoke action handler. Exception: ";
+
private static final EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(Controller.class);
public Controller() {
@@ -70,11 +77,11 @@ public class Controller extends org.onap.portalsdk.analytics.RaptorObject {
if (action == null)
throw new RaptorRuntimeException("Action not found");
} catch (RaptorException e) {
- logger.debug(EELFLoggerDelegate.debugLogger, ("[Controller.processRequest]Invalid raptor action [" + actionKey
+ logger.debug(EELFLoggerDelegate.debugLogger, (CONTROLLER_INVALID_ACTION + actionKey
+ "]. RaptorException: " + e.getMessage()));
return (new ErrorHandler()).processFatalError(request, new RaptorRuntimeException(
- "[Controller.processRequest]Invalid raptor action [" + actionKey
+ CONTROLLER_INVALID_ACTION + actionKey
+ "]. Exception: " + e.getMessage()));
}
@@ -94,34 +101,34 @@ public class Controller extends org.onap.portalsdk.analytics.RaptorObject {
return (String) handlerMethod.invoke(handler, paramValues);
} catch (ClassNotFoundException e) {
- logger.debug(EELFLoggerDelegate.debugLogger, ("[Controller.processRequest]Invalid raptor action [" + actionKey
+ logger.debug(EELFLoggerDelegate.debugLogger, (CONTROLLER_INVALID_ACTION + actionKey
+ "]. ClassNotFoundException: " + e.getMessage()));
return (new ErrorHandler()).processFatalError(request, new RaptorRuntimeException(
- "[Controller.processRequest] Unable to instantiate and invoke action handler. Exception: "
+ CONTROLLER_INSTANTIATE_EXCEPTION
+ e.getMessage()));
} catch (IllegalAccessException e) {
- logger.debug(EELFLoggerDelegate.debugLogger, ("[Controller.processRequest]Invalid raptor action [" + actionKey
+ logger.debug(EELFLoggerDelegate.debugLogger, (CONTROLLER_INVALID_ACTION + actionKey
+ "]. IllegalAccessException: " + e.getMessage()));
return (new ErrorHandler()).processFatalError(request, new RaptorRuntimeException(
- "[Controller.processRequest] Unable to instantiate and invoke action handler. Exception: "
+ CONTROLLER_INSTANTIATE_EXCEPTION
+ e.getMessage()));
}catch (InstantiationException e) {
- logger.debug(EELFLoggerDelegate.debugLogger, ("[Controller.processRequest]Invalid raptor action [" + actionKey
+ logger.debug(EELFLoggerDelegate.debugLogger, (CONTROLLER_INVALID_ACTION + actionKey
+ "]. InstantiationException: " + e.getMessage()));
return (new ErrorHandler()).processFatalError(request, new RaptorRuntimeException(
- "[Controller.processRequest] Unable to instantiate and invoke action handler. Exception: "
+ CONTROLLER_INSTANTIATE_EXCEPTION
+ e.getMessage()));
}catch (NoSuchMethodException e) {
- logger.debug(EELFLoggerDelegate.debugLogger, ("[Controller.processRequest]Invalid raptor action [" + actionKey
+ logger.debug(EELFLoggerDelegate.debugLogger, (CONTROLLER_INVALID_ACTION + actionKey
+ "]. NoSuchMethodException: " + e.getMessage()));
return (new ErrorHandler()).processFatalError(request, new RaptorRuntimeException(
- "[Controller.processRequest] Unable to instantiate and invoke action handler. Exception: "
+ CONTROLLER_INSTANTIATE_EXCEPTION
+ e.getMessage()));
}catch (InvocationTargetException e) {
- logger.debug(EELFLoggerDelegate.debugLogger, ("[Controller.processRequest]Invalid raptor action [" + actionKey
+ logger.debug(EELFLoggerDelegate.debugLogger, (CONTROLLER_INVALID_ACTION + actionKey
+ "]. InvocationTargetException: " + e.getMessage()));
return (new ErrorHandler()).processFatalError(request, new RaptorRuntimeException(
- "[Controller.processRequest] Unable to instantiate and invoke action handler. Exception: "
+ CONTROLLER_INSTANTIATE_EXCEPTION
+ e.getMessage()));
}
} // processRequest
@@ -134,7 +141,7 @@ public class Controller extends org.onap.portalsdk.analytics.RaptorObject {
} // handleRequest
public void handleRequest(String actionKey, HttpServletRequest request,
- HttpServletResponse response, ServletContext servletContext) throws Exception {
+ HttpServletResponse response, ServletContext servletContext) throws IOException,ServletException {
servletContext.getRequestDispatcher("/" + processRequest(actionKey, request)).forward(
request, response);
} // handleRequest
diff --git a/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/controller/ErrorHandler.java b/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/controller/ErrorHandler.java
index 403c6b6b..1a31e604 100644
--- a/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/controller/ErrorHandler.java
+++ b/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/controller/ErrorHandler.java
@@ -68,13 +68,12 @@ public class ErrorHandler extends org.onap.portalsdk.analytics.RaptorObject {
}
public void processError(HttpServletRequest request, String errorMsg) {
- //Log.write(errorMsg, 2);
logger.error(EELFLoggerDelegate.debugLogger, (errorMsg));
- ArrayList error_list = (ArrayList) request.getAttribute(AppConstants.RI_ERROR_LIST);
- if (error_list == null)
- error_list = new ArrayList(1);
- error_list.add(errorMsg);
- request.setAttribute(AppConstants.RI_ERROR_LIST, error_list);
+ ArrayList errorList = (ArrayList) request.getAttribute(AppConstants.RI_ERROR_LIST);
+ if (errorList == null)
+ errorList = new ArrayList(1);
+ errorList.add(errorMsg);
+ request.setAttribute(AppConstants.RI_ERROR_LIST, errorList);
} // processError
public void processError(HttpServletRequest request, RaptorException e) {
@@ -83,7 +82,7 @@ public class ErrorHandler extends org.onap.portalsdk.analytics.RaptorObject {
private String getSessionLog(HttpServletRequest request) {
String[] sessionVariablesToLog = Globals.getLogVariablesInSession().split(",");
- StringBuffer sessionLogStrBuf = new StringBuffer("\n");
+ StringBuilder sessionLogStrBuf = new StringBuilder("\n");
sessionLogStrBuf.append("***** ADDITIONAL INFORMATION ******");
HttpSession session = request.getSession();
ReportRuntime rr = (ReportRuntime) session.getAttribute(AppConstants.SI_REPORT_RUNTIME);
@@ -106,7 +105,6 @@ public class ErrorHandler extends org.onap.portalsdk.analytics.RaptorObject {
return sessionLogStrBuf.toString();
}
public String processFatalError(HttpServletRequest request, RaptorException e) {
- //Log.write("Fatal error [" + e.getClass().getName() + "]: " + nvl(e.getMessage()), 1);
logger.error(EELFLoggerDelegate.debugLogger, ("[EXCEPTION ENCOUNTERED IN RAPTOR] Fatal error [" + e.getClass().getName() + "]: " + nvl(e.getMessage())+" "+ getSessionLog(request) + e.getMessage()),AlarmSeverityEnum.MAJOR);
if (e instanceof ReportSQLException) {
String errorSQL = ((ReportSQLException) e).getReportSQL();
@@ -120,28 +118,25 @@ public class ErrorHandler extends org.onap.portalsdk.analytics.RaptorObject {
} // processFatalError
public String processFatalErrorJSON(HttpServletRequest request, RaptorException e) {
- //Log.write("Fatal error [" + e.getClass().getName() + "]: " + nvl(e.getMessage()), 1);
logger.error(EELFLoggerDelegate.debugLogger, ("[EXCEPTION ENCOUNTERED IN RAPTOR] Fatal error [" + e.getClass().getName() + "]: " + nvl(e.getMessage())+" "+ getSessionLog(request) + e.getMessage()),AlarmSeverityEnum.MAJOR);
if (e instanceof ReportSQLException) {
String errorSQL = ((ReportSQLException) e).getReportSQL();
if (nvl(errorSQL).length() > 0)
request.setAttribute("c_error_sql", errorSQL);
} // if
- //AppUtils.processErrorNotification(request, e);
request.setAttribute(AppConstants.RI_EXCEPTION, e);
ErrorJSONRuntime errorJSONRuntime = new ErrorJSONRuntime();
errorJSONRuntime.setErrormessage(e.toString());
errorJSONRuntime.setStacktrace(getStackTrace(e));
ObjectMapper mapper = new ObjectMapper();
- //mapper.setVisibility(JsonMethod.FIELD, Visibility.ANY);
- //mapper.setVisibilityChecker(mapper.getVisibilityChecker().with(JsonAutoDetect.Visibility.NONE));
mapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
String jsonInString = "";
try {
jsonInString = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(errorJSONRuntime);
} catch (Exception ex) {
+ logger.error(EELFLoggerDelegate.debugLogger, ("[EXCEPTION ENCOUNTERED IN RAPTOR] Fatal error [" + ex.getClass().getName() + "]: " + nvl(ex.getMessage())+" "+ getSessionLog(request) + ex.getMessage()),AlarmSeverityEnum.MAJOR);
ex.printStackTrace();
}
@@ -155,7 +150,6 @@ public class ErrorHandler extends org.onap.portalsdk.analytics.RaptorObject {
return result.toString();
}
public String processFatalErrorWMenu(HttpServletRequest request, RaptorException e) {
- //Log.write("Fatal error [" + e.getClass().getName() + "]: " + nvl(e.getMessage()), 1);
logger.error(EELFLoggerDelegate.debugLogger, ("[EXCEPTION ENCOUNTERED IN RAPTOR] Fatal error [" + e.getClass().getName() + "]: " + nvl(e.getMessage())+" "+ getSessionLog(request) + e.getMessage()),AlarmSeverityEnum.MAJOR);
if (e instanceof ReportSQLException) {
String errorSQL = ((ReportSQLException) e).getReportSQL();
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;
}